1 | #include "aubiowraphell.h" |
---|
2 | |
---|
3 | static char Py_fft_doc[] = "fft object"; |
---|
4 | |
---|
5 | AUBIO_DECLARE(fft, uint_t win_s) |
---|
6 | |
---|
7 | //AUBIO_NEW(fft) |
---|
8 | static PyObject * |
---|
9 | Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds) |
---|
10 | { |
---|
11 | int win_s = 0; |
---|
12 | Py_fft *self; |
---|
13 | static char *kwlist[] = { "win_s", NULL }; |
---|
14 | |
---|
15 | if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I", kwlist, |
---|
16 | &win_s)) { |
---|
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 (win_s > 0) { |
---|
29 | self->win_s = win_s; |
---|
30 | } else if (win_s < 0) { |
---|
31 | PyErr_SetString (PyExc_ValueError, |
---|
32 | "can not use negative window size"); |
---|
33 | return NULL; |
---|
34 | } |
---|
35 | |
---|
36 | return (PyObject *) self; |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | AUBIO_INIT(fft, self->win_s) |
---|
41 | |
---|
42 | AUBIO_DEL(fft) |
---|
43 | |
---|
44 | static PyObject * |
---|
45 | Py_fft_do(PyObject * self, PyObject * args) |
---|
46 | { |
---|
47 | PyObject *input; |
---|
48 | fvec_t *vec; |
---|
49 | cvec_t *output; |
---|
50 | |
---|
51 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
52 | return NULL; |
---|
53 | } |
---|
54 | |
---|
55 | vec = PyAubio_ArrayToCFvec (input); |
---|
56 | |
---|
57 | if (vec == NULL) { |
---|
58 | return NULL; |
---|
59 | } |
---|
60 | |
---|
61 | output = new_cvec(((Py_fft *) self)->win_s); |
---|
62 | |
---|
63 | // compute the function |
---|
64 | aubio_fft_do (((Py_fft *)self)->o, vec, output); |
---|
65 | return (PyObject *)PyAubio_CCvecToPyCvec(output); |
---|
66 | } |
---|
67 | |
---|
68 | AUBIO_MEMBERS_START(fft) |
---|
69 | {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY, |
---|
70 | "size of the window"}, |
---|
71 | AUBIO_MEMBERS_STOP(fft) |
---|
72 | |
---|
73 | static PyObject * |
---|
74 | Py_fft_rdo(Py_fft * self, PyObject * args) |
---|
75 | { |
---|
76 | PyObject *input; |
---|
77 | cvec_t *vec; |
---|
78 | fvec_t *output; |
---|
79 | |
---|
80 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
81 | return NULL; |
---|
82 | } |
---|
83 | |
---|
84 | vec = PyAubio_ArrayToCCvec (input); |
---|
85 | |
---|
86 | if (vec == NULL) { |
---|
87 | return NULL; |
---|
88 | } |
---|
89 | |
---|
90 | output = new_fvec(self->win_s); |
---|
91 | |
---|
92 | // compute the function |
---|
93 | aubio_fft_rdo (((Py_fft *)self)->o, vec, output); |
---|
94 | return (PyObject *)PyAubio_CFvecToArray(output); |
---|
95 | } |
---|
96 | |
---|
97 | static PyMethodDef Py_fft_methods[] = { |
---|
98 | {"rdo", (PyCFunction) Py_fft_rdo, METH_VARARGS, |
---|
99 | "synthesis of spectral grain"}, |
---|
100 | {NULL} |
---|
101 | }; |
---|
102 | |
---|
103 | AUBIO_TYPEOBJECT(fft, "aubio.fft") |
---|