Deprecate audioop (GH-32392)

This commit is contained in:
Brett Cannon 2022-04-07 12:27:35 -07:00 committed by GitHub
parent 1df4298b62
commit 87eec70d97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 68 additions and 26 deletions

View file

@ -73,7 +73,6 @@ is destroyed.
from chunk import Chunk
from collections import namedtuple
import audioop
import builtins
import struct
import sys
@ -91,6 +90,16 @@ _array_fmts = None, 'b', 'h', None, 'i'
_wave_params = namedtuple('_wave_params',
'nchannels sampwidth framerate nframes comptype compname')
def _byteswap(data, width):
swapped_data = bytearray(len(data))
for i in range(0, len(data), width):
for j in range(width):
swapped_data[i + width - 1 - j] = data[i + j]
return bytes(swapped_data)
class Wave_read:
"""Variables used in this class:
@ -241,7 +250,7 @@ class Wave_read:
return b''
data = self._data_chunk.read(nframes * self._framesize)
if self._sampwidth != 1 and sys.byteorder == 'big':
data = audioop.byteswap(data, self._sampwidth)
data = _byteswap(data, self._sampwidth)
if self._convert and data:
data = self._convert(data)
self._soundpos = self._soundpos + len(data) // (self._nchannels * self._sampwidth)
@ -428,7 +437,7 @@ class Wave_write:
if self._convert:
data = self._convert(data)
if self._sampwidth != 1 and sys.byteorder == 'big':
data = audioop.byteswap(data, self._sampwidth)
data = _byteswap(data, self._sampwidth)
self._file.write(data)
self._datawritten += len(data)
self._nframeswritten = self._nframeswritten + nframes