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,
55 "error creating fft with win_s=%d "
56 "(should be a power of 2 greater than 1; "
57 "try recompiling aubio with --enable-fftw3)",
62 self->doout = new_py_cvec(self->win_s);
63 self->rdoout = new_py_fvec(self->win_s);
69 Py_fft_del (Py_fft *self, PyObject *unused)
71 Py_XDECREF(self->doout);
72 Py_XDECREF(self->rdoout);
74 del_aubio_fft(self->o);
76 Py_TYPE(self)->tp_free((PyObject *) self);
80 Py_fft_do(Py_fft * self, PyObject * args)
85 if (!PyArg_ParseTuple (args, "O", &input)) {
89 if (!PyAubio_ArrayToCFvec(input, &(self->vecin))) {
93 if (self->vecin.length != self->win_s) {
94 PyErr_Format(PyExc_ValueError,
95 "input array has length %d, but fft expects length %d",
96 self->vecin.length, self->win_s);
100 Py_INCREF(self->doout);
101 if (!PyAubio_PyCvecToCCvec(self->doout, &c_out)) {
104 // compute the function
105 aubio_fft_do (self->o, &(self->vecin), &c_out);
109 static PyMemberDef Py_fft_members[] = {
110 {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY,
111 "size of the window"},
116 Py_fft_rdo(Py_fft * self, PyObject * args)
121 if (!PyArg_ParseTuple (args, "O", &input)) {
125 if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin)) ) {
129 if (self->cvecin.length != self->win_s / 2 + 1) {
130 PyErr_Format(PyExc_ValueError,
131 "input cvec has length %d, but fft expects length %d",
132 self->cvecin.length, self->win_s / 2 + 1);
136 Py_INCREF(self->rdoout);
137 if (!PyAubio_ArrayToCFvec(self->rdoout, &out) ) {
140 // compute the function
141 aubio_fft_rdo (self->o, &(self->cvecin), &out);
145 static PyMethodDef Py_fft_methods[] = {
146 {"rdo", (PyCFunction) Py_fft_rdo, METH_VARARGS,
147 "synthesis of spectral grain"},
151 PyTypeObject Py_fftType = {
152 PyVarObject_HEAD_INIT (NULL, 0)
156 (destructor) Py_fft_del,
166 (ternaryfunc)Py_fft_do,
187 (initproc) Py_fft_init,