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