Ignore:
Timestamp:
Jun 22, 2016, 1:00:10 PM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
4b9443c4
Parents:
60fc05b (diff), 6769586 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into notes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/ext/py-fft.c

    r60fc05b rf264b17  
    1 #include "aubiowraphell.h"
     1#include "aubio-types.h"
    22
    33static char Py_fft_doc[] = "fft object";
    44
    5 AUBIO_DECLARE(fft, uint_t win_s)
     5typedef struct
     6{
     7  PyObject_HEAD
     8  aubio_fft_t * o;
     9  uint_t win_s;
     10  // do / rdo input vectors
     11  fvec_t vecin;
     12  cvec_t cvecin;
     13  // do / rdo output results
     14  PyObject *doout;
     15  PyObject *rdoout;
     16} Py_fft;
    617
    7 //AUBIO_NEW(fft)
    818static PyObject *
    919Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
     
    3747}
    3848
     49static int
     50Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds)
     51{
     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)",
     58        self->win_s);
     59    return -1;
     60  }
    3961
    40 AUBIO_INIT(fft, self->win_s)
     62  self->doout = new_py_cvec(self->win_s);
     63  self->rdoout = new_py_fvec(self->win_s);
    4164
    42 AUBIO_DEL(fft)
     65  return 0;
     66}
    4367
    44 static PyObject *
    45 Py_fft_do(PyObject * self, PyObject * args)
     68static void
     69Py_fft_del (Py_fft *self, PyObject *unused)
     70{
     71  Py_XDECREF(self->doout);
     72  Py_XDECREF(self->rdoout);
     73  if (self->o) {
     74    del_aubio_fft(self->o);
     75  }
     76  Py_TYPE(self)->tp_free((PyObject *) self);
     77}
     78
     79static PyObject *
     80Py_fft_do(Py_fft * self, PyObject * args)
    4681{
    4782  PyObject *input;
    48   fvec_t *vec;
    49   cvec_t *output;
     83  cvec_t c_out;
    5084
    5185  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    5387  }
    5488
    55   vec = PyAubio_ArrayToCFvec (input);
    56 
    57   if (vec == NULL) {
     89  if (!PyAubio_ArrayToCFvec(input, &(self->vecin))) {
    5890    return NULL;
    5991  }
    6092
    61   output = new_cvec(((Py_fft *) self)->win_s);
     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);
     97    return NULL;
     98  }
    6299
     100  Py_INCREF(self->doout);
     101  if (!PyAubio_PyCvecToCCvec(self->doout, &c_out)) {
     102    return NULL;
     103  }
    63104  // compute the function
    64   aubio_fft_do (((Py_fft *)self)->o, vec, output);
    65   return (PyObject *)PyAubio_CCvecToPyCvec(output);
     105  aubio_fft_do (self->o, &(self->vecin), &c_out);
     106  return self->doout;
    66107}
    67108
    68 AUBIO_MEMBERS_START(fft)
     109static PyMemberDef Py_fft_members[] = {
    69110  {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY,
    70111    "size of the window"},
    71 AUBIO_MEMBERS_STOP(fft)
     112  {NULL}
     113};
    72114
    73 static PyObject * 
     115static PyObject *
    74116Py_fft_rdo(Py_fft * self, PyObject * args)
    75117{
    76118  PyObject *input;
    77   cvec_t *vec;
    78   fvec_t *output;
     119  fvec_t out;
    79120
    80121  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    82123  }
    83124
    84   vec = PyAubio_ArrayToCCvec (input);
    85 
    86   if (vec == NULL) {
     125  if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin)) ) {
    87126    return NULL;
    88127  }
    89128
    90   output = new_fvec(self->win_s);
     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);
     133    return NULL;
     134  }
    91135
     136  Py_INCREF(self->rdoout);
     137  if (!PyAubio_ArrayToCFvec(self->rdoout, &out) ) {
     138    return NULL;
     139  }
    92140  // compute the function
    93   aubio_fft_rdo (((Py_fft *)self)->o, vec, output);
    94   return (PyObject *)PyAubio_CFvecToArray(output);
     141  aubio_fft_rdo (self->o, &(self->cvecin), &out);
     142  return self->rdoout;
    95143}
    96144
     
    101149};
    102150
    103 AUBIO_TYPEOBJECT(fft, "aubio.fft")
     151PyTypeObject Py_fftType = {
     152  PyVarObject_HEAD_INIT (NULL, 0)
     153  "aubio.fft",
     154  sizeof (Py_fft),
     155  0,
     156  (destructor) Py_fft_del,
     157  0,
     158  0,
     159  0,
     160  0,
     161  0,
     162  0,
     163  0,
     164  0,
     165  0,
     166  (ternaryfunc)Py_fft_do,
     167  0,
     168  0,
     169  0,
     170  0,
     171  Py_TPFLAGS_DEFAULT,
     172  Py_fft_doc,
     173  0,
     174  0,
     175  0,
     176  0,
     177  0,
     178  0,
     179  Py_fft_methods,
     180  Py_fft_members,
     181  0,
     182  0,
     183  0,
     184  0,
     185  0,
     186  0,
     187  (initproc) Py_fft_init,
     188  0,
     189  Py_fft_new,
     190  0,
     191  0,
     192  0,
     193  0,
     194  0,
     195  0,
     196  0,
     197  0,
     198  0,
     199};
Note: See TracChangeset for help on using the changeset viewer.