diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-11-23 20:26:01 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-11-23 20:26:01 (GMT) |
commit | 3062c9a6c87ff9b480d1eea960efbfc604e4b157 (patch) | |
tree | b31b2fe4839d47d9ca54f171d6adf518cfbffa9d /Modules/audioop.c | |
parent | 2b38fc187c2a764b7608cd262de5a2777a77f4c8 (diff) | |
download | cpython-3062c9a6c87ff9b480d1eea960efbfc604e4b157.zip cpython-3062c9a6c87ff9b480d1eea960efbfc604e4b157.tar.gz cpython-3062c9a6c87ff9b480d1eea960efbfc604e4b157.tar.bz2 |
Issue #19641: Added the audioop.byteswap() function to convert big-endian
samples to little-endian and vice versa.
Diffstat (limited to 'Modules/audioop.c')
-rw-r--r-- | Modules/audioop.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Modules/audioop.c b/Modules/audioop.c index 5c83a7d..ae3ff06 100644 --- a/Modules/audioop.c +++ b/Modules/audioop.c @@ -1108,6 +1108,37 @@ audioop_reverse(PyObject *self, PyObject *args) } static PyObject * +audioop_byteswap(PyObject *self, PyObject *args) +{ + Py_buffer view; + unsigned char *ncp; + Py_ssize_t i; + int size; + PyObject *rv = NULL; + + if (!PyArg_ParseTuple(args, "y*i:swapbytes", + &view, &size)) + return NULL; + + if (!audioop_check_parameters(view.len, size)) + goto exit; + + rv = PyBytes_FromStringAndSize(NULL, view.len); + if (rv == NULL) + goto exit; + ncp = (unsigned char *)PyBytes_AsString(rv); + + for (i = 0; i < view.len; i += size) { + int j; + for (j = 0; j < size; j++) + ncp[i + size - 1 - j] = ((unsigned char *)view.buf)[i + j]; + } + exit: + PyBuffer_Release(&view); + return rv; +} + +static PyObject * audioop_lin2lin(PyObject *self, PyObject *args) { Py_buffer view; @@ -1698,6 +1729,7 @@ static PyMethodDef audioop_methods[] = { { "tostereo", audioop_tostereo, METH_VARARGS }, { "getsample", audioop_getsample, METH_VARARGS }, { "reverse", audioop_reverse, METH_VARARGS }, + { "byteswap", audioop_byteswap, METH_VARARGS }, { "ratecv", audioop_ratecv, METH_VARARGS }, { 0, 0 } }; |