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