1 #include "aubiowraphell.h"
3 static char Py_filterbank_doc[] = "filterbank object";
5 AUBIO_DECLARE(filterbank, uint_t n_filters; uint_t win_s)
7 //AUBIO_NEW(filterbank)
9 Py_filterbank_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
11 int win_s = 0, n_filters = 0;
13 static char *kwlist[] = { "n_filters", "win_s", NULL };
15 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
16 &n_filters, &win_s)) {
20 self = (Py_filterbank *) type->tp_alloc (type, 0);
26 self->win_s = Py_default_vector_length;
29 } else if (win_s < 0) {
30 PyErr_SetString (PyExc_ValueError,
31 "can not use negative window size");
37 self->n_filters = n_filters;
38 } else if (n_filters < 0) {
39 PyErr_SetString (PyExc_ValueError,
40 "can not use negative number of filters");
44 return (PyObject *) self;
48 AUBIO_INIT(filterbank, self->n_filters, self->win_s)
53 Py_filterbank_do(Py_filterbank * self, PyObject * args)
59 if (!PyArg_ParseTuple (args, "O", &input)) {
63 vec = PyAubio_ArrayToCCvec (input);
69 out = new_fvec (self->n_filters);
71 // compute the function
72 aubio_filterbank_do (self->o, vec, out);
73 return (PyObject *)PyAubio_CFvecToArray(out);
76 AUBIO_MEMBERS_START(filterbank)
77 {"win_s", T_INT, offsetof (Py_filterbank, win_s), READONLY,
78 "size of the window"},
79 {"n_filters", T_INT, offsetof (Py_filterbank, n_filters), READONLY,
81 AUBIO_MEMBERS_STOP(filterbank)
84 Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args)
91 if (!PyArg_ParseTuple (args, "OI", &input, &samplerate)) {
99 freqs = PyAubio_ArrayToCFvec (input);
105 err = aubio_filterbank_set_triangle_bands (self->o,
108 PyErr_SetString (PyExc_ValueError,
109 "error when setting filter to A-weighting");
116 Py_filterbank_set_mel_coeffs_slaney (Py_filterbank * self, PyObject *args)
121 if (!PyArg_ParseTuple (args, "I", &samplerate)) {
125 err = aubio_filterbank_set_mel_coeffs_slaney (self->o, samplerate);
127 PyErr_SetString (PyExc_ValueError,
128 "error when setting filter to A-weighting");
135 Py_filterbank_set_coeffs (Py_filterbank * self, PyObject *args)
142 if (!PyArg_ParseTuple (args, "O", &input)) {
146 coeffs = PyAubio_ArrayToCFmat (input);
148 if (coeffs == NULL) {
149 PyErr_SetString (PyExc_ValueError,
150 "unable to parse input array");
154 err = aubio_filterbank_set_coeffs (self->o, coeffs);
157 PyErr_SetString (PyExc_ValueError,
158 "error when setting filter coefficients");
165 Py_filterbank_get_coeffs (Py_filterbank * self, PyObject *unused)
167 return (PyObject *)PyAubio_CFmatToArray(
168 aubio_filterbank_get_coeffs (self->o) );
171 static PyMethodDef Py_filterbank_methods[] = {
172 {"set_triangle_bands", (PyCFunction) Py_filterbank_set_triangle_bands,
173 METH_VARARGS, "set coefficients of filterbanks"},
174 {"set_mel_coeffs_slaney", (PyCFunction) Py_filterbank_set_mel_coeffs_slaney,
175 METH_VARARGS, "set coefficients of filterbank as in Auditory Toolbox"},
176 {"get_coeffs", (PyCFunction) Py_filterbank_get_coeffs,
177 METH_NOARGS, "get coefficients of filterbank"},
178 {"set_coeffs", (PyCFunction) Py_filterbank_set_coeffs,
179 METH_VARARGS, "set coefficients of filterbank"},
183 AUBIO_TYPEOBJECT(filterbank, "aubio.filterbank")