source: python/ext/py-fft.c @ 1573b16

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

python/: move source files to ext/

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