2 error
='Audio_mac.error'
6 def __init__(self
, qsize
=QSIZE
):
13 self
._usercallback
= None
17 self
._usercallback
= None
21 while self
.getfilled():
26 def stop(self
, quietNow
= 1):
29 ##chan.SndDisposeChannel(1)
32 def setoutrate(self
, outrate
):
33 self
._outrate
= outrate
35 def setsampwidth(self
, sampwidth
):
36 self
._sampwidth
= sampwidth
38 def setnchannels(self
, nchannels
):
39 self
._nchannels
= nchannels
41 def writeframes(self
, data
):
48 self
._chan
= Snd
.SndNewChannel(5, 0, self
._callback
)
49 nframes
= len(data
) / self
._nchannels
/ self
._sampwidth
50 if len(data
) != nframes
* self
._nchannels
* self
._sampwidth
:
51 raise error
, 'data is not a whole number of frames'
53 self
.getfilled() + nframes
> \
54 self
._qsize
/ self
._nchannels
/ self
._sampwidth
:
56 if self
._sampwidth
== 1:
58 data
= audioop
.add(data
, '\x80'*len(data
), 1)
59 h1
= struct
.pack('llhhllbbl',
60 id(data
)+MacOS
.string_id_to_buffer
,
69 h3
= struct
.pack('hhlll',
76 self
._gc
.append((header
, data
))
77 self
._chan
.SndDoCommand((bufferCmd
, 0, header
), 0)
78 self
._chan
.SndDoCommand((callBackCmd
, 0, 0), 0)
80 def _callback(self
, *args
):
82 if self
._usercallback
:
85 def setcallback(self
, callback
):
86 self
._usercallback
= callback
90 for header
, data
in self
._gc
:
91 filled
= filled
+ len(data
)
92 return filled
/ self
._nchannels
/ self
._sampwidth
94 def getfillable(self
):
95 return (self
._qsize
/ self
._nchannels
/ self
._sampwidth
) - self
.getfilled()
97 def ulaw2lin(self
, data
):
99 return audioop
.ulaw2lin(data
, 2)
104 fss
, ok
= macfs
.PromptGetFile("Select an AIFF soundfile", "AIFF")
106 fn
= fss
.as_pathname()
107 af
= aifc
.open(fn
, 'r')
110 p
.setoutrate(af
.getframerate())
111 p
.setsampwidth(af
.getsampwidth())
112 p
.setnchannels(af
.getnchannels())
115 data
= af
.readframes(BUFSIZ
)
118 print 'wrote', len(data
), 'space', p
.getfillable()
121 if __name__
== '__main__':