source: interfaces/python/aubiomodule.c @ 1458de5

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

aubio-types.h, aubiomodule.c: update for numpy 1.8

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