[Python-checkins] bpo-30077: Add support for Apple aifc/sowt pseudo-compression (GH-24449)
ambv
webhook-mailer at python.org
Fri Aug 13 07:31:29 EDT 2021
https://github.com/python/cpython/commit/e4ed9d21534c2ed4397fdee0bb530a6e6a2c5af8
commit: e4ed9d21534c2ed4397fdee0bb530a6e6a2c5af8
branch: main
author: dnknth <41536869+dnknth at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2021-08-13T13:31:25+02:00
summary:
bpo-30077: Add support for Apple aifc/sowt pseudo-compression (GH-24449)
Co-authored-by: Toby Thurston <thurston at eml.cc>
files:
A Misc/NEWS.d/next/Library/2021-02-04-23-16-03.bpo-30077.v6TqAi.rst
M Lib/aifc.py
diff --git a/Lib/aifc.py b/Lib/aifc.py
index ed5da7d8936fd..d50f258e1acf8 100644
--- a/Lib/aifc.py
+++ b/Lib/aifc.py
@@ -462,6 +462,10 @@ def _adpcm2lin(self, data):
data, self._adpcmstate = audioop.adpcm2lin(data, 2, self._adpcmstate)
return data
+ def _sowt2lin(self, data):
+ import audioop
+ return audioop.byteswap(data, 2)
+
def _read_comm_chunk(self, chunk):
self._nchannels = _read_short(chunk)
self._nframes = _read_long(chunk)
@@ -497,6 +501,8 @@ def _read_comm_chunk(self, chunk):
self._convert = self._ulaw2lin
elif self._comptype in (b'alaw', b'ALAW'):
self._convert = self._alaw2lin
+ elif self._comptype in (b'sowt', b'SOWT'):
+ self._convert = self._sowt2lin
else:
raise Error('unsupported compression type')
self._sampwidth = 2
@@ -659,7 +665,7 @@ def setcomptype(self, comptype, compname):
if self._nframeswritten:
raise Error('cannot change parameters after starting to write')
if comptype not in (b'NONE', b'ulaw', b'ULAW',
- b'alaw', b'ALAW', b'G722'):
+ b'alaw', b'ALAW', b'G722', b'sowt', b'SOWT'):
raise Error('unsupported compression type')
self._comptype = comptype
self._compname = compname
@@ -680,7 +686,7 @@ def setparams(self, params):
if self._nframeswritten:
raise Error('cannot change parameters after starting to write')
if comptype not in (b'NONE', b'ulaw', b'ULAW',
- b'alaw', b'ALAW', b'G722'):
+ b'alaw', b'ALAW', b'G722', b'sowt', b'SOWT'):
raise Error('unsupported compression type')
self.setnchannels(nchannels)
self.setsampwidth(sampwidth)
@@ -778,14 +784,21 @@ def _lin2adpcm(self, data):
data, self._adpcmstate = audioop.lin2adpcm(data, 2, self._adpcmstate)
return data
+ def _lin2sowt(self, data):
+ import audioop
+ return audioop.byteswap(data, 2)
+
def _ensure_header_written(self, datasize):
if not self._nframeswritten:
- if self._comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'):
+ if self._comptype in (b'ULAW', b'ulaw',
+ b'ALAW', b'alaw', b'G722',
+ b'sowt', b'SOWT'):
if not self._sampwidth:
self._sampwidth = 2
if self._sampwidth != 2:
raise Error('sample width must be 2 when compressing '
- 'with ulaw/ULAW, alaw/ALAW or G7.22 (ADPCM)')
+ 'with ulaw/ULAW, alaw/ALAW, sowt/SOWT '
+ 'or G7.22 (ADPCM)')
if not self._nchannels:
raise Error('# channels not specified')
if not self._sampwidth:
@@ -801,6 +814,8 @@ def _init_compression(self):
self._convert = self._lin2ulaw
elif self._comptype in (b'alaw', b'ALAW'):
self._convert = self._lin2alaw
+ elif self._comptype in (b'sowt', b'SOWT'):
+ self._convert = self._lin2sowt
def _write_header(self, initlength):
if self._aifc and self._comptype != b'NONE':
diff --git a/Misc/NEWS.d/next/Library/2021-02-04-23-16-03.bpo-30077.v6TqAi.rst b/Misc/NEWS.d/next/Library/2021-02-04-23-16-03.bpo-30077.v6TqAi.rst
new file mode 100644
index 0000000000000..4af17eed8f733
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-02-04-23-16-03.bpo-30077.v6TqAi.rst
@@ -0,0 +1 @@
+Added support for Apple's aifc/sowt pseudo-compression
\ No newline at end of file
More information about the Python-checkins
mailing list