Changes in / [dfe6ab6:868c6b8]
- Files:
-
- 4 added
- 2 deleted
- 70 edited
Legend:
- Unmodified
- Added
- Removed
-
.appveyor.yml
rdfe6ab6 r868c6b8 76 76 test_script: 77 77 - "python python\\demos\\demo_create_test_sounds.py" 78 - " pytest--verbose"78 - "nose2 --verbose" -
.circleci/config.yml
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 3 3 matrix: 4 4 include: 5 - python: 3.6 5 - python: 3.5 6 os: linux 7 compiler: gcc 8 - python: 3.4 9 os: linux 10 compiler: gcc 11 - python: 2.7 6 12 os: linux 7 13 compiler: gcc … … 9 15 os: linux 10 16 compiler: gcc 11 env: WAFOPTS="--build-type=debug" 12 - python: 2.7 13 os: linux 14 compiler: gcc 15 - python: "pypy3.5" 16 os: linux 17 compiler: gcc 18 env: CFLAGS="-Os" WAFOPTS="--disable-avcodec" 19 - python: 3.6 20 os: linux 21 compiler: gcc 22 env: CFLAGS="-Os" WAFOPTS="--disable-samplerate" 23 - python: 3.5 17 env: CFLAGS="-Os" WAFOPTS="--disable-samplerate --disable-sndfile" 18 - python: 3.4 24 19 os: linux 25 20 compiler: gcc … … 91 86 - which pip 92 87 - pip --version 93 - pip install coverage94 88 95 89 script: -
ChangeLog
rdfe6ab6 r868c6b8 1 2018-12-19 Paul Brossier <piem@aubio.org>2 3 [ Overview ]4 5 * VERSION: bump to 0.4.96 * library: improve stability, fixing potential crashes and memory leaks on7 invalid arguments; improve library messages and reporting of system errors8 * tests/: major clean-up, check return codes, increase code coverage9 * python/tests/: switch to pytest (closes gh-163), check emitted warnings10 * python/: add pages to manual with brief descriptions of classes11 12 [ Fixes ]13 14 * security: improve arguments validation in new_aubio_filterbank (prevent15 possible null-pointer dereference on invalid n_filters, CVE-2018-19801),16 new_aubio-tempo (prevent possible buffer overflow, CVE-2018-19800), and17 new_aubio_onset (prevent null-pointer dereference, CVE-2018-19802). Thanks18 to Guoxiang Niu (@niugx), from the EaglEye Team for reporting these issues.19 * tempo: fix delay_ms methods20 * filterbank: fix aubio_filterbank_get_power (thanks to @romanbsd who21 also noticed this issue)22 * dct: creation fail on negative sizes or invalid accelerate radix,23 fix typo in error and warning messages, prevent possible memory leak24 * pitch: prevent null pointer dereference in yinfast, comment out unused25 functions in mcomb and yin, prevent possible leak in specacf26 * mfcc: always use dct module, strengthen input validation, change27 get_{scale,power} to return smpl_t28 * specdesc: improve error message29 * notes: prevent null pointer dereference30 * hist: add validation for size argument, prevent possible leak31 * awhitening: use shortest length available (closes gh-216)32 * io: add macros to display system errors, add helpers to validate input33 arguments of source and sink methods, always clean-up after failure34 * source: validate input sizes to prevent invalid reads35 * apple_audio: use native format conversions in source and sink, prevent36 possible apple_audio crash on empty string, get_duration returns 0 on failure37 * ffmpeg/avcodec: prevent deprecation warnings, read after close, and skipped38 samples warnings, improve warning messages, only show a warning when39 swr_convert failed, prevent possible memory leak when closing swr context40 * wavwrite: copy to all channels if needed, check fseek and fwrite return41 values, call fflush in open to return failure on full disk-system42 * source_sndfile: fix reading sizes when resampling, set error message when43 reading after close44 * aubio_priv.h: include blas first (see gh-225), add STRERROR macros45 46 [ Python ]47 48 * documentation: add pages to manual, add minimal docstrings for fft,49 digital_filter, and generated objects, improve specdesc documentation50 * filterbank: add get_norm/power documentation51 * source: take a copy of the last frame before resizing it, raise an52 exception when read failed, fix compilation warning53 * fixes: remove unneeded check convert with PyFloat_FromDouble or54 PyFloat_FromDouble, check if sink, digital_filter, were created before55 deleting56 57 [ Tests ]58 59 * python/tests/: switch to pytest (slightly slower than nose2 but better at60 capturing warnings and parametrization), improve coding style and coverage.61 Tests should now be run with `pytest`.62 * tests/: Each test program in C must now return 0, otherwise the test will63 fail. Examples have been modified to run themselves on a test audio file,64 but can still be run with arguments. Tests for `source` and `sink` have been65 factorised, and some code cleaning. A python script is used to create a66 test sound file. Tested on linux, macos, and windows, improvements to67 test-mfcc (closes gh-219).68 69 [ Build system ]70 71 * waf: upgrade to 2.0.14, check the return code of each test program,72 update rules to build manual and api documentation into build/, check73 for errno.h74 * osx: use -Os in scripts/build_apple_frameworks75 * Makefile: improve coverage reports76 * appveyor, travis, circleci: switch to pytest, set one travis config to use77 sndfile only78 * travis: add py3.6, drop py3.4, use py3.5 to test debug mode79 * azure: add basic configuration80 81 1 2018-11-21 Paul Brossier <piem@aubio.org> 82 2 -
MANIFEST.in
rdfe6ab6 r868c6b8 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 … … 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
rdfe6ab6 r868c6b8 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 . \ -
README.md
rdfe6ab6 r868c6b8 4 4 [](https://travis-ci.org/aubio/aubio "Travis build status") 5 5 [](https://ci.appveyor.com/project/piem/aubio "Appveyor build status") 6 [](https://landscape.io/github/aubio/aubio/master "Landscape code health") 6 7 [](https://github.com/aubio/aubio "Commits since last release") 7 8 -
VERSION
rdfe6ab6 r868c6b8 1 1 AUBIO_MAJOR_VERSION=0 2 AUBIO_MINOR_VERSION= 53 AUBIO_PATCH_VERSION= 02 AUBIO_MINOR_VERSION=4 3 AUBIO_PATCH_VERSION=9 4 4 AUBIO_VERSION_STATUS='~alpha' 5 5 LIBAUBIO_LT_CUR=5 -
azure-pipelines.yml
rdfe6ab6 r868c6b8 4 4 - job: linux 5 5 pool: 6 vmImage: ' ubuntu-16.04'6 vmImage: 'Ubuntu 16.04' 7 7 steps: 8 8 - script: | … … 14 14 - job: windows 15 15 pool: 16 vmI mage: 'vs2017-win2016'16 vmIMage: 'VS2017-Win2016' 17 17 steps: 18 18 - script: | … … 25 25 - job: macos 26 26 pool: 27 vmI mage: 'macos-10.13'27 vmIMage: macOS-10.13 28 28 steps: 29 29 - script: | -
doc/python_module.rst
rdfe6ab6 r868c6b8 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 -
doc/statuslinks.rst
rdfe6ab6 r868c6b8 10 10 :alt: Appveyor build status 11 11 12 .. image:: https://landscape.io/github/aubio/aubio/master/landscape.svg?style=flat 13 :target: https://landscape.io/github/aubio/aubio/master 14 :alt: Landscape code health 15 12 16 .. image:: https://readthedocs.org/projects/aubio/badge/?version=latest 13 17 :target: https://aubio.readthedocs.io/en/latest/?badge=latest -
examples/utils.c
rdfe6ab6 r868c6b8 185 185 186 186 del_aubio_source (this_source); 187 if (this_sink) 188 del_aubio_sink (this_sink); 187 del_aubio_sink (this_sink); 189 188 190 189 } -
python/demos/demo_wav2midi.py
rdfe6ab6 r868c6b8 64 64 if new_note[2] > 0: 65 65 track.append(Message('note_off', note=int(new_note[2]), 66 velocity=127, time= delta)66 velocity=127, time=0) 67 67 ) 68 68 track.append(Message('note_on', -
python/ext/py-filter.c
rdfe6ab6 r868c6b8 110 110 { 111 111 Py_XDECREF(self->out); 112 if (self->o) 113 del_aubio_filter (self->o); 112 del_aubio_filter (self->o); 114 113 Py_TYPE(self)->tp_free ((PyObject *) self); 115 114 } -
python/ext/py-sink.c
rdfe6ab6 r868c6b8 151 151 Py_sink_del (Py_sink *self, PyObject *unused) 152 152 { 153 if (self->o) { 154 del_aubio_sink(self->o); 155 free(self->mwrite_data.data); 156 } 153 del_aubio_sink(self->o); 154 free(self->mwrite_data.data); 157 155 if (self->uri) { 158 156 free(self->uri); -
python/ext/py-source.c
rdfe6ab6 r868c6b8 437 437 aubio_source_do (self->o, &(self->c_read_to), &read); 438 438 439 if (PyErr_Occurred() != NULL) {440 return NULL;441 }442 443 439 outputs = PyTuple_New(2); 444 440 PyTuple_SetItem( outputs, 0, self->read_to ); … … 461 457 /* compute _do function */ 462 458 aubio_source_do_multi (self->o, &(self->c_mread_to), &read); 463 464 if (PyErr_Occurred() != NULL) {465 return NULL;466 }467 459 468 460 outputs = PyTuple_New(2); … … 582 574 } else if (PyLong_AsLong(size) > 0) { 583 575 // short read, return a shorter array 584 PyObject *vec = PyTuple_GetItem(done, 0); 585 // take a copy to prevent resizing internal arrays 586 PyArrayObject *shortread = (PyArrayObject*)PyArray_FROM_OTF(vec, 587 NPY_NOTYPE, NPY_ARRAY_ENSURECOPY); 576 PyArrayObject *shortread = (PyArrayObject*)PyTuple_GetItem(done, 0); 588 577 PyArray_Dims newdims; 589 578 PyObject *reshaped; … … 598 587 reshaped = PyArray_Newshape(shortread, &newdims, NPY_CORDER); 599 588 Py_DECREF(shortread); 600 Py_DECREF(vec);601 589 return reshaped; 602 590 } else { -
python/lib/moresetuptools.py
rdfe6ab6 r868c6b8 69 69 for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H', 70 70 'HAVE_MATH_H', 'HAVE_STRING_H', 71 'HAVE_ ERRNO_H', 'HAVE_C99_VARARGS_MACROS',71 'HAVE_C99_VARARGS_MACROS', 72 72 'HAVE_LIMITS_H', 'HAVE_STDARG_H', 73 73 'HAVE_MEMCPY_HACKS']: -
python/tests/test_aubio.py
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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 utils import parse_file_samplerate 7 from _tools import parametrize, skipTest, assert_raises, assert_warns 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) 8 11 9 12 list_of_sounds = list_all_sounds('sounds') … … 21 24 all_params.append((hop_size, samplerate, soundfile)) 22 25 23 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\'') 24 31 25 32 def test_wrong_filename(self): 26 with assert_raises(RuntimeError):33 with self.assertRaises(RuntimeError): 27 34 sink('') 28 35 29 36 def test_wrong_samplerate(self): 30 with assert_raises(RuntimeError):37 with self.assertRaises(RuntimeError): 31 38 sink(get_tmp_sink_path(), -1) 32 39 33 40 def test_wrong_samplerate_too_large(self): 34 with assert_raises(RuntimeError):41 with self.assertRaises(RuntimeError): 35 42 sink(get_tmp_sink_path(), 1536001, 2) 36 43 37 44 def test_wrong_channels(self): 38 with assert_raises(RuntimeError):45 with self.assertRaises(RuntimeError): 39 46 sink(get_tmp_sink_path(), 44100, -1) 40 47 41 48 def test_wrong_channels_too_large(self): 42 with assert_raises(RuntimeError):49 with self.assertRaises(RuntimeError): 43 50 sink(get_tmp_sink_path(), 44100, 202020) 44 51 … … 60 67 shutil.rmtree(tmpdir) 61 68 62 @param etrize('hop_size, samplerate, path',all_params)69 @params(*all_params) 63 70 def test_read_and_write(self, hop_size, samplerate, path): 64 orig_samplerate = parse_file_samplerate(soundfile) 71 65 72 try: 66 if orig_samplerate is not None and orig_samplerate < samplerate: 67 # upsampling should emit a warning 68 with assert_warns(UserWarning): 69 f = source(soundfile, samplerate, hop_size) 70 else: 71 f = source(soundfile, samplerate, hop_size) 73 f = source(path, samplerate, hop_size) 72 74 except RuntimeError as e: 73 err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})' 74 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))) 75 76 if samplerate == 0: samplerate = f.samplerate 76 77 sink_path = get_tmp_sink_path() … … 84 85 del_tmp_sink_path(sink_path) 85 86 86 @param etrize('hop_size, samplerate, path',all_params)87 @params(*all_params) 87 88 def test_read_and_write_multi(self, hop_size, samplerate, path): 88 orig_samplerate = parse_file_samplerate(soundfile)89 89 try: 90 if orig_samplerate is not None and orig_samplerate < samplerate: 91 # upsampling should emit a warning 92 with assert_warns(UserWarning): 93 f = source(soundfile, samplerate, hop_size) 94 else: 95 f = source(soundfile, samplerate, hop_size) 90 f = source(path, samplerate, hop_size) 96 91 except RuntimeError as e: 97 err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})' 98 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))) 99 93 if samplerate == 0: samplerate = f.samplerate 100 94 sink_path = get_tmp_sink_path() … … 132 126 133 127 if __name__ == '__main__': 134 from _tools import run_module_suite 135 run_module_suite() 128 main() -
python/tests/test_slicing.py
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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, parse_file_samplerate7 import unittest 8 from _tools import assert_raises, assert_equal, assert_warns9 from _tools import parametrize, skipTest 7 from .utils import list_all_sounds 8 9 import warnings 10 warnings.filterwarnings('ignore', category=UserWarning, append=True) 10 11 11 12 list_of_sounds = list_all_sounds('sounds') … … 13 14 hop_sizes = [512, 1024, 64] 14 15 15 default_test_sound = len(list_of_sounds) and list_of_sounds[0] orNone16 path = None 16 17 17 18 all_params = [] … … 21 22 all_params.append((hop_size, samplerate, soundfile)) 22 23 23 no_sounds_msg = "no test sounds, add some in 'python/tests/sounds/'!"24 24 25 _debug = False 26 27 28 class Test_aubio_source_test_case(TestCase): 25 class aubio_source_test_case_base(TestCase): 29 26 30 27 def setUp(self): 31 if not default_test_sound: 32 skipTest(no_sounds_msg) 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] 33 31 34 def test_close_file(self): 32 class aubio_source_test_case(aubio_source_test_case_base): 33 34 @params(*list_of_sounds) 35 def test_close_file(self, filename): 35 36 samplerate = 0 # use native samplerate 36 37 hop_size = 256 37 f = source( default_test_sound, samplerate, hop_size)38 f = source(filename, samplerate, hop_size) 38 39 f.close() 39 40 40 def test_close_file_twice(self): 41 @params(*list_of_sounds) 42 def test_close_file_twice(self, filename): 41 43 samplerate = 0 # use native samplerate 42 44 hop_size = 256 43 f = source( default_test_sound, samplerate, hop_size)45 f = source(filename, samplerate, hop_size) 44 46 f.close() 45 47 f.close() 46 48 47 def test_read_after_close(self): 48 samplerate = 0 # use native samplerate 49 hop_size = 256 50 f = source(default_test_sound, samplerate, hop_size) 51 read, frames = f() 52 f.close() 53 with assert_raises(RuntimeError): 54 read, frames = f() 55 with assert_raises(RuntimeError): 56 read, frames = f.do_multi() 57 58 59 class Test_aubio_source_read(object): 49 class aubio_source_read_test_case(aubio_source_test_case_base): 60 50 61 51 def read_from_source(self, f): … … 67 57 assert_equal(samples[read:], 0) 68 58 break 69 if _debug: 70 result_str = "read {:.2f}s ({:d} frames" 71 result_str += " in {:d} blocks at {:d}Hz) from {:s}" 72 result_params = total_frames / float(f.samplerate), total_frames, \ 73 total_frames//f.hop_size, f.samplerate, f.uri 74 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)) 75 62 return total_frames 76 63 77 @param etrize('hop_size, samplerate, soundfile',all_params)64 @params(*all_params) 78 65 def test_samplerate_hopsize(self, hop_size, samplerate, soundfile): 79 orig_samplerate = parse_file_samplerate(soundfile)80 66 try: 81 if orig_samplerate is not None and orig_samplerate < samplerate: 82 # upsampling should emit a warning 83 with assert_warns(UserWarning): 84 f = source(soundfile, samplerate, hop_size) 85 else: 86 f = source(soundfile, samplerate, hop_size) 67 f = source(soundfile, samplerate, hop_size) 87 68 except RuntimeError as e: 88 err_msg = 'failed opening with hop_s={:d}, samplerate={:d} ({:s})' 89 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))) 90 70 assert f.samplerate != 0 91 71 read_frames = self.read_from_source(f) 92 72 if 'f_' in soundfile and samplerate == 0: 93 73 import re 94 f = re.compile( r'.*_\([0:9]*f\)_.*')74 f = re.compile('.*_\([0:9]*f\)_.*') 95 75 match_f = re.findall('([0-9]*)f_', soundfile) 96 76 if len(match_f) == 1: 97 77 expected_frames = int(match_f[0]) 98 assert_equal(expected_frames, read_frames)78 self.assertEqual(expected_frames, read_frames) 99 79 100 @param etrize('p',list_of_sounds)80 @params(*list_of_sounds) 101 81 def test_samplerate_none(self, p): 102 82 f = source(p) … … 104 84 self.read_from_source(f) 105 85 106 @param etrize('p',list_of_sounds)86 @params(*list_of_sounds) 107 87 def test_samplerate_0(self, p): 108 88 f = source(p, 0) … … 110 90 self.read_from_source(f) 111 91 112 @param etrize('p',list_of_sounds)92 @params(*list_of_sounds) 113 93 def test_zero_hop_size(self, p): 114 94 f = source(p, 0, 0) … … 117 97 self.read_from_source(f) 118 98 119 @param etrize('p',list_of_sounds)99 @params(*list_of_sounds) 120 100 def test_seek_to_half(self, p): 121 101 from random import randint … … 129 109 assert a == b + c 130 110 131 @param etrize('p',list_of_sounds)111 @params(*list_of_sounds) 132 112 def test_duration(self, p): 133 113 total_frames = 0 … … 138 118 total_frames += read 139 119 if read < f.hop_size: break 140 assert_equal(duration, total_frames)120 self.assertEqual(duration, total_frames) 141 121 142 122 143 class Test_aubio_source_wrong_params(object):123 class aubio_source_test_wrong_params(TestCase): 144 124 145 125 def test_wrong_file(self): 146 with assert_raises(RuntimeError):126 with self.assertRaises(RuntimeError): 147 127 source('path_to/unexisting file.mp3') 148 128 149 @unittest.skipIf(default_test_sound is None, no_sounds_msg) 150 class Test_aubio_source_wrong_params_with_file(TestCase): 129 class aubio_source_test_wrong_params_with_file(aubio_source_test_case_base): 151 130 152 131 def test_wrong_samplerate(self): 153 with assert_raises(ValueError):154 source( default_test_sound, -1)132 with self.assertRaises(ValueError): 133 source(self.default_test_sound, -1) 155 134 156 135 def test_wrong_hop_size(self): 157 with assert_raises(ValueError):158 source( default_test_sound, 0, -1)136 with self.assertRaises(ValueError): 137 source(self.default_test_sound, 0, -1) 159 138 160 139 def test_wrong_channels(self): 161 with assert_raises(ValueError):162 source( default_test_sound, 0, 0, -1)140 with self.assertRaises(ValueError): 141 source(self.default_test_sound, 0, 0, -1) 163 142 164 143 def test_wrong_seek(self): 165 f = source( default_test_sound)166 with assert_raises(ValueError):144 f = source(self.default_test_sound) 145 with self.assertRaises(ValueError): 167 146 f.seek(-1) 168 147 169 148 def test_wrong_seek_too_large(self): 170 f = source( default_test_sound)149 f = source(self.default_test_sound) 171 150 try: 172 with assert_raises(ValueError):151 with self.assertRaises(ValueError): 173 152 f.seek(f.duration + f.samplerate * 10) 174 except :175 s kipTest('seeking after end of stream failed raising ValueError')153 except AssertionError: 154 self.skipTest('seeking after end of stream failed raising ValueError') 176 155 177 class Test_aubio_source_readmulti(Test_aubio_source_read):156 class aubio_source_readmulti_test_case(aubio_source_read_test_case): 178 157 179 158 def read_from_source(self, f): … … 185 164 assert_equal(samples[:,read:], 0) 186 165 break 187 if _debug: 188 result_str = "read {:.2f}s ({:d} frames in {:d} channels" 189 result_str += " and {:d} blocks at {:d}Hz) from {:s}" 190 result_params = total_frames / float(f.samplerate), total_frames, \ 191 f.channels, int(total_frames/f.hop_size), \ 192 f.samplerate, f.uri 193 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)) 194 169 return total_frames 195 170 196 class Test_aubio_source_with(object):171 class aubio_source_with(aubio_source_test_case_base): 197 172 198 @parametrize('filename', list_of_sounds) 173 #@params(*list_of_sounds) 174 @params(*list_of_sounds) 199 175 def test_read_from_mono(self, filename): 200 176 total_frames = 0 … … 210 186 211 187 if __name__ == '__main__': 212 from _tools import run_module_suite 213 run_module_suite() 188 main() -
python/tests/test_source_channels.py
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 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
rdfe6ab6 r868c6b8 2 2 3 3 import os 4 import re5 4 import glob 6 5 import numpy as np … … 10 9 11 10 def array_from_text_file(filename, dtype = 'float'): 12 realpathname = os.path.join(os.path.dirname(__file__), filename) 13 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) 14 16 15 17 def list_all_sounds(rel_dir): … … 37 39 os.unlink(path) 38 40 except WindowsError as e: 39 # removing the temporary directory sometimes fails on windows 40 import warnings 41 errmsg = "failed deleting temporary file {:s} ({:s})" 42 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))) 43 48 44 49 def array_from_yaml_file(filename): … … 79 84 total_files += 1 80 85 return total_files 81 82 def parse_file_samplerate(soundfile):83 samplerate = None84 # parse samplerate85 re_sr = re.compile(r'/([0-9]{4,})Hz_.*')86 match_samplerate = re_sr.findall(soundfile)87 if match_samplerate:88 samplerate = int(match_samplerate[0])89 else:90 import warnings91 warnings.warn(UserWarning("could not parse samplerate for {:s}"92 .format(soundfile)))93 return samplerate -
requirements.txt
rdfe6ab6 r868c6b8 1 1 numpy 2 pytest 2 nose2 -
scripts/build_apple_frameworks
rdfe6ab6 r868c6b8 14 14 #VERSION+=+$(git log --pretty=format:"%h" -1) 15 15 16 CFLAGS="-Werror -O s"16 CFLAGS="-Werror -Ofast" 17 17 WAFCONF="--disable-sndfile --disable-avcodec --disable-samplerate --enable-fat" # --disable-memcpy --disable-accelerate" 18 18 -
scripts/get_waf.sh
rdfe6ab6 r868c6b8 4 4 #set -x 5 5 6 WAFVERSION=2.0.1 46 WAFVERSION=2.0.13 7 7 WAFTARBALL=waf-$WAFVERSION.tar.bz2 8 8 WAFURL=https://waf.io/$WAFTARBALL -
setup.py
rdfe6ab6 r868c6b8 96 96 ], 97 97 }, 98 test_suite = 'nose2.collector.collector', 99 extras_require = { 100 'tests': ['numpy'], 101 }, 98 102 ) -
src/aubio_priv.h
rdfe6ab6 r868c6b8 63 63 #endif 64 64 65 #ifdef HAVE_ERRNO_H66 #include <errno.h>67 #endif68 69 65 #ifdef HAVE_LIMITS_H 70 66 #include <limits.h> // for CHAR_BIT, in C99 standard … … 75 71 #endif 76 72 77 #if defined(HAVE_BLAS) // --enable-blas=true 78 // check which cblas header we found 73 #if defined(HAVE_ACCELERATE) 74 #define HAVE_ATLAS 1 75 #define HAVE_BLAS 1 76 #include <Accelerate/Accelerate.h> 77 #elif defined(HAVE_ATLAS_CBLAS_H) 78 #elif defined(HAVE_BLAS) 79 79 #if defined(HAVE_ATLAS_CBLAS_H) 80 80 #define HAVE_ATLAS 1 … … 84 84 #elif defined(HAVE_CBLAS_H) 85 85 #include <cblas.h> 86 #elif !defined(HAVE_ACCELERATE) 87 #error "HAVE_BLAS was defined, but no blas header was found" 88 #endif /* end of cblas includes */ 89 #endif 90 91 #if defined(HAVE_ACCELERATE) 92 // include accelerate framework after blas 93 #define HAVE_ATLAS 1 94 #define HAVE_BLAS 1 86 #endif 87 #endif 88 89 #ifdef HAVE_ACCELERATE 95 90 #include <Accelerate/Accelerate.h> 96 97 91 #ifndef HAVE_AUBIO_DOUBLE 98 92 #define aubio_vDSP_mmov vDSP_mmov … … 331 325 #endif 332 326 333 #if !defined(_MSC_VER)334 #define AUBIO_STRERROR(errno,buf,len) strerror_r(errno, buf, len)335 #else336 #define AUBIO_STRERROR(errno,buf,len) strerror_s(buf, len, errno)337 #endif338 339 #ifdef HAVE_C99_VARARGS_MACROS340 #define AUBIO_STRERR(...) \341 char errorstr[256]; \342 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); \343 AUBIO_ERR(__VA_ARGS__)344 #else345 #define AUBIO_STRERR(format, args...) \346 char errorstr[256]; \347 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); \348 AUBIO_ERR(format, ##args)349 #endif350 351 327 /* handy shortcuts */ 352 328 #define DB2LIN(g) (POW(10.0,(g)*0.05f)) -
src/io/ioutils.c
rdfe6ab6 r868c6b8 20 20 21 21 #include "aubio_priv.h" 22 #include "fmat.h"23 22 24 23 uint_t … … 52 51 } 53 52 return AUBIO_OK; 54 }55 56 uint_t57 aubio_source_validate_input_length(const char_t *kind, const char_t *path,58 uint_t hop_size, uint_t read_data_length)59 {60 uint_t length = hop_size;61 if (hop_size < read_data_length) {62 AUBIO_WRN("%s: partial read from %s, trying to read %d frames, but"63 " hop_size is %d\n", kind, path, read_data_length, hop_size);64 } else if (hop_size > read_data_length) {65 AUBIO_WRN("%s: partial read from %s, trying to read %d frames into"66 " a buffer of length %d\n", kind, path, hop_size, read_data_length);67 length = read_data_length;68 }69 return length;70 }71 72 uint_t73 aubio_source_validate_input_channels(const char_t *kind, const char_t *path,74 uint_t source_channels, uint_t read_data_height)75 {76 uint_t channels = source_channels;77 if (read_data_height < source_channels) {78 AUBIO_WRN("%s: partial read from %s, trying to read %d channels,"79 " but found output of height %d\n", kind, path, source_channels,80 read_data_height);81 channels = read_data_height;82 } else if (read_data_height > source_channels) {83 // do not show a warning when trying to read into more channels than84 // the input source.85 #if 086 AUBIO_WRN("%s: partial read from %s, trying to read %d channels,"87 " but found output of height %d\n", kind, path, source_channels,88 read_data_height);89 #endif90 channels = source_channels;91 }92 return channels;93 }94 95 void96 aubio_source_pad_output (fvec_t *read_data, uint_t source_read)97 {98 if (source_read < read_data->length) {99 AUBIO_MEMSET(read_data->data + source_read, 0,100 (read_data->length - source_read) * sizeof(smpl_t));101 }102 }103 104 void105 aubio_source_pad_multi_output (fmat_t *read_data,106 uint_t source_channels, uint_t source_read) {107 uint_t i;108 if (source_read < read_data->length) {109 for (i = 0; i < read_data->height; i++) {110 AUBIO_MEMSET(read_data->data[i] + source_read, 0,111 (read_data->length - source_read) * sizeof(smpl_t));112 }113 }114 115 // destination matrix has more channels than the file116 // copy channels from the source to extra output channels117 if (read_data->height > source_channels) {118 for (i = source_channels; i < read_data->height; i++) {119 AUBIO_MEMCPY(read_data->data[i], read_data->data[i % source_channels],120 sizeof(smpl_t) * read_data->length);121 }122 }123 53 } 124 54 -
src/io/ioutils.h
rdfe6ab6 r868c6b8 54 54 uint_t channels); 55 55 56 /** validate length of source output 57 58 \param kind the object kind to report on 59 \param path the path to report on 60 \param hop_size number of frames to be read 61 \param read_data_length actual length of input 62 63 \return hop_size or the maximum number of frames that can be written 64 */ 65 uint_t 66 aubio_source_validate_input_length(const char_t *kind, const char_t *path, 67 uint_t hop_size, uint_t read_data_length); 68 69 /** validate height of source output 70 71 \param kind the object kind to report on 72 \param path the path to report on 73 \param source_channels maximum number of channels that can be written 74 \param read_data_height actual height of input 75 76 \return write_data_height or the maximum number of channels 77 */ 78 uint_t 79 aubio_source_validate_input_channels(const char_t *kind, const char_t *path, 80 uint_t source_channels, uint_t read_data_height); 81 82 /** pad end of source output vector with zeroes 83 84 \param read_data output vector to pad 85 \param source_read number of frames read 86 87 */ 88 void 89 aubio_source_pad_output (fvec_t *read_data, uint_t source_read); 90 91 /** pad end of source output matrix with zeroes 92 93 \param read_data output matrix to pad 94 \param source_channels number of channels in the source 95 \param source_read number of frames read 96 97 */ 98 void 99 aubio_source_pad_multi_output (fmat_t *read_data, uint_t source_channels, 100 uint_t source_read); 101 102 /** validate length of sink input 56 /** validate length of input 103 57 104 58 \param kind the object kind to report on 105 59 \param path the path to report on 106 60 \param max_size maximum number of frames that can be written 107 \param write_data_length actual length of input 61 \param write_data_length actual length of input vector/matrix 108 62 \param write number of samples asked 109 63 … … 114 68 uint_t max_size, uint_t write_data_length, uint_t write); 115 69 116 /** validate height of sinkinput70 /** validate height of input 117 71 118 72 \param kind the object kind to report on 119 73 \param path the path to report on 120 \param sink_channelsmaximum number of channels that can be written74 \param max_size maximum number of channels that can be written 121 75 \param write_data_height actual height of input matrix 122 76 -
src/io/sink.c
rdfe6ab6 r868c6b8 136 136 137 137 void del_aubio_sink(aubio_sink_t * s) { 138 //AUBIO_ASSERT(s);139 if (s && s->s_del && s->sink)138 AUBIO_ASSERT(s); 139 if (s->s_del && s->sink) 140 140 s->s_del((void *)s->sink); 141 141 AUBIO_FREE(s); -
src/io/sink_wavwrite.c
rdfe6ab6 r868c6b8 28 28 #include "io/sink_wavwrite.h" 29 29 #include "io/ioutils.h" 30 31 #include <errno.h> 30 32 31 33 #define MAX_SIZE 4096 … … 161 163 unsigned char buf[5]; 162 164 uint_t byterate, blockalign; 163 size_t written = 0;164 165 165 166 /* open output file */ 166 167 s->fid = fopen((const char *)s->path, "wb"); 167 168 if (!s->fid) { 168 AUBIO_ STRERR("sink_wavwrite: could not open %s (%s)\n", s->path, errorstr);169 AUBIO_ERR("sink_wavwrite: could not open %s (%s)\n", s->path, strerror(errno)); 169 170 goto beach; 170 171 } 171 172 172 173 // ChunkID 173 written +=fwrite("RIFF", 4, 1, s->fid);174 fwrite("RIFF", 4, 1, s->fid); 174 175 175 176 // ChunkSize (0 for now, actual size will be written in _close) 176 written +=fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);177 fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid); 177 178 178 179 // Format 179 written +=fwrite("WAVE", 4, 1, s->fid);180 fwrite("WAVE", 4, 1, s->fid); 180 181 181 182 // Subchunk1ID 182 written +=fwrite("fmt ", 4, 1, s->fid);183 fwrite("fmt ", 4, 1, s->fid); 183 184 184 185 // Subchunk1Size 185 written +=fwrite(write_little_endian(16, buf, 4), 4, 1, s->fid);186 fwrite(write_little_endian(16, buf, 4), 4, 1, s->fid); 186 187 187 188 // AudioFormat 188 written +=fwrite(write_little_endian(1, buf, 2), 2, 1, s->fid);189 fwrite(write_little_endian(1, buf, 2), 2, 1, s->fid); 189 190 190 191 // NumChannels 191 written +=fwrite(write_little_endian(s->channels, buf, 2), 2, 1, s->fid);192 fwrite(write_little_endian(s->channels, buf, 2), 2, 1, s->fid); 192 193 193 194 // SampleRate 194 written +=fwrite(write_little_endian(s->samplerate, buf, 4), 4, 1, s->fid);195 fwrite(write_little_endian(s->samplerate, buf, 4), 4, 1, s->fid); 195 196 196 197 // ByteRate 197 198 byterate = s->samplerate * s->channels * s->bitspersample / 8; 198 written +=fwrite(write_little_endian(byterate, buf, 4), 4, 1, s->fid);199 fwrite(write_little_endian(byterate, buf, 4), 4, 1, s->fid); 199 200 200 201 // BlockAlign 201 202 blockalign = s->channels * s->bitspersample / 8; 202 written +=fwrite(write_little_endian(blockalign, buf, 2), 2, 1, s->fid);203 fwrite(write_little_endian(blockalign, buf, 2), 2, 1, s->fid); 203 204 204 205 // BitsPerSample 205 written +=fwrite(write_little_endian(s->bitspersample, buf, 2), 2, 1, s->fid);206 fwrite(write_little_endian(s->bitspersample, buf, 2), 2, 1, s->fid); 206 207 207 208 // Subchunk2ID 208 written +=fwrite("data", 4, 1, s->fid);209 fwrite("data", 4, 1, s->fid); 209 210 210 211 // Subchunk1Size (0 for now, actual size will be written in _close) 211 written += fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid); 212 213 // fwrite(*, *, 1, s->fid) was called 13 times, check success 214 if (written != 13 || fflush(s->fid)) { 215 AUBIO_STRERR("sink_wavwrite: writing header to %s failed" 216 " (wrote %d/%d, %s)\n", s->path, written, 13, errorstr); 217 fclose(s->fid); 218 s->fid = NULL; 219 return AUBIO_FAIL; 220 } 212 fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid); 221 213 222 214 s->scratch_size = s->max_size * s->channels; … … 235 227 } 236 228 237 static238 void aubio_sink_wavwrite_write_frames(aubio_sink_wavwrite_t *s, uint_t write)239 {240 uint_t written_frames = 0;241 242 written_frames = fwrite(s->scratch_data, 2 * s->channels, write, s->fid);243 244 if (written_frames != write) {245 AUBIO_STRERR("sink_wavwrite: trying to write %d frames to %s, but only %d"246 " could be written (%s)\n", write, s->path, written_frames, errorstr);247 }248 s->total_frames_written += written_frames;249 }250 229 251 230 void aubio_sink_wavwrite_do(aubio_sink_wavwrite_t *s, fvec_t * write_data, uint_t write){ 252 uint_t c = 0, i = 0 ;231 uint_t c = 0, i = 0, written_frames = 0; 253 232 uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path, 254 233 s->max_size, write_data->length, write); … … 259 238 } 260 239 } 261 262 aubio_sink_wavwrite_write_frames(s, length); 240 written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid); 241 242 if (written_frames != write) { 243 AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, " 244 "but only %d could be written\n", write, s->path, written_frames); 245 } 246 s->total_frames_written += written_frames; 247 return; 263 248 } 264 249 265 250 void aubio_sink_wavwrite_do_multi(aubio_sink_wavwrite_t *s, fmat_t * write_data, uint_t write){ 266 uint_t c = 0, i = 0 ;251 uint_t c = 0, i = 0, written_frames = 0; 267 252 268 253 uint_t channels = aubio_sink_validate_input_channels("sink_wavwrite", s->path, … … 276 261 } 277 262 } 278 279 aubio_sink_wavwrite_write_frames(s, length); 263 written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid); 264 265 if (written_frames != write * s->channels) { 266 AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, " 267 "but only %d could be written\n", write, s->path, written_frames / s->channels); 268 } 269 s->total_frames_written += written_frames; 270 return; 280 271 } 281 272 … … 283 274 uint_t data_size = s->total_frames_written * s->bitspersample * s->channels / 8; 284 275 unsigned char buf[5]; 285 size_t written = 0, err = 0;286 276 if (!s->fid) return AUBIO_FAIL; 287 277 // ChunkSize 288 err +=fseek(s->fid, 4, SEEK_SET);289 written +=fwrite(write_little_endian(data_size + 36, buf, 4), 4, 1, s->fid);278 fseek(s->fid, 4, SEEK_SET); 279 fwrite(write_little_endian(data_size + 36, buf, 4), 4, 1, s->fid); 290 280 // Subchunk2Size 291 err += fseek(s->fid, 40, SEEK_SET); 292 written += fwrite(write_little_endian(data_size, buf, 4), 4, 1, s->fid); 293 if (written != 2 || err != 0) { 294 AUBIO_STRERR("sink_wavwrite: updating header of %s failed, expected %d" 295 " write but got only %d (%s)\n", s->path, 2, written, errorstr); 296 } 281 fseek(s->fid, 40, SEEK_SET); 282 fwrite(write_little_endian(data_size, buf, 4), 4, 1, s->fid); 297 283 // close file 298 284 if (fclose(s->fid)) { 299 AUBIO_ STRERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, errorstr);285 AUBIO_ERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, strerror(errno)); 300 286 } 301 287 s->fid = NULL; -
src/io/source.c
rdfe6ab6 r868c6b8 139 139 140 140 void del_aubio_source(aubio_source_t * s) { 141 //AUBIO_ASSERT(s);142 if (s && s->s_del && s->source)141 AUBIO_ASSERT(s); 142 if (s->s_del && s->source) 143 143 s->s_del((void *)s->source); 144 144 AUBIO_FREE(s); -
src/io/source_apple_audio.c
rdfe6ab6 r868c6b8 25 25 #include "fvec.h" 26 26 #include "fmat.h" 27 #include "ioutils.h"28 27 #include "io/source_apple_audio.h" 29 28 … … 211 210 uint_t c, v; 212 211 UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s); 213 uint_t length = aubio_source_validate_input_length("source_apple_audio",214 s->path, s->block_size, read_to->length);215 212 smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData; 216 213 217 length = MIN(loadedPackets, length); 218 219 for (v = 0; v < length; v++) { 214 for (v = 0; v < loadedPackets; v++) { 220 215 read_to->data[v] = 0.; 221 216 for (c = 0; c < s->channels; c++) { … … 225 220 } 226 221 // short read, fill with zeros 227 aubio_source_pad_output(read_to, length); 228 229 *read = (uint_t)length; 222 if (loadedPackets < s->block_size) { 223 for (v = loadedPackets; v < s->block_size; v++) { 224 read_to->data[v] = 0.; 225 } 226 } 227 228 *read = (uint_t)loadedPackets; 229 return; 230 230 } 231 231 232 232 void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) { 233 233 uint_t c, v; 234 uint_t length = aubio_source_validate_input_length("source_apple_audio",235 s->path, s->block_size, read_to->length);236 uint_t channels = aubio_source_validate_input_channels("source_apple_audio",237 s->path, s->channels, read_to->height);238 234 UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s); 239 235 smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData; 240 236 241 length = MIN(loadedPackets, length); 242 243 for (v = 0; v < length; v++) { 244 for (c = 0; c < channels; c++) { 237 for (v = 0; v < loadedPackets; v++) { 238 for (c = 0; c < read_to->height; c++) { 245 239 read_to->data[c][v] = data[ v * s->channels + c]; 246 240 } 247 241 } 248 249 aubio_source_pad_multi_output(read_to, s->channels, (uint_t)length); 250 251 *read = (uint_t)length; 242 // if read_data has more channels than the file 243 if (read_to->height > s->channels) { 244 // copy last channel to all additional channels 245 for (v = 0; v < loadedPackets; v++) { 246 for (c = s->channels; c < read_to->height; c++) { 247 read_to->data[c][v] = data[ v * s->channels + (s->channels - 1)]; 248 } 249 } 250 } 251 // short read, fill with zeros 252 if (loadedPackets < s->block_size) { 253 for (v = loadedPackets; v < s->block_size; v++) { 254 for (c = 0; c < read_to->height; c++) { 255 read_to->data[c][v] = 0.; 256 } 257 } 258 } 259 260 *read = (uint_t)loadedPackets; 261 return; 252 262 } 253 263 … … 345 355 "error in ExtAudioFileGetProperty (%s)\n", s->path, 346 356 getPrintableOSStatusError(errorstr, err)); 347 return 0;357 return err; 348 358 } 349 359 return (uint_t)fileLengthFrames; -
src/io/source_avcodec.c
rdfe6ab6 r868c6b8 31 31 #endif 32 32 #include <libavutil/opt.h> 33 #include <stdlib.h> 33 34 34 35 // determine whether we use libavformat from ffmpeg or from libav … … 60 61 #include "fvec.h" 61 62 #include "fmat.h" 62 #include "ioutils.h"63 63 #include "source_avcodec.h" 64 64 … … 120 120 uint_t samplerate, uint_t hop_size) { 121 121 aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t); 122 AVFormatContext *avFormatCtx = NULL;123 AVCodecContext *avCodecCtx = NULL;124 AVFrame *avFrame = NULL;122 AVFormatContext *avFormatCtx = s->avFormatCtx; 123 AVCodecContext *avCodecCtx = s->avCodecCtx; 124 AVFrame *avFrame = s->avFrame; 125 125 sint_t selected_stream = -1; 126 126 #if FF_API_LAVF_AVCTX … … 464 464 (const uint8_t **)avFrame->data, in_samples); 465 465 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */ 466 if (out_samples < 0) {467 AUBIO_WRN("source_avcodec: error while resampling %s (%d)\n",468 s->path , out_samples);466 if (out_samples <= 0) { 467 AUBIO_WRN("source_avcodec: no sample found while converting frame (%s)\n", 468 s->path); 469 469 goto beach; 470 470 } … … 473 473 474 474 beach: 475 s->avFormatCtx = avFormatCtx; 476 s->avCodecCtx = avCodecCtx; 477 s->avFrame = avFrame; 478 #if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE) 479 s->avr = avr; 480 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */ 481 s->output = output; 482 475 483 av_packet_unref(&avPacket); 476 484 } … … 481 489 uint_t end = 0; 482 490 uint_t total_wrote = 0; 483 uint_t length = aubio_source_validate_input_length("source_avcodec", s->path, 484 s->hop_size, read_data->length); 485 if (!s->avr || !s->avFormatCtx || !s->avCodecCtx) { 486 AUBIO_ERR("source_avcodec: could not read from %s (file was closed)\n", 487 s->path); 488 *read= 0; 489 return; 490 } 491 while (total_wrote < length) { 492 end = MIN(s->read_samples - s->read_index, length - total_wrote); 491 while (total_wrote < s->hop_size) { 492 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); 493 493 for (i = 0; i < end; i++) { 494 494 read_data->data[i + total_wrote] = 0.; … … 500 500 } 501 501 total_wrote += end; 502 if (total_wrote < length) {502 if (total_wrote < s->hop_size) { 503 503 uint_t avcodec_read = 0; 504 504 aubio_source_avcodec_readframe(s, &avcodec_read); … … 512 512 } 513 513 } 514 515 aubio_source_pad_output(read_data, total_wrote); 516 514 if (total_wrote < s->hop_size) { 515 for (i = total_wrote; i < s->hop_size; i++) { 516 read_data->data[i] = 0.; 517 } 518 } 517 519 *read = total_wrote; 518 520 } … … 523 525 uint_t end = 0; 524 526 uint_t total_wrote = 0; 525 uint_t length = aubio_source_validate_input_length("source_avcodec", s->path, 526 s->hop_size, read_data->length); 527 uint_t channels = aubio_source_validate_input_channels("source_avcodec", 528 s->path, s->input_channels, read_data->height); 529 if (!s->avr || !s->avFormatCtx || !s->avCodecCtx) { 530 AUBIO_ERR("source_avcodec: could not read from %s (file was closed)\n", 531 s->path); 532 *read= 0; 533 return; 534 } 535 while (total_wrote < length) { 536 end = MIN(s->read_samples - s->read_index, length - total_wrote); 537 for (j = 0; j < channels; j++) { 527 while (total_wrote < s->hop_size) { 528 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); 529 for (j = 0; j < read_data->height; j++) { 538 530 for (i = 0; i < end; i++) { 539 531 read_data->data[j][i + total_wrote] = … … 542 534 } 543 535 total_wrote += end; 544 if (total_wrote < length) {536 if (total_wrote < s->hop_size) { 545 537 uint_t avcodec_read = 0; 546 538 aubio_source_avcodec_readframe(s, &avcodec_read); … … 554 546 } 555 547 } 556 557 aubio_source_pad_multi_output(read_data, s->input_channels, total_wrote); 558 548 if (total_wrote < s->hop_size) { 549 for (j = 0; j < read_data->height; j++) { 550 for (i = total_wrote; i < s->hop_size; i++) { 551 read_data->data[j][i] = 0.; 552 } 553 } 554 } 559 555 *read = total_wrote; 560 556 } … … 620 616 #ifdef HAVE_AVRESAMPLE 621 617 avresample_close( s->avr ); 618 #elif defined(HAVE_SWRESAMPLE) 619 swr_close ( s->avr ); 620 #endif 622 621 av_free ( s->avr ); 623 #elif defined(HAVE_SWRESAMPLE)624 swr_close ( s->avr );625 swr_free ( &s->avr );626 #endif627 622 } 628 623 s->avr = NULL; -
src/io/source_sndfile.c
rdfe6ab6 r868c6b8 27 27 #include "fvec.h" 28 28 #include "fmat.h" 29 #include "ioutils.h"30 29 #include "source_sndfile.h" 31 30 … … 171 170 uint_t i,j, input_channels = s->input_channels; 172 171 /* read from file into scratch_data */ 173 uint_t length = aubio_source_validate_input_length("source_sndfile", s->path, 174 s->hop_size, read_data->length); 175 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, 176 s->scratch_size); 177 uint_t read_length = read_samples / s->input_channels; 172 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size); 178 173 179 174 /* where to store de-interleaved data */ 180 175 smpl_t *ptr_data; 181 182 if (!s->handle) {183 AUBIO_ERR("source_sndfile: could not read from %s (file was closed)\n",184 s->path);185 *read = 0;186 return;187 }188 189 176 #ifdef HAVE_SAMPLERATE 190 177 if (s->ratio != 1) { … … 193 180 #endif /* HAVE_SAMPLERATE */ 194 181 { 195 read_length = MIN(length, read_length);196 182 ptr_data = read_data->data; 197 183 } 198 184 199 185 /* de-interleaving and down-mixing data */ 200 for (j = 0; j < read_ length; j++) {186 for (j = 0; j < read_samples / input_channels; j++) { 201 187 ptr_data[j] = 0; 202 188 for (i = 0; i < input_channels; i++) { … … 212 198 #endif /* HAVE_SAMPLERATE */ 213 199 214 *read = MIN(length, (uint_t)FLOOR(s->ratio * read_length + .5)); 215 216 aubio_source_pad_output (read_data, *read); 200 *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5); 201 202 if (*read < s->hop_size) { 203 for (j = *read; j < s->hop_size; j++) { 204 read_data->data[j] = 0; 205 } 206 } 217 207 218 208 } … … 221 211 uint_t i,j, input_channels = s->input_channels; 222 212 /* do actual reading */ 223 uint_t length = aubio_source_validate_input_length("source_sndfile", s->path, 224 s->hop_size, read_data->length); 225 uint_t channels = aubio_source_validate_input_channels("source_sndfile", 226 s->path, s->input_channels, read_data->height); 227 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, 228 s->scratch_size); 229 uint_t read_length = read_samples / s->input_channels; 213 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size); 230 214 231 215 /* where to store de-interleaved data */ 232 216 smpl_t **ptr_data; 233 234 if (!s->handle) {235 AUBIO_ERR("source_sndfile: could not read from %s (file was closed)\n",236 s->path);237 *read = 0;238 return;239 }240 241 217 #ifdef HAVE_SAMPLERATE 242 218 if (s->ratio != 1) { … … 245 221 #endif /* HAVE_SAMPLERATE */ 246 222 { 247 read_length = MIN(read_length, length);248 223 ptr_data = read_data->data; 249 224 } 250 225 251 for (j = 0; j < read_length; j++) { 252 for (i = 0; i < channels; i++) { 253 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 226 if (read_data->height < input_channels) { 227 // destination matrix has less channels than the file; copy only first 228 // channels of the file, de-interleaving data 229 for (j = 0; j < read_samples / input_channels; j++) { 230 for (i = 0; i < read_data->height; i++) { 231 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 232 } 233 } 234 } else { 235 // destination matrix has as many or more channels than the file; copy each 236 // channel from the file to the destination matrix, de-interleaving data 237 for (j = 0; j < read_samples / input_channels; j++) { 238 for (i = 0; i < input_channels; i++) { 239 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 240 } 241 } 242 } 243 244 if (read_data->height > input_channels) { 245 // destination matrix has more channels than the file; copy last channel 246 // of the file to each additional channels, de-interleaving data 247 for (j = 0; j < read_samples / input_channels; j++) { 248 for (i = input_channels; i < read_data->height; i++) { 249 ptr_data[i][j] = s->scratch_data[j * input_channels + (input_channels - 1)]; 250 } 254 251 } 255 252 } … … 268 265 #endif /* HAVE_SAMPLERATE */ 269 266 270 *read = MIN(length, (uint_t)FLOOR(s->ratio * read_length + .5)); 271 272 aubio_source_pad_multi_output(read_data, input_channels, *read); 267 *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5); 268 269 if (*read < s->hop_size) { 270 for (i = 0; i < read_data->height; i++) { 271 for (j = *read; j < s->hop_size; j++) { 272 read_data->data[i][j] = 0.; 273 } 274 } 275 } 276 273 277 } 274 278 -
src/io/source_wavread.c
rdfe6ab6 r868c6b8 25 25 #include "fvec.h" 26 26 #include "fmat.h" 27 #include "ioutils.h"28 27 #include "source_wavread.h" 29 28 29 #include <errno.h> 30 30 31 #define AUBIO_WAVREAD_BUFSIZE 1024 31 32 32 //#define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)33 #define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05) 33 34 34 35 struct _aubio_source_wavread_t { … … 99 100 s->fid = fopen((const char *)path, "rb"); 100 101 if (!s->fid) { 101 AUBIO_ STRERR("source_wavread: Failed opening %s (%s)\n", s->path, errorstr);102 AUBIO_ERR("source_wavread: Failed opening %s (System error: %s)\n", s->path, strerror(errno)); 102 103 goto beach; 103 104 } … … 132 133 bytes_junk += read_little_endian(buf, 4); 133 134 if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) { 134 AUBIO_ STRERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n",135 s->path, errorstr);135 AUBIO_ERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n", 136 s->path, strerror(errno)); 136 137 goto beach; 137 138 } … … 260 261 bytes_junk += read_little_endian(buf, 4); 261 262 if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) { 262 AUBIO_ STRERR("source_wavread: could not seek past unknown chunk in %s (%s)\n",263 s->path, errorstr);263 AUBIO_ERR("source_wavread: could not seek past unknown chunk in %s (%s)\n", 264 s->path, strerror(errno)); 264 265 goto beach; 265 266 } … … 347 348 uint_t end = 0; 348 349 uint_t total_wrote = 0; 349 uint_t length = aubio_source_validate_input_length("source_wavread", s->path,350 s->hop_size, read_data->length);351 350 if (s->fid == NULL) { 352 351 AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n", … … 354 353 return; 355 354 } 356 while (total_wrote < length) {357 end = MIN(s->read_samples - s->read_index, length- total_wrote);355 while (total_wrote < s->hop_size) { 356 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); 358 357 for (i = 0; i < end; i++) { 359 358 read_data->data[i + total_wrote] = 0; … … 364 363 } 365 364 total_wrote += end; 366 if (total_wrote < length) {365 if (total_wrote < s->hop_size) { 367 366 uint_t wavread_read = 0; 368 367 aubio_source_wavread_readframe(s, &wavread_read); … … 376 375 } 377 376 } 378 379 aubio_source_pad_output (read_data, total_wrote); 380 377 if (total_wrote < s->hop_size) { 378 for (i = end; i < s->hop_size; i++) { 379 read_data->data[i] = 0.; 380 } 381 } 381 382 *read = total_wrote; 382 383 } … … 386 387 uint_t end = 0; 387 388 uint_t total_wrote = 0; 388 uint_t length = aubio_source_validate_input_length("source_wavread", s->path,389 s->hop_size, read_data->length);390 uint_t channels = aubio_source_validate_input_channels("source_wavread",391 s->path, s->input_channels, read_data->height);392 389 if (s->fid == NULL) { 393 390 AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n", … … 395 392 return; 396 393 } 397 while (total_wrote < length) {398 end = MIN(s->read_samples - s->read_index, length- total_wrote);399 for (j = 0; j < channels; j++) {394 while (total_wrote < s->hop_size) { 395 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); 396 for (j = 0; j < read_data->height; j++) { 400 397 for (i = 0; i < end; i++) { 401 398 read_data->data[j][i + total_wrote] = s->output->data[j][i]; … … 403 400 } 404 401 total_wrote += end; 405 if (total_wrote < length) {402 if (total_wrote < s->hop_size) { 406 403 uint_t wavread_read = 0; 407 404 aubio_source_wavread_readframe(s, &wavread_read); … … 415 412 } 416 413 } 417 418 aubio_source_pad_multi_output(read_data, s->input_channels, total_wrote); 419 414 if (total_wrote < s->hop_size) { 415 for (j = 0; j < read_data->height; j++) { 416 for (i = end; i < s->hop_size; i++) { 417 read_data->data[j][i] = 0.; 418 } 419 } 420 } 420 421 *read = total_wrote; 421 422 } … … 441 442 ret = fseek(s->fid, s->seek_start + pos * s->blockalign, SEEK_SET); 442 443 if (ret != 0) { 443 AUBIO_ STRERR("source_wavread: could not seek %s at %d (%s)\n", s->path, pos, errorstr);444 AUBIO_ERR("source_wavread: could not seek %s at %d (%s)\n", s->path, pos, strerror(errno)); 444 445 return AUBIO_FAIL; 445 446 } … … 462 463 } 463 464 if (fclose(s->fid)) { 464 AUBIO_ STRERR("source_wavread: could not close %s (%s)\n", s->path, errorstr);465 AUBIO_ERR("source_wavread: could not close %s (%s)\n", s->path, strerror(errno)); 465 466 return AUBIO_FAIL; 466 467 } -
tests/src/io/base-sink_custom.h
rdfe6ab6 r868c6b8 152 152 close_temp_sink(sink_path, fd); 153 153 154 // shouldn't crash on null (bypassed, only check del_aubio_sink)155 // del_aubio_sink_custom(NULL);156 157 154 return run_on_default_source_and_sink(base_main); 158 155 } -
tests/src/io/base-source_custom.h
rdfe6ab6 r868c6b8 94 94 if (read != hop_size) return 1; 95 95 96 // read again in undersized vector97 del_fvec(vec);98 vec = new_fvec(hop_size - 1);99 aubio_source_custom_do(s, vec, &read);100 if (read != hop_size - 1) return 1;101 102 // read again in oversized vector103 del_fvec(vec);104 vec = new_fvec(hop_size + 1);105 aubio_source_custom_do(s, vec, &read);106 if (read != hop_size) return 1;107 108 96 // seek to 0 109 97 if(aubio_source_custom_seek(s, 0)) return 1; 110 98 111 99 // read again as multiple channels 112 aubio_source_custom_do_multi(s, mat, &read);113 if (read != hop_size) return 1;114 115 // read again as multiple channels in an undersized matrix116 del_fmat(mat);117 mat = new_fmat(channels - 1, hop_size);118 aubio_source_custom_do_multi(s, mat, &read);119 if (read != hop_size) return 1;120 121 // read again as multiple channels in an undersized matrix122 del_fmat(mat);123 mat = new_fmat(channels, hop_size - 1);124 aubio_source_custom_do_multi(s, mat, &read);125 if (read != hop_size - 1) return 1;126 127 // read again as multiple channels in an oversized matrix128 del_fmat(mat);129 mat = new_fmat(channels + 1, hop_size);130 aubio_source_custom_do_multi(s, mat, &read);131 if (read != hop_size) return 1;132 133 // read again as multiple channels in an oversized matrix134 del_fmat(mat);135 mat = new_fmat(channels, hop_size + 1);136 100 aubio_source_custom_do_multi(s, mat, &read); 137 101 if (read != hop_size) return 1; … … 142 106 aubio_source_custom_close(s); 143 107 144 // reading after close fails145 del_fvec(vec);146 vec = new_fvec(hop_size);147 aubio_source_custom_do(s, vec, &read);148 del_fmat(mat);149 mat = new_fmat(channels, hop_size);150 aubio_source_custom_do_multi(s, mat, &read);151 152 108 del_aubio_source_custom(s); 153 109 del_fmat(mat); 154 110 del_fvec(vec); 155 156 // shouldn't crash on null (bypassed, only check del_aubio_source)157 // del_aubio_source_custom(NULL);158 111 159 112 return run_on_default_source(base_main); -
tests/src/io/test-sink.c
rdfe6ab6 r868c6b8 148 148 close_temp_sink(sink_path, fd); 149 149 150 // shouldn't crash on null151 del_aubio_sink(NULL);152 153 150 return run_on_default_source_and_sink(main); 154 151 } -
tests/src/io/test-source.c
rdfe6ab6 r868c6b8 90 90 if (read != hop_size) return 1; 91 91 92 // read again in undersized vector93 del_fvec(vec);94 vec = new_fvec(hop_size - 1);95 aubio_source_do(s, vec, &read);96 if (read != hop_size - 1) return 1;97 98 // read again in oversized vector99 del_fvec(vec);100 vec = new_fvec(hop_size + 1);101 aubio_source_do(s, vec, &read);102 if (read != hop_size) return 1;103 104 92 // seek to 0 105 93 if(aubio_source_seek(s, 0)) return 1; 106 94 107 95 // read again as multiple channels 108 aubio_source_do_multi(s, mat, &read);109 if (read != hop_size) return 1;110 111 // read again as multiple channels in an undersized matrix112 del_fmat(mat);113 mat = new_fmat(channels - 1, hop_size);114 aubio_source_do_multi(s, mat, &read);115 if (read != hop_size) return 1;116 117 // read again as multiple channels in an undersized matrix118 del_fmat(mat);119 mat = new_fmat(channels, hop_size - 1);120 aubio_source_do_multi(s, mat, &read);121 if (read != hop_size - 1) return 1;122 123 // read again as multiple channels in an oversized matrix124 del_fmat(mat);125 mat = new_fmat(channels + 1, hop_size);126 aubio_source_do_multi(s, mat, &read);127 if (read != hop_size) return 1;128 129 // read again as multiple channels in an oversized matrix130 del_fmat(mat);131 mat = new_fmat(channels, hop_size + 1);132 96 aubio_source_do_multi(s, mat, &read); 133 97 if (read != hop_size) return 1; … … 138 102 aubio_source_close(s); 139 103 140 // reading after close fails141 del_fvec(vec);142 vec = new_fvec(hop_size);143 aubio_source_do(s, vec, &read);144 del_fmat(mat);145 mat = new_fmat(channels, hop_size);146 aubio_source_do_multi(s, mat, &read);147 148 104 del_aubio_source(s); 149 105 del_fmat(mat); 150 106 del_fvec(vec); 151 107 152 // shouldn't crash on null153 del_aubio_source(NULL);154 155 108 return run_on_default_source(main); 156 109 } -
tests/src/spectral/test-mfcc.c
rdfe6ab6 r868c6b8 34 34 aubio_mfcc_t *mfcc = 0; 35 35 36 fvec_t *in = new_fvec ( hop_s); // phase vocoder input37 cvec_t *fftgrain = new_cvec (win_s); // pvoc output / mfcc input38 fvec_t *out = new_fvec (n_coeffs); // mfcc output36 fvec_t *in = new_fvec (win_s); // input buffer 37 cvec_t *fftgrain = new_cvec (win_s); // input buffer 38 fvec_t *out = new_fvec (n_coeffs); // output coefficients 39 39 40 40 if (!in || !fftgrain || !out) { err = 1; goto failure; } -
tests/src/test-cvec.c
rdfe6ab6 r868c6b8 4 4 int main (void) 5 5 { 6 uint_t i, window_size = 16; 7 cvec_t * complex_vector = new_cvec (window_size);8 cvec_t * other_cvector = new_cvec(window_size);6 uint_t i, window_size = 16; // window size 7 cvec_t * complex_vector = new_cvec (window_size); // input buffer 8 uint_t rand_times = 4; 9 9 10 assert(cvec_norm_get_data(complex_vector) == complex_vector->norm); 11 assert(cvec_phas_get_data(complex_vector) == complex_vector->phas); 12 assert(complex_vector->length == window_size / 2 + 1); 10 utils_init_random(); 13 11 14 // all elements are initialized to 0 12 while (rand_times -- ) { 13 // fill with random phas and norm 14 for ( i = 0; i < complex_vector->length; i++ ) { 15 complex_vector->norm[i] = ( 2. / RAND_MAX * random() - 1. ); 16 complex_vector->phas[i] = ( 2. / RAND_MAX * random() - 1. ) * M_PI; 17 } 18 // print the vector 19 cvec_print(complex_vector); 20 } 21 22 // set all vector elements to `0` 23 cvec_norm_zeros(complex_vector); 15 24 for ( i = 0; i < complex_vector->length; i++ ) { 16 25 assert( complex_vector->norm[i] == 0. ); 17 assert( complex_vector->phas[i] == 0.);26 // assert( complex_vector->phas[i] == 0 ); 18 27 } 19 20 cvec_norm_set_sample(complex_vector, 2., 1);21 assert(cvec_norm_get_sample(complex_vector, 1));22 23 cvec_phas_set_sample(complex_vector, 2., 1);24 assert(cvec_phas_get_sample(complex_vector, 1));25 26 28 cvec_print(complex_vector); 27 29 28 // set all norm and phas elements to 0 29 cvec_zeros(complex_vector); 30 for ( i = 0; i < complex_vector->length; i++ ) { 31 assert( complex_vector->norm[i] == 0. ); 32 assert( complex_vector->phas[i] == 0. ); 33 } 34 35 // set all norm elements to 1 30 // set all vector elements to `1` 36 31 cvec_norm_ones(complex_vector); 37 32 for ( i = 0; i < complex_vector->length; i++ ) { 38 33 assert( complex_vector->norm[i] == 1. ); 34 // assert( complex_vector->phas[i] == 0 ); 39 35 } 36 cvec_print(complex_vector); 40 37 41 // set all norm elements to 0 38 cvec_zeros(complex_vector); 39 cvec_phas_zeros(complex_vector); 42 40 cvec_norm_zeros(complex_vector); 43 for ( i = 0; i < complex_vector->length; i++ ) {44 assert( complex_vector->norm[i] == 0.);45 }41 cvec_norm_ones(complex_vector); 42 cvec_phas_ones(complex_vector); 43 cvec_copy(complex_vector, complex_vector); 46 44 47 // set all phas elements to 1 48 cvec_phas_ones(complex_vector); 49 for ( i = 0; i < complex_vector->length; i++ ) { 50 assert( complex_vector->phas[i] == 1. ); 51 } 52 53 // set all phas elements to 0 54 cvec_phas_zeros(complex_vector); 55 for ( i = 0; i < complex_vector->length; i++ ) { 56 assert( complex_vector->phas[i] == 0. ); 57 } 58 59 cvec_copy(complex_vector, other_cvector); 60 // copy to self 61 cvec_copy(complex_vector, complex_vector); 62 // copy to a different size fails 63 del_cvec(other_cvector); 64 other_cvector = new_cvec(window_size + 2); 65 cvec_copy(complex_vector, other_cvector); 66 67 if (complex_vector) 68 del_cvec(complex_vector); 69 if (other_cvector) 70 del_cvec(other_cvector); 71 72 // wrong parameters 73 assert(new_cvec(-1) == NULL); 74 assert(new_cvec(0) == NULL); 75 45 // destroy it 46 del_cvec(complex_vector); 76 47 return 0; 77 48 } -
tests/src/test-fmat.c
rdfe6ab6 r868c6b8 5 5 // and j the column. 6 6 7 void assert_fmat_all_equal(fmat_t *mat, smpl_t scalar)7 int main (void) 8 8 { 9 uint_t i, j; 9 uint_t height = 3, length = 9, i, j; 10 // create fmat_t object 11 fmat_t * mat = new_fmat (height, length); 10 12 for ( i = 0; i < mat->height; i++ ) { 11 13 for ( j = 0; j < mat->length; j++ ) { 12 assert(mat->data[i][j] == scalar);13 }14 }15 }16 17 int main (void)18 {19 uint_t i, j;20 uint_t height = 3, length = 9;21 22 // create fmat_t object23 fmat_t * mat = new_fmat(height, length);24 fmat_t * other_mat = new_fmat(height, length);25 26 assert(mat);27 assert(other_mat);28 29 assert(mat->length == length);30 assert(mat->height == height);31 32 for (i = 0; i < mat->height; i++) {33 for (j = 0; j < mat->length; j++) {34 14 // all elements are already initialized to 0. 35 15 assert(mat->data[i][j] == 0); 36 16 // setting element of row i, column j 37 mat->data[i][j] = i * 1 0. + j;17 mat->data[i][j] = i * 1. + j *.1; 38 18 } 39 19 } 40 41 // print out matrix42 fmat_print(mat);43 44 // helpers45 fmat_rev(mat);46 fmat_print(mat);47 for (i = 0; i < mat->height; i++) {48 for (j = 0; j < mat->length; j++) {49 assert(mat->data[i][j] == i * 10. + mat->length - 1. - j);50 }51 }52 53 fmat_set_sample(mat, 3, 1, 1);54 assert(fmat_get_sample(mat, 1, 1) == 3.);55 56 fmat_ones(mat);57 assert_fmat_all_equal(mat, 1.);58 59 fmat_set(other_mat, .5);60 assert_fmat_all_equal(other_mat, .5);61 62 fmat_weight(mat, other_mat);63 assert_fmat_all_equal(mat, .5);64 65 20 fvec_t channel_onstack; 66 21 fvec_t *channel = &channel_onstack; 67 22 fmat_get_channel(mat, 1, channel); 68 assert(channel->data == mat->data[1]); 69 70 // copy of the same size 71 fmat_copy(mat, other_mat); 72 del_fmat(other_mat); 73 74 // copy to undersized 75 other_mat = new_fmat(height - 1, length); 76 fmat_copy(mat, other_mat); 77 del_fmat(other_mat); 78 79 // copy from undersized 80 other_mat = new_fmat(height, length + 1); 81 fmat_copy(mat, other_mat); 82 83 // wrong parameters 84 assert(new_fmat(-1, length) == NULL); 85 assert(new_fmat(height, -1) == NULL); 86 87 // methods for wrappers with opaque structure 88 assert (fmat_get_channel_data(mat, 0) == mat->data[0]); 89 assert (fmat_get_data(mat) == mat->data); 90 91 if (mat) 92 del_fmat(mat); 93 if (other_mat) 94 del_fmat(other_mat); 23 fvec_print (channel); 24 // print out matrix 25 fmat_print(mat); 26 // destroy it 27 del_fmat(mat); 95 28 return 0; 96 29 } 30 -
tests/src/test-fvec.c
rdfe6ab6 r868c6b8 2 2 #include "utils_tests.h" 3 3 4 void assert_fvec_all_equal(fvec_t *vec, smpl_t scalar)5 {6 uint_t i;7 for (i = 0; i < vec->length; i++) {8 assert(vec->data[i] == scalar);9 }10 }11 12 4 int main (void) 13 5 { 14 uint_t length = 10; 15 uint_t i; 16 17 fvec_t * vec = new_fvec (length); 18 fvec_t * other_vec = new_fvec (length); 19 20 assert (vec); 21 assert (other_vec); 6 uint_t vec_size = 10, i; 7 fvec_t * vec = new_fvec (vec_size); 22 8 23 9 // vec->length matches requested size 24 assert(vec->length == length);10 assert(vec->length == vec_size); 25 11 26 12 // all elements are initialized to `0.` … … 29 15 } 30 16 17 // all elements can be set to `0.` 18 fvec_zeros(vec); 19 for ( i = 0; i < vec->length; i++ ) { 20 assert(vec->data[i] == 0.); 21 } 22 fvec_print(vec); 23 31 24 // all elements can be set to `1.` 32 25 fvec_ones(vec); 33 assert_fvec_all_equal(vec, 1.); 34 35 // all elements can be set to `0.` 36 fvec_zeros(vec); 37 assert_fvec_all_equal(vec, 0.); 26 for ( i = 0; i < vec->length; i++ ) { 27 assert(vec->data[i] == 1.); 28 } 29 fvec_print(vec); 38 30 39 31 // each element can be accessed directly … … 44 36 fvec_print(vec); 45 37 46 fvec_set_sample(vec, 3, 2);47 assert(fvec_get_sample(vec, 2) == 3);38 // now destroys the vector 39 del_fvec(vec); 48 40 49 assert(fvec_get_data(vec) == vec->data);50 51 // wrong parameters52 assert(new_fvec(-1) == NULL);53 54 // copy to an identical size works55 fvec_copy(vec, other_vec);56 del_fvec(other_vec);57 58 // copy to a different size fail59 other_vec = new_fvec(length + 1);60 fvec_copy(vec, other_vec);61 del_fvec(other_vec);62 63 // copy to a different size fail64 other_vec = new_fvec(length - 1);65 fvec_copy(vec, other_vec);66 67 // now destroys the vector68 if (vec)69 del_fvec(vec);70 if (other_vec)71 del_fvec(other_vec);72 41 return 0; 73 42 } 43 -
tests/src/test-lvec.c
rdfe6ab6 r868c6b8 2 2 #include "utils_tests.h" 3 3 4 void assert_lvec_all_equal(lvec_t *vec, lsmp_t scalar)4 int main (void) 5 5 { 6 uint_t i; 7 for (i = 0; i < vec->length; i++) { 8 assert(vec->data[i] == scalar); 9 } 6 uint_t win_s = 32; // window size 7 lvec_t * sp = new_lvec (win_s); // input buffer 8 lvec_set_sample (sp, 2./3., 0); 9 PRINT_MSG(AUBIO_LSMP_FMT "\n", lvec_get_sample (sp, 0)); 10 lvec_print (sp); 11 lvec_ones (sp); 12 lvec_print (sp); 13 lvec_set_all (sp, 3./5.); 14 lvec_print (sp); 15 del_lvec(sp); 16 return 0; 10 17 } 11 18 12 int main (void)13 {14 uint_t length = 32; // window size15 16 lvec_t * vec = new_lvec (length); // input buffer17 18 assert(vec);19 20 assert(vec->length == length);21 22 lvec_set_sample (vec, 3., 0);23 assert(lvec_get_sample(vec, 0) == 3.);24 25 assert(lvec_get_data(vec) == vec->data);26 27 lvec_print (vec);28 // note AUBIO_LSMP_FMT can be used to print lsmp_t29 PRINT_MSG(AUBIO_LSMP_FMT "\n", lvec_get_sample (vec, 0));30 31 lvec_set_all (vec, 2.);32 assert_lvec_all_equal(vec, 2.);33 34 lvec_ones (vec);35 assert_lvec_all_equal(vec, 1.);36 37 lvec_zeros (vec);38 assert_lvec_all_equal(vec, 0.);39 40 del_lvec(vec);41 42 // wrong parameters43 assert(new_lvec(0) == NULL);44 assert(new_lvec(-1) == NULL);45 46 return 0;47 } -
tests/src/test-mathutils-window.c
rdfe6ab6 r868c6b8 8 8 uint_t lengths[4] = { 8, 10, 15, 16 }; 9 9 char *method = "default"; 10 char *window_types[1 1] = { "default",11 " ones", "rectangle", "hamming", "hanning", "hanningz",10 char *window_types[10] = { "default", 11 "rectangle", "hamming", "hanning", "hanningz", 12 12 "blackman", "blackman_harris", "gaussian", "welch", "parzen"}; 13 13 … … 27 27 } 28 28 } 29 30 assert (new_aubio_window("parzen", -1) == NULL);31 assert (new_aubio_window(NULL, length) == NULL);32 assert (new_aubio_window("\0", length) == NULL);33 29 return 0; 34 30 } -
wscript
rdfe6ab6 r868c6b8 140 140 ctx.check(header_name='math.h') 141 141 ctx.check(header_name='string.h') 142 ctx.check(header_name='errno.h')143 142 ctx.check(header_name='limits.h') 144 143 ctx.check(header_name='stdarg.h') … … 631 630 ctx.excl += ' **/.cache' 632 631 ctx.excl += ' **/**.zip **/**.tar.bz2' 633 ctx.excl += ' **.tar.bz2 **'632 ctx.excl += ' **.tar.bz2' 634 633 ctx.excl += ' **/doc/full/* **/doc/web/*' 635 634 ctx.excl += ' **/doc/full.cfg' … … 643 642 ctx.excl += ' **/.DS_Store' 644 643 ctx.excl += ' **/.travis.yml' 644 ctx.excl += ' **/.landscape.yml' 645 645 ctx.excl += ' **/.appveyor.yml' 646 646 ctx.excl += ' **/.circleci/*'
Note: See TracChangeset
for help on using the changeset viewer.