source: python/ext/py-musicutils.c @ 417fee0

feature/crepe_org
Last change on this file since 417fee0 was a617bf3, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[py] musicutils also use Pyfloat_FromDouble

  • Property mode set to 100644
File size: 4.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 = PyFloat_FromDouble(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 = PyFloat_FromDouble(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 = PyLong_FromLong(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 = PyFloat_FromDouble(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}
136
137PyObject *
138Py_aubio_shift(PyObject *self, PyObject *args)
139{
140  PyObject *input;
141  fvec_t vec;
142
143  if (!PyArg_ParseTuple (args, "O:shift", &input)) {
144    return NULL;
145  }
146
147  if (input == NULL) {
148    return NULL;
149  }
150
151  if (!PyAubio_ArrayToCFvec(input, &vec)) {
152    return NULL;
153  }
154
155  fvec_shift(&vec);
156
157  //Py_RETURN_NONE;
158  return (PyObject *) PyAubio_CFvecToArray(&vec);
159}
160
161PyObject *
162Py_aubio_ishift(PyObject *self, PyObject *args)
163{
164  PyObject *input;
165  fvec_t vec;
166
167  if (!PyArg_ParseTuple (args, "O:shift", &input)) {
168    return NULL;
169  }
170
171  if (input == NULL) {
172    return NULL;
173  }
174
175  if (!PyAubio_ArrayToCFvec(input, &vec)) {
176    return NULL;
177  }
178
179  fvec_ishift(&vec);
180
181  //Py_RETURN_NONE;
182  return (PyObject *) PyAubio_CFvecToArray(&vec);
183}
184
185PyObject*
186Py_aubio_hztomel(PyObject *self, PyObject *args, PyObject *kwds)
187{
188  smpl_t v;
189  PyObject *htk = NULL;
190  static char *kwlist[] = {"f", "htk", NULL};
191  if (!PyArg_ParseTupleAndKeywords(args, kwds, AUBIO_NPY_SMPL_CHR "|O",
192        kwlist, &v, &htk))
193  {
194    return NULL;
195  }
196  if (htk != NULL && PyObject_IsTrue(htk) == 1)
197    return PyFloat_FromDouble(aubio_hztomel_htk(v));
198  else
199    return PyFloat_FromDouble(aubio_hztomel(v));
200}
201
202PyObject*
203Py_aubio_meltohz(PyObject *self, PyObject *args, PyObject *kwds)
204{
205  smpl_t v;
206  PyObject *htk = NULL;
207  static char *kwlist[] = {"m", "htk", NULL};
208  if (!PyArg_ParseTupleAndKeywords(args, kwds, AUBIO_NPY_SMPL_CHR "|O",
209        kwlist, &v, &htk))
210  {
211    return NULL;
212  }
213  if (htk != NULL && PyObject_IsTrue(htk) == 1)
214    return PyFloat_FromDouble(aubio_meltohz_htk(v));
215  else
216    return PyFloat_FromDouble(aubio_meltohz(v));
217}
218
219PyObject*
220Py_aubio_hztomel_htk(PyObject *self, PyObject *args)
221{
222  smpl_t v;
223  if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) {
224    return NULL;
225  }
226  return PyFloat_FromDouble(aubio_hztomel_htk(v));
227}
228
229PyObject*
230Py_aubio_meltohz_htk(PyObject *self, PyObject *args)
231{
232  smpl_t v;
233  if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) {
234    return NULL;
235  }
236  return PyFloat_FromDouble(aubio_meltohz_htk(v));
237}
Note: See TracBrowser for help on using the repository browser.