Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(audioop_getsample__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 6 | "getsample($module, fragment, width, index, /)\n" |
| 7 | "--\n" |
| 8 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 9 | "Return the value of sample index from the fragment."); |
| 10 | |
| 11 | #define AUDIOOP_GETSAMPLE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 12 | {"getsample", (PyCFunction)(void(*)(void))audioop_getsample, METH_FASTCALL, audioop_getsample__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 13 | |
| 14 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 15 | audioop_getsample_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 16 | Py_ssize_t index); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 17 | |
| 18 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 19 | audioop_getsample(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 20 | { |
| 21 | PyObject *return_value = NULL; |
| 22 | Py_buffer fragment = {NULL, NULL}; |
| 23 | int width; |
| 24 | Py_ssize_t index; |
| 25 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 26 | if (!_PyArg_CheckPositional("getsample", nargs, 3, 3)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 27 | goto exit; |
| 28 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 29 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 30 | goto exit; |
| 31 | } |
| 32 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 33 | _PyArg_BadArgument("getsample", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 34 | goto exit; |
| 35 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 36 | width = _PyLong_AsInt(args[1]); |
| 37 | if (width == -1 && PyErr_Occurred()) { |
| 38 | goto exit; |
| 39 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 40 | { |
| 41 | Py_ssize_t ival = -1; |
Serhiy Storchaka | 5f4b229d | 2020-05-28 10:33:45 +0300 | [diff] [blame] | 42 | PyObject *iobj = _PyNumber_Index(args[2]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 43 | if (iobj != NULL) { |
| 44 | ival = PyLong_AsSsize_t(iobj); |
| 45 | Py_DECREF(iobj); |
| 46 | } |
| 47 | if (ival == -1 && PyErr_Occurred()) { |
| 48 | goto exit; |
| 49 | } |
| 50 | index = ival; |
| 51 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 52 | return_value = audioop_getsample_impl(module, &fragment, width, index); |
| 53 | |
| 54 | exit: |
| 55 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 56 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 57 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 58 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 59 | |
| 60 | return return_value; |
| 61 | } |
| 62 | |
| 63 | PyDoc_STRVAR(audioop_max__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 64 | "max($module, fragment, width, /)\n" |
| 65 | "--\n" |
| 66 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 67 | "Return the maximum of the absolute value of all samples in a fragment."); |
| 68 | |
| 69 | #define AUDIOOP_MAX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 70 | {"max", (PyCFunction)(void(*)(void))audioop_max, METH_FASTCALL, audioop_max__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 71 | |
| 72 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 73 | audioop_max_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 74 | |
| 75 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 76 | audioop_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 77 | { |
| 78 | PyObject *return_value = NULL; |
| 79 | Py_buffer fragment = {NULL, NULL}; |
| 80 | int width; |
| 81 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 82 | if (!_PyArg_CheckPositional("max", nargs, 2, 2)) { |
| 83 | goto exit; |
| 84 | } |
| 85 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 86 | goto exit; |
| 87 | } |
| 88 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 89 | _PyArg_BadArgument("max", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 90 | goto exit; |
| 91 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 92 | width = _PyLong_AsInt(args[1]); |
| 93 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 94 | goto exit; |
| 95 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 96 | return_value = audioop_max_impl(module, &fragment, width); |
| 97 | |
| 98 | exit: |
| 99 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 100 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 101 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 102 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 103 | |
| 104 | return return_value; |
| 105 | } |
| 106 | |
| 107 | PyDoc_STRVAR(audioop_minmax__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 108 | "minmax($module, fragment, width, /)\n" |
| 109 | "--\n" |
| 110 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 111 | "Return the minimum and maximum values of all samples in the sound fragment."); |
| 112 | |
| 113 | #define AUDIOOP_MINMAX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 114 | {"minmax", (PyCFunction)(void(*)(void))audioop_minmax, METH_FASTCALL, audioop_minmax__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 115 | |
| 116 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 117 | audioop_minmax_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 118 | |
| 119 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 120 | audioop_minmax(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 121 | { |
| 122 | PyObject *return_value = NULL; |
| 123 | Py_buffer fragment = {NULL, NULL}; |
| 124 | int width; |
| 125 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 126 | if (!_PyArg_CheckPositional("minmax", nargs, 2, 2)) { |
| 127 | goto exit; |
| 128 | } |
| 129 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 130 | goto exit; |
| 131 | } |
| 132 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 133 | _PyArg_BadArgument("minmax", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 134 | goto exit; |
| 135 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 136 | width = _PyLong_AsInt(args[1]); |
| 137 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 138 | goto exit; |
| 139 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 140 | return_value = audioop_minmax_impl(module, &fragment, width); |
| 141 | |
| 142 | exit: |
| 143 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 144 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 145 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 146 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 147 | |
| 148 | return return_value; |
| 149 | } |
| 150 | |
| 151 | PyDoc_STRVAR(audioop_avg__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 152 | "avg($module, fragment, width, /)\n" |
| 153 | "--\n" |
| 154 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 155 | "Return the average over all samples in the fragment."); |
| 156 | |
| 157 | #define AUDIOOP_AVG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 158 | {"avg", (PyCFunction)(void(*)(void))audioop_avg, METH_FASTCALL, audioop_avg__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 159 | |
| 160 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 161 | audioop_avg_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 162 | |
| 163 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 164 | audioop_avg(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 165 | { |
| 166 | PyObject *return_value = NULL; |
| 167 | Py_buffer fragment = {NULL, NULL}; |
| 168 | int width; |
| 169 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 170 | if (!_PyArg_CheckPositional("avg", nargs, 2, 2)) { |
| 171 | goto exit; |
| 172 | } |
| 173 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 174 | goto exit; |
| 175 | } |
| 176 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 177 | _PyArg_BadArgument("avg", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 178 | goto exit; |
| 179 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 180 | width = _PyLong_AsInt(args[1]); |
| 181 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 182 | goto exit; |
| 183 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 184 | return_value = audioop_avg_impl(module, &fragment, width); |
| 185 | |
| 186 | exit: |
| 187 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 188 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 189 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 190 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 191 | |
| 192 | return return_value; |
| 193 | } |
| 194 | |
| 195 | PyDoc_STRVAR(audioop_rms__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 196 | "rms($module, fragment, width, /)\n" |
| 197 | "--\n" |
| 198 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 199 | "Return the root-mean-square of the fragment, i.e. sqrt(sum(S_i^2)/n)."); |
| 200 | |
| 201 | #define AUDIOOP_RMS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 202 | {"rms", (PyCFunction)(void(*)(void))audioop_rms, METH_FASTCALL, audioop_rms__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 203 | |
| 204 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 205 | audioop_rms_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 206 | |
| 207 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 208 | audioop_rms(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 209 | { |
| 210 | PyObject *return_value = NULL; |
| 211 | Py_buffer fragment = {NULL, NULL}; |
| 212 | int width; |
| 213 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 214 | if (!_PyArg_CheckPositional("rms", nargs, 2, 2)) { |
| 215 | goto exit; |
| 216 | } |
| 217 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 218 | goto exit; |
| 219 | } |
| 220 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 221 | _PyArg_BadArgument("rms", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 222 | goto exit; |
| 223 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 224 | width = _PyLong_AsInt(args[1]); |
| 225 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 226 | goto exit; |
| 227 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 228 | return_value = audioop_rms_impl(module, &fragment, width); |
| 229 | |
| 230 | exit: |
| 231 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 232 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 233 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 234 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 235 | |
| 236 | return return_value; |
| 237 | } |
| 238 | |
| 239 | PyDoc_STRVAR(audioop_findfit__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 240 | "findfit($module, fragment, reference, /)\n" |
| 241 | "--\n" |
| 242 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 243 | "Try to match reference as well as possible to a portion of fragment."); |
| 244 | |
| 245 | #define AUDIOOP_FINDFIT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 246 | {"findfit", (PyCFunction)(void(*)(void))audioop_findfit, METH_FASTCALL, audioop_findfit__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 247 | |
| 248 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 249 | audioop_findfit_impl(PyObject *module, Py_buffer *fragment, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 250 | Py_buffer *reference); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 251 | |
| 252 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 253 | audioop_findfit(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 254 | { |
| 255 | PyObject *return_value = NULL; |
| 256 | Py_buffer fragment = {NULL, NULL}; |
| 257 | Py_buffer reference = {NULL, NULL}; |
| 258 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 259 | if (!_PyArg_CheckPositional("findfit", nargs, 2, 2)) { |
| 260 | goto exit; |
| 261 | } |
| 262 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 263 | goto exit; |
| 264 | } |
| 265 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 266 | _PyArg_BadArgument("findfit", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 267 | goto exit; |
| 268 | } |
| 269 | if (PyObject_GetBuffer(args[1], &reference, PyBUF_SIMPLE) != 0) { |
| 270 | goto exit; |
| 271 | } |
| 272 | if (!PyBuffer_IsContiguous(&reference, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 273 | _PyArg_BadArgument("findfit", "argument 2", "contiguous buffer", args[1]); |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 274 | goto exit; |
| 275 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 276 | return_value = audioop_findfit_impl(module, &fragment, &reference); |
| 277 | |
| 278 | exit: |
| 279 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 280 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 281 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 282 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 283 | /* Cleanup for reference */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 284 | if (reference.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 285 | PyBuffer_Release(&reference); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 286 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 287 | |
| 288 | return return_value; |
| 289 | } |
| 290 | |
| 291 | PyDoc_STRVAR(audioop_findfactor__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 292 | "findfactor($module, fragment, reference, /)\n" |
| 293 | "--\n" |
| 294 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 295 | "Return a factor F such that rms(add(fragment, mul(reference, -F))) is minimal."); |
| 296 | |
| 297 | #define AUDIOOP_FINDFACTOR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 298 | {"findfactor", (PyCFunction)(void(*)(void))audioop_findfactor, METH_FASTCALL, audioop_findfactor__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 299 | |
| 300 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 301 | audioop_findfactor_impl(PyObject *module, Py_buffer *fragment, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 302 | Py_buffer *reference); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 303 | |
| 304 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 305 | audioop_findfactor(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 306 | { |
| 307 | PyObject *return_value = NULL; |
| 308 | Py_buffer fragment = {NULL, NULL}; |
| 309 | Py_buffer reference = {NULL, NULL}; |
| 310 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 311 | if (!_PyArg_CheckPositional("findfactor", nargs, 2, 2)) { |
| 312 | goto exit; |
| 313 | } |
| 314 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 315 | goto exit; |
| 316 | } |
| 317 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 318 | _PyArg_BadArgument("findfactor", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 319 | goto exit; |
| 320 | } |
| 321 | if (PyObject_GetBuffer(args[1], &reference, PyBUF_SIMPLE) != 0) { |
| 322 | goto exit; |
| 323 | } |
| 324 | if (!PyBuffer_IsContiguous(&reference, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 325 | _PyArg_BadArgument("findfactor", "argument 2", "contiguous buffer", args[1]); |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 326 | goto exit; |
| 327 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 328 | return_value = audioop_findfactor_impl(module, &fragment, &reference); |
| 329 | |
| 330 | exit: |
| 331 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 332 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 333 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 334 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 335 | /* Cleanup for reference */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 336 | if (reference.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 337 | PyBuffer_Release(&reference); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 338 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 339 | |
| 340 | return return_value; |
| 341 | } |
| 342 | |
| 343 | PyDoc_STRVAR(audioop_findmax__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 344 | "findmax($module, fragment, length, /)\n" |
| 345 | "--\n" |
| 346 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 347 | "Search fragment for a slice of specified number of samples with maximum energy."); |
| 348 | |
| 349 | #define AUDIOOP_FINDMAX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 350 | {"findmax", (PyCFunction)(void(*)(void))audioop_findmax, METH_FASTCALL, audioop_findmax__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 351 | |
| 352 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 353 | audioop_findmax_impl(PyObject *module, Py_buffer *fragment, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 354 | Py_ssize_t length); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 355 | |
| 356 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 357 | audioop_findmax(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 358 | { |
| 359 | PyObject *return_value = NULL; |
| 360 | Py_buffer fragment = {NULL, NULL}; |
| 361 | Py_ssize_t length; |
| 362 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 363 | if (!_PyArg_CheckPositional("findmax", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 364 | goto exit; |
| 365 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 366 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 367 | goto exit; |
| 368 | } |
| 369 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 370 | _PyArg_BadArgument("findmax", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 371 | goto exit; |
| 372 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 373 | { |
| 374 | Py_ssize_t ival = -1; |
Serhiy Storchaka | 5f4b229d | 2020-05-28 10:33:45 +0300 | [diff] [blame] | 375 | PyObject *iobj = _PyNumber_Index(args[1]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 376 | if (iobj != NULL) { |
| 377 | ival = PyLong_AsSsize_t(iobj); |
| 378 | Py_DECREF(iobj); |
| 379 | } |
| 380 | if (ival == -1 && PyErr_Occurred()) { |
| 381 | goto exit; |
| 382 | } |
| 383 | length = ival; |
| 384 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 385 | return_value = audioop_findmax_impl(module, &fragment, length); |
| 386 | |
| 387 | exit: |
| 388 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 389 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 390 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 391 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 392 | |
| 393 | return return_value; |
| 394 | } |
| 395 | |
| 396 | PyDoc_STRVAR(audioop_avgpp__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 397 | "avgpp($module, fragment, width, /)\n" |
| 398 | "--\n" |
| 399 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 400 | "Return the average peak-peak value over all samples in the fragment."); |
| 401 | |
| 402 | #define AUDIOOP_AVGPP_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 403 | {"avgpp", (PyCFunction)(void(*)(void))audioop_avgpp, METH_FASTCALL, audioop_avgpp__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 404 | |
| 405 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 406 | audioop_avgpp_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 407 | |
| 408 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 409 | audioop_avgpp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 410 | { |
| 411 | PyObject *return_value = NULL; |
| 412 | Py_buffer fragment = {NULL, NULL}; |
| 413 | int width; |
| 414 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 415 | if (!_PyArg_CheckPositional("avgpp", nargs, 2, 2)) { |
| 416 | goto exit; |
| 417 | } |
| 418 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 419 | goto exit; |
| 420 | } |
| 421 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 422 | _PyArg_BadArgument("avgpp", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 423 | goto exit; |
| 424 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 425 | width = _PyLong_AsInt(args[1]); |
| 426 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 427 | goto exit; |
| 428 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 429 | return_value = audioop_avgpp_impl(module, &fragment, width); |
| 430 | |
| 431 | exit: |
| 432 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 433 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 434 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 435 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 436 | |
| 437 | return return_value; |
| 438 | } |
| 439 | |
| 440 | PyDoc_STRVAR(audioop_maxpp__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 441 | "maxpp($module, fragment, width, /)\n" |
| 442 | "--\n" |
| 443 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 444 | "Return the maximum peak-peak value in the sound fragment."); |
| 445 | |
| 446 | #define AUDIOOP_MAXPP_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 447 | {"maxpp", (PyCFunction)(void(*)(void))audioop_maxpp, METH_FASTCALL, audioop_maxpp__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 448 | |
| 449 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 450 | audioop_maxpp_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 451 | |
| 452 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 453 | audioop_maxpp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 454 | { |
| 455 | PyObject *return_value = NULL; |
| 456 | Py_buffer fragment = {NULL, NULL}; |
| 457 | int width; |
| 458 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 459 | if (!_PyArg_CheckPositional("maxpp", nargs, 2, 2)) { |
| 460 | goto exit; |
| 461 | } |
| 462 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 463 | goto exit; |
| 464 | } |
| 465 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 466 | _PyArg_BadArgument("maxpp", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 467 | goto exit; |
| 468 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 469 | width = _PyLong_AsInt(args[1]); |
| 470 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 471 | goto exit; |
| 472 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 473 | return_value = audioop_maxpp_impl(module, &fragment, width); |
| 474 | |
| 475 | exit: |
| 476 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 477 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 478 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 479 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 480 | |
| 481 | return return_value; |
| 482 | } |
| 483 | |
| 484 | PyDoc_STRVAR(audioop_cross__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 485 | "cross($module, fragment, width, /)\n" |
| 486 | "--\n" |
| 487 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 488 | "Return the number of zero crossings in the fragment passed as an argument."); |
| 489 | |
| 490 | #define AUDIOOP_CROSS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 491 | {"cross", (PyCFunction)(void(*)(void))audioop_cross, METH_FASTCALL, audioop_cross__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 492 | |
| 493 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 494 | audioop_cross_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 495 | |
| 496 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 497 | audioop_cross(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 498 | { |
| 499 | PyObject *return_value = NULL; |
| 500 | Py_buffer fragment = {NULL, NULL}; |
| 501 | int width; |
| 502 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 503 | if (!_PyArg_CheckPositional("cross", nargs, 2, 2)) { |
| 504 | goto exit; |
| 505 | } |
| 506 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 507 | goto exit; |
| 508 | } |
| 509 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 510 | _PyArg_BadArgument("cross", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 511 | goto exit; |
| 512 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 513 | width = _PyLong_AsInt(args[1]); |
| 514 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 515 | goto exit; |
| 516 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 517 | return_value = audioop_cross_impl(module, &fragment, width); |
| 518 | |
| 519 | exit: |
| 520 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 521 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 522 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 523 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 524 | |
| 525 | return return_value; |
| 526 | } |
| 527 | |
| 528 | PyDoc_STRVAR(audioop_mul__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 529 | "mul($module, fragment, width, factor, /)\n" |
| 530 | "--\n" |
| 531 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 532 | "Return a fragment that has all samples in the original fragment multiplied by the floating-point value factor."); |
| 533 | |
| 534 | #define AUDIOOP_MUL_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 535 | {"mul", (PyCFunction)(void(*)(void))audioop_mul, METH_FASTCALL, audioop_mul__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 536 | |
| 537 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 538 | audioop_mul_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 539 | double factor); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 540 | |
| 541 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 542 | audioop_mul(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 543 | { |
| 544 | PyObject *return_value = NULL; |
| 545 | Py_buffer fragment = {NULL, NULL}; |
| 546 | int width; |
| 547 | double factor; |
| 548 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 549 | if (!_PyArg_CheckPositional("mul", nargs, 3, 3)) { |
| 550 | goto exit; |
| 551 | } |
| 552 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 553 | goto exit; |
| 554 | } |
| 555 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 556 | _PyArg_BadArgument("mul", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 557 | goto exit; |
| 558 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 559 | width = _PyLong_AsInt(args[1]); |
| 560 | if (width == -1 && PyErr_Occurred()) { |
| 561 | goto exit; |
| 562 | } |
Raymond Hettinger | aef9ad8 | 2019-08-24 19:10:39 -0700 | [diff] [blame] | 563 | if (PyFloat_CheckExact(args[2])) { |
| 564 | factor = PyFloat_AS_DOUBLE(args[2]); |
| 565 | } |
| 566 | else |
| 567 | { |
| 568 | factor = PyFloat_AsDouble(args[2]); |
| 569 | if (factor == -1.0 && PyErr_Occurred()) { |
| 570 | goto exit; |
| 571 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 572 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 573 | return_value = audioop_mul_impl(module, &fragment, width, factor); |
| 574 | |
| 575 | exit: |
| 576 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 577 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 578 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 579 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 580 | |
| 581 | return return_value; |
| 582 | } |
| 583 | |
| 584 | PyDoc_STRVAR(audioop_tomono__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 585 | "tomono($module, fragment, width, lfactor, rfactor, /)\n" |
| 586 | "--\n" |
| 587 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 588 | "Convert a stereo fragment to a mono fragment."); |
| 589 | |
| 590 | #define AUDIOOP_TOMONO_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 591 | {"tomono", (PyCFunction)(void(*)(void))audioop_tomono, METH_FASTCALL, audioop_tomono__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 592 | |
| 593 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 594 | audioop_tomono_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 595 | double lfactor, double rfactor); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 596 | |
| 597 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 598 | audioop_tomono(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 599 | { |
| 600 | PyObject *return_value = NULL; |
| 601 | Py_buffer fragment = {NULL, NULL}; |
| 602 | int width; |
| 603 | double lfactor; |
| 604 | double rfactor; |
| 605 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 606 | if (!_PyArg_CheckPositional("tomono", nargs, 4, 4)) { |
| 607 | goto exit; |
| 608 | } |
| 609 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 610 | goto exit; |
| 611 | } |
| 612 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 613 | _PyArg_BadArgument("tomono", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 614 | goto exit; |
| 615 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 616 | width = _PyLong_AsInt(args[1]); |
| 617 | if (width == -1 && PyErr_Occurred()) { |
| 618 | goto exit; |
| 619 | } |
Raymond Hettinger | aef9ad8 | 2019-08-24 19:10:39 -0700 | [diff] [blame] | 620 | if (PyFloat_CheckExact(args[2])) { |
| 621 | lfactor = PyFloat_AS_DOUBLE(args[2]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 622 | } |
Raymond Hettinger | aef9ad8 | 2019-08-24 19:10:39 -0700 | [diff] [blame] | 623 | else |
| 624 | { |
| 625 | lfactor = PyFloat_AsDouble(args[2]); |
| 626 | if (lfactor == -1.0 && PyErr_Occurred()) { |
| 627 | goto exit; |
| 628 | } |
| 629 | } |
| 630 | if (PyFloat_CheckExact(args[3])) { |
| 631 | rfactor = PyFloat_AS_DOUBLE(args[3]); |
| 632 | } |
| 633 | else |
| 634 | { |
| 635 | rfactor = PyFloat_AsDouble(args[3]); |
| 636 | if (rfactor == -1.0 && PyErr_Occurred()) { |
| 637 | goto exit; |
| 638 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 639 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 640 | return_value = audioop_tomono_impl(module, &fragment, width, lfactor, rfactor); |
| 641 | |
| 642 | exit: |
| 643 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 644 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 645 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 646 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 647 | |
| 648 | return return_value; |
| 649 | } |
| 650 | |
| 651 | PyDoc_STRVAR(audioop_tostereo__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 652 | "tostereo($module, fragment, width, lfactor, rfactor, /)\n" |
| 653 | "--\n" |
| 654 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 655 | "Generate a stereo fragment from a mono fragment."); |
| 656 | |
| 657 | #define AUDIOOP_TOSTEREO_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 658 | {"tostereo", (PyCFunction)(void(*)(void))audioop_tostereo, METH_FASTCALL, audioop_tostereo__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 659 | |
| 660 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 661 | audioop_tostereo_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 662 | double lfactor, double rfactor); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 663 | |
| 664 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 665 | audioop_tostereo(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 666 | { |
| 667 | PyObject *return_value = NULL; |
| 668 | Py_buffer fragment = {NULL, NULL}; |
| 669 | int width; |
| 670 | double lfactor; |
| 671 | double rfactor; |
| 672 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 673 | if (!_PyArg_CheckPositional("tostereo", nargs, 4, 4)) { |
| 674 | goto exit; |
| 675 | } |
| 676 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 677 | goto exit; |
| 678 | } |
| 679 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 680 | _PyArg_BadArgument("tostereo", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 681 | goto exit; |
| 682 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 683 | width = _PyLong_AsInt(args[1]); |
| 684 | if (width == -1 && PyErr_Occurred()) { |
| 685 | goto exit; |
| 686 | } |
Raymond Hettinger | aef9ad8 | 2019-08-24 19:10:39 -0700 | [diff] [blame] | 687 | if (PyFloat_CheckExact(args[2])) { |
| 688 | lfactor = PyFloat_AS_DOUBLE(args[2]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 689 | } |
Raymond Hettinger | aef9ad8 | 2019-08-24 19:10:39 -0700 | [diff] [blame] | 690 | else |
| 691 | { |
| 692 | lfactor = PyFloat_AsDouble(args[2]); |
| 693 | if (lfactor == -1.0 && PyErr_Occurred()) { |
| 694 | goto exit; |
| 695 | } |
| 696 | } |
| 697 | if (PyFloat_CheckExact(args[3])) { |
| 698 | rfactor = PyFloat_AS_DOUBLE(args[3]); |
| 699 | } |
| 700 | else |
| 701 | { |
| 702 | rfactor = PyFloat_AsDouble(args[3]); |
| 703 | if (rfactor == -1.0 && PyErr_Occurred()) { |
| 704 | goto exit; |
| 705 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 706 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 707 | return_value = audioop_tostereo_impl(module, &fragment, width, lfactor, rfactor); |
| 708 | |
| 709 | exit: |
| 710 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 711 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 712 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 713 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 714 | |
| 715 | return return_value; |
| 716 | } |
| 717 | |
| 718 | PyDoc_STRVAR(audioop_add__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 719 | "add($module, fragment1, fragment2, width, /)\n" |
| 720 | "--\n" |
| 721 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 722 | "Return a fragment which is the addition of the two samples passed as parameters."); |
| 723 | |
| 724 | #define AUDIOOP_ADD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 725 | {"add", (PyCFunction)(void(*)(void))audioop_add, METH_FASTCALL, audioop_add__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 726 | |
| 727 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 728 | audioop_add_impl(PyObject *module, Py_buffer *fragment1, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 729 | Py_buffer *fragment2, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 730 | |
| 731 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 732 | audioop_add(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 733 | { |
| 734 | PyObject *return_value = NULL; |
| 735 | Py_buffer fragment1 = {NULL, NULL}; |
| 736 | Py_buffer fragment2 = {NULL, NULL}; |
| 737 | int width; |
| 738 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 739 | if (!_PyArg_CheckPositional("add", nargs, 3, 3)) { |
| 740 | goto exit; |
| 741 | } |
| 742 | if (PyObject_GetBuffer(args[0], &fragment1, PyBUF_SIMPLE) != 0) { |
| 743 | goto exit; |
| 744 | } |
| 745 | if (!PyBuffer_IsContiguous(&fragment1, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 746 | _PyArg_BadArgument("add", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 747 | goto exit; |
| 748 | } |
| 749 | if (PyObject_GetBuffer(args[1], &fragment2, PyBUF_SIMPLE) != 0) { |
| 750 | goto exit; |
| 751 | } |
| 752 | if (!PyBuffer_IsContiguous(&fragment2, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 753 | _PyArg_BadArgument("add", "argument 2", "contiguous buffer", args[1]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 754 | goto exit; |
| 755 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 756 | width = _PyLong_AsInt(args[2]); |
| 757 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 758 | goto exit; |
| 759 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 760 | return_value = audioop_add_impl(module, &fragment1, &fragment2, width); |
| 761 | |
| 762 | exit: |
| 763 | /* Cleanup for fragment1 */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 764 | if (fragment1.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 765 | PyBuffer_Release(&fragment1); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 766 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 767 | /* Cleanup for fragment2 */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 768 | if (fragment2.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 769 | PyBuffer_Release(&fragment2); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 770 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 771 | |
| 772 | return return_value; |
| 773 | } |
| 774 | |
| 775 | PyDoc_STRVAR(audioop_bias__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 776 | "bias($module, fragment, width, bias, /)\n" |
| 777 | "--\n" |
| 778 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 779 | "Return a fragment that is the original fragment with a bias added to each sample."); |
| 780 | |
| 781 | #define AUDIOOP_BIAS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 782 | {"bias", (PyCFunction)(void(*)(void))audioop_bias, METH_FASTCALL, audioop_bias__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 783 | |
| 784 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 785 | audioop_bias_impl(PyObject *module, Py_buffer *fragment, int width, int bias); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 786 | |
| 787 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 788 | audioop_bias(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 789 | { |
| 790 | PyObject *return_value = NULL; |
| 791 | Py_buffer fragment = {NULL, NULL}; |
| 792 | int width; |
| 793 | int bias; |
| 794 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 795 | if (!_PyArg_CheckPositional("bias", nargs, 3, 3)) { |
| 796 | goto exit; |
| 797 | } |
| 798 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 799 | goto exit; |
| 800 | } |
| 801 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 802 | _PyArg_BadArgument("bias", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 803 | goto exit; |
| 804 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 805 | width = _PyLong_AsInt(args[1]); |
| 806 | if (width == -1 && PyErr_Occurred()) { |
| 807 | goto exit; |
| 808 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 809 | bias = _PyLong_AsInt(args[2]); |
| 810 | if (bias == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 811 | goto exit; |
| 812 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 813 | return_value = audioop_bias_impl(module, &fragment, width, bias); |
| 814 | |
| 815 | exit: |
| 816 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 817 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 818 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 819 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 820 | |
| 821 | return return_value; |
| 822 | } |
| 823 | |
| 824 | PyDoc_STRVAR(audioop_reverse__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 825 | "reverse($module, fragment, width, /)\n" |
| 826 | "--\n" |
| 827 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 828 | "Reverse the samples in a fragment and returns the modified fragment."); |
| 829 | |
| 830 | #define AUDIOOP_REVERSE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 831 | {"reverse", (PyCFunction)(void(*)(void))audioop_reverse, METH_FASTCALL, audioop_reverse__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 832 | |
| 833 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 834 | audioop_reverse_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 835 | |
| 836 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 837 | audioop_reverse(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 838 | { |
| 839 | PyObject *return_value = NULL; |
| 840 | Py_buffer fragment = {NULL, NULL}; |
| 841 | int width; |
| 842 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 843 | if (!_PyArg_CheckPositional("reverse", nargs, 2, 2)) { |
| 844 | goto exit; |
| 845 | } |
| 846 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 847 | goto exit; |
| 848 | } |
| 849 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 850 | _PyArg_BadArgument("reverse", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 851 | goto exit; |
| 852 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 853 | width = _PyLong_AsInt(args[1]); |
| 854 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 855 | goto exit; |
| 856 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 857 | return_value = audioop_reverse_impl(module, &fragment, width); |
| 858 | |
| 859 | exit: |
| 860 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 861 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 862 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 863 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 864 | |
| 865 | return return_value; |
| 866 | } |
| 867 | |
| 868 | PyDoc_STRVAR(audioop_byteswap__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 869 | "byteswap($module, fragment, width, /)\n" |
| 870 | "--\n" |
| 871 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 872 | "Convert big-endian samples to little-endian and vice versa."); |
| 873 | |
| 874 | #define AUDIOOP_BYTESWAP_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 875 | {"byteswap", (PyCFunction)(void(*)(void))audioop_byteswap, METH_FASTCALL, audioop_byteswap__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 876 | |
| 877 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 878 | audioop_byteswap_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 879 | |
| 880 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 881 | audioop_byteswap(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 882 | { |
| 883 | PyObject *return_value = NULL; |
| 884 | Py_buffer fragment = {NULL, NULL}; |
| 885 | int width; |
| 886 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 887 | if (!_PyArg_CheckPositional("byteswap", nargs, 2, 2)) { |
| 888 | goto exit; |
| 889 | } |
| 890 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 891 | goto exit; |
| 892 | } |
| 893 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 894 | _PyArg_BadArgument("byteswap", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 895 | goto exit; |
| 896 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 897 | width = _PyLong_AsInt(args[1]); |
| 898 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 899 | goto exit; |
| 900 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 901 | return_value = audioop_byteswap_impl(module, &fragment, width); |
| 902 | |
| 903 | exit: |
| 904 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 905 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 906 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 907 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 908 | |
| 909 | return return_value; |
| 910 | } |
| 911 | |
| 912 | PyDoc_STRVAR(audioop_lin2lin__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 913 | "lin2lin($module, fragment, width, newwidth, /)\n" |
| 914 | "--\n" |
| 915 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 916 | "Convert samples between 1-, 2-, 3- and 4-byte formats."); |
| 917 | |
| 918 | #define AUDIOOP_LIN2LIN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 919 | {"lin2lin", (PyCFunction)(void(*)(void))audioop_lin2lin, METH_FASTCALL, audioop_lin2lin__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 920 | |
| 921 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 922 | audioop_lin2lin_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 923 | int newwidth); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 924 | |
| 925 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 926 | audioop_lin2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 927 | { |
| 928 | PyObject *return_value = NULL; |
| 929 | Py_buffer fragment = {NULL, NULL}; |
| 930 | int width; |
| 931 | int newwidth; |
| 932 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 933 | if (!_PyArg_CheckPositional("lin2lin", nargs, 3, 3)) { |
| 934 | goto exit; |
| 935 | } |
| 936 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 937 | goto exit; |
| 938 | } |
| 939 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 940 | _PyArg_BadArgument("lin2lin", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 941 | goto exit; |
| 942 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 943 | width = _PyLong_AsInt(args[1]); |
| 944 | if (width == -1 && PyErr_Occurred()) { |
| 945 | goto exit; |
| 946 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 947 | newwidth = _PyLong_AsInt(args[2]); |
| 948 | if (newwidth == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 949 | goto exit; |
| 950 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 951 | return_value = audioop_lin2lin_impl(module, &fragment, width, newwidth); |
| 952 | |
| 953 | exit: |
| 954 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 955 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 956 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 957 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 958 | |
| 959 | return return_value; |
| 960 | } |
| 961 | |
| 962 | PyDoc_STRVAR(audioop_ratecv__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 963 | "ratecv($module, fragment, width, nchannels, inrate, outrate, state,\n" |
| 964 | " weightA=1, weightB=0, /)\n" |
| 965 | "--\n" |
| 966 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 967 | "Convert the frame rate of the input fragment."); |
| 968 | |
| 969 | #define AUDIOOP_RATECV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 970 | {"ratecv", (PyCFunction)(void(*)(void))audioop_ratecv, METH_FASTCALL, audioop_ratecv__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 971 | |
| 972 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 973 | audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 974 | int nchannels, int inrate, int outrate, PyObject *state, |
| 975 | int weightA, int weightB); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 976 | |
| 977 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 978 | audioop_ratecv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 979 | { |
| 980 | PyObject *return_value = NULL; |
| 981 | Py_buffer fragment = {NULL, NULL}; |
| 982 | int width; |
| 983 | int nchannels; |
| 984 | int inrate; |
| 985 | int outrate; |
| 986 | PyObject *state; |
| 987 | int weightA = 1; |
| 988 | int weightB = 0; |
| 989 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 990 | if (!_PyArg_CheckPositional("ratecv", nargs, 6, 8)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 991 | goto exit; |
| 992 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 993 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 994 | goto exit; |
| 995 | } |
| 996 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 997 | _PyArg_BadArgument("ratecv", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 998 | goto exit; |
| 999 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1000 | width = _PyLong_AsInt(args[1]); |
| 1001 | if (width == -1 && PyErr_Occurred()) { |
| 1002 | goto exit; |
| 1003 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1004 | nchannels = _PyLong_AsInt(args[2]); |
| 1005 | if (nchannels == -1 && PyErr_Occurred()) { |
| 1006 | goto exit; |
| 1007 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1008 | inrate = _PyLong_AsInt(args[3]); |
| 1009 | if (inrate == -1 && PyErr_Occurred()) { |
| 1010 | goto exit; |
| 1011 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1012 | outrate = _PyLong_AsInt(args[4]); |
| 1013 | if (outrate == -1 && PyErr_Occurred()) { |
| 1014 | goto exit; |
| 1015 | } |
| 1016 | state = args[5]; |
| 1017 | if (nargs < 7) { |
| 1018 | goto skip_optional; |
| 1019 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1020 | weightA = _PyLong_AsInt(args[6]); |
| 1021 | if (weightA == -1 && PyErr_Occurred()) { |
| 1022 | goto exit; |
| 1023 | } |
| 1024 | if (nargs < 8) { |
| 1025 | goto skip_optional; |
| 1026 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1027 | weightB = _PyLong_AsInt(args[7]); |
| 1028 | if (weightB == -1 && PyErr_Occurred()) { |
| 1029 | goto exit; |
| 1030 | } |
| 1031 | skip_optional: |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1032 | return_value = audioop_ratecv_impl(module, &fragment, width, nchannels, inrate, outrate, state, weightA, weightB); |
| 1033 | |
| 1034 | exit: |
| 1035 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1036 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1037 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1038 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1039 | |
| 1040 | return return_value; |
| 1041 | } |
| 1042 | |
| 1043 | PyDoc_STRVAR(audioop_lin2ulaw__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 1044 | "lin2ulaw($module, fragment, width, /)\n" |
| 1045 | "--\n" |
| 1046 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1047 | "Convert samples in the audio fragment to u-LAW encoding."); |
| 1048 | |
| 1049 | #define AUDIOOP_LIN2ULAW_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1050 | {"lin2ulaw", (PyCFunction)(void(*)(void))audioop_lin2ulaw, METH_FASTCALL, audioop_lin2ulaw__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1051 | |
| 1052 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1053 | audioop_lin2ulaw_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1054 | |
| 1055 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1056 | audioop_lin2ulaw(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1057 | { |
| 1058 | PyObject *return_value = NULL; |
| 1059 | Py_buffer fragment = {NULL, NULL}; |
| 1060 | int width; |
| 1061 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1062 | if (!_PyArg_CheckPositional("lin2ulaw", nargs, 2, 2)) { |
| 1063 | goto exit; |
| 1064 | } |
| 1065 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 1066 | goto exit; |
| 1067 | } |
| 1068 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 1069 | _PyArg_BadArgument("lin2ulaw", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1070 | goto exit; |
| 1071 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1072 | width = _PyLong_AsInt(args[1]); |
| 1073 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1074 | goto exit; |
| 1075 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1076 | return_value = audioop_lin2ulaw_impl(module, &fragment, width); |
| 1077 | |
| 1078 | exit: |
| 1079 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1080 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1081 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1082 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1083 | |
| 1084 | return return_value; |
| 1085 | } |
| 1086 | |
| 1087 | PyDoc_STRVAR(audioop_ulaw2lin__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 1088 | "ulaw2lin($module, fragment, width, /)\n" |
| 1089 | "--\n" |
| 1090 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1091 | "Convert sound fragments in u-LAW encoding to linearly encoded sound fragments."); |
| 1092 | |
| 1093 | #define AUDIOOP_ULAW2LIN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1094 | {"ulaw2lin", (PyCFunction)(void(*)(void))audioop_ulaw2lin, METH_FASTCALL, audioop_ulaw2lin__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1095 | |
| 1096 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1097 | audioop_ulaw2lin_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1098 | |
| 1099 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1100 | audioop_ulaw2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1101 | { |
| 1102 | PyObject *return_value = NULL; |
| 1103 | Py_buffer fragment = {NULL, NULL}; |
| 1104 | int width; |
| 1105 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1106 | if (!_PyArg_CheckPositional("ulaw2lin", nargs, 2, 2)) { |
| 1107 | goto exit; |
| 1108 | } |
| 1109 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 1110 | goto exit; |
| 1111 | } |
| 1112 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 1113 | _PyArg_BadArgument("ulaw2lin", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1114 | goto exit; |
| 1115 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1116 | width = _PyLong_AsInt(args[1]); |
| 1117 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1118 | goto exit; |
| 1119 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1120 | return_value = audioop_ulaw2lin_impl(module, &fragment, width); |
| 1121 | |
| 1122 | exit: |
| 1123 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1124 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1125 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1126 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1127 | |
| 1128 | return return_value; |
| 1129 | } |
| 1130 | |
| 1131 | PyDoc_STRVAR(audioop_lin2alaw__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 1132 | "lin2alaw($module, fragment, width, /)\n" |
| 1133 | "--\n" |
| 1134 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1135 | "Convert samples in the audio fragment to a-LAW encoding."); |
| 1136 | |
| 1137 | #define AUDIOOP_LIN2ALAW_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1138 | {"lin2alaw", (PyCFunction)(void(*)(void))audioop_lin2alaw, METH_FASTCALL, audioop_lin2alaw__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1139 | |
| 1140 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1141 | audioop_lin2alaw_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1142 | |
| 1143 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1144 | audioop_lin2alaw(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1145 | { |
| 1146 | PyObject *return_value = NULL; |
| 1147 | Py_buffer fragment = {NULL, NULL}; |
| 1148 | int width; |
| 1149 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1150 | if (!_PyArg_CheckPositional("lin2alaw", nargs, 2, 2)) { |
| 1151 | goto exit; |
| 1152 | } |
| 1153 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 1154 | goto exit; |
| 1155 | } |
| 1156 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 1157 | _PyArg_BadArgument("lin2alaw", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1158 | goto exit; |
| 1159 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1160 | width = _PyLong_AsInt(args[1]); |
| 1161 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1162 | goto exit; |
| 1163 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1164 | return_value = audioop_lin2alaw_impl(module, &fragment, width); |
| 1165 | |
| 1166 | exit: |
| 1167 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1168 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1169 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1170 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1171 | |
| 1172 | return return_value; |
| 1173 | } |
| 1174 | |
| 1175 | PyDoc_STRVAR(audioop_alaw2lin__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 1176 | "alaw2lin($module, fragment, width, /)\n" |
| 1177 | "--\n" |
| 1178 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1179 | "Convert sound fragments in a-LAW encoding to linearly encoded sound fragments."); |
| 1180 | |
| 1181 | #define AUDIOOP_ALAW2LIN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1182 | {"alaw2lin", (PyCFunction)(void(*)(void))audioop_alaw2lin, METH_FASTCALL, audioop_alaw2lin__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1183 | |
| 1184 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1185 | audioop_alaw2lin_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1186 | |
| 1187 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1188 | audioop_alaw2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1189 | { |
| 1190 | PyObject *return_value = NULL; |
| 1191 | Py_buffer fragment = {NULL, NULL}; |
| 1192 | int width; |
| 1193 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1194 | if (!_PyArg_CheckPositional("alaw2lin", nargs, 2, 2)) { |
| 1195 | goto exit; |
| 1196 | } |
| 1197 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 1198 | goto exit; |
| 1199 | } |
| 1200 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 1201 | _PyArg_BadArgument("alaw2lin", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1202 | goto exit; |
| 1203 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1204 | width = _PyLong_AsInt(args[1]); |
| 1205 | if (width == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1206 | goto exit; |
| 1207 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1208 | return_value = audioop_alaw2lin_impl(module, &fragment, width); |
| 1209 | |
| 1210 | exit: |
| 1211 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1212 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1213 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1214 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1215 | |
| 1216 | return return_value; |
| 1217 | } |
| 1218 | |
| 1219 | PyDoc_STRVAR(audioop_lin2adpcm__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 1220 | "lin2adpcm($module, fragment, width, state, /)\n" |
| 1221 | "--\n" |
| 1222 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1223 | "Convert samples to 4 bit Intel/DVI ADPCM encoding."); |
| 1224 | |
| 1225 | #define AUDIOOP_LIN2ADPCM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1226 | {"lin2adpcm", (PyCFunction)(void(*)(void))audioop_lin2adpcm, METH_FASTCALL, audioop_lin2adpcm__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1227 | |
| 1228 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1229 | audioop_lin2adpcm_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 1230 | PyObject *state); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1231 | |
| 1232 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1233 | audioop_lin2adpcm(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1234 | { |
| 1235 | PyObject *return_value = NULL; |
| 1236 | Py_buffer fragment = {NULL, NULL}; |
| 1237 | int width; |
| 1238 | PyObject *state; |
| 1239 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1240 | if (!_PyArg_CheckPositional("lin2adpcm", nargs, 3, 3)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1241 | goto exit; |
| 1242 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1243 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 1244 | goto exit; |
| 1245 | } |
| 1246 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 1247 | _PyArg_BadArgument("lin2adpcm", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1248 | goto exit; |
| 1249 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1250 | width = _PyLong_AsInt(args[1]); |
| 1251 | if (width == -1 && PyErr_Occurred()) { |
| 1252 | goto exit; |
| 1253 | } |
| 1254 | state = args[2]; |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1255 | return_value = audioop_lin2adpcm_impl(module, &fragment, width, state); |
| 1256 | |
| 1257 | exit: |
| 1258 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1259 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1260 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1261 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1262 | |
| 1263 | return return_value; |
| 1264 | } |
| 1265 | |
| 1266 | PyDoc_STRVAR(audioop_adpcm2lin__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 1267 | "adpcm2lin($module, fragment, width, state, /)\n" |
| 1268 | "--\n" |
| 1269 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1270 | "Decode an Intel/DVI ADPCM coded fragment to a linear fragment."); |
| 1271 | |
| 1272 | #define AUDIOOP_ADPCM2LIN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1273 | {"adpcm2lin", (PyCFunction)(void(*)(void))audioop_adpcm2lin, METH_FASTCALL, audioop_adpcm2lin__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1274 | |
| 1275 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1276 | audioop_adpcm2lin_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 1277 | PyObject *state); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1278 | |
| 1279 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1280 | audioop_adpcm2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1281 | { |
| 1282 | PyObject *return_value = NULL; |
| 1283 | Py_buffer fragment = {NULL, NULL}; |
| 1284 | int width; |
| 1285 | PyObject *state; |
| 1286 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1287 | if (!_PyArg_CheckPositional("adpcm2lin", nargs, 3, 3)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1288 | goto exit; |
| 1289 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1290 | if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { |
| 1291 | goto exit; |
| 1292 | } |
| 1293 | if (!PyBuffer_IsContiguous(&fragment, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 1294 | _PyArg_BadArgument("adpcm2lin", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1295 | goto exit; |
| 1296 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1297 | width = _PyLong_AsInt(args[1]); |
| 1298 | if (width == -1 && PyErr_Occurred()) { |
| 1299 | goto exit; |
| 1300 | } |
| 1301 | state = args[2]; |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1302 | return_value = audioop_adpcm2lin_impl(module, &fragment, width, state); |
| 1303 | |
| 1304 | exit: |
| 1305 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1306 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1307 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1308 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 1309 | |
| 1310 | return return_value; |
| 1311 | } |
Serhiy Storchaka | 5f4b229d | 2020-05-28 10:33:45 +0300 | [diff] [blame] | 1312 | /*[clinic end generated code: output=840f8c315ebd4946 input=a9049054013a1b77]*/ |