1 #include "aubio-types.h"
3 static char Py_fft_doc[] = "fft object";
10 // do / rdo input vectors
13 // do / rdo output results
19 Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
23 static char *kwlist[] = { "win_s", NULL };
25 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I", kwlist,
30 self = (Py_fft *) type->tp_alloc (type, 0);
36 self->win_s = Py_default_vector_length;
40 } else if (win_s < 0) {
41 PyErr_SetString (PyExc_ValueError,
42 "can not use negative window size");
46 return (PyObject *) self;
50 Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds)
52 self->o = new_aubio_fft (self->win_s);
53 if (self->o == NULL) {
54 // PyErr_Format(PyExc_RuntimeError, ...) was set above by new_ which called
55 // AUBIO_ERR when failing
59 self->doout = new_py_cvec(self->win_s);
60 self->rdoout = new_py_fvec(self->win_s);
66 Py_fft_del (Py_fft *self, PyObject *unused)
68 Py_XDECREF(self->doout);
69 Py_XDECREF(self->rdoout);
71 del_aubio_fft(self->o);
73 Py_TYPE(self)->tp_free((PyObject *) self);
77 Py_fft_do(Py_fft * self, PyObject * args)
82 if (!PyArg_ParseTuple (args, "O", &input)) {
86 if (!PyAubio_ArrayToCFvec(input, &(self->vecin))) {
90 if (self->vecin.length != self->win_s) {
91 PyErr_Format(PyExc_ValueError,
92 "input array has length %d, but fft expects length %d",
93 self->vecin.length, self->win_s);
97 Py_INCREF(self->doout);
98 if (!PyAubio_PyCvecToCCvec(self->doout, &c_out)) {
101 // compute the function
102 aubio_fft_do (self->o, &(self->vecin), &c_out);
106 static PyMemberDef Py_fft_members[] = {
107 {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY,
108 "size of the window"},
113 Py_fft_rdo(Py_fft * self, PyObject * args)
118 if (!PyArg_ParseTuple (args, "O", &input)) {
122 if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin)) ) {
126 if (self->cvecin.length != self->win_s / 2 + 1) {
127 PyErr_Format(PyExc_ValueError,
128 "input cvec has length %d, but fft expects length %d",
129 self->cvecin.length, self->win_s / 2 + 1);
133 Py_INCREF(self->rdoout);
134 if (!PyAubio_ArrayToCFvec(self->rdoout, &out) ) {
137 // compute the function
138 aubio_fft_rdo (self->o, &(self->cvecin), &out);
142 static PyMethodDef Py_fft_methods[] = {
143 {"rdo", (PyCFunction) Py_fft_rdo, METH_VARARGS,
144 "synthesis of spectral grain"},
148 PyTypeObject Py_fftType = {
149 PyVarObject_HEAD_INIT (NULL, 0)
153 (destructor) Py_fft_del,
163 (ternaryfunc)Py_fft_do,
184 (initproc) Py_fft_init,