Changeset 633400d for python/ext/py-filterbank.c
- Timestamp:
- Dec 5, 2018, 10:34:39 PM (6 years ago)
- Branches:
- feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- 283a619a
- Parents:
- 5b46bc3 (diff), f19db54 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/ext/py-filterbank.c
r5b46bc3 r633400d 95 95 if (self->vec.length != self->win_s / 2 + 1) { 96 96 PyErr_Format(PyExc_ValueError, 97 "input cvec has length %d, but f ftexpects length %d",97 "input cvec has length %d, but filterbank expects length %d", 98 98 self->vec.length, self->win_s / 2 + 1); 99 99 return NULL; … … 123 123 124 124 PyObject *input; 125 uint_t samplerate;126 if (!PyArg_ParseTuple (args, "O I", &input, &samplerate)) {125 smpl_t samplerate; 126 if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR, &input, &samplerate)) { 127 127 return NULL; 128 128 } … … 139 139 &(self->freqs), samplerate); 140 140 if (err > 0) { 141 PyErr_SetString (PyExc_ValueError, 142 "error when setting filter to A-weighting"); 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 } 143 149 return NULL; 144 150 } … … 151 157 uint_t err = 0; 152 158 153 uint_t samplerate;154 if (!PyArg_ParseTuple (args, "I", &samplerate)) {159 smpl_t samplerate; 160 if (!PyArg_ParseTuple (args, AUBIO_NPY_SMPL_CHR, &samplerate)) { 155 161 return NULL; 156 162 } … … 158 164 err = aubio_filterbank_set_mel_coeffs_slaney (self->o, samplerate); 159 165 if (err > 0) { 160 PyErr_SetString (PyExc_ValueError, 161 "error when setting filter to A-weighting"); 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 smpl_t samplerate; 185 smpl_t freq_min; 186 smpl_t freq_max; 187 if (!PyArg_ParseTuple (args, AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR 188 AUBIO_NPY_SMPL_CHR, &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 smpl_t samplerate; 214 smpl_t freq_min; 215 smpl_t freq_max; 216 if (!PyArg_ParseTuple (args, AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR 217 AUBIO_NPY_SMPL_CHR, &samplerate, &freq_min, &freq_max)) { 218 return NULL; 219 } 220 221 err = aubio_filterbank_set_mel_coeffs_htk (self->o, samplerate, 222 freq_min, freq_max); 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 232 return NULL; 163 233 } … … 194 264 return (PyObject *)PyAubio_CFmatToArray( 195 265 aubio_filterbank_get_coeffs (self->o) ); 266 } 267 268 static PyObject * 269 Py_filterbank_set_power(Py_filterbank *self, PyObject *args) 270 { 271 smpl_t power; 272 273 if (!PyArg_ParseTuple (args, AUBIO_NPY_SMPL_CHR, &power)) { 274 return NULL; 275 } 276 if(aubio_filterbank_set_power (self->o, power)) { 277 if (PyErr_Occurred() == NULL) { 278 PyErr_SetString (PyExc_ValueError, 279 "error running filterbank.set_power"); 280 } else { 281 // change the RuntimeError into ValueError 282 PyObject *type, *value, *traceback; 283 PyErr_Fetch(&type, &value, &traceback); 284 PyErr_Restore(PyExc_ValueError, value, traceback); 285 } 286 return NULL; 287 } 288 Py_RETURN_NONE; 289 } 290 291 static PyObject * 292 Py_filterbank_set_norm(Py_filterbank *self, PyObject *args) 293 { 294 smpl_t norm; 295 296 if (!PyArg_ParseTuple (args, AUBIO_NPY_SMPL_CHR, &norm)) { 297 return NULL; 298 } 299 if(aubio_filterbank_set_norm (self->o, norm)) { 300 if (PyErr_Occurred() == NULL) { 301 PyErr_SetString (PyExc_ValueError, 302 "error running filterbank.set_power"); 303 } else { 304 // change the RuntimeError into ValueError 305 PyObject *type, *value, *traceback; 306 PyErr_Fetch(&type, &value, &traceback); 307 PyErr_Restore(PyExc_ValueError, value, traceback); 308 } 309 return NULL; 310 } 311 Py_RETURN_NONE; 196 312 } 197 313 … … 201 317 {"set_mel_coeffs_slaney", (PyCFunction) Py_filterbank_set_mel_coeffs_slaney, 202 318 METH_VARARGS, "set coefficients of filterbank as in Auditory Toolbox"}, 319 {"set_mel_coeffs", (PyCFunction) Py_filterbank_set_mel_coeffs, 320 METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"}, 321 {"set_mel_coeffs_htk", (PyCFunction) Py_filterbank_set_mel_coeffs_htk, 322 METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"}, 203 323 {"get_coeffs", (PyCFunction) Py_filterbank_get_coeffs, 204 324 METH_NOARGS, "get coefficients of filterbank"}, 205 325 {"set_coeffs", (PyCFunction) Py_filterbank_set_coeffs, 206 326 METH_VARARGS, "set coefficients of filterbank"}, 327 {"set_power", (PyCFunction) Py_filterbank_set_power, 328 METH_VARARGS, "set power applied to filterbank input spectrum"}, 329 {"set_norm", (PyCFunction) Py_filterbank_set_norm, 330 METH_VARARGS, "set norm applied to filterbank input spectrum"}, 207 331 {NULL} 208 332 };
Note: See TracChangeset
for help on using the changeset viewer.