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

Skip to content

Commit e4ed9d2

Browse files
dnknththruston
andauthored
bpo-30077: Add support for Apple aifc/sowt pseudo-compression (GH-24449)
Co-authored-by: Toby Thurston <[email protected]>
1 parent e43b9bb commit e4ed9d2

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

Lib/aifc.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ def _adpcm2lin(self, data):
462462
data, self._adpcmstate = audioop.adpcm2lin(data, 2, self._adpcmstate)
463463
return data
464464

465+
def _sowt2lin(self, data):
466+
import audioop
467+
return audioop.byteswap(data, 2)
468+
465469
def _read_comm_chunk(self, chunk):
466470
self._nchannels = _read_short(chunk)
467471
self._nframes = _read_long(chunk)
@@ -497,6 +501,8 @@ def _read_comm_chunk(self, chunk):
497501
self._convert = self._ulaw2lin
498502
elif self._comptype in (b'alaw', b'ALAW'):
499503
self._convert = self._alaw2lin
504+
elif self._comptype in (b'sowt', b'SOWT'):
505+
self._convert = self._sowt2lin
500506
else:
501507
raise Error('unsupported compression type')
502508
self._sampwidth = 2
@@ -659,7 +665,7 @@ def setcomptype(self, comptype, compname):
659665
if self._nframeswritten:
660666
raise Error('cannot change parameters after starting to write')
661667
if comptype not in (b'NONE', b'ulaw', b'ULAW',
662-
b'alaw', b'ALAW', b'G722'):
668+
b'alaw', b'ALAW', b'G722', b'sowt', b'SOWT'):
663669
raise Error('unsupported compression type')
664670
self._comptype = comptype
665671
self._compname = compname
@@ -680,7 +686,7 @@ def setparams(self, params):
680686
if self._nframeswritten:
681687
raise Error('cannot change parameters after starting to write')
682688
if comptype not in (b'NONE', b'ulaw', b'ULAW',
683-
b'alaw', b'ALAW', b'G722'):
689+
b'alaw', b'ALAW', b'G722', b'sowt', b'SOWT'):
684690
raise Error('unsupported compression type')
685691
self.setnchannels(nchannels)
686692
self.setsampwidth(sampwidth)
@@ -778,14 +784,21 @@ def _lin2adpcm(self, data):
778784
data, self._adpcmstate = audioop.lin2adpcm(data, 2, self._adpcmstate)
779785
return data
780786

787+
def _lin2sowt(self, data):
788+
import audioop
789+
return audioop.byteswap(data, 2)
790+
781791
def _ensure_header_written(self, datasize):
782792
if not self._nframeswritten:
783-
if self._comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'):
793+
if self._comptype in (b'ULAW', b'ulaw',
794+
b'ALAW', b'alaw', b'G722',
795+
b'sowt', b'SOWT'):
784796
if not self._sampwidth:
785797
self._sampwidth = 2
786798
if self._sampwidth != 2:
787799
raise Error('sample width must be 2 when compressing '
788-
'with ulaw/ULAW, alaw/ALAW or G7.22 (ADPCM)')
800+
'with ulaw/ULAW, alaw/ALAW, sowt/SOWT '
801+
'or G7.22 (ADPCM)')
789802
if not self._nchannels:
790803
raise Error('# channels not specified')
791804
if not self._sampwidth:
@@ -801,6 +814,8 @@ def _init_compression(self):
801814
self._convert = self._lin2ulaw
802815
elif self._comptype in (b'alaw', b'ALAW'):
803816
self._convert = self._lin2alaw
817+
elif self._comptype in (b'sowt', b'SOWT'):
818+
self._convert = self._lin2sowt
804819

805820
def _write_header(self, initlength):
806821
if self._aifc and self._comptype != b'NONE':
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added support for Apple's aifc/sowt pseudo-compression

0 commit comments

Comments
 (0)