blob: 6ba1172e95913c26070daa16fae020062f162a68 [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 *
Victor Stinner259f0e42017-01-17 01:35:17 +010019audioop_getsample(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
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
Victor Stinner259f0e42017-01-17 01:35:17 +010026 if (!_PyArg_ParseStack(args, nargs, "y*in:getsample",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030027 &fragment, &width, &index)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020028 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030029 }
Victor Stinner259f0e42017-01-17 01:35:17 +010030
31 if (!_PyArg_NoStackKeywords("getsample", kwnames)) {
32 goto exit;
33 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020034 return_value = audioop_getsample_impl(module, &fragment, width, index);
35
36exit:
37 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030038 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020039 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030040 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020041
42 return return_value;
43}
44
45PyDoc_STRVAR(audioop_max__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080046"max($module, fragment, width, /)\n"
47"--\n"
48"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020049"Return the maximum of the absolute value of all samples in a fragment.");
50
51#define AUDIOOP_MAX_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +010052 {"max", (PyCFunction)audioop_max, METH_FASTCALL, audioop_max__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020053
54static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030055audioop_max_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020056
57static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +010058audioop_max(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020059{
60 PyObject *return_value = NULL;
61 Py_buffer fragment = {NULL, NULL};
62 int width;
63
Victor Stinner259f0e42017-01-17 01:35:17 +010064 if (!_PyArg_ParseStack(args, nargs, "y*i:max",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030065 &fragment, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020066 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030067 }
Victor Stinner259f0e42017-01-17 01:35:17 +010068
69 if (!_PyArg_NoStackKeywords("max", kwnames)) {
70 goto exit;
71 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020072 return_value = audioop_max_impl(module, &fragment, width);
73
74exit:
75 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030076 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020077 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030078 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020079
80 return return_value;
81}
82
83PyDoc_STRVAR(audioop_minmax__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080084"minmax($module, fragment, width, /)\n"
85"--\n"
86"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020087"Return the minimum and maximum values of all samples in the sound fragment.");
88
89#define AUDIOOP_MINMAX_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +010090 {"minmax", (PyCFunction)audioop_minmax, METH_FASTCALL, audioop_minmax__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020091
92static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030093audioop_minmax_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020094
95static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +010096audioop_minmax(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +020097{
98 PyObject *return_value = NULL;
99 Py_buffer fragment = {NULL, NULL};
100 int width;
101
Victor Stinner259f0e42017-01-17 01:35:17 +0100102 if (!_PyArg_ParseStack(args, nargs, "y*i:minmax",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300103 &fragment, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200104 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300105 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100106
107 if (!_PyArg_NoStackKeywords("minmax", kwnames)) {
108 goto exit;
109 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200110 return_value = audioop_minmax_impl(module, &fragment, width);
111
112exit:
113 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300114 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200115 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300116 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200117
118 return return_value;
119}
120
121PyDoc_STRVAR(audioop_avg__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800122"avg($module, fragment, width, /)\n"
123"--\n"
124"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200125"Return the average over all samples in the fragment.");
126
127#define AUDIOOP_AVG_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100128 {"avg", (PyCFunction)audioop_avg, METH_FASTCALL, audioop_avg__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200129
130static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300131audioop_avg_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200132
133static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100134audioop_avg(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200135{
136 PyObject *return_value = NULL;
137 Py_buffer fragment = {NULL, NULL};
138 int width;
139
Victor Stinner259f0e42017-01-17 01:35:17 +0100140 if (!_PyArg_ParseStack(args, nargs, "y*i:avg",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300141 &fragment, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200142 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300143 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100144
145 if (!_PyArg_NoStackKeywords("avg", kwnames)) {
146 goto exit;
147 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200148 return_value = audioop_avg_impl(module, &fragment, width);
149
150exit:
151 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300152 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200153 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300154 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200155
156 return return_value;
157}
158
159PyDoc_STRVAR(audioop_rms__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800160"rms($module, fragment, width, /)\n"
161"--\n"
162"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200163"Return the root-mean-square of the fragment, i.e. sqrt(sum(S_i^2)/n).");
164
165#define AUDIOOP_RMS_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100166 {"rms", (PyCFunction)audioop_rms, METH_FASTCALL, audioop_rms__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200167
168static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300169audioop_rms_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200170
171static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100172audioop_rms(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200173{
174 PyObject *return_value = NULL;
175 Py_buffer fragment = {NULL, NULL};
176 int width;
177
Victor Stinner259f0e42017-01-17 01:35:17 +0100178 if (!_PyArg_ParseStack(args, nargs, "y*i:rms",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300179 &fragment, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200180 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300181 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100182
183 if (!_PyArg_NoStackKeywords("rms", kwnames)) {
184 goto exit;
185 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200186 return_value = audioop_rms_impl(module, &fragment, width);
187
188exit:
189 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300190 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200191 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300192 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200193
194 return return_value;
195}
196
197PyDoc_STRVAR(audioop_findfit__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800198"findfit($module, fragment, reference, /)\n"
199"--\n"
200"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200201"Try to match reference as well as possible to a portion of fragment.");
202
203#define AUDIOOP_FINDFIT_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100204 {"findfit", (PyCFunction)audioop_findfit, METH_FASTCALL, audioop_findfit__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200205
206static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300207audioop_findfit_impl(PyObject *module, Py_buffer *fragment,
Larry Hastings89964c42015-04-14 18:07:59 -0400208 Py_buffer *reference);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200209
210static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100211audioop_findfit(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200212{
213 PyObject *return_value = NULL;
214 Py_buffer fragment = {NULL, NULL};
215 Py_buffer reference = {NULL, NULL};
216
Victor Stinner259f0e42017-01-17 01:35:17 +0100217 if (!_PyArg_ParseStack(args, nargs, "y*y*:findfit",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300218 &fragment, &reference)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200219 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300220 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100221
222 if (!_PyArg_NoStackKeywords("findfit", kwnames)) {
223 goto exit;
224 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200225 return_value = audioop_findfit_impl(module, &fragment, &reference);
226
227exit:
228 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300229 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200230 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300231 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200232 /* Cleanup for reference */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300233 if (reference.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200234 PyBuffer_Release(&reference);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300235 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200236
237 return return_value;
238}
239
240PyDoc_STRVAR(audioop_findfactor__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800241"findfactor($module, fragment, reference, /)\n"
242"--\n"
243"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200244"Return a factor F such that rms(add(fragment, mul(reference, -F))) is minimal.");
245
246#define AUDIOOP_FINDFACTOR_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100247 {"findfactor", (PyCFunction)audioop_findfactor, METH_FASTCALL, audioop_findfactor__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200248
249static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300250audioop_findfactor_impl(PyObject *module, Py_buffer *fragment,
Larry Hastings89964c42015-04-14 18:07:59 -0400251 Py_buffer *reference);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200252
253static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100254audioop_findfactor(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200255{
256 PyObject *return_value = NULL;
257 Py_buffer fragment = {NULL, NULL};
258 Py_buffer reference = {NULL, NULL};
259
Victor Stinner259f0e42017-01-17 01:35:17 +0100260 if (!_PyArg_ParseStack(args, nargs, "y*y*:findfactor",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300261 &fragment, &reference)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200262 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300263 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100264
265 if (!_PyArg_NoStackKeywords("findfactor", kwnames)) {
266 goto exit;
267 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200268 return_value = audioop_findfactor_impl(module, &fragment, &reference);
269
270exit:
271 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300272 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200273 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300274 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200275 /* Cleanup for reference */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300276 if (reference.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200277 PyBuffer_Release(&reference);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300278 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200279
280 return return_value;
281}
282
283PyDoc_STRVAR(audioop_findmax__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800284"findmax($module, fragment, length, /)\n"
285"--\n"
286"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200287"Search fragment for a slice of specified number of samples with maximum energy.");
288
289#define AUDIOOP_FINDMAX_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100290 {"findmax", (PyCFunction)audioop_findmax, METH_FASTCALL, audioop_findmax__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200291
292static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300293audioop_findmax_impl(PyObject *module, Py_buffer *fragment,
Larry Hastings89964c42015-04-14 18:07:59 -0400294 Py_ssize_t length);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200295
296static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100297audioop_findmax(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200298{
299 PyObject *return_value = NULL;
300 Py_buffer fragment = {NULL, NULL};
301 Py_ssize_t length;
302
Victor Stinner259f0e42017-01-17 01:35:17 +0100303 if (!_PyArg_ParseStack(args, nargs, "y*n:findmax",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300304 &fragment, &length)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200305 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300306 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100307
308 if (!_PyArg_NoStackKeywords("findmax", kwnames)) {
309 goto exit;
310 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200311 return_value = audioop_findmax_impl(module, &fragment, length);
312
313exit:
314 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300315 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200316 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300317 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200318
319 return return_value;
320}
321
322PyDoc_STRVAR(audioop_avgpp__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800323"avgpp($module, fragment, width, /)\n"
324"--\n"
325"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200326"Return the average peak-peak value over all samples in the fragment.");
327
328#define AUDIOOP_AVGPP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100329 {"avgpp", (PyCFunction)audioop_avgpp, METH_FASTCALL, audioop_avgpp__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200330
331static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300332audioop_avgpp_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200333
334static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100335audioop_avgpp(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200336{
337 PyObject *return_value = NULL;
338 Py_buffer fragment = {NULL, NULL};
339 int width;
340
Victor Stinner259f0e42017-01-17 01:35:17 +0100341 if (!_PyArg_ParseStack(args, nargs, "y*i:avgpp",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300342 &fragment, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200343 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300344 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100345
346 if (!_PyArg_NoStackKeywords("avgpp", kwnames)) {
347 goto exit;
348 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200349 return_value = audioop_avgpp_impl(module, &fragment, width);
350
351exit:
352 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300353 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200354 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300355 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200356
357 return return_value;
358}
359
360PyDoc_STRVAR(audioop_maxpp__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800361"maxpp($module, fragment, width, /)\n"
362"--\n"
363"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200364"Return the maximum peak-peak value in the sound fragment.");
365
366#define AUDIOOP_MAXPP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100367 {"maxpp", (PyCFunction)audioop_maxpp, METH_FASTCALL, audioop_maxpp__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200368
369static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300370audioop_maxpp_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200371
372static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100373audioop_maxpp(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200374{
375 PyObject *return_value = NULL;
376 Py_buffer fragment = {NULL, NULL};
377 int width;
378
Victor Stinner259f0e42017-01-17 01:35:17 +0100379 if (!_PyArg_ParseStack(args, nargs, "y*i:maxpp",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300380 &fragment, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200381 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300382 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100383
384 if (!_PyArg_NoStackKeywords("maxpp", kwnames)) {
385 goto exit;
386 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200387 return_value = audioop_maxpp_impl(module, &fragment, width);
388
389exit:
390 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300391 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200392 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300393 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200394
395 return return_value;
396}
397
398PyDoc_STRVAR(audioop_cross__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800399"cross($module, fragment, width, /)\n"
400"--\n"
401"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200402"Return the number of zero crossings in the fragment passed as an argument.");
403
404#define AUDIOOP_CROSS_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100405 {"cross", (PyCFunction)audioop_cross, METH_FASTCALL, audioop_cross__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200406
407static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300408audioop_cross_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200409
410static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100411audioop_cross(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200412{
413 PyObject *return_value = NULL;
414 Py_buffer fragment = {NULL, NULL};
415 int width;
416
Victor Stinner259f0e42017-01-17 01:35:17 +0100417 if (!_PyArg_ParseStack(args, nargs, "y*i:cross",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300418 &fragment, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200419 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300420 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100421
422 if (!_PyArg_NoStackKeywords("cross", kwnames)) {
423 goto exit;
424 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200425 return_value = audioop_cross_impl(module, &fragment, width);
426
427exit:
428 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300429 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200430 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300431 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200432
433 return return_value;
434}
435
436PyDoc_STRVAR(audioop_mul__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800437"mul($module, fragment, width, factor, /)\n"
438"--\n"
439"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200440"Return a fragment that has all samples in the original fragment multiplied by the floating-point value factor.");
441
442#define AUDIOOP_MUL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100443 {"mul", (PyCFunction)audioop_mul, METH_FASTCALL, audioop_mul__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200444
445static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300446audioop_mul_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -0400447 double factor);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200448
449static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100450audioop_mul(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200451{
452 PyObject *return_value = NULL;
453 Py_buffer fragment = {NULL, NULL};
454 int width;
455 double factor;
456
Victor Stinner259f0e42017-01-17 01:35:17 +0100457 if (!_PyArg_ParseStack(args, nargs, "y*id:mul",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300458 &fragment, &width, &factor)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200459 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300460 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100461
462 if (!_PyArg_NoStackKeywords("mul", kwnames)) {
463 goto exit;
464 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200465 return_value = audioop_mul_impl(module, &fragment, width, factor);
466
467exit:
468 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300469 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200470 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300471 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200472
473 return return_value;
474}
475
476PyDoc_STRVAR(audioop_tomono__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800477"tomono($module, fragment, width, lfactor, rfactor, /)\n"
478"--\n"
479"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200480"Convert a stereo fragment to a mono fragment.");
481
482#define AUDIOOP_TOMONO_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100483 {"tomono", (PyCFunction)audioop_tomono, METH_FASTCALL, audioop_tomono__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200484
485static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300486audioop_tomono_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -0400487 double lfactor, double rfactor);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200488
489static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100490audioop_tomono(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200491{
492 PyObject *return_value = NULL;
493 Py_buffer fragment = {NULL, NULL};
494 int width;
495 double lfactor;
496 double rfactor;
497
Victor Stinner259f0e42017-01-17 01:35:17 +0100498 if (!_PyArg_ParseStack(args, nargs, "y*idd:tomono",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300499 &fragment, &width, &lfactor, &rfactor)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200500 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300501 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100502
503 if (!_PyArg_NoStackKeywords("tomono", kwnames)) {
504 goto exit;
505 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200506 return_value = audioop_tomono_impl(module, &fragment, width, lfactor, rfactor);
507
508exit:
509 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300510 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200511 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300512 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200513
514 return return_value;
515}
516
517PyDoc_STRVAR(audioop_tostereo__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800518"tostereo($module, fragment, width, lfactor, rfactor, /)\n"
519"--\n"
520"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200521"Generate a stereo fragment from a mono fragment.");
522
523#define AUDIOOP_TOSTEREO_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100524 {"tostereo", (PyCFunction)audioop_tostereo, METH_FASTCALL, audioop_tostereo__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200525
526static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300527audioop_tostereo_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -0400528 double lfactor, double rfactor);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200529
530static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100531audioop_tostereo(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200532{
533 PyObject *return_value = NULL;
534 Py_buffer fragment = {NULL, NULL};
535 int width;
536 double lfactor;
537 double rfactor;
538
Victor Stinner259f0e42017-01-17 01:35:17 +0100539 if (!_PyArg_ParseStack(args, nargs, "y*idd:tostereo",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300540 &fragment, &width, &lfactor, &rfactor)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200541 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300542 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100543
544 if (!_PyArg_NoStackKeywords("tostereo", kwnames)) {
545 goto exit;
546 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200547 return_value = audioop_tostereo_impl(module, &fragment, width, lfactor, rfactor);
548
549exit:
550 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300551 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200552 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300553 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200554
555 return return_value;
556}
557
558PyDoc_STRVAR(audioop_add__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800559"add($module, fragment1, fragment2, width, /)\n"
560"--\n"
561"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200562"Return a fragment which is the addition of the two samples passed as parameters.");
563
564#define AUDIOOP_ADD_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100565 {"add", (PyCFunction)audioop_add, METH_FASTCALL, audioop_add__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200566
567static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300568audioop_add_impl(PyObject *module, Py_buffer *fragment1,
Larry Hastings89964c42015-04-14 18:07:59 -0400569 Py_buffer *fragment2, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200570
571static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100572audioop_add(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200573{
574 PyObject *return_value = NULL;
575 Py_buffer fragment1 = {NULL, NULL};
576 Py_buffer fragment2 = {NULL, NULL};
577 int width;
578
Victor Stinner259f0e42017-01-17 01:35:17 +0100579 if (!_PyArg_ParseStack(args, nargs, "y*y*i:add",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300580 &fragment1, &fragment2, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200581 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300582 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100583
584 if (!_PyArg_NoStackKeywords("add", kwnames)) {
585 goto exit;
586 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200587 return_value = audioop_add_impl(module, &fragment1, &fragment2, width);
588
589exit:
590 /* Cleanup for fragment1 */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300591 if (fragment1.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200592 PyBuffer_Release(&fragment1);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300593 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200594 /* Cleanup for fragment2 */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300595 if (fragment2.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200596 PyBuffer_Release(&fragment2);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300597 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200598
599 return return_value;
600}
601
602PyDoc_STRVAR(audioop_bias__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800603"bias($module, fragment, width, bias, /)\n"
604"--\n"
605"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200606"Return a fragment that is the original fragment with a bias added to each sample.");
607
608#define AUDIOOP_BIAS_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100609 {"bias", (PyCFunction)audioop_bias, METH_FASTCALL, audioop_bias__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200610
611static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300612audioop_bias_impl(PyObject *module, Py_buffer *fragment, int width, int bias);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200613
614static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100615audioop_bias(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200616{
617 PyObject *return_value = NULL;
618 Py_buffer fragment = {NULL, NULL};
619 int width;
620 int bias;
621
Victor Stinner259f0e42017-01-17 01:35:17 +0100622 if (!_PyArg_ParseStack(args, nargs, "y*ii:bias",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300623 &fragment, &width, &bias)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200624 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300625 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100626
627 if (!_PyArg_NoStackKeywords("bias", kwnames)) {
628 goto exit;
629 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200630 return_value = audioop_bias_impl(module, &fragment, width, bias);
631
632exit:
633 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300634 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200635 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300636 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200637
638 return return_value;
639}
640
641PyDoc_STRVAR(audioop_reverse__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800642"reverse($module, fragment, width, /)\n"
643"--\n"
644"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200645"Reverse the samples in a fragment and returns the modified fragment.");
646
647#define AUDIOOP_REVERSE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100648 {"reverse", (PyCFunction)audioop_reverse, METH_FASTCALL, audioop_reverse__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200649
650static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300651audioop_reverse_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200652
653static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100654audioop_reverse(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200655{
656 PyObject *return_value = NULL;
657 Py_buffer fragment = {NULL, NULL};
658 int width;
659
Victor Stinner259f0e42017-01-17 01:35:17 +0100660 if (!_PyArg_ParseStack(args, nargs, "y*i:reverse",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300661 &fragment, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200662 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300663 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100664
665 if (!_PyArg_NoStackKeywords("reverse", kwnames)) {
666 goto exit;
667 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200668 return_value = audioop_reverse_impl(module, &fragment, width);
669
670exit:
671 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300672 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200673 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300674 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200675
676 return return_value;
677}
678
679PyDoc_STRVAR(audioop_byteswap__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800680"byteswap($module, fragment, width, /)\n"
681"--\n"
682"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200683"Convert big-endian samples to little-endian and vice versa.");
684
685#define AUDIOOP_BYTESWAP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100686 {"byteswap", (PyCFunction)audioop_byteswap, METH_FASTCALL, audioop_byteswap__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200687
688static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300689audioop_byteswap_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200690
691static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100692audioop_byteswap(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200693{
694 PyObject *return_value = NULL;
695 Py_buffer fragment = {NULL, NULL};
696 int width;
697
Victor Stinner259f0e42017-01-17 01:35:17 +0100698 if (!_PyArg_ParseStack(args, nargs, "y*i:byteswap",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300699 &fragment, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200700 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300701 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100702
703 if (!_PyArg_NoStackKeywords("byteswap", kwnames)) {
704 goto exit;
705 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200706 return_value = audioop_byteswap_impl(module, &fragment, width);
707
708exit:
709 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300710 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200711 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300712 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200713
714 return return_value;
715}
716
717PyDoc_STRVAR(audioop_lin2lin__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800718"lin2lin($module, fragment, width, newwidth, /)\n"
719"--\n"
720"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200721"Convert samples between 1-, 2-, 3- and 4-byte formats.");
722
723#define AUDIOOP_LIN2LIN_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100724 {"lin2lin", (PyCFunction)audioop_lin2lin, METH_FASTCALL, audioop_lin2lin__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200725
726static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300727audioop_lin2lin_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -0400728 int newwidth);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200729
730static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100731audioop_lin2lin(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200732{
733 PyObject *return_value = NULL;
734 Py_buffer fragment = {NULL, NULL};
735 int width;
736 int newwidth;
737
Victor Stinner259f0e42017-01-17 01:35:17 +0100738 if (!_PyArg_ParseStack(args, nargs, "y*ii:lin2lin",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300739 &fragment, &width, &newwidth)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200740 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300741 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100742
743 if (!_PyArg_NoStackKeywords("lin2lin", kwnames)) {
744 goto exit;
745 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200746 return_value = audioop_lin2lin_impl(module, &fragment, width, newwidth);
747
748exit:
749 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300750 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200751 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300752 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200753
754 return return_value;
755}
756
757PyDoc_STRVAR(audioop_ratecv__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800758"ratecv($module, fragment, width, nchannels, inrate, outrate, state,\n"
759" weightA=1, weightB=0, /)\n"
760"--\n"
761"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200762"Convert the frame rate of the input fragment.");
763
764#define AUDIOOP_RATECV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100765 {"ratecv", (PyCFunction)audioop_ratecv, METH_FASTCALL, audioop_ratecv__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200766
767static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300768audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -0400769 int nchannels, int inrate, int outrate, PyObject *state,
770 int weightA, int weightB);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200771
772static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100773audioop_ratecv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200774{
775 PyObject *return_value = NULL;
776 Py_buffer fragment = {NULL, NULL};
777 int width;
778 int nchannels;
779 int inrate;
780 int outrate;
781 PyObject *state;
782 int weightA = 1;
783 int weightB = 0;
784
Victor Stinner259f0e42017-01-17 01:35:17 +0100785 if (!_PyArg_ParseStack(args, nargs, "y*iiiiO|ii:ratecv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300786 &fragment, &width, &nchannels, &inrate, &outrate, &state, &weightA, &weightB)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200787 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300788 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100789
790 if (!_PyArg_NoStackKeywords("ratecv", kwnames)) {
791 goto exit;
792 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200793 return_value = audioop_ratecv_impl(module, &fragment, width, nchannels, inrate, outrate, state, weightA, weightB);
794
795exit:
796 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300797 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200798 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300799 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200800
801 return return_value;
802}
803
804PyDoc_STRVAR(audioop_lin2ulaw__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800805"lin2ulaw($module, fragment, width, /)\n"
806"--\n"
807"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200808"Convert samples in the audio fragment to u-LAW encoding.");
809
810#define AUDIOOP_LIN2ULAW_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100811 {"lin2ulaw", (PyCFunction)audioop_lin2ulaw, METH_FASTCALL, audioop_lin2ulaw__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200812
813static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300814audioop_lin2ulaw_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200815
816static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100817audioop_lin2ulaw(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200818{
819 PyObject *return_value = NULL;
820 Py_buffer fragment = {NULL, NULL};
821 int width;
822
Victor Stinner259f0e42017-01-17 01:35:17 +0100823 if (!_PyArg_ParseStack(args, nargs, "y*i:lin2ulaw",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300824 &fragment, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200825 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300826 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100827
828 if (!_PyArg_NoStackKeywords("lin2ulaw", kwnames)) {
829 goto exit;
830 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200831 return_value = audioop_lin2ulaw_impl(module, &fragment, width);
832
833exit:
834 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300835 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200836 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300837 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200838
839 return return_value;
840}
841
842PyDoc_STRVAR(audioop_ulaw2lin__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800843"ulaw2lin($module, fragment, width, /)\n"
844"--\n"
845"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200846"Convert sound fragments in u-LAW encoding to linearly encoded sound fragments.");
847
848#define AUDIOOP_ULAW2LIN_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100849 {"ulaw2lin", (PyCFunction)audioop_ulaw2lin, METH_FASTCALL, audioop_ulaw2lin__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200850
851static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300852audioop_ulaw2lin_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200853
854static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100855audioop_ulaw2lin(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200856{
857 PyObject *return_value = NULL;
858 Py_buffer fragment = {NULL, NULL};
859 int width;
860
Victor Stinner259f0e42017-01-17 01:35:17 +0100861 if (!_PyArg_ParseStack(args, nargs, "y*i:ulaw2lin",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300862 &fragment, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200863 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300864 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100865
866 if (!_PyArg_NoStackKeywords("ulaw2lin", kwnames)) {
867 goto exit;
868 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200869 return_value = audioop_ulaw2lin_impl(module, &fragment, width);
870
871exit:
872 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300873 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200874 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300875 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200876
877 return return_value;
878}
879
880PyDoc_STRVAR(audioop_lin2alaw__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800881"lin2alaw($module, fragment, width, /)\n"
882"--\n"
883"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200884"Convert samples in the audio fragment to a-LAW encoding.");
885
886#define AUDIOOP_LIN2ALAW_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100887 {"lin2alaw", (PyCFunction)audioop_lin2alaw, METH_FASTCALL, audioop_lin2alaw__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200888
889static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300890audioop_lin2alaw_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200891
892static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100893audioop_lin2alaw(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200894{
895 PyObject *return_value = NULL;
896 Py_buffer fragment = {NULL, NULL};
897 int width;
898
Victor Stinner259f0e42017-01-17 01:35:17 +0100899 if (!_PyArg_ParseStack(args, nargs, "y*i:lin2alaw",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300900 &fragment, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200901 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300902 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100903
904 if (!_PyArg_NoStackKeywords("lin2alaw", kwnames)) {
905 goto exit;
906 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200907 return_value = audioop_lin2alaw_impl(module, &fragment, width);
908
909exit:
910 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300911 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200912 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300913 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200914
915 return return_value;
916}
917
918PyDoc_STRVAR(audioop_alaw2lin__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800919"alaw2lin($module, fragment, width, /)\n"
920"--\n"
921"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200922"Convert sound fragments in a-LAW encoding to linearly encoded sound fragments.");
923
924#define AUDIOOP_ALAW2LIN_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100925 {"alaw2lin", (PyCFunction)audioop_alaw2lin, METH_FASTCALL, audioop_alaw2lin__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200926
927static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300928audioop_alaw2lin_impl(PyObject *module, Py_buffer *fragment, int width);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200929
930static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100931audioop_alaw2lin(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200932{
933 PyObject *return_value = NULL;
934 Py_buffer fragment = {NULL, NULL};
935 int width;
936
Victor Stinner259f0e42017-01-17 01:35:17 +0100937 if (!_PyArg_ParseStack(args, nargs, "y*i:alaw2lin",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300938 &fragment, &width)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200939 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300940 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100941
942 if (!_PyArg_NoStackKeywords("alaw2lin", kwnames)) {
943 goto exit;
944 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200945 return_value = audioop_alaw2lin_impl(module, &fragment, width);
946
947exit:
948 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300949 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200950 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300951 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200952
953 return return_value;
954}
955
956PyDoc_STRVAR(audioop_lin2adpcm__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800957"lin2adpcm($module, fragment, width, state, /)\n"
958"--\n"
959"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200960"Convert samples to 4 bit Intel/DVI ADPCM encoding.");
961
962#define AUDIOOP_LIN2ADPCM_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100963 {"lin2adpcm", (PyCFunction)audioop_lin2adpcm, METH_FASTCALL, audioop_lin2adpcm__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200964
965static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300966audioop_lin2adpcm_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -0400967 PyObject *state);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200968
969static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100970audioop_lin2adpcm(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200971{
972 PyObject *return_value = NULL;
973 Py_buffer fragment = {NULL, NULL};
974 int width;
975 PyObject *state;
976
Victor Stinner259f0e42017-01-17 01:35:17 +0100977 if (!_PyArg_ParseStack(args, nargs, "y*iO:lin2adpcm",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300978 &fragment, &width, &state)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200979 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300980 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100981
982 if (!_PyArg_NoStackKeywords("lin2adpcm", kwnames)) {
983 goto exit;
984 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200985 return_value = audioop_lin2adpcm_impl(module, &fragment, width, state);
986
987exit:
988 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300989 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200990 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300991 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +0200992
993 return return_value;
994}
995
996PyDoc_STRVAR(audioop_adpcm2lin__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800997"adpcm2lin($module, fragment, width, state, /)\n"
998"--\n"
999"\n"
Serhiy Storchaka8d00d732014-01-25 11:57:59 +02001000"Decode an Intel/DVI ADPCM coded fragment to a linear fragment.");
1001
1002#define AUDIOOP_ADPCM2LIN_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001003 {"adpcm2lin", (PyCFunction)audioop_adpcm2lin, METH_FASTCALL, audioop_adpcm2lin__doc__},
Serhiy Storchaka8d00d732014-01-25 11:57:59 +02001004
1005static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001006audioop_adpcm2lin_impl(PyObject *module, Py_buffer *fragment, int width,
Larry Hastings89964c42015-04-14 18:07:59 -04001007 PyObject *state);
Serhiy Storchaka8d00d732014-01-25 11:57:59 +02001008
1009static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01001010audioop_adpcm2lin(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka8d00d732014-01-25 11:57:59 +02001011{
1012 PyObject *return_value = NULL;
1013 Py_buffer fragment = {NULL, NULL};
1014 int width;
1015 PyObject *state;
1016
Victor Stinner259f0e42017-01-17 01:35:17 +01001017 if (!_PyArg_ParseStack(args, nargs, "y*iO:adpcm2lin",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001018 &fragment, &width, &state)) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +02001019 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001020 }
Victor Stinner259f0e42017-01-17 01:35:17 +01001021
1022 if (!_PyArg_NoStackKeywords("adpcm2lin", kwnames)) {
1023 goto exit;
1024 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +02001025 return_value = audioop_adpcm2lin_impl(module, &fragment, width, state);
1026
1027exit:
1028 /* Cleanup for fragment */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001029 if (fragment.obj) {
Serhiy Storchaka8d00d732014-01-25 11:57:59 +02001030 PyBuffer_Release(&fragment);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001031 }
Serhiy Storchaka8d00d732014-01-25 11:57:59 +02001032
1033 return return_value;
1034}
Victor Stinner259f0e42017-01-17 01:35:17 +01001035/*[clinic end generated code: output=ee7c63ec28a11b78 input=a9049054013a1b77]*/