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