Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e174c15

Browse files
committed
audiodev.py: Mac port.
Audio_mac.py: Mac specific class for audiodev.py. aifc.py: open files for reading/writing in binary mode ('rb', 'wb').
1 parent 2d16703 commit e174c15

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

Lib/aifc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def initfp(self, file):
413413

414414
def __init__(self, f):
415415
if type(f) == type(''):
416-
f = __builtin__.open(f, 'r')
416+
f = __builtin__.open(f, 'rb')
417417
# else, assume it is an open file object already
418418
self.initfp(f)
419419

@@ -638,7 +638,7 @@ class Aifc_write:
638638
def __init__(self, f):
639639
if type(f) == type(''):
640640
filename = f
641-
f = __builtin__.open(f, 'w')
641+
f = __builtin__.open(f, 'wb')
642642
else:
643643
# else, assume it is an open file object already
644644
filename = '???'

Lib/audiodev.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,27 @@ def AudioDev():
215215
import sunaudiodev
216216
return Play_Audio_sun()
217217
except ImportError:
218-
raise error, 'no audio device'
218+
try:
219+
import Audio_mac
220+
return Audio_mac.Play_Audio_mac()
221+
except ImportError:
222+
raise error, 'no audio device'
223+
224+
def test(fn = 'f:just samples:just.aif'):
225+
import aifc
226+
af = aifc.open(fn, 'r')
227+
print fn, af.getparams()
228+
p = AudioDev()
229+
p.setoutrate(af.getframerate())
230+
p.setsampwidth(af.getsampwidth())
231+
p.setnchannels(af.getnchannels())
232+
BUFSIZ = af.getframerate()/af.getsampwidth()/af.getnchannels()
233+
while 1:
234+
data = af.readframes(BUFSIZ)
235+
if not data: break
236+
print len(data)
237+
p.writeframes(data)
238+
p.wait()
239+
240+
if __name__ == '__main__':
241+
test()

0 commit comments

Comments
 (0)