slated for removal in Python 3.13:
* :mod:`aifc`
+ * :mod:`audioop`
(Contributed by Brett Cannon in :issue:`47061`.)
#
def _alaw2lin(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
return audioop.alaw2lin(data, 2)
def _ulaw2lin(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
return audioop.ulaw2lin(data, 2)
def _adpcm2lin(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
if not hasattr(self, '_adpcmstate'):
# first time
self._adpcmstate = None
return data
def _sowt2lin(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
return audioop.byteswap(data, 2)
def _read_comm_chunk(self, chunk):
#
def _lin2alaw(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
return audioop.lin2alaw(data, 2)
def _lin2ulaw(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
return audioop.lin2ulaw(data, 2)
def _lin2adpcm(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
if not hasattr(self, '_adpcmstate'):
self._adpcmstate = None
data, self._adpcmstate = audioop.lin2adpcm(data, 2, self._adpcmstate)
return data
def _lin2sowt(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
return audioop.byteswap(data, 2)
def _ensure_header_written(self, datasize):
"""
from collections import namedtuple
+import warnings
_sunau_params = namedtuple('_sunau_params',
data = self._file.read(nframes * self._framesize)
self._soundpos += len(data) // self._framesize
if self._encoding == AUDIO_FILE_ENCODING_MULAW_8:
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
data = audioop.ulaw2lin(data, self._sampwidth)
return data
return None # XXX--not implemented yet
data = memoryview(data).cast('B')
self._ensure_header_written()
if self._comptype == 'ULAW':
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
data = audioop.lin2ulaw(data, self._sampwidth)
nframes = len(data) // self._framesize
self._file.write(data)
import unittest
from unittest import mock
from test import audiotests
-from audioop import byteswap
import io
import sys
import struct
aifc = import_deprecated("aifc")
+audioop = import_deprecated("audioop")
class AifcTest(audiotests.AudioWriteTests,
E5040CBC 617C0A3C 08BC0A3C 2C7C0B3C 517C0E3C 8A8410FC B6840EBC 457C0A3C \
""")
if sys.byteorder != 'big':
- frames = byteswap(frames, 2)
+ frames = audioop.byteswap(frames, 2)
class AifcALAWTest(AifcTest, unittest.TestCase):
E4800CC0 62000A40 08C00A40 2B000B40 52000E40 8A001180 B6000EC0 46000A40 \
""")
if sys.byteorder != 'big':
- frames = byteswap(frames, 2)
+ frames = audioop.byteswap(frames, 2)
class AifcMiscTest(unittest.TestCase):
-import audioop
import sys
+from test.support import warnings_helper
import unittest
+audioop = warnings_helper.import_deprecated("audioop")
+
+
def pack(width, data):
return b''.join(v.to_bytes(width, sys.byteorder, signed=True) for v in data)
from test import support
-from test.support import import_helper
+from test.support import import_helper, warnings_helper
support.requires('audio')
from test.support import findfile
ossaudiodev = import_helper.import_module('ossaudiodev')
+audioop = warnings_helper.import_deprecated('audioop')
import errno
import sys
import sunau
import time
-import audioop
import unittest
# Arggh, AFMT_S16_NE not defined on all platforms -- seems to be a
cm = self.checkModule
# These were once some of the longest modules.
- cm('aifc', ignore=('_aifc_params',)) # set with = in module
cm('random', ignore=('Random',)) # from _random import Random as CoreGenerator
cm('cgi', ignore=('log',)) # set with = in module
cm('pickle', ignore=('partial', 'PickleBuffer'))
import unittest
from test import audiotests
-from audioop import byteswap
import io
import struct
import sys
import sunau
+from test.support import warnings_helper
+
+audioop = warnings_helper.import_deprecated("audioop")
class SunauTest(audiotests.AudioWriteTests,
E5040CBC 617C0A3C 08BC0A3C 2C7C0B3C 517C0E3C 8A8410FC B6840EBC 457C0A3C \
""")
if sys.byteorder != 'big':
- frames = byteswap(frames, 2)
+ frames = audioop.byteswap(frames, 2)
class SunauLowLevelTest(unittest.TestCase):
import unittest
from test import audiotests
from test import support
-from audioop import byteswap
import io
import struct
import sys
E4B50CEB 63440A5A 08CA0A1F 2BBA0B0B 51460E47 8BCB113C B6F50EEA 44150A59 \
""")
if sys.byteorder != 'big':
- frames = byteswap(frames, 2)
+ frames = wave._byteswap(frames, 2)
class WavePCM24Test(WaveTest, unittest.TestCase):
51486F0E44E1 8BCC64113B05 B6F4EC0EEB36 4413170A5B48 \
""")
if sys.byteorder != 'big':
- frames = byteswap(frames, 3)
+ frames = wave._byteswap(frames, 3)
class WavePCM32Test(WaveTest, unittest.TestCase):
51486F800E44E190 8BCC6480113B0580 B6F4EC000EEB3630 441317800A5B48A0 \
""")
if sys.byteorder != 'big':
- frames = byteswap(frames, 4)
+ frames = wave._byteswap(frames, 4)
class MiscTestCase(unittest.TestCase):
from chunk import Chunk
from collections import namedtuple
-import audioop
import builtins
import struct
import sys
_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:
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)
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
--- /dev/null
+Deprecate audioop.
PyMODINIT_FUNC
PyInit_audioop(void)
{
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "'audioop' is deprecated and slated for removal in "
+ "Python 3.13",
+ 7)) {
+ return NULL;
+ }
+
return PyModuleDef_Init(&audioopmodule);
}