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

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

File:
1 edited

Legend:

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

    ra35db12 r569b363  
    2626{
    2727  PyObject *input;
    28   fvec_t *vec;
     28  fvec_t vec;
    2929  PyObject *level_lin;
    3030
     
    3838  }
    3939
    40   vec = (fvec_t *)malloc(sizeof(fvec_t));
    41   if (!PyAubio_ArrayToCFvec(input, vec)) {
    42     free(vec);
     40  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    4341    return NULL;
    4442  }
    4543
    46   level_lin = Py_BuildValue("f", aubio_level_lin(vec));
    47   free(vec);
     44  level_lin = Py_BuildValue("f", aubio_level_lin(&vec));
    4845  if (level_lin == NULL) {
    4946    PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
     
    5855{
    5956  PyObject *input;
    60   fvec_t *vec;
     57  fvec_t vec;
    6158  PyObject *db_spl;
    6259
     
    7067  }
    7168
    72   vec = (fvec_t *)malloc(sizeof(fvec_t));
    73   if (!PyAubio_ArrayToCFvec(input, vec)) {
    74     free(vec);
     69  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    7570    return NULL;
    7671  }
    7772
    78   db_spl = Py_BuildValue("f", aubio_db_spl(vec));
    79   free(vec);
     73  db_spl = Py_BuildValue("f", aubio_db_spl(&vec));
    8074  if (db_spl == NULL) {
    8175    PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
     
    9084{
    9185  PyObject *input;
    92   fvec_t *vec;
     86  fvec_t vec;
    9387  PyObject *silence_detection;
    9488  smpl_t threshold;
     
    10397  }
    10498
    105   vec = (fvec_t *)malloc(sizeof(fvec_t));
    106   if (!PyAubio_ArrayToCFvec(input, vec)) {
    107     free(vec);
     99  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    108100    return NULL;
    109101  }
    110102
    111   silence_detection = Py_BuildValue("I", aubio_silence_detection(vec, threshold));
    112   free(vec);
     103  silence_detection = Py_BuildValue("I", aubio_silence_detection(&vec, threshold));
    113104  if (silence_detection == NULL) {
    114105    PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");
     
    123114{
    124115  PyObject *input;
    125   fvec_t *vec;
     116  fvec_t vec;
    126117  PyObject *level_detection;
    127118  smpl_t threshold;
     
    136127  }
    137128
    138   vec = (fvec_t *)malloc(sizeof(fvec_t));
    139   if (!PyAubio_ArrayToCFvec(input, vec)) {
    140     free(vec);
     129  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    141130    return NULL;
    142131  }
    143132
    144   level_detection = Py_BuildValue("f", aubio_level_detection(vec, threshold));
    145   free(vec);
     133  level_detection = Py_BuildValue("f", aubio_level_detection(&vec, threshold));
    146134  if (level_detection == NULL) {
    147135    PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
Note: See TracChangeset for help on using the changeset viewer.