annotate Lib/audiodev.py @ 5817:48b94de85bf3 legacy-trunk

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