Changeset de81d2b


Ignore:
Timestamp:
Apr 18, 2016, 9:07:24 PM (3 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
7c785e6
Parents:
202697a
Message:

ext/py-fft.c: continue fixing memory leak (#49)

File:
1 edited

Legend:

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

    r202697a rde81d2b  
    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  cvec_t *out;
     11  fvec_t *rout;
     12} Py_fft;
    613
    714//AUBIO_NEW(fft)
     
    3744}
    3845
     46static int
     47Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds)
     48{
     49  self->o = new_aubio_fft (self->win_s);
     50  if (self->o == NULL) {
     51    char_t errstr[30];
     52    sprintf(errstr, "error creating fft with win_s=%d", self->win_s);
     53    PyErr_SetString (PyExc_StandardError, errstr);
     54    return -1;
     55  }
     56  self->out = new_cvec(self->win_s);
     57  self->rout = new_fvec(self->win_s);
    3958
    40 AUBIO_INIT(fft, self->win_s)
     59  return 0;
     60}
    4161
    42 AUBIO_DEL(fft)
     62static void
     63Py_fft_del (Py_fft *self, PyObject *unused)
     64{
     65  del_aubio_fft(self->o);
     66  del_cvec(self->out);
     67  del_fvec(self->rout);
     68  self->ob_type->tp_free((PyObject *) self);
     69}
    4370
    4471static PyObject *
    45 Py_fft_do(PyObject * self, PyObject * args)
     72Py_fft_do(Py_fft * self, PyObject * args)
    4673{
    4774  PyObject *input;
    4875  fvec_t *vec;
    49   cvec_t *output;
    5076
    5177  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    5985  }
    6086
    61   output = new_cvec(((Py_fft *) self)->win_s);
    62 
    6387  // compute the function
    64   aubio_fft_do (((Py_fft *)self)->o, vec, output);
    65   return (PyObject *)PyAubio_CCvecToPyCvec(output);
     88  aubio_fft_do (((Py_fft *)self)->o, vec, self->out);
     89  return (PyObject *)PyAubio_CCvecToPyCvec(self->out);
    6690}
    6791
     
    76100  PyObject *input;
    77101  cvec_t *vec;
    78   fvec_t *output;
    79102
    80103  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    88111  }
    89112
    90   output = new_fvec(self->win_s);
    91 
    92113  // compute the function
    93   aubio_fft_rdo (((Py_fft *)self)->o, vec, output);
    94   return (PyObject *)PyAubio_CFvecToArray(output);
     114  aubio_fft_rdo (((Py_fft *)self)->o, vec, self->rout);
     115  return (PyObject *)PyAubio_CFvecToArray(self->rout);
    95116}
    96117
Note: See TracChangeset for help on using the changeset viewer.