annotate Lib/audiodev.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents ffdb5f4139fe
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11691
e34991022571 Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents: 10818
diff changeset
1 """Classes for manipulating audio devices (currently only for Sun and SGI)"""
46702
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 19221
diff changeset
2 from warnings import warnpy3k
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 19221
diff changeset
3 warnpy3k("the audiodev module has been removed in Python 3.0", stacklevel=2)
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 19221
diff changeset
4 del warnpy3k
11691
e34991022571 Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents: 10818
diff changeset
5
16070
b5345e99596b added __all__ lists to a number of Python modules
Skip Montanaro <skip@pobox.com>
parents: 15857
diff changeset
6 __all__ = ["error","AudioDev"]
b5345e99596b added __all__ lists to a number of Python modules
Skip Montanaro <skip@pobox.com>
parents: 15857
diff changeset
7
14022
d44603f2b928 Convert some old-style string exceptions to class exceptions.
Fred Drake <fdrake@acm.org>
parents: 11691
diff changeset
8 class error(Exception):
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
9 pass
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
10
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
11 class Play_Audio_sgi:
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
12 # Private instance variables
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
13 ## if 0: access frameratelist, nchannelslist, sampwidthlist, oldparams, \
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
14 ## params, config, inited_outrate, inited_width, \
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
15 ## 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
16
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
17 classinited = 0
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
18 frameratelist = nchannelslist = sampwidthlist = None
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
19
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
20 def initclass(self):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
21 import AL
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
22 self.frameratelist = [
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
23 (48000, AL.RATE_48000),
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
24 (44100, AL.RATE_44100),
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
25 (32000, AL.RATE_32000),
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
26 (22050, AL.RATE_22050),
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
27 (16000, AL.RATE_16000),
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
28 (11025, AL.RATE_11025),
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
29 ( 8000, AL.RATE_8000),
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
30 ]
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
31 self.nchannelslist = [
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
32 (1, AL.MONO),
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
33 (2, AL.STEREO),
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
34 (4, AL.QUADRO),
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
35 ]
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
36 self.sampwidthlist = [
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
37 (1, AL.SAMPLE_8),
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
38 (2, AL.SAMPLE_16),
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
39 (3, AL.SAMPLE_24),
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
40 ]
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
41 self.classinited = 1
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
42
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
43 def __init__(self):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
44 import al, AL
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
45 if not self.classinited:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
46 self.initclass()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
47 self.oldparams = []
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
48 self.params = [AL.OUTPUT_RATE, 0]
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
49 self.config = al.newconfig()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
50 self.inited_outrate = 0
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
51 self.inited_width = 0
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
52 self.inited_nchannels = 0
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
53 self.converter = None
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
54 self.port = None
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
55 return
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
56
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
57 def __del__(self):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
58 if self.port:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
59 self.stop()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
60 if self.oldparams:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
61 import al, AL
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
62 al.setparams(AL.DEFAULT_DEVICE, self.oldparams)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
63 self.oldparams = []
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
64
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
65 def wait(self):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
66 if not self.port:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
67 return
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
68 import time
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
69 while self.port.getfilled() > 0:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
70 time.sleep(0.1)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
71 self.stop()
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
72
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
73 def stop(self):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
74 if self.port:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
75 self.port.closeport()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
76 self.port = None
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
77 if self.oldparams:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
78 import al, AL
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
79 al.setparams(AL.DEFAULT_DEVICE, self.oldparams)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
80 self.oldparams = []
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
81
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
82 def setoutrate(self, rate):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
83 for (raw, cooked) in self.frameratelist:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
84 if rate == raw:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
85 self.params[1] = cooked
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
86 self.inited_outrate = 1
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
87 break
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
88 else:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
89 raise error, 'bad output rate'
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
90
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
91 def setsampwidth(self, width):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
92 for (raw, cooked) in self.sampwidthlist:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
93 if width == raw:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
94 self.config.setwidth(cooked)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
95 self.inited_width = 1
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
96 break
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
97 else:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
98 if width == 0:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
99 import AL
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
100 self.inited_width = 0
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
101 self.config.setwidth(AL.SAMPLE_16)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
102 self.converter = self.ulaw2lin
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
103 else:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
104 raise error, 'bad sample width'
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
105
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
106 def setnchannels(self, nchannels):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
107 for (raw, cooked) in self.nchannelslist:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
108 if nchannels == raw:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
109 self.config.setchannels(cooked)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
110 self.inited_nchannels = 1
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
111 break
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
112 else:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
113 raise error, 'bad # of channels'
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
114
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
115 def writeframes(self, data):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
116 if not (self.inited_outrate and self.inited_nchannels):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
117 raise error, 'params not specified'
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
118 if not self.port:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
119 import al, AL
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
120 self.port = al.openport('Python', 'w', self.config)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
121 self.oldparams = self.params[:]
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
122 al.getparams(AL.DEFAULT_DEVICE, self.oldparams)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
123 al.setparams(AL.DEFAULT_DEVICE, self.params)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
124 if self.converter:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
125 data = self.converter(data)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
126 self.port.writesamps(data)
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
127
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
128 def getfilled(self):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
129 if self.port:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
130 return self.port.getfilled()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
131 else:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
132 return 0
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
133
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
134 def getfillable(self):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
135 if self.port:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
136 return self.port.getfillable()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
137 else:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
138 return self.config.getqueuesize()
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
139
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
140 # private methods
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
141 ## if 0: access *: private
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
142
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
143 def ulaw2lin(self, data):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
144 import audioop
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
145 return audioop.ulaw2lin(data, 2)
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
146
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
147 class Play_Audio_sun:
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
148 ## if 0: access outrate, sampwidth, nchannels, inited_outrate, inited_width, \
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
149 ## inited_nchannels, converter: private
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
150
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
151 def __init__(self):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
152 self.outrate = 0
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
153 self.sampwidth = 0
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
154 self.nchannels = 0
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
155 self.inited_outrate = 0
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
156 self.inited_width = 0
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
157 self.inited_nchannels = 0
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
158 self.converter = None
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
159 self.port = None
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
160 return
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
161
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
162 def __del__(self):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
163 self.stop()
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
164
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
165 def setoutrate(self, rate):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
166 self.outrate = rate
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
167 self.inited_outrate = 1
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
168
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
169 def setsampwidth(self, width):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
170 self.sampwidth = width
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
171 self.inited_width = 1
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
172
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
173 def setnchannels(self, nchannels):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
174 self.nchannels = nchannels
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
175 self.inited_nchannels = 1
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
176
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
177 def writeframes(self, data):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
178 if not (self.inited_outrate and self.inited_width and self.inited_nchannels):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
179 raise error, 'params not specified'
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
180 if not self.port:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
181 import sunaudiodev, SUNAUDIODEV
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
182 self.port = sunaudiodev.open('w')
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
183 info = self.port.getinfo()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
184 info.o_sample_rate = self.outrate
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
185 info.o_channels = self.nchannels
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
186 if self.sampwidth == 0:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
187 info.o_precision = 8
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
188 self.o_encoding = SUNAUDIODEV.ENCODING_ULAW
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
189 # XXX Hack, hack -- leave defaults
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
190 else:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
191 info.o_precision = 8 * self.sampwidth
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
192 info.o_encoding = SUNAUDIODEV.ENCODING_LINEAR
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
193 self.port.setinfo(info)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
194 if self.converter:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
195 data = self.converter(data)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
196 self.port.write(data)
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
197
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
198 def wait(self):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
199 if not self.port:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
200 return
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
201 self.port.drain()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
202 self.stop()
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
203
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
204 def stop(self):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
205 if self.port:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
206 self.port.flush()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
207 self.port.close()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
208 self.port = None
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
209
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
210 def getfilled(self):
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
211 if self.port:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
212 return self.port.obufcount()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
213 else:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
214 return 0
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
215
19221
3c7ad5037ab1 Commenting out the getfillable() method -- it's broken, and nobody
Guido van Rossum <guido@python.org>
parents: 16070
diff changeset
216 ## # Nobody remembers what this method does, and it's broken. :-(
3c7ad5037ab1 Commenting out the getfillable() method -- it's broken, and nobody
Guido van Rossum <guido@python.org>
parents: 16070
diff changeset
217 ## def getfillable(self):
3c7ad5037ab1 Commenting out the getfillable() method -- it's broken, and nobody
Guido van Rossum <guido@python.org>
parents: 16070
diff changeset
218 ## return BUFFERSIZE - self.getfilled()
1434
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
219
46c217337bde Interface to audio hardware for SGI and Sun.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
220 def AudioDev():
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
221 # Dynamically try to import and use a platform specific module.
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
222 try:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
223 import al
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
224 except ImportError:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
225 try:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
226 import sunaudiodev
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
227 return Play_Audio_sun()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
228 except ImportError:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
229 try:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
230 import Audio_mac
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
231 except ImportError:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
232 raise error, 'no audio device'
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
233 else:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
234 return Audio_mac.Play_Audio_mac()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
235 else:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
236 return Play_Audio_sgi()
1893
aba51621244e audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
237
4710
7b9a6166281a Added support for 4-channel on SGI.
Guido van Rossum <guido@python.org>
parents: 4078
diff changeset
238 def test(fn = None):
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
239 import sys
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
240 if sys.argv[1:]:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
241 fn = sys.argv[1]
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
242 else:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
243 fn = 'f:just samples:just.aif'
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
244 import aifc
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
245 af = aifc.open(fn, 'r')
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
246 print fn, af.getparams()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
247 p = AudioDev()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
248 p.setoutrate(af.getframerate())
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
249 p.setsampwidth(af.getsampwidth())
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
250 p.setnchannels(af.getnchannels())
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
251 BUFSIZ = af.getframerate()/af.getsampwidth()/af.getnchannels()
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
252 while 1:
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
253 data = af.readframes(BUFSIZ)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
254 if not data: break
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
255 print len(data)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
256 p.writeframes(data)
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
257 p.wait()
1893
aba51621244e audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
258
aba51621244e audiodev.py: Mac port.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
259 if __name__ == '__main__':
15857
0a8da6f397b7 Whitespace standardization.
Tim Peters <tim.peters@gmail.com>
parents: 14022
diff changeset
260 test()