Changeset b5bef11


Ignore:
Timestamp:
Apr 21, 2016, 9:31:10 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:
a7f398d
Parents:
bfe8256
Message:

ext/: use new proxy functions

Location:
python/ext
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • python/ext/aubiomodule.c

    rbfe8256 rb5bef11  
    9696  }
    9797
    98   vec = PyAubio_ArrayToCFvec (input);
    99 
    100   if (vec == NULL) {
     98  vec = (fvec_t *)malloc(sizeof(fvec_t));
     99  if (!PyAubio_ArrayToCFvec(input, vec)) {
     100    free(vec);
    101101    return NULL;
    102102  }
     
    104104  // compute the function
    105105  result = Py_BuildValue ("f", fvec_alpha_norm (vec, alpha));
     106  free(vec);
    106107  if (result == NULL) {
    107108    return NULL;
     
    186187  }
    187188
    188   vec = PyAubio_ArrayToCFvec (input);
    189 
    190   if (vec == NULL) {
     189  vec = (fvec_t *)malloc(sizeof(fvec_t));
     190  if (!PyAubio_ArrayToCFvec(input, vec)) {
     191    free(vec);
    191192    return NULL;
    192193  }
     
    194195  // compute the function
    195196  result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec));
     197  free(vec);
    196198  if (result == NULL) {
    197199    return NULL;
     
    215217  }
    216218
    217   vec = PyAubio_ArrayToCFvec (input);
    218 
    219   if (vec == NULL) {
     219  vec = (fvec_t *)malloc(sizeof(fvec_t));
     220  if (!PyAubio_ArrayToCFvec(input, vec)) {
     221    free(vec);
    220222    return NULL;
    221223  }
  • python/ext/py-fft.c

    rbfe8256 rb5bef11  
    88  aubio_fft_t * o;
    99  uint_t win_s;
     10  fvec_t *vecin;
    1011  cvec_t *out;
     12  Py_cvec *py_out;
     13  cvec_t *cvecin;
    1114  fvec_t *rout;
    1215} Py_fft;
     
    5356    return -1;
    5457  }
     58
     59  self->cvecin = (cvec_t *)malloc(sizeof(cvec_t));
     60  self->vecin = (fvec_t *)malloc(sizeof(fvec_t));
     61
    5562  self->out = new_cvec(self->win_s);
     63  self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
     64  Py_XINCREF(self->py_out);
    5665  self->rout = new_fvec(self->win_s);
    5766
     
    6271Py_fft_del (Py_fft *self, PyObject *unused)
    6372{
     73  Py_XDECREF((PyObject*)(self->py_out));
    6474  del_aubio_fft(self->o);
    6575  del_cvec(self->out);
    6676  del_fvec(self->rout);
     77  free(self->cvecin);
     78  free(self->vecin);
    6779  Py_TYPE(self)->tp_free((PyObject *) self);
    6880}
    6981
    70 static PyObject * 
     82static PyObject *
    7183Py_fft_do(Py_fft * self, PyObject * args)
    7284{
    7385  PyObject *input;
    74   fvec_t *vec;
    7586
    7687  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    7889  }
    7990
    80   vec = PyAubio_ArrayToCFvec (input);
    81 
    82   if (vec == NULL) {
     91  if (!PyAubio_ArrayToCFvec(input, self->vecin)) {
    8392    return NULL;
    8493  }
    8594
    8695  // compute the function
    87   aubio_fft_do (((Py_fft *)self)->o, vec, self->out);
    88   return (PyObject *)PyAubio_CCvecToPyCvec(self->out);
     96  aubio_fft_do (((Py_fft *)self)->o, self->vecin, self->out);
     97#if 0
     98  Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
     99  PyObject* output = PyAubio_CCvecToPyCvec(self->out, py_out);
     100  return output;
     101#else
     102  // convert cvec to py_cvec, incrementing refcount to keep a copy
     103  return PyAubio_CCvecToPyCvec(self->out, self->py_out);
     104#endif
    89105}
    90106
     
    95111};
    96112
    97 static PyObject * 
     113static PyObject *
    98114Py_fft_rdo(Py_fft * self, PyObject * args)
    99115{
    100116  PyObject *input;
    101   cvec_t *vec;
    102117
    103118  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    105120  }
    106121
    107   vec = PyAubio_ArrayToCCvec (input);
    108 
    109   if (vec == NULL) {
     122  if (!PyAubio_ArrayToCCvec (input, self->cvecin) ) {
    110123    return NULL;
    111124  }
    112125
    113126  // compute the function
    114   aubio_fft_rdo (((Py_fft *)self)->o, vec, self->rout);
    115   return (PyObject *)PyAubio_CFvecToArray(self->rout);
     127  aubio_fft_rdo (self->o, self->cvecin, self->rout);
     128  return PyAubio_CFvecToArray(self->rout);
    116129}
    117130
  • python/ext/py-filter.c

    rbfe8256 rb5bef11  
    66  aubio_filter_t * o;
    77  uint_t order;
     8  fvec_t *vec;
    89  fvec_t *out;
    910} Py_filter;
     
    5051  }
    5152  self->out = new_fvec(Py_default_vector_length);
     53  self->vec = (fvec_t *)malloc(sizeof(fvec_t));
    5254  return 0;
    5355}
     
    5860  del_fvec(self->out);
    5961  del_aubio_filter (self->o);
     62  free(self->vec);
    6063  Py_TYPE(self)->tp_free ((PyObject *) self);
    6164}
     
    6568{
    6669  PyObject *input;
    67   fvec_t *vec;
    6870
    6971  if (!PyArg_ParseTuple (args, "O:digital_filter.do", &input)) {
     
    7577  }
    7678
    77   vec = PyAubio_ArrayToCFvec (input);
    78 
    79   if (vec == NULL) {
     79  if (!PyAubio_ArrayToCFvec(input, self->vec)) {
    8080    return NULL;
    8181  }
    8282
    8383  // reallocate the output if needed
    84   if (vec->length != self->out->length) {
     84  if (self->vec->length != self->out->length) {
    8585    del_fvec(self->out);
    86     self->out = new_fvec(vec->length);
     86    self->out = new_fvec(self->vec->length);
    8787  }
    8888  // compute the function
    89   aubio_filter_do_outplace (self->o, vec, self->out);
     89  aubio_filter_do_outplace (self->o, self->vec, self->out);
    9090  return PyAubio_CFvecToArray(self->out);
    9191}
  • python/ext/py-filterbank.c

    rbfe8256 rb5bef11  
    99  uint_t n_filters;
    1010  uint_t win_s;
     11  cvec_t *vec;
    1112  fvec_t *out;
     13  fvec_t *freqs;
     14  fmat_t *coeffs;
    1215} Py_filterbank;
    1316
     
    6467  self->out = new_fvec(self->n_filters);
    6568
     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
    6677  return 0;
    6778}
     
    7283  del_aubio_filterbank(self->o);
    7384  del_fvec(self->out);
     85  free(self->vec);
     86  free(self->freqs);
     87  free(self->coeffs->data);
     88  free(self->coeffs);
    7489  Py_TYPE(self)->tp_free((PyObject *) self);
    7590}
     
    7994{
    8095  PyObject *input;
    81   cvec_t *vec;
    8296
    8397  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    8599  }
    86100
    87   vec = PyAubio_ArrayToCCvec (input);
    88 
    89   if (vec == NULL) {
     101  if (!PyAubio_ArrayToCCvec(input, self->vec)) {
    90102    return NULL;
    91103  }
    92104
    93105  // compute the function
    94   aubio_filterbank_do (self->o, vec, self->out);
     106  aubio_filterbank_do (self->o, self->vec, self->out);
    95107  return (PyObject *)PyAubio_CFvecToArray(self->out);
    96108}
     
    111123  PyObject *input;
    112124  uint_t samplerate;
    113   fvec_t *freqs;
    114125  if (!PyArg_ParseTuple (args, "OI", &input, &samplerate)) {
    115126    return NULL;
     
    120131  }
    121132
    122   freqs = PyAubio_ArrayToCFvec (input);
    123 
    124   if (freqs == NULL) {
     133  if (!PyAubio_ArrayToCFvec(input, self->freqs)) {
    125134    return NULL;
    126135  }
    127136
    128137  err = aubio_filterbank_set_triangle_bands (self->o,
    129       freqs, samplerate);
     138      self->freqs, samplerate);
    130139  if (err > 0) {
    131140    PyErr_SetString (PyExc_ValueError,
     
    161170
    162171  PyObject *input;
    163   fmat_t *coeffs;
    164 
    165172  if (!PyArg_ParseTuple (args, "O", &input)) {
    166173    return NULL;
    167174  }
    168175
    169   coeffs = PyAubio_ArrayToCFmat (input);
    170 
    171   if (coeffs == NULL) {
    172     PyErr_SetString (PyExc_ValueError,
    173         "unable to parse input array");
    174     return NULL;
    175   }
    176 
    177   err = aubio_filterbank_set_coeffs (self->o, coeffs);
     176  if (!PyAubio_ArrayToCFmat(input, self->coeffs)) {
     177    return NULL;
     178  }
     179
     180  err = aubio_filterbank_set_coeffs (self->o, self->coeffs);
    178181
    179182  if (err > 0) {
  • python/ext/py-musicutils.c

    rbfe8256 rb5bef11  
    3838  }
    3939
    40   vec = PyAubio_ArrayToCFvec (input);
    41   if (vec == NULL) {
     40  vec = (fvec_t *)malloc(sizeof(fvec_t));
     41  if (!PyAubio_ArrayToCFvec(input, vec)) {
     42    free(vec);
    4243    return NULL;
    4344  }
    4445
    4546  level_lin = Py_BuildValue("f", aubio_level_lin(vec));
     47  free(vec);
    4648  if (level_lin == NULL) {
    4749    PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
     
    6870  }
    6971
    70   vec = PyAubio_ArrayToCFvec (input);
    71   if (vec == NULL) {
     72  vec = (fvec_t *)malloc(sizeof(fvec_t));
     73  if (!PyAubio_ArrayToCFvec(input, vec)) {
     74    free(vec);
    7275    return NULL;
    7376  }
    7477
    7578  db_spl = Py_BuildValue("f", aubio_db_spl(vec));
     79  free(vec);
    7680  if (db_spl == NULL) {
    7781    PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
     
    99103  }
    100104
    101   vec = PyAubio_ArrayToCFvec (input);
    102   if (vec == NULL) {
     105  vec = (fvec_t *)malloc(sizeof(fvec_t));
     106  if (!PyAubio_ArrayToCFvec(input, vec)) {
     107    free(vec);
    103108    return NULL;
    104109  }
    105110
    106111  silence_detection = Py_BuildValue("I", aubio_silence_detection(vec, threshold));
     112  free(vec);
    107113  if (silence_detection == NULL) {
    108114    PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");
     
    130136  }
    131137
    132   vec = PyAubio_ArrayToCFvec (input);
    133   if (vec == NULL) {
     138  vec = (fvec_t *)malloc(sizeof(fvec_t));
     139  if (!PyAubio_ArrayToCFvec(input, vec)) {
     140    free(vec);
    134141    return NULL;
    135142  }
    136143
    137144  level_detection = Py_BuildValue("f", aubio_level_detection(vec, threshold));
     145  free(vec);
    138146  if (level_detection == NULL) {
    139147    PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
  • python/ext/py-phasevoc.c

    rbfe8256 rb5bef11  
    99  uint_t win_s;
    1010  uint_t hop_s;
     11  fvec_t *vecin;
    1112  cvec_t *output;
     13  Py_cvec *py_out;
     14  cvec_t *cvecin;
    1215  fvec_t *routput;
    1316} Py_pvoc;
     
    6972  }
    7073
     74  self->cvecin = (cvec_t *)malloc(sizeof(cvec_t));
     75  self->vecin = (fvec_t *)malloc(sizeof(fvec_t));
     76
    7177  self->output = new_cvec(self->win_s);
     78  self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
    7279  self->routput = new_fvec(self->hop_s);
    7380
     
    8289  del_cvec(self->output);
    8390  del_fvec(self->routput);
     91  free(self->cvecin);
     92  free(self->vecin);
    8493  Py_TYPE(self)->tp_free((PyObject *) self);
    8594}
    8695
    8796
    88 static PyObject * 
     97static PyObject *
    8998Py_pvoc_do(Py_pvoc * self, PyObject * args)
    9099{
    91100  PyObject *input;
    92   fvec_t *vec;
    93101
    94102  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    96104  }
    97105
    98   vec = PyAubio_ArrayToCFvec (input);
    99 
    100   if (vec == NULL) {
     106  if (!PyAubio_ArrayToCFvec (input, self->vecin)) {
    101107    return NULL;
    102108  }
    103109
    104110  // compute the function
    105   aubio_pvoc_do (self->o, vec, self->output);
    106   return (PyObject *)PyAubio_CCvecToPyCvec(self->output);
     111  aubio_pvoc_do (self->o, self->vecin, self->output);
     112#if 0
     113  Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
     114  PyObject* output = PyAubio_CCvecToPyCvec(self->output, py_out);
     115  return output;
     116#else
     117  // convert cvec to py_cvec, incrementing refcount to keep a copy
     118  return PyAubio_CCvecToPyCvec(self->output, self->py_out);
     119#endif
    107120}
    108121
     
    119132{
    120133  PyObject *input;
    121   cvec_t *vec;
    122134  if (!PyArg_ParseTuple (args, "O", &input)) {
    123135    return NULL;
    124136  }
    125137
    126   vec = PyAubio_ArrayToCCvec (input);
    127 
    128   if (vec == NULL) {
     138  if (!PyAubio_ArrayToCCvec (input, self->cvecin)) {
    129139    return NULL;
    130140  }
    131141
    132142  // compute the function
    133   aubio_pvoc_rdo (self->o, vec, self->routput);
    134   return (PyObject *)PyAubio_CFvecToArray(self->routput);
     143  aubio_pvoc_rdo (self->o, self->cvecin, self->routput);
     144  return PyAubio_CFvecToArray(self->routput);
    135145}
    136146
  • python/ext/py-sink.c

    rbfe8256 rb5bef11  
    88  uint_t samplerate;
    99  uint_t channels;
     10  fvec_t *write_data;
     11  fmat_t *mwrite_data;
    1012} Py_sink;
    1113
     
    122124  self->channels = aubio_sink_get_channels ( self->o );
    123125
     126  self->write_data = (fvec_t *)malloc(sizeof(fvec_t));
     127  self->mwrite_data = (fmat_t *)malloc(sizeof(fmat_t));
     128  self->mwrite_data->height = self->channels;
     129  self->mwrite_data->data = (smpl_t **)malloc(sizeof(smpl_t*) * self->channels);
    124130  return 0;
    125131}
     
    129135{
    130136  del_aubio_sink(self->o);
     137  free(self->write_data);
     138  free(self->mwrite_data->data);
     139  free(self->mwrite_data);
    131140  Py_TYPE(self)->tp_free((PyObject *) self);
    132141}
     
    140149
    141150  /* input vectors prototypes */
    142   fvec_t* write_data;
    143151  uint_t write;
    144152
     
    148156  }
    149157
    150 
    151158  /* input vectors parsing */
    152   write_data = PyAubio_ArrayToCFvec (write_data_obj);
    153 
    154   if (write_data == NULL) {
    155     return NULL;
    156   }
    157 
    158 
    159 
     159  if (!PyAubio_ArrayToCFvec(write_data_obj, self->write_data)) {
     160    return NULL;
     161  }
    160162
    161163
    162164  /* compute _do function */
    163   aubio_sink_do (self->o, write_data, write);
     165  aubio_sink_do (self->o, self->write_data, write);
    164166
    165167  Py_RETURN_NONE;
     
    174176
    175177  /* input vectors prototypes */
    176   fmat_t * write_data;
    177178  uint_t write;
    178179
     
    184185
    185186  /* input vectors parsing */
    186   write_data = PyAubio_ArrayToCFmat (write_data_obj);
    187 
    188   if (write_data == NULL) {
    189     return NULL;
    190   }
    191 
    192 
    193 
    194 
     187  if (!PyAubio_ArrayToCFmat(write_data_obj, self->mwrite_data)) {
     188    return NULL;
     189  }
    195190
    196191  /* compute _do function */
    197   aubio_sink_do_multi (self->o, write_data, write);
     192  aubio_sink_do_multi (self->o, self->mwrite_data, write);
    198193  Py_RETURN_NONE;
    199194}
Note: See TracChangeset for help on using the changeset viewer.