blob: 2a2811b6f08d992f96c4a4e44964cce8e03779fa [file] [log] [blame]
Serhiy Storchaka8d00d732014-01-25 11:57:59 +02001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(audioop_getsample__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -08006"getsample($module, fragment, width, index, /)\n"
7"--\n"
8"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +02009"Return the value of sample index from the fragment.");
10
11#define AUDIOOP_GETSAMPLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +010012 {"getsample", (PyCFunction)audioop_getsample, METH_FASTCALL, audioop_getsample__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020013
14static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030015audioop_getsample_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -040016 Py_ssize_t index);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020017
18static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +030019audioop_getsample(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020020{
21 PyObject *return_value = NULL;
22 Py_buffer fragment = {NULL, NULL};
23 int width;
24 Py_ssize_t index;
25
Sylvain74453812017-06-10 06:51:48 +020026 if (!_PyArg_ParseStack(args, nargs, "y*in:getsample",
27 &fragment, &width, &index)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010028 goto exit;
29 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020030 return_value = audioop_getsample_impl(module, &fragment, width, index);
31
32exit:
33 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030034 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020035 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030036 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020037
38 return return_value;
39}
40
41PyDoc_STRVAR(audioop_max__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080042"max($module, fragment, width, /)\n"
43"--\n"
44"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020045"Return the maximum of the absolute value of all samples in a fragment.");
46
47#define AUDIOOP_MAX_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +010048 {"max", (PyCFunction)audioop_max, METH_FASTCALL, audioop_max__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020049
50static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030051audioop_max_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020052
53static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +030054audioop_max(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020055{
56 PyObject *return_value = NULL;
57 Py_buffer fragment = {NULL, NULL};
58 int width;
59
Sylvain74453812017-06-10 06:51:48 +020060 if (!_PyArg_ParseStack(args, nargs, "y*i:max",
61 &fragment, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010062 goto exit;
63 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020064 return_value = audioop_max_impl(module, &fragment, width);
65
66exit:
67 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030068 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020069 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030070 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020071
72 return return_value;
73}
74
75PyDoc_STRVAR(audioop_minmax__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080076"minmax($module, fragment, width, /)\n"
77"--\n"
78"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020079"Return the minimum and maximum values of all samples in the sound fragment.");
80
81#define AUDIOOP_MINMAX_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +010082 {"minmax", (PyCFunction)audioop_minmax, METH_FASTCALL, audioop_minmax__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020083
84static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030085audioop_minmax_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020086
87static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +030088audioop_minmax(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020089{
90 PyObject *return_value = NULL;
91 Py_buffer fragment = {NULL, NULL};
92 int width;
93
Sylvain74453812017-06-10 06:51:48 +020094 if (!_PyArg_ParseStack(args, nargs, "y*i:minmax",
95 &fragment, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010096 goto exit;
97 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020098 return_value = audioop_minmax_impl(module, &fragment, width);
99
100exit:
101 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300102 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200103 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300104 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200105
106 return return_value;
107}
108
109PyDoc_STRVAR(audioop_avg__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800110"avg($module, fragment, width, /)\n"
111"--\n"
112"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200113"Return the average over all samples in the fragment.");
114
115#define AUDIOOP_AVG_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100116 {"avg", (PyCFunction)audioop_avg, METH_FASTCALL, audioop_avg__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200117
118static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300119audioop_avg_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200120
121static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300122audioop_avg(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200123{
124 PyObject *return_value = NULL;
125 Py_buffer fragment = {NULL, NULL};
126 int width;
127
Sylvain74453812017-06-10 06:51:48 +0200128 if (!_PyArg_ParseStack(args, nargs, "y*i:avg",
129 &fragment, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100130 goto exit;
131 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200132 return_value = audioop_avg_impl(module, &fragment, width);
133
134exit:
135 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300136 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200137 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300138 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200139
140 return return_value;
141}
142
143PyDoc_STRVAR(audioop_rms__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800144"rms($module, fragment, width, /)\n"
145"--\n"
146"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200147"Return the root-mean-square of the fragment, i.e. sqrt(sum(S_i^2)/n).");
148
149#define AUDIOOP_RMS_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100150 {"rms", (PyCFunction)audioop_rms, METH_FASTCALL, audioop_rms__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200151
152static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300153audioop_rms_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200154
155static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300156audioop_rms(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200157{
158 PyObject *return_value = NULL;
159 Py_buffer fragment = {NULL, NULL};
160 int width;
161
Sylvain74453812017-06-10 06:51:48 +0200162 if (!_PyArg_ParseStack(args, nargs, "y*i:rms",
163 &fragment, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100164 goto exit;
165 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200166 return_value = audioop_rms_impl(module, &fragment, width);
167
168exit:
169 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300170 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200171 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300172 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200173
174 return return_value;
175}
176
177PyDoc_STRVAR(audioop_findfit__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800178"findfit($module, fragment, reference, /)\n"
179"--\n"
180"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200181"Try to match reference as well as possible to a portion of fragment.");
182
183#define AUDIOOP_FINDFIT_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100184 {"findfit", (PyCFunction)audioop_findfit, METH_FASTCALL, audioop_findfit__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200185
186static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300187audioop_findfit_impl(PyObject *module, Py_buffer *fragment,
Larry Hastings89964c42015-04-14 18:07:59 -0400188 Py_buffer *reference);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200189
190static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300191audioop_findfit(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200192{
193 PyObject *return_value = NULL;
194 Py_buffer fragment = {NULL, NULL};
195 Py_buffer reference = {NULL, NULL};
196
Sylvain74453812017-06-10 06:51:48 +0200197 if (!_PyArg_ParseStack(args, nargs, "y*y*:findfit",
198 &fragment, &reference)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100199 goto exit;
200 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200201 return_value = audioop_findfit_impl(module, &fragment, &reference);
202
203exit:
204 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300205 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200206 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300207 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200208 /* Cleanup for reference */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300209 if (reference.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200210 PyBuffer_Release(&reference);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300211 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200212
213 return return_value;
214}
215
216PyDoc_STRVAR(audioop_findfactor__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800217"findfactor($module, fragment, reference, /)\n"
218"--\n"
219"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200220"Return a factor F such that rms(add(fragment, mul(reference, -F))) is minimal.");
221
222#define AUDIOOP_FINDFACTOR_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100223 {"findfactor", (PyCFunction)audioop_findfactor, METH_FASTCALL, audioop_findfactor__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200224
225static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300226audioop_findfactor_impl(PyObject *module, Py_buffer *fragment,
Larry Hastings89964c42015-04-14 18:07:59 -0400227 Py_buffer *reference);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200228
229static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300230audioop_findfactor(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200231{
232 PyObject *return_value = NULL;
233 Py_buffer fragment = {NULL, NULL};
234 Py_buffer reference = {NULL, NULL};
235
Sylvain74453812017-06-10 06:51:48 +0200236 if (!_PyArg_ParseStack(args, nargs, "y*y*:findfactor",
237 &fragment, &reference)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100238 goto exit;
239 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200240 return_value = audioop_findfactor_impl(module, &fragment, &reference);
241
242exit:
243 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300244 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200245 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300246 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200247 /* Cleanup for reference */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300248 if (reference.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200249 PyBuffer_Release(&reference);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300250 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200251
252 return return_value;
253}
254
255PyDoc_STRVAR(audioop_findmax__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800256"findmax($module, fragment, length, /)\n"
257"--\n"
258"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200259"Search fragment for a slice of specified number of samples with maximum energy.");
260
261#define AUDIOOP_FINDMAX_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100262 {"findmax", (PyCFunction)audioop_findmax, METH_FASTCALL, audioop_findmax__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200263
264static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300265audioop_findmax_impl(PyObject *module, Py_buffer *fragment,
Larry Hastings89964c42015-04-14 18:07:59 -0400266 Py_ssize_t length);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200267
268static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300269audioop_findmax(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200270{
271 PyObject *return_value = NULL;
272 Py_buffer fragment = {NULL, NULL};
273 Py_ssize_t length;
274
Sylvain74453812017-06-10 06:51:48 +0200275 if (!_PyArg_ParseStack(args, nargs, "y*n:findmax",
276 &fragment, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100277 goto exit;
278 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200279 return_value = audioop_findmax_impl(module, &fragment, length);
280
281exit:
282 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300283 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200284 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300285 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200286
287 return return_value;
288}
289
290PyDoc_STRVAR(audioop_avgpp__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800291"avgpp($module, fragment, width, /)\n"
292"--\n"
293"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200294"Return the average peak-peak value over all samples in the fragment.");
295
296#define AUDIOOP_AVGPP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100297 {"avgpp", (PyCFunction)audioop_avgpp, METH_FASTCALL, audioop_avgpp__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200298
299static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300300audioop_avgpp_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200301
302static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300303audioop_avgpp(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200304{
305 PyObject *return_value = NULL;
306 Py_buffer fragment = {NULL, NULL};
307 int width;
308
Sylvain74453812017-06-10 06:51:48 +0200309 if (!_PyArg_ParseStack(args, nargs, "y*i:avgpp",
310 &fragment, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100311 goto exit;
312 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200313 return_value = audioop_avgpp_impl(module, &fragment, width);
314
315exit:
316 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300317 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200318 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300319 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200320
321 return return_value;
322}
323
324PyDoc_STRVAR(audioop_maxpp__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800325"maxpp($module, fragment, width, /)\n"
326"--\n"
327"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200328"Return the maximum peak-peak value in the sound fragment.");
329
330#define AUDIOOP_MAXPP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100331 {"maxpp", (PyCFunction)audioop_maxpp, METH_FASTCALL, audioop_maxpp__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200332
333static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300334audioop_maxpp_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200335
336static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300337audioop_maxpp(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200338{
339 PyObject *return_value = NULL;
340 Py_buffer fragment = {NULL, NULL};
341 int width;
342
Sylvain74453812017-06-10 06:51:48 +0200343 if (!_PyArg_ParseStack(args, nargs, "y*i:maxpp",
344 &fragment, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100345 goto exit;
346 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200347 return_value = audioop_maxpp_impl(module, &fragment, width);
348
349exit:
350 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300351 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200352 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300353 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200354
355 return return_value;
356}
357
358PyDoc_STRVAR(audioop_cross__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800359"cross($module, fragment, width, /)\n"
360"--\n"
361"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200362"Return the number of zero crossings in the fragment passed as an argument.");
363
364#define AUDIOOP_CROSS_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100365 {"cross", (PyCFunction)audioop_cross, METH_FASTCALL, audioop_cross__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200366
367static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300368audioop_cross_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200369
370static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300371audioop_cross(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200372{
373 PyObject *return_value = NULL;
374 Py_buffer fragment = {NULL, NULL};
375 int width;
376
Sylvain74453812017-06-10 06:51:48 +0200377 if (!_PyArg_ParseStack(args, nargs, "y*i:cross",
378 &fragment, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100379 goto exit;
380 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200381 return_value = audioop_cross_impl(module, &fragment, width);
382
383exit:
384 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300385 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200386 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300387 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200388
389 return return_value;
390}
391
392PyDoc_STRVAR(audioop_mul__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800393"mul($module, fragment, width, factor, /)\n"
394"--\n"
395"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200396"Return a fragment that has all samples in the original fragment multiplied by the floating-point value factor.");
397
398#define AUDIOOP_MUL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100399 {"mul", (PyCFunction)audioop_mul, METH_FASTCALL, audioop_mul__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200400
401static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300402audioop_mul_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -0400403 double factor);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200404
405static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300406audioop_mul(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200407{
408 PyObject *return_value = NULL;
409 Py_buffer fragment = {NULL, NULL};
410 int width;
411 double factor;
412
Sylvain74453812017-06-10 06:51:48 +0200413 if (!_PyArg_ParseStack(args, nargs, "y*id:mul",
414 &fragment, &width, &factor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100415 goto exit;
416 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200417 return_value = audioop_mul_impl(module, &fragment, width, factor);
418
419exit:
420 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300421 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200422 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300423 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200424
425 return return_value;
426}
427
428PyDoc_STRVAR(audioop_tomono__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800429"tomono($module, fragment, width, lfactor, rfactor, /)\n"
430"--\n"
431"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200432"Convert a stereo fragment to a mono fragment.");
433
434#define AUDIOOP_TOMONO_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100435 {"tomono", (PyCFunction)audioop_tomono, METH_FASTCALL, audioop_tomono__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200436
437static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300438audioop_tomono_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -0400439 double lfactor, double rfactor);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200440
441static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300442audioop_tomono(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200443{
444 PyObject *return_value = NULL;
445 Py_buffer fragment = {NULL, NULL};
446 int width;
447 double lfactor;
448 double rfactor;
449
Sylvain74453812017-06-10 06:51:48 +0200450 if (!_PyArg_ParseStack(args, nargs, "y*idd:tomono",
451 &fragment, &width, &lfactor, &rfactor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100452 goto exit;
453 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200454 return_value = audioop_tomono_impl(module, &fragment, width, lfactor, rfactor);
455
456exit:
457 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300458 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200459 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300460 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200461
462 return return_value;
463}
464
465PyDoc_STRVAR(audioop_tostereo__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800466"tostereo($module, fragment, width, lfactor, rfactor, /)\n"
467"--\n"
468"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200469"Generate a stereo fragment from a mono fragment.");
470
471#define AUDIOOP_TOSTEREO_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100472 {"tostereo", (PyCFunction)audioop_tostereo, METH_FASTCALL, audioop_tostereo__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200473
474static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300475audioop_tostereo_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -0400476 double lfactor, double rfactor);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200477
478static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300479audioop_tostereo(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200480{
481 PyObject *return_value = NULL;
482 Py_buffer fragment = {NULL, NULL};
483 int width;
484 double lfactor;
485 double rfactor;
486
Sylvain74453812017-06-10 06:51:48 +0200487 if (!_PyArg_ParseStack(args, nargs, "y*idd:tostereo",
488 &fragment, &width, &lfactor, &rfactor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100489 goto exit;
490 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200491 return_value = audioop_tostereo_impl(module, &fragment, width, lfactor, rfactor);
492
493exit:
494 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300495 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200496 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300497 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200498
499 return return_value;
500}
501
502PyDoc_STRVAR(audioop_add__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800503"add($module, fragment1, fragment2, width, /)\n"
504"--\n"
505"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200506"Return a fragment which is the addition of the two samples passed as parameters.");
507
508#define AUDIOOP_ADD_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100509 {"add", (PyCFunction)audioop_add, METH_FASTCALL, audioop_add__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200510
511static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300512audioop_add_impl(PyObject *module, Py_buffer *fragment1,
Larry Hastings89964c42015-04-14 18:07:59 -0400513 Py_buffer *fragment2, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200514
515static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300516audioop_add(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200517{
518 PyObject *return_value = NULL;
519 Py_buffer fragment1 = {NULL, NULL};
520 Py_buffer fragment2 = {NULL, NULL};
521 int width;
522
Sylvain74453812017-06-10 06:51:48 +0200523 if (!_PyArg_ParseStack(args, nargs, "y*y*i:add",
524 &fragment1, &fragment2, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100525 goto exit;
526 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200527 return_value = audioop_add_impl(module, &fragment1, &fragment2, width);
528
529exit:
530 /* Cleanup for fragment1 */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300531 if (fragment1.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200532 PyBuffer_Release(&fragment1);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300533 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200534 /* Cleanup for fragment2 */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300535 if (fragment2.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200536 PyBuffer_Release(&fragment2);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300537 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200538
539 return return_value;
540}
541
542PyDoc_STRVAR(audioop_bias__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800543"bias($module, fragment, width, bias, /)\n"
544"--\n"
545"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200546"Return a fragment that is the original fragment with a bias added to each sample.");
547
548#define AUDIOOP_BIAS_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100549 {"bias", (PyCFunction)audioop_bias, METH_FASTCALL, audioop_bias__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200550
551static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300552audioop_bias_impl(PyObject *module, Py_buffer *fragment, int width, int bias);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200553
554static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300555audioop_bias(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200556{
557 PyObject *return_value = NULL;
558 Py_buffer fragment = {NULL, NULL};
559 int width;
560 int bias;
561
Sylvain74453812017-06-10 06:51:48 +0200562 if (!_PyArg_ParseStack(args, nargs, "y*ii:bias",
563 &fragment, &width, &bias)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100564 goto exit;
565 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200566 return_value = audioop_bias_impl(module, &fragment, width, bias);
567
568exit:
569 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300570 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200571 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300572 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200573
574 return return_value;
575}
576
577PyDoc_STRVAR(audioop_reverse__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800578"reverse($module, fragment, width, /)\n"
579"--\n"
580"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200581"Reverse the samples in a fragment and returns the modified fragment.");
582
583#define AUDIOOP_REVERSE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100584 {"reverse", (PyCFunction)audioop_reverse, METH_FASTCALL, audioop_reverse__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200585
586static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300587audioop_reverse_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200588
589static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300590audioop_reverse(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200591{
592 PyObject *return_value = NULL;
593 Py_buffer fragment = {NULL, NULL};
594 int width;
595
Sylvain74453812017-06-10 06:51:48 +0200596 if (!_PyArg_ParseStack(args, nargs, "y*i:reverse",
597 &fragment, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100598 goto exit;
599 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200600 return_value = audioop_reverse_impl(module, &fragment, width);
601
602exit:
603 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300604 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200605 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300606 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200607
608 return return_value;
609}
610
611PyDoc_STRVAR(audioop_byteswap__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800612"byteswap($module, fragment, width, /)\n"
613"--\n"
614"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200615"Convert big-endian samples to little-endian and vice versa.");
616
617#define AUDIOOP_BYTESWAP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100618 {"byteswap", (PyCFunction)audioop_byteswap, METH_FASTCALL, audioop_byteswap__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200619
620static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300621audioop_byteswap_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200622
623static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300624audioop_byteswap(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200625{
626 PyObject *return_value = NULL;
627 Py_buffer fragment = {NULL, NULL};
628 int width;
629
Sylvain74453812017-06-10 06:51:48 +0200630 if (!_PyArg_ParseStack(args, nargs, "y*i:byteswap",
631 &fragment, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100632 goto exit;
633 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200634 return_value = audioop_byteswap_impl(module, &fragment, width);
635
636exit:
637 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300638 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200639 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300640 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200641
642 return return_value;
643}
644
645PyDoc_STRVAR(audioop_lin2lin__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800646"lin2lin($module, fragment, width, newwidth, /)\n"
647"--\n"
648"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200649"Convert samples between 1-, 2-, 3- and 4-byte formats.");
650
651#define AUDIOOP_LIN2LIN_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100652 {"lin2lin", (PyCFunction)audioop_lin2lin, METH_FASTCALL, audioop_lin2lin__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200653
654static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300655audioop_lin2lin_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -0400656 int newwidth);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200657
658static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300659audioop_lin2lin(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200660{
661 PyObject *return_value = NULL;
662 Py_buffer fragment = {NULL, NULL};
663 int width;
664 int newwidth;
665
Sylvain74453812017-06-10 06:51:48 +0200666 if (!_PyArg_ParseStack(args, nargs, "y*ii:lin2lin",
667 &fragment, &width, &newwidth)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100668 goto exit;
669 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200670 return_value = audioop_lin2lin_impl(module, &fragment, width, newwidth);
671
672exit:
673 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300674 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200675 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300676 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200677
678 return return_value;
679}
680
681PyDoc_STRVAR(audioop_ratecv__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800682"ratecv($module, fragment, width, nchannels, inrate, outrate, state,\n"
683" weightA=1, weightB=0, /)\n"
684"--\n"
685"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200686"Convert the frame rate of the input fragment.");
687
688#define AUDIOOP_RATECV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100689 {"ratecv", (PyCFunction)audioop_ratecv, METH_FASTCALL, audioop_ratecv__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200690
691static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300692audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -0400693 int nchannels, int inrate, int outrate, PyObject *state,
694 int weightA, int weightB);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200695
696static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300697audioop_ratecv(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200698{
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
Sylvain74453812017-06-10 06:51:48 +0200709 if (!_PyArg_ParseStack(args, nargs, "y*iiiiO|ii:ratecv",
710 &fragment, &width, &nchannels, &inrate, &outrate, &state, &weightA, &weightB)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100711 goto exit;
712 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200713 return_value = audioop_ratecv_impl(module, &fragment, width, nchannels, inrate, outrate, state, weightA, weightB);
714
715exit:
716 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300717 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200718 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300719 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200720
721 return return_value;
722}
723
724PyDoc_STRVAR(audioop_lin2ulaw__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800725"lin2ulaw($module, fragment, width, /)\n"
726"--\n"
727"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200728"Convert samples in the audio fragment to u-LAW encoding.");
729
730#define AUDIOOP_LIN2ULAW_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100731 {"lin2ulaw", (PyCFunction)audioop_lin2ulaw, METH_FASTCALL, audioop_lin2ulaw__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200732
733static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300734audioop_lin2ulaw_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200735
736static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300737audioop_lin2ulaw(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200738{
739 PyObject *return_value = NULL;
740 Py_buffer fragment = {NULL, NULL};
741 int width;
742
Sylvain74453812017-06-10 06:51:48 +0200743 if (!_PyArg_ParseStack(args, nargs, "y*i:lin2ulaw",
744 &fragment, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100745 goto exit;
746 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200747 return_value = audioop_lin2ulaw_impl(module, &fragment, width);
748
749exit:
750 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300751 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200752 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300753 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200754
755 return return_value;
756}
757
758PyDoc_STRVAR(audioop_ulaw2lin__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800759"ulaw2lin($module, fragment, width, /)\n"
760"--\n"
761"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200762"Convert sound fragments in u-LAW encoding to linearly encoded sound fragments.");
763
764#define AUDIOOP_ULAW2LIN_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100765 {"ulaw2lin", (PyCFunction)audioop_ulaw2lin, METH_FASTCALL, audioop_ulaw2lin__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200766
767static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300768audioop_ulaw2lin_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200769
770static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300771audioop_ulaw2lin(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200772{
773 PyObject *return_value = NULL;
774 Py_buffer fragment = {NULL, NULL};
775 int width;
776
Sylvain74453812017-06-10 06:51:48 +0200777 if (!_PyArg_ParseStack(args, nargs, "y*i:ulaw2lin",
778 &fragment, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100779 goto exit;
780 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200781 return_value = audioop_ulaw2lin_impl(module, &fragment, width);
782
783exit:
784 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300785 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200786 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300787 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200788
789 return return_value;
790}
791
792PyDoc_STRVAR(audioop_lin2alaw__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800793"lin2alaw($module, fragment, width, /)\n"
794"--\n"
795"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200796"Convert samples in the audio fragment to a-LAW encoding.");
797
798#define AUDIOOP_LIN2ALAW_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100799 {"lin2alaw", (PyCFunction)audioop_lin2alaw, METH_FASTCALL, audioop_lin2alaw__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200800
801static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300802audioop_lin2alaw_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200803
804static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300805audioop_lin2alaw(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200806{
807 PyObject *return_value = NULL;
808 Py_buffer fragment = {NULL, NULL};
809 int width;
810
Sylvain74453812017-06-10 06:51:48 +0200811 if (!_PyArg_ParseStack(args, nargs, "y*i:lin2alaw",
812 &fragment, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100813 goto exit;
814 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200815 return_value = audioop_lin2alaw_impl(module, &fragment, width);
816
817exit:
818 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300819 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200820 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300821 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200822
823 return return_value;
824}
825
826PyDoc_STRVAR(audioop_alaw2lin__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800827"alaw2lin($module, fragment, width, /)\n"
828"--\n"
829"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200830"Convert sound fragments in a-LAW encoding to linearly encoded sound fragments.");
831
832#define AUDIOOP_ALAW2LIN_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100833 {"alaw2lin", (PyCFunction)audioop_alaw2lin, METH_FASTCALL, audioop_alaw2lin__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200834
835static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300836audioop_alaw2lin_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200837
838static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300839audioop_alaw2lin(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200840{
841 PyObject *return_value = NULL;
842 Py_buffer fragment = {NULL, NULL};
843 int width;
844
Sylvain74453812017-06-10 06:51:48 +0200845 if (!_PyArg_ParseStack(args, nargs, "y*i:alaw2lin",
846 &fragment, &width)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100847 goto exit;
848 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200849 return_value = audioop_alaw2lin_impl(module, &fragment, width);
850
851exit:
852 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300853 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200854 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300855 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200856
857 return return_value;
858}
859
860PyDoc_STRVAR(audioop_lin2adpcm__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800861"lin2adpcm($module, fragment, width, state, /)\n"
862"--\n"
863"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200864"Convert samples to 4 bit Intel/DVI ADPCM encoding.");
865
866#define AUDIOOP_LIN2ADPCM_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100867 {"lin2adpcm", (PyCFunction)audioop_lin2adpcm, METH_FASTCALL, audioop_lin2adpcm__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200868
869static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300870audioop_lin2adpcm_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -0400871 PyObject *state);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200872
873static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300874audioop_lin2adpcm(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200875{
876 PyObject *return_value = NULL;
877 Py_buffer fragment = {NULL, NULL};
878 int width;
879 PyObject *state;
880
Sylvain74453812017-06-10 06:51:48 +0200881 if (!_PyArg_ParseStack(args, nargs, "y*iO:lin2adpcm",
882 &fragment, &width, &state)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100883 goto exit;
884 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200885 return_value = audioop_lin2adpcm_impl(module, &fragment, width, state);
886
887exit:
888 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300889 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200890 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300891 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200892
893 return return_value;
894}
895
896PyDoc_STRVAR(audioop_adpcm2lin__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800897"adpcm2lin($module, fragment, width, state, /)\n"
898"--\n"
899"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200900"Decode an Intel/DVI ADPCM coded fragment to a linear fragment.");
901
902#define AUDIOOP_ADPCM2LIN_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100903 {"adpcm2lin", (PyCFunction)audioop_adpcm2lin, METH_FASTCALL, audioop_adpcm2lin__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200904
905static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300906audioop_adpcm2lin_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -0400907 PyObject *state);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200908
909static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300910audioop_adpcm2lin(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200911{
912 PyObject *return_value = NULL;
913 Py_buffer fragment = {NULL, NULL};
914 int width;
915 PyObject *state;
916
Sylvain74453812017-06-10 06:51:48 +0200917 if (!_PyArg_ParseStack(args, nargs, "y*iO:adpcm2lin",
918 &fragment, &width, &state)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100919 goto exit;
920 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200921 return_value = audioop_adpcm2lin_impl(module, &fragment, width, state);
922
923exit:
924 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300925 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200926 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300927 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200928
929 return return_value;
930}
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300931/*[clinic end generated code: output=e2076026235d7f0f input=a9049054013a1b77]*/