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 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 26 | if (!_PyArg_ParseStack(args, nargs, "y*in:getsample", |
| 27 | &fragment, &width, &index)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 28 | goto exit; |
| 29 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 30 | return_value = audioop_getsample_impl(module, &fragment, width, index); |
| 31 | |
| 32 | exit: |
| 33 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 34 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 35 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 36 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 37 | |
| 38 | return return_value; |
| 39 | } |
| 40 | |
| 41 | PyDoc_STRVAR(audioop_max__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 42 | "max($module, fragment, width, /)\n" |
| 43 | "--\n" |
| 44 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 45 | "Return the maximum of the absolute value of all samples in a fragment."); |
| 46 | |
| 47 | #define AUDIOOP_MAX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 48 | {"max", (PyCFunction)(void(*)(void))audioop_max, METH_FASTCALL, audioop_max__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 49 | |
| 50 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 51 | audioop_max_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 52 | |
| 53 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 54 | audioop_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 55 | { |
| 56 | PyObject *return_value = NULL; |
| 57 | Py_buffer fragment = {NULL, NULL}; |
| 58 | int width; |
| 59 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 60 | if (!_PyArg_ParseStack(args, nargs, "y*i:max", |
| 61 | &fragment, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 62 | goto exit; |
| 63 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 64 | return_value = audioop_max_impl(module, &fragment, width); |
| 65 | |
| 66 | exit: |
| 67 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 68 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 69 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 70 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 71 | |
| 72 | return return_value; |
| 73 | } |
| 74 | |
| 75 | PyDoc_STRVAR(audioop_minmax__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 76 | "minmax($module, fragment, width, /)\n" |
| 77 | "--\n" |
| 78 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 79 | "Return the minimum and maximum values of all samples in the sound fragment."); |
| 80 | |
| 81 | #define AUDIOOP_MINMAX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 82 | {"minmax", (PyCFunction)(void(*)(void))audioop_minmax, METH_FASTCALL, audioop_minmax__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 83 | |
| 84 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 85 | audioop_minmax_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 86 | |
| 87 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 88 | audioop_minmax(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 89 | { |
| 90 | PyObject *return_value = NULL; |
| 91 | Py_buffer fragment = {NULL, NULL}; |
| 92 | int width; |
| 93 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 94 | if (!_PyArg_ParseStack(args, nargs, "y*i:minmax", |
| 95 | &fragment, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 96 | goto exit; |
| 97 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 98 | return_value = audioop_minmax_impl(module, &fragment, width); |
| 99 | |
| 100 | exit: |
| 101 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 102 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 103 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 104 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 105 | |
| 106 | return return_value; |
| 107 | } |
| 108 | |
| 109 | PyDoc_STRVAR(audioop_avg__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 110 | "avg($module, fragment, width, /)\n" |
| 111 | "--\n" |
| 112 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 113 | "Return the average over all samples in the fragment."); |
| 114 | |
| 115 | #define AUDIOOP_AVG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 116 | {"avg", (PyCFunction)(void(*)(void))audioop_avg, METH_FASTCALL, audioop_avg__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 117 | |
| 118 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 119 | audioop_avg_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 120 | |
| 121 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 122 | audioop_avg(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 123 | { |
| 124 | PyObject *return_value = NULL; |
| 125 | Py_buffer fragment = {NULL, NULL}; |
| 126 | int width; |
| 127 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 128 | if (!_PyArg_ParseStack(args, nargs, "y*i:avg", |
| 129 | &fragment, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 130 | goto exit; |
| 131 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 132 | return_value = audioop_avg_impl(module, &fragment, width); |
| 133 | |
| 134 | exit: |
| 135 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 136 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 137 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 138 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 139 | |
| 140 | return return_value; |
| 141 | } |
| 142 | |
| 143 | PyDoc_STRVAR(audioop_rms__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 144 | "rms($module, fragment, width, /)\n" |
| 145 | "--\n" |
| 146 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 147 | "Return the root-mean-square of the fragment, i.e. sqrt(sum(S_i^2)/n)."); |
| 148 | |
| 149 | #define AUDIOOP_RMS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 150 | {"rms", (PyCFunction)(void(*)(void))audioop_rms, METH_FASTCALL, audioop_rms__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 151 | |
| 152 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 153 | audioop_rms_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 154 | |
| 155 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 156 | audioop_rms(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 157 | { |
| 158 | PyObject *return_value = NULL; |
| 159 | Py_buffer fragment = {NULL, NULL}; |
| 160 | int width; |
| 161 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 162 | if (!_PyArg_ParseStack(args, nargs, "y*i:rms", |
| 163 | &fragment, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 164 | goto exit; |
| 165 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 166 | return_value = audioop_rms_impl(module, &fragment, width); |
| 167 | |
| 168 | exit: |
| 169 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 170 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 171 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 172 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 173 | |
| 174 | return return_value; |
| 175 | } |
| 176 | |
| 177 | PyDoc_STRVAR(audioop_findfit__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 178 | "findfit($module, fragment, reference, /)\n" |
| 179 | "--\n" |
| 180 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 181 | "Try to match reference as well as possible to a portion of fragment."); |
| 182 | |
| 183 | #define AUDIOOP_FINDFIT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 184 | {"findfit", (PyCFunction)(void(*)(void))audioop_findfit, METH_FASTCALL, audioop_findfit__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 185 | |
| 186 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 187 | audioop_findfit_impl(PyObject *module, Py_buffer *fragment, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 188 | Py_buffer *reference); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 189 | |
| 190 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 191 | audioop_findfit(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 192 | { |
| 193 | PyObject *return_value = NULL; |
| 194 | Py_buffer fragment = {NULL, NULL}; |
| 195 | Py_buffer reference = {NULL, NULL}; |
| 196 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 197 | if (!_PyArg_ParseStack(args, nargs, "y*y*:findfit", |
| 198 | &fragment, &reference)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 199 | goto exit; |
| 200 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 201 | return_value = audioop_findfit_impl(module, &fragment, &reference); |
| 202 | |
| 203 | exit: |
| 204 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 205 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 206 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 207 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 208 | /* Cleanup for reference */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 209 | if (reference.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 210 | PyBuffer_Release(&reference); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 211 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 212 | |
| 213 | return return_value; |
| 214 | } |
| 215 | |
| 216 | PyDoc_STRVAR(audioop_findfactor__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 217 | "findfactor($module, fragment, reference, /)\n" |
| 218 | "--\n" |
| 219 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 220 | "Return a factor F such that rms(add(fragment, mul(reference, -F))) is minimal."); |
| 221 | |
| 222 | #define AUDIOOP_FINDFACTOR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 223 | {"findfactor", (PyCFunction)(void(*)(void))audioop_findfactor, METH_FASTCALL, audioop_findfactor__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 224 | |
| 225 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 226 | audioop_findfactor_impl(PyObject *module, Py_buffer *fragment, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 227 | Py_buffer *reference); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 228 | |
| 229 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 230 | audioop_findfactor(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 231 | { |
| 232 | PyObject *return_value = NULL; |
| 233 | Py_buffer fragment = {NULL, NULL}; |
| 234 | Py_buffer reference = {NULL, NULL}; |
| 235 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 236 | if (!_PyArg_ParseStack(args, nargs, "y*y*:findfactor", |
| 237 | &fragment, &reference)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 238 | goto exit; |
| 239 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 240 | return_value = audioop_findfactor_impl(module, &fragment, &reference); |
| 241 | |
| 242 | exit: |
| 243 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 244 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 245 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 246 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 247 | /* Cleanup for reference */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 248 | if (reference.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 249 | PyBuffer_Release(&reference); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 250 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 251 | |
| 252 | return return_value; |
| 253 | } |
| 254 | |
| 255 | PyDoc_STRVAR(audioop_findmax__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 256 | "findmax($module, fragment, length, /)\n" |
| 257 | "--\n" |
| 258 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 259 | "Search fragment for a slice of specified number of samples with maximum energy."); |
| 260 | |
| 261 | #define AUDIOOP_FINDMAX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 262 | {"findmax", (PyCFunction)(void(*)(void))audioop_findmax, METH_FASTCALL, audioop_findmax__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 263 | |
| 264 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 265 | audioop_findmax_impl(PyObject *module, Py_buffer *fragment, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 266 | Py_ssize_t length); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 267 | |
| 268 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 269 | audioop_findmax(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 270 | { |
| 271 | PyObject *return_value = NULL; |
| 272 | Py_buffer fragment = {NULL, NULL}; |
| 273 | Py_ssize_t length; |
| 274 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 275 | if (!_PyArg_ParseStack(args, nargs, "y*n:findmax", |
| 276 | &fragment, &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 277 | goto exit; |
| 278 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 279 | return_value = audioop_findmax_impl(module, &fragment, length); |
| 280 | |
| 281 | exit: |
| 282 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 283 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 284 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 285 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 286 | |
| 287 | return return_value; |
| 288 | } |
| 289 | |
| 290 | PyDoc_STRVAR(audioop_avgpp__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 291 | "avgpp($module, fragment, width, /)\n" |
| 292 | "--\n" |
| 293 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 294 | "Return the average peak-peak value over all samples in the fragment."); |
| 295 | |
| 296 | #define AUDIOOP_AVGPP_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 297 | {"avgpp", (PyCFunction)(void(*)(void))audioop_avgpp, METH_FASTCALL, audioop_avgpp__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 298 | |
| 299 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 300 | audioop_avgpp_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 301 | |
| 302 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 303 | audioop_avgpp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 304 | { |
| 305 | PyObject *return_value = NULL; |
| 306 | Py_buffer fragment = {NULL, NULL}; |
| 307 | int width; |
| 308 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 309 | if (!_PyArg_ParseStack(args, nargs, "y*i:avgpp", |
| 310 | &fragment, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 311 | goto exit; |
| 312 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 313 | return_value = audioop_avgpp_impl(module, &fragment, width); |
| 314 | |
| 315 | exit: |
| 316 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 317 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 318 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 319 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 320 | |
| 321 | return return_value; |
| 322 | } |
| 323 | |
| 324 | PyDoc_STRVAR(audioop_maxpp__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 325 | "maxpp($module, fragment, width, /)\n" |
| 326 | "--\n" |
| 327 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 328 | "Return the maximum peak-peak value in the sound fragment."); |
| 329 | |
| 330 | #define AUDIOOP_MAXPP_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 331 | {"maxpp", (PyCFunction)(void(*)(void))audioop_maxpp, METH_FASTCALL, audioop_maxpp__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 332 | |
| 333 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 334 | audioop_maxpp_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 335 | |
| 336 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 337 | audioop_maxpp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 338 | { |
| 339 | PyObject *return_value = NULL; |
| 340 | Py_buffer fragment = {NULL, NULL}; |
| 341 | int width; |
| 342 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 343 | if (!_PyArg_ParseStack(args, nargs, "y*i:maxpp", |
| 344 | &fragment, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 345 | goto exit; |
| 346 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 347 | return_value = audioop_maxpp_impl(module, &fragment, width); |
| 348 | |
| 349 | exit: |
| 350 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 351 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 352 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 353 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 354 | |
| 355 | return return_value; |
| 356 | } |
| 357 | |
| 358 | PyDoc_STRVAR(audioop_cross__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 359 | "cross($module, fragment, width, /)\n" |
| 360 | "--\n" |
| 361 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 362 | "Return the number of zero crossings in the fragment passed as an argument."); |
| 363 | |
| 364 | #define AUDIOOP_CROSS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 365 | {"cross", (PyCFunction)(void(*)(void))audioop_cross, METH_FASTCALL, audioop_cross__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 366 | |
| 367 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 368 | audioop_cross_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 369 | |
| 370 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 371 | audioop_cross(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 372 | { |
| 373 | PyObject *return_value = NULL; |
| 374 | Py_buffer fragment = {NULL, NULL}; |
| 375 | int width; |
| 376 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 377 | if (!_PyArg_ParseStack(args, nargs, "y*i:cross", |
| 378 | &fragment, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 379 | goto exit; |
| 380 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 381 | return_value = audioop_cross_impl(module, &fragment, width); |
| 382 | |
| 383 | exit: |
| 384 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 385 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 386 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 387 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 388 | |
| 389 | return return_value; |
| 390 | } |
| 391 | |
| 392 | PyDoc_STRVAR(audioop_mul__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 393 | "mul($module, fragment, width, factor, /)\n" |
| 394 | "--\n" |
| 395 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 396 | "Return a fragment that has all samples in the original fragment multiplied by the floating-point value factor."); |
| 397 | |
| 398 | #define AUDIOOP_MUL_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 399 | {"mul", (PyCFunction)(void(*)(void))audioop_mul, METH_FASTCALL, audioop_mul__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 400 | |
| 401 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 402 | audioop_mul_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 403 | double factor); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 404 | |
| 405 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 406 | audioop_mul(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 407 | { |
| 408 | PyObject *return_value = NULL; |
| 409 | Py_buffer fragment = {NULL, NULL}; |
| 410 | int width; |
| 411 | double factor; |
| 412 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 413 | if (!_PyArg_ParseStack(args, nargs, "y*id:mul", |
| 414 | &fragment, &width, &factor)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 415 | goto exit; |
| 416 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 417 | return_value = audioop_mul_impl(module, &fragment, width, factor); |
| 418 | |
| 419 | exit: |
| 420 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 421 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 422 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 423 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 424 | |
| 425 | return return_value; |
| 426 | } |
| 427 | |
| 428 | PyDoc_STRVAR(audioop_tomono__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 429 | "tomono($module, fragment, width, lfactor, rfactor, /)\n" |
| 430 | "--\n" |
| 431 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 432 | "Convert a stereo fragment to a mono fragment."); |
| 433 | |
| 434 | #define AUDIOOP_TOMONO_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 435 | {"tomono", (PyCFunction)(void(*)(void))audioop_tomono, METH_FASTCALL, audioop_tomono__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 436 | |
| 437 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 438 | audioop_tomono_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 439 | double lfactor, double rfactor); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 440 | |
| 441 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 442 | audioop_tomono(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 443 | { |
| 444 | PyObject *return_value = NULL; |
| 445 | Py_buffer fragment = {NULL, NULL}; |
| 446 | int width; |
| 447 | double lfactor; |
| 448 | double rfactor; |
| 449 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 450 | if (!_PyArg_ParseStack(args, nargs, "y*idd:tomono", |
| 451 | &fragment, &width, &lfactor, &rfactor)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 452 | goto exit; |
| 453 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 454 | return_value = audioop_tomono_impl(module, &fragment, width, lfactor, rfactor); |
| 455 | |
| 456 | exit: |
| 457 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 458 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 459 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 460 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 461 | |
| 462 | return return_value; |
| 463 | } |
| 464 | |
| 465 | PyDoc_STRVAR(audioop_tostereo__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 466 | "tostereo($module, fragment, width, lfactor, rfactor, /)\n" |
| 467 | "--\n" |
| 468 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 469 | "Generate a stereo fragment from a mono fragment."); |
| 470 | |
| 471 | #define AUDIOOP_TOSTEREO_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 472 | {"tostereo", (PyCFunction)(void(*)(void))audioop_tostereo, METH_FASTCALL, audioop_tostereo__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 473 | |
| 474 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 475 | audioop_tostereo_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 476 | double lfactor, double rfactor); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 477 | |
| 478 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 479 | audioop_tostereo(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 480 | { |
| 481 | PyObject *return_value = NULL; |
| 482 | Py_buffer fragment = {NULL, NULL}; |
| 483 | int width; |
| 484 | double lfactor; |
| 485 | double rfactor; |
| 486 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 487 | if (!_PyArg_ParseStack(args, nargs, "y*idd:tostereo", |
| 488 | &fragment, &width, &lfactor, &rfactor)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 489 | goto exit; |
| 490 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 491 | return_value = audioop_tostereo_impl(module, &fragment, width, lfactor, rfactor); |
| 492 | |
| 493 | exit: |
| 494 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 495 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 496 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 497 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 498 | |
| 499 | return return_value; |
| 500 | } |
| 501 | |
| 502 | PyDoc_STRVAR(audioop_add__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 503 | "add($module, fragment1, fragment2, width, /)\n" |
| 504 | "--\n" |
| 505 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 506 | "Return a fragment which is the addition of the two samples passed as parameters."); |
| 507 | |
| 508 | #define AUDIOOP_ADD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 509 | {"add", (PyCFunction)(void(*)(void))audioop_add, METH_FASTCALL, audioop_add__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 510 | |
| 511 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 512 | audioop_add_impl(PyObject *module, Py_buffer *fragment1, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 513 | Py_buffer *fragment2, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 514 | |
| 515 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 516 | audioop_add(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 517 | { |
| 518 | PyObject *return_value = NULL; |
| 519 | Py_buffer fragment1 = {NULL, NULL}; |
| 520 | Py_buffer fragment2 = {NULL, NULL}; |
| 521 | int width; |
| 522 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 523 | if (!_PyArg_ParseStack(args, nargs, "y*y*i:add", |
| 524 | &fragment1, &fragment2, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 525 | goto exit; |
| 526 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 527 | return_value = audioop_add_impl(module, &fragment1, &fragment2, width); |
| 528 | |
| 529 | exit: |
| 530 | /* Cleanup for fragment1 */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 531 | if (fragment1.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 532 | PyBuffer_Release(&fragment1); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 533 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 534 | /* Cleanup for fragment2 */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 535 | if (fragment2.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 536 | PyBuffer_Release(&fragment2); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 537 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 538 | |
| 539 | return return_value; |
| 540 | } |
| 541 | |
| 542 | PyDoc_STRVAR(audioop_bias__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 543 | "bias($module, fragment, width, bias, /)\n" |
| 544 | "--\n" |
| 545 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 546 | "Return a fragment that is the original fragment with a bias added to each sample."); |
| 547 | |
| 548 | #define AUDIOOP_BIAS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 549 | {"bias", (PyCFunction)(void(*)(void))audioop_bias, METH_FASTCALL, audioop_bias__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 550 | |
| 551 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 552 | audioop_bias_impl(PyObject *module, Py_buffer *fragment, int width, int bias); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 553 | |
| 554 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 555 | audioop_bias(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 556 | { |
| 557 | PyObject *return_value = NULL; |
| 558 | Py_buffer fragment = {NULL, NULL}; |
| 559 | int width; |
| 560 | int bias; |
| 561 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 562 | if (!_PyArg_ParseStack(args, nargs, "y*ii:bias", |
| 563 | &fragment, &width, &bias)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 564 | goto exit; |
| 565 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 566 | return_value = audioop_bias_impl(module, &fragment, width, bias); |
| 567 | |
| 568 | exit: |
| 569 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 570 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 571 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 572 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 573 | |
| 574 | return return_value; |
| 575 | } |
| 576 | |
| 577 | PyDoc_STRVAR(audioop_reverse__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 578 | "reverse($module, fragment, width, /)\n" |
| 579 | "--\n" |
| 580 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 581 | "Reverse the samples in a fragment and returns the modified fragment."); |
| 582 | |
| 583 | #define AUDIOOP_REVERSE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 584 | {"reverse", (PyCFunction)(void(*)(void))audioop_reverse, METH_FASTCALL, audioop_reverse__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 585 | |
| 586 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 587 | audioop_reverse_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 588 | |
| 589 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 590 | audioop_reverse(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 591 | { |
| 592 | PyObject *return_value = NULL; |
| 593 | Py_buffer fragment = {NULL, NULL}; |
| 594 | int width; |
| 595 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 596 | if (!_PyArg_ParseStack(args, nargs, "y*i:reverse", |
| 597 | &fragment, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 598 | goto exit; |
| 599 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 600 | return_value = audioop_reverse_impl(module, &fragment, width); |
| 601 | |
| 602 | exit: |
| 603 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 604 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 605 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 606 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 607 | |
| 608 | return return_value; |
| 609 | } |
| 610 | |
| 611 | PyDoc_STRVAR(audioop_byteswap__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 612 | "byteswap($module, fragment, width, /)\n" |
| 613 | "--\n" |
| 614 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 615 | "Convert big-endian samples to little-endian and vice versa."); |
| 616 | |
| 617 | #define AUDIOOP_BYTESWAP_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 618 | {"byteswap", (PyCFunction)(void(*)(void))audioop_byteswap, METH_FASTCALL, audioop_byteswap__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 619 | |
| 620 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 621 | audioop_byteswap_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 622 | |
| 623 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 624 | audioop_byteswap(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 625 | { |
| 626 | PyObject *return_value = NULL; |
| 627 | Py_buffer fragment = {NULL, NULL}; |
| 628 | int width; |
| 629 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 630 | if (!_PyArg_ParseStack(args, nargs, "y*i:byteswap", |
| 631 | &fragment, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 632 | goto exit; |
| 633 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 634 | return_value = audioop_byteswap_impl(module, &fragment, width); |
| 635 | |
| 636 | exit: |
| 637 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 638 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 639 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 640 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 641 | |
| 642 | return return_value; |
| 643 | } |
| 644 | |
| 645 | PyDoc_STRVAR(audioop_lin2lin__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 646 | "lin2lin($module, fragment, width, newwidth, /)\n" |
| 647 | "--\n" |
| 648 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 649 | "Convert samples between 1-, 2-, 3- and 4-byte formats."); |
| 650 | |
| 651 | #define AUDIOOP_LIN2LIN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 652 | {"lin2lin", (PyCFunction)(void(*)(void))audioop_lin2lin, METH_FASTCALL, audioop_lin2lin__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 653 | |
| 654 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 655 | audioop_lin2lin_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 656 | int newwidth); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 657 | |
| 658 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 659 | audioop_lin2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 660 | { |
| 661 | PyObject *return_value = NULL; |
| 662 | Py_buffer fragment = {NULL, NULL}; |
| 663 | int width; |
| 664 | int newwidth; |
| 665 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 666 | if (!_PyArg_ParseStack(args, nargs, "y*ii:lin2lin", |
| 667 | &fragment, &width, &newwidth)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 668 | goto exit; |
| 669 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 670 | return_value = audioop_lin2lin_impl(module, &fragment, width, newwidth); |
| 671 | |
| 672 | exit: |
| 673 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 674 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 675 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 676 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 677 | |
| 678 | return return_value; |
| 679 | } |
| 680 | |
| 681 | PyDoc_STRVAR(audioop_ratecv__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 682 | "ratecv($module, fragment, width, nchannels, inrate, outrate, state,\n" |
| 683 | " weightA=1, weightB=0, /)\n" |
| 684 | "--\n" |
| 685 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 686 | "Convert the frame rate of the input fragment."); |
| 687 | |
| 688 | #define AUDIOOP_RATECV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 689 | {"ratecv", (PyCFunction)(void(*)(void))audioop_ratecv, METH_FASTCALL, audioop_ratecv__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 690 | |
| 691 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 692 | audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 693 | int nchannels, int inrate, int outrate, PyObject *state, |
| 694 | int weightA, int weightB); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 695 | |
| 696 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 697 | audioop_ratecv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 698 | { |
| 699 | PyObject *return_value = NULL; |
| 700 | Py_buffer fragment = {NULL, NULL}; |
| 701 | int width; |
| 702 | int nchannels; |
| 703 | int inrate; |
| 704 | int outrate; |
| 705 | PyObject *state; |
| 706 | int weightA = 1; |
| 707 | int weightB = 0; |
| 708 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 709 | if (!_PyArg_ParseStack(args, nargs, "y*iiiiO|ii:ratecv", |
| 710 | &fragment, &width, &nchannels, &inrate, &outrate, &state, &weightA, &weightB)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 711 | goto exit; |
| 712 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 713 | return_value = audioop_ratecv_impl(module, &fragment, width, nchannels, inrate, outrate, state, weightA, weightB); |
| 714 | |
| 715 | exit: |
| 716 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 717 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 718 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 719 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 720 | |
| 721 | return return_value; |
| 722 | } |
| 723 | |
| 724 | PyDoc_STRVAR(audioop_lin2ulaw__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 725 | "lin2ulaw($module, fragment, width, /)\n" |
| 726 | "--\n" |
| 727 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 728 | "Convert samples in the audio fragment to u-LAW encoding."); |
| 729 | |
| 730 | #define AUDIOOP_LIN2ULAW_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 731 | {"lin2ulaw", (PyCFunction)(void(*)(void))audioop_lin2ulaw, METH_FASTCALL, audioop_lin2ulaw__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 732 | |
| 733 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 734 | audioop_lin2ulaw_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 735 | |
| 736 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 737 | audioop_lin2ulaw(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 738 | { |
| 739 | PyObject *return_value = NULL; |
| 740 | Py_buffer fragment = {NULL, NULL}; |
| 741 | int width; |
| 742 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 743 | if (!_PyArg_ParseStack(args, nargs, "y*i:lin2ulaw", |
| 744 | &fragment, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 745 | goto exit; |
| 746 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 747 | return_value = audioop_lin2ulaw_impl(module, &fragment, width); |
| 748 | |
| 749 | exit: |
| 750 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 751 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 752 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 753 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 754 | |
| 755 | return return_value; |
| 756 | } |
| 757 | |
| 758 | PyDoc_STRVAR(audioop_ulaw2lin__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 759 | "ulaw2lin($module, fragment, width, /)\n" |
| 760 | "--\n" |
| 761 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 762 | "Convert sound fragments in u-LAW encoding to linearly encoded sound fragments."); |
| 763 | |
| 764 | #define AUDIOOP_ULAW2LIN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 765 | {"ulaw2lin", (PyCFunction)(void(*)(void))audioop_ulaw2lin, METH_FASTCALL, audioop_ulaw2lin__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 766 | |
| 767 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 768 | audioop_ulaw2lin_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 769 | |
| 770 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 771 | audioop_ulaw2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 772 | { |
| 773 | PyObject *return_value = NULL; |
| 774 | Py_buffer fragment = {NULL, NULL}; |
| 775 | int width; |
| 776 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 777 | if (!_PyArg_ParseStack(args, nargs, "y*i:ulaw2lin", |
| 778 | &fragment, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 779 | goto exit; |
| 780 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 781 | return_value = audioop_ulaw2lin_impl(module, &fragment, width); |
| 782 | |
| 783 | exit: |
| 784 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 785 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 786 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 787 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 788 | |
| 789 | return return_value; |
| 790 | } |
| 791 | |
| 792 | PyDoc_STRVAR(audioop_lin2alaw__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 793 | "lin2alaw($module, fragment, width, /)\n" |
| 794 | "--\n" |
| 795 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 796 | "Convert samples in the audio fragment to a-LAW encoding."); |
| 797 | |
| 798 | #define AUDIOOP_LIN2ALAW_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 799 | {"lin2alaw", (PyCFunction)(void(*)(void))audioop_lin2alaw, METH_FASTCALL, audioop_lin2alaw__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 800 | |
| 801 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 802 | audioop_lin2alaw_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 803 | |
| 804 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 805 | audioop_lin2alaw(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 806 | { |
| 807 | PyObject *return_value = NULL; |
| 808 | Py_buffer fragment = {NULL, NULL}; |
| 809 | int width; |
| 810 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 811 | if (!_PyArg_ParseStack(args, nargs, "y*i:lin2alaw", |
| 812 | &fragment, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 813 | goto exit; |
| 814 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 815 | return_value = audioop_lin2alaw_impl(module, &fragment, width); |
| 816 | |
| 817 | exit: |
| 818 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 819 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 820 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 821 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 822 | |
| 823 | return return_value; |
| 824 | } |
| 825 | |
| 826 | PyDoc_STRVAR(audioop_alaw2lin__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 827 | "alaw2lin($module, fragment, width, /)\n" |
| 828 | "--\n" |
| 829 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 830 | "Convert sound fragments in a-LAW encoding to linearly encoded sound fragments."); |
| 831 | |
| 832 | #define AUDIOOP_ALAW2LIN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 833 | {"alaw2lin", (PyCFunction)(void(*)(void))audioop_alaw2lin, METH_FASTCALL, audioop_alaw2lin__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 834 | |
| 835 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 836 | audioop_alaw2lin_impl(PyObject *module, Py_buffer *fragment, int width); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 837 | |
| 838 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 839 | audioop_alaw2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 840 | { |
| 841 | PyObject *return_value = NULL; |
| 842 | Py_buffer fragment = {NULL, NULL}; |
| 843 | int width; |
| 844 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 845 | if (!_PyArg_ParseStack(args, nargs, "y*i:alaw2lin", |
| 846 | &fragment, &width)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 847 | goto exit; |
| 848 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 849 | return_value = audioop_alaw2lin_impl(module, &fragment, width); |
| 850 | |
| 851 | exit: |
| 852 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 853 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 854 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 855 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 856 | |
| 857 | return return_value; |
| 858 | } |
| 859 | |
| 860 | PyDoc_STRVAR(audioop_lin2adpcm__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 861 | "lin2adpcm($module, fragment, width, state, /)\n" |
| 862 | "--\n" |
| 863 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 864 | "Convert samples to 4 bit Intel/DVI ADPCM encoding."); |
| 865 | |
| 866 | #define AUDIOOP_LIN2ADPCM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 867 | {"lin2adpcm", (PyCFunction)(void(*)(void))audioop_lin2adpcm, METH_FASTCALL, audioop_lin2adpcm__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 868 | |
| 869 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 870 | audioop_lin2adpcm_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 871 | PyObject *state); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 872 | |
| 873 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 874 | audioop_lin2adpcm(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 875 | { |
| 876 | PyObject *return_value = NULL; |
| 877 | Py_buffer fragment = {NULL, NULL}; |
| 878 | int width; |
| 879 | PyObject *state; |
| 880 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 881 | if (!_PyArg_ParseStack(args, nargs, "y*iO:lin2adpcm", |
| 882 | &fragment, &width, &state)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 883 | goto exit; |
| 884 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 885 | return_value = audioop_lin2adpcm_impl(module, &fragment, width, state); |
| 886 | |
| 887 | exit: |
| 888 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 889 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 890 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 891 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 892 | |
| 893 | return return_value; |
| 894 | } |
| 895 | |
| 896 | PyDoc_STRVAR(audioop_adpcm2lin__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 897 | "adpcm2lin($module, fragment, width, state, /)\n" |
| 898 | "--\n" |
| 899 | "\n" |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 900 | "Decode an Intel/DVI ADPCM coded fragment to a linear fragment."); |
| 901 | |
| 902 | #define AUDIOOP_ADPCM2LIN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 903 | {"adpcm2lin", (PyCFunction)(void(*)(void))audioop_adpcm2lin, METH_FASTCALL, audioop_adpcm2lin__doc__}, |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 904 | |
| 905 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 906 | audioop_adpcm2lin_impl(PyObject *module, Py_buffer *fragment, int width, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 907 | PyObject *state); |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 908 | |
| 909 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 910 | audioop_adpcm2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 911 | { |
| 912 | PyObject *return_value = NULL; |
| 913 | Py_buffer fragment = {NULL, NULL}; |
| 914 | int width; |
| 915 | PyObject *state; |
| 916 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 917 | if (!_PyArg_ParseStack(args, nargs, "y*iO:adpcm2lin", |
| 918 | &fragment, &width, &state)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 919 | goto exit; |
| 920 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 921 | return_value = audioop_adpcm2lin_impl(module, &fragment, width, state); |
| 922 | |
| 923 | exit: |
| 924 | /* Cleanup for fragment */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 925 | if (fragment.obj) { |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 926 | PyBuffer_Release(&fragment); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 927 | } |
Serhiy Storchaka | 8d00d73 | 2014-01-25 11:57:59 +0200 | [diff] [blame] | 928 | |
| 929 | return return_value; |
| 930 | } |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 931 | /*[clinic end generated code: output=d197b1559196a48a input=a9049054013a1b77]*/ |