1 #define PY_AUBIO_MODULE_MAIN
2 #include "aubio-types.h"
3 #include "aubio-generated.h"
5 static char aubio_module_doc[] = "Python module for the aubio library";
7 static char Py_alpha_norm_doc[] = ""
8 "alpha_norm(fvec, integer) -> float\n"
10 "Compute alpha normalisation factor on vector, given alpha\n"
15 ">>> b = alpha_norm(a, 9)";
17 static char Py_bintomidi_doc[] = ""
18 "bintomidi(float, samplerate = integer, fftsize = integer) -> float\n"
20 "Convert bin (float) to midi (float), given the sampling rate and the FFT size\n"
25 ">>> midi = bintomidi(float, samplerate = 44100, fftsize = 1024)";
27 static char Py_miditobin_doc[] = ""
28 "miditobin(float, samplerate = integer, fftsize = integer) -> float\n"
30 "Convert midi (float) to bin (float), given the sampling rate and the FFT size\n"
35 ">>> bin = miditobin(midi, samplerate = 44100, fftsize = 1024)";
37 static char Py_bintofreq_doc[] = ""
38 "bintofreq(float, samplerate = integer, fftsize = integer) -> float\n"
40 "Convert bin number (float) in frequency (Hz), given the sampling rate and the FFT size\n"
45 ">>> freq = bintofreq(bin, samplerate = 44100, fftsize = 1024)";
47 static char Py_freqtobin_doc[] = ""
48 "freqtobin(float, samplerate = integer, fftsize = integer) -> float\n"
50 "Convert frequency (Hz) in bin number (float), given the sampling rate and the FFT size\n"
55 ">>> bin = freqtobin(freq, samplerate = 44100, fftsize = 1024)";
57 static char Py_zero_crossing_rate_doc[] = ""
58 "zero_crossing_rate(fvec) -> float\n"
60 "Compute Zero crossing rate of a vector\n"
65 ">>> z = zero_crossing_rate(a)";
67 static char Py_min_removal_doc[] = ""
68 "min_removal(fvec) -> float\n"
70 "Remove the minimum value of a vector, in-place modification\n"
77 extern void add_generated_objects ( PyObject *m );
78 extern void add_ufuncs ( PyObject *m );
79 extern int generated_types_ready(void);
82 Py_alpha_norm (PyObject * self, PyObject * args)
89 if (!PyArg_ParseTuple (args, "Of:alpha_norm", &input, &alpha)) {
97 vec = PyAubio_ArrayToCFvec (input);
103 // compute the function
104 result = Py_BuildValue ("f", fvec_alpha_norm (vec, alpha));
105 if (result == NULL) {
113 Py_bintomidi (PyObject * self, PyObject * args)
115 smpl_t input, samplerate, fftsize;
118 if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
122 output = aubio_bintomidi (input, samplerate, fftsize);
124 return (PyObject *)PyFloat_FromDouble (output);
128 Py_miditobin (PyObject * self, PyObject * args)
130 smpl_t input, samplerate, fftsize;
133 if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
137 output = aubio_miditobin (input, samplerate, fftsize);
139 return (PyObject *)PyFloat_FromDouble (output);
143 Py_bintofreq (PyObject * self, PyObject * args)
145 smpl_t input, samplerate, fftsize;
148 if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
152 output = aubio_bintofreq (input, samplerate, fftsize);
154 return (PyObject *)PyFloat_FromDouble (output);
158 Py_freqtobin (PyObject * self, PyObject * args)
160 smpl_t input, samplerate, fftsize;
163 if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
167 output = aubio_freqtobin (input, samplerate, fftsize);
169 return (PyObject *)PyFloat_FromDouble (output);
173 Py_zero_crossing_rate (PyObject * self, PyObject * args)
179 if (!PyArg_ParseTuple (args, "O:zero_crossing_rate", &input)) {
187 vec = PyAubio_ArrayToCFvec (input);
193 // compute the function
194 result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec));
195 if (result == NULL) {
203 Py_min_removal(PyObject * self, PyObject * args)
208 if (!PyArg_ParseTuple (args, "O:min_removal", &input)) {
216 vec = PyAubio_ArrayToCFvec (input);
222 // compute the function
223 fvec_min_removal (vec);
225 // since this function does not return, we could return None
227 // however it is convenient to return the modified vector
228 return (PyObject *) PyAubio_CFvecToArray(vec);
229 // or even without converting it back to an array
231 //return (PyObject *)vec;
234 static PyMethodDef aubio_methods[] = {
235 {"bintomidi", Py_bintomidi, METH_VARARGS, Py_bintomidi_doc},
236 {"miditobin", Py_miditobin, METH_VARARGS, Py_miditobin_doc},
237 {"bintofreq", Py_bintofreq, METH_VARARGS, Py_bintofreq_doc},
238 {"freqtobin", Py_freqtobin, METH_VARARGS, Py_freqtobin_doc},
239 {"alpha_norm", Py_alpha_norm, METH_VARARGS, Py_alpha_norm_doc},
240 {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS, Py_zero_crossing_rate_doc},
241 {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc},
242 {NULL, NULL} /* Sentinel */
251 // fvec is defined in __init__.py
252 if ( (PyType_Ready (&Py_cvecType) < 0)
253 || (PyType_Ready (&Py_filterType) < 0)
254 || (PyType_Ready (&Py_filterbankType) < 0)
255 || (PyType_Ready (&Py_fftType) < 0)
256 || (PyType_Ready (&Py_pvocType) < 0)
257 || (PyType_Ready (&Py_sourceType) < 0)
258 || (PyType_Ready (&Py_sinkType) < 0)
260 || (generated_types_ready() < 0 )
265 m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc);
271 err = _import_array ();
274 "Unable to import Numpy array from aubio module (error %d)\n", err);
277 Py_INCREF (&Py_cvecType);
278 PyModule_AddObject (m, "cvec", (PyObject *) & Py_cvecType);
279 Py_INCREF (&Py_filterType);
280 PyModule_AddObject (m, "digital_filter", (PyObject *) & Py_filterType);
281 Py_INCREF (&Py_filterbankType);
282 PyModule_AddObject (m, "filterbank", (PyObject *) & Py_filterbankType);
283 Py_INCREF (&Py_fftType);
284 PyModule_AddObject (m, "fft", (PyObject *) & Py_fftType);
285 Py_INCREF (&Py_pvocType);
286 PyModule_AddObject (m, "pvoc", (PyObject *) & Py_pvocType);
287 Py_INCREF (&Py_sourceType);
288 PyModule_AddObject (m, "source", (PyObject *) & Py_sourceType);
289 Py_INCREF (&Py_sinkType);
290 PyModule_AddObject (m, "sink", (PyObject *) & Py_sinkType);
292 // add generated objects
293 add_generated_objects(m);