History

Merge branch 'master' into feature/sink_vorbis

Paul Brossier committed 7 years ago

Commit f5adffe2 parents 0e6ad10 004566853 files · +405 −400Browse files

Unified · Split

53 files
  1. .appveyor.yml +1 −1
  2. .circleci/config.yml +8 −8
  3. .travis.yml +1 −0
  4. MANIFEST.in +1 −3
  5. Makefile +4 −6
  6. doc/python_module.rst +8 −7
  7. nose2.cfg +0 −6
  8. python/README.md +1 −1
  9. python/ext/aubiomodule.c +2 −2
  10. python/ext/py-cvec.c +1 −1
  11. python/ext/py-musicutils.c +10 −10
  12. python/tests/__init__.py +0 −1
  13. python/tests/_tools.py +41 −0
  14. python/tests/run_all_tests +0 −5
  15. python/tests/test_aubio.py +1 −2
  16. python/tests/test_aubio_cmd.py +2 −2
  17. python/tests/test_aubio_cut.py +1 −1
  18. python/tests/test_cvec.py +1 −1
  19. python/tests/test_dct.py +4 −0
  20. python/tests/test_fft.py +1 −1
  21. python/tests/test_filter.py +2 −2
  22. python/tests/test_filterbank.py +3 −3
  23. python/tests/test_filterbank_mel.py +14 −15
  24. python/tests/test_fvec.py +1 −1
  25. python/tests/test_fvec_shift.py +1 −1
  26. python/tests/test_hztomel.py +11 −8
  27. python/tests/test_mathutils.py +1 −1
  28. python/tests/test_mfcc.py +17 −21
  29. python/tests/test_midi2note.py +11 −12
  30. python/tests/test_musicutils.py +2 −2
  31. python/tests/test_note2midi.py +24 −19
  32. python/tests/test_notes.py +6 −7
  33. python/tests/test_onset.py +1 −1
  34. python/tests/test_phasevoc.py +13 −8
  35. python/tests/test_pitch.py +5 −5
  36. python/tests/test_sink.py +16 −22
  37. python/tests/test_slicing.py +3 −3
  38. python/tests/test_source.py +56 −53
  39. python/tests/test_source_channels.py +1 −1
  40. python/tests/test_specdesc.py +1 −1
  41. python/tests/test_zero_crossing_rate.py +1 −1
  42. python/tests/utils.py +6 −12
  43. requirements.txt +1 −1
  44. setup.py +0 −4
  45. src/io/sink_apple_audio.c +34 −8
  46. src/io/source_apple_audio.c +27 −41
  47. src/io/utils_apple_audio.c +4 −3
  48. tests/src/io/base-sink_custom.h +16 −12
  49. tests/src/io/test-sink.c +16 −12
  50. tests/src/onset/test-onset.c +9 −12
  51. tests/src/tempo/test-tempo.c +7 −14
  52. tests/src/temporal/test-filter.c +7 −12
  53. tests/src/test-delnull.c +0 −24
.appveyor.yml+1−1
@@ -75,4 +75,4 @@ build_script: · 74 unmodified lines
75 75
76test_script:76test_script:
77 - "python python\\demos\\demo_create_test_sounds.py"77 - "python python\\demos\\demo_create_test_sounds.py"
78 - "nose2 --verbose"78 - "pytest --verbose"
.circleci/config.yml+8−8
@@ -19,16 +19,16 @@ install-wheel: &install-wheel · 18 unmodified lines
19 command: |19 command: |
20 pip install --user dist/aubio*.whl20 pip install --user dist/aubio*.whl
21 21
22test-nose2: &test-nose222test-pytest: &test-pytest
23 name: Test python wheel23 name: Test python wheel
24 command: |24 command: |
25 make create_test_sounds25 make create_test_sounds
26 PATH=/home/circleci/.local/bin:$PATH nose2 -v26 PATH=/home/circleci/.local/bin:$PATH pytest -v
27 27
28test-nose2-nosounds: &test-nose2-nosounds28test-pytest-nosounds: &test-pytest-nosounds
29 name: Test python wheel29 name: Test python wheel
30 command: |30 command: |
31 PATH=/home/circleci/.local/bin:$PATH nose2 -v31 PATH=/home/circleci/.local/bin:$PATH pytest -v
32 32
33uninstall-wheel: &uninstall-wheel33uninstall-wheel: &uninstall-wheel
34 name: Uninstall python wheel34 name: Uninstall python wheel
@@ -47,7 +47,7 @@ jobs: · 12 unmodified lines
47 - run: *pip-install47 - run: *pip-install
48 - run: *build-wheel48 - run: *build-wheel
49 - run: *install-wheel49 - run: *install-wheel
50 - run: *test-nose250 - run: *test-pytest
51 - run: *uninstall-wheel51 - run: *uninstall-wheel
52 - store_artifacts:52 - store_artifacts:
53 path: dist/53 path: dist/
@@ -61,7 +61,7 @@ jobs: · 7 unmodified lines
61 - run: *pip-install61 - run: *pip-install
62 - run: *build-wheel62 - run: *build-wheel
63 - run: *install-wheel63 - run: *install-wheel
64 - run: *test-nose264 - run: *test-pytest
65 - run: *uninstall-wheel65 - run: *uninstall-wheel
66 - store_artifacts:66 - store_artifacts:
67 path: dist/67 path: dist/
@@ -75,7 +75,7 @@ jobs: · 7 unmodified lines
75 - run: *pip-install75 - run: *pip-install
76 - run: *build-wheel76 - run: *build-wheel
77 - run: *install-wheel77 - run: *install-wheel
78 - run: *test-nose278 - run: *test-pytest
79 - run: *uninstall-wheel79 - run: *uninstall-wheel
80 - store_artifacts:80 - store_artifacts:
81 path: dist/81 path: dist/
@@ -88,7 +88,7 @@ jobs: · 6 unmodified lines
88 - run: *pip-install88 - run: *pip-install
89 - run: *build-wheel89 - run: *build-wheel
90 - run: *install-wheel90 - run: *install-wheel
91 - run: *test-nose2-nosounds91 - run: *test-pytest-nosounds
92 - run: *uninstall-wheel92 - run: *uninstall-wheel
93 - store_artifacts:93 - store_artifacts:
94 path: dist/94 path: dist/
.travis.yml+1−0
@@ -87,6 +87,7 @@ install: · 86 unmodified lines
87 - travis_retry make getwaf expandwaf deps_python87 - travis_retry make getwaf expandwaf deps_python
88 - which pip88 - which pip
89 - pip --version89 - pip --version
90 - pip install coverage
90 91
91script:92script:
92 - make create_test_sounds93 - make create_test_sounds
MANIFEST.in+1−3
@@ -6,16 +6,14 @@ include waf · 5 unmodified lines
6recursive-include waflib *.py6recursive-include waflib *.py
7include Makefile wscript */wscript_build7include Makefile wscript */wscript_build
8include aubio.pc.in8include aubio.pc.in
9include nose2.cfg
10include requirements.txt9include requirements.txt
11include src/*.c src/*.h10include src/*.c src/*.h
12include src/*/*.c src/*/*.h11include src/*/*.c src/*/*.h
13include examples/*.c examples/*.h12include examples/*.c examples/*.h
14include tests/*.h tests/*/*.c tests/*/*/*.c13recursive-include tests *.h *.c *.py
15include python/ext/*.h14include python/ext/*.h
16recursive-include python *.py15recursive-include python *.py
17include python/README.md16include python/README.md
18include python/tests/run_all_tests
19include python/tests/eval_pitch17include python/tests/eval_pitch
20include python/tests/*.expected18include python/tests/*.expected
21include doc/*.txt doc/*.rst doc/*.cfg doc/Makefile doc/make.bat doc/conf.py19include doc/*.txt doc/*.rst doc/*.cfg doc/Makefile doc/make.bat doc/conf.py
Makefile+4−6
@@ -35,8 +35,8 @@ INCLUDEDIR?=$(PREFIX)/include · 34 unmodified lines
35DATAROOTDIR?=$(PREFIX)/share35DATAROOTDIR?=$(PREFIX)/share
36MANDIR?=$(DATAROOTDIR)/man36MANDIR?=$(DATAROOTDIR)/man
37 37
38# default nose2 command38# default python test command
39NOSE2?=nose2 -N 4 --verbose39PYTEST?=pytest --verbose
40 40
41SOX=sox41SOX=sox
42 42
@@ -140,9 +140,7 @@ test_python: export LD_LIBRARY_PATH=$(DESTDIR)/$(LIBDIR) · 97 unmodified lines
140test_python: export PYTHONPATH=$(PYDESTDIR)/$(LIBDIR)140test_python: export PYTHONPATH=$(PYDESTDIR)/$(LIBDIR)
141test_python: local_dylib141test_python: local_dylib
142 # run test with installed package142 # run test with installed package
143 # ./python/tests/run_all_tests --verbose143 $(PYTEST)
144 # run with nose2, multiple processes
145 $(NOSE2)
146 144
147clean_python:145clean_python:
148 ./setup.py clean146 ./setup.py clean
@@ -253,7 +251,7 @@ coverage: force_uninstall_python deps_python \ · 104 unmodified lines
253 # build and test python251 # build and test python
254 pip install -v -e .252 pip install -v -e .
255 # run tests, with python coverage253 # run tests, with python coverage
256 coverage run `which nose2`254 coverage run `which pytest`
257 # capture coverage again255 # capture coverage again
258 lcov $(LCOVOPTS) --capture --no-external --directory . \256 lcov $(LCOVOPTS) --capture --no-external --directory . \
259 --output-file build/coverage_python.info257 --output-file build/coverage_python.info
doc/python_module.rst+8−7
@@ -89,14 +89,15 @@ The command line `aubio` is also installed: · 88 unmodified lines
89Python tests89Python tests
90------------90------------
91 91
92A number of Python tests are provided in the `python tests`_. To run them,92A number of Python tests are provided in the `python/tests`_ folder. To run
93install `nose2`_ and run the script ``python/tests/run_all_tests``:93them, install `pytest`_ and run it from the aubio source directory:
94 94
95.. code-block:: console95.. code-block:: console
96 96
97 $ pip install nose297 $ pip install pytest
98 $ ./python/tests/run_all_tests98 $ git clone https://git.aubio.org/aubio/aubio
99 $ cd aubio
100 $ pytest
99 101
100.. _demo_filter.py: https://github.com/aubio/aubio/blob/master/python/demos/demo_filter.py102.. _python/tests: https://github.com/aubio/aubio/blob/master/python/tests
101.. _python tests: https://github.com/aubio/aubio/blob/master/python/tests103.. _pytest: https://pytest.org
102.. _nose2: https://github.com/nose-devs/nose2
nose2.cfg+0−6
@@ -1,6 +0,0 @@
1[unittest]
2start-dir = python/tests/
3plugins = nose2.plugins.mp
4
5[multiprocess]
6always-on = false
python/README.md+1−1
@@ -27,7 +27,7 @@ Links · 26 unmodified lines
27Demos27Demos
28-----28-----
29 29
30Some examples are available in the [`python/demos`][demos_dir] folder. Each30Some examples are available in the [`python/demos` folder][demos_dir]. Each
31script is a command line program which accepts one ore more argument.31script is a command line program which accepts one ore more argument.
32 32
33**Notes**: installing additional modules is required to run some of the demos.33**Notes**: installing additional modules is required to run some of the demos.
python/ext/aubiomodule.c+2−2
@@ -223,7 +223,7 @@ Py_alpha_norm (PyObject * self, PyObject * args) · 222 unmodified lines
223 }223 }
224 224
225 // compute the function225 // compute the function
226 result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, fvec_alpha_norm (&vec, alpha));226 result = PyFloat_FromDouble(fvec_alpha_norm (&vec, alpha));
227 if (result == NULL) {227 if (result == NULL) {
228 return NULL;228 return NULL;
229 }229 }
@@ -319,7 +319,7 @@ Py_zero_crossing_rate (PyObject * self, PyObject * args) · 89 unmodified lines
319 }319 }
320 320
321 // compute the function321 // compute the function
322 result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, aubio_zero_crossing_rate (&vec));322 result = PyFloat_FromDouble(aubio_zero_crossing_rate (&vec));
323 if (result == NULL) {323 if (result == NULL) {
324 return NULL;324 return NULL;
325 }325 }
python/ext/py-cvec.c+1−1
@@ -136,7 +136,7 @@ Py_cvec_repr (Py_cvec * self, PyObject * unused) · 135 unmodified lines
136 goto fail;136 goto fail;
137 }137 }
138 138
139 args = Py_BuildValue ("I", self->length);139 args = PyLong_FromLong(self->length);
140 if (args == NULL) {140 if (args == NULL) {
141 goto fail;141 goto fail;
142 }142 }
python/ext/py-musicutils.c+10−10
@@ -39,7 +39,7 @@ Py_aubio_level_lin(PyObject *self, PyObject *args) · 38 unmodified lines
39 return NULL;39 return NULL;
40 }40 }
41 41
42 level_lin = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_lin(&vec));42 level_lin = PyFloat_FromDouble(aubio_level_lin(&vec));
43 if (level_lin == NULL) {43 if (level_lin == NULL) {
44 PyErr_SetString (PyExc_ValueError, "failed computing level_lin");44 PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
45 return NULL;45 return NULL;
@@ -67,7 +67,7 @@ Py_aubio_db_spl(PyObject *self, PyObject *args) · 21 unmodified lines
67 return NULL;67 return NULL;
68 }68 }
69 69
70 db_spl = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_db_spl(&vec));70 db_spl = PyFloat_FromDouble(aubio_db_spl(&vec));
71 if (db_spl == NULL) {71 if (db_spl == NULL) {
72 PyErr_SetString (PyExc_ValueError, "failed computing db_spl");72 PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
73 return NULL;73 return NULL;
@@ -96,7 +96,7 @@ Py_aubio_silence_detection(PyObject *self, PyObject *args) · 22 unmodified lines
96 return NULL;96 return NULL;
97 }97 }
98 98
99 silence_detection = Py_BuildValue("I", aubio_silence_detection(&vec, threshold));99 silence_detection = PyLong_FromLong(aubio_silence_detection(&vec, threshold));
100 if (silence_detection == NULL) {100 if (silence_detection == NULL) {
101 PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");101 PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");
102 return NULL;102 return NULL;
@@ -125,7 +125,7 @@ Py_aubio_level_detection(PyObject *self, PyObject *args) · 22 unmodified lines
125 return NULL;125 return NULL;
126 }126 }
127 127
128 level_detection = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_detection(&vec, threshold));128 level_detection = PyFloat_FromDouble(aubio_level_detection(&vec, threshold));
129 if (level_detection == NULL) {129 if (level_detection == NULL) {
130 PyErr_SetString (PyExc_ValueError, "failed computing level_detection");130 PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
131 return NULL;131 return NULL;
@@ -194,9 +194,9 @@ Py_aubio_hztomel(PyObject *self, PyObject *args, PyObject *kwds) · 62 unmodified lines
194 return NULL;194 return NULL;
195 }195 }
196 if (htk != NULL && PyObject_IsTrue(htk) == 1)196 if (htk != NULL && PyObject_IsTrue(htk) == 1)
197 return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));197 return PyFloat_FromDouble(aubio_hztomel_htk(v));
198 else198 else
199 return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel(v));199 return PyFloat_FromDouble(aubio_hztomel(v));
200}200}
201 201
202PyObject*202PyObject*
@@ -211,9 +211,9 @@ Py_aubio_meltohz(PyObject *self, PyObject *args, PyObject *kwds) · 8 unmodified lines
211 return NULL;211 return NULL;
212 }212 }
213 if (htk != NULL && PyObject_IsTrue(htk) == 1)213 if (htk != NULL && PyObject_IsTrue(htk) == 1)
214 return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v));214 return PyFloat_FromDouble(aubio_meltohz_htk(v));
215 else215 else
216 return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz(v));216 return PyFloat_FromDouble(aubio_meltohz(v));
217}217}
218 218
219PyObject*219PyObject*
@@ -223,7 +223,7 @@ Py_aubio_hztomel_htk(PyObject *self, PyObject *args) · 3 unmodified lines
223 if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) {223 if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) {
224 return NULL;224 return NULL;
225 }225 }
226 return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));226 return PyFloat_FromDouble(aubio_hztomel_htk(v));
227}227}
228 228
229PyObject*229PyObject*
@@ -233,5 +233,5 @@ Py_aubio_meltohz_htk(PyObject *self, PyObject *args) · 3 unmodified lines
233 if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) {233 if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) {
234 return NULL;234 return NULL;
235 }235 }
236 return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v));236 return PyFloat_FromDouble(aubio_meltohz_htk(v));
237}237}
python/tests/__init__.py+0−1
@@ -1 +0,0 @@
1
python/tests/_tools.py+41−0
@@ -0,0 +1,41 @@
1"""
2This file imports test methods from different testing modules, in this
3order:
4
5 - try importing 'pytest'
6 - if it fails, fallback to 'numpy.testing'
7
8Nose2 support was removed because of lacking assertWarns on py2.7.
9
10"""
11
12import sys
13
14_has_pytest = False
15
16# check if we have pytest
17try:
18 import pytest
19 parametrize = pytest.mark.parametrize
20 assert_raises = pytest.raises
21 assert_warns = pytest.warns
22 skipTest = pytest.skip
23 _has_pytest = True
24 def run_module_suite():
25 import sys, pytest
26 pytest.main(sys.argv)
27except:
28 pass
29
30# otherwise fallback on numpy.testing
31if not _has_pytest:
32 from numpy.testing import dec, assert_raises, assert_warns
33 from numpy.testing import SkipTest
34 parametrize = dec.parametrize
35 def skipTest(msg):
36 raise SkipTest(msg)
37 from numpy.testing import run_module_suite
38
39# always use numpy's assert_equal
40import numpy
41assert_equal = numpy.testing.assert_equal
python/tests/run_all_tests+0−5
@@ -1,5 +0,0 @@
1#! /usr/bin/env python
2
3if __name__ == '__main__':
4 import nose2.main
5 nose2.discover()
python/tests/test_aubio.py+1−2
@@ -1,6 +1,5 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main
4from numpy.testing import TestCase3from numpy.testing import TestCase
5 4
6class aubiomodule_test_case(TestCase):5class aubiomodule_test_case(TestCase):
@@ -15,5 +14,5 @@ class aubiomodule_test_case(TestCase): · 8 unmodified lines
15 self.assertEqual('0', aubio.version[0])14 self.assertEqual('0', aubio.version[0])
16 15
17if __name__ == '__main__':16if __name__ == '__main__':
17 from unittest import main
18 main()18 main()
19
python/tests/test_aubio_cmd.py+2−2
@@ -1,8 +1,7 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3import aubio.cmd
4from nose2 import main
5from numpy.testing import TestCase3from numpy.testing import TestCase
4import aubio.cmd
6 5
7class aubio_cmd(TestCase):6class aubio_cmd(TestCase):
8 7
@@ -31,4 +30,5 @@ class aubio_cmd_utils(TestCase): · 22 unmodified lines
31 "3200\t")30 "3200\t")
32 31
33if __name__ == '__main__':32if __name__ == '__main__':
33 from unittest import main
34 main()34 main()
python/tests/test_aubio_cut.py+1−1
@@ -1,7 +1,6 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3import aubio.cut3import aubio.cut
4from nose2 import main
5from numpy.testing import TestCase4from numpy.testing import TestCase
6 5
7class aubio_cut(TestCase):6class aubio_cut(TestCase):
@@ -13,4 +12,5 @@ class aubio_cut(TestCase): · 5 unmodified lines
13 assert self.a_parser.parse_args(['-v']).verbose12 assert self.a_parser.parse_args(['-v']).verbose
14 13
15if __name__ == '__main__':14if __name__ == '__main__':
15 from unittest import main
16 main()16 main()
python/tests/test_cvec.py+1−1
@@ -1,6 +1,5 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main
4import numpy as np3import numpy as np
5from numpy.testing import TestCase, assert_equal4from numpy.testing import TestCase, assert_equal
6from aubio import cvec, fvec, float_type5from aubio import cvec, fvec, float_type
@@ -141,4 +140,5 @@ class aubio_cvec_wrong_norm_input(TestCase): · 134 unmodified lines
141 a.norm = np.zeros((512//2+1, 2), dtype = float_type)140 a.norm = np.zeros((512//2+1, 2), dtype = float_type)
142 141
143if __name__ == '__main__':142if __name__ == '__main__':
143 from unittest import main
144 main()144 main()
python/tests/test_dct.py+4−0
@@ -66,3 +66,7 @@ class aubio_dct(TestCase): · 65 unmodified lines
66 aubio.dct(size)66 aubio.dct(size)
67 except AssertionError:67 except AssertionError:
68 self.skipTest('creating aubio.dct with size %d did not fail' % size)68 self.skipTest('creating aubio.dct with size %d did not fail' % size)
69
70if __name__ == '__main__':
71 from unittest import main
72 main()
python/tests/test_fft.py+1−1
@@ -1,6 +1,5 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main
4from numpy.testing import TestCase3from numpy.testing import TestCase
5from numpy.testing import assert_equal, assert_almost_equal4from numpy.testing import assert_equal, assert_almost_equal
6import numpy as np5import numpy as np
@@ -212,4 +211,5 @@ class aubio_fft_wrong_params(TestCase): · 205 unmodified lines
212 fft(win_s)211 fft(win_s)
213 212
214if __name__ == '__main__':213if __name__ == '__main__':
214 from unittest import main
215 main()215 main()
python/tests/test_filter.py+2−2
@@ -1,9 +1,8 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main
4from numpy.testing import TestCase, assert_equal, assert_almost_equal3from numpy.testing import TestCase, assert_equal, assert_almost_equal
5from aubio import fvec, digital_filter4from aubio import fvec, digital_filter
6from .utils import array_from_text_file5from utils import array_from_text_file
7 6
8class aubio_filter_test_case(TestCase):7class aubio_filter_test_case(TestCase):
9 8
@@ -94,4 +93,5 @@ class aubio_filter_wrong_params(TestCase): · 84 unmodified lines
94 digital_filter(-1)93 digital_filter(-1)
95 94
96if __name__ == '__main__':95if __name__ == '__main__':
96 from unittest import main
97 main()97 main()
python/tests/test_filterbank.py+3−3
@@ -4,7 +4,7 @@ import numpy as np · 3 unmodified lines
4from numpy.testing import TestCase, assert_equal, assert_almost_equal4from numpy.testing import TestCase, assert_equal, assert_almost_equal
5 5
6from aubio import cvec, filterbank, float_type6from aubio import cvec, filterbank, float_type
7from .utils import array_from_text_file7from utils import array_from_text_file
8 8
9class aubio_filterbank_test_case(TestCase):9class aubio_filterbank_test_case(TestCase):
10 10
@@ -87,5 +87,5 @@ class aubio_filterbank_wrong_values(TestCase): · 76 unmodified lines
87 f(cvec(256))87 f(cvec(256))
88 88
89if __name__ == '__main__':89if __name__ == '__main__':
90 import nose290 from unittest import main
91 nose2.main()91 main()
python/tests/test_filterbank_mel.py+14−15
@@ -2,12 +2,10 @@ · 1 unmodified line
2 2
3import numpy as np3import numpy as np
4from numpy.testing import TestCase, assert_equal, assert_almost_equal4from numpy.testing import TestCase, assert_equal, assert_almost_equal
5from _tools import assert_warns
5 6
6from aubio import fvec, cvec, filterbank, float_type7from aubio import fvec, cvec, filterbank, float_type
7 8
8import warnings
9warnings.filterwarnings('ignore', category=UserWarning, append=True)
10
11class aubio_filterbank_mel_test_case(TestCase):9class aubio_filterbank_mel_test_case(TestCase):
12 10
13 def test_slaney(self):11 def test_slaney(self):
@@ -75,40 +73,41 @@ class aubio_filterbank_mel_test_case(TestCase): · 61 unmodified lines
75 samplerate = 2205073 samplerate = 22050
76 freq_list = [0, samplerate//4, samplerate // 2 + 1]74 freq_list = [0, samplerate//4, samplerate // 2 + 1]
77 f = filterbank(len(freq_list)-2, 1024)75 f = filterbank(len(freq_list)-2, 1024)
78 # TODO add assert_warns76 with assert_warns(UserWarning):
79 f.set_triangle_bands(fvec(freq_list), samplerate)77 f.set_triangle_bands(fvec(freq_list), samplerate)
80 78
81 def test_triangle_freqs_with_not_enough_filters(self):79 def test_triangle_freqs_with_not_enough_filters(self):
82 """make sure set_triangle_bands warns when not enough filters"""80 """make sure set_triangle_bands warns when not enough filters"""
83 samplerate = 2205081 samplerate = 22050
84 freq_list = [0, 100, 1000, 4000, 8000, 10000]82 freq_list = [0, 100, 1000, 4000, 8000, 10000]
85 f = filterbank(len(freq_list)-3, 1024)83 f = filterbank(len(freq_list)-3, 1024)
86 # TODO add assert_warns84 with assert_warns(UserWarning):
87 f.set_triangle_bands(fvec(freq_list), samplerate)85 f.set_triangle_bands(fvec(freq_list), samplerate)
88 86
89 def test_triangle_freqs_with_too_many_filters(self):87 def test_triangle_freqs_with_too_many_filters(self):
90 """make sure set_triangle_bands warns when too many filters"""88 """make sure set_triangle_bands warns when too many filters"""
91 samplerate = 2205089 samplerate = 22050
92 freq_list = [0, 100, 1000, 4000, 8000, 10000]90 freq_list = [0, 100, 1000, 4000, 8000, 10000]
93 f = filterbank(len(freq_list)-1, 1024)91 f = filterbank(len(freq_list)-1, 1024)
94 # TODO add assert_warns92 with assert_warns(UserWarning):
95 f.set_triangle_bands(fvec(freq_list), samplerate)93 f.set_triangle_bands(fvec(freq_list), samplerate)
96 94
97 def test_triangle_freqs_with_double_value(self):95 def test_triangle_freqs_with_double_value(self):
98 """make sure set_triangle_bands works with 2 duplicate freqs"""96 """make sure set_triangle_bands works with 2 duplicate freqs"""
99 samplerate = 2205097 samplerate = 22050
100 freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]98 freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
101 f = filterbank(len(freq_list)-2, 1024)99 f = filterbank(len(freq_list)-2, 1024)
102 # TODO add assert_warns100 with assert_warns(UserWarning):
103 f.set_triangle_bands(fvec(freq_list), samplerate)101 f.set_triangle_bands(fvec(freq_list), samplerate)
104 102
105 def test_triangle_freqs_with_triple(self):103 def test_triangle_freqs_with_triple(self):
106 """make sure set_triangle_bands works with 3 duplicate freqs"""104 """make sure set_triangle_bands works with 3 duplicate freqs"""
107 samplerate = 22050105 samplerate = 22050
108 freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]106 freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
109 f = filterbank(len(freq_list)-2, 1024)107 f = filterbank(len(freq_list)-2, 1024)
110 # TODO add assert_warns108 with assert_warns(UserWarning):
111 f.set_triangle_bands(fvec(freq_list), samplerate)109 f.set_triangle_bands(fvec(freq_list), samplerate)
110
112 111
113 def test_triangle_freqs_without_norm(self):112 def test_triangle_freqs_without_norm(self):
114 """make sure set_triangle_bands works without """113 """make sure set_triangle_bands works without """
@@ -168,5 +167,5 @@ class aubio_filterbank_mel_test_case(TestCase): · 53 unmodified lines
168 167
169 168
170if __name__ == '__main__':169if __name__ == '__main__':
171 import nose2170 from unittest import main
172 nose2.main()171 main()
python/tests/test_fvec.py+1−1
@@ -1,6 +1,5 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main
4import numpy as np3import numpy as np
5from numpy.testing import TestCase, assert_equal, assert_almost_equal4from numpy.testing import TestCase, assert_equal, assert_almost_equal
6from aubio import fvec, zero_crossing_rate, alpha_norm, min_removal5from aubio import fvec, zero_crossing_rate, alpha_norm, min_removal
@@ -148,4 +147,5 @@ class aubio_fvec_test_memory(TestCase): · 141 unmodified lines
148 del c147 del c
149 148
150if __name__ == '__main__':149if __name__ == '__main__':
150 from unittest import main
151 main()151 main()
python/tests/test_fvec_shift.py+1−1
@@ -30,6 +30,6 @@ class aubio_shift_test_case(TestCase): · 29 unmodified lines
30 def test_can_shift_fvec_odd(self):30 def test_can_shift_fvec_odd(self):
31 self.run_shift_ishift(7)31 self.run_shift_ishift(7)
32 32
33from unittest import main
34if __name__ == '__main__':33if __name__ == '__main__':
34 from unittest import main
35 main()35 main()
python/tests/test_hztomel.py+11−8
@@ -3,6 +3,7 @@ · 2 unmodified lines
3from unittest import main3from unittest import main
4from numpy.testing import TestCase4from numpy.testing import TestCase
5from numpy.testing import assert_equal, assert_almost_equal5from numpy.testing import assert_equal, assert_almost_equal
6from _tools import assert_warns
6import numpy as np7import numpy as np
7import aubio8import aubio
8 9
@@ -37,12 +38,12 @@ class aubio_hztomel_test_case(TestCase): · 28 unmodified lines
37 assert_almost_equal(meltohz(hztomel(f)) - f, 0, decimal=1)38 assert_almost_equal(meltohz(hztomel(f)) - f, 0, decimal=1)
38 39
39 def test_meltohz_negative(self):40 def test_meltohz_negative(self):
40 # TODO add assert_warns41 with assert_warns(UserWarning):
41 assert_equal(meltohz(-1), 0)42 assert_equal(meltohz(-1), 0)
42 43
43 def test_hztomel_negative(self):44 def test_hztomel_negative(self):
44 # TODO add assert_warns45 with assert_warns(UserWarning):
45 assert_equal(hztomel(-1), 0)46 assert_equal(hztomel(-1), 0)
46 47
47 48
48class aubio_hztomel_htk_test_case(TestCase):49class aubio_hztomel_htk_test_case(TestCase):
@@ -57,14 +58,16 @@ class aubio_hztomel_htk_test_case(TestCase): · 8 unmodified lines
57 assert_almost_equal(hztomel(6300, htk=True), 2595., decimal=1)58 assert_almost_equal(hztomel(6300, htk=True), 2595., decimal=1)
58 59
59 def test_meltohz_negative(self):60 def test_meltohz_negative(self):
60 # TODO add assert_warns61 with assert_warns(UserWarning):
61 assert_equal(meltohz(-1, htk=True), 0)62 assert_equal(meltohz(-1, htk=True), 0)
62 assert_almost_equal(meltohz(2000, htk=True), 3428.7, decimal=1)63 assert_almost_equal(meltohz(2000, htk=True), 3428.7, decimal=1)
63 assert_almost_equal(meltohz(1000, htk=True), 1000., decimal=1)64 assert_almost_equal(meltohz(1000, htk=True), 1000., decimal=1)
64 65
65 def test_hztomel_negative(self):66 def test_hztomel_negative(self):
66 # TODO add assert_warns67 with assert_warns(UserWarning):
67 assert_equal(hztomel(-1, htk=True), 0)68 assert_equal(meltohz(-1, htk=True), 0)
69 with assert_warns(UserWarning):
70 assert_equal(hztomel(-1, htk=True), 0)
68 assert_almost_equal(hztomel(1000, htk=True), 1000., decimal=1)71 assert_almost_equal(hztomel(1000, htk=True), 1000., decimal=1)
69 72
70 def test_hztomel_htk(self):73 def test_hztomel_htk(self):
python/tests/test_mathutils.py+1−1
@@ -1,6 +1,5 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main
4from numpy.testing import TestCase, assert_equal3from numpy.testing import TestCase, assert_equal
5from numpy import array, arange, isnan, isinf4from numpy import array, arange, isnan, isinf
6from aubio import bintomidi, miditobin, freqtobin, bintofreq, freqtomidi, miditofreq5from aubio import bintomidi, miditobin, freqtobin, bintofreq, freqtomidi, miditofreq
@@ -101,4 +100,5 @@ class aubio_mathutils(TestCase): · 94 unmodified lines
101 assert_equal ( array(b) < 0, False )100 assert_equal ( array(b) < 0, False )
102 101
103if __name__ == '__main__':102if __name__ == '__main__':
103 from unittest import main
104 main()104 main()
python/tests/test_mfcc.py+17−21
@@ -1,7 +1,6 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from nose2 import main3from _tools import parametrize, assert_raises
4from nose2.tools import params
5from numpy import random, count_nonzero4from numpy import random, count_nonzero
6from numpy.testing import TestCase5from numpy.testing import TestCase
7from aubio import mfcc, cvec, float_type6from aubio import mfcc, cvec, float_type
@@ -15,28 +14,21 @@ samplerate = 44100 · 7 unmodified lines
15new_params = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']14new_params = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
16new_deflts = [1024, 40, 13, 44100]15new_deflts = [1024, 40, 13, 44100]
17 16
18class aubio_mfcc(TestCase):17class Test_aubio_mfcc(object):
19 18
20 def setUp(self):19 members_args = 'name'
21 self.o = mfcc()
22 20
23 def test_default_creation(self):21 @parametrize(members_args, new_params)
24 pass
25
26 def test_delete(self):
27 del self.o
28
29 @params(*new_params)
30 def test_read_only_member(self, name):22 def test_read_only_member(self, name):
31 o = self.o23 o = mfcc()
32 with self.assertRaises((TypeError, AttributeError)):24 with assert_raises((TypeError, AttributeError)):
33 setattr(o, name, 0)25 setattr(o, name, 0)
34 26
35 @params(*zip(new_params, new_deflts))27 @parametrize('name, expected', zip(new_params, new_deflts))
36 def test_default_param(self, name, expected):28 def test_default_param(self, name, expected):
37 """ test mfcc.{:s} = {:d} """.format(name, expected)29 """ test mfcc.{:s} = {:d} """.format(name, expected)
38 o = self.o30 o = mfcc()
39 self.assertEqual( getattr(o, name), expected)31 assert getattr(o, name) == expected
40 32
41class aubio_mfcc_wrong_params(TestCase):33class aubio_mfcc_wrong_params(TestCase):
42 34
@@ -82,9 +74,9 @@ class aubio_mfcc_compute(TestCase): · 39 unmodified lines
82 #print coeffs74 #print coeffs
83 75
84 76
85class aubio_mfcc_all_parameters(TestCase):77class Test_aubio_mfcc_all_parameters(object):
86 78
87 @params(79 run_values = [
88 (2048, 40, 13, 44100),80 (2048, 40, 13, 44100),
89 (1024, 40, 13, 44100),81 (1024, 40, 13, 44100),
90 (512, 40, 13, 44100),82 (512, 40, 13, 44100),
@@ -100,7 +92,10 @@ class aubio_mfcc_all_parameters(TestCase): · 9 unmodified lines
100 #(1024, 30, 20, 44100),92 #(1024, 30, 20, 44100),
101 (1024, 40, 40, 44100),93 (1024, 40, 40, 44100),
102 (1024, 40, 3, 44100),94 (1024, 40, 3, 44100),
103 )95 ]
96 run_args = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
97
98 @parametrize(run_args, run_values)
104 def test_run_with_params(self, buf_size, n_filters, n_coeffs, samplerate):99 def test_run_with_params(self, buf_size, n_filters, n_coeffs, samplerate):
105 " check mfcc can run with reasonable parameters "100 " check mfcc can run with reasonable parameters "
106 o = mfcc(buf_size, n_filters, n_coeffs, samplerate)101 o = mfcc(buf_size, n_filters, n_coeffs, samplerate)
@@ -148,4 +143,5 @@ class aubio_mfcc_fb_params(TestCase): · 41 unmodified lines
148 assert m.get_scale() == 1143 assert m.get_scale() == 1
149 144
150if __name__ == '__main__':145if __name__ == '__main__':
151 main()146 from _tools import run_module_suite
147 run_module_suite()
python/tests/test_midi2note.py+11−12
@@ -2,8 +2,7 @@ · 1 unmodified line
2# -*- coding: utf-8 -*-2# -*- coding: utf-8 -*-
3 3
4from aubio import midi2note4from aubio import midi2note
5from nose2.tools import params5from _tools import parametrize, assert_raises
6import unittest
7 6
8list_of_known_midis = (7list_of_known_midis = (
9 ( 0, 'C-1' ),8 ( 0, 'C-1' ),
@@ -15,31 +14,31 @@ list_of_known_midis = ( · 5 unmodified lines
15 ( 127, 'G9' ),14 ( 127, 'G9' ),
16 )15 )
17 16
18class midi2note_good_values(unittest.TestCase):17class Test_midi2note_good_values(object):
19 18
20 @params(*list_of_known_midis)19 @parametrize('midi, note', list_of_known_midis)
21 def test_midi2note_known_values(self, midi, note):20 def test_midi2note_known_values(self, midi, note):
22 " known values are correctly converted "21 " known values are correctly converted "
23 self.assertEqual ( midi2note(midi), note )22 assert midi2note(midi) == (note)
24 23
25class midi2note_wrong_values(unittest.TestCase):24class Test_midi2note_wrong_values(object):
26 25
27 def test_midi2note_negative_value(self):26 def test_midi2note_negative_value(self):
28 " fails when passed a negative value "27 " fails when passed a negative value "
29 self.assertRaises(ValueError, midi2note, -2)28 assert_raises(ValueError, midi2note, -2)
30 29
31 def test_midi2note_large(self):30 def test_midi2note_large(self):
32 " fails when passed a value greater than 127 "31 " fails when passed a value greater than 127 "
33 self.assertRaises(ValueError, midi2note, 128)32 assert_raises(ValueError, midi2note, 128)
34 33
35 def test_midi2note_floating_value(self):34 def test_midi2note_floating_value(self):
36 " fails when passed a floating point "35 " fails when passed a floating point "
37 self.assertRaises(TypeError, midi2note, 69.2)36 assert_raises(TypeError, midi2note, 69.2)
38 37
39 def test_midi2note_character_value(self):38 def test_midi2note_character_value(self):
40 " fails when passed a value that can not be transformed to integer "39 " fails when passed a value that can not be transformed to integer "
41 self.assertRaises(TypeError, midi2note, "a")40 assert_raises(TypeError, midi2note, "a")
42 41
43if __name__ == '__main__':42if __name__ == '__main__':
44 import nose243 from _tools import run_module_suite
45 nose2.main()44 run_module_suite()
python/tests/test_musicutils.py+2−2
@@ -1,9 +1,8 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main
4import numpy as np3import numpy as np
5from numpy.testing import TestCase4from numpy.testing import TestCase
6from numpy.testing.utils import assert_equal, assert_almost_equal5from numpy.testing import assert_equal, assert_almost_equal
7from aubio import window, level_lin, db_spl, silence_detection, level_detection6from aubio import window, level_lin, db_spl, silence_detection, level_detection
8from aubio import fvec, float_type7from aubio import fvec, float_type
9 8
@@ -85,4 +84,5 @@ class aubio_level_detection(TestCase): · 75 unmodified lines
85 assert level_detection(ones(1024, dtype = float_type), -70) == 084 assert level_detection(ones(1024, dtype = float_type), -70) == 0
86 85
87if __name__ == '__main__':86if __name__ == '__main__':
87 from unittest import main
88 main()88 main()
python/tests/test_note2midi.py+24−19
@@ -4,8 +4,8 @@ · 3 unmodified lines
4from __future__ import unicode_literals4from __future__ import unicode_literals
5 5
6from aubio import note2midi, freq2note, note2freq, float_type6from aubio import note2midi, freq2note, note2freq, float_type
7from nose2.tools import params7from numpy.testing import TestCase
8import unittest8from _tools import parametrize, assert_raises, skipTest
9 9
10list_of_known_notes = (10list_of_known_notes = (
11 ( 'C-1', 0 ),11 ( 'C-1', 0 ),
@@ -44,29 +44,32 @@ list_of_unknown_notes = ( · 32 unmodified lines
44 ( '2' ),44 ( '2' ),
45 )45 )
46 46
47class note2midi_good_values(unittest.TestCase):47class Test_note2midi_good_values(object):
48 48
49 @params(*list_of_known_notes)49 @parametrize('note, midi', list_of_known_notes)
50 def test_note2midi_known_values(self, note, midi):50 def test_note2midi_known_values(self, note, midi):
51 " known values are correctly converted "51 " known values are correctly converted "
52 self.assertEqual ( note2midi(note), midi )52 assert note2midi(note) == midi
53 53
54 @params(*list_of_known_notes_with_unicode_issues)54 @parametrize('note, midi', list_of_known_notes_with_unicode_issues)
55 def test_note2midi_known_values_with_unicode_issues(self, note, midi):55 def test_note2midi_known_values_with_unicode_issues(self, note, midi):
56 " known values are correctly converted, unless decoding is expected to fail"56 " difficult values are correctly converted unless expected failure "
57 try:57 try:
58 self.assertEqual ( note2midi(note), midi )58 assert note2midi(note) == midi
59 except UnicodeEncodeError as e:59 except UnicodeEncodeError as e:
60 # platforms with decoding failures include:
61 # - osx: python <= 2.7.10
62 # - win: python <= 2.7.12
60 import sys63 import sys
61 strfmt = "len(u'\\U0001D12A') != 1, excpected decoding failure | {:s} | {:s} {:s}"64 strmsg = "len(u'\\U0001D12A') != 1, expected decoding failure"
62 strres = strfmt.format(e, sys.platform, sys.version)65 strmsg += " | upgrade to Python 3 to fix"
63 # happens with: darwin 2.7.10, windows 2.7.1266 strmsg += " | {:s} | {:s} {:s}"
64 if len('\U0001D12A') != 1 and sys.version[0] == '2':67 if len('\U0001D12A') != 1 and sys.version[0] == '2':
65 self.skipTest(strres + " | upgrade to Python 3 to fix")68 skipTest(strmsg.format(repr(e), sys.platform, sys.version))
66 else:69 else:
67 raise70 raise
68 71
69class note2midi_wrong_values(unittest.TestCase):72class note2midi_wrong_values(TestCase):
70 73
71 def test_note2midi_missing_octave(self):74 def test_note2midi_missing_octave(self):
72 " fails when passed only one character"75 " fails when passed only one character"
@@ -104,12 +107,14 @@ class note2midi_wrong_values(unittest.TestCase): · 31 unmodified lines
104 " fails when passed a note with a note name longer than expected"107 " fails when passed a note with a note name longer than expected"
105 self.assertRaises(ValueError, note2midi, 'CB+-3')108 self.assertRaises(ValueError, note2midi, 'CB+-3')
106 109
107 @params(*list_of_unknown_notes)110class Test_note2midi_unknown_values(object):
111
112 @parametrize('note', list_of_unknown_notes)
108 def test_note2midi_unknown_values(self, note):113 def test_note2midi_unknown_values(self, note):
109 " unknown values throw out an error "114 " unknown values throw out an error "
110 self.assertRaises(ValueError, note2midi, note)115 assert_raises(ValueError, note2midi, note)
111 116
112class freq2note_simple_test(unittest.TestCase):117class freq2note_simple_test(TestCase):
113 118
114 def test_freq2note_above(self):119 def test_freq2note_above(self):
115 " make sure freq2note(441) == A4 "120 " make sure freq2note(441) == A4 "
@@ -119,7 +124,7 @@ class freq2note_simple_test(unittest.TestCase): · 3 unmodified lines
119 " make sure freq2note(439) == A4 "124 " make sure freq2note(439) == A4 "
120 self.assertEqual("A4", freq2note(439))125 self.assertEqual("A4", freq2note(439))
121 126
122class note2freq_simple_test(unittest.TestCase):127class note2freq_simple_test(TestCase):
123 128
124 def test_note2freq(self):129 def test_note2freq(self):
125 " make sure note2freq('A3') == 220"130 " make sure note2freq('A3') == 220"
@@ -133,5 +138,5 @@ class note2freq_simple_test(unittest.TestCase): · 7 unmodified lines
133 self.assertLess(abs(note2freq("A4")-440), 1.e-12)138 self.assertLess(abs(note2freq("A4")-440), 1.e-12)
134 139
135if __name__ == '__main__':140if __name__ == '__main__':
136 import nose2141 from _tools import run_module_suite
137 nose2.main()142 run_module_suite()
python/tests/test_notes.py+6−7
@@ -1,8 +1,11 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main
4from numpy.testing import TestCase, assert_equal, assert_almost_equal3from numpy.testing import TestCase, assert_equal, assert_almost_equal
5from aubio import notes4from aubio import notes, source
5import numpy as np
6from utils import list_all_sounds
7
8list_of_sounds = list_all_sounds('sounds')
6 9
7AUBIO_DEFAULT_NOTES_SILENCE = -70.10AUBIO_DEFAULT_NOTES_SILENCE = -70.
8AUBIO_DEFAULT_NOTES_RELEASE_DROP = 10.11AUBIO_DEFAULT_NOTES_RELEASE_DROP = 10.
@@ -52,14 +55,9 @@ class aubio_notes_params(TestCase): · 43 unmodified lines
52 with self.assertRaises(ValueError):55 with self.assertRaises(ValueError):
53 self.o.set_release_drop(val)56 self.o.set_release_drop(val)
54 57
55from .utils import list_all_sounds
56list_of_sounds = list_all_sounds('sounds')
57
58class aubio_notes_sinewave(TestCase):58class aubio_notes_sinewave(TestCase):
59 59
60 def analyze_file(self, filepath, samplerate=0):60 def analyze_file(self, filepath, samplerate=0):
61 from aubio import source
62 import numpy as np
63 win_s = 512 # fft size61 win_s = 512 # fft size
64 hop_s = 256 # hop size62 hop_s = 256 # hop size
65 63
@@ -92,4 +90,5 @@ class aubio_notes_sinewave(TestCase): · 26 unmodified lines
92 assert_equal (results[0][1], [69, 123, -1])90 assert_equal (results[0][1], [69, 123, -1])
93 91
94if __name__ == '__main__':92if __name__ == '__main__':
93 from unittest import main
95 main()94 main()
python/tests/test_onset.py+1−1
@@ -1,6 +1,5 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main
4from numpy.testing import TestCase, assert_equal, assert_almost_equal3from numpy.testing import TestCase, assert_equal, assert_almost_equal
5from aubio import onset, fvec4from aubio import onset, fvec
6 5
@@ -116,4 +115,5 @@ class aubio_onset_coverate(TestCase): · 109 unmodified lines
116 115
117 116
118if __name__ == '__main__':117if __name__ == '__main__':
118 from unittest import main
119 main()119 main()
python/tests/test_phasevoc.py+13−8
@@ -1,9 +1,8 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from numpy.testing import TestCase, assert_equal, assert_array_less3from numpy.testing import TestCase, assert_equal, assert_array_less
4from _tools import parametrize
4from aubio import fvec, cvec, pvoc, float_type5from aubio import fvec, cvec, pvoc, float_type
5from nose2 import main
6from nose2.tools import params
7import numpy as np6import numpy as np
8 7
9if float_type == 'float32':8if float_type == 'float32':
@@ -18,7 +17,7 @@ def create_sine(hop_s, freq, samplerate): · 8 unmodified lines
18def create_noise(hop_s):17def create_noise(hop_s):
19 return np.random.rand(hop_s).astype(float_type) * 2. - 1.18 return np.random.rand(hop_s).astype(float_type) * 2. - 1.
20 19
21class aubio_pvoc_test_case(TestCase):20class Test_aubio_pvoc_test_case(object):
22 """ pvoc object test case """21 """ pvoc object test case """
23 22
24 def test_members_automatic_sizes_default(self):23 def test_members_automatic_sizes_default(self):
@@ -65,7 +64,8 @@ class aubio_pvoc_test_case(TestCase): · 40 unmodified lines
65 r = f.rdo(s)64 r = f.rdo(s)
66 assert_equal ( t, 0.)65 assert_equal ( t, 0.)
67 66
68 @params(67 resynth_noise_args = "hop_s, ratio"
68 resynth_noise_values = [
69 ( 256, 8),69 ( 256, 8),
70 ( 256, 4),70 ( 256, 4),
71 ( 256, 2),71 ( 256, 2),
@@ -87,13 +87,16 @@ class aubio_pvoc_test_case(TestCase): · 15 unmodified lines
87 (8192, 8),87 (8192, 8),
88 (8192, 4),88 (8192, 4),
89 (8192, 2),89 (8192, 2),
90 )90 ]
91
92 @parametrize(resynth_noise_args, resynth_noise_values)
91 def test_resynth_steps_noise(self, hop_s, ratio):93 def test_resynth_steps_noise(self, hop_s, ratio):
92 """ check the resynthesis of a random signal is correct """94 """ check the resynthesis of a random signal is correct """
93 sigin = create_noise(hop_s)95 sigin = create_noise(hop_s)
94 self.reconstruction(sigin, hop_s, ratio)96 self.reconstruction(sigin, hop_s, ratio)
95 97
96 @params(98 resynth_sine_args = "samplerate, hop_s, ratio, freq"
99 resynth_sine_values = [
97 (44100, 256, 8, 441),100 (44100, 256, 8, 441),
98 (44100, 256, 4, 1203),101 (44100, 256, 4, 1203),
99 (44100, 256, 2, 3045),102 (44100, 256, 2, 3045),
@@ -108,7 +111,9 @@ class aubio_pvoc_test_case(TestCase): · 8 unmodified lines
108 (22050, 256, 8, 445),111 (22050, 256, 8, 445),
109 (96000, 1024, 8, 47000),112 (96000, 1024, 8, 47000),
110 (96000, 1024, 8, 20),113 (96000, 1024, 8, 20),
111 )114 ]
115
116 @parametrize(resynth_sine_args, resynth_sine_values)
112 def test_resynth_steps_sine(self, samplerate, hop_s, ratio, freq):117 def test_resynth_steps_sine(self, samplerate, hop_s, ratio, freq):
113 """ check the resynthesis of a sine is correct """118 """ check the resynthesis of a sine is correct """
114 sigin = create_sine(hop_s, freq, samplerate)119 sigin = create_sine(hop_s, freq, samplerate)
@@ -199,5 +204,5 @@ class aubio_pvoc_wrong_params(TestCase): · 84 unmodified lines
199 self.skipTest('creating aubio.pvoc with size %d did not fail' % win_s)204 self.skipTest('creating aubio.pvoc with size %d did not fail' % win_s)
200 205
201if __name__ == '__main__':206if __name__ == '__main__':
207 from unittest import main
202 main()208 main()
203
python/tests/test_pitch.py+5−5
@@ -1,7 +1,6 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import TestCase, main3from numpy.testing import TestCase, assert_equal
4from numpy.testing import assert_equal
5from numpy import sin, arange, mean, median, isnan, pi4from numpy import sin, arange, mean, median, isnan, pi
6from aubio import fvec, pitch, freqtomidi, float_type5from aubio import fvec, pitch, freqtomidi, float_type
7 6
@@ -116,10 +115,11 @@ def create_test (algo, mode): · 108 unmodified lines
116 115
117for algo in pitch_algorithms:116for algo in pitch_algorithms:
118 for mode in signal_modes:117 for mode in signal_modes:
119 test_method = create_test (algo, mode)118 _test_method = create_test (algo, mode)
120 test_method.__name__ = 'test_pitch_%s_%d_%d_%dHz_sin_%.0f' % ( algo,119 _test_method.__name__ = 'test_pitch_%s_%d_%d_%dHz_sin_%.0f' % ( algo,
121 mode[0], mode[1], mode[2], mode[3] )120 mode[0], mode[1], mode[2], mode[3] )
122 setattr (aubio_pitch_Sinusoid, test_method.__name__, test_method)121 setattr (aubio_pitch_Sinusoid, _test_method.__name__, _test_method)
123 122
124if __name__ == '__main__':123if __name__ == '__main__':
124 from unittest import main
125 main()125 main()
python/tests/test_sink.py+16−22
@@ -1,13 +1,9 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from nose2 import main
4from nose2.tools import params
5from numpy.testing import TestCase3from numpy.testing import TestCase
6from aubio import fvec, source, sink4from aubio import fvec, source, sink
7from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path5from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
8 6from _tools import parametrize, skipTest, assert_raises
9import warnings
10warnings.filterwarnings('ignore', category=UserWarning, append=True)
11 7
12list_of_sounds = list_all_sounds('sounds')8list_of_sounds = list_all_sounds('sounds')
13samplerates = [0, 44100, 8000, 32000]9samplerates = [0, 44100, 8000, 32000]
@@ -23,30 +19,26 @@ for soundfile in list_of_sounds: · 9 unmodified lines
23 for samplerate in samplerates:19 for samplerate in samplerates:
24 all_params.append((hop_size, samplerate, soundfile))20 all_params.append((hop_size, samplerate, soundfile))
25 21
26class aubio_sink_test_case(TestCase):22class Test_aubio_sink(object):
27
28 def setUp(self):
29 if not len(list_of_sounds):
30 self.skipTest('add some sound files in \'python/tests/sounds\'')
31 23
32 def test_wrong_filename(self):24 def test_wrong_filename(self):
33 with self.assertRaises(RuntimeError):25 with assert_raises(RuntimeError):
34 sink('')26 sink('')
35 27
36 def test_wrong_samplerate(self):28 def test_wrong_samplerate(self):
37 with self.assertRaises(RuntimeError):29 with assert_raises(RuntimeError):
38 sink(get_tmp_sink_path(), -1)30 sink(get_tmp_sink_path(), -1)
39 31
40 def test_wrong_samplerate_too_large(self):32 def test_wrong_samplerate_too_large(self):
41 with self.assertRaises(RuntimeError):33 with assert_raises(RuntimeError):
42 sink(get_tmp_sink_path(), 1536001, 2)34 sink(get_tmp_sink_path(), 1536001, 2)
43 35
44 def test_wrong_channels(self):36 def test_wrong_channels(self):
45 with self.assertRaises(RuntimeError):37 with assert_raises(RuntimeError):
46 sink(get_tmp_sink_path(), 44100, -1)38 sink(get_tmp_sink_path(), 44100, -1)
47 39
48 def test_wrong_channels_too_large(self):40 def test_wrong_channels_too_large(self):
49 with self.assertRaises(RuntimeError):41 with assert_raises(RuntimeError):
50 sink(get_tmp_sink_path(), 44100, 202020)42 sink(get_tmp_sink_path(), 44100, 202020)
51 43
52 def test_many_sinks(self):44 def test_many_sinks(self):
@@ -66,13 +58,13 @@ class aubio_sink_test_case(TestCase): · 13 unmodified lines
66 g.close()58 g.close()
67 shutil.rmtree(tmpdir)59 shutil.rmtree(tmpdir)
68 60
69 @params(*all_params)61 @parametrize('hop_size, samplerate, path', all_params)
70 def test_read_and_write(self, hop_size, samplerate, path):62 def test_read_and_write(self, hop_size, samplerate, path):
71
72 try:63 try:
73 f = source(path, samplerate, hop_size)64 f = source(path, samplerate, hop_size)
74 except RuntimeError as e:65 except RuntimeError as e:
75 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))66 err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
67 skipTest(err_msg.format(str(e), hop_size, samplerate))
76 if samplerate == 0: samplerate = f.samplerate68 if samplerate == 0: samplerate = f.samplerate
77 sink_path = get_tmp_sink_path()69 sink_path = get_tmp_sink_path()
78 g = sink(sink_path, samplerate)70 g = sink(sink_path, samplerate)
@@ -84,12 +76,13 @@ class aubio_sink_test_case(TestCase): · 5 unmodified lines
84 if read < f.hop_size: break76 if read < f.hop_size: break
85 del_tmp_sink_path(sink_path)77 del_tmp_sink_path(sink_path)
86 78
87 @params(*all_params)79 @parametrize('hop_size, samplerate, path', all_params)
88 def test_read_and_write_multi(self, hop_size, samplerate, path):80 def test_read_and_write_multi(self, hop_size, samplerate, path):
89 try:81 try:
90 f = source(path, samplerate, hop_size)82 f = source(path, samplerate, hop_size)
91 except RuntimeError as e:83 except RuntimeError as e:
92 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))84 err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
85 skipTest(err_msg.format(str(e), hop_size, samplerate))
93 if samplerate == 0: samplerate = f.samplerate86 if samplerate == 0: samplerate = f.samplerate
94 sink_path = get_tmp_sink_path()87 sink_path = get_tmp_sink_path()
95 g = sink(sink_path, samplerate, channels = f.channels)88 g = sink(sink_path, samplerate, channels = f.channels)
@@ -125,4 +118,5 @@ class aubio_sink_test_case(TestCase): · 29 unmodified lines
125 g(vec, 128)118 g(vec, 128)
126 119
127if __name__ == '__main__':120if __name__ == '__main__':
128 main()121 from _tools import run_module_suite
122 run_module_suite()
python/tests/test_slicing.py+3−3
@@ -1,10 +1,9 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main
4from numpy.testing import TestCase, assert_equal3from numpy.testing import TestCase, assert_equal
5from aubio import slice_source_at_stamps4from aubio import slice_source_at_stamps
6from .utils import count_files_in_directory, get_default_test_sound5from utils import count_files_in_directory, get_default_test_sound
7from .utils import count_samples_in_directory, count_samples_in_file6from utils import count_samples_in_directory, count_samples_in_file
8 7
9import tempfile8import tempfile
10import shutil9import shutil
@@ -167,4 +166,5 @@ class aubio_slicing_wrong_ends_test_case(TestCase): · 156 unmodified lines
167 shutil.rmtree(self.output_dir)166 shutil.rmtree(self.output_dir)
168 167
169if __name__ == '__main__':168if __name__ == '__main__':
169 from unittest import main
170 main()170 main()
python/tests/test_source.py+56−53
@@ -1,19 +1,17 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from nose2 import main3
4from nose2.tools import params
5from numpy.testing import TestCase, assert_equal4from numpy.testing import TestCase, assert_equal
6from aubio import source5from aubio import source
7from .utils import list_all_sounds6from utils import list_all_sounds
8 7import unittest
9import warnings8from _tools import parametrize, assert_raises, assert_equal, skipTest
10warnings.filterwarnings('ignore', category=UserWarning, append=True)
11 9
12list_of_sounds = list_all_sounds('sounds')10list_of_sounds = list_all_sounds('sounds')
13samplerates = [0, 44100, 8000, 32000]11samplerates = [0, 44100, 8000, 32000]
14hop_sizes = [512, 1024, 64]12hop_sizes = [512, 1024, 64]
15 13
16path = None14default_test_sound = len(list_of_sounds) and list_of_sounds[0] or None
17 15
18all_params = []16all_params = []
19for soundfile in list_of_sounds:17for soundfile in list_of_sounds:
@@ -21,24 +19,20 @@ for soundfile in list_of_sounds: · 1 unmodified line
21 for samplerate in samplerates:19 for samplerate in samplerates:
22 all_params.append((hop_size, samplerate, soundfile))20 all_params.append((hop_size, samplerate, soundfile))
23 21
22no_sounds_msg = "no test sounds, add some in 'python/tests/sounds/'!"
24 23
25class aubio_source_test_case_base(TestCase):24_debug = False
26
27 def setUp(self):
28 if not len(list_of_sounds):
29 self.skipTest('add some sound files in \'python/tests/sounds\'')
30 self.default_test_sound = list_of_sounds[0]
31 25
32class aubio_source_test_case(aubio_source_test_case_base):26class Test_aubio_source_test_case(object):
33 27
34 @params(*list_of_sounds)28 @parametrize('filename', list_of_sounds)
35 def test_close_file(self, filename):29 def test_close_file(self, filename):
36 samplerate = 0 # use native samplerate30 samplerate = 0 # use native samplerate
37 hop_size = 25631 hop_size = 256
38 f = source(filename, samplerate, hop_size)32 f = source(filename, samplerate, hop_size)
39 f.close()33 f.close()
40 34
41 @params(*list_of_sounds)35 @parametrize('filename', list_of_sounds)
42 def test_close_file_twice(self, filename):36 def test_close_file_twice(self, filename):
43 samplerate = 0 # use native samplerate37 samplerate = 0 # use native samplerate
44 hop_size = 25638 hop_size = 256
@@ -46,7 +40,7 @@ class aubio_source_test_case(aubio_source_test_case_base): · 1 unmodified line
46 f.close()40 f.close()
47 f.close()41 f.close()
48 42
49class aubio_source_read_test_case(aubio_source_test_case_base):43class Test_aubio_source_read(object):
50 44
51 def read_from_source(self, f):45 def read_from_source(self, f):
52 total_frames = 046 total_frames = 0
@@ -56,47 +50,51 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 3 unmodified lines
56 if read < f.hop_size:50 if read < f.hop_size:
57 assert_equal(samples[read:], 0)51 assert_equal(samples[read:], 0)
58 break52 break
59 #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"53 if _debug:
60 #result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri54 result_str = "read {:.2f}s ({:d} frames"
61 #print (result_str.format(*result_params))55 result_str += " in {:d} blocks at {:d}Hz) from {:s}"
56 result_params = total_frames / float(f.samplerate), total_frames, \
57 total_frames//f.hop_size, f.samplerate, f.uri
58 print (result_str.format(*result_params))
62 return total_frames59 return total_frames
63 60
64 @params(*all_params)61 @parametrize('hop_size, samplerate, soundfile', all_params)
65 def test_samplerate_hopsize(self, hop_size, samplerate, soundfile):62 def test_samplerate_hopsize(self, hop_size, samplerate, soundfile):
66 try:63 try:
67 f = source(soundfile, samplerate, hop_size)64 f = source(soundfile, samplerate, hop_size)
68 except RuntimeError as e:65 except RuntimeError as e:
69 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))66 err_msg = 'failed opening with hop_s={:d}, samplerate={:d} ({:s})'
67 skipTest(err_msg.format(hop_size, samplerate, str(e)))
70 assert f.samplerate != 068 assert f.samplerate != 0
71 read_frames = self.read_from_source(f)69 read_frames = self.read_from_source(f)
72 if 'f_' in soundfile and samplerate == 0:70 if 'f_' in soundfile and samplerate == 0:
73 import re71 import re
74 f = re.compile('.*_\([0:9]*f\)_.*')72 f = re.compile(r'.*_\([0:9]*f\)_.*')
75 match_f = re.findall('([0-9]*)f_', soundfile)73 match_f = re.findall('([0-9]*)f_', soundfile)
76 if len(match_f) == 1:74 if len(match_f) == 1:
77 expected_frames = int(match_f[0])75 expected_frames = int(match_f[0])
78 self.assertEqual(expected_frames, read_frames)76 assert_equal(expected_frames, read_frames)
79 77
80 @params(*list_of_sounds)78 @parametrize('p', list_of_sounds)
81 def test_samplerate_none(self, p):79 def test_samplerate_none(self, p):
82 f = source(p)80 f = source(p)
83 assert f.samplerate != 081 assert f.samplerate != 0
84 self.read_from_source(f)82 self.read_from_source(f)
85 83
86 @params(*list_of_sounds)84 @parametrize('p', list_of_sounds)
87 def test_samplerate_0(self, p):85 def test_samplerate_0(self, p):
88 f = source(p, 0)86 f = source(p, 0)
89 assert f.samplerate != 087 assert f.samplerate != 0
90 self.read_from_source(f)88 self.read_from_source(f)
91 89
92 @params(*list_of_sounds)90 @parametrize('p', list_of_sounds)
93 def test_zero_hop_size(self, p):91 def test_zero_hop_size(self, p):
94 f = source(p, 0, 0)92 f = source(p, 0, 0)
95 assert f.samplerate != 093 assert f.samplerate != 0
96 assert f.hop_size != 094 assert f.hop_size != 0
97 self.read_from_source(f)95 self.read_from_source(f)
98 96
99 @params(*list_of_sounds)97 @parametrize('p', list_of_sounds)
100 def test_seek_to_half(self, p):98 def test_seek_to_half(self, p):
101 from random import randint99 from random import randint
102 f = source(p, 0, 0)100 f = source(p, 0, 0)
@@ -108,7 +106,7 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 5 unmodified lines
108 b = self.read_from_source(f)106 b = self.read_from_source(f)
109 assert a == b + c107 assert a == b + c
110 108
111 @params(*list_of_sounds)109 @parametrize('p', list_of_sounds)
112 def test_duration(self, p):110 def test_duration(self, p):
113 total_frames = 0111 total_frames = 0
114 f = source(p)112 f = source(p)
@@ -117,43 +115,44 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 2 unmodified lines
117 _, read = f()115 _, read = f()
118 total_frames += read116 total_frames += read
119 if read < f.hop_size: break117 if read < f.hop_size: break
120 self.assertEqual(duration, total_frames)118 assert_equal (duration, total_frames)
121 119
122 120
123class aubio_source_test_wrong_params(TestCase):121class Test_aubio_source_wrong_params(object):
124 122
125 def test_wrong_file(self):123 def test_wrong_file(self):
126 with self.assertRaises(RuntimeError):124 with assert_raises(RuntimeError):
127 source('path_to/unexisting file.mp3')125 source('path_to/unexisting file.mp3')
128 126
129class aubio_source_test_wrong_params_with_file(aubio_source_test_case_base):127@unittest.skipIf(default_test_sound is None, no_sounds_msg)
128class Test_aubio_source_wrong_params_with_file(TestCase):
130 129
131 def test_wrong_samplerate(self):130 def test_wrong_samplerate(self):
132 with self.assertRaises(ValueError):131 with assert_raises(ValueError):
133 source(self.default_test_sound, -1)132 source(default_test_sound, -1)
134 133
135 def test_wrong_hop_size(self):134 def test_wrong_hop_size(self):
136 with self.assertRaises(ValueError):135 with assert_raises(ValueError):
137 source(self.default_test_sound, 0, -1)136 source(default_test_sound, 0, -1)
138 137
139 def test_wrong_channels(self):138 def test_wrong_channels(self):
140 with self.assertRaises(ValueError):139 with assert_raises(ValueError):
141 source(self.default_test_sound, 0, 0, -1)140 source(default_test_sound, 0, 0, -1)
142 141
143 def test_wrong_seek(self):142 def test_wrong_seek(self):
144 f = source(self.default_test_sound)143 f = source(default_test_sound)
145 with self.assertRaises(ValueError):144 with assert_raises(ValueError):
146 f.seek(-1)145 f.seek(-1)
147 146
148 def test_wrong_seek_too_large(self):147 def test_wrong_seek_too_large(self):
149 f = source(self.default_test_sound)148 f = source(default_test_sound)
150 try:149 try:
151 with self.assertRaises(ValueError):150 with assert_raises(ValueError):
152 f.seek(f.duration + f.samplerate * 10)151 f.seek(f.duration + f.samplerate * 10)
153 except AssertionError:152 except:
154 self.skipTest('seeking after end of stream failed raising ValueError')153 skipTest('seeking after end of stream failed raising ValueError')
155 154
156class aubio_source_readmulti_test_case(aubio_source_read_test_case):155class Test_aubio_source_readmulti(Test_aubio_source_read):
157 156
158 def read_from_source(self, f):157 def read_from_source(self, f):
159 total_frames = 0158 total_frames = 0
@@ -163,15 +162,18 @@ class aubio_source_readmulti_test_case(aubio_source_read_test_case): · 3 unmodified lines
163 if read < f.hop_size:162 if read < f.hop_size:
164 assert_equal(samples[:,read:], 0)163 assert_equal(samples[:,read:], 0)
165 break164 break
166 #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"165 if _debug:
167 #result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri166 result_str = "read {:.2f}s ({:d} frames in {:d} channels"
168 #print (result_str.format(*result_params))167 result_str += " and {:d} blocks at {:d}Hz) from {:s}"
168 result_params = total_frames / float(f.samplerate), total_frames, \
169 f.channels, int(total_frames/f.hop_size), \
170 f.samplerate, f.uri
171 print (result_str.format(*result_params))
169 return total_frames172 return total_frames
170 173
171class aubio_source_with(aubio_source_test_case_base):174class Test_aubio_source_with(object):
172 175
173 #@params(*list_of_sounds)176 @parametrize('filename', list_of_sounds)
174 @params(*list_of_sounds)
175 def test_read_from_mono(self, filename):177 def test_read_from_mono(self, filename):
176 total_frames = 0178 total_frames = 0
177 hop_size = 2048179 hop_size = 2048
@@ -185,4 +187,5 @@ class aubio_source_with(aubio_source_test_case_base): · 7 unmodified lines
185 assert_equal(total_frames, input_source.duration)187 assert_equal(total_frames, input_source.duration)
186 188
187if __name__ == '__main__':189if __name__ == '__main__':
188 main()190 from _tools import run_module_suite
191 run_module_suite()
python/tests/test_source_channels.py+1−1
@@ -8,7 +8,7 @@ import unittest · 7 unmodified lines
8import aubio8import aubio
9import numpy as np9import numpy as np
10from numpy.testing import assert_equal10from numpy.testing import assert_equal
11from .utils import get_tmp_sink_path11from utils import get_tmp_sink_path
12 12
13class aubio_source_test_case(unittest.TestCase):13class aubio_source_test_case(unittest.TestCase):
14 14
python/tests/test_specdesc.py+1−1
@@ -1,6 +1,5 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main
4from numpy.testing import TestCase, assert_equal, assert_almost_equal3from numpy.testing import TestCase, assert_equal, assert_almost_equal
5from numpy import random, arange, log, zeros4from numpy import random, arange, log, zeros
6from aubio import specdesc, cvec, float_type5from aubio import specdesc, cvec, float_type
@@ -229,4 +228,5 @@ class aubio_specdesc_wrong(TestCase): · 222 unmodified lines
229 specdesc("unknown", 512)228 specdesc("unknown", 512)
230 229
231if __name__ == '__main__':230if __name__ == '__main__':
231 from unittest import main
232 main()232 main()
python/tests/test_zero_crossing_rate.py+1−1
@@ -1,6 +1,5 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main
4from numpy.testing import TestCase3from numpy.testing import TestCase
5from aubio import fvec, zero_crossing_rate4from aubio import fvec, zero_crossing_rate
6 5
@@ -43,4 +42,5 @@ class zero_crossing_rate_test_case(TestCase): · 36 unmodified lines
43 self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))42 self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
44 43
45if __name__ == '__main__':44if __name__ == '__main__':
45 from unittest import main
46 main()46 main()
python/tests/utils.py+6−12
@@ -8,11 +8,8 @@ from tempfile import mkstemp · 7 unmodified lines
8DEFAULT_SOUND = '22050Hz_5s_brownnoise.wav'8DEFAULT_SOUND = '22050Hz_5s_brownnoise.wav'
9 9
10def array_from_text_file(filename, dtype = 'float'):10def array_from_text_file(filename, dtype = 'float'):
11 filename = os.path.join(os.path.dirname(__file__), filename)11 realpathname = os.path.join(os.path.dirname(__file__), filename)
12 with open(filename) as f:12 return np.loadtxt(realpathname, dtype = dtype)
13 lines = f.readlines()
14 return np.array([line.split() for line in lines],
15 dtype = dtype)
16 13
17def list_all_sounds(rel_dir):14def list_all_sounds(rel_dir):
18 datadir = os.path.join(os.path.dirname(__file__), rel_dir)15 datadir = os.path.join(os.path.dirname(__file__), rel_dir)
@@ -38,13 +35,10 @@ def del_tmp_sink_path(path): · 19 unmodified lines
38 try:35 try:
39 os.unlink(path)36 os.unlink(path)
40 except WindowsError as e:37 except WindowsError as e:
41 print("deleting {:s} failed ({:s}), reopening".format(path, repr(e)))38 # removing the temporary directory sometimes fails on windows
42 with open(path, 'wb') as f:39 import warnings
43 f.close()40 errmsg = "failed deleting temporary file {:s} ({:s})"
44 try:41 warnings.warn(UserWarning(errmsg.format(path, repr(e))))
45 os.unlink(path)
46 except WindowsError as f:
47 print("deleting {:s} failed ({:s}), aborting".format(path, repr(e)))
48 42
49def array_from_yaml_file(filename):43def array_from_yaml_file(filename):
50 import yaml44 import yaml
requirements.txt+1−1
@@ -1,2 +1,2 @@
1numpy1numpy
2nose22pytest
setup.py+0−4
@@ -95,8 +95,4 @@ distrib = setup(name='aubio', · 94 unmodified lines
95 'aubiocut = aubio.cut:main',95 'aubiocut = aubio.cut:main',
96 ],96 ],
97 },97 },
98 test_suite = 'nose2.collector.collector',
99 extras_require = {
100 'tests': ['numpy'],
101 },
102 )98 )
src/io/sink_apple_audio.c+34−8
@@ -31,9 +31,7 @@ · 30 unmodified lines
31// ExtAudioFileRef, AudioStreamBasicDescription, AudioBufferList, ...31// ExtAudioFileRef, AudioStreamBasicDescription, AudioBufferList, ...
32#include <AudioToolbox/AudioToolbox.h>32#include <AudioToolbox/AudioToolbox.h>
33 33
34#define FLOAT_TO_SHORT(x) (short)(x * 32768)34extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
35
36extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
37extern void freeAudioBufferList(AudioBufferList *bufferList);35extern void freeAudioBufferList(AudioBufferList *bufferList);
38extern CFURLRef createURLFromPath(const char * path);36extern CFURLRef createURLFromPath(const char * path);
39char_t *getPrintableOSStatusError(char_t *str, OSStatus error);37char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
@@ -76,6 +74,7 @@ aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(const char_t * uri, uint_t · 36 unmodified lines
76 if ((sint_t)samplerate == 0) {74 if ((sint_t)samplerate == 0) {
77 return s;75 return s;
78 }76 }
77
79 // invalid samplerate given, abort78 // invalid samplerate given, abort
80 if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {79 if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
81 goto beach;80 goto beach;
@@ -150,6 +149,18 @@ uint_t aubio_sink_apple_audio_open(aubio_sink_apple_audio_t *s) { · 68 unmodified lines
150 AudioFileTypeID fileType = kAudioFileWAVEType;149 AudioFileTypeID fileType = kAudioFileWAVEType;
151 CFURLRef fileURL = createURLFromPath(s->path);150 CFURLRef fileURL = createURLFromPath(s->path);
152 bool overwrite = true;151 bool overwrite = true;
152
153 // set the in-memory format
154 AudioStreamBasicDescription inputFormat;
155 memset(&inputFormat, 0, sizeof(AudioStreamBasicDescription));
156 inputFormat.mFormatID = kAudioFormatLinearPCM;
157 inputFormat.mSampleRate = (Float64)(s->samplerate);
158 inputFormat.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked;
159 inputFormat.mChannelsPerFrame = s->channels;
160 inputFormat.mBitsPerChannel = sizeof(smpl_t) * 8;
161 inputFormat.mFramesPerPacket = 1;
162 inputFormat.mBytesPerFrame = inputFormat.mBitsPerChannel * inputFormat.mChannelsPerFrame / 8;
163 inputFormat.mBytesPerPacket = inputFormat.mFramesPerPacket * inputFormat.mBytesPerFrame;
153 OSStatus err = noErr;164 OSStatus err = noErr;
154 err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL,165 err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL,
155 overwrite ? kAudioFileFlags_EraseFile : 0, &s->audioFile);166 overwrite ? kAudioFileFlags_EraseFile : 0, &s->audioFile);
@@ -161,7 +172,18 @@ uint_t aubio_sink_apple_audio_open(aubio_sink_apple_audio_t *s) { · 5 unmodified lines
161 getPrintableOSStatusError(errorstr, err));172 getPrintableOSStatusError(errorstr, err));
162 goto beach;173 goto beach;
163 }174 }
164 if (createAubioBufferList(&s->bufferList, s->channels, s->max_frames * s->channels)) {175
176 err = ExtAudioFileSetProperty(s->audioFile,
177 kExtAudioFileProperty_ClientDataFormat,
178 sizeof(AudioStreamBasicDescription), &inputFormat);
179 if (err) {
180 char_t errorstr[20];
181 AUBIO_ERR("sink_apple_audio: error when trying to set output format on %s "
182 "(%s)\n", s->path, getPrintableOSStatusError(errorstr, err));
183 goto beach;
184 }
185
186 if (createAudioBufferList(&s->bufferList, s->channels, s->max_frames * s->channels)) {
165 AUBIO_ERR("sink_apple_audio: error when creating buffer list for %s, "187 AUBIO_ERR("sink_apple_audio: error when creating buffer list for %s, "
166 "out of memory? \n", s->path);188 "out of memory? \n", s->path);
167 goto beach;189 goto beach;
@@ -174,13 +196,13 @@ beach: · 6 unmodified lines
174 196
175void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) {197void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) {
176 UInt32 c, v;198 UInt32 c, v;
177 short *data = (short*)s->bufferList.mBuffers[0].mData;199 smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
178 uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,200 uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,
179 s->max_frames, write_data->length, write);201 s->max_frames, write_data->length, write);
180 202
181 for (c = 0; c < s->channels; c++) {203 for (c = 0; c < s->channels; c++) {
182 for (v = 0; v < length; v++) {204 for (v = 0; v < length; v++) {
183 data[v * s->channels + c] = FLOAT_TO_SHORT(write_data->data[v]);205 data[v * s->channels + c] = write_data->data[v];
184 }206 }
185 }207 }
186 208
@@ -189,7 +211,7 @@ void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data · 2 unmodified lines
189 211
190void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) {212void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) {
191 UInt32 c, v;213 UInt32 c, v;
192 short *data = (short*)s->bufferList.mBuffers[0].mData;214 smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
193 uint_t channels = aubio_sink_validate_input_channels("sink_apple_audio",215 uint_t channels = aubio_sink_validate_input_channels("sink_apple_audio",
194 s->path, s->channels, write_data->height);216 s->path, s->channels, write_data->height);
195 uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,217 uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,
@@ -197,7 +219,7 @@ void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * writ · 1 unmodified line
197 219
198 for (c = 0; c < channels; c++) {220 for (c = 0; c < channels; c++) {
199 for (v = 0; v < length; v++) {221 for (v = 0; v < length; v++) {
200 data[v * s->channels + c] = FLOAT_TO_SHORT(write_data->data[c][v]);222 data[v * s->channels + c] = write_data->data[c][v];
201 }223 }
202 }224 }
203 225
@@ -206,6 +228,10 @@ void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * writ · 2 unmodified lines
206 228
207void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) {229void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) {
208 OSStatus err = noErr;230 OSStatus err = noErr;
231 // set mDataByteSize to match the number of frames to be written
232 // see https://www.mail-archive.com/coreaudio-api@lists.apple.com/msg01109.html
233 s->bufferList.mBuffers[0].mDataByteSize = write * s->channels
234 * sizeof(smpl_t);
209 if (s->async) {235 if (s->async) {
210 err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);236 err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
211 if (err) {237 if (err) {
src/io/source_apple_audio.c+27−41
@@ -34,8 +34,6 @@ · 33 unmodified lines
34#define RT_BYTE3( a ) ( ((a) >> 16) & 0xff )34#define RT_BYTE3( a ) ( ((a) >> 16) & 0xff )
35#define RT_BYTE4( a ) ( ((a) >> 24) & 0xff )35#define RT_BYTE4( a ) ( ((a) >> 24) & 0xff )
36 36
37#define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
38
39struct _aubio_source_apple_audio_t {37struct _aubio_source_apple_audio_t {
40 uint_t channels;38 uint_t channels;
41 uint_t samplerate; //< requested samplerate39 uint_t samplerate; //< requested samplerate
@@ -48,7 +46,7 @@ struct _aubio_source_apple_audio_t { · 6 unmodified lines
48 AudioBufferList bufferList;46 AudioBufferList bufferList;
49};47};
50 48
51extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);49extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
52extern void freeAudioBufferList(AudioBufferList *bufferList);50extern void freeAudioBufferList(AudioBufferList *bufferList);
53extern CFURLRef createURLFromPath(const char * path);51extern CFURLRef createURLFromPath(const char * path);
54char_t *getPrintableOSStatusError(char_t *str, OSStatus error);52char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
@@ -138,17 +136,16 @@ uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, const char_ · 83 unmodified lines
138 s->channels = fileFormat.mChannelsPerFrame;136 s->channels = fileFormat.mChannelsPerFrame;
139 137
140 AudioStreamBasicDescription clientFormat;138 AudioStreamBasicDescription clientFormat;
141 propSize = sizeof(clientFormat);139 propSize = sizeof(AudioStreamBasicDescription);
142 memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription));140 memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription));
143 clientFormat.mFormatID = kAudioFormatLinearPCM;141 clientFormat.mFormatID = kAudioFormatLinearPCM;
144 clientFormat.mSampleRate = (Float64)(s->samplerate);142 clientFormat.mSampleRate = (Float64)(s->samplerate);
145 clientFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;143 clientFormat.mFormatFlags = kAudioFormatFlagIsFloat;
146 clientFormat.mChannelsPerFrame = s->channels;144 clientFormat.mChannelsPerFrame = s->channels;
147 clientFormat.mBitsPerChannel = sizeof(short) * 8;145 clientFormat.mBitsPerChannel = sizeof(smpl_t) * 8;
148 clientFormat.mFramesPerPacket = 1;146 clientFormat.mFramesPerPacket = 1;
149 clientFormat.mBytesPerFrame = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8;147 clientFormat.mBytesPerFrame = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8;
150 clientFormat.mBytesPerPacket = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame;148 clientFormat.mBytesPerPacket = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame;
151 clientFormat.mReserved = 0;
152 149
153 // set the client format description150 // set the client format description
154 err = ExtAudioFileSetProperty(s->audioFile, kExtAudioFileProperty_ClientDataFormat,151 err = ExtAudioFileSetProperty(s->audioFile, kExtAudioFileProperty_ClientDataFormat,
@@ -186,7 +183,7 @@ uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, const char_ · 31 unmodified lines
186 183
187 // allocate the AudioBufferList184 // allocate the AudioBufferList
188 freeAudioBufferList(&s->bufferList);185 freeAudioBufferList(&s->bufferList);
189 if (createAubioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {186 if (createAudioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {
190 AUBIO_ERR("source_apple_audio: failed creating bufferList\n");187 AUBIO_ERR("source_apple_audio: failed creating bufferList\n");
191 goto beach;188 goto beach;
192 }189 }
@@ -195,60 +192,51 @@ beach: · 2 unmodified lines
195 return err;192 return err;
196}193}
197 194
198void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to, uint_t * read) {195static UInt32 aubio_source_apple_audio_read_frame(aubio_source_apple_audio_t *s)
199 UInt32 c, v, loadedPackets = s->block_size;196{
197 UInt32 loadedPackets = s->block_size;
200 OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);198 OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
201 if (err) {199 if (err) {
202 char_t errorstr[20];200 char_t errorstr[20];
203 AUBIO_ERROR("source_apple_audio: error while reading %s "201 AUBIO_ERROR("source_apple_audio: error while reading %s "
204 "with ExtAudioFileRead (%s)\n", s->path,202 "with ExtAudioFileRead (%s)\n", s->path,
205 getPrintableOSStatusError(errorstr, err));203 getPrintableOSStatusError(errorstr, err));
206 goto beach;
207 }204 }
205 return loadedPackets;
206}
208 207
209 short *data = (short*)s->bufferList.mBuffers[0].mData;208void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to,
210 209 uint_t * read) {
211 smpl_t *buf = read_to->data;210 uint_t c, v;
211 UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
212 smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
212 213
213 for (v = 0; v < loadedPackets; v++) {214 for (v = 0; v < loadedPackets; v++) {
214 buf[v] = 0.;215 read_to->data[v] = 0.;
215 for (c = 0; c < s->channels; c++) {216 for (c = 0; c < s->channels; c++) {
216 buf[v] += SHORT_TO_FLOAT(data[ v * s->channels + c]);217 read_to->data[v] += data[ v * s->channels + c];
217 }218 }
218 buf[v] /= (smpl_t)s->channels;219 read_to->data[v] /= (smpl_t)s->channels;
219 }220 }
220 // short read, fill with zeros221 // short read, fill with zeros
221 if (loadedPackets < s->block_size) {222 if (loadedPackets < s->block_size) {
222 for (v = loadedPackets; v < s->block_size; v++) {223 for (v = loadedPackets; v < s->block_size; v++) {
223 buf[v] = 0.;224 read_to->data[v] = 0.;
224 }225 }
225 }226 }
226 227
227 *read = (uint_t)loadedPackets;228 *read = (uint_t)loadedPackets;
228 return;229 return;
229beach:
230 *read = 0;
231 return;
232}230}
233 231
234void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) {232void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) {
235 UInt32 c, v, loadedPackets = s->block_size;233 uint_t c, v;
236 OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);234 UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
237 if (err) {235 smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
238 char_t errorstr[20];
239 AUBIO_ERROR("source_apple_audio: error while reading %s "
240 "with ExtAudioFileRead (%s)\n", s->path,
241 getPrintableOSStatusError(errorstr, err));
242 goto beach;
243 }
244
245 short *data = (short*)s->bufferList.mBuffers[0].mData;
246
247 smpl_t **buf = read_to->data;
248 236
249 for (v = 0; v < loadedPackets; v++) {237 for (v = 0; v < loadedPackets; v++) {
250 for (c = 0; c < read_to->height; c++) {238 for (c = 0; c < read_to->height; c++) {
251 buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + c]);239 read_to->data[c][v] = data[ v * s->channels + c];
252 }240 }
253 }241 }
254 // if read_data has more channels than the file242 // if read_data has more channels than the file
@@ -256,7 +244,7 @@ void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * r · 1 unmodified line
256 // copy last channel to all additional channels244 // copy last channel to all additional channels
257 for (v = 0; v < loadedPackets; v++) {245 for (v = 0; v < loadedPackets; v++) {
258 for (c = s->channels; c < read_to->height; c++) {246 for (c = s->channels; c < read_to->height; c++) {
259 buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + (s->channels - 1)]);247 read_to->data[c][v] = data[ v * s->channels + (s->channels - 1)];
260 }248 }
261 }249 }
262 }250 }
@@ -264,15 +252,13 @@ void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * r · 1 unmodified line
264 if (loadedPackets < s->block_size) {252 if (loadedPackets < s->block_size) {
265 for (v = loadedPackets; v < s->block_size; v++) {253 for (v = loadedPackets; v < s->block_size; v++) {
266 for (c = 0; c < read_to->height; c++) {254 for (c = 0; c < read_to->height; c++) {
267 buf[c][v] = 0.;255 read_to->data[c][v] = 0.;
268 }256 }
269 }257 }
270 }258 }
259
271 *read = (uint_t)loadedPackets;260 *read = (uint_t)loadedPackets;
272 return;261 return;
273beach:
274 *read = 0;
275 return;
276}262}
277 263
278uint_t aubio_source_apple_audio_close (aubio_source_apple_audio_t *s)264uint_t aubio_source_apple_audio_close (aubio_source_apple_audio_t *s)
@@ -322,7 +308,7 @@ uint_t aubio_source_apple_audio_seek (aubio_source_apple_audio_t * s, uint_t pos · 43 unmodified lines
322 }308 }
323 // after a short read, the bufferList size needs to resetted to prepare for a full read309 // after a short read, the bufferList size needs to resetted to prepare for a full read
324 AudioBufferList *bufferList = &s->bufferList;310 AudioBufferList *bufferList = &s->bufferList;
325 bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (short);311 bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (smpl_t);
326 // do the actual seek312 // do the actual seek
327 err = ExtAudioFileSeek(s->audioFile, resampled_pos);313 err = ExtAudioFileSeek(s->audioFile, resampled_pos);
328 if (err) {314 if (err) {
src/io/utils_apple_audio.c+4−3
@@ -12,11 +12,12 @@ void freeAudioBufferList(AudioBufferList *bufferList); · 11 unmodified lines
12CFURLRef getURLFromPath(const char * path);12CFURLRef getURLFromPath(const char * path);
13char_t *getPrintableOSStatusError(char_t *str, OSStatus error);13char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
14 14
15int createAubioBufferList(AudioBufferList * bufferList, int channels, int max_source_samples) {15int createAudioBufferList(AudioBufferList * bufferList, int channels,
16 int max_source_samples) {
16 bufferList->mNumberBuffers = 1;17 bufferList->mNumberBuffers = 1;
17 bufferList->mBuffers[0].mNumberChannels = channels;18 bufferList->mBuffers[0].mNumberChannels = channels;
18 bufferList->mBuffers[0].mData = AUBIO_ARRAY(short, max_source_samples);19 bufferList->mBuffers[0].mData = AUBIO_ARRAY(smpl_t, max_source_samples);
19 bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(short);20 bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(smpl_t);
20 return 0;21 return 0;
21}22}
22 23
tests/src/io/base-sink_custom.h+16−12
@@ -25,21 +25,25 @@ int base_main(int argc, char **argv) · 24 unmodified lines
25 char_t *source_path = argv[1];25 char_t *source_path = argv[1];
26 char_t *sink_path = argv[2];26 char_t *sink_path = argv[2];
27 27
28 aubio_source_t *src = NULL;
29 aubio_sink_custom_t *snk = NULL;
30
28 if ( argc >= 4 ) samplerate = atoi(argv[3]);31 if ( argc >= 4 ) samplerate = atoi(argv[3]);
29 if ( argc >= 5 ) hop_size = atoi(argv[4]);32 if ( argc >= 5 ) hop_size = atoi(argv[4]);
30 33
31 fvec_t *vec = new_fvec(hop_size);34 fvec_t *vec = new_fvec(hop_size);
35 if (!vec) { err = 1; goto failure; }
32 36
33 aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);37 src = new_aubio_source(source_path, samplerate, hop_size);
34 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);38 if (!src) { err = 1; goto failure; }
35 39 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(src);
36 aubio_sink_custom_t *o = new_aubio_sink_custom(sink_path, samplerate);
37 40
38 if (!vec || !i || !o) { err = 1; goto failure; }41 snk = new_aubio_sink_custom(sink_path, samplerate);
42 if (!snk) { err = 1; goto failure; }
39 43
40 do {44 do {
41 aubio_source_do(i, vec, &read);45 aubio_source_do(src, vec, &read);
42 aubio_sink_custom_do(o, vec, read);46 aubio_sink_custom_do(snk, vec, read);
43 n_frames += read;47 n_frames += read;
44 } while ( read == hop_size );48 } while ( read == hop_size );
45 49
@@ -48,13 +52,13 @@ int base_main(int argc, char **argv) · 2 unmodified lines
48 source_path, sink_path);52 source_path, sink_path);
49 53
50 // close sink now (optional)54 // close sink now (optional)
51 aubio_sink_custom_close(o);55 aubio_sink_custom_close(snk);
52 56
53failure:57failure:
54 if (o)58 if (snk)
55 del_aubio_sink_custom(o);59 del_aubio_sink_custom(snk);
56 if (i)60 if (src)
57 del_aubio_source(i);61 del_aubio_source(src);
58 if (vec)62 if (vec)
59 del_fvec(vec);63 del_fvec(vec);
60 64
tests/src/io/test-sink.c+16−12
@@ -21,21 +21,25 @@ int main(int argc, char **argv) · 20 unmodified lines
21 char_t *source_path = argv[1];21 char_t *source_path = argv[1];
22 char_t *sink_path = argv[2];22 char_t *sink_path = argv[2];
23 23
24 aubio_source_t *src = NULL;
25 aubio_sink_t *snk = NULL;
26
24 if ( argc >= 4 ) samplerate = atoi(argv[3]);27 if ( argc >= 4 ) samplerate = atoi(argv[3]);
25 if ( argc >= 5 ) hop_size = atoi(argv[4]);28 if ( argc >= 5 ) hop_size = atoi(argv[4]);
26 29
27 fvec_t *vec = new_fvec(hop_size);30 fvec_t *vec = new_fvec(hop_size);
31 if (!vec) { err = 1; goto failure; }
28 32
29 aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);33 src = new_aubio_source(source_path, samplerate, hop_size);
30 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);34 if (!src) { err = 1; goto failure; }
31 35 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(src);
32 aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
33 36
34 if (!vec || !i || !o) { err = 1; goto failure; }37 snk = new_aubio_sink(sink_path, samplerate);
38 if (!snk) { err = 1; goto failure; }
35 39
36 do {40 do {
37 aubio_source_do(i, vec, &read);41 aubio_source_do(src, vec, &read);
38 aubio_sink_do(o, vec, read);42 aubio_sink_do(snk, vec, read);
39 n_frames += read;43 n_frames += read;
40 } while ( read == hop_size );44 } while ( read == hop_size );
41 45
@@ -44,13 +48,13 @@ int main(int argc, char **argv) · 2 unmodified lines
44 source_path, sink_path);48 source_path, sink_path);
45 49
46 // close sink now (optional)50 // close sink now (optional)
47 aubio_sink_close(o);51 aubio_sink_close(snk);
48 52
49failure:53failure:
50 if (o)54 if (snk)
51 del_aubio_sink(o);55 del_aubio_sink(snk);
52 if (i)56 if (src)
53 del_aubio_source(i);57 del_aubio_source(src);
54 if (vec)58 if (vec)
55 del_fvec(vec);59 del_fvec(vec);
56 60
tests/src/onset/test-onset.c+9−12
@@ -69,21 +69,19 @@ int test_wrong_params(void) · 68 unmodified lines
69 uint_t hop_size = win_size / 2;69 uint_t hop_size = win_size / 2;
70 uint_t samplerate = 44100;70 uint_t samplerate = 44100;
71 // hop_size < 171 // hop_size < 1
72 if (new_aubio_onset("default", 5, 0, samplerate))72 if (new_aubio_onset("default", 5, 0, samplerate)) return 1;
73 return 1;73
74 // buf_size < 274 // buf_size < 2
75 if (new_aubio_onset("default", 1, 1, samplerate))75 if (new_aubio_onset("default", 1, 1, samplerate)) return 1;
76 return 1;76
77 // buf_size < hop_size77 // buf_size < hop_size
78 if (new_aubio_onset("default", hop_size, win_size, samplerate))78 if (new_aubio_onset("default", hop_size, win_size, samplerate)) return 1;
79 return 1;79
80 // samplerate < 180 // samplerate < 1
81 if (new_aubio_onset("default", 1024, 512, 0))81 if (new_aubio_onset("default", 1024, 512, 0)) return 1;
82 return 1;
83 82
84 // specdesc creation failed83 // specdesc creation failed
85 if (new_aubio_onset("abcd", win_size, win_size/2, samplerate))84 if (new_aubio_onset("abcd", win_size, win_size/2, samplerate)) return 1;
86 return 1;
87 85
88 aubio_onset_t *o;86 aubio_onset_t *o;
89 87
@@ -92,8 +90,7 @@ int test_wrong_params(void) · 2 unmodified lines
92 if (o) del_aubio_onset(o);90 if (o) del_aubio_onset(o);
93 91
94 o = new_aubio_onset("default", win_size, hop_size, samplerate);92 o = new_aubio_onset("default", win_size, hop_size, samplerate);
95 if (!aubio_onset_set_default_parameters(o, "wrong_type"))93 if (!aubio_onset_set_default_parameters(o, "wrong_type")) return 1;
96 return 1;
97 del_aubio_onset(o);94 del_aubio_onset(o);
98 95
99 return run_on_default_source(main);96 return run_on_default_source(main);
tests/src/tempo/test-tempo.c+7−14
@@ -81,35 +81,28 @@ int test_wrong_params(void) · 80 unmodified lines
81 uint_t i;81 uint_t i;
82 82
83 // test wrong method fails83 // test wrong method fails
84 if (new_aubio_tempo("unexisting_method", win_size, hop_size, samplerate))84 if (new_aubio_tempo("undefined", win_size, hop_size, samplerate)) return 1;
85 return 1;
86 85
87 // test hop > win fails86 // test hop > win fails
88 if (new_aubio_tempo("default", hop_size, win_size, samplerate))87 if (new_aubio_tempo("default", hop_size, win_size, samplerate)) return 1;
89 return 1;
90 88
91 // test null hop_size fails89 // test null hop_size fails
92 if (new_aubio_tempo("default", win_size, 0, samplerate))90 if (new_aubio_tempo("default", win_size, 0, samplerate)) return 1;
93 return 1;
94 91
95 // test 1 buf_size fails92 // test 1 buf_size fails
96 if (new_aubio_tempo("default", 1, 1, samplerate))93 if (new_aubio_tempo("default", 1, 1, samplerate)) return 1;
97 return 1;
98 94
99 // test null samplerate fails95 // test null samplerate fails
100 if (new_aubio_tempo("default", win_size, hop_size, 0))96 if (new_aubio_tempo("default", win_size, hop_size, 0)) return 1;
101 return 1;
102 97
103 // test short sizes workaround98 // test short sizes workaround
104 t = new_aubio_tempo("default", 2048, 2048, 500);99 t = new_aubio_tempo("default", 2048, 2048, 500);
105 if (!t)100 if (!t) return 1;
106 return 1;
107 101
108 del_aubio_tempo(t);102 del_aubio_tempo(t);
109 103
110 t = new_aubio_tempo("default", win_size, hop_size, samplerate);104 t = new_aubio_tempo("default", win_size, hop_size, samplerate);
111 if (!t)105 if (!t) return 1;
112 return 1;
113 106
114 in = new_fvec(hop_size);107 in = new_fvec(hop_size);
115 out = new_fvec(1);108 out = new_fvec(1);
tests/src/temporal/test-filter.c+7−12
@@ -9,17 +9,13 @@ int main (void) · 8 unmodified lines
9 9
10 aubio_filter_t *o = new_aubio_filter_c_weighting (44100);10 aubio_filter_t *o = new_aubio_filter_c_weighting (44100);
11 11
12 if (new_aubio_filter(0))12 if (new_aubio_filter(0)) return 1;
13 return 1;
14 13
15 if (aubio_filter_get_samplerate(o) != 44100)14 if (aubio_filter_get_samplerate(o) != 44100) return 1;
16 return 1;
17 15
18 if (aubio_filter_set_c_weighting (o, -1) == 0)16 if (aubio_filter_set_c_weighting (o, -1) == 0) return 1;
19 return 1;
20 17
21 if (aubio_filter_set_c_weighting (0, 32000) == 0)18 if (aubio_filter_set_c_weighting (0, 32000) == 0) return 1;
22 return 1;
23 19
24 in->data[impulse_at] = 0.5;20 in->data[impulse_at] = 0.5;
25 fvec_print (in);21 fvec_print (in);
@@ -29,10 +25,9 @@ int main (void) · 3 unmodified lines
29 25
30 o = new_aubio_filter_a_weighting (32000);26 o = new_aubio_filter_a_weighting (32000);
31 27
32 if (aubio_filter_set_a_weighting (o, -1) == 0)28 if (aubio_filter_set_a_weighting (o, -1) == 0) return 1;
33 return 1;29
34 if (aubio_filter_set_a_weighting (0, 32000) == 0)30 if (aubio_filter_set_a_weighting (0, 32000) == 0) return 1;
35 return 1;
36 31
37 in->data[impulse_at] = 0.5;32 in->data[impulse_at] = 0.5;
38 fvec_print (in);33 fvec_print (in);
tests/src/test-delnull.c+0−24
@@ -1,24 +0,0 @@
1#include <stdlib.h>
2#include "aubio.h"
3
4// When creating an aubio object, the user should check whether the object is
5// set NULL, indicating the creation failed and the object was not allocated.
6
7int main (void)
8{
9 uint_t return_code = 0;
10 fvec_t *f = new_fvec(-12);
11 cvec_t *c = new_cvec(-12);
12 lvec_t *l = new_lvec(-12);
13 aubio_fft_t *fft = new_aubio_fft(-12);
14 if (f != NULL) {
15 return_code = 1;
16 } else if (c != NULL) {
17 return_code = 2;
18 } else if (l != NULL) {
19 return_code = 3;
20 } else if (fft != NULL) {
21 return_code = 3;
22 }
23 return return_code;
24}

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