Changeset 04cd251 for python


Ignore:
Timestamp:
Nov 17, 2018, 3:16:10 AM (13 months ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master
Children:
1d51820
Parents:
fa713bd
Message:

[py] add filterbank.set_mel_coeffs, improve error messages

File:
1 edited

Legend:

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

    rfa713bd r04cd251  
    139139      &(self->freqs), samplerate);
    140140  if (err > 0) {
    141     PyErr_SetString (PyExc_ValueError,
    142         "error when running set_triangle_bands");
     141    if (PyErr_Occurred() == NULL) {
     142      PyErr_SetString (PyExc_ValueError, "error running set_triangle_bands");
     143    } else {
     144      // change the RuntimeError into ValueError
     145      PyObject *type, *value, *traceback;
     146      PyErr_Fetch(&type, &value, &traceback);
     147      PyErr_Restore(PyExc_ValueError, value, traceback);
     148    }
    143149    return NULL;
    144150  }
     
    158164  err = aubio_filterbank_set_mel_coeffs_slaney (self->o, samplerate);
    159165  if (err > 0) {
    160     PyErr_SetString (PyExc_ValueError,
    161         "error when running set_mel_coeffs_slaney");
     166    if (PyErr_Occurred() == NULL) {
     167      PyErr_SetString (PyExc_ValueError, "error running set_mel_coeffs_slaney");
     168    } else {
     169      // change the RuntimeError into ValueError
     170      PyObject *type, *value, *traceback;
     171      PyErr_Fetch(&type, &value, &traceback);
     172      PyErr_Restore(PyExc_ValueError, value, traceback);
     173    }
     174    return NULL;
     175  }
     176  Py_RETURN_NONE;
     177}
     178
     179static PyObject *
     180Py_filterbank_set_mel_coeffs (Py_filterbank * self, PyObject *args)
     181{
     182  uint_t err = 0;
     183
     184  uint_t samplerate;
     185  smpl_t freq_min;
     186  smpl_t freq_max;
     187  if (!PyArg_ParseTuple (args, "I" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR,
     188        &samplerate, &freq_min, &freq_max)) {
     189    return NULL;
     190  }
     191
     192  err = aubio_filterbank_set_mel_coeffs (self->o, samplerate,
     193      freq_min, freq_max);
     194  if (err > 0) {
     195    if (PyErr_Occurred() == NULL) {
     196      PyErr_SetString (PyExc_ValueError, "error running set_mel_coeffs");
     197    } else {
     198      // change the RuntimeError into ValueError
     199      PyObject *type, *value, *traceback;
     200      PyErr_Fetch(&type, &value, &traceback);
     201      PyErr_Restore(PyExc_ValueError, value, traceback);
     202    }
     203    return NULL;
     204  }
     205  Py_RETURN_NONE;
     206}
     207
     208static PyObject *
     209Py_filterbank_set_mel_coeffs_htk (Py_filterbank * self, PyObject *args)
     210{
     211  uint_t err = 0;
     212
     213  uint_t samplerate;
     214  smpl_t freq_min;
     215  smpl_t freq_max;
     216  if (!PyArg_ParseTuple (args, "I" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR,
     217        &samplerate, &freq_min, &freq_max)) {
     218    return NULL;
     219  }
     220
     221  err = aubio_filterbank_set_mel_coeffs_htk (self->o,
     222      freq_min, freq_max, samplerate);
     223  if (err > 0) {
     224    if (PyErr_Occurred() == NULL) {
     225      PyErr_SetString (PyExc_ValueError, "error running set_mel_coeffs_htk");
     226    } else {
     227      // change the RuntimeError into ValueError
     228      PyObject *type, *value, *traceback;
     229      PyErr_Fetch(&type, &value, &traceback);
     230      PyErr_Restore(PyExc_ValueError, value, traceback);
     231    }
    162232    return NULL;
    163233  }
     
    201271  {"set_mel_coeffs_slaney", (PyCFunction) Py_filterbank_set_mel_coeffs_slaney,
    202272    METH_VARARGS, "set coefficients of filterbank as in Auditory Toolbox"},
     273  {"set_mel_coeffs", (PyCFunction) Py_filterbank_set_mel_coeffs,
     274    METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"},
     275  {"set_mel_coeffs_htk", (PyCFunction) Py_filterbank_set_mel_coeffs_htk,
     276    METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"},
    203277  {"get_coeffs", (PyCFunction) Py_filterbank_get_coeffs,
    204278    METH_NOARGS, "get coefficients of filterbank"},
Note: See TracChangeset for help on using the changeset viewer.