LCOV - code coverage report
Current view: top level - Modules/clinic - audioop.c.h (source / functions) Hit Total Coverage
Test: CPython lcov report Lines: 423 555 76.2 %
Date: 2022-07-07 18:19:46 Functions: 26 26 100.0 %

          Line data    Source code
       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_CAST(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 *
      19          33 : audioop_getsample(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
      20             : {
      21          33 :     PyObject *return_value = NULL;
      22          33 :     Py_buffer fragment = {NULL, NULL};
      23             :     int width;
      24             :     Py_ssize_t index;
      25             : 
      26          33 :     if (!_PyArg_CheckPositional("getsample", nargs, 3, 3)) {
      27           0 :         goto exit;
      28             :     }
      29          33 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
      30           1 :         goto exit;
      31             :     }
      32          32 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
      33           0 :         _PyArg_BadArgument("getsample", "argument 1", "contiguous buffer", args[0]);
      34           0 :         goto exit;
      35             :     }
      36          32 :     width = _PyLong_AsInt(args[1]);
      37          32 :     if (width == -1 && PyErr_Occurred()) {
      38           0 :         goto exit;
      39             :     }
      40             :     {
      41          32 :         Py_ssize_t ival = -1;
      42          32 :         PyObject *iobj = _PyNumber_Index(args[2]);
      43          32 :         if (iobj != NULL) {
      44          32 :             ival = PyLong_AsSsize_t(iobj);
      45          32 :             Py_DECREF(iobj);
      46             :         }
      47          32 :         if (ival == -1 && PyErr_Occurred()) {
      48           0 :             goto exit;
      49             :         }
      50          32 :         index = ival;
      51             :     }
      52          32 :     return_value = audioop_getsample_impl(module, &fragment, width, index);
      53             : 
      54          33 : exit:
      55             :     /* Cleanup for fragment */
      56          33 :     if (fragment.obj) {
      57          32 :        PyBuffer_Release(&fragment);
      58             :     }
      59             : 
      60          33 :     return return_value;
      61             : }
      62             : 
      63             : PyDoc_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_CAST(audioop_max), METH_FASTCALL, audioop_max__doc__},
      71             : 
      72             : static PyObject *
      73             : audioop_max_impl(PyObject *module, Py_buffer *fragment, int width);
      74             : 
      75             : static PyObject *
      76          37 : audioop_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
      77             : {
      78          37 :     PyObject *return_value = NULL;
      79          37 :     Py_buffer fragment = {NULL, NULL};
      80             :     int width;
      81             : 
      82          37 :     if (!_PyArg_CheckPositional("max", nargs, 2, 2)) {
      83           0 :         goto exit;
      84             :     }
      85          37 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
      86           1 :         goto exit;
      87             :     }
      88          36 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
      89           0 :         _PyArg_BadArgument("max", "argument 1", "contiguous buffer", args[0]);
      90           0 :         goto exit;
      91             :     }
      92          36 :     width = _PyLong_AsInt(args[1]);
      93          36 :     if (width == -1 && PyErr_Occurred()) {
      94           0 :         goto exit;
      95             :     }
      96          36 :     return_value = audioop_max_impl(module, &fragment, width);
      97             : 
      98          37 : exit:
      99             :     /* Cleanup for fragment */
     100          37 :     if (fragment.obj) {
     101          36 :        PyBuffer_Release(&fragment);
     102             :     }
     103             : 
     104          37 :     return return_value;
     105             : }
     106             : 
     107             : PyDoc_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_CAST(audioop_minmax), METH_FASTCALL, audioop_minmax__doc__},
     115             : 
     116             : static PyObject *
     117             : audioop_minmax_impl(PyObject *module, Py_buffer *fragment, int width);
     118             : 
     119             : static PyObject *
     120          37 : audioop_minmax(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     121             : {
     122          37 :     PyObject *return_value = NULL;
     123          37 :     Py_buffer fragment = {NULL, NULL};
     124             :     int width;
     125             : 
     126          37 :     if (!_PyArg_CheckPositional("minmax", nargs, 2, 2)) {
     127           0 :         goto exit;
     128             :     }
     129          37 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     130           1 :         goto exit;
     131             :     }
     132          36 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     133           0 :         _PyArg_BadArgument("minmax", "argument 1", "contiguous buffer", args[0]);
     134           0 :         goto exit;
     135             :     }
     136          36 :     width = _PyLong_AsInt(args[1]);
     137          36 :     if (width == -1 && PyErr_Occurred()) {
     138           0 :         goto exit;
     139             :     }
     140          36 :     return_value = audioop_minmax_impl(module, &fragment, width);
     141             : 
     142          37 : exit:
     143             :     /* Cleanup for fragment */
     144          37 :     if (fragment.obj) {
     145          36 :        PyBuffer_Release(&fragment);
     146             :     }
     147             : 
     148          37 :     return return_value;
     149             : }
     150             : 
     151             : PyDoc_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_CAST(audioop_avg), METH_FASTCALL, audioop_avg__doc__},
     159             : 
     160             : static PyObject *
     161             : audioop_avg_impl(PyObject *module, Py_buffer *fragment, int width);
     162             : 
     163             : static PyObject *
     164          39 : audioop_avg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     165             : {
     166          39 :     PyObject *return_value = NULL;
     167          39 :     Py_buffer fragment = {NULL, NULL};
     168             :     int width;
     169             : 
     170          39 :     if (!_PyArg_CheckPositional("avg", nargs, 2, 2)) {
     171           0 :         goto exit;
     172             :     }
     173          39 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     174           1 :         goto exit;
     175             :     }
     176          38 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     177           0 :         _PyArg_BadArgument("avg", "argument 1", "contiguous buffer", args[0]);
     178           0 :         goto exit;
     179             :     }
     180          38 :     width = _PyLong_AsInt(args[1]);
     181          38 :     if (width == -1 && PyErr_Occurred()) {
     182           0 :         goto exit;
     183             :     }
     184          38 :     return_value = audioop_avg_impl(module, &fragment, width);
     185             : 
     186          39 : exit:
     187             :     /* Cleanup for fragment */
     188          39 :     if (fragment.obj) {
     189          38 :        PyBuffer_Release(&fragment);
     190             :     }
     191             : 
     192          39 :     return return_value;
     193             : }
     194             : 
     195             : PyDoc_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_CAST(audioop_rms), METH_FASTCALL, audioop_rms__doc__},
     203             : 
     204             : static PyObject *
     205             : audioop_rms_impl(PyObject *module, Py_buffer *fragment, int width);
     206             : 
     207             : static PyObject *
     208          33 : audioop_rms(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     209             : {
     210          33 :     PyObject *return_value = NULL;
     211          33 :     Py_buffer fragment = {NULL, NULL};
     212             :     int width;
     213             : 
     214          33 :     if (!_PyArg_CheckPositional("rms", nargs, 2, 2)) {
     215           0 :         goto exit;
     216             :     }
     217          33 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     218           1 :         goto exit;
     219             :     }
     220          32 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     221           0 :         _PyArg_BadArgument("rms", "argument 1", "contiguous buffer", args[0]);
     222           0 :         goto exit;
     223             :     }
     224          32 :     width = _PyLong_AsInt(args[1]);
     225          32 :     if (width == -1 && PyErr_Occurred()) {
     226           0 :         goto exit;
     227             :     }
     228          32 :     return_value = audioop_rms_impl(module, &fragment, width);
     229             : 
     230          33 : exit:
     231             :     /* Cleanup for fragment */
     232          33 :     if (fragment.obj) {
     233          32 :        PyBuffer_Release(&fragment);
     234             :     }
     235             : 
     236          33 :     return return_value;
     237             : }
     238             : 
     239             : PyDoc_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_CAST(audioop_findfit), METH_FASTCALL, audioop_findfit__doc__},
     247             : 
     248             : static PyObject *
     249             : audioop_findfit_impl(PyObject *module, Py_buffer *fragment,
     250             :                      Py_buffer *reference);
     251             : 
     252             : static PyObject *
     253           5 : audioop_findfit(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     254             : {
     255           5 :     PyObject *return_value = NULL;
     256           5 :     Py_buffer fragment = {NULL, NULL};
     257           5 :     Py_buffer reference = {NULL, NULL};
     258             : 
     259           5 :     if (!_PyArg_CheckPositional("findfit", nargs, 2, 2)) {
     260           0 :         goto exit;
     261             :     }
     262           5 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     263           0 :         goto exit;
     264             :     }
     265           5 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     266           0 :         _PyArg_BadArgument("findfit", "argument 1", "contiguous buffer", args[0]);
     267           0 :         goto exit;
     268             :     }
     269           5 :     if (PyObject_GetBuffer(args[1], &reference, PyBUF_SIMPLE) != 0) {
     270           0 :         goto exit;
     271             :     }
     272           5 :     if (!PyBuffer_IsContiguous(&reference, 'C')) {
     273           0 :         _PyArg_BadArgument("findfit", "argument 2", "contiguous buffer", args[1]);
     274           0 :         goto exit;
     275             :     }
     276           5 :     return_value = audioop_findfit_impl(module, &fragment, &reference);
     277             : 
     278           5 : exit:
     279             :     /* Cleanup for fragment */
     280           5 :     if (fragment.obj) {
     281           5 :        PyBuffer_Release(&fragment);
     282             :     }
     283             :     /* Cleanup for reference */
     284           5 :     if (reference.obj) {
     285           5 :        PyBuffer_Release(&reference);
     286             :     }
     287             : 
     288           5 :     return return_value;
     289             : }
     290             : 
     291             : PyDoc_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_CAST(audioop_findfactor), METH_FASTCALL, audioop_findfactor__doc__},
     299             : 
     300             : static PyObject *
     301             : audioop_findfactor_impl(PyObject *module, Py_buffer *fragment,
     302             :                         Py_buffer *reference);
     303             : 
     304             : static PyObject *
     305           4 : audioop_findfactor(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     306             : {
     307           4 :     PyObject *return_value = NULL;
     308           4 :     Py_buffer fragment = {NULL, NULL};
     309           4 :     Py_buffer reference = {NULL, NULL};
     310             : 
     311           4 :     if (!_PyArg_CheckPositional("findfactor", nargs, 2, 2)) {
     312           0 :         goto exit;
     313             :     }
     314           4 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     315           0 :         goto exit;
     316             :     }
     317           4 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     318           0 :         _PyArg_BadArgument("findfactor", "argument 1", "contiguous buffer", args[0]);
     319           0 :         goto exit;
     320             :     }
     321           4 :     if (PyObject_GetBuffer(args[1], &reference, PyBUF_SIMPLE) != 0) {
     322           0 :         goto exit;
     323             :     }
     324           4 :     if (!PyBuffer_IsContiguous(&reference, 'C')) {
     325           0 :         _PyArg_BadArgument("findfactor", "argument 2", "contiguous buffer", args[1]);
     326           0 :         goto exit;
     327             :     }
     328           4 :     return_value = audioop_findfactor_impl(module, &fragment, &reference);
     329             : 
     330           4 : exit:
     331             :     /* Cleanup for fragment */
     332           4 :     if (fragment.obj) {
     333           4 :        PyBuffer_Release(&fragment);
     334             :     }
     335             :     /* Cleanup for reference */
     336           4 :     if (reference.obj) {
     337           4 :        PyBuffer_Release(&reference);
     338             :     }
     339             : 
     340           4 :     return return_value;
     341             : }
     342             : 
     343             : PyDoc_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_CAST(audioop_findmax), METH_FASTCALL, audioop_findmax__doc__},
     351             : 
     352             : static PyObject *
     353             : audioop_findmax_impl(PyObject *module, Py_buffer *fragment,
     354             :                      Py_ssize_t length);
     355             : 
     356             : static PyObject *
     357           4 : audioop_findmax(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     358             : {
     359           4 :     PyObject *return_value = NULL;
     360           4 :     Py_buffer fragment = {NULL, NULL};
     361             :     Py_ssize_t length;
     362             : 
     363           4 :     if (!_PyArg_CheckPositional("findmax", nargs, 2, 2)) {
     364           0 :         goto exit;
     365             :     }
     366           4 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     367           0 :         goto exit;
     368             :     }
     369           4 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     370           0 :         _PyArg_BadArgument("findmax", "argument 1", "contiguous buffer", args[0]);
     371           0 :         goto exit;
     372             :     }
     373             :     {
     374           4 :         Py_ssize_t ival = -1;
     375           4 :         PyObject *iobj = _PyNumber_Index(args[1]);
     376           4 :         if (iobj != NULL) {
     377           4 :             ival = PyLong_AsSsize_t(iobj);
     378           4 :             Py_DECREF(iobj);
     379             :         }
     380           4 :         if (ival == -1 && PyErr_Occurred()) {
     381           0 :             goto exit;
     382             :         }
     383           4 :         length = ival;
     384             :     }
     385           4 :     return_value = audioop_findmax_impl(module, &fragment, length);
     386             : 
     387           4 : exit:
     388             :     /* Cleanup for fragment */
     389           4 :     if (fragment.obj) {
     390           4 :        PyBuffer_Release(&fragment);
     391             :     }
     392             : 
     393           4 :     return return_value;
     394             : }
     395             : 
     396             : PyDoc_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_CAST(audioop_avgpp), METH_FASTCALL, audioop_avgpp__doc__},
     404             : 
     405             : static PyObject *
     406             : audioop_avgpp_impl(PyObject *module, Py_buffer *fragment, int width);
     407             : 
     408             : static PyObject *
     409          29 : audioop_avgpp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     410             : {
     411          29 :     PyObject *return_value = NULL;
     412          29 :     Py_buffer fragment = {NULL, NULL};
     413             :     int width;
     414             : 
     415          29 :     if (!_PyArg_CheckPositional("avgpp", nargs, 2, 2)) {
     416           0 :         goto exit;
     417             :     }
     418          29 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     419           1 :         goto exit;
     420             :     }
     421          28 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     422           0 :         _PyArg_BadArgument("avgpp", "argument 1", "contiguous buffer", args[0]);
     423           0 :         goto exit;
     424             :     }
     425          28 :     width = _PyLong_AsInt(args[1]);
     426          28 :     if (width == -1 && PyErr_Occurred()) {
     427           0 :         goto exit;
     428             :     }
     429          28 :     return_value = audioop_avgpp_impl(module, &fragment, width);
     430             : 
     431          29 : exit:
     432             :     /* Cleanup for fragment */
     433          29 :     if (fragment.obj) {
     434          28 :        PyBuffer_Release(&fragment);
     435             :     }
     436             : 
     437          29 :     return return_value;
     438             : }
     439             : 
     440             : PyDoc_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_CAST(audioop_maxpp), METH_FASTCALL, audioop_maxpp__doc__},
     448             : 
     449             : static PyObject *
     450             : audioop_maxpp_impl(PyObject *module, Py_buffer *fragment, int width);
     451             : 
     452             : static PyObject *
     453          29 : audioop_maxpp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     454             : {
     455          29 :     PyObject *return_value = NULL;
     456          29 :     Py_buffer fragment = {NULL, NULL};
     457             :     int width;
     458             : 
     459          29 :     if (!_PyArg_CheckPositional("maxpp", nargs, 2, 2)) {
     460           0 :         goto exit;
     461             :     }
     462          29 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     463           1 :         goto exit;
     464             :     }
     465          28 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     466           0 :         _PyArg_BadArgument("maxpp", "argument 1", "contiguous buffer", args[0]);
     467           0 :         goto exit;
     468             :     }
     469          28 :     width = _PyLong_AsInt(args[1]);
     470          28 :     if (width == -1 && PyErr_Occurred()) {
     471           0 :         goto exit;
     472             :     }
     473          28 :     return_value = audioop_maxpp_impl(module, &fragment, width);
     474             : 
     475          29 : exit:
     476             :     /* Cleanup for fragment */
     477          29 :     if (fragment.obj) {
     478          28 :        PyBuffer_Release(&fragment);
     479             :     }
     480             : 
     481          29 :     return return_value;
     482             : }
     483             : 
     484             : PyDoc_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_CAST(audioop_cross), METH_FASTCALL, audioop_cross__doc__},
     492             : 
     493             : static PyObject *
     494             : audioop_cross_impl(PyObject *module, Py_buffer *fragment, int width);
     495             : 
     496             : static PyObject *
     497          37 : audioop_cross(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     498             : {
     499          37 :     PyObject *return_value = NULL;
     500          37 :     Py_buffer fragment = {NULL, NULL};
     501             :     int width;
     502             : 
     503          37 :     if (!_PyArg_CheckPositional("cross", nargs, 2, 2)) {
     504           0 :         goto exit;
     505             :     }
     506          37 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     507           1 :         goto exit;
     508             :     }
     509          36 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     510           0 :         _PyArg_BadArgument("cross", "argument 1", "contiguous buffer", args[0]);
     511           0 :         goto exit;
     512             :     }
     513          36 :     width = _PyLong_AsInt(args[1]);
     514          36 :     if (width == -1 && PyErr_Occurred()) {
     515           0 :         goto exit;
     516             :     }
     517          36 :     return_value = audioop_cross_impl(module, &fragment, width);
     518             : 
     519          37 : exit:
     520             :     /* Cleanup for fragment */
     521          37 :     if (fragment.obj) {
     522          36 :        PyBuffer_Release(&fragment);
     523             :     }
     524             : 
     525          37 :     return return_value;
     526             : }
     527             : 
     528             : PyDoc_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_CAST(audioop_mul), METH_FASTCALL, audioop_mul__doc__},
     536             : 
     537             : static PyObject *
     538             : audioop_mul_impl(PyObject *module, Py_buffer *fragment, int width,
     539             :                  double factor);
     540             : 
     541             : static PyObject *
     542          29 : audioop_mul(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     543             : {
     544          29 :     PyObject *return_value = NULL;
     545          29 :     Py_buffer fragment = {NULL, NULL};
     546             :     int width;
     547             :     double factor;
     548             : 
     549          29 :     if (!_PyArg_CheckPositional("mul", nargs, 3, 3)) {
     550           0 :         goto exit;
     551             :     }
     552          29 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     553           1 :         goto exit;
     554             :     }
     555          28 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     556           0 :         _PyArg_BadArgument("mul", "argument 1", "contiguous buffer", args[0]);
     557           0 :         goto exit;
     558             :     }
     559          28 :     width = _PyLong_AsInt(args[1]);
     560          28 :     if (width == -1 && PyErr_Occurred()) {
     561           0 :         goto exit;
     562             :     }
     563          28 :     if (PyFloat_CheckExact(args[2])) {
     564           4 :         factor = PyFloat_AS_DOUBLE(args[2]);
     565             :     }
     566             :     else
     567             :     {
     568          24 :         factor = PyFloat_AsDouble(args[2]);
     569          24 :         if (factor == -1.0 && PyErr_Occurred()) {
     570           0 :             goto exit;
     571             :         }
     572             :     }
     573          28 :     return_value = audioop_mul_impl(module, &fragment, width, factor);
     574             : 
     575          29 : exit:
     576             :     /* Cleanup for fragment */
     577          29 :     if (fragment.obj) {
     578          28 :        PyBuffer_Release(&fragment);
     579             :     }
     580             : 
     581          29 :     return return_value;
     582             : }
     583             : 
     584             : PyDoc_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_CAST(audioop_tomono), METH_FASTCALL, audioop_tomono__doc__},
     592             : 
     593             : static PyObject *
     594             : audioop_tomono_impl(PyObject *module, Py_buffer *fragment, int width,
     595             :                     double lfactor, double rfactor);
     596             : 
     597             : static PyObject *
     598          25 : audioop_tomono(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     599             : {
     600          25 :     PyObject *return_value = NULL;
     601          25 :     Py_buffer fragment = {NULL, NULL};
     602             :     int width;
     603             :     double lfactor;
     604             :     double rfactor;
     605             : 
     606          25 :     if (!_PyArg_CheckPositional("tomono", nargs, 4, 4)) {
     607           0 :         goto exit;
     608             :     }
     609          25 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     610           1 :         goto exit;
     611             :     }
     612          24 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     613           0 :         _PyArg_BadArgument("tomono", "argument 1", "contiguous buffer", args[0]);
     614           0 :         goto exit;
     615             :     }
     616          24 :     width = _PyLong_AsInt(args[1]);
     617          24 :     if (width == -1 && PyErr_Occurred()) {
     618           0 :         goto exit;
     619             :     }
     620          24 :     if (PyFloat_CheckExact(args[2])) {
     621          16 :         lfactor = PyFloat_AS_DOUBLE(args[2]);
     622             :     }
     623             :     else
     624             :     {
     625           8 :         lfactor = PyFloat_AsDouble(args[2]);
     626           8 :         if (lfactor == -1.0 && PyErr_Occurred()) {
     627           0 :             goto exit;
     628             :         }
     629             :     }
     630          24 :     if (PyFloat_CheckExact(args[3])) {
     631          16 :         rfactor = PyFloat_AS_DOUBLE(args[3]);
     632             :     }
     633             :     else
     634             :     {
     635           8 :         rfactor = PyFloat_AsDouble(args[3]);
     636           8 :         if (rfactor == -1.0 && PyErr_Occurred()) {
     637           0 :             goto exit;
     638             :         }
     639             :     }
     640          24 :     return_value = audioop_tomono_impl(module, &fragment, width, lfactor, rfactor);
     641             : 
     642          25 : exit:
     643             :     /* Cleanup for fragment */
     644          25 :     if (fragment.obj) {
     645          24 :        PyBuffer_Release(&fragment);
     646             :     }
     647             : 
     648          25 :     return return_value;
     649             : }
     650             : 
     651             : PyDoc_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_CAST(audioop_tostereo), METH_FASTCALL, audioop_tostereo__doc__},
     659             : 
     660             : static PyObject *
     661             : audioop_tostereo_impl(PyObject *module, Py_buffer *fragment, int width,
     662             :                       double lfactor, double rfactor);
     663             : 
     664             : static PyObject *
     665          25 : audioop_tostereo(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     666             : {
     667          25 :     PyObject *return_value = NULL;
     668          25 :     Py_buffer fragment = {NULL, NULL};
     669             :     int width;
     670             :     double lfactor;
     671             :     double rfactor;
     672             : 
     673          25 :     if (!_PyArg_CheckPositional("tostereo", nargs, 4, 4)) {
     674           0 :         goto exit;
     675             :     }
     676          25 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     677           1 :         goto exit;
     678             :     }
     679          24 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     680           0 :         _PyArg_BadArgument("tostereo", "argument 1", "contiguous buffer", args[0]);
     681           0 :         goto exit;
     682             :     }
     683          24 :     width = _PyLong_AsInt(args[1]);
     684          24 :     if (width == -1 && PyErr_Occurred()) {
     685           0 :         goto exit;
     686             :     }
     687          24 :     if (PyFloat_CheckExact(args[2])) {
     688           4 :         lfactor = PyFloat_AS_DOUBLE(args[2]);
     689             :     }
     690             :     else
     691             :     {
     692          20 :         lfactor = PyFloat_AsDouble(args[2]);
     693          20 :         if (lfactor == -1.0 && PyErr_Occurred()) {
     694           0 :             goto exit;
     695             :         }
     696             :     }
     697          24 :     if (PyFloat_CheckExact(args[3])) {
     698           4 :         rfactor = PyFloat_AS_DOUBLE(args[3]);
     699             :     }
     700             :     else
     701             :     {
     702          20 :         rfactor = PyFloat_AsDouble(args[3]);
     703          20 :         if (rfactor == -1.0 && PyErr_Occurred()) {
     704           0 :             goto exit;
     705             :         }
     706             :     }
     707          24 :     return_value = audioop_tostereo_impl(module, &fragment, width, lfactor, rfactor);
     708             : 
     709          25 : exit:
     710             :     /* Cleanup for fragment */
     711          25 :     if (fragment.obj) {
     712          24 :        PyBuffer_Release(&fragment);
     713             :     }
     714             : 
     715          25 :     return return_value;
     716             : }
     717             : 
     718             : PyDoc_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_CAST(audioop_add), METH_FASTCALL, audioop_add__doc__},
     726             : 
     727             : static PyObject *
     728             : audioop_add_impl(PyObject *module, Py_buffer *fragment1,
     729             :                  Py_buffer *fragment2, int width);
     730             : 
     731             : static PyObject *
     732          25 : audioop_add(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     733             : {
     734          25 :     PyObject *return_value = NULL;
     735          25 :     Py_buffer fragment1 = {NULL, NULL};
     736          25 :     Py_buffer fragment2 = {NULL, NULL};
     737             :     int width;
     738             : 
     739          25 :     if (!_PyArg_CheckPositional("add", nargs, 3, 3)) {
     740           0 :         goto exit;
     741             :     }
     742          25 :     if (PyObject_GetBuffer(args[0], &fragment1, PyBUF_SIMPLE) != 0) {
     743           1 :         goto exit;
     744             :     }
     745          24 :     if (!PyBuffer_IsContiguous(&fragment1, 'C')) {
     746           0 :         _PyArg_BadArgument("add", "argument 1", "contiguous buffer", args[0]);
     747           0 :         goto exit;
     748             :     }
     749          24 :     if (PyObject_GetBuffer(args[1], &fragment2, PyBUF_SIMPLE) != 0) {
     750           0 :         goto exit;
     751             :     }
     752          24 :     if (!PyBuffer_IsContiguous(&fragment2, 'C')) {
     753           0 :         _PyArg_BadArgument("add", "argument 2", "contiguous buffer", args[1]);
     754           0 :         goto exit;
     755             :     }
     756          24 :     width = _PyLong_AsInt(args[2]);
     757          24 :     if (width == -1 && PyErr_Occurred()) {
     758           0 :         goto exit;
     759             :     }
     760          24 :     return_value = audioop_add_impl(module, &fragment1, &fragment2, width);
     761             : 
     762          25 : exit:
     763             :     /* Cleanup for fragment1 */
     764          25 :     if (fragment1.obj) {
     765          24 :        PyBuffer_Release(&fragment1);
     766             :     }
     767             :     /* Cleanup for fragment2 */
     768          25 :     if (fragment2.obj) {
     769          24 :        PyBuffer_Release(&fragment2);
     770             :     }
     771             : 
     772          25 :     return return_value;
     773             : }
     774             : 
     775             : PyDoc_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_CAST(audioop_bias), METH_FASTCALL, audioop_bias__doc__},
     783             : 
     784             : static PyObject *
     785             : audioop_bias_impl(PyObject *module, Py_buffer *fragment, int width, int bias);
     786             : 
     787             : static PyObject *
     788         105 : audioop_bias(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     789             : {
     790         105 :     PyObject *return_value = NULL;
     791         105 :     Py_buffer fragment = {NULL, NULL};
     792             :     int width;
     793             :     int bias;
     794             : 
     795         105 :     if (!_PyArg_CheckPositional("bias", nargs, 3, 3)) {
     796           0 :         goto exit;
     797             :     }
     798         105 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     799           1 :         goto exit;
     800             :     }
     801         104 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     802           0 :         _PyArg_BadArgument("bias", "argument 1", "contiguous buffer", args[0]);
     803           0 :         goto exit;
     804             :     }
     805         104 :     width = _PyLong_AsInt(args[1]);
     806         104 :     if (width == -1 && PyErr_Occurred()) {
     807           0 :         goto exit;
     808             :     }
     809         104 :     bias = _PyLong_AsInt(args[2]);
     810         104 :     if (bias == -1 && PyErr_Occurred()) {
     811           0 :         goto exit;
     812             :     }
     813         104 :     return_value = audioop_bias_impl(module, &fragment, width, bias);
     814             : 
     815         105 : exit:
     816             :     /* Cleanup for fragment */
     817         105 :     if (fragment.obj) {
     818         104 :        PyBuffer_Release(&fragment);
     819             :     }
     820             : 
     821         105 :     return return_value;
     822             : }
     823             : 
     824             : PyDoc_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_CAST(audioop_reverse), METH_FASTCALL, audioop_reverse__doc__},
     832             : 
     833             : static PyObject *
     834             : audioop_reverse_impl(PyObject *module, Py_buffer *fragment, int width);
     835             : 
     836             : static PyObject *
     837          21 : audioop_reverse(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     838             : {
     839          21 :     PyObject *return_value = NULL;
     840          21 :     Py_buffer fragment = {NULL, NULL};
     841             :     int width;
     842             : 
     843          21 :     if (!_PyArg_CheckPositional("reverse", nargs, 2, 2)) {
     844           0 :         goto exit;
     845             :     }
     846          21 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     847           1 :         goto exit;
     848             :     }
     849          20 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     850           0 :         _PyArg_BadArgument("reverse", "argument 1", "contiguous buffer", args[0]);
     851           0 :         goto exit;
     852             :     }
     853          20 :     width = _PyLong_AsInt(args[1]);
     854          20 :     if (width == -1 && PyErr_Occurred()) {
     855           0 :         goto exit;
     856             :     }
     857          20 :     return_value = audioop_reverse_impl(module, &fragment, width);
     858             : 
     859          21 : exit:
     860             :     /* Cleanup for fragment */
     861          21 :     if (fragment.obj) {
     862          20 :        PyBuffer_Release(&fragment);
     863             :     }
     864             : 
     865          21 :     return return_value;
     866             : }
     867             : 
     868             : PyDoc_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_CAST(audioop_byteswap), METH_FASTCALL, audioop_byteswap__doc__},
     876             : 
     877             : static PyObject *
     878             : audioop_byteswap_impl(PyObject *module, Py_buffer *fragment, int width);
     879             : 
     880             : static PyObject *
     881          23 : audioop_byteswap(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     882             : {
     883          23 :     PyObject *return_value = NULL;
     884          23 :     Py_buffer fragment = {NULL, NULL};
     885             :     int width;
     886             : 
     887          23 :     if (!_PyArg_CheckPositional("byteswap", nargs, 2, 2)) {
     888           0 :         goto exit;
     889             :     }
     890          23 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     891           0 :         goto exit;
     892             :     }
     893          23 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     894           0 :         _PyArg_BadArgument("byteswap", "argument 1", "contiguous buffer", args[0]);
     895           0 :         goto exit;
     896             :     }
     897          23 :     width = _PyLong_AsInt(args[1]);
     898          23 :     if (width == -1 && PyErr_Occurred()) {
     899           0 :         goto exit;
     900             :     }
     901          23 :     return_value = audioop_byteswap_impl(module, &fragment, width);
     902             : 
     903          23 : exit:
     904             :     /* Cleanup for fragment */
     905          23 :     if (fragment.obj) {
     906          23 :        PyBuffer_Release(&fragment);
     907             :     }
     908             : 
     909          23 :     return return_value;
     910             : }
     911             : 
     912             : PyDoc_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_CAST(audioop_lin2lin), METH_FASTCALL, audioop_lin2lin__doc__},
     920             : 
     921             : static PyObject *
     922             : audioop_lin2lin_impl(PyObject *module, Py_buffer *fragment, int width,
     923             :                      int newwidth);
     924             : 
     925             : static PyObject *
     926          29 : audioop_lin2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     927             : {
     928          29 :     PyObject *return_value = NULL;
     929          29 :     Py_buffer fragment = {NULL, NULL};
     930             :     int width;
     931             :     int newwidth;
     932             : 
     933          29 :     if (!_PyArg_CheckPositional("lin2lin", nargs, 3, 3)) {
     934           0 :         goto exit;
     935             :     }
     936          29 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     937           1 :         goto exit;
     938             :     }
     939          28 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     940           0 :         _PyArg_BadArgument("lin2lin", "argument 1", "contiguous buffer", args[0]);
     941           0 :         goto exit;
     942             :     }
     943          28 :     width = _PyLong_AsInt(args[1]);
     944          28 :     if (width == -1 && PyErr_Occurred()) {
     945           0 :         goto exit;
     946             :     }
     947          28 :     newwidth = _PyLong_AsInt(args[2]);
     948          28 :     if (newwidth == -1 && PyErr_Occurred()) {
     949           0 :         goto exit;
     950             :     }
     951          28 :     return_value = audioop_lin2lin_impl(module, &fragment, width, newwidth);
     952             : 
     953          29 : exit:
     954             :     /* Cleanup for fragment */
     955          29 :     if (fragment.obj) {
     956          28 :        PyBuffer_Release(&fragment);
     957             :     }
     958             : 
     959          29 :     return return_value;
     960             : }
     961             : 
     962             : PyDoc_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_CAST(audioop_ratecv), METH_FASTCALL, audioop_ratecv__doc__},
     971             : 
     972             : static PyObject *
     973             : audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
     974             :                     int nchannels, int inrate, int outrate, PyObject *state,
     975             :                     int weightA, int weightB);
     976             : 
     977             : static PyObject *
     978          77 : audioop_ratecv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     979             : {
     980          77 :     PyObject *return_value = NULL;
     981          77 :     Py_buffer fragment = {NULL, NULL};
     982             :     int width;
     983             :     int nchannels;
     984             :     int inrate;
     985             :     int outrate;
     986             :     PyObject *state;
     987          77 :     int weightA = 1;
     988          77 :     int weightB = 0;
     989             : 
     990          77 :     if (!_PyArg_CheckPositional("ratecv", nargs, 6, 8)) {
     991           0 :         goto exit;
     992             :     }
     993          77 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
     994           1 :         goto exit;
     995             :     }
     996          76 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
     997           0 :         _PyArg_BadArgument("ratecv", "argument 1", "contiguous buffer", args[0]);
     998           0 :         goto exit;
     999             :     }
    1000          76 :     width = _PyLong_AsInt(args[1]);
    1001          76 :     if (width == -1 && PyErr_Occurred()) {
    1002           0 :         goto exit;
    1003             :     }
    1004          76 :     nchannels = _PyLong_AsInt(args[2]);
    1005          76 :     if (nchannels == -1 && PyErr_Occurred()) {
    1006           0 :         goto exit;
    1007             :     }
    1008          76 :     inrate = _PyLong_AsInt(args[3]);
    1009          76 :     if (inrate == -1 && PyErr_Occurred()) {
    1010           0 :         goto exit;
    1011             :     }
    1012          76 :     outrate = _PyLong_AsInt(args[4]);
    1013          76 :     if (outrate == -1 && PyErr_Occurred()) {
    1014           0 :         goto exit;
    1015             :     }
    1016          76 :     state = args[5];
    1017          76 :     if (nargs < 7) {
    1018          64 :         goto skip_optional;
    1019             :     }
    1020          12 :     weightA = _PyLong_AsInt(args[6]);
    1021          12 :     if (weightA == -1 && PyErr_Occurred()) {
    1022           0 :         goto exit;
    1023             :     }
    1024          12 :     if (nargs < 8) {
    1025           0 :         goto skip_optional;
    1026             :     }
    1027          12 :     weightB = _PyLong_AsInt(args[7]);
    1028          12 :     if (weightB == -1 && PyErr_Occurred()) {
    1029           0 :         goto exit;
    1030             :     }
    1031          12 : skip_optional:
    1032          76 :     return_value = audioop_ratecv_impl(module, &fragment, width, nchannels, inrate, outrate, state, weightA, weightB);
    1033             : 
    1034          77 : exit:
    1035             :     /* Cleanup for fragment */
    1036          77 :     if (fragment.obj) {
    1037          76 :        PyBuffer_Release(&fragment);
    1038             :     }
    1039             : 
    1040          77 :     return return_value;
    1041             : }
    1042             : 
    1043             : PyDoc_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_CAST(audioop_lin2ulaw), METH_FASTCALL, audioop_lin2ulaw__doc__},
    1051             : 
    1052             : static PyObject *
    1053             : audioop_lin2ulaw_impl(PyObject *module, Py_buffer *fragment, int width);
    1054             : 
    1055             : static PyObject *
    1056         201 : audioop_lin2ulaw(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1057             : {
    1058         201 :     PyObject *return_value = NULL;
    1059         201 :     Py_buffer fragment = {NULL, NULL};
    1060             :     int width;
    1061             : 
    1062         201 :     if (!_PyArg_CheckPositional("lin2ulaw", nargs, 2, 2)) {
    1063           0 :         goto exit;
    1064             :     }
    1065         201 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
    1066           1 :         goto exit;
    1067             :     }
    1068         200 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
    1069           0 :         _PyArg_BadArgument("lin2ulaw", "argument 1", "contiguous buffer", args[0]);
    1070           0 :         goto exit;
    1071             :     }
    1072         200 :     width = _PyLong_AsInt(args[1]);
    1073         200 :     if (width == -1 && PyErr_Occurred()) {
    1074           0 :         goto exit;
    1075             :     }
    1076         200 :     return_value = audioop_lin2ulaw_impl(module, &fragment, width);
    1077             : 
    1078         201 : exit:
    1079             :     /* Cleanup for fragment */
    1080         201 :     if (fragment.obj) {
    1081         200 :        PyBuffer_Release(&fragment);
    1082             :     }
    1083             : 
    1084         201 :     return return_value;
    1085             : }
    1086             : 
    1087             : PyDoc_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_CAST(audioop_ulaw2lin), METH_FASTCALL, audioop_ulaw2lin__doc__},
    1095             : 
    1096             : static PyObject *
    1097             : audioop_ulaw2lin_impl(PyObject *module, Py_buffer *fragment, int width);
    1098             : 
    1099             : static PyObject *
    1100         219 : audioop_ulaw2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1101             : {
    1102         219 :     PyObject *return_value = NULL;
    1103         219 :     Py_buffer fragment = {NULL, NULL};
    1104             :     int width;
    1105             : 
    1106         219 :     if (!_PyArg_CheckPositional("ulaw2lin", nargs, 2, 2)) {
    1107           0 :         goto exit;
    1108             :     }
    1109         219 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
    1110           0 :         goto exit;
    1111             :     }
    1112         219 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
    1113           0 :         _PyArg_BadArgument("ulaw2lin", "argument 1", "contiguous buffer", args[0]);
    1114           0 :         goto exit;
    1115             :     }
    1116         219 :     width = _PyLong_AsInt(args[1]);
    1117         219 :     if (width == -1 && PyErr_Occurred()) {
    1118           0 :         goto exit;
    1119             :     }
    1120         219 :     return_value = audioop_ulaw2lin_impl(module, &fragment, width);
    1121             : 
    1122         219 : exit:
    1123             :     /* Cleanup for fragment */
    1124         219 :     if (fragment.obj) {
    1125         219 :        PyBuffer_Release(&fragment);
    1126             :     }
    1127             : 
    1128         219 :     return return_value;
    1129             : }
    1130             : 
    1131             : PyDoc_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_CAST(audioop_lin2alaw), METH_FASTCALL, audioop_lin2alaw__doc__},
    1139             : 
    1140             : static PyObject *
    1141             : audioop_lin2alaw_impl(PyObject *module, Py_buffer *fragment, int width);
    1142             : 
    1143             : static PyObject *
    1144         107 : audioop_lin2alaw(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1145             : {
    1146         107 :     PyObject *return_value = NULL;
    1147         107 :     Py_buffer fragment = {NULL, NULL};
    1148             :     int width;
    1149             : 
    1150         107 :     if (!_PyArg_CheckPositional("lin2alaw", nargs, 2, 2)) {
    1151           0 :         goto exit;
    1152             :     }
    1153         107 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
    1154           1 :         goto exit;
    1155             :     }
    1156         106 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
    1157           0 :         _PyArg_BadArgument("lin2alaw", "argument 1", "contiguous buffer", args[0]);
    1158           0 :         goto exit;
    1159             :     }
    1160         106 :     width = _PyLong_AsInt(args[1]);
    1161         106 :     if (width == -1 && PyErr_Occurred()) {
    1162           0 :         goto exit;
    1163             :     }
    1164         106 :     return_value = audioop_lin2alaw_impl(module, &fragment, width);
    1165             : 
    1166         107 : exit:
    1167             :     /* Cleanup for fragment */
    1168         107 :     if (fragment.obj) {
    1169         106 :        PyBuffer_Release(&fragment);
    1170             :     }
    1171             : 
    1172         107 :     return return_value;
    1173             : }
    1174             : 
    1175             : PyDoc_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_CAST(audioop_alaw2lin), METH_FASTCALL, audioop_alaw2lin__doc__},
    1183             : 
    1184             : static PyObject *
    1185             : audioop_alaw2lin_impl(PyObject *module, Py_buffer *fragment, int width);
    1186             : 
    1187             : static PyObject *
    1188         118 : audioop_alaw2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1189             : {
    1190         118 :     PyObject *return_value = NULL;
    1191         118 :     Py_buffer fragment = {NULL, NULL};
    1192             :     int width;
    1193             : 
    1194         118 :     if (!_PyArg_CheckPositional("alaw2lin", nargs, 2, 2)) {
    1195           0 :         goto exit;
    1196             :     }
    1197         118 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
    1198           0 :         goto exit;
    1199             :     }
    1200         118 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
    1201           0 :         _PyArg_BadArgument("alaw2lin", "argument 1", "contiguous buffer", args[0]);
    1202           0 :         goto exit;
    1203             :     }
    1204         118 :     width = _PyLong_AsInt(args[1]);
    1205         118 :     if (width == -1 && PyErr_Occurred()) {
    1206           0 :         goto exit;
    1207             :     }
    1208         118 :     return_value = audioop_alaw2lin_impl(module, &fragment, width);
    1209             : 
    1210         118 : exit:
    1211             :     /* Cleanup for fragment */
    1212         118 :     if (fragment.obj) {
    1213         118 :        PyBuffer_Release(&fragment);
    1214             :     }
    1215             : 
    1216         118 :     return return_value;
    1217             : }
    1218             : 
    1219             : PyDoc_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_CAST(audioop_lin2adpcm), METH_FASTCALL, audioop_lin2adpcm__doc__},
    1227             : 
    1228             : static PyObject *
    1229             : audioop_lin2adpcm_impl(PyObject *module, Py_buffer *fragment, int width,
    1230             :                        PyObject *state);
    1231             : 
    1232             : static PyObject *
    1233          20 : audioop_lin2adpcm(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1234             : {
    1235          20 :     PyObject *return_value = NULL;
    1236          20 :     Py_buffer fragment = {NULL, NULL};
    1237             :     int width;
    1238             :     PyObject *state;
    1239             : 
    1240          20 :     if (!_PyArg_CheckPositional("lin2adpcm", nargs, 3, 3)) {
    1241           0 :         goto exit;
    1242             :     }
    1243          20 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
    1244           1 :         goto exit;
    1245             :     }
    1246          19 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
    1247           0 :         _PyArg_BadArgument("lin2adpcm", "argument 1", "contiguous buffer", args[0]);
    1248           0 :         goto exit;
    1249             :     }
    1250          19 :     width = _PyLong_AsInt(args[1]);
    1251          19 :     if (width == -1 && PyErr_Occurred()) {
    1252           0 :         goto exit;
    1253             :     }
    1254          19 :     state = args[2];
    1255          19 :     return_value = audioop_lin2adpcm_impl(module, &fragment, width, state);
    1256             : 
    1257          20 : exit:
    1258             :     /* Cleanup for fragment */
    1259          20 :     if (fragment.obj) {
    1260          19 :        PyBuffer_Release(&fragment);
    1261             :     }
    1262             : 
    1263          20 :     return return_value;
    1264             : }
    1265             : 
    1266             : PyDoc_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_CAST(audioop_adpcm2lin), METH_FASTCALL, audioop_adpcm2lin__doc__},
    1274             : 
    1275             : static PyObject *
    1276             : audioop_adpcm2lin_impl(PyObject *module, Py_buffer *fragment, int width,
    1277             :                        PyObject *state);
    1278             : 
    1279             : static PyObject *
    1280          19 : audioop_adpcm2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1281             : {
    1282          19 :     PyObject *return_value = NULL;
    1283          19 :     Py_buffer fragment = {NULL, NULL};
    1284             :     int width;
    1285             :     PyObject *state;
    1286             : 
    1287          19 :     if (!_PyArg_CheckPositional("adpcm2lin", nargs, 3, 3)) {
    1288           0 :         goto exit;
    1289             :     }
    1290          19 :     if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) {
    1291           0 :         goto exit;
    1292             :     }
    1293          19 :     if (!PyBuffer_IsContiguous(&fragment, 'C')) {
    1294           0 :         _PyArg_BadArgument("adpcm2lin", "argument 1", "contiguous buffer", args[0]);
    1295           0 :         goto exit;
    1296             :     }
    1297          19 :     width = _PyLong_AsInt(args[1]);
    1298          19 :     if (width == -1 && PyErr_Occurred()) {
    1299           0 :         goto exit;
    1300             :     }
    1301          19 :     state = args[2];
    1302          19 :     return_value = audioop_adpcm2lin_impl(module, &fragment, width, state);
    1303             : 
    1304          19 : exit:
    1305             :     /* Cleanup for fragment */
    1306          19 :     if (fragment.obj) {
    1307          19 :        PyBuffer_Release(&fragment);
    1308             :     }
    1309             : 
    1310          19 :     return return_value;
    1311             : }
    1312             : /*[clinic end generated code: output=a581c3893ef8ad75 input=a9049054013a1b77]*/

Generated by: LCOV version 1.14