Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -138,8 +138,14 @@ Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args) · 137 unmodified lines | |||
| 138 | err = aubio_filterbank_set_triangle_bands (self->o, | 138 | err = aubio_filterbank_set_triangle_bands (self->o, |
| 139 | &(self->freqs), samplerate); | 139 | &(self->freqs), samplerate); |
| 140 | if (err > 0) { | 140 | if (err > 0) { |
| 141 | PyErr_SetString (PyExc_ValueError, | 141 | if (PyErr_Occurred() == NULL) { |
| 142 | "error when running set_triangle_bands"); | 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 | } | ||
| 143 | return NULL; | 149 | return NULL; |
| 144 | } | 150 | } |
| 145 | Py_RETURN_NONE; | 151 | Py_RETURN_NONE; |
| @@ -157,8 +163,72 @@ Py_filterbank_set_mel_coeffs_slaney (Py_filterbank * self, PyObject *args) · 11 unmodified lines | |||
| 157 | 163 | ||
| 158 | err = aubio_filterbank_set_mel_coeffs_slaney (self->o, samplerate); | 164 | err = aubio_filterbank_set_mel_coeffs_slaney (self->o, samplerate); |
| 159 | if (err > 0) { | 165 | if (err > 0) { |
| 160 | PyErr_SetString (PyExc_ValueError, | 166 | if (PyErr_Occurred() == NULL) { |
| 161 | "error when running set_mel_coeffs_slaney"); | 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 | |||
| 179 | static PyObject * | ||
| 180 | Py_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 | |||
| 208 | static PyObject * | ||
| 209 | Py_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 | } | ||
| 162 | return NULL; | 232 | return NULL; |
| 163 | } | 233 | } |
| 164 | Py_RETURN_NONE; | 234 | Py_RETURN_NONE; |
| @@ -200,6 +270,10 @@ static PyMethodDef Py_filterbank_methods[] = { · 35 unmodified lines | |||
| 200 | METH_VARARGS, "set coefficients of filterbanks"}, | 270 | METH_VARARGS, "set coefficients of filterbanks"}, |
| 201 | {"set_mel_coeffs_slaney", (PyCFunction) Py_filterbank_set_mel_coeffs_slaney, | 271 | {"set_mel_coeffs_slaney", (PyCFunction) Py_filterbank_set_mel_coeffs_slaney, |
| 202 | METH_VARARGS, "set coefficients of filterbank as in Auditory Toolbox"}, | 272 | 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"}, | ||
| 203 | {"get_coeffs", (PyCFunction) Py_filterbank_get_coeffs, | 277 | {"get_coeffs", (PyCFunction) Py_filterbank_get_coeffs, |
| 204 | METH_NOARGS, "get coefficients of filterbank"}, | 278 | METH_NOARGS, "get coefficients of filterbank"}, |
| 205 | {"set_coeffs", (PyCFunction) Py_filterbank_set_coeffs, | 279 | {"set_coeffs", (PyCFunction) Py_filterbank_set_coeffs, |