2 error
='Audio_mac.error'
4 from warnings
import warnpy3k
5 warnpy3k("In 3.x, the Play_Audio_mac module is removed.", stacklevel
=2)
9 def __init__(self
, qsize
=QSIZE
):
16 self
._usercallback
= None
20 self
._usercallback
= None
24 while self
.getfilled():
29 def stop(self
, quietNow
= 1):
32 ##chan.SndDisposeChannel(1)
35 def setoutrate(self
, outrate
):
36 self
._outrate
= outrate
38 def setsampwidth(self
, sampwidth
):
39 self
._sampwidth
= sampwidth
41 def setnchannels(self
, nchannels
):
42 self
._nchannels
= nchannels
44 def writeframes(self
, data
):
46 from Carbon
.Sound
import bufferCmd
, callBackCmd
, extSH
50 from Carbon
import Snd
51 self
._chan
= Snd
.SndNewChannel(5, 0, self
._callback
)
52 nframes
= len(data
) / self
._nchannels
/ self
._sampwidth
53 if len(data
) != nframes
* self
._nchannels
* self
._sampwidth
:
54 raise error
, 'data is not a whole number of frames'
56 self
.getfilled() + nframes
> \
57 self
._qsize
/ self
._nchannels
/ self
._sampwidth
:
59 if self
._sampwidth
== 1:
61 data
= audioop
.add(data
, '\x80'*len(data
), 1)
62 h1
= struct
.pack('llHhllbbl',
63 id(data
)+MacOS
.string_id_to_buffer
,
72 h3
= struct
.pack('hhlll',
79 self
._gc
.append((header
, data
))
80 self
._chan
.SndDoCommand((bufferCmd
, 0, header
), 0)
81 self
._chan
.SndDoCommand((callBackCmd
, 0, 0), 0)
83 def _callback(self
, *args
):
85 if self
._usercallback
:
88 def setcallback(self
, callback
):
89 self
._usercallback
= callback
93 for header
, data
in self
._gc
:
94 filled
= filled
+ len(data
)
95 return filled
/ self
._nchannels
/ self
._sampwidth
97 def getfillable(self
):
98 return (self
._qsize
/ self
._nchannels
/ self
._sampwidth
) - self
.getfilled()
100 def ulaw2lin(self
, data
):
102 return audioop
.ulaw2lin(data
, 2)
107 fn
= EasyDialogs
.AskFileForOpen(message
="Select an AIFF soundfile", typeList
=("AIFF",))
109 af
= aifc
.open(fn
, 'r')
112 p
.setoutrate(af
.getframerate())
113 p
.setsampwidth(af
.getsampwidth())
114 p
.setnchannels(af
.getnchannels())
117 data
= af
.readframes(BUFSIZ
)
120 print 'wrote', len(data
), 'space', p
.getfillable()
123 if __name__
== '__main__':