1 #include "aubio-types.h"
3 static char Py_fft_doc[] = ""
6 "Compute Fast Fourier Transorms.\n"
11 " size of the FFT to compute\n"
15 ">>> x = aubio.fvec(512)\n"
16 ">>> f = aubio.fft(512)\n"
18 "aubio cvec of 257 elements\n"
19 ">>> x2 = f.rdo(c); x2.shape\n"
28 // do / rdo input vectors
31 // do / rdo output results
37 Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
41 static char *kwlist[] = { "win_s", NULL };
43 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I", kwlist,
48 self = (Py_fft *) type->tp_alloc (type, 0);
54 self->win_s = Py_default_vector_length;
58 } else if (win_s < 0) {
59 PyErr_SetString (PyExc_ValueError,
60 "can not use negative window size");
64 return (PyObject *) self;
68 Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds)
70 self->o = new_aubio_fft (self->win_s);
71 if (self->o == NULL) {
72 // PyErr_Format(PyExc_RuntimeError, ...) was set above by new_ which called
73 // AUBIO_ERR when failing
77 self->doout = new_py_cvec(self->win_s);
78 self->rdoout = new_py_fvec(self->win_s);
84 Py_fft_del (Py_fft *self, PyObject *unused)
86 Py_XDECREF(self->doout);
87 Py_XDECREF(self->rdoout);
89 del_aubio_fft(self->o);
91 Py_TYPE(self)->tp_free((PyObject *) self);
95 Py_fft_do(Py_fft * self, PyObject * args)
100 if (!PyArg_ParseTuple (args, "O", &input)) {
104 if (!PyAubio_ArrayToCFvec(input, &(self->vecin))) {
108 if (self->vecin.length != self->win_s) {
109 PyErr_Format(PyExc_ValueError,
110 "input array has length %d, but fft expects length %d",
111 self->vecin.length, self->win_s);
115 Py_INCREF(self->doout);
116 if (!PyAubio_PyCvecToCCvec(self->doout, &c_out)) {
119 // compute the function
120 aubio_fft_do (self->o, &(self->vecin), &c_out);
124 static PyMemberDef Py_fft_members[] = {
125 {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY,
126 "size of the window"},
131 Py_fft_rdo(Py_fft * self, PyObject * args)
136 if (!PyArg_ParseTuple (args, "O", &input)) {
140 if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin)) ) {
144 if (self->cvecin.length != self->win_s / 2 + 1) {
145 PyErr_Format(PyExc_ValueError,
146 "input cvec has length %d, but fft expects length %d",
147 self->cvecin.length, self->win_s / 2 + 1);
151 Py_INCREF(self->rdoout);
152 if (!PyAubio_ArrayToCFvec(self->rdoout, &out) ) {
155 // compute the function
156 aubio_fft_rdo (self->o, &(self->cvecin), &out);
160 static PyMethodDef Py_fft_methods[] = {
161 {"rdo", (PyCFunction) Py_fft_rdo, METH_VARARGS,
162 "synthesis of spectral grain"},
166 PyTypeObject Py_fftType = {
167 PyVarObject_HEAD_INIT (NULL, 0)
171 (destructor) Py_fft_del,
181 (ternaryfunc)Py_fft_do,
202 (initproc) Py_fft_init,