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) {
55 sprintf(errstr, "error creating fft with win_s=%d", self->win_s);
56 PyErr_SetString (PyExc_Exception, errstr);
60 self->doout = new_py_cvec(self->win_s);
61 self->rdoout = new_py_fvec(self->win_s);
67 Py_fft_del (Py_fft *self, PyObject *unused)
69 Py_XDECREF(self->doout);
70 Py_XDECREF(self->rdoout);
71 del_aubio_fft(self->o);
72 Py_TYPE(self)->tp_free((PyObject *) self);
76 Py_fft_do(Py_fft * self, PyObject * args)
80 if (!PyArg_ParseTuple (args, "O", &input)) {
84 if (!PyAubio_ArrayToCFvec(input, &(self->vecin))) {
88 if (self->vecin.length != self->win_s) {
89 PyErr_Format(PyExc_ValueError,
90 "input array has length %d, but fft expects length %d",
91 self->vecin.length, self->win_s);
96 Py_INCREF(self->doout);
97 if (!PyAubio_PyCvecToCCvec(self->doout, &c_out)) {
100 // compute the function
101 aubio_fft_do (self->o, &(self->vecin), &c_out);
105 static PyMemberDef Py_fft_members[] = {
106 {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY,
107 "size of the window"},
112 Py_fft_rdo(Py_fft * self, PyObject * args)
116 if (!PyArg_ParseTuple (args, "O", &input)) {
120 if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin)) ) {
124 if (self->cvecin.length != self->win_s / 2 + 1) {
125 PyErr_Format(PyExc_ValueError,
126 "input cvec has length %d, but fft expects length %d",
127 self->cvecin.length, self->win_s / 2 + 1);
132 Py_INCREF(self->rdoout);
133 if (!PyAubio_ArrayToCFvec(self->rdoout, &out) ) {
136 // compute the function
137 aubio_fft_rdo (self->o, &(self->cvecin), &out);
141 static PyMethodDef Py_fft_methods[] = {
142 {"rdo", (PyCFunction) Py_fft_rdo, METH_VARARGS,
143 "synthesis of spectral grain"},
147 PyTypeObject Py_fftType = {
148 PyVarObject_HEAD_INIT (NULL, 0)
152 (destructor) Py_fft_del,
162 (ternaryfunc)Py_fft_do,
183 (initproc) Py_fft_init,