source: interfaces/python/aubiomodule.c @ 7d9ec37

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

aubiomodule.c: swith to new proxy functions, remove py_fvec and py_fmat

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[0a6c211]1#include <Python.h>
[ae6e15c]2#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API
[0a6c211]3#include <numpy/arrayobject.h>
4
[ae6e15c]5#include "aubio-types.h"
[449bff6]6#include "generated/aubio-generated.h"
[0a6c211]7
[6b1aafc]8static char Py_alpha_norm_doc[] = "compute alpha normalisation factor";
9
10static PyObject *
11Py_alpha_norm (PyObject * self, PyObject * args)
12{
13  PyObject *input;
[ce4bfe3]14  fvec_t *vec;
[6b1aafc]15  smpl_t alpha;
16  PyObject *result;
17
18  if (!PyArg_ParseTuple (args, "Of:alpha_norm", &input, &alpha)) {
19    return NULL;
20  }
21
22  if (input == NULL) {
23    return NULL;
24  }
25
[ce4bfe3]26  vec = PyAubio_ArrayToCFvec (input);
[6b1aafc]27
28  if (vec == NULL) {
29    return NULL;
30  }
31
[ae6e15c]32  // compute the function
[ce4bfe3]33  result = Py_BuildValue ("f", fvec_alpha_norm (vec, alpha));
[0a6c211]34  if (result == NULL) {
35    return NULL;
36  }
37
38  return result;
39}
40
[207ed19]41static char Py_zero_crossing_rate_doc[] = "compute zero crossing rate";
42
43static PyObject *
44Py_zero_crossing_rate (PyObject * self, PyObject * args)
45{
46  PyObject *input;
[ce4bfe3]47  fvec_t *vec;
[207ed19]48  PyObject *result;
49
50  if (!PyArg_ParseTuple (args, "O:zero_crossing_rate", &input)) {
51    return NULL;
52  }
53
54  if (input == NULL) {
55    return NULL;
56  }
57
[ce4bfe3]58  vec = PyAubio_ArrayToCFvec (input);
[207ed19]59
60  if (vec == NULL) {
61    return NULL;
62  }
63
64  // compute the function
[ce4bfe3]65  result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec));
[207ed19]66  if (result == NULL) {
67    return NULL;
68  }
69
70  return result;
71}
72
73static char Py_min_removal_doc[] = "compute zero crossing rate";
74
[ce4bfe3]75static PyObject *
[207ed19]76Py_min_removal(PyObject * self, PyObject * args)
77{
78  PyObject *input;
[ce4bfe3]79  fvec_t *vec;
[207ed19]80
[ccf8b77]81  if (!PyArg_ParseTuple (args, "O:min_removal", &input)) {
[207ed19]82    return NULL;
83  }
84
85  if (input == NULL) {
86    return NULL;
87  }
88
[ce4bfe3]89  vec = PyAubio_ArrayToCFvec (input);
[207ed19]90
91  if (vec == NULL) {
92    return NULL;
93  }
94
95  // compute the function
[ce4bfe3]96  fvec_min_removal (vec);
[615ac7d]97
[207ed19]98  // since this function does not return, we could return None
99  //return Py_None;
[ce4bfe3]100  // however it is convenient to return the modified vector
101  return (PyObject *) PyAubio_CFvecToArray(vec);
[207ed19]102  // or even without converting it back to an array
[9b23eb31]103  //Py_INCREF(vec);
104  //return (PyObject *)vec;
[207ed19]105}
106
[0a6c211]107static PyMethodDef aubio_methods[] = {
108  {"alpha_norm", Py_alpha_norm, METH_VARARGS, Py_alpha_norm_doc},
[ce4bfe3]109  {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS,
[207ed19]110    Py_zero_crossing_rate_doc},
111  {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc},
[ccf8b77]112  {NULL, NULL} /* Sentinel */
[0a6c211]113};
114
[ae6e15c]115static char aubio_module_doc[] = "Python module for the aubio library";
116
[0a6c211]117PyMODINIT_FUNC
118init_aubio (void)
119{
120  PyObject *m;
121  int err;
122
[ce4bfe3]123  if (   (PyType_Ready (&Py_cvecType) < 0)
124      || (PyType_Ready (&Py_filterType) < 0)
125      || (PyType_Ready (&Py_filterbankType) < 0)
126      || (PyType_Ready (&Py_fftType) < 0)
127      || (PyType_Ready (&Py_pvocType) < 0)
[449bff6]128      // generated objects
129      || (generated_types_ready() < 0 )
[615ac7d]130  ) {
[0a6c211]131    return;
132  }
133
134  err = _import_array ();
135
136  if (err != 0) {
137    fprintf (stderr,
138        "Unable to import Numpy C API from aubio module (error %d)\n", err);
139  }
140
141  m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc);
142
143  if (m == NULL) {
144    return;
145  }
146
[9b23eb31]147  Py_INCREF (&Py_cvecType);
148  PyModule_AddObject (m, "cvec", (PyObject *) & Py_cvecType);
149  Py_INCREF (&Py_filterType);
150  PyModule_AddObject (m, "digital_filter", (PyObject *) & Py_filterType);
[615ac7d]151  Py_INCREF (&Py_filterbankType);
152  PyModule_AddObject (m, "filterbank", (PyObject *) & Py_filterbankType);
153  Py_INCREF (&Py_fftType);
154  PyModule_AddObject (m, "fft", (PyObject *) & Py_fftType);
155  Py_INCREF (&Py_pvocType);
156  PyModule_AddObject (m, "pvoc", (PyObject *) & Py_pvocType);
[449bff6]157
158  // generated objects
159  add_generated_objects(m);
[0a6c211]160}
Note: See TracBrowser for help on using the repository browser.