source: python/aubiomodule.c @ cd6fc5a

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretchpitchshiftsamplertimestretchyinfft+
Last change on this file since cd6fc5a was cd6fc5a, checked in by Paul Brossier <piem@piem.org>, 7 years ago

python/: remove NPY_NO_DEPRECATED_API to build anyway

  • Property mode set to 100644
File size: 3.5 KB
Line 
1#include <Python.h>
2#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API
3//#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
4#include <numpy/arrayobject.h>
5
6#include "aubio-types.h"
7#include "generated/aubio-generated.h"
8
9static char Py_alpha_norm_doc[] = "compute alpha normalisation factor";
10
11static PyObject *
12Py_alpha_norm (PyObject * self, PyObject * args)
13{
14  PyObject *input;
15  fvec_t *vec;
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
27  vec = PyAubio_ArrayToCFvec (input);
28
29  if (vec == NULL) {
30    return NULL;
31  }
32
33  // compute the function
34  result = Py_BuildValue ("f", fvec_alpha_norm (vec, alpha));
35  if (result == NULL) {
36    return NULL;
37  }
38
39  return result;
40}
41
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;
48  fvec_t *vec;
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
59  vec = PyAubio_ArrayToCFvec (input);
60
61  if (vec == NULL) {
62    return NULL;
63  }
64
65  // compute the function
66  result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec));
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
76static PyObject *
77Py_min_removal(PyObject * self, PyObject * args)
78{
79  PyObject *input;
80  fvec_t *vec;
81
82  if (!PyArg_ParseTuple (args, "O:min_removal", &input)) {
83    return NULL;
84  }
85
86  if (input == NULL) {
87    return NULL;
88  }
89
90  vec = PyAubio_ArrayToCFvec (input);
91
92  if (vec == NULL) {
93    return NULL;
94  }
95
96  // compute the function
97  fvec_min_removal (vec);
98
99  // since this function does not return, we could return None
100  //return Py_None;
101  // however it is convenient to return the modified vector
102  return (PyObject *) PyAubio_CFvecToArray(vec);
103  // or even without converting it back to an array
104  //Py_INCREF(vec);
105  //return (PyObject *)vec;
106}
107
108static PyMethodDef aubio_methods[] = {
109  {"alpha_norm", Py_alpha_norm, METH_VARARGS, Py_alpha_norm_doc},
110  {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS,
111    Py_zero_crossing_rate_doc},
112  {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc},
113  {NULL, NULL} /* Sentinel */
114};
115
116static char aubio_module_doc[] = "Python module for the aubio library";
117
118PyMODINIT_FUNC
119init_aubio (void)
120{
121  PyObject *m;
122  int err;
123
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)
129      // generated objects
130      || (generated_types_ready() < 0 )
131  ) {
132    return;
133  }
134
135  m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc);
136
137  if (m == NULL) {
138    return;
139  }
140
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
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);
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);
158
159  // generated objects
160  add_generated_objects(m);
161}
Note: See TracBrowser for help on using the repository browser.