Skip to content

Commit 4b53259

Browse files
Issue #19131: The aifc module now correctly reads and writes sampwidth of
compressed streams.
1 parent 8aa7b89 commit 4b53259

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Lib/aifc.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,13 @@ def _read_comm_chunk(self, chunk):
457457
if self._comptype != b'NONE':
458458
if self._comptype == b'G722':
459459
self._convert = self._adpcm2lin
460-
self._framesize = self._framesize // 4
461460
elif self._comptype in (b'ulaw', b'ULAW'):
462461
self._convert = self._ulaw2lin
463-
self._framesize = self._framesize // 2
464462
elif self._comptype in (b'alaw', b'ALAW'):
465463
self._convert = self._alaw2lin
466-
self._framesize = self._framesize // 2
467464
else:
468465
raise Error('unsupported compression type')
466+
self._sampwidth = 2
469467
else:
470468
self._comptype = b'NONE'
471469
self._compname = b'not compressed'
@@ -787,7 +785,10 @@ def _write_header(self, initlength):
787785
_write_short(self._file, self._nchannels)
788786
self._nframes_pos = self._file.tell()
789787
_write_ulong(self._file, self._nframes)
790-
_write_short(self._file, self._sampwidth * 8)
788+
if self._comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'):
789+
_write_short(self._file, 8)
790+
else:
791+
_write_short(self._file, self._sampwidth * 8)
791792
_write_float(self._file, self._framerate)
792793
if self._aifc:
793794
self._file.write(self._comptype)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ Core and Builtins
7676
Library
7777
-------
7878

79+
- Issue #19131: The aifc module now correctly reads and writes sampwidth of
80+
compressed streams.
81+
7982
- Issue #19158: a rare race in BoundedSemaphore could allow .release() too
8083
often.
8184

0 commit comments

Comments
 (0)