Showing the changes to python/ext/py-fft.c (1 of 1 file). Show all
Unified · Split
| @@ -2,7 +2,14 @@ · 1 unmodified line | |||
| 2 | 2 | ||
| 3 | static char Py_fft_doc[] = "fft object"; | 3 | static char Py_fft_doc[] = "fft object"; |
| 4 | 4 | ||
| 5 | AUBIO_DECLARE(fft, uint_t win_s) | 5 | typedef struct |
| 6 | { | ||
| 7 | PyObject_HEAD | ||
| 8 | aubio_fft_t * o; | ||
| 9 | uint_t win_s; | ||
| 10 | cvec_t *out; | ||
| 11 | fvec_t *rout; | ||
| 12 | } Py_fft; | ||
| 6 | 13 | ||
| 7 | //AUBIO_NEW(fft) | 14 | //AUBIO_NEW(fft) |
| 8 | static PyObject * | 15 | static PyObject * |
| @@ -36,17 +43,36 @@ Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds) · 27 unmodified lines | |||
| 36 | return (PyObject *) self; | 43 | return (PyObject *) self; |
| 37 | } | 44 | } |
| 38 | 45 | ||
| 46 | static int | ||
| 47 | Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds) | ||
| 48 | { | ||
| 49 | self->o = new_aubio_fft (self->win_s); | ||
| 50 | if (self->o == NULL) { | ||
| 51 | char_t errstr[30]; | ||
| 52 | sprintf(errstr, "error creating fft with win_s=%d", self->win_s); | ||
| 53 | PyErr_SetString (PyExc_StandardError, errstr); | ||
| 54 | return -1; | ||
| 55 | } | ||
| 56 | self->out = new_cvec(self->win_s); | ||
| 57 | self->rout = new_fvec(self->win_s); | ||
| 39 | 58 | ||
| 40 | AUBIO_INIT(fft, self->win_s) | 59 | return 0; |
| 60 | } | ||
| 41 | 61 | ||
| 42 | AUBIO_DEL(fft) | 62 | static void |
| 63 | Py_fft_del (Py_fft *self, PyObject *unused) | ||
| 64 | { | ||
| 65 | del_aubio_fft(self->o); | ||
| 66 | del_cvec(self->out); | ||
| 67 | del_fvec(self->rout); | ||
| 68 | self->ob_type->tp_free((PyObject *) self); | ||
| 69 | } | ||
| 43 | 70 | ||
| 44 | static PyObject * | 71 | static PyObject * |
| 45 | Py_fft_do(PyObject * self, PyObject * args) | 72 | Py_fft_do(Py_fft * self, PyObject * args) |
| 46 | { | 73 | { |
| 47 | PyObject *input; | 74 | PyObject *input; |
| 48 | fvec_t *vec; | 75 | fvec_t *vec; |
| 49 | cvec_t *output; | ||
| 50 | 76 | ||
| 51 | if (!PyArg_ParseTuple (args, "O", &input)) { | 77 | if (!PyArg_ParseTuple (args, "O", &input)) { |
| 52 | return NULL; | 78 | return NULL; |
| @@ -58,11 +84,9 @@ Py_fft_do(PyObject * self, PyObject * args) · 5 unmodified lines | |||
| 58 | return NULL; | 84 | return NULL; |
| 59 | } | 85 | } |
| 60 | 86 | ||
| 61 | output = new_cvec(((Py_fft *) self)->win_s); | ||
| 62 | |||
| 63 | // compute the function | 87 | // compute the function |
| 64 | aubio_fft_do (((Py_fft *)self)->o, vec, output); | 88 | aubio_fft_do (((Py_fft *)self)->o, vec, self->out); |
| 65 | return (PyObject *)PyAubio_CCvecToPyCvec(output); | 89 | return (PyObject *)PyAubio_CCvecToPyCvec(self->out); |
| 66 | } | 90 | } |
| 67 | 91 | ||
| 68 | AUBIO_MEMBERS_START(fft) | 92 | AUBIO_MEMBERS_START(fft) |
| @@ -75,7 +99,6 @@ Py_fft_rdo(Py_fft * self, PyObject * args) · 6 unmodified lines | |||
| 75 | { | 99 | { |
| 76 | PyObject *input; | 100 | PyObject *input; |
| 77 | cvec_t *vec; | 101 | cvec_t *vec; |
| 78 | fvec_t *output; | ||
| 79 | 102 | ||
| 80 | if (!PyArg_ParseTuple (args, "O", &input)) { | 103 | if (!PyArg_ParseTuple (args, "O", &input)) { |
| 81 | return NULL; | 104 | return NULL; |
| @@ -87,11 +110,9 @@ Py_fft_rdo(Py_fft * self, PyObject * args) · 5 unmodified lines | |||
| 87 | return NULL; | 110 | return NULL; |
| 88 | } | 111 | } |
| 89 | 112 | ||
| 90 | output = new_fvec(self->win_s); | ||
| 91 | |||
| 92 | // compute the function | 113 | // compute the function |
| 93 | aubio_fft_rdo (((Py_fft *)self)->o, vec, output); | 114 | aubio_fft_rdo (((Py_fft *)self)->o, vec, self->rout); |
| 94 | return (PyObject *)PyAubio_CFvecToArray(output); | 115 | return (PyObject *)PyAubio_CFvecToArray(self->rout); |
| 95 | } | 116 | } |
| 96 | 117 | ||
| 97 | static PyMethodDef Py_fft_methods[] = { | 118 | static PyMethodDef Py_fft_methods[] = { |