- Timestamp:
- Nov 17, 2018, 4:38:29 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- ab8e838
- Parents:
- 75f9fff (diff), 2eb52bd (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. - Location:
- python
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
python/ext/aubiomodule.c
r75f9fff ra95b386 373 373 {"shift", Py_aubio_shift, METH_VARARGS, Py_aubio_shift_doc}, 374 374 {"ishift", Py_aubio_ishift, METH_VARARGS, Py_aubio_ishift_doc}, 375 {"hztomel", Py_aubio_hztomel, METH_VARARGS|METH_KEYWORDS, Py_aubio_hztomel_doc}, 376 {"meltohz", Py_aubio_meltohz, METH_VARARGS|METH_KEYWORDS, Py_aubio_meltohz_doc}, 377 {"hztomel_htk", Py_aubio_hztomel_htk, METH_VARARGS, Py_aubio_hztomel_htk_doc}, 378 {"meltohz_htk", Py_aubio_meltohz_htk, METH_VARARGS, Py_aubio_meltohz_htk_doc}, 375 379 {NULL, NULL, 0, NULL} /* Sentinel */ 376 380 }; -
python/ext/py-filterbank.c
r75f9fff ra95b386 139 139 &(self->freqs), samplerate); 140 140 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 } 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 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 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 uint_t power; 272 273 if (!PyArg_ParseTuple (args, "I", &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 uint_t playing; 295 296 if (!PyArg_ParseTuple (args, "I", &playing)) { 297 return NULL; 298 } 299 if(aubio_filterbank_set_norm (self->o, playing)) { 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 }; -
python/ext/py-musicutils.c
r75f9fff ra95b386 182 182 return (PyObject *) PyAubio_CFvecToArray(&vec); 183 183 } 184 185 PyObject* 186 Py_aubio_hztomel(PyObject *self, PyObject *args, PyObject *kwds) 187 { 188 smpl_t v; 189 PyObject *htk = NULL; 190 static char *kwlist[] = {"f", "htk", NULL}; 191 if (!PyArg_ParseTupleAndKeywords(args, kwds, AUBIO_NPY_SMPL_CHR "|O", 192 kwlist, &v, &htk)) 193 { 194 return NULL; 195 } 196 if (htk != NULL && PyObject_IsTrue(htk) == 1) 197 return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v)); 198 else 199 return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel(v)); 200 } 201 202 PyObject* 203 Py_aubio_meltohz(PyObject *self, PyObject *args, PyObject *kwds) 204 { 205 smpl_t v; 206 PyObject *htk = NULL; 207 static char *kwlist[] = {"m", "htk", NULL}; 208 if (!PyArg_ParseTupleAndKeywords(args, kwds, AUBIO_NPY_SMPL_CHR "|O", 209 kwlist, &v, &htk)) 210 { 211 return NULL; 212 } 213 if (htk != NULL && PyObject_IsTrue(htk) == 1) 214 return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v)); 215 else 216 return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz(v)); 217 } 218 219 PyObject* 220 Py_aubio_hztomel_htk(PyObject *self, PyObject *args) 221 { 222 smpl_t v; 223 if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) { 224 return NULL; 225 } 226 return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v)); 227 } 228 229 PyObject* 230 Py_aubio_meltohz_htk(PyObject *self, PyObject *args) 231 { 232 smpl_t v; 233 if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) { 234 return NULL; 235 } 236 return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v)); 237 } -
python/ext/py-musicutils.h
r75f9fff ra95b386 301 301 PyObject * Py_aubio_ishift(PyObject *self, PyObject *args); 302 302 303 static char Py_aubio_hztomel_doc[] = "" 304 "hztomel(f, htk=False)\n" 305 "\n" 306 "Convert a scalar from frequency to mel scale.\n" 307 "\n" 308 "Parameters\n" 309 "----------\n" 310 "m : float\n" 311 " input frequency, in Hz\n" 312 "htk : bool\n" 313 " if `True`, use Htk mel scale instead of Slaney.\n" 314 "\n" 315 "Returns\n" 316 "-------\n" 317 "float\n" 318 " output mel\n" 319 "\n" 320 "See Also\n" 321 "--------\n" 322 "meltohz\n" 323 ""; 324 PyObject * Py_aubio_hztomel(PyObject *self, PyObject *args); 325 326 static char Py_aubio_meltohz_doc[] = "" 327 "meltohz(m, htk=False)\n" 328 "\n" 329 "Convert a scalar from mel scale to frequency.\n" 330 "\n" 331 "Parameters\n" 332 "----------\n" 333 "m : float\n" 334 " input mel\n" 335 "htk : bool\n" 336 " if `True`, use Htk mel scale instead of Slaney.\n" 337 "\n" 338 "Returns\n" 339 "-------\n" 340 "float\n" 341 " output frequency, in Hz\n" 342 "\n" 343 "See Also\n" 344 "--------\n" 345 "hztomel\n" 346 ""; 347 PyObject * Py_aubio_meltohz(PyObject *self, PyObject *args); 348 349 static char Py_aubio_hztomel_htk_doc[] = "" 350 "hztomel_htk(m)\n" 351 "\n" 352 "Same as `hztomel(m, htk=True)`\n" 353 "\n" 354 "See Also\n" 355 "--------\n" 356 "hztomel\n" 357 ""; 358 PyObject * Py_aubio_hztomel_htk(PyObject *self, PyObject *args); 359 360 static char Py_aubio_meltohz_htk_doc[] = "" 361 "meltohz_htk(m)\n" 362 "\n" 363 "Same as `meltohz(m, htk=True)`\n" 364 "\n" 365 "See Also\n" 366 "--------\n" 367 "meltohz\n" 368 ""; 369 PyObject * Py_aubio_meltohz_htk(PyObject *self, PyObject *args); 370 303 371 #endif /* PY_AUBIO_MUSICUTILS_H */ -
python/lib/gen_code.py
r75f9fff ra95b386 463 463 """.format(**self.__dict__) 464 464 for set_param in self.prototypes['set']: 465 params = get_params_types_names(set_param)[1] 466 paramtype = params['type'] 465 params = get_params_types_names(set_param)[1:] 466 param = self.shortname.split('_set_')[-1] 467 paramdecls = "".join([""" 468 {0} {1};""".format(p['type'], p['name']) for p in params]) 467 469 method_name = get_name(set_param) 468 470 param = method_name.split('aubio_'+self.shortname+'_set_')[-1] 469 pyparamtype = pyargparse_chars[paramtype] 471 refs = ", ".join(["&%s" % p['name'] for p in params]) 472 paramlist = ", ".join(["%s" % p['name'] for p in params]) 473 if len(params): 474 paramlist = "," + paramlist 475 pyparamtypes = ''.join([pyargparse_chars[p['type']] for p in params]) 470 476 out += """ 471 477 static PyObject * … … 473 479 {{ 474 480 uint_t err = 0; 475 {paramtype} {param}; 476 477 if (!PyArg_ParseTuple (args, "{pyparamtype}", &{param})) {{ 481 {paramdecls} 482 """.format(param = param, paramdecls = paramdecls, **self.__dict__) 483 484 if len(refs) and len(pyparamtypes): 485 out += """ 486 487 if (!PyArg_ParseTuple (args, "{pyparamtypes}", {refs})) {{ 478 488 return NULL; 479 489 }} 480 err = aubio_{shortname}_set_{param} (self->o, {param}); 490 """.format(pyparamtypes = pyparamtypes, refs = refs) 491 492 out += """ 493 err = aubio_{shortname}_set_{param} (self->o {paramlist}); 481 494 482 495 if (err > 0) {{ … … 493 506 Py_RETURN_NONE; 494 507 }} 495 """.format(param = param, paramtype = paramtype, pyparamtype = pyparamtype, **self.__dict__) 508 """.format(param = param, refs = refs, paramdecls = paramdecls, 509 pyparamtypes = pyparamtypes, paramlist = paramlist, **self.__dict__) 496 510 return out 497 511 -
python/tests/test_fft.py
r75f9fff ra95b386 142 142 assert_almost_equal ( r[1:], 0) 143 143 144 class aubio_fft_odd_sizes(TestCase): 145 146 def test_reconstruct_with_odd_size(self): 147 win_s = 29 148 self.recontruct(win_s, 'odd sizes not supported') 149 150 def test_reconstruct_with_radix15(self): 151 win_s = 2 ** 4 * 15 152 self.recontruct(win_s, 'radix 15 supported') 153 154 def test_reconstruct_with_radix5(self): 155 win_s = 2 ** 4 * 5 156 self.recontruct(win_s, 'radix 5 supported') 157 158 def test_reconstruct_with_radix3(self): 159 win_s = 2 ** 4 * 3 160 self.recontruct(win_s, 'radix 3 supported') 161 162 def recontruct(self, win_s, skipMessage): 163 try: 164 f = fft(win_s) 165 except RuntimeError: 166 self.skipTest(skipMessage) 167 input_signal = fvec(win_s) 168 input_signal[win_s//2] = 1 169 c = f(input_signal) 170 output_signal = f.rdo(c) 171 assert_almost_equal(input_signal, output_signal) 172 173 class aubio_fft_wrong_params(TestCase): 174 144 175 def test_large_input_timegrain(self): 145 176 win_s = 1024 … … 169 200 with self.assertRaises(ValueError): 170 201 f.rdo(s) 171 172 class aubio_fft_wrong_params(TestCase):173 202 174 203 def test_wrong_buf_size(self): … … 176 205 with self.assertRaises(ValueError): 177 206 fft(win_s) 178 179 def test_buf_size_not_power_of_two(self):180 # when compiled with fftw3, aubio supports non power of two fft sizes181 win_s = 320182 try:183 with self.assertRaises(RuntimeError):184 fft(win_s)185 except AssertionError:186 self.skipTest('creating aubio.fft with size %d did not fail' % win_s)187 207 188 208 def test_buf_size_too_small(self): -
python/tests/test_filterbank_mel.py
r75f9fff ra95b386 110 110 111 111 112 def test_triangle_freqs_without_norm(self): 113 """make sure set_triangle_bands works without """ 114 samplerate = 22050 115 freq_list = fvec([0, 100, 1000, 10000]) 116 f = filterbank(len(freq_list) - 2, 1024) 117 f.set_norm(0) 118 f.set_triangle_bands(freq_list, samplerate) 119 expected = f.get_coeffs() 120 f.set_norm(1) 121 f.set_triangle_bands(fvec(freq_list), samplerate) 122 assert_almost_equal(f.get_coeffs().T, 123 expected.T * 2. / (freq_list[2:] - freq_list[:-2])) 124 125 def test_triangle_freqs_wrong_norm(self): 126 f = filterbank(10, 1024) 127 with self.assertRaises(ValueError): 128 f.set_norm(-1) 129 130 def test_triangle_freqs_with_power(self): 131 f = filterbank(9, 1024) 132 freqs = fvec([40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 133 24000]) 134 f.set_power(2) 135 f.set_triangle_bands(freqs, 48000) 136 spec = cvec(1024) 137 spec.norm[:] = .1 138 expected = fvec([0.02070313, 0.02138672, 0.02127604, 0.02135417, 139 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345]) 140 expected /= 100. 141 assert_almost_equal(f(spec), expected) 142 143 def test_mel_coeffs(self): 144 f = filterbank(40, 1024) 145 f.set_mel_coeffs(44100, 0, 44100 / 2) 146 147 def test_zero_fmax(self): 148 f = filterbank(40, 1024) 149 f.set_mel_coeffs(44100, 0, 0) 150 151 def test_wrong_mel_coeffs(self): 152 f = filterbank(40, 1024) 153 with self.assertRaises(ValueError): 154 f.set_mel_coeffs_slaney(0) 155 with self.assertRaises(ValueError): 156 f.set_mel_coeffs(44100, 0, -44100 / 2) 157 with self.assertRaises(ValueError): 158 f.set_mel_coeffs(44100, -0.1, 44100 / 2) 159 with self.assertRaises(ValueError): 160 f.set_mel_coeffs(-44100, 0.1, 44100 / 2) 161 with self.assertRaises(ValueError): 162 f.set_mel_coeffs_htk(-1, 0, 0) 163 164 def test_mel_coeffs_htk(self): 165 f = filterbank(40, 1024) 166 f.set_mel_coeffs_htk(44100, 0, 44100 / 2) 167 168 112 169 if __name__ == '__main__': 113 170 from unittest import main
Note: See TracChangeset
for help on using the changeset viewer.