Showing the changes to python/ext (1 of 1 file). Show all
Unified · Split
| @@ -2,7 +2,14 @@ · 1 unmodified line | |||
| 2 | 2 | ||
| 3 | static char Py_filterbank_doc[] = "filterbank object"; | 3 | static char Py_filterbank_doc[] = "filterbank object"; |
| 4 | 4 | ||
| 5 | AUBIO_DECLARE(filterbank, uint_t n_filters; uint_t win_s) | 5 | typedef struct |
| 6 | { | ||
| 7 | PyObject_HEAD | ||
| 8 | aubio_filterbank_t * o; | ||
| 9 | uint_t n_filters; | ||
| 10 | uint_t win_s; | ||
| 11 | fvec_t *out; | ||
| 12 | } Py_filterbank; | ||
| 6 | 13 | ||
| 7 | //AUBIO_NEW(filterbank) | 14 | //AUBIO_NEW(filterbank) |
| 8 | static PyObject * | 15 | static PyObject * |
| @@ -44,17 +51,35 @@ Py_filterbank_new (PyTypeObject * type, PyObject * args, PyObject * kwds) · 35 unmodified lines | |||
| 44 | return (PyObject *) self; | 51 | return (PyObject *) self; |
| 45 | } | 52 | } |
| 46 | 53 | ||
| 54 | static int | ||
| 55 | Py_filterbank_init (Py_filterbank * self, PyObject * args, PyObject * kwds) | ||
| 56 | { | ||
| 57 | self->o = new_aubio_filterbank (self->n_filters, self->win_s); | ||
| 58 | if (self->o == NULL) { | ||
| 59 | char_t errstr[30]; | ||
| 60 | sprintf(errstr, "error creating filterbank with n_filters=%d, win_s=%d", | ||
| 61 | self->n_filters, self->win_s); | ||
| 62 | PyErr_SetString (PyExc_StandardError, errstr); | ||
| 63 | return -1; | ||
| 64 | } | ||
| 65 | self->out = new_fvec(self->n_filters); | ||
| 47 | 66 | ||
| 48 | AUBIO_INIT(filterbank, self->n_filters, self->win_s) | 67 | return 0; |
| 68 | } | ||
| 49 | 69 | ||
| 50 | AUBIO_DEL(filterbank) | 70 | static void |
| 71 | Py_filterbank_del (Py_filterbank *self, PyObject *unused) | ||
| 72 | { | ||
| 73 | del_aubio_filterbank(self->o); | ||
| 74 | del_fvec(self->out); | ||
| 75 | self->ob_type->tp_free((PyObject *) self); | ||
| 76 | } | ||
| 51 | 77 | ||
| 52 | static PyObject * | 78 | static PyObject * |
| 53 | Py_filterbank_do(Py_filterbank * self, PyObject * args) | 79 | Py_filterbank_do(Py_filterbank * self, PyObject * args) |
| 54 | { | 80 | { |
| 55 | PyObject *input; | 81 | PyObject *input; |
| 56 | cvec_t *vec; | 82 | cvec_t *vec; |
| 57 | fvec_t *out; | ||
| 58 | 83 | ||
| 59 | if (!PyArg_ParseTuple (args, "O", &input)) { | 84 | if (!PyArg_ParseTuple (args, "O", &input)) { |
| 60 | return NULL; | 85 | return NULL; |
| @@ -66,11 +91,9 @@ Py_filterbank_do(Py_filterbank * self, PyObject * args) · 5 unmodified lines | |||
| 66 | return NULL; | 91 | return NULL; |
| 67 | } | 92 | } |
| 68 | 93 | ||
| 69 | out = new_fvec (self->n_filters); | ||
| 70 | |||
| 71 | // compute the function | 94 | // compute the function |
| 72 | aubio_filterbank_do (self->o, vec, out); | 95 | aubio_filterbank_do (self->o, vec, self->out); |
| 73 | return (PyObject *)PyAubio_CFvecToArray(out); | 96 | return (PyObject *)PyAubio_CFvecToArray(self->out); |
| 74 | } | 97 | } |
| 75 | 98 | ||
| 76 | AUBIO_MEMBERS_START(filterbank) | 99 | AUBIO_MEMBERS_START(filterbank) |