source: interfaces/python/aubiomodule.c @ a8aaef3

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

.

  • 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
7static char Py_alpha_norm_doc[] = "compute alpha normalisation factor";
8
9static PyObject *
10Py_alpha_norm (PyObject * self, PyObject * args)
11{
12  PyObject *input;
13  Py_fvec *vec;
14  smpl_t alpha;
15  PyObject *result;
16
17  if (!PyArg_ParseTuple (args, "Of:alpha_norm", &input, &alpha)) {
18    return NULL;
19  }
20
21  if (input == NULL) {
22    return NULL;
23  }
24
25  vec = PyAubio_ArrayToFvec (input);
26
27  if (vec == NULL) {
28    return NULL;
29  }
30
31  // compute the function
32  result = Py_BuildValue ("f", fvec_alpha_norm (vec->o, alpha));
33  if (result == NULL) {
34    return NULL;
35  }
36
37  return result;
38}
39
40static char Py_zero_crossing_rate_doc[] = "compute zero crossing rate";
41
42static PyObject *
43Py_zero_crossing_rate (PyObject * self, PyObject * args)
44{
45  PyObject *input;
46  Py_fvec *vec;
47  PyObject *result;
48
49  if (!PyArg_ParseTuple (args, "O:zero_crossing_rate", &input)) {
50    return NULL;
51  }
52
53  if (input == NULL) {
54    return NULL;
55  }
56
57  vec = PyAubio_ArrayToFvec (input);
58
59  if (vec == NULL) {
60    return NULL;
61  }
62
63  // compute the function
64  result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec->o));
65  if (result == NULL) {
66    return NULL;
67  }
68
69  return result;
70}
71
72static char Py_min_removal_doc[] = "compute zero crossing rate";
73
74static PyObject * 
75Py_min_removal(PyObject * self, PyObject * args)
76{
77  PyObject *input;
78  Py_fvec *vec;
79
80  if (!PyArg_ParseTuple (args, "O:min_removal", &input)) {
81    return NULL;
82  }
83
84  if (input == NULL) {
85    return NULL;
86  }
87
88  vec = PyAubio_ArrayToFvec (input);
89
90  if (vec == NULL) {
91    return NULL;
92  }
93
94  // compute the function
95  fvec_min_removal (vec->o);
96
97  // since this function does not return, we could return None
98  //return Py_None;
99  // however it is convenient to return the modified vector
100  return (PyObject *) PyAubio_FvecToArray(vec);
101  // or even without converting it back to an array
102  //Py_INCREF(vec);
103  //return (PyObject *)vec;
104}
105
106static PyMethodDef aubio_methods[] = {
107  {"alpha_norm", Py_alpha_norm, METH_VARARGS, Py_alpha_norm_doc},
108  {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS, 
109    Py_zero_crossing_rate_doc},
110  {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc},
111  {NULL, NULL} /* Sentinel */
112};
113
114static char aubio_module_doc[] = "Python module for the aubio library";
115
116PyMODINIT_FUNC
117init_aubio (void)
118{
119  PyObject *m;
120  int err;
121
122  if ((PyType_Ready (&Py_fvecType) < 0) 
123      || (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  ) {
129    return;
130  }
131
132  err = _import_array ();
133
134  if (err != 0) {
135    fprintf (stderr,
136        "Unable to import Numpy C API from aubio module (error %d)\n", err);
137  }
138
139  m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc);
140
141  if (m == NULL) {
142    return;
143  }
144
145  Py_INCREF (&Py_fvecType);
146  PyModule_AddObject (m, "fvec", (PyObject *) & Py_fvecType);
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}
Note: See TracBrowser for help on using the repository browser.