Changes in / [f5adffe:0e6ad10]


Ignore:
Files:
4 added
1 deleted
48 edited

Legend:

Unmodified
Added
Removed
  • .appveyor.yml

    rf5adffe r0e6ad10  
    7676test_script:
    7777  - "python python\\demos\\demo_create_test_sounds.py"
    78   - "pytest --verbose"
     78  - "nose2 --verbose"
  • .circleci/config.yml

    rf5adffe r0e6ad10  
    2020    pip install --user dist/aubio*.whl
    2121
    22 test-pytest: &test-pytest
     22test-nose2: &test-nose2
    2323  name: Test python wheel
    2424  command: |
    2525    make create_test_sounds
    26     PATH=/home/circleci/.local/bin:$PATH pytest -v
     26    PATH=/home/circleci/.local/bin:$PATH nose2 -v
    2727
    28 test-pytest-nosounds: &test-pytest-nosounds
     28test-nose2-nosounds: &test-nose2-nosounds
    2929  name: Test python wheel
    3030  command: |
    31     PATH=/home/circleci/.local/bin:$PATH pytest -v
     31    PATH=/home/circleci/.local/bin:$PATH nose2 -v
    3232
    3333uninstall-wheel: &uninstall-wheel
     
    4848      - run: *build-wheel
    4949      - run: *install-wheel
    50       - run: *test-pytest
     50      - run: *test-nose2
    5151      - run: *uninstall-wheel
    5252      - store_artifacts:
     
    6262      - run: *build-wheel
    6363      - run: *install-wheel
    64       - run: *test-pytest
     64      - run: *test-nose2
    6565      - run: *uninstall-wheel
    6666      - store_artifacts:
     
    7676      - run: *build-wheel
    7777      - run: *install-wheel
    78       - run: *test-pytest
     78      - run: *test-nose2
    7979      - run: *uninstall-wheel
    8080      - store_artifacts:
     
    8989      - run: *build-wheel
    9090      - run: *install-wheel
    91       - run: *test-pytest-nosounds
     91      - run: *test-nose2-nosounds
    9292      - run: *uninstall-wheel
    9393      - store_artifacts:
  • .travis.yml

    rf5adffe r0e6ad10  
    8888  - which pip
    8989  - pip --version
    90   - pip install coverage
    9190
    9291script:
  • MANIFEST.in

    rf5adffe r0e6ad10  
    77include Makefile wscript */wscript_build
    88include aubio.pc.in
     9include nose2.cfg
    910include requirements.txt
    1011include src/*.c src/*.h
    1112include src/*/*.c src/*/*.h
    1213include examples/*.c examples/*.h
    13 recursive-include tests *.h *.c *.py
     14include tests/*.h tests/*/*.c tests/*/*/*.c
    1415include python/ext/*.h
    1516recursive-include python *.py
    1617include python/README.md
     18include python/tests/run_all_tests
    1719include python/tests/eval_pitch
    1820include python/tests/*.expected
  • Makefile

    rf5adffe r0e6ad10  
    3636MANDIR?=$(DATAROOTDIR)/man
    3737
    38 # default python test command
    39 PYTEST?=pytest --verbose
     38# default nose2 command
     39NOSE2?=nose2 -N 4 --verbose
    4040
    4141SOX=sox
     
    141141test_python: local_dylib
    142142        # run test with installed package
    143         $(PYTEST)
     143        # ./python/tests/run_all_tests --verbose
     144        # run with nose2, multiple processes
     145        $(NOSE2)
    144146
    145147clean_python:
     
    252254        pip install -v -e .
    253255        # run tests, with python coverage
    254         coverage run `which pytest`
     256        coverage run `which nose2`
    255257        # capture coverage again
    256258        lcov $(LCOVOPTS) --capture --no-external --directory . \
  • doc/python_module.rst

    rf5adffe r0e6ad10  
    9090------------
    9191
    92 A number of Python tests are provided in the `python/tests`_ folder. To run
    93 them, install `pytest`_ and run it from the aubio source directory:
     92A number of Python tests are provided in the `python tests`_. To run them,
     93install `nose2`_ and run the script ``python/tests/run_all_tests``:
    9494
    9595.. code-block:: console
    9696
    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
    10199
    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  
    2828-----
    2929
    30 Some examples are available in the [`python/demos` folder][demos_dir]. Each
     30Some examples are available in the [`python/demos`][demos_dir] folder. Each
    3131script is a command line program which accepts one ore more argument.
    3232
  • python/ext/aubiomodule.c

    rf5adffe r0e6ad10  
    224224
    225225  // compute the function
    226   result = PyFloat_FromDouble(fvec_alpha_norm (&vec, alpha));
     226  result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, fvec_alpha_norm (&vec, alpha));
    227227  if (result == NULL) {
    228228    return NULL;
     
    320320
    321321  // compute the function
    322   result = PyFloat_FromDouble(aubio_zero_crossing_rate (&vec));
     322  result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, aubio_zero_crossing_rate (&vec));
    323323  if (result == NULL) {
    324324    return NULL;
  • python/ext/py-cvec.c

    rf5adffe r0e6ad10  
    137137  }
    138138
    139   args = PyLong_FromLong(self->length);
     139  args = Py_BuildValue ("I", self->length);
    140140  if (args == NULL) {
    141141    goto fail;
  • python/ext/py-musicutils.c

    rf5adffe r0e6ad10  
    4040  }
    4141
    42   level_lin = PyFloat_FromDouble(aubio_level_lin(&vec));
     42  level_lin = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_lin(&vec));
    4343  if (level_lin == NULL) {
    4444    PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
     
    6868  }
    6969
    70   db_spl = PyFloat_FromDouble(aubio_db_spl(&vec));
     70  db_spl = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_db_spl(&vec));
    7171  if (db_spl == NULL) {
    7272    PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
     
    9797  }
    9898
    99   silence_detection = PyLong_FromLong(aubio_silence_detection(&vec, threshold));
     99  silence_detection = Py_BuildValue("I", aubio_silence_detection(&vec, threshold));
    100100  if (silence_detection == NULL) {
    101101    PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");
     
    126126  }
    127127
    128   level_detection = PyFloat_FromDouble(aubio_level_detection(&vec, threshold));
     128  level_detection = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_detection(&vec, threshold));
    129129  if (level_detection == NULL) {
    130130    PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
     
    195195  }
    196196  if (htk != NULL && PyObject_IsTrue(htk) == 1)
    197     return PyFloat_FromDouble(aubio_hztomel_htk(v));
     197    return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));
    198198  else
    199     return PyFloat_FromDouble(aubio_hztomel(v));
     199    return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel(v));
    200200}
    201201
     
    212212  }
    213213  if (htk != NULL && PyObject_IsTrue(htk) == 1)
    214     return PyFloat_FromDouble(aubio_meltohz_htk(v));
     214    return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v));
    215215  else
    216     return PyFloat_FromDouble(aubio_meltohz(v));
     216    return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz(v));
    217217}
    218218
     
    224224    return NULL;
    225225  }
    226   return PyFloat_FromDouble(aubio_hztomel_htk(v));
     226  return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));
    227227}
    228228
     
    234234    return NULL;
    235235  }
    236   return PyFloat_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  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase
    45
     
    1516
    1617if __name__ == '__main__':
    17     from unittest import main
    1818    main()
     19
  • python/tests/test_aubio_cmd.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
     3import aubio.cmd
     4from nose2 import main
    35from numpy.testing import TestCase
    4 import aubio.cmd
    56
    67class aubio_cmd(TestCase):
     
    3132
    3233if __name__ == '__main__':
    33     from unittest import main
    3434    main()
  • python/tests/test_aubio_cut.py

    rf5adffe r0e6ad10  
    22
    33import aubio.cut
     4from nose2 import main
    45from numpy.testing import TestCase
    56
     
    1314
    1415if __name__ == '__main__':
    15     from unittest import main
    1616    main()
  • python/tests/test_cvec.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34import numpy as np
    45from numpy.testing import TestCase, assert_equal
     
    141142
    142143if __name__ == '__main__':
    143     from unittest import main
    144144    main()
  • python/tests/test_dct.py

    rf5adffe r0e6ad10  
    6767        except AssertionError:
    6868            self.skipTest('creating aubio.dct with size %d did not fail' % size)
    69 
    70 if __name__ == '__main__':
    71     from unittest import main
    72     main()
  • python/tests/test_fft.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase
    45from numpy.testing import assert_equal, assert_almost_equal
     
    212213
    213214if __name__ == '__main__':
    214     from unittest import main
    215215    main()
  • python/tests/test_filter.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal, assert_almost_equal
    45from aubio import fvec, digital_filter
    5 from utils import array_from_text_file
     6from .utils import array_from_text_file
    67
    78class aubio_filter_test_case(TestCase):
     
    9495
    9596if __name__ == '__main__':
    96     from unittest import main
    9797    main()
  • python/tests/test_filterbank.py

    rf5adffe r0e6ad10  
    55
    66from aubio import cvec, filterbank, float_type
    7 from utils import array_from_text_file
     7from .utils import array_from_text_file
    88
    99class aubio_filterbank_test_case(TestCase):
     
    8888
    8989if __name__ == '__main__':
    90     from unittest import main
    91     main()
     90    import nose2
     91    nose2.main()
  • python/tests/test_filterbank_mel.py

    rf5adffe r0e6ad10  
    33import numpy as np
    44from numpy.testing import TestCase, assert_equal, assert_almost_equal
    5 from _tools import assert_warns
    65
    76from aubio import fvec, cvec, filterbank, float_type
     7
     8import warnings
     9warnings.filterwarnings('ignore', category=UserWarning, append=True)
    810
    911class aubio_filterbank_mel_test_case(TestCase):
     
    7476        freq_list = [0, samplerate//4, samplerate // 2 + 1]
    7577        f = filterbank(len(freq_list)-2, 1024)
    76         with assert_warns(UserWarning):
    77             f.set_triangle_bands(fvec(freq_list), samplerate)
     78        # TODO add assert_warns
     79        f.set_triangle_bands(fvec(freq_list), samplerate)
    7880
    7981    def test_triangle_freqs_with_not_enough_filters(self):
     
    8284        freq_list = [0, 100, 1000, 4000, 8000, 10000]
    8385        f = filterbank(len(freq_list)-3, 1024)
    84         with assert_warns(UserWarning):
    85             f.set_triangle_bands(fvec(freq_list), samplerate)
     86        # TODO add assert_warns
     87        f.set_triangle_bands(fvec(freq_list), samplerate)
    8688
    8789    def test_triangle_freqs_with_too_many_filters(self):
     
    9092        freq_list = [0, 100, 1000, 4000, 8000, 10000]
    9193        f = filterbank(len(freq_list)-1, 1024)
    92         with assert_warns(UserWarning):
    93             f.set_triangle_bands(fvec(freq_list), samplerate)
     94        # TODO add assert_warns
     95        f.set_triangle_bands(fvec(freq_list), samplerate)
    9496
    9597    def test_triangle_freqs_with_double_value(self):
     
    98100        freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
    99101        f = filterbank(len(freq_list)-2, 1024)
    100         with assert_warns(UserWarning):
    101             f.set_triangle_bands(fvec(freq_list), samplerate)
     102        # TODO add assert_warns
     103        f.set_triangle_bands(fvec(freq_list), samplerate)
    102104
    103105    def test_triangle_freqs_with_triple(self):
     
    106108        freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
    107109        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)
    111112
    112113    def test_triangle_freqs_without_norm(self):
     
    168169
    169170if __name__ == '__main__':
    170     from unittest import main
    171     main()
     171    import nose2
     172    nose2.main()
  • python/tests/test_fvec.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34import numpy as np
    45from numpy.testing import TestCase, assert_equal, assert_almost_equal
     
    148149
    149150if __name__ == '__main__':
    150     from unittest import main
    151151    main()
  • python/tests/test_fvec_shift.py

    rf5adffe r0e6ad10  
    3131        self.run_shift_ishift(7)
    3232
     33from unittest import main
    3334if __name__ == '__main__':
    34     from unittest import main
    3535    main()
  • python/tests/test_hztomel.py

    rf5adffe r0e6ad10  
    44from numpy.testing import TestCase
    55from numpy.testing import assert_equal, assert_almost_equal
    6 from _tools import assert_warns
    76import numpy as np
    87import aubio
     
    3938
    4039    def test_meltohz_negative(self):
    41         with assert_warns(UserWarning):
    42             assert_equal(meltohz(-1), 0)
     40        # TODO add assert_warns
     41        assert_equal(meltohz(-1), 0)
    4342
    4443    def test_hztomel_negative(self):
    45         with assert_warns(UserWarning):
    46             assert_equal(hztomel(-1), 0)
     44        # TODO add assert_warns
     45        assert_equal(hztomel(-1), 0)
    4746
    4847
     
    5958
    6059    def test_meltohz_negative(self):
    61         with assert_warns(UserWarning):
    62             assert_equal(meltohz(-1, htk=True), 0)
     60        # TODO add assert_warns
     61        assert_equal(meltohz(-1, htk=True), 0)
    6362        assert_almost_equal(meltohz(2000, htk=True), 3428.7, decimal=1)
    6463        assert_almost_equal(meltohz(1000, htk=True), 1000., decimal=1)
    6564
    6665    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)
    7168        assert_almost_equal(hztomel(1000, htk=True), 1000., decimal=1)
    7269
  • python/tests/test_mathutils.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal
    45from numpy import array, arange, isnan, isinf
     
    101102
    102103if __name__ == '__main__':
    103     from unittest import main
    104104    main()
  • python/tests/test_mfcc.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
    3 from _tools import parametrize, assert_raises
     3from nose2 import main
     4from nose2.tools import params
    45from numpy import random, count_nonzero
    56from numpy.testing import TestCase
     
    1516new_deflts = [1024, 40, 13, 44100]
    1617
    17 class Test_aubio_mfcc(object):
     18class aubio_mfcc(TestCase):
    1819
    19     members_args = 'name'
     20    def setUp(self):
     21        self.o = mfcc()
    2022
    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)
    2230    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)):
    2533            setattr(o, name, 0)
    2634
    27     @parametrize('name, expected', zip(new_params, new_deflts))
     35    @params(*zip(new_params, new_deflts))
    2836    def test_default_param(self, name, expected):
    2937        """ test mfcc.{:s} = {:d} """.format(name, expected)
    30         o = mfcc()
    31         assert getattr(o, name) == expected
     38        o = self.o
     39        self.assertEqual( getattr(o, name), expected)
    3240
    3341class aubio_mfcc_wrong_params(TestCase):
     
    7583
    7684
    77 class Test_aubio_mfcc_all_parameters(object):
     85class aubio_mfcc_all_parameters(TestCase):
    7886
    79     run_values = [
     87    @params(
    8088            (2048, 40, 13, 44100),
    8189            (1024, 40, 13, 44100),
     
    93101            (1024, 40, 40, 44100),
    94102            (1024, 40, 3, 44100),
    95             ]
    96     run_args = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
    97 
    98     @parametrize(run_args, run_values)
     103            )
    99104    def test_run_with_params(self, buf_size, n_filters, n_coeffs, samplerate):
    100105        " check mfcc can run with reasonable parameters "
     
    144149
    145150if __name__ == '__main__':
    146     from _tools import run_module_suite
    147     run_module_suite()
     151    main()
  • python/tests/test_midi2note.py

    rf5adffe r0e6ad10  
    33
    44from aubio import midi2note
    5 from _tools import parametrize, assert_raises
     5from nose2.tools import params
     6import unittest
    67
    78list_of_known_midis = (
     
    1516        )
    1617
    17 class Test_midi2note_good_values(object):
     18class midi2note_good_values(unittest.TestCase):
    1819
    19     @parametrize('midi, note', list_of_known_midis)
     20    @params(*list_of_known_midis)
    2021    def test_midi2note_known_values(self, midi, note):
    2122        " known values are correctly converted "
    22         assert midi2note(midi) == (note)
     23        self.assertEqual ( midi2note(midi), note )
    2324
    24 class Test_midi2note_wrong_values(object):
     25class midi2note_wrong_values(unittest.TestCase):
    2526
    2627    def test_midi2note_negative_value(self):
    2728        " fails when passed a negative value "
    28         assert_raises(ValueError, midi2note, -2)
     29        self.assertRaises(ValueError, midi2note, -2)
    2930
    3031    def test_midi2note_large(self):
    3132        " fails when passed a value greater than 127 "
    32         assert_raises(ValueError, midi2note, 128)
     33        self.assertRaises(ValueError, midi2note, 128)
    3334
    3435    def test_midi2note_floating_value(self):
    3536        " fails when passed a floating point "
    36         assert_raises(TypeError, midi2note, 69.2)
     37        self.assertRaises(TypeError, midi2note, 69.2)
    3738
    3839    def test_midi2note_character_value(self):
    3940        " fails when passed a value that can not be transformed to integer "
    40         assert_raises(TypeError, midi2note, "a")
     41        self.assertRaises(TypeError, midi2note, "a")
    4142
    4243if __name__ == '__main__':
    43     from _tools import run_module_suite
    44     run_module_suite()
     44    import nose2
     45    nose2.main()
  • python/tests/test_musicutils.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34import numpy as np
    45from numpy.testing import TestCase
    5 from numpy.testing import assert_equal, assert_almost_equal
     6from numpy.testing.utils import assert_equal, assert_almost_equal
    67from aubio import window, level_lin, db_spl, silence_detection, level_detection
    78from aubio import fvec, float_type
     
    8586
    8687if __name__ == '__main__':
    87     from unittest import main
    8888    main()
  • python/tests/test_note2midi.py

    rf5adffe r0e6ad10  
    55
    66from aubio import note2midi, freq2note, note2freq, float_type
    7 from numpy.testing import TestCase
    8 from _tools import parametrize, assert_raises, skipTest
     7from nose2.tools import params
     8import unittest
    99
    1010list_of_known_notes = (
     
    4545        )
    4646
    47 class Test_note2midi_good_values(object):
     47class note2midi_good_values(unittest.TestCase):
    4848
    49     @parametrize('note, midi', list_of_known_notes)
     49    @params(*list_of_known_notes)
    5050    def test_note2midi_known_values(self, note, midi):
    5151        " known values are correctly converted "
    52         assert note2midi(note) == midi
     52        self.assertEqual ( note2midi(note), midi )
    5353
    54     @parametrize('note, midi', list_of_known_notes_with_unicode_issues)
     54    @params(*list_of_known_notes_with_unicode_issues)
    5555    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"
    5757        try:
    58             assert note2midi(note) == midi
     58            self.assertEqual ( note2midi(note), midi )
    5959        except UnicodeEncodeError as e:
    60             # platforms with decoding failures include:
    61             # - osx: python <= 2.7.10
    62             # - win: python <= 2.7.12
    6360            import sys
    64             strmsg = "len(u'\\U0001D12A') != 1, expected decoding failure"
    65             strmsg += " | 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
    6764            if len('\U0001D12A') != 1 and sys.version[0] == '2':
    68                 skipTest(strmsg.format(repr(e), sys.platform, sys.version))
     65                self.skipTest(strres + " | upgrade to Python 3 to fix")
    6966            else:
    7067                raise
    7168
    72 class note2midi_wrong_values(TestCase):
     69class note2midi_wrong_values(unittest.TestCase):
    7370
    7471    def test_note2midi_missing_octave(self):
     
    108105        self.assertRaises(ValueError, note2midi, 'CB+-3')
    109106
    110 class Test_note2midi_unknown_values(object):
    111 
    112     @parametrize('note', list_of_unknown_notes)
     107    @params(*list_of_unknown_notes)
    113108    def test_note2midi_unknown_values(self, note):
    114109        " unknown values throw out an error "
    115         assert_raises(ValueError, note2midi, note)
     110        self.assertRaises(ValueError, note2midi, note)
    116111
    117 class freq2note_simple_test(TestCase):
     112class freq2note_simple_test(unittest.TestCase):
    118113
    119114    def test_freq2note_above(self):
     
    125120        self.assertEqual("A4", freq2note(439))
    126121
    127 class note2freq_simple_test(TestCase):
     122class note2freq_simple_test(unittest.TestCase):
    128123
    129124    def test_note2freq(self):
     
    139134
    140135if __name__ == '__main__':
    141     from _tools import run_module_suite
    142     run_module_suite()
     136    import nose2
     137    nose2.main()
  • python/tests/test_notes.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from 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')
     5from aubio import notes
    96
    107AUBIO_DEFAULT_NOTES_SILENCE = -70.
     
    5653            self.o.set_release_drop(val)
    5754
     55from .utils import list_all_sounds
     56list_of_sounds = list_all_sounds('sounds')
     57
    5858class aubio_notes_sinewave(TestCase):
    5959
    6060    def analyze_file(self, filepath, samplerate=0):
     61        from aubio import source
     62        import numpy as np
    6163        win_s = 512 # fft size
    6264        hop_s = 256 # hop size
     
    9193
    9294if __name__ == '__main__':
    93     from unittest import main
    9495    main()
  • python/tests/test_onset.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal, assert_almost_equal
    45from aubio import onset, fvec
     
    116117
    117118if __name__ == '__main__':
    118     from unittest import main
    119119    main()
  • python/tests/test_phasevoc.py

    rf5adffe r0e6ad10  
    22
    33from numpy.testing import TestCase, assert_equal, assert_array_less
    4 from _tools import parametrize
    54from aubio import fvec, cvec, pvoc, float_type
     5from nose2 import main
     6from nose2.tools import params
    67import numpy as np
    78
     
    1819    return np.random.rand(hop_s).astype(float_type) * 2. - 1.
    1920
    20 class Test_aubio_pvoc_test_case(object):
     21class aubio_pvoc_test_case(TestCase):
    2122    """ pvoc object test case """
    2223
     
    6566            assert_equal ( t, 0.)
    6667
    67     resynth_noise_args = "hop_s, ratio"
    68     resynth_noise_values = [
     68    @params(
    6969            ( 256, 8),
    7070            ( 256, 4),
     
    8888            (8192, 4),
    8989            (8192, 2),
    90             ]
    91 
    92     @parametrize(resynth_noise_args, resynth_noise_values)
     90            )
    9391    def test_resynth_steps_noise(self, hop_s, ratio):
    9492        """ check the resynthesis of a random signal is correct """
     
    9694        self.reconstruction(sigin, hop_s, ratio)
    9795
    98     resynth_sine_args = "samplerate, hop_s, ratio, freq"
    99     resynth_sine_values = [
     96    @params(
    10097            (44100,  256, 8,   441),
    10198            (44100,  256, 4,  1203),
     
    112109            (96000, 1024, 8, 47000),
    113110            (96000, 1024, 8,    20),
    114             ]
    115 
    116     @parametrize(resynth_sine_args, resynth_sine_values)
     111            )
    117112    def test_resynth_steps_sine(self, samplerate, hop_s, ratio, freq):
    118113        """ check the resynthesis of a sine is correct """
     
    205200
    206201if __name__ == '__main__':
    207     from unittest import main
    208202    main()
     203
  • python/tests/test_pitch.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
    3 from numpy.testing import TestCase, assert_equal
     3from unittest import TestCase, main
     4from numpy.testing import assert_equal
    45from numpy import sin, arange, mean, median, isnan, pi
    56from aubio import fvec, pitch, freqtomidi, float_type
     
    116117for algo in pitch_algorithms:
    117118    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,
    120121                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)
    122123
    123124if __name__ == '__main__':
    124     from unittest import main
    125125    main()
  • python/tests/test_sink.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
     3from nose2 import main
     4from nose2.tools import params
    35from numpy.testing import TestCase
    46from 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
     7from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
     8
     9import warnings
     10warnings.filterwarnings('ignore', category=UserWarning, append=True)
    711
    812list_of_sounds = list_all_sounds('sounds')
     
    2024            all_params.append((hop_size, samplerate, soundfile))
    2125
    22 class Test_aubio_sink(object):
     26class 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\'')
    2331
    2432    def test_wrong_filename(self):
    25         with assert_raises(RuntimeError):
     33        with self.assertRaises(RuntimeError):
    2634            sink('')
    2735
    2836    def test_wrong_samplerate(self):
    29         with assert_raises(RuntimeError):
     37        with self.assertRaises(RuntimeError):
    3038            sink(get_tmp_sink_path(), -1)
    3139
    3240    def test_wrong_samplerate_too_large(self):
    33         with assert_raises(RuntimeError):
     41        with self.assertRaises(RuntimeError):
    3442            sink(get_tmp_sink_path(), 1536001, 2)
    3543
    3644    def test_wrong_channels(self):
    37         with assert_raises(RuntimeError):
     45        with self.assertRaises(RuntimeError):
    3846            sink(get_tmp_sink_path(), 44100, -1)
    3947
    4048    def test_wrong_channels_too_large(self):
    41         with assert_raises(RuntimeError):
     49        with self.assertRaises(RuntimeError):
    4250            sink(get_tmp_sink_path(), 44100, 202020)
    4351
     
    5967        shutil.rmtree(tmpdir)
    6068
    61     @parametrize('hop_size, samplerate, path', all_params)
     69    @params(*all_params)
    6270    def test_read_and_write(self, hop_size, samplerate, path):
     71
    6372        try:
    6473            f = source(path, samplerate, hop_size)
    6574        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)))
    6876        if samplerate == 0: samplerate = f.samplerate
    6977        sink_path = get_tmp_sink_path()
     
    7785        del_tmp_sink_path(sink_path)
    7886
    79     @parametrize('hop_size, samplerate, path', all_params)
     87    @params(*all_params)
    8088    def test_read_and_write_multi(self, hop_size, samplerate, path):
    8189        try:
    8290            f = source(path, samplerate, hop_size)
    8391        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)))
    8693        if samplerate == 0: samplerate = f.samplerate
    8794        sink_path = get_tmp_sink_path()
     
    119126
    120127if __name__ == '__main__':
    121     from _tools import run_module_suite
    122     run_module_suite()
     128    main()
  • python/tests/test_slicing.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal
    45from aubio import slice_source_at_stamps
    5 from utils import count_files_in_directory, get_default_test_sound
    6 from utils import count_samples_in_directory, count_samples_in_file
     6from .utils import count_files_in_directory, get_default_test_sound
     7from .utils import count_samples_in_directory, count_samples_in_file
    78
    89import tempfile
     
    167168
    168169if __name__ == '__main__':
    169     from unittest import main
    170170    main()
  • python/tests/test_source.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
    3 
     3from nose2 import main
     4from nose2.tools import params
    45from numpy.testing import TestCase, assert_equal
    56from aubio import source
    6 from utils import list_all_sounds
    7 import unittest
    8 from _tools import parametrize, assert_raises, assert_equal, skipTest
     7from .utils import list_all_sounds
     8
     9import warnings
     10warnings.filterwarnings('ignore', category=UserWarning, append=True)
    911
    1012list_of_sounds = list_all_sounds('sounds')
     
    1214hop_sizes = [512, 1024, 64]
    1315
    14 default_test_sound = len(list_of_sounds) and list_of_sounds[0] or None
     16path = None
    1517
    1618all_params = []
     
    2022            all_params.append((hop_size, samplerate, soundfile))
    2123
    22 no_sounds_msg = "no test sounds, add some in 'python/tests/sounds/'!"
    2324
    24 _debug = False
     25class aubio_source_test_case_base(TestCase):
    2526
    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]
    2731
    28     @parametrize('filename', list_of_sounds)
     32class aubio_source_test_case(aubio_source_test_case_base):
     33
     34    @params(*list_of_sounds)
    2935    def test_close_file(self, filename):
    3036        samplerate = 0 # use native samplerate
     
    3339        f.close()
    3440
    35     @parametrize('filename', list_of_sounds)
     41    @params(*list_of_sounds)
    3642    def test_close_file_twice(self, filename):
    3743        samplerate = 0 # use native samplerate
     
    4147        f.close()
    4248
    43 class Test_aubio_source_read(object):
     49class aubio_source_read_test_case(aubio_source_test_case_base):
    4450
    4551    def read_from_source(self, f):
     
    5157                assert_equal(samples[read:], 0)
    5258                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))
    5962        return total_frames
    6063
    61     @parametrize('hop_size, samplerate, soundfile', all_params)
     64    @params(*all_params)
    6265    def test_samplerate_hopsize(self, hop_size, samplerate, soundfile):
    6366        try:
    6467            f = source(soundfile, samplerate, hop_size)
    6568        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)))
    6870        assert f.samplerate != 0
    6971        read_frames = self.read_from_source(f)
    7072        if 'f_' in soundfile and samplerate == 0:
    7173            import re
    72             f = re.compile(r'.*_\([0:9]*f\)_.*')
     74            f = re.compile('.*_\([0:9]*f\)_.*')
    7375            match_f = re.findall('([0-9]*)f_', soundfile)
    7476            if len(match_f) == 1:
    7577                expected_frames = int(match_f[0])
    76                 assert_equal(expected_frames, read_frames)
     78                self.assertEqual(expected_frames, read_frames)
    7779
    78     @parametrize('p', list_of_sounds)
     80    @params(*list_of_sounds)
    7981    def test_samplerate_none(self, p):
    8082        f = source(p)
     
    8284        self.read_from_source(f)
    8385
    84     @parametrize('p', list_of_sounds)
     86    @params(*list_of_sounds)
    8587    def test_samplerate_0(self, p):
    8688        f = source(p, 0)
     
    8890        self.read_from_source(f)
    8991
    90     @parametrize('p', list_of_sounds)
     92    @params(*list_of_sounds)
    9193    def test_zero_hop_size(self, p):
    9294        f = source(p, 0, 0)
     
    9597        self.read_from_source(f)
    9698
    97     @parametrize('p', list_of_sounds)
     99    @params(*list_of_sounds)
    98100    def test_seek_to_half(self, p):
    99101        from random import randint
     
    107109        assert a == b + c
    108110
    109     @parametrize('p', list_of_sounds)
     111    @params(*list_of_sounds)
    110112    def test_duration(self, p):
    111113        total_frames = 0
     
    116118            total_frames += read
    117119            if read < f.hop_size: break
    118         assert_equal (duration, total_frames)
     120        self.assertEqual(duration, total_frames)
    119121
    120122
    121 class Test_aubio_source_wrong_params(object):
     123class aubio_source_test_wrong_params(TestCase):
    122124
    123125    def test_wrong_file(self):
    124         with assert_raises(RuntimeError):
     126        with self.assertRaises(RuntimeError):
    125127            source('path_to/unexisting file.mp3')
    126128
    127 @unittest.skipIf(default_test_sound is None, no_sounds_msg)
    128 class Test_aubio_source_wrong_params_with_file(TestCase):
     129class aubio_source_test_wrong_params_with_file(aubio_source_test_case_base):
    129130
    130131    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)
    133134
    134135    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)
    137138
    138139    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)
    141142
    142143    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):
    145146            f.seek(-1)
    146147
    147148    def test_wrong_seek_too_large(self):
    148         f = source(default_test_sound)
     149        f = source(self.default_test_sound)
    149150        try:
    150             with assert_raises(ValueError):
     151            with self.assertRaises(ValueError):
    151152                f.seek(f.duration + f.samplerate * 10)
    152         except:
    153             skipTest('seeking after end of stream failed raising ValueError')
     153        except AssertionError:
     154            self.skipTest('seeking after end of stream failed raising ValueError')
    154155
    155 class Test_aubio_source_readmulti(Test_aubio_source_read):
     156class aubio_source_readmulti_test_case(aubio_source_read_test_case):
    156157
    157158    def read_from_source(self, f):
     
    163164                assert_equal(samples[:,read:], 0)
    164165                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))
    172169        return total_frames
    173170
    174 class Test_aubio_source_with(object):
     171class aubio_source_with(aubio_source_test_case_base):
    175172
    176     @parametrize('filename', list_of_sounds)
     173    #@params(*list_of_sounds)
     174    @params(*list_of_sounds)
    177175    def test_read_from_mono(self, filename):
    178176        total_frames = 0
     
    188186
    189187if __name__ == '__main__':
    190     from _tools import run_module_suite
    191     run_module_suite()
     188    main()
  • python/tests/test_source_channels.py

    rf5adffe r0e6ad10  
    99import numpy as np
    1010from numpy.testing import assert_equal
    11 from utils import get_tmp_sink_path
     11from .utils import get_tmp_sink_path
    1212
    1313class aubio_source_test_case(unittest.TestCase):
  • python/tests/test_specdesc.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal, assert_almost_equal
    45from numpy import random, arange, log, zeros
     
    229230
    230231if __name__ == '__main__':
    231     from unittest import main
    232232    main()
  • python/tests/test_zero_crossing_rate.py

    rf5adffe r0e6ad10  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase
    45from aubio import fvec, zero_crossing_rate
     
    4344
    4445if __name__ == '__main__':
    45     from unittest import main
    4646    main()
  • python/tests/utils.py

    rf5adffe r0e6ad10  
    99
    1010def 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)
    1316
    1417def list_all_sounds(rel_dir):
     
    3639        os.unlink(path)
    3740    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)))
    4248
    4349def array_from_yaml_file(filename):
  • requirements.txt

    rf5adffe r0e6ad10  
    11numpy
    2 pytest
     2nose2
  • setup.py

    rf5adffe r0e6ad10  
    9696        ],
    9797    },
     98    test_suite = 'nose2.collector.collector',
     99    extras_require = {
     100        'tests': ['numpy'],
     101        },
    98102    )
  • src/io/sink_apple_audio.c

    rf5adffe r0e6ad10  
    3232#include <AudioToolbox/AudioToolbox.h>
    3333
    34 extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
     34#define FLOAT_TO_SHORT(x) (short)(x * 32768)
     35
     36extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
    3537extern void freeAudioBufferList(AudioBufferList *bufferList);
    3638extern CFURLRef createURLFromPath(const char * path);
     
    7577    return s;
    7678  }
    77 
    7879  // invalid samplerate given, abort
    7980  if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
     
    150151  CFURLRef fileURL = createURLFromPath(s->path);
    151152  bool overwrite = true;
    152 
    153   // set the in-memory format
    154   AudioStreamBasicDescription inputFormat;
    155   memset(&inputFormat, 0, sizeof(AudioStreamBasicDescription));
    156   inputFormat.mFormatID         = kAudioFormatLinearPCM;
    157   inputFormat.mSampleRate       = (Float64)(s->samplerate);
    158   inputFormat.mFormatFlags      = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked;
    159   inputFormat.mChannelsPerFrame = s->channels;
    160   inputFormat.mBitsPerChannel   = sizeof(smpl_t) * 8;
    161   inputFormat.mFramesPerPacket  = 1;
    162   inputFormat.mBytesPerFrame    = inputFormat.mBitsPerChannel * inputFormat.mChannelsPerFrame / 8;
    163   inputFormat.mBytesPerPacket   = inputFormat.mFramesPerPacket * inputFormat.mBytesPerFrame;
    164153  OSStatus err = noErr;
    165154  err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL,
     
    173162    goto beach;
    174163  }
    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)) {
    187165    AUBIO_ERR("sink_apple_audio: error when creating buffer list for %s, "
    188166        "out of memory? \n", s->path);
     
    197175void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) {
    198176  UInt32 c, v;
    199   smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
     177  short *data = (short*)s->bufferList.mBuffers[0].mData;
    200178  uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,
    201179      s->max_frames, write_data->length, write);
     
    203181  for (c = 0; c < s->channels; c++) {
    204182    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]);
    206184    }
    207185  }
     
    212190void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) {
    213191  UInt32 c, v;
    214   smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
     192  short *data = (short*)s->bufferList.mBuffers[0].mData;
    215193  uint_t channels = aubio_sink_validate_input_channels("sink_apple_audio",
    216194      s->path, s->channels, write_data->height);
     
    220198  for (c = 0; c < channels; c++) {
    221199    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]);
    223201    }
    224202  }
     
    229207void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) {
    230208  OSStatus err = noErr;
    231   // set mDataByteSize to match the number of frames to be written
    232   // see https://www.mail-archive.com/coreaudio-api@lists.apple.com/msg01109.html
    233   s->bufferList.mBuffers[0].mDataByteSize = write * s->channels
    234     * sizeof(smpl_t);
    235209  if (s->async) {
    236210    err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
  • src/io/source_apple_audio.c

    rf5adffe r0e6ad10  
    3434#define RT_BYTE3( a )      ( ((a) >> 16) & 0xff )
    3535#define RT_BYTE4( a )      ( ((a) >> 24) & 0xff )
     36
     37#define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
    3638
    3739struct _aubio_source_apple_audio_t {
     
    4749};
    4850
    49 extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
     51extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
    5052extern void freeAudioBufferList(AudioBufferList *bufferList);
    5153extern CFURLRef createURLFromPath(const char * path);
     
    137139
    138140  AudioStreamBasicDescription clientFormat;
    139   propSize = sizeof(AudioStreamBasicDescription);
     141  propSize = sizeof(clientFormat);
    140142  memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription));
    141143  clientFormat.mFormatID         = kAudioFormatLinearPCM;
    142144  clientFormat.mSampleRate       = (Float64)(s->samplerate);
    143   clientFormat.mFormatFlags      = kAudioFormatFlagIsFloat;
     145  clientFormat.mFormatFlags      = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
    144146  clientFormat.mChannelsPerFrame = s->channels;
    145   clientFormat.mBitsPerChannel   = sizeof(smpl_t) * 8;
     147  clientFormat.mBitsPerChannel   = sizeof(short) * 8;
    146148  clientFormat.mFramesPerPacket  = 1;
    147149  clientFormat.mBytesPerFrame    = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8;
    148150  clientFormat.mBytesPerPacket   = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame;
     151  clientFormat.mReserved         = 0;
    149152
    150153  // set the client format description
     
    184187  // allocate the AudioBufferList
    185188  freeAudioBufferList(&s->bufferList);
    186   if (createAudioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {
     189  if (createAubioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {
    187190    AUBIO_ERR("source_apple_audio: failed creating bufferList\n");
    188191    goto beach;
     
    193196}
    194197
    195 static UInt32 aubio_source_apple_audio_read_frame(aubio_source_apple_audio_t *s)
    196 {
    197   UInt32 loadedPackets = s->block_size;
     198void 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;
    198200  OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
    199201  if (err) {
     
    202204        "with ExtAudioFileRead (%s)\n", s->path,
    203205        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;
    213212
    214213  for (v = 0; v < loadedPackets; v++) {
    215     read_to->data[v] = 0.;
     214    buf[v] = 0.;
    216215    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;
    220219  }
    221220  // short read, fill with zeros
    222221  if (loadedPackets < s->block_size) {
    223222    for (v = loadedPackets; v < s->block_size; v++) {
    224       read_to->data[v] = 0.;
     223      buf[v] = 0.;
    225224    }
    226225  }
     
    228227  *read = (uint_t)loadedPackets;
    229228  return;
     229beach:
     230  *read = 0;
     231  return;
    230232}
    231233
    232234void 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;
    236248
    237249  for (v = 0; v < loadedPackets; v++) {
    238250    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]);
    240252    }
    241253  }
     
    245257    for (v = 0; v < loadedPackets; v++) {
    246258      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)]);
    248260      }
    249261    }
     
    253265    for (v = loadedPackets; v < s->block_size; v++) {
    254266      for (c = 0; c < read_to->height; c++) {
    255         read_to->data[c][v] = 0.;
     267        buf[c][v] = 0.;
    256268      }
    257269    }
    258270  }
    259 
    260271  *read = (uint_t)loadedPackets;
     272  return;
     273beach:
     274  *read = 0;
    261275  return;
    262276}
     
    309323  // after a short read, the bufferList size needs to resetted to prepare for a full read
    310324  AudioBufferList *bufferList = &s->bufferList;
    311   bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (smpl_t);
     325  bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (short);
    312326  // do the actual seek
    313327  err = ExtAudioFileSeek(s->audioFile, resampled_pos);
  • src/io/utils_apple_audio.c

    rf5adffe r0e6ad10  
    1313char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
    1414
    15 int createAudioBufferList(AudioBufferList * bufferList, int channels,
    16     int max_source_samples) {
     15int createAubioBufferList(AudioBufferList * bufferList, int channels, int max_source_samples) {
    1716  bufferList->mNumberBuffers = 1;
    1817  bufferList->mBuffers[0].mNumberChannels = channels;
    19   bufferList->mBuffers[0].mData = AUBIO_ARRAY(smpl_t, max_source_samples);
    20   bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(smpl_t);
     18  bufferList->mBuffers[0].mData = AUBIO_ARRAY(short, max_source_samples);
     19  bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(short);
    2120  return 0;
    2221}
  • tests/src/io/base-sink_custom.h

    rf5adffe r0e6ad10  
    2626  char_t *sink_path = argv[2];
    2727
    28   aubio_source_t *src = NULL;
    29   aubio_sink_custom_t *snk = NULL;
    30 
    3128  if ( argc >= 4 ) samplerate = atoi(argv[3]);
    3229  if ( argc >= 5 ) hop_size = atoi(argv[4]);
    3330
    3431  fvec_t *vec = new_fvec(hop_size);
    35   if (!vec) { err = 1; goto failure; }
    3632
    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);
    4035
    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; }
    4339
    4440  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);
    4743    n_frames += read;
    4844  } while ( read == hop_size );
     
    5349
    5450  // close sink now (optional)
    55   aubio_sink_custom_close(snk);
     51  aubio_sink_custom_close(o);
    5652
    5753failure:
    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);
    6258  if (vec)
    6359    del_fvec(vec);
  • tests/src/io/test-sink.c

    rf5adffe r0e6ad10  
    2222  char_t *sink_path = argv[2];
    2323
    24   aubio_source_t *src = NULL;
    25   aubio_sink_t *snk = NULL;
    26 
    2724  if ( argc >= 4 ) samplerate = atoi(argv[3]);
    2825  if ( argc >= 5 ) hop_size = atoi(argv[4]);
    2926
    3027  fvec_t *vec = new_fvec(hop_size);
    31   if (!vec) { err = 1; goto failure; }
    3228
    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);
    3631
    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; }
    3935
    4036  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);
    4339    n_frames += read;
    4440  } while ( read == hop_size );
     
    4945
    5046  // close sink now (optional)
    51   aubio_sink_close(snk);
     47  aubio_sink_close(o);
    5248
    5349failure:
    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);
    5854  if (vec)
    5955    del_fvec(vec);
  • tests/src/onset/test-onset.c

    rf5adffe r0e6ad10  
    7070  uint_t samplerate = 44100;
    7171  // 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;
    7474  // 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;
    7777  // 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;
    8080  // 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;
    8283
    8384  // 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;
    8587
    8688  aubio_onset_t *o;
     
    9193
    9294  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;
    9497  del_aubio_onset(o);
    9598
  • tests/src/tempo/test-tempo.c

    rf5adffe r0e6ad10  
    8282
    8383  // 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;
    8586
    8687  // 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;
    8890
    8991  // 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;
    9194
    9295  // 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;
    9498
    9599  // 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;
    97102
    98103  // test short sizes workaround
    99104  t = new_aubio_tempo("default", 2048, 2048, 500);
    100   if (!t) return 1;
     105  if (!t)
     106    return 1;
    101107
    102108  del_aubio_tempo(t);
    103109
    104110  t = new_aubio_tempo("default", win_size, hop_size, samplerate);
    105   if (!t) return 1;
     111  if (!t)
     112    return 1;
    106113
    107114  in = new_fvec(hop_size);
  • tests/src/temporal/test-filter.c

    rf5adffe r0e6ad10  
    1010  aubio_filter_t *o = new_aubio_filter_c_weighting (44100);
    1111
    12   if (new_aubio_filter(0)) return 1;
     12  if (new_aubio_filter(0))
     13    return 1;
    1314
    14   if (aubio_filter_get_samplerate(o) != 44100) return 1;
     15  if (aubio_filter_get_samplerate(o) != 44100)
     16    return 1;
    1517
    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;
    1720
    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;
    1923
    2024  in->data[impulse_at] = 0.5;
     
    2630  o = new_aubio_filter_a_weighting (32000);
    2731
    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;
    3136
    3237  in->data[impulse_at] = 0.5;
Note: See TracChangeset for help on using the changeset viewer.