source: python/ext/py-musicutils.c @ 26eb6d0

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

ext/py-musicutils.c: add level_detection (closes #21)

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