]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
audiodev.py: Mac port.
authorGuido van Rossum <guido@python.org>
Fri, 16 Sep 1994 10:55:53 +0000 (10:55 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 16 Sep 1994 10:55:53 +0000 (10:55 +0000)
Audio_mac.py: Mac specific class for audiodev.py.
aifc.py: open files for reading/writing in binary mode ('rb', 'wb').

Lib/aifc.py
Lib/audiodev.py

index a9e6f85006fac2d89921352489f9e1291d93d383..22bff01916d4ee5a1d6f9c337a9e65d2d4656761 100644 (file)
@@ -413,7 +413,7 @@ class Aifc_read:
 
        def __init__(self, f):
                if type(f) == type(''):
-                       f = __builtin__.open(f, 'r')
+                       f = __builtin__.open(f, 'rb')
                # else, assume it is an open file object already
                self.initfp(f)
 
@@ -638,7 +638,7 @@ class Aifc_write:
        def __init__(self, f):
                if type(f) == type(''):
                        filename = f
-                       f = __builtin__.open(f, 'w')
+                       f = __builtin__.open(f, 'wb')
                else:
                        # else, assume it is an open file object already
                        filename = '???'
index 02d63f772473a533c7554613cbcd491c8f6f5879..adfeb96a551342cd29dc52885e26592016ce86f1 100644 (file)
@@ -215,4 +215,27 @@ def AudioDev():
                        import sunaudiodev
                        return Play_Audio_sun()
                except ImportError:
-                       raise error, 'no audio device'
+                       try:
+                               import Audio_mac
+                               return Audio_mac.Play_Audio_mac()
+                       except ImportError:
+                               raise error, 'no audio device'
+
+def test(fn = 'f:just samples:just.aif'):
+       import aifc
+       af = aifc.open(fn, 'r')
+       print fn, af.getparams()
+       p = AudioDev()
+       p.setoutrate(af.getframerate())
+       p.setsampwidth(af.getsampwidth())
+       p.setnchannels(af.getnchannels())
+       BUFSIZ = af.getframerate()/af.getsampwidth()/af.getnchannels()
+       while 1:
+               data = af.readframes(BUFSIZ)
+               if not data: break
+               print len(data)
+               p.writeframes(data)
+       p.wait()
+
+if __name__ == '__main__':
+       test()