1 #define PY_AUBIO_MODULE_MAIN
2 #include "aubio-types.h"
3 #include "aubio-generated.h"
4 #include "py-musicutils.h"
6 static char aubio_module_doc[] = "Python module for the aubio library";
8 static char Py_alpha_norm_doc[] = ""
9 "alpha_norm(fvec, integer) -> float\n"
11 "Compute alpha normalisation factor on vector, given alpha\n"
16 ">>> b = alpha_norm(a, 9)";
18 static char Py_bintomidi_doc[] = ""
19 "bintomidi(float, samplerate = integer, fftsize = integer) -> float\n"
21 "Convert bin (float) to midi (float), given the sampling rate and the FFT size\n"
26 ">>> midi = bintomidi(float, samplerate = 44100, fftsize = 1024)";
28 static char Py_miditobin_doc[] = ""
29 "miditobin(float, samplerate = integer, fftsize = integer) -> float\n"
31 "Convert midi (float) to bin (float), given the sampling rate and the FFT size\n"
36 ">>> bin = miditobin(midi, samplerate = 44100, fftsize = 1024)";
38 static char Py_bintofreq_doc[] = ""
39 "bintofreq(float, samplerate = integer, fftsize = integer) -> float\n"
41 "Convert bin number (float) in frequency (Hz), given the sampling rate and the FFT size\n"
46 ">>> freq = bintofreq(bin, samplerate = 44100, fftsize = 1024)";
48 static char Py_freqtobin_doc[] = ""
49 "freqtobin(float, samplerate = integer, fftsize = integer) -> float\n"
51 "Convert frequency (Hz) in bin number (float), given the sampling rate and the FFT size\n"
56 ">>> bin = freqtobin(freq, samplerate = 44100, fftsize = 1024)";
58 static char Py_zero_crossing_rate_doc[] = ""
59 "zero_crossing_rate(fvec) -> float\n"
61 "Compute Zero crossing rate of a vector\n"
66 ">>> z = zero_crossing_rate(a)";
68 static char Py_min_removal_doc[] = ""
69 "min_removal(fvec) -> float\n"
71 "Remove the minimum value of a vector, in-place modification\n"
78 extern void add_generated_objects ( PyObject *m );
79 extern void add_ufuncs ( PyObject *m );
80 extern int generated_types_ready(void);
83 Py_alpha_norm (PyObject * self, PyObject * args)
90 if (!PyArg_ParseTuple (args, "Of:alpha_norm", &input, &alpha)) {
98 vec = PyAubio_ArrayToCFvec (input);
104 // compute the function
105 result = Py_BuildValue ("f", fvec_alpha_norm (vec, alpha));
106 if (result == NULL) {
114 Py_bintomidi (PyObject * self, PyObject * args)
116 smpl_t input, samplerate, fftsize;
119 if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
123 output = aubio_bintomidi (input, samplerate, fftsize);
125 return (PyObject *)PyFloat_FromDouble (output);
129 Py_miditobin (PyObject * self, PyObject * args)
131 smpl_t input, samplerate, fftsize;
134 if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
138 output = aubio_miditobin (input, samplerate, fftsize);
140 return (PyObject *)PyFloat_FromDouble (output);
144 Py_bintofreq (PyObject * self, PyObject * args)
146 smpl_t input, samplerate, fftsize;
149 if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
153 output = aubio_bintofreq (input, samplerate, fftsize);
155 return (PyObject *)PyFloat_FromDouble (output);
159 Py_freqtobin (PyObject * self, PyObject * args)
161 smpl_t input, samplerate, fftsize;
164 if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
168 output = aubio_freqtobin (input, samplerate, fftsize);
170 return (PyObject *)PyFloat_FromDouble (output);
174 Py_zero_crossing_rate (PyObject * self, PyObject * args)
180 if (!PyArg_ParseTuple (args, "O:zero_crossing_rate", &input)) {
188 vec = PyAubio_ArrayToCFvec (input);
194 // compute the function
195 result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec));
196 if (result == NULL) {
204 Py_min_removal(PyObject * self, PyObject * args)
209 if (!PyArg_ParseTuple (args, "O:min_removal", &input)) {
217 vec = PyAubio_ArrayToCFvec (input);
223 // compute the function
224 fvec_min_removal (vec);
226 // since this function does not return, we could return None
228 // however it is convenient to return the modified vector
229 return (PyObject *) PyAubio_CFvecToArray(vec);
230 // or even without converting it back to an array
232 //return (PyObject *)vec;
235 static PyMethodDef aubio_methods[] = {
236 {"bintomidi", Py_bintomidi, METH_VARARGS, Py_bintomidi_doc},
237 {"miditobin", Py_miditobin, METH_VARARGS, Py_miditobin_doc},
238 {"bintofreq", Py_bintofreq, METH_VARARGS, Py_bintofreq_doc},
239 {"freqtobin", Py_freqtobin, METH_VARARGS, Py_freqtobin_doc},
240 {"alpha_norm", Py_alpha_norm, METH_VARARGS, Py_alpha_norm_doc},
241 {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS, Py_zero_crossing_rate_doc},
242 {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc},
243 {"level_lin", Py_aubio_level_lin, METH_VARARGS, Py_aubio_level_lin_doc},
244 {"db_spl", Py_aubio_db_spl, METH_VARARGS, Py_aubio_db_spl_doc},
245 {"window", Py_aubio_window, METH_VARARGS, Py_aubio_window_doc},
246 {NULL, NULL} /* Sentinel */
255 // fvec is defined in __init__.py
256 if ( (PyType_Ready (&Py_cvecType) < 0)
257 || (PyType_Ready (&Py_filterType) < 0)
258 || (PyType_Ready (&Py_filterbankType) < 0)
259 || (PyType_Ready (&Py_fftType) < 0)
260 || (PyType_Ready (&Py_pvocType) < 0)
261 || (PyType_Ready (&Py_sourceType) < 0)
262 || (PyType_Ready (&Py_sinkType) < 0)
264 || (generated_types_ready() < 0 )
269 m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc);
275 err = _import_array ();
278 "Unable to import Numpy array from aubio module (error %d)\n", err);
281 Py_INCREF (&Py_cvecType);
282 PyModule_AddObject (m, "cvec", (PyObject *) & Py_cvecType);
283 Py_INCREF (&Py_filterType);
284 PyModule_AddObject (m, "digital_filter", (PyObject *) & Py_filterType);
285 Py_INCREF (&Py_filterbankType);
286 PyModule_AddObject (m, "filterbank", (PyObject *) & Py_filterbankType);
287 Py_INCREF (&Py_fftType);
288 PyModule_AddObject (m, "fft", (PyObject *) & Py_fftType);
289 Py_INCREF (&Py_pvocType);
290 PyModule_AddObject (m, "pvoc", (PyObject *) & Py_pvocType);
291 Py_INCREF (&Py_sourceType);
292 PyModule_AddObject (m, "source", (PyObject *) & Py_sourceType);
293 Py_INCREF (&Py_sinkType);
294 PyModule_AddObject (m, "sink", (PyObject *) & Py_sinkType);
296 // add generated objects
297 add_generated_objects(m);