Ignore:
Timestamp:
Apr 24, 2016, 6:23:14 PM (9 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:
51b9c83
Parents:
a35db12
Message:

python/ext: simplify memory allocations, removed unneeded malloc/free calls

File:
1 edited

Legend:

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

    ra35db12 r569b363  
    99  uint_t n_filters;
    1010  uint_t win_s;
    11   cvec_t *vec;
     11  cvec_t vec;
     12  fvec_t freqs;
     13  fmat_t coeffs;
    1214  fvec_t *out;
    13   fvec_t *freqs;
    14   fmat_t *coeffs;
    1515} Py_filterbank;
    1616
     
    6767  self->out = new_fvec(self->n_filters);
    6868
    69   self->vec = (cvec_t *)malloc(sizeof(cvec_t));
    70 
    71   self->freqs = (fvec_t *)malloc(sizeof(fvec_t));
    72 
    73   self->coeffs = (fmat_t *)malloc(sizeof(fmat_t));
    74   self->coeffs->data = (smpl_t **)malloc(sizeof(smpl_t*) * self->n_filters);
    75   self->coeffs->height = self->n_filters;
    76 
    7769  return 0;
    7870}
     
    8375  del_aubio_filterbank(self->o);
    8476  del_fvec(self->out);
    85   free(self->vec);
    86   free(self->freqs);
    87   free(self->coeffs->data);
    88   free(self->coeffs);
     77  free(self->coeffs.data);
    8978  Py_TYPE(self)->tp_free((PyObject *) self);
    9079}
     
    9988  }
    10089
    101   if (!PyAubio_ArrayToCCvec(input, self->vec)) {
     90  if (!PyAubio_ArrayToCCvec(input, &(self->vec) )) {
    10291    return NULL;
    10392  }
    10493
    10594  // compute the function
    106   aubio_filterbank_do (self->o, self->vec, self->out);
     95  aubio_filterbank_do (self->o, &(self->vec), self->out);
    10796  return (PyObject *)PyAubio_CFvecToArray(self->out);
    10897}
     
    131120  }
    132121
    133   if (!PyAubio_ArrayToCFvec(input, self->freqs)) {
     122  if (!PyAubio_ArrayToCFvec(input, &(self->freqs) )) {
    134123    return NULL;
    135124  }
    136125
    137126  err = aubio_filterbank_set_triangle_bands (self->o,
    138       self->freqs, samplerate);
     127      &(self->freqs), samplerate);
    139128  if (err > 0) {
    140129    PyErr_SetString (PyExc_ValueError,
     
    174163  }
    175164
    176   if (!PyAubio_ArrayToCFmat(input, self->coeffs)) {
    177     return NULL;
    178   }
    179 
    180   err = aubio_filterbank_set_coeffs (self->o, self->coeffs);
     165  if (!PyAubio_ArrayToCFmat(input, &(self->coeffs))) {
     166    return NULL;
     167  }
     168
     169  err = aubio_filterbank_set_coeffs (self->o, &(self->coeffs));
    181170
    182171  if (err > 0) {
Note: See TracChangeset for help on using the changeset viewer.