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
):
47 self
._chan
= Snd
.SndNewChannel(5, 0, self
._callback
)
48 nframes
= len(data
) / self
._nchannels
/ self
._sampwidth
49 if len(data
) != nframes
* self
._nchannels
* self
._sampwidth
:
50 raise error
, 'data is not a whole number of frames'
52 self
.getfilled() + nframes
> \
53 self
._qsize
/ self
._nchannels
/ self
._sampwidth
:
55 if self
._sampwidth
== 1:
57 data
= audioop
.add(data
, '\x80'*len(data
), 1)
58 h1
= struct
.pack('llhhllbbl',
68 h3
= struct
.pack('hhlll',
75 self
._gc
.append((header
, data
))
76 self
._chan
.SndDoCommand((bufferCmd
, 0, header
), 0)
77 self
._chan
.SndDoCommand((callBackCmd
, 0, 0), 0)
79 def _callback(self
, *args
):
81 if self
._usercallback
:
84 def setcallback(self
, callback
):
85 self
._usercallback
= callback
89 for header
, data
in self
._gc
:
90 filled
= filled
+ len(data
)
91 return filled
/ self
._nchannels
/ self
._sampwidth
93 def getfillable(self
):
94 return (self
._qsize
/ self
._nchannels
/ self
._sampwidth
) - self
.getfilled()
96 def ulaw2lin(self
, data
):
98 return audioop
.ulaw2lin(data
, 2)
103 fss
, ok
= macfs
.PromptGetFile("Select an AIFF soundfile", "AIFF")
105 fn
= fss
.as_pathname()
106 af
= aifc
.open(fn
, 'r')
109 p
.setoutrate(af
.getframerate())
110 p
.setsampwidth(af
.getsampwidth())
111 p
.setnchannels(af
.getnchannels())
114 data
= af
.readframes(BUFSIZ
)
117 print 'wrote', len(data
), 'space', p
.getfillable()
120 if __name__
== '__main__':