source: python/ext/py-musicutils.c @ 569b363

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 569b363 was 569b363, checked in by Paul Brossier <piem@piem.org>, 8 years ago

python/ext: simplify memory allocations, removed unneeded malloc/free calls

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