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

Skip to content

Commit 4ae423d

Browse files
Issue #19131: The aifc module now correctly reads and writes sampwidth of
compressed streams.
2 parents 34808e2 + 4b53259 commit 4ae423d

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

Lib/aifc.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,13 @@ def _read_comm_chunk(self, chunk):
468468
if self._comptype != b'NONE':
469469
if self._comptype == b'G722':
470470
self._convert = self._adpcm2lin
471-
self._framesize = self._framesize // 4
472471
elif self._comptype in (b'ulaw', b'ULAW'):
473472
self._convert = self._ulaw2lin
474-
self._framesize = self._framesize // 2
475473
elif self._comptype in (b'alaw', b'ALAW'):
476474
self._convert = self._alaw2lin
477-
self._framesize = self._framesize // 2
478475
else:
479476
raise Error('unsupported compression type')
477+
self._sampwidth = 2
480478
else:
481479
self._comptype = b'NONE'
482480
self._compname = b'not compressed'
@@ -804,7 +802,10 @@ def _write_header(self, initlength):
804802
_write_short(self._file, self._nchannels)
805803
self._nframes_pos = self._file.tell()
806804
_write_ulong(self._file, self._nframes)
807-
_write_short(self._file, self._sampwidth * 8)
805+
if self._comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'):
806+
_write_short(self._file, 8)
807+
else:
808+
_write_short(self._file, self._sampwidth * 8)
808809
_write_float(self._file, self._framerate)
809810
if self._aifc:
810811
self._file.write(self._comptype)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ Core and Builtins
3636
Library
3737
-------
3838

39+
- Issue #19131: The aifc module now correctly reads and writes sampwidth of
40+
compressed streams.
41+
3942
- Issue #19209: Remove import of copyreg from the os module to speed up
4043
interpreter startup. stat_result and statvfs_result are now hard-coded to
4144
reside in the os module.

0 commit comments

Comments
 (0)