summaryrefslogtreecommitdiffstats
path: root/Lib/wave.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2022-04-07 19:27:35 (GMT)
committerGitHub <noreply@github.com>2022-04-07 19:27:35 (GMT)
commit87eec70d97b250f820325b4f1b4f781b443b5180 (patch)
treef8e20384e332b2c5743c134d87a82070cee87ff7 /Lib/wave.py
parent1df4298b62fcc124ba9de861f8dc8239ad72cde2 (diff)
downloadcpython-87eec70d97b250f820325b4f1b4f781b443b5180.zip
cpython-87eec70d97b250f820325b4f1b4f781b443b5180.tar.gz
cpython-87eec70d97b250f820325b4f1b4f781b443b5180.tar.bz2
Deprecate audioop (GH-32392)
Diffstat (limited to 'Lib/wave.py')
-rw-r--r--Lib/wave.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/wave.py b/Lib/wave.py
index b707119..47a233d 100644
--- a/Lib/wave.py
+++ b/Lib/wave.py
@@ -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