[615ac7d] | 1 | #include "aubiowraphell.h" |
---|
| 2 | |
---|
| 3 | static char Py_fft_doc[] = "fft object"; |
---|
| 4 | |
---|
[96fe713] | 5 | AUBIO_DECLARE(fft, uint_t win_s) |
---|
[615ac7d] | 6 | |
---|
| 7 | //AUBIO_NEW(fft) |
---|
| 8 | static PyObject * |
---|
| 9 | Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds) |
---|
| 10 | { |
---|
[96fe713] | 11 | int win_s = 0; |
---|
[615ac7d] | 12 | Py_fft *self; |
---|
[96fe713] | 13 | static char *kwlist[] = { "win_s", NULL }; |
---|
[615ac7d] | 14 | |
---|
[96fe713] | 15 | if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I", kwlist, |
---|
| 16 | &win_s)) { |
---|
[615ac7d] | 17 | return NULL; |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | self = (Py_fft *) type->tp_alloc (type, 0); |
---|
| 21 | |
---|
| 22 | if (self == NULL) { |
---|
| 23 | return NULL; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | self->win_s = Py_default_vector_length; |
---|
| 27 | |
---|
| 28 | if (win_s > 0) { |
---|
| 29 | self->win_s = win_s; |
---|
| 30 | } else if (win_s < 0) { |
---|
| 31 | PyErr_SetString (PyExc_ValueError, |
---|
| 32 | "can not use negative window size"); |
---|
| 33 | return NULL; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | return (PyObject *) self; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | |
---|
[96fe713] | 40 | AUBIO_INIT(fft, self->win_s) |
---|
[615ac7d] | 41 | |
---|
| 42 | AUBIO_DEL(fft) |
---|
| 43 | |
---|
| 44 | static PyObject * |
---|
| 45 | Py_fft_do(PyObject * self, PyObject * args) |
---|
| 46 | { |
---|
| 47 | PyObject *input; |
---|
[965b302] | 48 | fvec_t *vec; |
---|
| 49 | cvec_t *output; |
---|
[615ac7d] | 50 | |
---|
| 51 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
| 52 | return NULL; |
---|
| 53 | } |
---|
| 54 | |
---|
[965b302] | 55 | vec = PyAubio_ArrayToCFvec (input); |
---|
[615ac7d] | 56 | |
---|
| 57 | if (vec == NULL) { |
---|
| 58 | return NULL; |
---|
| 59 | } |
---|
| 60 | |
---|
[965b302] | 61 | output = new_cvec(((Py_fft *) self)->win_s); |
---|
[615ac7d] | 62 | |
---|
| 63 | // compute the function |
---|
[965b302] | 64 | aubio_fft_do (((Py_fft *)self)->o, vec, output); |
---|
| 65 | return (PyObject *)PyAubio_CCvecToPyCvec(output); |
---|
[615ac7d] | 66 | } |
---|
| 67 | |
---|
| 68 | AUBIO_MEMBERS_START(fft) |
---|
| 69 | {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY, |
---|
| 70 | "size of the window"}, |
---|
| 71 | AUBIO_MEMBERS_STOP(fft) |
---|
| 72 | |
---|
| 73 | static PyObject * |
---|
[965b302] | 74 | Py_fft_rdo(Py_fft * self, PyObject * args) |
---|
[615ac7d] | 75 | { |
---|
| 76 | PyObject *input; |
---|
[965b302] | 77 | cvec_t *vec; |
---|
| 78 | fvec_t *output; |
---|
[615ac7d] | 79 | |
---|
| 80 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
| 81 | return NULL; |
---|
| 82 | } |
---|
| 83 | |
---|
[965b302] | 84 | vec = PyAubio_ArrayToCCvec (input); |
---|
[615ac7d] | 85 | |
---|
| 86 | if (vec == NULL) { |
---|
| 87 | return NULL; |
---|
| 88 | } |
---|
| 89 | |
---|
[965b302] | 90 | output = new_fvec(self->win_s); |
---|
[615ac7d] | 91 | |
---|
| 92 | // compute the function |
---|
[965b302] | 93 | aubio_fft_rdo (((Py_fft *)self)->o, vec, output); |
---|
| 94 | return (PyObject *)PyAubio_CFvecToArray(output); |
---|
[615ac7d] | 95 | } |
---|
| 96 | |
---|
| 97 | static PyMethodDef Py_fft_methods[] = { |
---|
| 98 | {"rdo", (PyCFunction) Py_fft_rdo, METH_VARARGS, |
---|
| 99 | "synthesis of spectral grain"}, |
---|
| 100 | {NULL} |
---|
| 101 | }; |
---|
| 102 | |
---|
| 103 | AUBIO_TYPEOBJECT(fft, "aubio.fft") |
---|