source: interfaces/python/aubiomodule.c @ ce4bfe3

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since ce4bfe3 was ce4bfe3, checked in by Paul Brossier <piem@piem.org>, 14 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
Line 
1#include <Python.h>
2#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API
3#include <numpy/arrayobject.h>
4
5#include "aubio-types.h"
6#include "generated/aubio-generated.h"
7
8static char Py_alpha_norm_doc[] = "compute alpha normalisation factor";
9
10static PyObject *
11Py_alpha_norm (PyObject * self, PyObject * args)
12{
13  PyObject *input;
14  fvec_t *vec;
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
26  vec = PyAubio_ArrayToCFvec (input);
27
28  if (vec == NULL) {
29    return NULL;
30  }
31
32  // compute the function
33  result = Py_BuildValue ("f", fvec_alpha_norm (vec, alpha));
34  if (result == NULL) {
35    return NULL;
36  }
37
38  return result;
39}
40
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;
47  fvec_t *vec;
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
58  vec = PyAubio_ArrayToCFvec (input);
59
60  if (vec == NULL) {
61    return NULL;
62  }
63
64  // compute the function
65  result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec));
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
75static PyObject *
76Py_min_removal(PyObject * self, PyObject * args)
77{
78  PyObject *input;
79  fvec_t *vec;
80
81  if (!PyArg_ParseTuple (args, "O:min_removal", &input)) {
82    return NULL;
83  }
84
85  if (input == NULL) {
86    return NULL;
87  }
88
89  vec = PyAubio_ArrayToCFvec (input);
90
91  if (vec == NULL) {
92    return NULL;
93  }
94
95  // compute the function
96  fvec_min_removal (vec);
97
98  // since this function does not return, we could return None
99  //return Py_None;
100  // however it is convenient to return the modified vector
101  return (PyObject *) PyAubio_CFvecToArray(vec);
102  // or even without converting it back to an array
103  //Py_INCREF(vec);
104  //return (PyObject *)vec;
105}
106
107static PyMethodDef aubio_methods[] = {
108  {"alpha_norm", Py_alpha_norm, METH_VARARGS, Py_alpha_norm_doc},
109  {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS,
110    Py_zero_crossing_rate_doc},
111  {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc},
112  {NULL, NULL} /* Sentinel */
113};
114
115static char aubio_module_doc[] = "Python module for the aubio library";
116
117PyMODINIT_FUNC
118init_aubio (void)
119{
120  PyObject *m;
121  int err;
122
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)
128      // generated objects
129      || (generated_types_ready() < 0 )
130  ) {
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
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);
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);
157
158  // generated objects
159  add_generated_objects(m);
160}
Note: See TracBrowser for help on using the repository browser.