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