Changes in / [0e6ad10:f5adffe]
- Files:
-
- 1 added
- 4 deleted
- 48 edited
Legend:
- Unmodified
- Added
- Removed
-
.appveyor.yml
r0e6ad10 rf5adffe 76 76 test_script: 77 77 - "python python\\demos\\demo_create_test_sounds.py" 78 - " nose2--verbose"78 - "pytest --verbose" -
.circleci/config.yml
r0e6ad10 rf5adffe 20 20 pip install --user dist/aubio*.whl 21 21 22 test- nose2: &test-nose222 test-pytest: &test-pytest 23 23 name: Test python wheel 24 24 command: | 25 25 make create_test_sounds 26 PATH=/home/circleci/.local/bin:$PATH nose2-v26 PATH=/home/circleci/.local/bin:$PATH pytest -v 27 27 28 test- nose2-nosounds: &test-nose2-nosounds28 test-pytest-nosounds: &test-pytest-nosounds 29 29 name: Test python wheel 30 30 command: | 31 PATH=/home/circleci/.local/bin:$PATH nose2-v31 PATH=/home/circleci/.local/bin:$PATH pytest -v 32 32 33 33 uninstall-wheel: &uninstall-wheel … … 48 48 - run: *build-wheel 49 49 - run: *install-wheel 50 - run: *test- nose250 - run: *test-pytest 51 51 - run: *uninstall-wheel 52 52 - store_artifacts: … … 62 62 - run: *build-wheel 63 63 - run: *install-wheel 64 - run: *test- nose264 - run: *test-pytest 65 65 - run: *uninstall-wheel 66 66 - store_artifacts: … … 76 76 - run: *build-wheel 77 77 - run: *install-wheel 78 - run: *test- nose278 - run: *test-pytest 79 79 - run: *uninstall-wheel 80 80 - store_artifacts: … … 89 89 - run: *build-wheel 90 90 - run: *install-wheel 91 - run: *test- nose2-nosounds91 - run: *test-pytest-nosounds 92 92 - run: *uninstall-wheel 93 93 - store_artifacts: -
.travis.yml
r0e6ad10 rf5adffe 88 88 - which pip 89 89 - pip --version 90 - pip install coverage 90 91 91 92 script: -
MANIFEST.in
r0e6ad10 rf5adffe 7 7 include Makefile wscript */wscript_build 8 8 include aubio.pc.in 9 include nose2.cfg10 9 include requirements.txt 11 10 include src/*.c src/*.h 12 11 include src/*/*.c src/*/*.h 13 12 include examples/*.c examples/*.h 14 include tests/*.h tests/*/*.c tests/*/*/*.c 13 recursive-include tests *.h *.c *.py 15 14 include python/ext/*.h 16 15 recursive-include python *.py 17 16 include python/README.md 18 include python/tests/run_all_tests19 17 include python/tests/eval_pitch 20 18 include python/tests/*.expected -
Makefile
r0e6ad10 rf5adffe 36 36 MANDIR?=$(DATAROOTDIR)/man 37 37 38 # default nose2command39 NOSE2?=nose2 -N 4--verbose38 # default python test command 39 PYTEST?=pytest --verbose 40 40 41 41 SOX=sox … … 141 141 test_python: local_dylib 142 142 # run test with installed package 143 # ./python/tests/run_all_tests --verbose 144 # run with nose2, multiple processes 145 $(NOSE2) 143 $(PYTEST) 146 144 147 145 clean_python: … … 254 252 pip install -v -e . 255 253 # run tests, with python coverage 256 coverage run `which nose2`254 coverage run `which pytest` 257 255 # capture coverage again 258 256 lcov $(LCOVOPTS) --capture --no-external --directory . \ -
doc/python_module.rst
r0e6ad10 rf5adffe 90 90 ------------ 91 91 92 A number of Python tests are provided in the `python tests`_. To run them,93 install `nose2`_ and run the script ``python/tests/run_all_tests``:92 A number of Python tests are provided in the `python/tests`_ folder. To run 93 them, install `pytest`_ and run it from the aubio source directory: 94 94 95 95 .. code-block:: console 96 96 97 $ pip install nose2 98 $ ./python/tests/run_all_tests 97 $ pip install pytest 98 $ 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.py 101 .. _python tests: https://github.com/aubio/aubio/blob/master/python/tests 102 .. _nose2: https://github.com/nose-devs/nose2 102 .. _python/tests: https://github.com/aubio/aubio/blob/master/python/tests 103 .. _pytest: https://pytest.org -
python/README.md
r0e6ad10 rf5adffe 28 28 ----- 29 29 30 Some examples are available in the [`python/demos` ][demos_dir] folder. Each30 Some examples are available in the [`python/demos` folder][demos_dir]. Each 31 31 script is a command line program which accepts one ore more argument. 32 32 -
python/ext/aubiomodule.c
r0e6ad10 rf5adffe 224 224 225 225 // 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 227 if (result == NULL) { 228 228 return NULL; … … 320 320 321 321 // 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 323 if (result == NULL) { 324 324 return NULL; -
python/ext/py-cvec.c
r0e6ad10 rf5adffe 137 137 } 138 138 139 args = Py _BuildValue ("I",self->length);139 args = PyLong_FromLong(self->length); 140 140 if (args == NULL) { 141 141 goto fail; -
python/ext/py-musicutils.c
r0e6ad10 rf5adffe 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 43 if (level_lin == NULL) { 44 44 PyErr_SetString (PyExc_ValueError, "failed computing level_lin"); … … 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 71 if (db_spl == NULL) { 72 72 PyErr_SetString (PyExc_ValueError, "failed computing db_spl"); … … 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 100 if (silence_detection == NULL) { 101 101 PyErr_SetString (PyExc_ValueError, "failed computing silence_detection"); … … 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 129 if (level_detection == NULL) { 130 130 PyErr_SetString (PyExc_ValueError, "failed computing level_detection"); … … 195 195 } 196 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 198 else 199 return Py _BuildValue(AUBIO_NPY_SMPL_CHR,aubio_hztomel(v));199 return PyFloat_FromDouble(aubio_hztomel(v)); 200 200 } 201 201 … … 212 212 } 213 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 215 else 216 return Py _BuildValue(AUBIO_NPY_SMPL_CHR,aubio_meltohz(v));216 return PyFloat_FromDouble(aubio_meltohz(v)); 217 217 } 218 218 … … 224 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 … … 234 234 return NULL; 235 235 } 236 return Py _BuildValue(AUBIO_NPY_SMPL_CHR,aubio_meltohz_htk(v));237 } 236 return PyFloat_FromDouble(aubio_meltohz_htk(v)); 237 } -
python/tests/test_aubio.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from unittest import main4 3 from numpy.testing import TestCase 5 4 … … 16 15 17 16 if __name__ == '__main__': 17 from unittest import main 18 18 main() 19 -
python/tests/test_aubio_cmd.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from numpy.testing import TestCase 3 4 import aubio.cmd 4 from nose2 import main5 from numpy.testing import TestCase6 5 7 6 class aubio_cmd(TestCase): … … 32 31 33 32 if __name__ == '__main__': 33 from unittest import main 34 34 main() -
python/tests/test_aubio_cut.py
r0e6ad10 rf5adffe 2 2 3 3 import aubio.cut 4 from nose2 import main5 4 from numpy.testing import TestCase 6 5 … … 14 13 15 14 if __name__ == '__main__': 15 from unittest import main 16 16 main() -
python/tests/test_cvec.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from unittest import main4 3 import numpy as np 5 4 from numpy.testing import TestCase, assert_equal … … 142 141 143 142 if __name__ == '__main__': 143 from unittest import main 144 144 main() -
python/tests/test_dct.py
r0e6ad10 rf5adffe 67 67 except AssertionError: 68 68 self.skipTest('creating aubio.dct with size %d did not fail' % size) 69 70 if __name__ == '__main__': 71 from unittest import main 72 main() -
python/tests/test_fft.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from unittest import main4 3 from numpy.testing import TestCase 5 4 from numpy.testing import assert_equal, assert_almost_equal … … 213 212 214 213 if __name__ == '__main__': 214 from unittest import main 215 215 main() -
python/tests/test_filter.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from unittest import main4 3 from numpy.testing import TestCase, assert_equal, assert_almost_equal 5 4 from aubio import fvec, digital_filter 6 from .utils import array_from_text_file5 from utils import array_from_text_file 7 6 8 7 class aubio_filter_test_case(TestCase): … … 95 94 96 95 if __name__ == '__main__': 96 from unittest import main 97 97 main() -
python/tests/test_filterbank.py
r0e6ad10 rf5adffe 5 5 6 6 from aubio import cvec, filterbank, float_type 7 from .utils import array_from_text_file7 from utils import array_from_text_file 8 8 9 9 class aubio_filterbank_test_case(TestCase): … … 88 88 89 89 if __name__ == '__main__': 90 import nose291 nose2.main()90 from unittest import main 91 main() -
python/tests/test_filterbank_mel.py
r0e6ad10 rf5adffe 3 3 import numpy as np 4 4 from numpy.testing import TestCase, assert_equal, assert_almost_equal 5 from _tools import assert_warns 5 6 6 7 from aubio import fvec, cvec, filterbank, float_type 7 8 import warnings9 warnings.filterwarnings('ignore', category=UserWarning, append=True)10 8 11 9 class aubio_filterbank_mel_test_case(TestCase): … … 76 74 freq_list = [0, samplerate//4, samplerate // 2 + 1] 77 75 f = filterbank(len(freq_list)-2, 1024) 78 # TODO add assert_warns79 f.set_triangle_bands(fvec(freq_list), samplerate)76 with assert_warns(UserWarning): 77 f.set_triangle_bands(fvec(freq_list), samplerate) 80 78 81 79 def test_triangle_freqs_with_not_enough_filters(self): … … 84 82 freq_list = [0, 100, 1000, 4000, 8000, 10000] 85 83 f = filterbank(len(freq_list)-3, 1024) 86 # TODO add assert_warns87 f.set_triangle_bands(fvec(freq_list), samplerate)84 with assert_warns(UserWarning): 85 f.set_triangle_bands(fvec(freq_list), samplerate) 88 86 89 87 def test_triangle_freqs_with_too_many_filters(self): … … 92 90 freq_list = [0, 100, 1000, 4000, 8000, 10000] 93 91 f = filterbank(len(freq_list)-1, 1024) 94 # TODO add assert_warns95 f.set_triangle_bands(fvec(freq_list), samplerate)92 with assert_warns(UserWarning): 93 f.set_triangle_bands(fvec(freq_list), samplerate) 96 94 97 95 def test_triangle_freqs_with_double_value(self): … … 100 98 freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000] 101 99 f = filterbank(len(freq_list)-2, 1024) 102 # TODO add assert_warns103 f.set_triangle_bands(fvec(freq_list), samplerate)100 with assert_warns(UserWarning): 101 f.set_triangle_bands(fvec(freq_list), samplerate) 104 102 105 103 def test_triangle_freqs_with_triple(self): … … 108 106 freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000] 109 107 f = filterbank(len(freq_list)-2, 1024) 110 # TODO add assert_warns 111 f.set_triangle_bands(fvec(freq_list), samplerate) 108 with assert_warns(UserWarning): 109 f.set_triangle_bands(fvec(freq_list), samplerate) 110 112 111 113 112 def test_triangle_freqs_without_norm(self): … … 169 168 170 169 if __name__ == '__main__': 171 import nose2172 nose2.main()170 from unittest import main 171 main() -
python/tests/test_fvec.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from unittest import main4 3 import numpy as np 5 4 from numpy.testing import TestCase, assert_equal, assert_almost_equal … … 149 148 150 149 if __name__ == '__main__': 150 from unittest import main 151 151 main() -
python/tests/test_fvec_shift.py
r0e6ad10 rf5adffe 31 31 self.run_shift_ishift(7) 32 32 33 from unittest import main34 33 if __name__ == '__main__': 34 from unittest import main 35 35 main() -
python/tests/test_hztomel.py
r0e6ad10 rf5adffe 4 4 from numpy.testing import TestCase 5 5 from numpy.testing import assert_equal, assert_almost_equal 6 from _tools import assert_warns 6 7 import numpy as np 7 8 import aubio … … 38 39 39 40 def test_meltohz_negative(self): 40 # TODO add assert_warns41 assert_equal(meltohz(-1), 0)41 with assert_warns(UserWarning): 42 assert_equal(meltohz(-1), 0) 42 43 43 44 def test_hztomel_negative(self): 44 # TODO add assert_warns45 assert_equal(hztomel(-1), 0)45 with assert_warns(UserWarning): 46 assert_equal(hztomel(-1), 0) 46 47 47 48 … … 58 59 59 60 def test_meltohz_negative(self): 60 # TODO add assert_warns61 assert_equal(meltohz(-1, htk=True), 0)61 with assert_warns(UserWarning): 62 assert_equal(meltohz(-1, htk=True), 0) 62 63 assert_almost_equal(meltohz(2000, htk=True), 3428.7, decimal=1) 63 64 assert_almost_equal(meltohz(1000, htk=True), 1000., decimal=1) 64 65 65 66 def test_hztomel_negative(self): 66 # TODO add assert_warns 67 assert_equal(hztomel(-1, htk=True), 0) 67 with assert_warns(UserWarning): 68 assert_equal(meltohz(-1, htk=True), 0) 69 with assert_warns(UserWarning): 70 assert_equal(hztomel(-1, htk=True), 0) 68 71 assert_almost_equal(hztomel(1000, htk=True), 1000., decimal=1) 69 72 -
python/tests/test_mathutils.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from unittest import main4 3 from numpy.testing import TestCase, assert_equal 5 4 from numpy import array, arange, isnan, isinf … … 102 101 103 102 if __name__ == '__main__': 103 from unittest import main 104 104 main() -
python/tests/test_mfcc.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from nose2 import main 4 from nose2.tools import params 3 from _tools import parametrize, assert_raises 5 4 from numpy import random, count_nonzero 6 5 from numpy.testing import TestCase … … 16 15 new_deflts = [1024, 40, 13, 44100] 17 16 18 class aubio_mfcc(TestCase):17 class Test_aubio_mfcc(object): 19 18 20 def setUp(self): 21 self.o = mfcc() 19 members_args = 'name' 22 20 23 def test_default_creation(self): 24 pass 25 26 def test_delete(self): 27 del self.o 28 29 @params(*new_params) 21 @parametrize(members_args, new_params) 30 22 def test_read_only_member(self, name): 31 o = self.o32 with self.assertRaises((TypeError, AttributeError)):23 o = mfcc() 24 with assert_raises((TypeError, AttributeError)): 33 25 setattr(o, name, 0) 34 26 35 @param s(*zip(new_params, new_deflts))27 @parametrize('name, expected', zip(new_params, new_deflts)) 36 28 def test_default_param(self, name, expected): 37 29 """ test mfcc.{:s} = {:d} """.format(name, expected) 38 o = self.o39 self.assertEqual( getattr(o, name), expected)30 o = mfcc() 31 assert getattr(o, name) == expected 40 32 41 33 class aubio_mfcc_wrong_params(TestCase): … … 83 75 84 76 85 class aubio_mfcc_all_parameters(TestCase):77 class Test_aubio_mfcc_all_parameters(object): 86 78 87 @params(79 run_values = [ 88 80 (2048, 40, 13, 44100), 89 81 (1024, 40, 13, 44100), … … 101 93 (1024, 40, 40, 44100), 102 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 99 def test_run_with_params(self, buf_size, n_filters, n_coeffs, samplerate): 105 100 " check mfcc can run with reasonable parameters " … … 149 144 150 145 if __name__ == '__main__': 151 main() 146 from _tools import run_module_suite 147 run_module_suite() -
python/tests/test_midi2note.py
r0e6ad10 rf5adffe 3 3 4 4 from aubio import midi2note 5 from nose2.tools import params 6 import unittest 5 from _tools import parametrize, assert_raises 7 6 8 7 list_of_known_midis = ( … … 16 15 ) 17 16 18 class midi2note_good_values(unittest.TestCase):17 class Test_midi2note_good_values(object): 19 18 20 @param s(*list_of_known_midis)19 @parametrize('midi, note', list_of_known_midis) 21 20 def test_midi2note_known_values(self, midi, note): 22 21 " known values are correctly converted " 23 self.assertEqual ( midi2note(midi), note)22 assert midi2note(midi) == (note) 24 23 25 class midi2note_wrong_values(unittest.TestCase):24 class Test_midi2note_wrong_values(object): 26 25 27 26 def test_midi2note_negative_value(self): 28 27 " fails when passed a negative value " 29 self.assertRaises(ValueError, midi2note, -2)28 assert_raises(ValueError, midi2note, -2) 30 29 31 30 def test_midi2note_large(self): 32 31 " fails when passed a value greater than 127 " 33 self.assertRaises(ValueError, midi2note, 128)32 assert_raises(ValueError, midi2note, 128) 34 33 35 34 def test_midi2note_floating_value(self): 36 35 " fails when passed a floating point " 37 self.assertRaises(TypeError, midi2note, 69.2)36 assert_raises(TypeError, midi2note, 69.2) 38 37 39 38 def test_midi2note_character_value(self): 40 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 43 42 if __name__ == '__main__': 44 import nose245 nose2.main()43 from _tools import run_module_suite 44 run_module_suite() -
python/tests/test_musicutils.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from unittest import main4 3 import numpy as np 5 4 from numpy.testing import TestCase 6 from numpy.testing .utilsimport assert_equal, assert_almost_equal5 from numpy.testing import assert_equal, assert_almost_equal 7 6 from aubio import window, level_lin, db_spl, silence_detection, level_detection 8 7 from aubio import fvec, float_type … … 86 85 87 86 if __name__ == '__main__': 87 from unittest import main 88 88 main() -
python/tests/test_note2midi.py
r0e6ad10 rf5adffe 5 5 6 6 from aubio import note2midi, freq2note, note2freq, float_type 7 from n ose2.tools import params8 import unittest7 from numpy.testing import TestCase 8 from _tools import parametrize, assert_raises, skipTest 9 9 10 10 list_of_known_notes = ( … … 45 45 ) 46 46 47 class note2midi_good_values(unittest.TestCase):47 class Test_note2midi_good_values(object): 48 48 49 @param s(*list_of_known_notes)49 @parametrize('note, midi', list_of_known_notes) 50 50 def test_note2midi_known_values(self, note, midi): 51 51 " known values are correctly converted " 52 self.assertEqual ( note2midi(note), midi )52 assert note2midi(note) == midi 53 53 54 @param s(*list_of_known_notes_with_unicode_issues)54 @parametrize('note, midi', list_of_known_notes_with_unicode_issues) 55 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 57 try: 58 self.assertEqual ( note2midi(note), midi )58 assert note2midi(note) == midi 59 59 except UnicodeEncodeError as e: 60 # platforms with decoding failures include: 61 # - osx: python <= 2.7.10 62 # - win: python <= 2.7.12 60 63 import sys 61 str fmt = "len(u'\\U0001D12A') != 1, excpected decoding failure | {:s} | {:s} {:s}"62 str res = strfmt.format(e, sys.platform, sys.version)63 # happens with: darwin 2.7.10, windows 2.7.1264 strmsg = "len(u'\\U0001D12A') != 1, expected decoding failure" 65 strmsg += " | upgrade to Python 3 to fix" 66 strmsg += " | {:s} | {:s} {:s}" 64 67 if len('\U0001D12A') != 1 and sys.version[0] == '2': 65 s elf.skipTest(strres + " | upgrade to Python 3 to fix")68 skipTest(strmsg.format(repr(e), sys.platform, sys.version)) 66 69 else: 67 70 raise 68 71 69 class note2midi_wrong_values( unittest.TestCase):72 class note2midi_wrong_values(TestCase): 70 73 71 74 def test_note2midi_missing_octave(self): … … 105 108 self.assertRaises(ValueError, note2midi, 'CB+-3') 106 109 107 @params(*list_of_unknown_notes) 110 class Test_note2midi_unknown_values(object): 111 112 @parametrize('note', list_of_unknown_notes) 108 113 def test_note2midi_unknown_values(self, note): 109 114 " unknown values throw out an error " 110 self.assertRaises(ValueError, note2midi, note)115 assert_raises(ValueError, note2midi, note) 111 116 112 class freq2note_simple_test( unittest.TestCase):117 class freq2note_simple_test(TestCase): 113 118 114 119 def test_freq2note_above(self): … … 120 125 self.assertEqual("A4", freq2note(439)) 121 126 122 class note2freq_simple_test( unittest.TestCase):127 class note2freq_simple_test(TestCase): 123 128 124 129 def test_note2freq(self): … … 134 139 135 140 if __name__ == '__main__': 136 import nose2137 nose2.main()141 from _tools import run_module_suite 142 run_module_suite() -
python/tests/test_notes.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from unittest import main4 3 from numpy.testing import TestCase, assert_equal, assert_almost_equal 5 from aubio import notes 4 from aubio import notes, source 5 import numpy as np 6 from utils import list_all_sounds 7 8 list_of_sounds = list_all_sounds('sounds') 6 9 7 10 AUBIO_DEFAULT_NOTES_SILENCE = -70. … … 53 56 self.o.set_release_drop(val) 54 57 55 from .utils import list_all_sounds56 list_of_sounds = list_all_sounds('sounds')57 58 58 class aubio_notes_sinewave(TestCase): 59 59 60 60 def analyze_file(self, filepath, samplerate=0): 61 from aubio import source62 import numpy as np63 61 win_s = 512 # fft size 64 62 hop_s = 256 # hop size … … 93 91 94 92 if __name__ == '__main__': 93 from unittest import main 95 94 main() -
python/tests/test_onset.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from unittest import main4 3 from numpy.testing import TestCase, assert_equal, assert_almost_equal 5 4 from aubio import onset, fvec … … 117 116 118 117 if __name__ == '__main__': 118 from unittest import main 119 119 main() -
python/tests/test_phasevoc.py
r0e6ad10 rf5adffe 2 2 3 3 from numpy.testing import TestCase, assert_equal, assert_array_less 4 from _tools import parametrize 4 5 from aubio import fvec, cvec, pvoc, float_type 5 from nose2 import main6 from nose2.tools import params7 6 import numpy as np 8 7 … … 19 18 return np.random.rand(hop_s).astype(float_type) * 2. - 1. 20 19 21 class aubio_pvoc_test_case(TestCase):20 class Test_aubio_pvoc_test_case(object): 22 21 """ pvoc object test case """ 23 22 … … 66 65 assert_equal ( t, 0.) 67 66 68 @params( 67 resynth_noise_args = "hop_s, ratio" 68 resynth_noise_values = [ 69 69 ( 256, 8), 70 70 ( 256, 4), … … 88 88 (8192, 4), 89 89 (8192, 2), 90 ) 90 ] 91 92 @parametrize(resynth_noise_args, resynth_noise_values) 91 93 def test_resynth_steps_noise(self, hop_s, ratio): 92 94 """ check the resynthesis of a random signal is correct """ … … 94 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 100 (44100, 256, 8, 441), 98 101 (44100, 256, 4, 1203), … … 109 112 (96000, 1024, 8, 47000), 110 113 (96000, 1024, 8, 20), 111 ) 114 ] 115 116 @parametrize(resynth_sine_args, resynth_sine_values) 112 117 def test_resynth_steps_sine(self, samplerate, hop_s, ratio, freq): 113 118 """ check the resynthesis of a sine is correct """ … … 200 205 201 206 if __name__ == '__main__': 207 from unittest import main 202 208 main() 203 -
python/tests/test_pitch.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from unittest import TestCase, main 4 from numpy.testing import assert_equal 3 from numpy.testing import TestCase, assert_equal 5 4 from numpy import sin, arange, mean, median, isnan, pi 6 5 from aubio import fvec, pitch, freqtomidi, float_type … … 117 116 for algo in pitch_algorithms: 118 117 for mode in signal_modes: 119 test_method = create_test (algo, mode)120 test_method.__name__ = 'test_pitch_%s_%d_%d_%dHz_sin_%.0f' % ( algo,118 _test_method = create_test (algo, mode) 119 _test_method.__name__ = 'test_pitch_%s_%d_%d_%dHz_sin_%.0f' % ( algo, 121 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 124 123 if __name__ == '__main__': 124 from unittest import main 125 125 main() -
python/tests/test_sink.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from nose2 import main4 from nose2.tools import params5 3 from numpy.testing import TestCase 6 4 from aubio import fvec, source, sink 7 from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path 8 9 import warnings 10 warnings.filterwarnings('ignore', category=UserWarning, append=True) 5 from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path 6 from _tools import parametrize, skipTest, assert_raises 11 7 12 8 list_of_sounds = list_all_sounds('sounds') … … 24 20 all_params.append((hop_size, samplerate, soundfile)) 25 21 26 class aubio_sink_test_case(TestCase): 27 28 def setUp(self): 29 if not len(list_of_sounds): 30 self.skipTest('add some sound files in \'python/tests/sounds\'') 22 class Test_aubio_sink(object): 31 23 32 24 def test_wrong_filename(self): 33 with self.assertRaises(RuntimeError):25 with assert_raises(RuntimeError): 34 26 sink('') 35 27 36 28 def test_wrong_samplerate(self): 37 with self.assertRaises(RuntimeError):29 with assert_raises(RuntimeError): 38 30 sink(get_tmp_sink_path(), -1) 39 31 40 32 def test_wrong_samplerate_too_large(self): 41 with self.assertRaises(RuntimeError):33 with assert_raises(RuntimeError): 42 34 sink(get_tmp_sink_path(), 1536001, 2) 43 35 44 36 def test_wrong_channels(self): 45 with self.assertRaises(RuntimeError):37 with assert_raises(RuntimeError): 46 38 sink(get_tmp_sink_path(), 44100, -1) 47 39 48 40 def test_wrong_channels_too_large(self): 49 with self.assertRaises(RuntimeError):41 with assert_raises(RuntimeError): 50 42 sink(get_tmp_sink_path(), 44100, 202020) 51 43 … … 67 59 shutil.rmtree(tmpdir) 68 60 69 @param s(*all_params)61 @parametrize('hop_size, samplerate, path', all_params) 70 62 def test_read_and_write(self, hop_size, samplerate, path): 71 72 63 try: 73 64 f = source(path, samplerate, hop_size) 74 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 68 if samplerate == 0: samplerate = f.samplerate 77 69 sink_path = get_tmp_sink_path() … … 85 77 del_tmp_sink_path(sink_path) 86 78 87 @param s(*all_params)79 @parametrize('hop_size, samplerate, path', all_params) 88 80 def test_read_and_write_multi(self, hop_size, samplerate, path): 89 81 try: 90 82 f = source(path, samplerate, hop_size) 91 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 86 if samplerate == 0: samplerate = f.samplerate 94 87 sink_path = get_tmp_sink_path() … … 126 119 127 120 if __name__ == '__main__': 128 main() 121 from _tools import run_module_suite 122 run_module_suite() -
python/tests/test_slicing.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from unittest import main4 3 from numpy.testing import TestCase, assert_equal 5 4 from aubio import slice_source_at_stamps 6 from .utils import count_files_in_directory, get_default_test_sound7 from .utils import count_samples_in_directory, count_samples_in_file5 from utils import count_files_in_directory, get_default_test_sound 6 from utils import count_samples_in_directory, count_samples_in_file 8 7 9 8 import tempfile … … 168 167 169 168 if __name__ == '__main__': 169 from unittest import main 170 170 main() -
python/tests/test_source.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from nose2 import main 4 from nose2.tools import params 3 5 4 from numpy.testing import TestCase, assert_equal 6 5 from aubio import source 7 from .utils import list_all_sounds 8 9 import warnings 10 warnings.filterwarnings('ignore', category=UserWarning, append=True) 6 from utils import list_all_sounds 7 import unittest 8 from _tools import parametrize, assert_raises, assert_equal, skipTest 11 9 12 10 list_of_sounds = list_all_sounds('sounds') … … 14 12 hop_sizes = [512, 1024, 64] 15 13 16 path =None14 default_test_sound = len(list_of_sounds) and list_of_sounds[0] or None 17 15 18 16 all_params = [] … … 22 20 all_params.append((hop_size, samplerate, soundfile)) 23 21 22 no_sounds_msg = "no test sounds, add some in 'python/tests/sounds/'!" 24 23 25 class aubio_source_test_case_base(TestCase): 24 _debug = False 26 25 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] 26 class Test_aubio_source_test_case(object): 31 27 32 class aubio_source_test_case(aubio_source_test_case_base): 33 34 @params(*list_of_sounds) 28 @parametrize('filename', list_of_sounds) 35 29 def test_close_file(self, filename): 36 30 samplerate = 0 # use native samplerate … … 39 33 f.close() 40 34 41 @param s(*list_of_sounds)35 @parametrize('filename', list_of_sounds) 42 36 def test_close_file_twice(self, filename): 43 37 samplerate = 0 # use native samplerate … … 47 41 f.close() 48 42 49 class aubio_source_read_test_case(aubio_source_test_case_base):43 class Test_aubio_source_read(object): 50 44 51 45 def read_from_source(self, f): … … 57 51 assert_equal(samples[read:], 0) 58 52 break 59 #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}" 60 #result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri 61 #print (result_str.format(*result_params)) 53 if _debug: 54 result_str = "read {:.2f}s ({:d} frames" 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 59 return total_frames 63 60 64 @param s(*all_params)61 @parametrize('hop_size, samplerate, soundfile', all_params) 65 62 def test_samplerate_hopsize(self, hop_size, samplerate, soundfile): 66 63 try: 67 64 f = source(soundfile, samplerate, hop_size) 68 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 68 assert f.samplerate != 0 71 69 read_frames = self.read_from_source(f) 72 70 if 'f_' in soundfile and samplerate == 0: 73 71 import re 74 f = re.compile( '.*_\([0:9]*f\)_.*')72 f = re.compile(r'.*_\([0:9]*f\)_.*') 75 73 match_f = re.findall('([0-9]*)f_', soundfile) 76 74 if len(match_f) == 1: 77 75 expected_frames = int(match_f[0]) 78 self.assertEqual(expected_frames, read_frames)76 assert_equal(expected_frames, read_frames) 79 77 80 @param s(*list_of_sounds)78 @parametrize('p', list_of_sounds) 81 79 def test_samplerate_none(self, p): 82 80 f = source(p) … … 84 82 self.read_from_source(f) 85 83 86 @param s(*list_of_sounds)84 @parametrize('p', list_of_sounds) 87 85 def test_samplerate_0(self, p): 88 86 f = source(p, 0) … … 90 88 self.read_from_source(f) 91 89 92 @param s(*list_of_sounds)90 @parametrize('p', list_of_sounds) 93 91 def test_zero_hop_size(self, p): 94 92 f = source(p, 0, 0) … … 97 95 self.read_from_source(f) 98 96 99 @param s(*list_of_sounds)97 @parametrize('p', list_of_sounds) 100 98 def test_seek_to_half(self, p): 101 99 from random import randint … … 109 107 assert a == b + c 110 108 111 @param s(*list_of_sounds)109 @parametrize('p', list_of_sounds) 112 110 def test_duration(self, p): 113 111 total_frames = 0 … … 118 116 total_frames += read 119 117 if read < f.hop_size: break 120 self.assertEqual(duration, total_frames)118 assert_equal (duration, total_frames) 121 119 122 120 123 class aubio_source_test_wrong_params(TestCase):121 class Test_aubio_source_wrong_params(object): 124 122 125 123 def test_wrong_file(self): 126 with self.assertRaises(RuntimeError):124 with assert_raises(RuntimeError): 127 125 source('path_to/unexisting file.mp3') 128 126 129 class aubio_source_test_wrong_params_with_file(aubio_source_test_case_base): 127 @unittest.skipIf(default_test_sound is None, no_sounds_msg) 128 class Test_aubio_source_wrong_params_with_file(TestCase): 130 129 131 130 def test_wrong_samplerate(self): 132 with self.assertRaises(ValueError):133 source( self.default_test_sound, -1)131 with assert_raises(ValueError): 132 source(default_test_sound, -1) 134 133 135 134 def test_wrong_hop_size(self): 136 with self.assertRaises(ValueError):137 source( self.default_test_sound, 0, -1)135 with assert_raises(ValueError): 136 source(default_test_sound, 0, -1) 138 137 139 138 def test_wrong_channels(self): 140 with self.assertRaises(ValueError):141 source( self.default_test_sound, 0, 0, -1)139 with assert_raises(ValueError): 140 source(default_test_sound, 0, 0, -1) 142 141 143 142 def test_wrong_seek(self): 144 f = source( self.default_test_sound)145 with self.assertRaises(ValueError):143 f = source(default_test_sound) 144 with assert_raises(ValueError): 146 145 f.seek(-1) 147 146 148 147 def test_wrong_seek_too_large(self): 149 f = source( self.default_test_sound)148 f = source(default_test_sound) 150 149 try: 151 with self.assertRaises(ValueError):150 with assert_raises(ValueError): 152 151 f.seek(f.duration + f.samplerate * 10) 153 except AssertionError:154 s elf.skipTest('seeking after end of stream failed raising ValueError')152 except: 153 skipTest('seeking after end of stream failed raising ValueError') 155 154 156 class aubio_source_readmulti_test_case(aubio_source_read_test_case):155 class Test_aubio_source_readmulti(Test_aubio_source_read): 157 156 158 157 def read_from_source(self, f): … … 164 163 assert_equal(samples[:,read:], 0) 165 164 break 166 #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}" 167 #result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri 168 #print (result_str.format(*result_params)) 165 if _debug: 166 result_str = "read {:.2f}s ({:d} frames in {:d} channels" 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 172 return total_frames 170 173 171 class aubio_source_with(aubio_source_test_case_base):174 class Test_aubio_source_with(object): 172 175 173 #@params(*list_of_sounds) 174 @params(*list_of_sounds) 176 @parametrize('filename', list_of_sounds) 175 177 def test_read_from_mono(self, filename): 176 178 total_frames = 0 … … 186 188 187 189 if __name__ == '__main__': 188 main() 190 from _tools import run_module_suite 191 run_module_suite() -
python/tests/test_source_channels.py
r0e6ad10 rf5adffe 9 9 import numpy as np 10 10 from numpy.testing import assert_equal 11 from .utils import get_tmp_sink_path11 from utils import get_tmp_sink_path 12 12 13 13 class aubio_source_test_case(unittest.TestCase): -
python/tests/test_specdesc.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from unittest import main4 3 from numpy.testing import TestCase, assert_equal, assert_almost_equal 5 4 from numpy import random, arange, log, zeros … … 230 229 231 230 if __name__ == '__main__': 231 from unittest import main 232 232 main() -
python/tests/test_zero_crossing_rate.py
r0e6ad10 rf5adffe 1 1 #! /usr/bin/env python 2 2 3 from unittest import main4 3 from numpy.testing import TestCase 5 4 from aubio import fvec, zero_crossing_rate … … 44 43 45 44 if __name__ == '__main__': 45 from unittest import main 46 46 main() -
python/tests/utils.py
r0e6ad10 rf5adffe 9 9 10 10 def array_from_text_file(filename, dtype = 'float'): 11 filename = os.path.join(os.path.dirname(__file__), filename) 12 with open(filename) as f: 13 lines = f.readlines() 14 return np.array([line.split() for line in lines], 15 dtype = dtype) 11 realpathname = os.path.join(os.path.dirname(__file__), filename) 12 return np.loadtxt(realpathname, dtype = dtype) 16 13 17 14 def list_all_sounds(rel_dir): … … 39 36 os.unlink(path) 40 37 except WindowsError as e: 41 print("deleting {:s} failed ({:s}), reopening".format(path, repr(e))) 42 with open(path, 'wb') as f: 43 f.close() 44 try: 45 os.unlink(path) 46 except WindowsError as f: 47 print("deleting {:s} failed ({:s}), aborting".format(path, repr(e))) 38 # removing the temporary directory sometimes fails on windows 39 import warnings 40 errmsg = "failed deleting temporary file {:s} ({:s})" 41 warnings.warn(UserWarning(errmsg.format(path, repr(e)))) 48 42 49 43 def array_from_yaml_file(filename): -
requirements.txt
r0e6ad10 rf5adffe 1 1 numpy 2 nose2 2 pytest -
setup.py
r0e6ad10 rf5adffe 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
r0e6ad10 rf5adffe 32 32 #include <AudioToolbox/AudioToolbox.h> 33 33 34 #define FLOAT_TO_SHORT(x) (short)(x * 32768) 35 36 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize); 34 extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int segmentSize); 37 35 extern void freeAudioBufferList(AudioBufferList *bufferList); 38 36 extern CFURLRef createURLFromPath(const char * path); … … 77 75 return s; 78 76 } 77 79 78 // invalid samplerate given, abort 80 79 if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) { … … 151 150 CFURLRef fileURL = createURLFromPath(s->path); 152 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 164 OSStatus err = noErr; 154 165 err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL, … … 162 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 187 AUBIO_ERR("sink_apple_audio: error when creating buffer list for %s, " 166 188 "out of memory? \n", s->path); … … 175 197 void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) { 176 198 UInt32 c, v; 177 s hort *data = (short*)s->bufferList.mBuffers[0].mData;199 smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData; 178 200 uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path, 179 201 s->max_frames, write_data->length, write); … … 181 203 for (c = 0; c < s->channels; c++) { 182 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 } … … 190 212 void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) { 191 213 UInt32 c, v; 192 s hort *data = (short*)s->bufferList.mBuffers[0].mData;214 smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData; 193 215 uint_t channels = aubio_sink_validate_input_channels("sink_apple_audio", 194 216 s->path, s->channels, write_data->height); … … 198 220 for (c = 0; c < channels; c++) { 199 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 } … … 207 229 void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) { 208 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 235 if (s->async) { 210 236 err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList); -
src/io/source_apple_audio.c
r0e6ad10 rf5adffe 34 34 #define RT_BYTE3( a ) ( ((a) >> 16) & 0xff ) 35 35 #define RT_BYTE4( a ) ( ((a) >> 24) & 0xff ) 36 37 #define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)38 36 39 37 struct _aubio_source_apple_audio_t { … … 49 47 }; 50 48 51 extern int createAu bioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);49 extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples); 52 50 extern void freeAudioBufferList(AudioBufferList *bufferList); 53 51 extern CFURLRef createURLFromPath(const char * path); … … 139 137 140 138 AudioStreamBasicDescription clientFormat; 141 propSize = sizeof( clientFormat);139 propSize = sizeof(AudioStreamBasicDescription); 142 140 memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription)); 143 141 clientFormat.mFormatID = kAudioFormatLinearPCM; 144 142 clientFormat.mSampleRate = (Float64)(s->samplerate); 145 clientFormat.mFormatFlags = kAudioFormatFlagIs SignedInteger | kAudioFormatFlagIsPacked;143 clientFormat.mFormatFlags = kAudioFormatFlagIsFloat; 146 144 clientFormat.mChannelsPerFrame = s->channels; 147 clientFormat.mBitsPerChannel = sizeof(s hort) * 8;145 clientFormat.mBitsPerChannel = sizeof(smpl_t) * 8; 148 146 clientFormat.mFramesPerPacket = 1; 149 147 clientFormat.mBytesPerFrame = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8; 150 148 clientFormat.mBytesPerPacket = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame; 151 clientFormat.mReserved = 0;152 149 153 150 // set the client format description … … 187 184 // allocate the AudioBufferList 188 185 freeAudioBufferList(&s->bufferList); 189 if (createAu bioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {186 if (createAudioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) { 190 187 AUBIO_ERR("source_apple_audio: failed creating bufferList\n"); 191 188 goto beach; … … 196 193 } 197 194 198 void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to, uint_t * read) { 199 UInt32 c, v, loadedPackets = s->block_size; 195 static UInt32 aubio_source_apple_audio_read_frame(aubio_source_apple_audio_t *s) 196 { 197 UInt32 loadedPackets = s->block_size; 200 198 OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList); 201 199 if (err) { … … 204 202 "with ExtAudioFileRead (%s)\n", s->path, 205 203 getPrintableOSStatusError(errorstr, err)); 206 goto beach; 207 } 208 209 short *data = (short*)s->bufferList.mBuffers[0].mData; 210 211 smpl_t *buf = read_to->data; 204 } 205 return loadedPackets; 206 } 207 208 void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to, 209 uint_t * read) { 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 214 for (v = 0; v < loadedPackets; v++) { 214 buf[v] = 0.;215 read_to->data[v] = 0.; 215 216 for (c = 0; c < s->channels; c++) { 216 buf[v] += SHORT_TO_FLOAT(data[ v * s->channels + c]);217 } 218 buf[v] /= (smpl_t)s->channels;217 read_to->data[v] += data[ v * s->channels + c]; 218 } 219 read_to->data[v] /= (smpl_t)s->channels; 219 220 } 220 221 // short read, fill with zeros 221 222 if (loadedPackets < s->block_size) { 222 223 for (v = loadedPackets; v < s->block_size; v++) { 223 buf[v] = 0.;224 read_to->data[v] = 0.; 224 225 } 225 226 } … … 227 228 *read = (uint_t)loadedPackets; 228 229 return; 229 beach:230 *read = 0;231 return;232 230 } 233 231 234 232 void 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; 236 OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList); 237 if (err) { 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; 233 uint_t c, v; 234 UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s); 235 smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData; 248 236 249 237 for (v = 0; v < loadedPackets; v++) { 250 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 } … … 257 245 for (v = 0; v < loadedPackets; v++) { 258 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 } … … 265 253 for (v = loadedPackets; v < s->block_size; v++) { 266 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 260 *read = (uint_t)loadedPackets; 272 return;273 beach:274 *read = 0;275 261 return; 276 262 } … … 323 309 // after a short read, the bufferList size needs to resetted to prepare for a full read 324 310 AudioBufferList *bufferList = &s->bufferList; 325 bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (s hort);311 bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (smpl_t); 326 312 // do the actual seek 327 313 err = ExtAudioFileSeek(s->audioFile, resampled_pos); -
src/io/utils_apple_audio.c
r0e6ad10 rf5adffe 13 13 char_t *getPrintableOSStatusError(char_t *str, OSStatus error); 14 14 15 int createAubioBufferList(AudioBufferList * bufferList, int channels, int max_source_samples) { 15 int createAudioBufferList(AudioBufferList * bufferList, int channels, 16 int max_source_samples) { 16 17 bufferList->mNumberBuffers = 1; 17 18 bufferList->mBuffers[0].mNumberChannels = channels; 18 bufferList->mBuffers[0].mData = AUBIO_ARRAY(s hort, max_source_samples);19 bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(s hort);19 bufferList->mBuffers[0].mData = AUBIO_ARRAY(smpl_t, max_source_samples); 20 bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(smpl_t); 20 21 return 0; 21 22 } -
tests/src/io/base-sink_custom.h
r0e6ad10 rf5adffe 26 26 char_t *sink_path = argv[2]; 27 27 28 aubio_source_t *src = NULL; 29 aubio_sink_custom_t *snk = NULL; 30 28 31 if ( argc >= 4 ) samplerate = atoi(argv[3]); 29 32 if ( argc >= 5 ) hop_size = atoi(argv[4]); 30 33 31 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); 34 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i); 37 src = new_aubio_source(source_path, samplerate, hop_size); 38 if (!src) { err = 1; goto failure; } 39 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(src); 35 40 36 aubio_sink_custom_t *o = new_aubio_sink_custom(sink_path, samplerate); 37 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 44 do { 41 aubio_source_do( i, vec, &read);42 aubio_sink_custom_do( o, vec, read);45 aubio_source_do(src, vec, &read); 46 aubio_sink_custom_do(snk, vec, read); 43 47 n_frames += read; 44 48 } while ( read == hop_size ); … … 49 53 50 54 // close sink now (optional) 51 aubio_sink_custom_close( o);55 aubio_sink_custom_close(snk); 52 56 53 57 failure: 54 if ( o)55 del_aubio_sink_custom( o);56 if ( i)57 del_aubio_source( i);58 if (snk) 59 del_aubio_sink_custom(snk); 60 if (src) 61 del_aubio_source(src); 58 62 if (vec) 59 63 del_fvec(vec); -
tests/src/io/test-sink.c
r0e6ad10 rf5adffe 22 22 char_t *sink_path = argv[2]; 23 23 24 aubio_source_t *src = NULL; 25 aubio_sink_t *snk = NULL; 26 24 27 if ( argc >= 4 ) samplerate = atoi(argv[3]); 25 28 if ( argc >= 5 ) hop_size = atoi(argv[4]); 26 29 27 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); 30 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i); 33 src = new_aubio_source(source_path, samplerate, hop_size); 34 if (!src) { err = 1; goto failure; } 35 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(src); 31 36 32 aubio_sink_t *o = new_aubio_sink(sink_path, samplerate); 33 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 40 do { 37 aubio_source_do( i, vec, &read);38 aubio_sink_do( o, vec, read);41 aubio_source_do(src, vec, &read); 42 aubio_sink_do(snk, vec, read); 39 43 n_frames += read; 40 44 } while ( read == hop_size ); … … 45 49 46 50 // close sink now (optional) 47 aubio_sink_close( o);51 aubio_sink_close(snk); 48 52 49 53 failure: 50 if ( o)51 del_aubio_sink( o);52 if ( i)53 del_aubio_source( i);54 if (snk) 55 del_aubio_sink(snk); 56 if (src) 57 del_aubio_source(src); 54 58 if (vec) 55 59 del_fvec(vec); -
tests/src/onset/test-onset.c
r0e6ad10 rf5adffe 70 70 uint_t samplerate = 44100; 71 71 // hop_size < 1 72 if (new_aubio_onset("default", 5, 0, samplerate)) 73 return 1; 72 if (new_aubio_onset("default", 5, 0, samplerate)) return 1; 73 74 74 // buf_size < 2 75 if (new_aubio_onset("default", 1, 1, samplerate)) 76 return 1; 75 if (new_aubio_onset("default", 1, 1, samplerate)) return 1; 76 77 77 // buf_size < hop_size 78 if (new_aubio_onset("default", hop_size, win_size, samplerate)) 79 return 1; 78 if (new_aubio_onset("default", hop_size, win_size, samplerate)) return 1; 79 80 80 // samplerate < 1 81 if (new_aubio_onset("default", 1024, 512, 0)) 82 return 1; 81 if (new_aubio_onset("default", 1024, 512, 0)) return 1; 83 82 84 83 // specdesc creation failed 85 if (new_aubio_onset("abcd", win_size, win_size/2, samplerate)) 86 return 1; 84 if (new_aubio_onset("abcd", win_size, win_size/2, samplerate)) return 1; 87 85 88 86 aubio_onset_t *o; … … 93 91 94 92 o = new_aubio_onset("default", win_size, hop_size, samplerate); 95 if (!aubio_onset_set_default_parameters(o, "wrong_type")) 96 return 1; 93 if (!aubio_onset_set_default_parameters(o, "wrong_type")) return 1; 97 94 del_aubio_onset(o); 98 95 -
tests/src/tempo/test-tempo.c
r0e6ad10 rf5adffe 82 82 83 83 // test wrong method fails 84 if (new_aubio_tempo("unexisting_method", win_size, hop_size, samplerate)) 85 return 1; 84 if (new_aubio_tempo("undefined", win_size, hop_size, samplerate)) return 1; 86 85 87 86 // test hop > win fails 88 if (new_aubio_tempo("default", hop_size, win_size, samplerate)) 89 return 1; 87 if (new_aubio_tempo("default", hop_size, win_size, samplerate)) return 1; 90 88 91 89 // test null hop_size fails 92 if (new_aubio_tempo("default", win_size, 0, samplerate)) 93 return 1; 90 if (new_aubio_tempo("default", win_size, 0, samplerate)) return 1; 94 91 95 92 // test 1 buf_size fails 96 if (new_aubio_tempo("default", 1, 1, samplerate)) 97 return 1; 93 if (new_aubio_tempo("default", 1, 1, samplerate)) return 1; 98 94 99 95 // test null samplerate fails 100 if (new_aubio_tempo("default", win_size, hop_size, 0)) 101 return 1; 96 if (new_aubio_tempo("default", win_size, hop_size, 0)) return 1; 102 97 103 98 // test short sizes workaround 104 99 t = new_aubio_tempo("default", 2048, 2048, 500); 105 if (!t) 106 return 1; 100 if (!t) return 1; 107 101 108 102 del_aubio_tempo(t); 109 103 110 104 t = new_aubio_tempo("default", win_size, hop_size, samplerate); 111 if (!t) 112 return 1; 105 if (!t) return 1; 113 106 114 107 in = new_fvec(hop_size); -
tests/src/temporal/test-filter.c
r0e6ad10 rf5adffe 10 10 aubio_filter_t *o = new_aubio_filter_c_weighting (44100); 11 11 12 if (new_aubio_filter(0)) 13 return 1; 12 if (new_aubio_filter(0)) return 1; 14 13 15 if (aubio_filter_get_samplerate(o) != 44100) 16 return 1; 14 if (aubio_filter_get_samplerate(o) != 44100) return 1; 17 15 18 if (aubio_filter_set_c_weighting (o, -1) == 0) 19 return 1; 16 if (aubio_filter_set_c_weighting (o, -1) == 0) return 1; 20 17 21 if (aubio_filter_set_c_weighting (0, 32000) == 0) 22 return 1; 18 if (aubio_filter_set_c_weighting (0, 32000) == 0) return 1; 23 19 24 20 in->data[impulse_at] = 0.5; … … 30 26 o = new_aubio_filter_a_weighting (32000); 31 27 32 if (aubio_filter_set_a_weighting (o, -1) == 0) 33 return 1; 34 if (aubio_filter_set_a_weighting (0, 32000) == 0) 35 return 1; 28 if (aubio_filter_set_a_weighting (o, -1) == 0) return 1; 29 30 if (aubio_filter_set_a_weighting (0, 32000) == 0) return 1; 36 31 37 32 in->data[impulse_at] = 0.5;
Note: See TracChangeset
for help on using the changeset viewer.