[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 (self == NULL) { |
---|
| 29 | return NULL; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | if (win_s > 0) { |
---|
| 33 | self->win_s = win_s; |
---|
| 34 | } else if (win_s < 0) { |
---|
| 35 | PyErr_SetString (PyExc_ValueError, |
---|
| 36 | "can not use negative window size"); |
---|
| 37 | return NULL; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | return (PyObject *) self; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | |
---|
[96fe713] | 44 | AUBIO_INIT(fft, self->win_s) |
---|
[615ac7d] | 45 | |
---|
| 46 | AUBIO_DEL(fft) |
---|
| 47 | |
---|
| 48 | static PyObject * |
---|
| 49 | Py_fft_do(PyObject * self, PyObject * args) |
---|
| 50 | { |
---|
| 51 | PyObject *input; |
---|
| 52 | Py_fvec *vec; |
---|
| 53 | Py_cvec *output; |
---|
| 54 | |
---|
| 55 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
| 56 | return NULL; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | vec = PyAubio_ArrayToFvec (input); |
---|
| 60 | |
---|
| 61 | if (vec == NULL) { |
---|
| 62 | return NULL; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | output = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); |
---|
| 66 | output->length = ((Py_fft *) self)->win_s; |
---|
[96fe713] | 67 | output->o = new_cvec(((Py_fft *) self)->win_s); |
---|
[615ac7d] | 68 | |
---|
| 69 | // compute the function |
---|
| 70 | aubio_fft_do (((Py_fft *)self)->o, vec->o, output->o); |
---|
| 71 | Py_INCREF(output); |
---|
| 72 | return (PyObject *)output; |
---|
| 73 | //return (PyObject *)PyAubio_CvecToArray(output); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | AUBIO_MEMBERS_START(fft) |
---|
| 77 | {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY, |
---|
| 78 | "size of the window"}, |
---|
| 79 | AUBIO_MEMBERS_STOP(fft) |
---|
| 80 | |
---|
| 81 | static PyObject * |
---|
| 82 | Py_fft_rdo(PyObject * self, PyObject * args) |
---|
| 83 | { |
---|
| 84 | PyObject *input; |
---|
| 85 | Py_cvec *vec; |
---|
| 86 | Py_fvec *output; |
---|
| 87 | |
---|
| 88 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
| 89 | return NULL; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | vec = PyAubio_ArrayToCvec (input); |
---|
| 93 | |
---|
| 94 | if (vec == NULL) { |
---|
| 95 | return NULL; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType); |
---|
| 99 | output->length = ((Py_fft *) self)->win_s; |
---|
[96fe713] | 100 | output->o = new_fvec(output->length); |
---|
[615ac7d] | 101 | |
---|
| 102 | // compute the function |
---|
| 103 | aubio_fft_rdo (((Py_fft *)self)->o, vec->o, output->o); |
---|
| 104 | return (PyObject *)PyAubio_FvecToArray(output); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | static PyMethodDef Py_fft_methods[] = { |
---|
| 108 | {"rdo", (PyCFunction) Py_fft_rdo, METH_VARARGS, |
---|
| 109 | "synthesis of spectral grain"}, |
---|
| 110 | {NULL} |
---|
| 111 | }; |
---|
| 112 | |
---|
| 113 | AUBIO_TYPEOBJECT(fft, "aubio.fft") |
---|