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

feature/cnnfeature/crepefeature/pitchshiftfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretch
Last change on this file since ad65346 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
Line 
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;
8  fvec_t *window = NULL;
9
10  if (!PyArg_ParseTuple (args, "|sI", &wintype, &winlen)) {
11    return NULL;
12  }
13
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);
21}
22
23PyObject *
24Py_aubio_level_lin(PyObject *self, PyObject *args)
25{
26  PyObject *input;
27  fvec_t vec;
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
38  if (!PyAubio_ArrayToCFvec(input, &vec)) {
39    return NULL;
40  }
41
42  level_lin = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_lin(&vec));
43  if (level_lin == NULL) {
44    PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
45    return NULL;
46  }
47
48  return level_lin;
49}
50
51PyObject *
52Py_aubio_db_spl(PyObject *self, PyObject *args)
53{
54  PyObject *input;
55  fvec_t vec;
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
66  if (!PyAubio_ArrayToCFvec(input, &vec)) {
67    return NULL;
68  }
69
70  db_spl = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_db_spl(&vec));
71  if (db_spl == NULL) {
72    PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
73    return NULL;
74  }
75
76  return db_spl;
77}
78
79PyObject *
80Py_aubio_silence_detection(PyObject *self, PyObject *args)
81{
82  PyObject *input;
83  fvec_t vec;
84  PyObject *silence_detection;
85  smpl_t threshold;
86
87  if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":silence_detection", &input, &threshold)) {
88    return NULL;
89  }
90
91  if (input == NULL) {
92    return NULL;
93  }
94
95  if (!PyAubio_ArrayToCFvec(input, &vec)) {
96    return NULL;
97  }
98
99  silence_detection = Py_BuildValue("I", aubio_silence_detection(&vec, threshold));
100  if (silence_detection == NULL) {
101    PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");
102    return NULL;
103  }
104
105  return silence_detection;
106}
107
108PyObject *
109Py_aubio_level_detection(PyObject *self, PyObject *args)
110{
111  PyObject *input;
112  fvec_t vec;
113  PyObject *level_detection;
114  smpl_t threshold;
115
116  if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":level_detection", &input, &threshold)) {
117    return NULL;
118  }
119
120  if (input == NULL) {
121    return NULL;
122  }
123
124  if (!PyAubio_ArrayToCFvec(input, &vec)) {
125    return NULL;
126  }
127
128  level_detection = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_detection(&vec, threshold));
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.