source: interfaces/python/py-fft.c @ 615ac7d

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 615ac7d was 615ac7d, checked in by Paul Brossier <piem@piem.org>, 15 years ago

.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1#include "aubiowraphell.h"
2
3static char Py_fft_doc[] = "fft object";
4
5AUBIO_DECLARE(fft, uint_t win_s; uint_t channels)
6
7//AUBIO_NEW(fft)
8static PyObject *
9Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
10{
11  int win_s = 0, channels = 0;
12  Py_fft *self;
13  static char *kwlist[] = { "win_s", "channels", NULL };
14
15  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
16          &win_s, &channels)) {
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  self->channels = Py_default_vector_channels;
28
29  if (self == NULL) {
30    return NULL;
31  }
32
33  if (win_s > 0) {
34    self->win_s = win_s;
35  } else if (win_s < 0) {
36    PyErr_SetString (PyExc_ValueError,
37        "can not use negative window size");
38    return NULL;
39  }
40
41  if (channels > 0) {
42    self->channels = channels;
43  } else if (channels < 0) {
44    PyErr_SetString (PyExc_ValueError,
45        "can not use negative number of filters");
46    return NULL;
47  }
48
49  return (PyObject *) self;
50}
51
52
53AUBIO_INIT(fft, self->win_s, self->channels)
54
55AUBIO_DEL(fft)
56
57static PyObject * 
58Py_fft_do(PyObject * self, PyObject * args)
59{
60  PyObject *input;
61  Py_fvec *vec;
62  Py_cvec *output;
63
64  if (!PyArg_ParseTuple (args, "O", &input)) {
65    return NULL;
66  }
67
68  vec = PyAubio_ArrayToFvec (input);
69
70  if (vec == NULL) {
71    return NULL;
72  }
73
74  output = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
75  output->channels = vec->channels;
76  output->length = ((Py_fft *) self)->win_s;
77  output->o = new_cvec(((Py_fft *) self)->win_s, vec->channels);
78
79  // compute the function
80  aubio_fft_do (((Py_fft *)self)->o, vec->o, output->o);
81  Py_INCREF(output);
82  return (PyObject *)output;
83  //return (PyObject *)PyAubio_CvecToArray(output);
84}
85
86AUBIO_MEMBERS_START(fft) 
87  {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY,
88    "size of the window"},
89  {"channels", T_INT, offsetof (Py_fft, channels), READONLY,
90    "number of channels"},
91AUBIO_MEMBERS_STOP(fft)
92
93static PyObject * 
94Py_fft_rdo(PyObject * self, PyObject * args)
95{
96  PyObject *input;
97  Py_cvec *vec;
98  Py_fvec *output;
99
100  if (!PyArg_ParseTuple (args, "O", &input)) {
101    return NULL;
102  }
103
104  vec = PyAubio_ArrayToCvec (input);
105
106  if (vec == NULL) {
107    return NULL;
108  }
109
110  output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType);
111  output->channels = vec->channels;
112  output->length = ((Py_fft *) self)->win_s;
113  output->o = new_fvec(output->length, output->channels);
114
115  // compute the function
116  aubio_fft_rdo (((Py_fft *)self)->o, vec->o, output->o);
117  return (PyObject *)PyAubio_FvecToArray(output);
118}
119
120static PyMethodDef Py_fft_methods[] = {
121  {"rdo", (PyCFunction) Py_fft_rdo, METH_VARARGS,
122    "synthesis of spectral grain"},
123  {NULL}
124};
125
126AUBIO_TYPEOBJECT(fft, "aubio.fft")
Note: See TracBrowser for help on using the repository browser.