History

[py] add filterbank.set_mel_coeffs, improve error messages

Paul Brossier committed 8 years ago

Commit 04cd2511 parent fa713bd1 file · +78 −4Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/ext/py-filterbank.c+78−4
@@ -138,8 +138,14 @@ Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args) · 137 unmodified lines
138138 err = aubio_filterbank_set_triangle_bands (self->o,
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 }
145151 Py_RETURN_NONE;
@@ -157,8 +163,72 @@ Py_filterbank_set_mel_coeffs_slaney (Py_filterbank * self, PyObject *args) · 11 unmodified lines
157163
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+
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+ }
162232 return NULL;
163233 }
164234 Py_RETURN_NONE;
@@ -200,6 +270,10 @@ static PyMethodDef Py_filterbank_methods[] = { · 35 unmodified lines
200270 METH_VARARGS, "set coefficients of filterbanks"},
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"},
205279 {"set_coeffs", (PyCFunction) Py_filterbank_set_coeffs,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t