Showing the changes to python (10 of 13 files). Show all
Unified · Split
| @@ -1,7 +1,7 @@ | |||
| 1 | #define PYAUBIO_dct_doc \ | 1 | #define PYAUBIO_dct_doc \ |
| 2 | "dct(size=1024)\n"\ | 2 | "dct(size=1024)\n"\ |
| 3 | "\n"\ | 3 | "\n"\ |
| 4 | "Compute Discrete Fourier Transorms of Type-II.\n"\ | 4 | "Compute Discrete Fourier Transforms of Type-II.\n"\ |
| 5 | "\n"\ | 5 | "\n"\ |
| 6 | "Parameters\n"\ | 6 | "Parameters\n"\ |
| 7 | "----------\n"\ | 7 | "----------\n"\ |
| @@ -3,7 +3,7 @@ · 2 unmodified lines | |||
| 3 | static char Py_fft_doc[] = "" | 3 | static char Py_fft_doc[] = "" |
| 4 | "fft(size=1024)\n" | 4 | "fft(size=1024)\n" |
| 5 | "\n" | 5 | "\n" |
| 6 | "Compute Fast Fourier Transorms.\n" | 6 | "Compute Fast Fourier Transforms.\n" |
| 7 | "\n" | 7 | "\n" |
| 8 | "Parameters\n" | 8 | "Parameters\n" |
| 9 | "----------\n" | 9 | "----------\n" |
| @@ -156,8 +156,18 @@ Py_filter_set_c_weighting (Py_filter * self, PyObject *args) · 155 unmodified lines | |||
| 156 | 156 | ||
| 157 | err = aubio_filter_set_c_weighting (self->o, samplerate); | 157 | err = aubio_filter_set_c_weighting (self->o, samplerate); |
| 158 | if (err > 0) { | 158 | if (err > 0) { |
| 159 | PyErr_SetString (PyExc_ValueError, | 159 | if (PyErr_Occurred() == NULL) { |
| 160 | "error when setting filter to C-weighting"); | 160 | PyErr_SetString (PyExc_ValueError, |
| 161 | "error when setting filter to C-weighting"); | ||
| 162 | } else { | ||
| 163 | // change the RuntimeError into ValueError | ||
| 164 | PyObject *type, *value, *traceback; | ||
| 165 | PyErr_Fetch(&type, &value, &traceback); | ||
| 166 | Py_XDECREF(type); | ||
| 167 | type = PyExc_ValueError; | ||
| 168 | Py_XINCREF(type); | ||
| 169 | PyErr_Restore(type, value, traceback); | ||
| 170 | } | ||
| 161 | return NULL; | 171 | return NULL; |
| 162 | } | 172 | } |
| 163 | Py_RETURN_NONE; | 173 | Py_RETURN_NONE; |
| @@ -174,8 +184,18 @@ Py_filter_set_a_weighting (Py_filter * self, PyObject *args) · 10 unmodified lines | |||
| 174 | 184 | ||
| 175 | err = aubio_filter_set_a_weighting (self->o, samplerate); | 185 | err = aubio_filter_set_a_weighting (self->o, samplerate); |
| 176 | if (err > 0) { | 186 | if (err > 0) { |
| 177 | PyErr_SetString (PyExc_ValueError, | 187 | if (PyErr_Occurred() == NULL) { |
| 178 | "error when setting filter to A-weighting"); | 188 | PyErr_SetString (PyExc_ValueError, |
| 189 | "error when setting filter to A-weighting"); | ||
| 190 | } else { | ||
| 191 | // change the RuntimeError into ValueError | ||
| 192 | PyObject *type, *value, *traceback; | ||
| 193 | PyErr_Fetch(&type, &value, &traceback); | ||
| 194 | Py_XDECREF(type); | ||
| 195 | type = PyExc_ValueError; | ||
| 196 | Py_XINCREF(type); | ||
| 197 | PyErr_Restore(type, value, traceback); | ||
| 198 | } | ||
| 179 | return NULL; | 199 | return NULL; |
| 180 | } | 200 | } |
| 181 | Py_RETURN_NONE; | 201 | Py_RETURN_NONE; |
| @@ -192,8 +212,18 @@ Py_filter_set_biquad(Py_filter * self, PyObject *args) · 10 unmodified lines | |||
| 192 | 212 | ||
| 193 | err = aubio_filter_set_biquad (self->o, b0, b1, b2, a1, a2); | 213 | err = aubio_filter_set_biquad (self->o, b0, b1, b2, a1, a2); |
| 194 | if (err > 0) { | 214 | if (err > 0) { |
| 195 | PyErr_SetString (PyExc_ValueError, | 215 | if (PyErr_Occurred() == NULL) { |
| 196 | "error when setting filter with biquad coefficients"); | 216 | PyErr_SetString (PyExc_ValueError, |
| 217 | "error when setting filter with biquad coefficients"); | ||
| 218 | } else { | ||
| 219 | // change the RuntimeError into ValueError | ||
| 220 | PyObject *type, *value, *traceback; | ||
| 221 | PyErr_Fetch(&type, &value, &traceback); | ||
| 222 | Py_XDECREF(type); | ||
| 223 | type = PyExc_ValueError; | ||
| 224 | Py_XINCREF(type); | ||
| 225 | PyErr_Restore(type, value, traceback); | ||
| 226 | } | ||
| 197 | return NULL; | 227 | return NULL; |
| 198 | } | 228 | } |
| 199 | Py_RETURN_NONE; | 229 | Py_RETURN_NONE; |
| @@ -326,7 +326,10 @@ Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args) · 325 unmodified lines | |||
| 326 | // change the RuntimeError into ValueError | 326 | // change the RuntimeError into ValueError |
| 327 | PyObject *type, *value, *traceback; | 327 | PyObject *type, *value, *traceback; |
| 328 | PyErr_Fetch(&type, &value, &traceback); | 328 | PyErr_Fetch(&type, &value, &traceback); |
| 329 | PyErr_Restore(PyExc_ValueError, value, traceback); | 329 | Py_XDECREF(type); |
| 330 | type = PyExc_ValueError; | ||
| 331 | Py_XINCREF(type); | ||
| 332 | PyErr_Restore(type, value, traceback); | ||
| 330 | } | 333 | } |
| 331 | return NULL; | 334 | return NULL; |
| 332 | } | 335 | } |
| @@ -351,7 +354,10 @@ Py_filterbank_set_mel_coeffs_slaney (Py_filterbank * self, PyObject *args) · 18 unmodified lines | |||
| 351 | // change the RuntimeError into ValueError | 354 | // change the RuntimeError into ValueError |
| 352 | PyObject *type, *value, *traceback; | 355 | PyObject *type, *value, *traceback; |
| 353 | PyErr_Fetch(&type, &value, &traceback); | 356 | PyErr_Fetch(&type, &value, &traceback); |
| 354 | PyErr_Restore(PyExc_ValueError, value, traceback); | 357 | Py_XDECREF(type); |
| 358 | type = PyExc_ValueError; | ||
| 359 | Py_XINCREF(type); | ||
| 360 | PyErr_Restore(type, value, traceback); | ||
| 355 | } | 361 | } |
| 356 | return NULL; | 362 | return NULL; |
| 357 | } | 363 | } |
| @@ -380,7 +386,10 @@ Py_filterbank_set_mel_coeffs (Py_filterbank * self, PyObject *args) · 22 unmodified lines | |||
| 380 | // change the RuntimeError into ValueError | 386 | // change the RuntimeError into ValueError |
| 381 | PyObject *type, *value, *traceback; | 387 | PyObject *type, *value, *traceback; |
| 382 | PyErr_Fetch(&type, &value, &traceback); | 388 | PyErr_Fetch(&type, &value, &traceback); |
| 383 | PyErr_Restore(PyExc_ValueError, value, traceback); | 389 | Py_XDECREF(type); |
| 390 | type = PyExc_ValueError; | ||
| 391 | Py_XINCREF(type); | ||
| 392 | PyErr_Restore(type, value, traceback); | ||
| 384 | } | 393 | } |
| 385 | return NULL; | 394 | return NULL; |
| 386 | } | 395 | } |
| @@ -409,7 +418,10 @@ Py_filterbank_set_mel_coeffs_htk (Py_filterbank * self, PyObject *args) · 22 unmodified lines | |||
| 409 | // change the RuntimeError into ValueError | 418 | // change the RuntimeError into ValueError |
| 410 | PyObject *type, *value, *traceback; | 419 | PyObject *type, *value, *traceback; |
| 411 | PyErr_Fetch(&type, &value, &traceback); | 420 | PyErr_Fetch(&type, &value, &traceback); |
| 412 | PyErr_Restore(PyExc_ValueError, value, traceback); | 421 | Py_XDECREF(type); |
| 422 | type = PyExc_ValueError; | ||
| 423 | Py_XINCREF(type); | ||
| 424 | PyErr_Restore(type, value, traceback); | ||
| 413 | } | 425 | } |
| 414 | return NULL; | 426 | return NULL; |
| 415 | } | 427 | } |
| @@ -463,7 +475,10 @@ Py_filterbank_set_power(Py_filterbank *self, PyObject *args) · 47 unmodified lines | |||
| 463 | // change the RuntimeError into ValueError | 475 | // change the RuntimeError into ValueError |
| 464 | PyObject *type, *value, *traceback; | 476 | PyObject *type, *value, *traceback; |
| 465 | PyErr_Fetch(&type, &value, &traceback); | 477 | PyErr_Fetch(&type, &value, &traceback); |
| 466 | PyErr_Restore(PyExc_ValueError, value, traceback); | 478 | Py_XDECREF(type); |
| 479 | type = PyExc_ValueError; | ||
| 480 | Py_XINCREF(type); | ||
| 481 | PyErr_Restore(type, value, traceback); | ||
| 467 | } | 482 | } |
| 468 | return NULL; | 483 | return NULL; |
| 469 | } | 484 | } |
| @@ -493,7 +508,10 @@ Py_filterbank_set_norm(Py_filterbank *self, PyObject *args) · 23 unmodified lines | |||
| 493 | // change the RuntimeError into ValueError | 508 | // change the RuntimeError into ValueError |
| 494 | PyObject *type, *value, *traceback; | 509 | PyObject *type, *value, *traceback; |
| 495 | PyErr_Fetch(&type, &value, &traceback); | 510 | PyErr_Fetch(&type, &value, &traceback); |
| 496 | PyErr_Restore(PyExc_ValueError, value, traceback); | 511 | Py_XDECREF(type); |
| 512 | type = PyExc_ValueError; | ||
| 513 | Py_XINCREF(type); | ||
| 514 | PyErr_Restore(type, value, traceback); | ||
| 497 | } | 515 | } |
| 498 | return NULL; | 516 | return NULL; |
| 499 | } | 517 | } |
| @@ -81,7 +81,7 @@ static char Py_sink_close_doc[] = "" · 80 unmodified lines | |||
| 81 | "Close this sink now.\n" | 81 | "Close this sink now.\n" |
| 82 | "\n" | 82 | "\n" |
| 83 | "By default, the sink will be closed before being deleted.\n" | 83 | "By default, the sink will be closed before being deleted.\n" |
| 84 | "Explicitely closing a sink can be useful to control the number\n" | 84 | "Explicitly closing a sink can be useful to control the number\n" |
| 85 | "of files simultaneously opened.\n" | 85 | "of files simultaneously opened.\n" |
| 86 | ""; | 86 | ""; |
| 87 | 87 | ||
| @@ -523,7 +523,10 @@ Pyaubio_{shortname}_set_{param} (Py_{shortname} *self, PyObject *args) · 522 unmodified lines | |||
| 523 | // change the RuntimeError into ValueError | 523 | // change the RuntimeError into ValueError |
| 524 | PyObject *type, *value, *traceback; | 524 | PyObject *type, *value, *traceback; |
| 525 | PyErr_Fetch(&type, &value, &traceback); | 525 | PyErr_Fetch(&type, &value, &traceback); |
| 526 | PyErr_Restore(PyExc_ValueError, value, traceback); | 526 | Py_XDECREF(type); |
| 527 | type = PyExc_ValueError; | ||
| 528 | Py_XINCREF(type); | ||
| 529 | PyErr_Restore(type, value, traceback); | ||
| 527 | }} | 530 | }} |
| 528 | return NULL; | 531 | return NULL; |
| 529 | }} | 532 | }} |
| @@ -121,23 +121,24 @@ def get_cpp_output(header=header, usedouble=False): · 120 unmodified lines | |||
| 121 | print("Running command: {:s}".format(" ".join(cpp_cmd))) | 121 | print("Running command: {:s}".format(" ".join(cpp_cmd))) |
| 122 | proc = subprocess.Popen(cpp_cmd, | 122 | proc = subprocess.Popen(cpp_cmd, |
| 123 | stderr=subprocess.PIPE, | 123 | stderr=subprocess.PIPE, |
| 124 | stdout=subprocess.PIPE) | 124 | stdout=subprocess.PIPE, |
| 125 | universal_newlines=True) | ||
| 125 | assert proc, 'Proc was none' | 126 | assert proc, 'Proc was none' |
| 126 | cpp_output = proc.stdout.read() | 127 | cpp_output = proc.stdout.read() |
| 127 | err_output = proc.stderr.read() | 128 | err_output = proc.stderr.read() |
| 128 | if err_output: | 129 | if err_output: |
| 129 | print("Warning: preprocessor produced errors or warnings:\n%s" \ | 130 | print("Warning: preprocessor produced errors or warnings:\n%s" \ |
| 130 | % err_output.decode('utf8')) | 131 | % err_output) |
| 131 | if not cpp_output: | 132 | if not cpp_output: |
| 132 | raise_msg = "preprocessor output is empty! Running command " \ | 133 | raise_msg = "preprocessor output is empty! Running command " \ |
| 133 | + "\"%s\" failed" % " ".join(cpp_cmd) | 134 | + "\"%s\" failed" % " ".join(cpp_cmd) |
| 134 | if err_output: | 135 | if err_output: |
| 135 | raise_msg += " with stderr: \"%s\"" % err_output.decode('utf8') | 136 | raise_msg += " with stderr: \"%s\"" % err_output |
| 136 | else: | 137 | else: |
| 137 | raise_msg += " with no stdout or stderr" | 138 | raise_msg += " with no stdout or stderr" |
| 138 | raise Exception(raise_msg) | 139 | raise Exception(raise_msg) |
| 139 | if not isinstance(cpp_output, list): | 140 | if not isinstance(cpp_output, list): |
| 140 | cpp_output = [l.strip() for l in cpp_output.decode('utf8').split('\n')] | 141 | cpp_output = [l.strip() for l in cpp_output.split('\n')] |
| 141 | 142 | ||
| 142 | return cpp_output | 143 | return cpp_output |
| 143 | 144 | ||
| @@ -4,23 +4,28 @@ from unittest import main · 3 unmodified lines | |||
| 4 | from numpy.testing import TestCase | 4 | from numpy.testing import TestCase |
| 5 | from numpy.testing import assert_equal, assert_almost_equal | 5 | from numpy.testing import assert_equal, assert_almost_equal |
| 6 | from _tools import assert_warns | 6 | from _tools import assert_warns |
| 7 | from utils import is32bit | ||
| 7 | import numpy as np | 8 | import numpy as np |
| 8 | import aubio | 9 | import aubio |
| 9 | 10 | ||
| 10 | from aubio import hztomel, meltohz | 11 | from aubio import hztomel, meltohz |
| 11 | from aubio import hztomel_htk, meltohz_htk | 12 | from aubio import hztomel_htk, meltohz_htk |
| 12 | 13 | ||
| 13 | |||
| 14 | class aubio_hztomel_test_case(TestCase): | 14 | class aubio_hztomel_test_case(TestCase): |
| 15 | 15 | ||
| 16 | def test_hztomel(self): | 16 | def test_hztomel(self): |
| 17 | assert_equal(hztomel(0.), 0.) | 17 | assert_equal(hztomel(0.), 0.) |
| 18 | assert_almost_equal(hztomel(400. / 3.), 2., decimal=5) | 18 | assert_almost_equal(hztomel(400. / 3.), 2., decimal=5) |
| 19 | assert_almost_equal(hztomel(1000. / 3), 5.) | 19 | assert_almost_equal(hztomel(1000. / 3), 5.) |
| 20 | assert_equal(hztomel(200.), 3.) | 20 | # on 32bit, some of these tests fails unless compiling with -ffloat-store |
| 21 | try: | ||
| 22 | assert_equal(hztomel(200.), 3.) | ||
| 23 | except AssertionError: | ||
| 24 | if not is32bit(): raise | ||
| 25 | assert_almost_equal(hztomel(200.), 3., decimal=5) | ||
| 21 | assert_almost_equal(hztomel(1000.), 15) | 26 | assert_almost_equal(hztomel(1000.), 15) |
| 22 | assert_almost_equal(hztomel(6400), 42) | 27 | assert_almost_equal(hztomel(6400), 42, decimal=5) |
| 23 | assert_almost_equal(hztomel(40960), 69) | 28 | assert_almost_equal(hztomel(40960), 69, decimal=5) |
| 24 | 29 | ||
| 25 | for m in np.linspace(0, 1000, 100): | 30 | for m in np.linspace(0, 1000, 100): |
| 26 | assert_almost_equal(hztomel(meltohz(m)) - m, 0, decimal=3) | 31 | assert_almost_equal(hztomel(meltohz(m)) - m, 0, decimal=3) |
| @@ -28,7 +33,11 @@ class aubio_hztomel_test_case(TestCase): · 1 unmodified line | |||
| 28 | def test_meltohz(self): | 33 | def test_meltohz(self): |
| 29 | assert_equal(meltohz(0.), 0.) | 34 | assert_equal(meltohz(0.), 0.) |
| 30 | assert_almost_equal(meltohz(2), 400. / 3., decimal=4) | 35 | assert_almost_equal(meltohz(2), 400. / 3., decimal=4) |
| 31 | assert_equal(meltohz(3.), 200.) | 36 | try: |
| 37 | assert_equal(meltohz(3.), 200.) | ||
| 38 | except AssertionError: | ||
| 39 | if not is32bit(): raise | ||
| 40 | assert_almost_equal(meltohz(3.), 200., decimal=5) | ||
| 32 | assert_almost_equal(meltohz(5), 1000. / 3., decimal=4) | 41 | assert_almost_equal(meltohz(5), 1000. / 3., decimal=4) |
| 33 | assert_almost_equal(meltohz(15), 1000., decimal=4) | 42 | assert_almost_equal(meltohz(15), 1000., decimal=4) |
| 34 | assert_almost_equal(meltohz(42), 6400., decimal=2) | 43 | assert_almost_equal(meltohz(42), 6400., decimal=2) |
| @@ -1,7 +1,7 @@ | |||
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | 2 | ||
| 3 | from numpy.testing import TestCase, assert_equal, assert_array_less | 3 | from numpy.testing import TestCase, assert_equal, assert_array_less |
| 4 | from _tools import parametrize | 4 | from _tools import parametrize, skipTest |
| 5 | from aubio import fvec, cvec, pvoc, float_type | 5 | from aubio import fvec, cvec, pvoc, float_type |
| 6 | import numpy as np | 6 | import numpy as np |
| 7 | 7 | ||
| @@ -51,7 +51,7 @@ class Test_aubio_pvoc_test_case(object): · 43 unmodified lines | |||
| 51 | assert_equal (s.phas[s.phas > 0], +np.pi) | 51 | assert_equal (s.phas[s.phas > 0], +np.pi) |
| 52 | assert_equal (s.phas[s.phas < 0], -np.pi) | 52 | assert_equal (s.phas[s.phas < 0], -np.pi) |
| 53 | assert_equal (np.abs(s.phas[np.abs(s.phas) != np.pi]), 0) | 53 | assert_equal (np.abs(s.phas[np.abs(s.phas) != np.pi]), 0) |
| 54 | self.skipTest('pvoc(fvec(%d)).phas != +0, ' % win_s \ | 54 | skipTest('pvoc(fvec(%d)).phas != +0, ' % win_s \ |
| 55 | + 'This is expected when using fftw3 on powerpc.') | 55 | + 'This is expected when using fftw3 on powerpc.') |
| 56 | assert_equal ( r, 0.) | 56 | assert_equal ( r, 0.) |
| 57 | 57 | ||
| @@ -3,11 +3,15 @@ · 2 unmodified lines | |||
| 3 | import os | 3 | import os |
| 4 | import re | 4 | import re |
| 5 | import glob | 5 | import glob |
| 6 | import struct | ||
| 6 | import numpy as np | 7 | import numpy as np |
| 7 | from tempfile import mkstemp | 8 | from tempfile import mkstemp |
| 8 | 9 | ||
| 9 | DEFAULT_SOUND = '22050Hz_5s_brownnoise.wav' | 10 | DEFAULT_SOUND = '22050Hz_5s_brownnoise.wav' |
| 10 | 11 | ||
| 12 | def is32bit(): | ||
| 13 | return struct.calcsize("P") * 8 == 32 | ||
| 14 | |||
| 11 | def array_from_text_file(filename, dtype = 'float'): | 15 | def array_from_text_file(filename, dtype = 'float'): |
| 12 | realpathname = os.path.join(os.path.dirname(__file__), filename) | 16 | realpathname = os.path.join(os.path.dirname(__file__), filename) |
| 13 | return np.loadtxt(realpathname, dtype = dtype) | 17 | return np.loadtxt(realpathname, dtype = dtype) |