Mercurial > cpython-lru_cache-weakref
annotate Lib/audiodev.py @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 18451dca9469 |
| children | 7b9a6166281a |
| rev | line source |
|---|---|
|
1434
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1 error = 'audiodev.error' |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3 class Play_Audio_sgi: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
4 # Private instance variables |
|
4078
18451dca9469
Get rid of access statement
Guido van Rossum <guido@python.org>
parents:
2936
diff
changeset
|
5 ## if 0: access frameratelist, nchannelslist, sampwidthlist, oldparams, \ |
|
18451dca9469
Get rid of access statement
Guido van Rossum <guido@python.org>
parents:
2936
diff
changeset
|
6 ## params, config, inited_outrate, inited_width, \ |
|
18451dca9469
Get rid of access statement
Guido van Rossum <guido@python.org>
parents:
2936
diff
changeset
|
7 ## inited_nchannels, port, converter, classinited: private |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
8 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
9 classinited = 0 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
10 frameratelist = nchannelslist = sampwidthlist = None |
|
1434
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
11 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
12 def initclass(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
13 import AL |
|
2936
0970ebd31536
rather ugly temporary hacks to make it work in grail & restricted mode
Guido van Rossum <guido@python.org>
parents:
1893
diff
changeset
|
14 self.frameratelist = [ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
15 (48000, AL.RATE_48000), |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
16 (44100, AL.RATE_44100), |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
17 (32000, AL.RATE_32000), |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
18 (22050, AL.RATE_22050), |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
19 (16000, AL.RATE_16000), |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
20 (11025, AL.RATE_11025), |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
21 ( 8000, AL.RATE_8000), |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
22 ] |
|
2936
0970ebd31536
rather ugly temporary hacks to make it work in grail & restricted mode
Guido van Rossum <guido@python.org>
parents:
1893
diff
changeset
|
23 self.nchannelslist = [ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
24 (1, AL.MONO), |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
25 (2, AL.STEREO), |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
26 ] |
|
2936
0970ebd31536
rather ugly temporary hacks to make it work in grail & restricted mode
Guido van Rossum <guido@python.org>
parents:
1893
diff
changeset
|
27 self.sampwidthlist = [ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
28 (1, AL.SAMPLE_8), |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
29 (2, AL.SAMPLE_16), |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
30 (3, AL.SAMPLE_24), |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
31 ] |
|
2936
0970ebd31536
rather ugly temporary hacks to make it work in grail & restricted mode
Guido van Rossum <guido@python.org>
parents:
1893
diff
changeset
|
32 self.classinited = 1 |
|
1434
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
33 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
34 def __init__(self): |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
35 import al, AL |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
36 if not self.classinited: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
37 self.initclass() |
|
1434
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
38 self.oldparams = [] |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
39 self.params = [AL.OUTPUT_RATE, 0] |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
40 self.config = al.newconfig() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
41 self.inited_outrate = 0 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
42 self.inited_width = 0 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
43 self.inited_nchannels = 0 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
44 self.converter = None |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
45 self.port = None |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
46 return |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
47 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
48 def __del__(self): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
49 if self.port: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
50 self.stop() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
51 if self.oldparams: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
52 import al, AL |
|
1434
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
53 al.setparams(AL.DEFAULT_DEVICE, self.oldparams) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
54 self.oldparams = [] |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
55 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
56 def wait(self): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
57 if not self.port: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
58 return |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
59 import time |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
60 while self.port.getfilled() > 0: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
61 time.sleep(0.1) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
62 self.stop() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
63 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
64 def stop(self): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
65 if self.port: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
66 self.port.closeport() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
67 self.port = None |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
68 if self.oldparams: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
69 import al, AL |
|
1434
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
70 al.setparams(AL.DEFAULT_DEVICE, self.oldparams) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
71 self.oldparams = [] |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
72 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
73 def setoutrate(self, rate): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
74 for (raw, cooked) in self.frameratelist: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
75 if rate == raw: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
76 self.params[1] = cooked |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
77 self.inited_outrate = 1 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
78 break |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
79 else: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
80 raise error, 'bad output rate' |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
81 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
82 def setsampwidth(self, width): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
83 for (raw, cooked) in self.sampwidthlist: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
84 if width == raw: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
85 self.config.setwidth(cooked) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
86 self.inited_width = 1 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
87 break |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
88 else: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
89 if width == 0: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
90 import AL |
|
1434
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
91 self.inited_width = 0 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
92 self.config.setwidth(AL.SAMPLE_16) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
93 self.converter = self.ulaw2lin |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
94 else: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
95 raise error, 'bad sample width' |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
96 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
97 def setnchannels(self, nchannels): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
98 for (raw, cooked) in self.nchannelslist: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
99 if nchannels == raw: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
100 self.config.setchannels(cooked) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
101 self.inited_nchannels = 1 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
102 break |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
103 else: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
104 raise error, 'bad # of channels' |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
105 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
106 def writeframes(self, data): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
107 if not (self.inited_outrate and self.inited_nchannels): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
108 raise error, 'params not specified' |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
109 if not self.port: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
110 import al, AL |
|
1434
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
111 self.port = al.openport('Python', 'w', self.config) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
112 self.oldparams = self.params[:] |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
113 al.getparams(AL.DEFAULT_DEVICE, self.oldparams) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
114 al.setparams(AL.DEFAULT_DEVICE, self.params) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
115 if self.converter: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
116 data = self.converter(data) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
117 self.port.writesamps(data) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
118 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
119 def getfilled(self): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
120 if self.port: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
121 return self.port.getfilled() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
122 else: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
123 return 0 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
124 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
125 def getfillable(self): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
126 if self.port: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
127 return self.port.getfillable() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
128 else: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
129 return self.config.getqueuesize() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
130 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
131 # private methods |
|
4078
18451dca9469
Get rid of access statement
Guido van Rossum <guido@python.org>
parents:
2936
diff
changeset
|
132 ## if 0: access *: private |
|
1434
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
133 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
134 def ulaw2lin(self, data): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
135 import audioop |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
136 return audioop.ulaw2lin(data, 2) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
137 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
138 class Play_Audio_sun: |
|
4078
18451dca9469
Get rid of access statement
Guido van Rossum <guido@python.org>
parents:
2936
diff
changeset
|
139 ## if 0: access outrate, sampwidth, nchannels, inited_outrate, inited_width, \ |
|
18451dca9469
Get rid of access statement
Guido van Rossum <guido@python.org>
parents:
2936
diff
changeset
|
140 ## inited_nchannels, converter: private |
|
1434
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
141 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
142 def __init__(self): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
143 self.outrate = 0 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
144 self.sampwidth = 0 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
145 self.nchannels = 0 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
146 self.inited_outrate = 0 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
147 self.inited_width = 0 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
148 self.inited_nchannels = 0 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
149 self.converter = None |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
150 self.port = None |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
151 return |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
152 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
153 def __del__(self): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
154 self.stop() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
155 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
156 def setoutrate(self, rate): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
157 self.outrate = rate |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
158 self.inited_outrate = 1 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
159 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
160 def setsampwidth(self, width): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
161 self.sampwidth = width |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
162 self.inited_width = 1 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
163 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
164 def setnchannels(self, nchannels): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
165 self.nchannels = nchannels |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
166 self.inited_nchannels = 1 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
167 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
168 def writeframes(self, data): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
169 if not (self.inited_outrate and self.inited_width and self.inited_nchannels): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
170 raise error, 'params not specified' |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
171 if not self.port: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1434
diff
changeset
|
172 import sunaudiodev, SUNAUDIODEV |
|
1434
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
173 self.port = sunaudiodev.open('w') |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
174 info = self.port.getinfo() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
175 info.o_sample_rate = self.outrate |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
176 info.o_channels = self.nchannels |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
177 if self.sampwidth == 0: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
178 info.o_precision = 8 |
|
2936
0970ebd31536
rather ugly temporary hacks to make it work in grail & restricted mode
Guido van Rossum <guido@python.org>
parents:
1893
diff
changeset
|
179 self.o_encoding = SUNAUDIODEV.ENCODING_ULAW |
|
0970ebd31536
rather ugly temporary hacks to make it work in grail & restricted mode
Guido van Rossum <guido@python.org>
parents:
1893
diff
changeset
|
180 # XXX Hack, hack -- leave defaults |
|
1434
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
181 else: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
182 info.o_precision = 8 * self.sampwidth |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
183 info.o_encoding = SUNAUDIODEV.ENCODING_LINEAR |
|
2936
0970ebd31536
rather ugly temporary hacks to make it work in grail & restricted mode
Guido van Rossum <guido@python.org>
parents:
1893
diff
changeset
|
184 self.port.setinfo(info) |
|
1434
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
185 if self.converter: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
186 data = self.converter(data) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
187 self.port.write(data) |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
188 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
189 def wait(self): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
190 if not self.port: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
191 return |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
192 self.port.drain() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
193 self.stop() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
194 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
195 def stop(self): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
196 if self.port: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
197 self.port.flush() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
198 self.port.close() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
199 self.port = None |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
200 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
201 def getfilled(self): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
202 if self.port: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
203 return self.port.obufcount() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
204 else: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
205 return 0 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
206 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
207 def getfillable(self): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
208 return BUFFERSIZE - self.getfilled() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
209 |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
210 def AudioDev(): |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
211 try: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
212 import al |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
213 except ImportError: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
214 try: |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
215 import sunaudiodev |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
216 return Play_Audio_sun() |
|
46c217337bde
Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
217 except ImportError: |
|
1893
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
218 try: |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
219 import Audio_mac |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
220 except ImportError: |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
221 raise error, 'no audio device' |
|
2936
0970ebd31536
rather ugly temporary hacks to make it work in grail & restricted mode
Guido van Rossum <guido@python.org>
parents:
1893
diff
changeset
|
222 else: |
|
0970ebd31536
rather ugly temporary hacks to make it work in grail & restricted mode
Guido van Rossum <guido@python.org>
parents:
1893
diff
changeset
|
223 return Audio_mac.Play_Audio_mac() |
|
0970ebd31536
rather ugly temporary hacks to make it work in grail & restricted mode
Guido van Rossum <guido@python.org>
parents:
1893
diff
changeset
|
224 else: |
|
0970ebd31536
rather ugly temporary hacks to make it work in grail & restricted mode
Guido van Rossum <guido@python.org>
parents:
1893
diff
changeset
|
225 return Play_Audio_sgi() |
|
1893
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
226 |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
227 def test(fn = 'f:just samples:just.aif'): |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
228 import aifc |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
229 af = aifc.open(fn, 'r') |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
230 print fn, af.getparams() |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
231 p = AudioDev() |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
232 p.setoutrate(af.getframerate()) |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
233 p.setsampwidth(af.getsampwidth()) |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
234 p.setnchannels(af.getnchannels()) |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
235 BUFSIZ = af.getframerate()/af.getsampwidth()/af.getnchannels() |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
236 while 1: |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
237 data = af.readframes(BUFSIZ) |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
238 if not data: break |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
239 print len(data) |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
240 p.writeframes(data) |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
241 p.wait() |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
242 |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
243 if __name__ == '__main__': |
|
aba51621244e
audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
244 test() |
