audioop.c.h 36 KB

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