[7a6521d] | 1 | #define PY_AUBIO_MODULE_MAIN |
---|
[ae6e15c] | 2 | #include "aubio-types.h" |
---|
[449bff6] | 3 | #include "generated/aubio-generated.h" |
---|
[0a6c211] | 4 | |
---|
[6b1aafc] | 5 | static char Py_alpha_norm_doc[] = "compute alpha normalisation factor"; |
---|
| 6 | |
---|
| 7 | static PyObject * |
---|
| 8 | Py_alpha_norm (PyObject * self, PyObject * args) |
---|
| 9 | { |
---|
| 10 | PyObject *input; |
---|
[ce4bfe3] | 11 | fvec_t *vec; |
---|
[6b1aafc] | 12 | smpl_t alpha; |
---|
| 13 | PyObject *result; |
---|
| 14 | |
---|
| 15 | if (!PyArg_ParseTuple (args, "Of:alpha_norm", &input, &alpha)) { |
---|
| 16 | return NULL; |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | if (input == NULL) { |
---|
| 20 | return NULL; |
---|
| 21 | } |
---|
| 22 | |
---|
[ce4bfe3] | 23 | vec = PyAubio_ArrayToCFvec (input); |
---|
[6b1aafc] | 24 | |
---|
| 25 | if (vec == NULL) { |
---|
| 26 | return NULL; |
---|
| 27 | } |
---|
| 28 | |
---|
[ae6e15c] | 29 | // compute the function |
---|
[ce4bfe3] | 30 | result = Py_BuildValue ("f", fvec_alpha_norm (vec, alpha)); |
---|
[0a6c211] | 31 | if (result == NULL) { |
---|
| 32 | return NULL; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | return result; |
---|
| 36 | } |
---|
| 37 | |
---|
[6514bb6] | 38 | static char Py_unwrap2pi_doc[] = "unwrap phase value to [-pi, pi]"; |
---|
| 39 | |
---|
| 40 | static PyObject * |
---|
| 41 | Py_unwrap2pi (PyObject * self, PyObject * args) |
---|
| 42 | { |
---|
| 43 | smpl_t input; |
---|
| 44 | smpl_t output; |
---|
| 45 | |
---|
| 46 | if (!PyArg_ParseTuple (args, "|f", &input)) { |
---|
| 47 | return NULL; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | output = aubio_unwrap2pi (input); |
---|
| 51 | |
---|
| 52 | return (PyObject *)PyFloat_FromDouble (output); |
---|
| 53 | } |
---|
| 54 | |
---|
[6a50b9e] | 55 | static char Py_bintomidi_doc[] = "convert bin to midi"; |
---|
| 56 | |
---|
| 57 | static PyObject * |
---|
| 58 | Py_bintomidi (PyObject * self, PyObject * args) |
---|
| 59 | { |
---|
| 60 | smpl_t input, samplerate, fftsize; |
---|
| 61 | smpl_t output; |
---|
| 62 | |
---|
| 63 | if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) { |
---|
| 64 | return NULL; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | output = aubio_bintomidi (input, samplerate, fftsize); |
---|
| 68 | |
---|
| 69 | return (PyObject *)PyFloat_FromDouble (output); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | static char Py_miditobin_doc[] = "convert midi to bin"; |
---|
| 73 | |
---|
| 74 | static PyObject * |
---|
| 75 | Py_miditobin (PyObject * self, PyObject * args) |
---|
| 76 | { |
---|
| 77 | smpl_t input, samplerate, fftsize; |
---|
| 78 | smpl_t output; |
---|
| 79 | |
---|
| 80 | if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) { |
---|
| 81 | return NULL; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | output = aubio_miditobin (input, samplerate, fftsize); |
---|
| 85 | |
---|
| 86 | return (PyObject *)PyFloat_FromDouble (output); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | static char Py_bintofreq_doc[] = "convert bin to freq"; |
---|
| 90 | |
---|
| 91 | static PyObject * |
---|
| 92 | Py_bintofreq (PyObject * self, PyObject * args) |
---|
| 93 | { |
---|
| 94 | smpl_t input, samplerate, fftsize; |
---|
| 95 | smpl_t output; |
---|
| 96 | |
---|
| 97 | if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) { |
---|
| 98 | return NULL; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | output = aubio_bintofreq (input, samplerate, fftsize); |
---|
| 102 | |
---|
| 103 | return (PyObject *)PyFloat_FromDouble (output); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | static char Py_freqtobin_doc[] = "convert freq to bin"; |
---|
| 107 | |
---|
| 108 | static PyObject * |
---|
| 109 | Py_freqtobin (PyObject * self, PyObject * args) |
---|
| 110 | { |
---|
| 111 | smpl_t input, samplerate, fftsize; |
---|
| 112 | smpl_t output; |
---|
| 113 | |
---|
| 114 | if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) { |
---|
| 115 | return NULL; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | output = aubio_freqtobin (input, samplerate, fftsize); |
---|
| 119 | |
---|
| 120 | return (PyObject *)PyFloat_FromDouble (output); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | static char Py_freqtomidi_doc[] = "convert freq to midi"; |
---|
| 124 | |
---|
| 125 | static PyObject * |
---|
| 126 | Py_freqtomidi (PyObject * self, PyObject * args) |
---|
| 127 | { |
---|
| 128 | smpl_t input; |
---|
| 129 | smpl_t output; |
---|
| 130 | |
---|
| 131 | if (!PyArg_ParseTuple (args, "|f", &input)) { |
---|
| 132 | return NULL; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | output = aubio_freqtomidi (input); |
---|
| 136 | |
---|
| 137 | return (PyObject *)PyFloat_FromDouble (output); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | static char Py_miditofreq_doc[] = "convert midi to freq"; |
---|
| 141 | |
---|
| 142 | static PyObject * |
---|
| 143 | Py_miditofreq (PyObject * self, PyObject * args) |
---|
| 144 | { |
---|
| 145 | smpl_t input; |
---|
| 146 | smpl_t output; |
---|
| 147 | |
---|
| 148 | if (!PyArg_ParseTuple (args, "|f", &input)) { |
---|
| 149 | return NULL; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | output = aubio_miditofreq (input); |
---|
| 153 | |
---|
| 154 | return (PyObject *)PyFloat_FromDouble (output); |
---|
| 155 | } |
---|
| 156 | |
---|
[207ed19] | 157 | static char Py_zero_crossing_rate_doc[] = "compute zero crossing rate"; |
---|
| 158 | |
---|
| 159 | static PyObject * |
---|
| 160 | Py_zero_crossing_rate (PyObject * self, PyObject * args) |
---|
| 161 | { |
---|
| 162 | PyObject *input; |
---|
[ce4bfe3] | 163 | fvec_t *vec; |
---|
[207ed19] | 164 | PyObject *result; |
---|
| 165 | |
---|
| 166 | if (!PyArg_ParseTuple (args, "O:zero_crossing_rate", &input)) { |
---|
| 167 | return NULL; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | if (input == NULL) { |
---|
| 171 | return NULL; |
---|
| 172 | } |
---|
| 173 | |
---|
[ce4bfe3] | 174 | vec = PyAubio_ArrayToCFvec (input); |
---|
[207ed19] | 175 | |
---|
| 176 | if (vec == NULL) { |
---|
| 177 | return NULL; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | // compute the function |
---|
[ce4bfe3] | 181 | result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec)); |
---|
[207ed19] | 182 | if (result == NULL) { |
---|
| 183 | return NULL; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | return result; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | static char Py_min_removal_doc[] = "compute zero crossing rate"; |
---|
| 190 | |
---|
[ce4bfe3] | 191 | static PyObject * |
---|
[207ed19] | 192 | Py_min_removal(PyObject * self, PyObject * args) |
---|
| 193 | { |
---|
| 194 | PyObject *input; |
---|
[ce4bfe3] | 195 | fvec_t *vec; |
---|
[207ed19] | 196 | |
---|
[ccf8b77] | 197 | if (!PyArg_ParseTuple (args, "O:min_removal", &input)) { |
---|
[207ed19] | 198 | return NULL; |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | if (input == NULL) { |
---|
| 202 | return NULL; |
---|
| 203 | } |
---|
| 204 | |
---|
[ce4bfe3] | 205 | vec = PyAubio_ArrayToCFvec (input); |
---|
[207ed19] | 206 | |
---|
| 207 | if (vec == NULL) { |
---|
| 208 | return NULL; |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | // compute the function |
---|
[ce4bfe3] | 212 | fvec_min_removal (vec); |
---|
[615ac7d] | 213 | |
---|
[207ed19] | 214 | // since this function does not return, we could return None |
---|
| 215 | //return Py_None; |
---|
[ce4bfe3] | 216 | // however it is convenient to return the modified vector |
---|
| 217 | return (PyObject *) PyAubio_CFvecToArray(vec); |
---|
[207ed19] | 218 | // or even without converting it back to an array |
---|
[9b23eb31] | 219 | //Py_INCREF(vec); |
---|
| 220 | //return (PyObject *)vec; |
---|
[207ed19] | 221 | } |
---|
| 222 | |
---|
[0a6c211] | 223 | static PyMethodDef aubio_methods[] = { |
---|
[0d222ee] | 224 | //{"unwrap2pi", Py_unwrap2pi, METH_VARARGS, Py_unwrap2pi_doc}, |
---|
[6a50b9e] | 225 | {"bintomidi", Py_bintomidi, METH_VARARGS, Py_bintomidi_doc}, |
---|
| 226 | {"miditobin", Py_miditobin, METH_VARARGS, Py_miditobin_doc}, |
---|
| 227 | {"bintofreq", Py_bintofreq, METH_VARARGS, Py_bintofreq_doc}, |
---|
| 228 | {"freqtobin", Py_freqtobin, METH_VARARGS, Py_freqtobin_doc}, |
---|
| 229 | {"miditofreq", Py_miditofreq, METH_VARARGS, Py_miditofreq_doc}, |
---|
| 230 | {"freqtomidi", Py_freqtomidi, METH_VARARGS, Py_freqtomidi_doc}, |
---|
[0a6c211] | 231 | {"alpha_norm", Py_alpha_norm, METH_VARARGS, Py_alpha_norm_doc}, |
---|
[6a50b9e] | 232 | {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS, Py_zero_crossing_rate_doc}, |
---|
[207ed19] | 233 | {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc}, |
---|
[ccf8b77] | 234 | {NULL, NULL} /* Sentinel */ |
---|
[0a6c211] | 235 | }; |
---|
| 236 | |
---|
[ae6e15c] | 237 | static char aubio_module_doc[] = "Python module for the aubio library"; |
---|
| 238 | |
---|
[0a6c211] | 239 | PyMODINIT_FUNC |
---|
| 240 | init_aubio (void) |
---|
| 241 | { |
---|
| 242 | PyObject *m; |
---|
| 243 | int err; |
---|
| 244 | |
---|
[7a6521d] | 245 | // fvec is defined in __init__.py |
---|
[ce4bfe3] | 246 | if ( (PyType_Ready (&Py_cvecType) < 0) |
---|
| 247 | || (PyType_Ready (&Py_filterType) < 0) |
---|
| 248 | || (PyType_Ready (&Py_filterbankType) < 0) |
---|
| 249 | || (PyType_Ready (&Py_fftType) < 0) |
---|
| 250 | || (PyType_Ready (&Py_pvocType) < 0) |
---|
[449bff6] | 251 | // generated objects |
---|
| 252 | || (generated_types_ready() < 0 ) |
---|
[615ac7d] | 253 | ) { |
---|
[0a6c211] | 254 | return; |
---|
| 255 | } |
---|
| 256 | |
---|
[1458de5] | 257 | m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc); |
---|
| 258 | |
---|
| 259 | if (m == NULL) { |
---|
| 260 | return; |
---|
| 261 | } |
---|
| 262 | |
---|
[0a6c211] | 263 | err = _import_array (); |
---|
| 264 | |
---|
| 265 | if (err != 0) { |
---|
| 266 | fprintf (stderr, |
---|
| 267 | "Unable to import Numpy C API from aubio module (error %d)\n", err); |
---|
| 268 | } |
---|
| 269 | |
---|
[9b23eb31] | 270 | Py_INCREF (&Py_cvecType); |
---|
| 271 | PyModule_AddObject (m, "cvec", (PyObject *) & Py_cvecType); |
---|
| 272 | Py_INCREF (&Py_filterType); |
---|
| 273 | PyModule_AddObject (m, "digital_filter", (PyObject *) & Py_filterType); |
---|
[615ac7d] | 274 | Py_INCREF (&Py_filterbankType); |
---|
| 275 | PyModule_AddObject (m, "filterbank", (PyObject *) & Py_filterbankType); |
---|
| 276 | Py_INCREF (&Py_fftType); |
---|
| 277 | PyModule_AddObject (m, "fft", (PyObject *) & Py_fftType); |
---|
| 278 | Py_INCREF (&Py_pvocType); |
---|
| 279 | PyModule_AddObject (m, "pvoc", (PyObject *) & Py_pvocType); |
---|
[449bff6] | 280 | |
---|
[7a6521d] | 281 | // add generated objects |
---|
[449bff6] | 282 | add_generated_objects(m); |
---|
[0d222ee] | 283 | |
---|
| 284 | // add ufunc |
---|
| 285 | add_ufuncs(m); |
---|
[0a6c211] | 286 | } |
---|