]> granicus.if.org Git - python/commitdiff
Issue #19131: The aifc module now correctly reads and writes sampwidth of
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 12 Oct 2013 15:21:12 +0000 (18:21 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 12 Oct 2013 15:21:12 +0000 (18:21 +0300)
compressed streams.

Lib/aifc.py
Misc/NEWS

index 12c665fa8c1ff353afad3f3b93e0d2e1cefb5d61..f4c196c4f6b62024daa2a100d544097d11086fe6 100644 (file)
@@ -480,7 +480,7 @@ class Aifc_read:
                         pass
                     else:
                         self._convert = self._adpcm2lin
-                        self._framesize = self._framesize // 4
+                        self._sampwidth = 2
                         return
                 # for ULAW and ALAW try Compression Library
                 try:
@@ -490,21 +490,20 @@ class Aifc_read:
                         try:
                             import audioop
                             self._convert = self._ulaw2lin
-                            self._framesize = self._framesize // 2
+                            self._sampwidth = 2
                             return
                         except ImportError:
                             pass
                     raise Error, 'cannot read compressed AIFF-C files'
                 if self._comptype == 'ULAW':
                     scheme = cl.G711_ULAW
-                    self._framesize = self._framesize // 2
                 elif self._comptype == 'ALAW':
                     scheme = cl.G711_ALAW
-                    self._framesize = self._framesize // 2
                 else:
                     raise Error, 'unsupported compression type'
                 self._decomp = cl.OpenDecompressor(scheme)
                 self._convert = self._decomp_data
+                self._sampwidth = 2
         else:
             self._comptype = 'NONE'
             self._compname = 'not compressed'
@@ -867,7 +866,10 @@ class Aifc_write:
         _write_short(self._file, self._nchannels)
         self._nframes_pos = self._file.tell()
         _write_ulong(self._file, self._nframes)
-        _write_short(self._file, self._sampwidth * 8)
+        if self._comptype in ('ULAW', 'ALAW', 'G722'):
+            _write_short(self._file, 8)
+        else:
+            _write_short(self._file, self._sampwidth * 8)
         _write_float(self._file, self._framerate)
         if self._aifc:
             self._file.write(self._comptype)
index 144e80176ed294ea44bbb3d4e55628e419e43bea..d23f7ccca37c04eae217248ddea029a30639009e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -32,6 +32,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #19131: The aifc module now correctly reads and writes sampwidth of
+  compressed streams.
+
 - Issue #19158:  a rare race in BoundedSemaphore could allow .release() too
   often.