source: python/ext/py-musicutils.c @ b37e2b2

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change on this file since b37e2b2 was ff89a06, checked in by Paul Brossier <piem@piem.org>, 9 years ago

python/ext/py-musicutils.c: do not overwrite PyArg_ParseTuple messages

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[913a7f1]1#include "aubio-types.h"
2
3PyObject *
4Py_aubio_window(PyObject *self, PyObject *args)
5{
6  char_t *wintype = NULL;
7  uint_t winlen = 0;
[efa62ce]8  fvec_t *window = NULL;
[913a7f1]9
[efa62ce]10  if (!PyArg_ParseTuple (args, "|sI", &wintype, &winlen)) {
[913a7f1]11    return NULL;
12  }
13
[efa62ce]14  window = new_aubio_window(wintype, winlen);
15  if (window == NULL) {
16    PyErr_SetString (PyExc_ValueError, "failed computing window");
17    return NULL;
18  }
19
20  return (PyObject *) PyAubio_CFvecToArray(window);
[913a7f1]21}
[5a7e2c3]22
23PyObject *
24Py_aubio_level_lin(PyObject *self, PyObject *args)
25{
26  PyObject *input;
[569b363]27  fvec_t vec;
[5a7e2c3]28  PyObject *level_lin;
29
30  if (!PyArg_ParseTuple (args, "O:level_lin", &input)) {
31    return NULL;
32  }
33
34  if (input == NULL) {
35    return NULL;
36  }
37
[569b363]38  if (!PyAubio_ArrayToCFvec(input, &vec)) {
[5a7e2c3]39    return NULL;
40  }
41
[c6388f4]42  level_lin = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_lin(&vec));
[5a7e2c3]43  if (level_lin == NULL) {
44    PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
45    return NULL;
46  }
47
48  return level_lin;
49}
[4615886a]50
51PyObject *
52Py_aubio_db_spl(PyObject *self, PyObject *args)
53{
54  PyObject *input;
[569b363]55  fvec_t vec;
[4615886a]56  PyObject *db_spl;
57
58  if (!PyArg_ParseTuple (args, "O:db_spl", &input)) {
59    return NULL;
60  }
61
62  if (input == NULL) {
63    return NULL;
64  }
65
[569b363]66  if (!PyAubio_ArrayToCFvec(input, &vec)) {
[4615886a]67    return NULL;
68  }
69
[c6388f4]70  db_spl = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_db_spl(&vec));
[4615886a]71  if (db_spl == NULL) {
72    PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
73    return NULL;
74  }
75
76  return db_spl;
77}
[31a09d2]78
79PyObject *
80Py_aubio_silence_detection(PyObject *self, PyObject *args)
81{
82  PyObject *input;
[569b363]83  fvec_t vec;
[31a09d2]84  PyObject *silence_detection;
85  smpl_t threshold;
86
[c6388f4]87  if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":silence_detection", &input, &threshold)) {
[31a09d2]88    return NULL;
89  }
90
91  if (input == NULL) {
92    return NULL;
93  }
94
[569b363]95  if (!PyAubio_ArrayToCFvec(input, &vec)) {
[31a09d2]96    return NULL;
97  }
98
[569b363]99  silence_detection = Py_BuildValue("I", aubio_silence_detection(&vec, threshold));
[31a09d2]100  if (silence_detection == NULL) {
101    PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");
102    return NULL;
103  }
104
105  return silence_detection;
106}
[9c8c8a6]107
108PyObject *
109Py_aubio_level_detection(PyObject *self, PyObject *args)
110{
111  PyObject *input;
[569b363]112  fvec_t vec;
[9c8c8a6]113  PyObject *level_detection;
114  smpl_t threshold;
115
[c6388f4]116  if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":level_detection", &input, &threshold)) {
[9c8c8a6]117    return NULL;
118  }
119
120  if (input == NULL) {
121    return NULL;
122  }
123
[569b363]124  if (!PyAubio_ArrayToCFvec(input, &vec)) {
[9c8c8a6]125    return NULL;
126  }
127
[c6388f4]128  level_detection = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_detection(&vec, threshold));
[9c8c8a6]129  if (level_detection == NULL) {
130    PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
131    return NULL;
132  }
133
134  return level_detection;
135}
Note: See TracBrowser for help on using the repository browser.