1 #include "aubio-types.h"
3 static char Py_filterbank_doc[] = "filterbank object";
8 aubio_filterbank_t * o;
15 Py_filterbank_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
17 int win_s = 0, n_filters = 0;
19 static char *kwlist[] = { "n_filters", "win_s", NULL };
21 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
22 &n_filters, &win_s)) {
26 self = (Py_filterbank *) type->tp_alloc (type, 0);
32 self->win_s = Py_default_vector_length;
35 } else if (win_s < 0) {
36 PyErr_SetString (PyExc_ValueError,
37 "can not use negative window size");
43 self->n_filters = n_filters;
44 } else if (n_filters < 0) {
45 PyErr_SetString (PyExc_ValueError,
46 "can not use negative number of filters");
50 return (PyObject *) self;
54 Py_filterbank_init (Py_filterbank * self, PyObject * args, PyObject * kwds)
56 self->o = new_aubio_filterbank (self->n_filters, self->win_s);
57 if (self->o == NULL) {
59 sprintf(errstr, "error creating filterbank with n_filters=%d, win_s=%d",
60 self->n_filters, self->win_s);
61 PyErr_SetString (PyExc_RuntimeError, errstr);
64 self->out = new_fvec(self->n_filters);
70 Py_filterbank_del (Py_filterbank *self, PyObject *unused)
72 del_aubio_filterbank(self->o);
74 Py_TYPE(self)->tp_free((PyObject *) self);
78 Py_filterbank_do(Py_filterbank * self, PyObject * args)
83 if (!PyArg_ParseTuple (args, "O", &input)) {
87 vec = PyAubio_ArrayToCCvec (input);
93 // compute the function
94 aubio_filterbank_do (self->o, vec, self->out);
95 return (PyObject *)PyAubio_CFvecToArray(self->out);
98 static PyMemberDef Py_filterbank_members[] = {
99 {"win_s", T_INT, offsetof (Py_filterbank, win_s), READONLY,
100 "size of the window"},
101 {"n_filters", T_INT, offsetof (Py_filterbank, n_filters), READONLY,
102 "number of filters"},
103 {NULL} /* sentinel */
107 Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args)
114 if (!PyArg_ParseTuple (args, "OI", &input, &samplerate)) {
122 freqs = PyAubio_ArrayToCFvec (input);
128 err = aubio_filterbank_set_triangle_bands (self->o,
131 PyErr_SetString (PyExc_ValueError,
132 "error when setting filter to A-weighting");
139 Py_filterbank_set_mel_coeffs_slaney (Py_filterbank * self, PyObject *args)
144 if (!PyArg_ParseTuple (args, "I", &samplerate)) {
148 err = aubio_filterbank_set_mel_coeffs_slaney (self->o, samplerate);
150 PyErr_SetString (PyExc_ValueError,
151 "error when setting filter to A-weighting");
158 Py_filterbank_set_coeffs (Py_filterbank * self, PyObject *args)
165 if (!PyArg_ParseTuple (args, "O", &input)) {
169 coeffs = PyAubio_ArrayToCFmat (input);
171 if (coeffs == NULL) {
172 PyErr_SetString (PyExc_ValueError,
173 "unable to parse input array");
177 err = aubio_filterbank_set_coeffs (self->o, coeffs);
180 PyErr_SetString (PyExc_ValueError,
181 "error when setting filter coefficients");
188 Py_filterbank_get_coeffs (Py_filterbank * self, PyObject *unused)
190 return (PyObject *)PyAubio_CFmatToArray(
191 aubio_filterbank_get_coeffs (self->o) );
194 static PyMethodDef Py_filterbank_methods[] = {
195 {"set_triangle_bands", (PyCFunction) Py_filterbank_set_triangle_bands,
196 METH_VARARGS, "set coefficients of filterbanks"},
197 {"set_mel_coeffs_slaney", (PyCFunction) Py_filterbank_set_mel_coeffs_slaney,
198 METH_VARARGS, "set coefficients of filterbank as in Auditory Toolbox"},
199 {"get_coeffs", (PyCFunction) Py_filterbank_get_coeffs,
200 METH_NOARGS, "get coefficients of filterbank"},
201 {"set_coeffs", (PyCFunction) Py_filterbank_set_coeffs,
202 METH_VARARGS, "set coefficients of filterbank"},
206 PyTypeObject Py_filterbankType = {
207 PyVarObject_HEAD_INIT (NULL, 0)
209 sizeof (Py_filterbank),
211 (destructor) Py_filterbank_del,
221 (ternaryfunc)Py_filterbank_do,
234 Py_filterbank_methods,
235 Py_filterbank_members,
242 (initproc) Py_filterbank_init,