Ignore:
Timestamp:
Mar 10, 2017, 2:26:32 PM (7 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, sampler
Children:
ee8a57c
Parents:
00d0275 (diff), 67b6618 (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 awhitening

File:
1 edited

Legend:

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

    r00d0275 r155cc10  
    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, ...) was set above by new_ which called
     55    // AUBIO_ERR when failing
     56    return -1;
     57  }
    3958
    40 AUBIO_INIT(fft, self->win_s)
     59  self->doout = new_py_cvec(self->win_s);
     60  self->rdoout = new_py_fvec(self->win_s);
    4161
    42 AUBIO_DEL(fft)
     62  return 0;
     63}
    4364
    44 static PyObject *
    45 Py_fft_do(PyObject * self, PyObject * args)
     65static void
     66Py_fft_del (Py_fft *self, PyObject *unused)
     67{
     68  Py_XDECREF(self->doout);
     69  Py_XDECREF(self->rdoout);
     70  if (self->o) {
     71    del_aubio_fft(self->o);
     72  }
     73  Py_TYPE(self)->tp_free((PyObject *) self);
     74}
     75
     76static PyObject *
     77Py_fft_do(Py_fft * self, PyObject * args)
    4678{
    4779  PyObject *input;
    48   fvec_t *vec;
    49   cvec_t *output;
     80  cvec_t c_out;
    5081
    5182  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    5384  }
    5485
    55   vec = PyAubio_ArrayToCFvec (input);
    56 
    57   if (vec == NULL) {
     86  if (!PyAubio_ArrayToCFvec(input, &(self->vecin))) {
    5887    return NULL;
    5988  }
    6089
    61   output = new_cvec(((Py_fft *) self)->win_s);
     90  if (self->vecin.length != self->win_s) {
     91    PyErr_Format(PyExc_ValueError,
     92                 "input array has length %d, but fft expects length %d",
     93                 self->vecin.length, self->win_s);
     94    return NULL;
     95  }
    6296
     97  Py_INCREF(self->doout);
     98  if (!PyAubio_PyCvecToCCvec(self->doout, &c_out)) {
     99    return NULL;
     100  }
    63101  // compute the function
    64   aubio_fft_do (((Py_fft *)self)->o, vec, output);
    65   return (PyObject *)PyAubio_CCvecToPyCvec(output);
     102  aubio_fft_do (self->o, &(self->vecin), &c_out);
     103  return self->doout;
    66104}
    67105
    68 AUBIO_MEMBERS_START(fft)
     106static PyMemberDef Py_fft_members[] = {
    69107  {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY,
    70108    "size of the window"},
    71 AUBIO_MEMBERS_STOP(fft)
     109  {NULL}
     110};
    72111
    73 static PyObject * 
     112static PyObject *
    74113Py_fft_rdo(Py_fft * self, PyObject * args)
    75114{
    76115  PyObject *input;
    77   cvec_t *vec;
    78   fvec_t *output;
     116  fvec_t out;
    79117
    80118  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    82120  }
    83121
    84   vec = PyAubio_ArrayToCCvec (input);
    85 
    86   if (vec == NULL) {
     122  if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin)) ) {
    87123    return NULL;
    88124  }
    89125
    90   output = new_fvec(self->win_s);
     126  if (self->cvecin.length != self->win_s / 2 + 1) {
     127    PyErr_Format(PyExc_ValueError,
     128                 "input cvec has length %d, but fft expects length %d",
     129                 self->cvecin.length, self->win_s / 2 + 1);
     130    return NULL;
     131  }
    91132
     133  Py_INCREF(self->rdoout);
     134  if (!PyAubio_ArrayToCFvec(self->rdoout, &out) ) {
     135    return NULL;
     136  }
    92137  // compute the function
    93   aubio_fft_rdo (((Py_fft *)self)->o, vec, output);
    94   return (PyObject *)PyAubio_CFvecToArray(output);
     138  aubio_fft_rdo (self->o, &(self->cvecin), &out);
     139  return self->rdoout;
    95140}
    96141
     
    101146};
    102147
    103 AUBIO_TYPEOBJECT(fft, "aubio.fft")
     148PyTypeObject Py_fftType = {
     149  PyVarObject_HEAD_INIT (NULL, 0)
     150  "aubio.fft",
     151  sizeof (Py_fft),
     152  0,
     153  (destructor) Py_fft_del,
     154  0,
     155  0,
     156  0,
     157  0,
     158  0,
     159  0,
     160  0,
     161  0,
     162  0,
     163  (ternaryfunc)Py_fft_do,
     164  0,
     165  0,
     166  0,
     167  0,
     168  Py_TPFLAGS_DEFAULT,
     169  Py_fft_doc,
     170  0,
     171  0,
     172  0,
     173  0,
     174  0,
     175  0,
     176  Py_fft_methods,
     177  Py_fft_members,
     178  0,
     179  0,
     180  0,
     181  0,
     182  0,
     183  0,
     184  (initproc) Py_fft_init,
     185  0,
     186  Py_fft_new,
     187  0,
     188  0,
     189  0,
     190  0,
     191  0,
     192  0,
     193  0,
     194  0,
     195  0,
     196};
Note: See TracChangeset for help on using the changeset viewer.