Changeset 5573a6b


Ignore:
Timestamp:
Dec 19, 2018, 9:50:06 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
Children:
65628c4, 9630fa8
Parents:
eba24c59 (diff), f5adffe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'feature/sink_vorbis' into feature/sink_flac

Files:
1 added
4 deleted
48 edited

Legend:

Unmodified
Added
Removed
  • .appveyor.yml

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

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

    reba24c59 r5573a6b  
    9090  - which pip
    9191  - pip --version
     92  - pip install coverage
    9293
    9394script:
  • MANIFEST.in

    reba24c59 r5573a6b  
    77include Makefile wscript */wscript_build
    88include aubio.pc.in
    9 include nose2.cfg
    109include requirements.txt
    1110include src/*.c src/*.h
    1211include src/*/*.c src/*/*.h
    1312include examples/*.c examples/*.h
    14 include tests/*.h tests/*/*.c tests/*/*/*.c
     13recursive-include tests *.h *.c *.py
    1514include python/ext/*.h
    1615recursive-include python *.py
    1716include python/README.md
    18 include python/tests/run_all_tests
    1917include python/tests/eval_pitch
    2018include python/tests/*.expected
  • Makefile

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

    reba24c59 r5573a6b  
    9090------------
    9191
    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``:
     92A number of Python tests are provided in the `python/tests`_ folder. To run
     93them, install `pytest`_ and run it from the aubio source directory:
    9494
    9595.. code-block:: console
    9696
    97     $ pip install nose2
    98     $ ./python/tests/run_all_tests
     97    $ pip install pytest
     98    $ git clone https://git.aubio.org/aubio/aubio
     99    $ cd aubio
     100    $ pytest
    99101
    100 .. _demo_filter.py: https://github.com/aubio/aubio/blob/master/python/demos/demo_filter.py
    101 .. _python tests: https://github.com/aubio/aubio/blob/master/python/tests
    102 .. _nose2: https://github.com/nose-devs/nose2
     102.. _python/tests: https://github.com/aubio/aubio/blob/master/python/tests
     103.. _pytest: https://pytest.org
  • python/README.md

    reba24c59 r5573a6b  
    2828-----
    2929
    30 Some examples are available in the [`python/demos`][demos_dir] folder. Each
     30Some examples are available in the [`python/demos` folder][demos_dir]. Each
    3131script is a command line program which accepts one ore more argument.
    3232
  • python/ext/aubiomodule.c

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

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

    reba24c59 r5573a6b  
    4040  }
    4141
    42   level_lin = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_lin(&vec));
     42  level_lin = PyFloat_FromDouble(aubio_level_lin(&vec));
    4343  if (level_lin == NULL) {
    4444    PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
     
    6868  }
    6969
    70   db_spl = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_db_spl(&vec));
     70  db_spl = PyFloat_FromDouble(aubio_db_spl(&vec));
    7171  if (db_spl == NULL) {
    7272    PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
     
    9797  }
    9898
    99   silence_detection = Py_BuildValue("I", aubio_silence_detection(&vec, threshold));
     99  silence_detection = PyLong_FromLong(aubio_silence_detection(&vec, threshold));
    100100  if (silence_detection == NULL) {
    101101    PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");
     
    126126  }
    127127
    128   level_detection = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_detection(&vec, threshold));
     128  level_detection = PyFloat_FromDouble(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 Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));
     197    return PyFloat_FromDouble(aubio_hztomel_htk(v));
    198198  else
    199     return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel(v));
     199    return PyFloat_FromDouble(aubio_hztomel(v));
    200200}
    201201
     
    212212  }
    213213  if (htk != NULL && PyObject_IsTrue(htk) == 1)
    214     return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v));
     214    return PyFloat_FromDouble(aubio_meltohz_htk(v));
    215215  else
    216     return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz(v));
     216    return PyFloat_FromDouble(aubio_meltohz(v));
    217217}
    218218
     
    224224    return NULL;
    225225  }
    226   return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));
     226  return PyFloat_FromDouble(aubio_hztomel_htk(v));
    227227}
    228228
     
    234234    return NULL;
    235235  }
    236   return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v));
    237 }
     236  return PyFloat_FromDouble(aubio_meltohz_htk(v));
     237}
  • python/tests/test_aubio.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    43from numpy.testing import TestCase
    54
     
    1615
    1716if __name__ == '__main__':
     17    from unittest import main
    1818    main()
    19 
  • python/tests/test_aubio_cmd.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
     3from numpy.testing import TestCase
    34import aubio.cmd
    4 from nose2 import main
    5 from numpy.testing import TestCase
    65
    76class aubio_cmd(TestCase):
     
    3231
    3332if __name__ == '__main__':
     33    from unittest import main
    3434    main()
  • python/tests/test_aubio_cut.py

    reba24c59 r5573a6b  
    22
    33import aubio.cut
    4 from nose2 import main
    54from numpy.testing import TestCase
    65
     
    1413
    1514if __name__ == '__main__':
     15    from unittest import main
    1616    main()
  • python/tests/test_cvec.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    43import numpy as np
    54from numpy.testing import TestCase, assert_equal
     
    142141
    143142if __name__ == '__main__':
     143    from unittest import main
    144144    main()
  • python/tests/test_dct.py

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

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    43from numpy.testing import TestCase
    54from numpy.testing import assert_equal, assert_almost_equal
     
    213212
    214213if __name__ == '__main__':
     214    from unittest import main
    215215    main()
  • python/tests/test_filter.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    43from numpy.testing import TestCase, assert_equal, assert_almost_equal
    54from aubio import fvec, digital_filter
    6 from .utils import array_from_text_file
     5from utils import array_from_text_file
    76
    87class aubio_filter_test_case(TestCase):
     
    9594
    9695if __name__ == '__main__':
     96    from unittest import main
    9797    main()
  • python/tests/test_filterbank.py

    reba24c59 r5573a6b  
    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     import nose2
    91     nose2.main()
     90    from unittest import main
     91    main()
  • python/tests/test_filterbank_mel.py

    reba24c59 r5573a6b  
    33import numpy as np
    44from numpy.testing import TestCase, assert_equal, assert_almost_equal
     5from _tools import assert_warns
    56
    67from aubio import fvec, cvec, filterbank, float_type
    7 
    8 import warnings
    9 warnings.filterwarnings('ignore', category=UserWarning, append=True)
    108
    119class aubio_filterbank_mel_test_case(TestCase):
     
    7674        freq_list = [0, samplerate//4, samplerate // 2 + 1]
    7775        f = filterbank(len(freq_list)-2, 1024)
    78         # TODO add assert_warns
    79         f.set_triangle_bands(fvec(freq_list), samplerate)
     76        with assert_warns(UserWarning):
     77            f.set_triangle_bands(fvec(freq_list), samplerate)
    8078
    8179    def test_triangle_freqs_with_not_enough_filters(self):
     
    8482        freq_list = [0, 100, 1000, 4000, 8000, 10000]
    8583        f = filterbank(len(freq_list)-3, 1024)
    86         # TODO add assert_warns
    87         f.set_triangle_bands(fvec(freq_list), samplerate)
     84        with assert_warns(UserWarning):
     85            f.set_triangle_bands(fvec(freq_list), samplerate)
    8886
    8987    def test_triangle_freqs_with_too_many_filters(self):
     
    9290        freq_list = [0, 100, 1000, 4000, 8000, 10000]
    9391        f = filterbank(len(freq_list)-1, 1024)
    94         # TODO add assert_warns
    95         f.set_triangle_bands(fvec(freq_list), samplerate)
     92        with assert_warns(UserWarning):
     93            f.set_triangle_bands(fvec(freq_list), samplerate)
    9694
    9795    def test_triangle_freqs_with_double_value(self):
     
    10098        freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
    10199        f = filterbank(len(freq_list)-2, 1024)
    102         # TODO add assert_warns
    103         f.set_triangle_bands(fvec(freq_list), samplerate)
     100        with assert_warns(UserWarning):
     101            f.set_triangle_bands(fvec(freq_list), samplerate)
    104102
    105103    def test_triangle_freqs_with_triple(self):
     
    108106        freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
    109107        f = filterbank(len(freq_list)-2, 1024)
    110         # TODO add assert_warns
    111         f.set_triangle_bands(fvec(freq_list), samplerate)
     108        with assert_warns(UserWarning):
     109            f.set_triangle_bands(fvec(freq_list), samplerate)
     110
    112111
    113112    def test_triangle_freqs_without_norm(self):
     
    169168
    170169if __name__ == '__main__':
    171     import nose2
    172     nose2.main()
     170    from unittest import main
     171    main()
  • python/tests/test_fvec.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    43import numpy as np
    54from numpy.testing import TestCase, assert_equal, assert_almost_equal
     
    149148
    150149if __name__ == '__main__':
     150    from unittest import main
    151151    main()
  • python/tests/test_fvec_shift.py

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

    reba24c59 r5573a6b  
    44from numpy.testing import TestCase
    55from numpy.testing import assert_equal, assert_almost_equal
     6from _tools import assert_warns
    67import numpy as np
    78import aubio
     
    3839
    3940    def test_meltohz_negative(self):
    40         # TODO add assert_warns
    41         assert_equal(meltohz(-1), 0)
     41        with assert_warns(UserWarning):
     42            assert_equal(meltohz(-1), 0)
    4243
    4344    def test_hztomel_negative(self):
    44         # TODO add assert_warns
    45         assert_equal(hztomel(-1), 0)
     45        with assert_warns(UserWarning):
     46            assert_equal(hztomel(-1), 0)
    4647
    4748
     
    5859
    5960    def test_meltohz_negative(self):
    60         # TODO add assert_warns
    61         assert_equal(meltohz(-1, htk=True), 0)
     61        with assert_warns(UserWarning):
     62            assert_equal(meltohz(-1, htk=True), 0)
    6263        assert_almost_equal(meltohz(2000, htk=True), 3428.7, decimal=1)
    6364        assert_almost_equal(meltohz(1000, htk=True), 1000., decimal=1)
    6465
    6566    def test_hztomel_negative(self):
    66         # TODO add assert_warns
    67         assert_equal(hztomel(-1, htk=True), 0)
     67        with assert_warns(UserWarning):
     68            assert_equal(meltohz(-1, htk=True), 0)
     69        with assert_warns(UserWarning):
     70            assert_equal(hztomel(-1, htk=True), 0)
    6871        assert_almost_equal(hztomel(1000, htk=True), 1000., decimal=1)
    6972
  • python/tests/test_mathutils.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    43from numpy.testing import TestCase, assert_equal
    54from numpy import array, arange, isnan, isinf
     
    102101
    103102if __name__ == '__main__':
     103    from unittest import main
    104104    main()
  • python/tests/test_mfcc.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from nose2 import main
    4 from nose2.tools import params
     3from _tools import parametrize, assert_raises
    54from numpy import random, count_nonzero
    65from numpy.testing import TestCase
     
    1615new_deflts = [1024, 40, 13, 44100]
    1716
    18 class aubio_mfcc(TestCase):
     17class Test_aubio_mfcc(object):
    1918
    20     def setUp(self):
    21         self.o = mfcc()
     19    members_args = 'name'
    2220
    23     def test_default_creation(self):
    24         pass
    25 
    26     def test_delete(self):
    27         del self.o
    28 
    29     @params(*new_params)
     21    @parametrize(members_args, new_params)
    3022    def test_read_only_member(self, name):
    31         o = self.o
    32         with self.assertRaises((TypeError, AttributeError)):
     23        o = mfcc()
     24        with assert_raises((TypeError, AttributeError)):
    3325            setattr(o, name, 0)
    3426
    35     @params(*zip(new_params, new_deflts))
     27    @parametrize('name, expected', zip(new_params, new_deflts))
    3628    def test_default_param(self, name, expected):
    3729        """ test mfcc.{:s} = {:d} """.format(name, expected)
    38         o = self.o
    39         self.assertEqual( getattr(o, name), expected)
     30        o = mfcc()
     31        assert getattr(o, name) == expected
    4032
    4133class aubio_mfcc_wrong_params(TestCase):
     
    8375
    8476
    85 class aubio_mfcc_all_parameters(TestCase):
     77class Test_aubio_mfcc_all_parameters(object):
    8678
    87     @params(
     79    run_values = [
    8880            (2048, 40, 13, 44100),
    8981            (1024, 40, 13, 44100),
     
    10193            (1024, 40, 40, 44100),
    10294            (1024, 40, 3, 44100),
    103             )
     95            ]
     96    run_args = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
     97
     98    @parametrize(run_args, run_values)
    10499    def test_run_with_params(self, buf_size, n_filters, n_coeffs, samplerate):
    105100        " check mfcc can run with reasonable parameters "
     
    149144
    150145if __name__ == '__main__':
    151     main()
     146    from _tools import run_module_suite
     147    run_module_suite()
  • python/tests/test_midi2note.py

    reba24c59 r5573a6b  
    33
    44from aubio import midi2note
    5 from nose2.tools import params
    6 import unittest
     5from _tools import parametrize, assert_raises
    76
    87list_of_known_midis = (
     
    1615        )
    1716
    18 class midi2note_good_values(unittest.TestCase):
     17class Test_midi2note_good_values(object):
    1918
    20     @params(*list_of_known_midis)
     19    @parametrize('midi, note', list_of_known_midis)
    2120    def test_midi2note_known_values(self, midi, note):
    2221        " known values are correctly converted "
    23         self.assertEqual ( midi2note(midi), note )
     22        assert midi2note(midi) == (note)
    2423
    25 class midi2note_wrong_values(unittest.TestCase):
     24class Test_midi2note_wrong_values(object):
    2625
    2726    def test_midi2note_negative_value(self):
    2827        " fails when passed a negative value "
    29         self.assertRaises(ValueError, midi2note, -2)
     28        assert_raises(ValueError, midi2note, -2)
    3029
    3130    def test_midi2note_large(self):
    3231        " fails when passed a value greater than 127 "
    33         self.assertRaises(ValueError, midi2note, 128)
     32        assert_raises(ValueError, midi2note, 128)
    3433
    3534    def test_midi2note_floating_value(self):
    3635        " fails when passed a floating point "
    37         self.assertRaises(TypeError, midi2note, 69.2)
     36        assert_raises(TypeError, midi2note, 69.2)
    3837
    3938    def test_midi2note_character_value(self):
    4039        " fails when passed a value that can not be transformed to integer "
    41         self.assertRaises(TypeError, midi2note, "a")
     40        assert_raises(TypeError, midi2note, "a")
    4241
    4342if __name__ == '__main__':
    44     import nose2
    45     nose2.main()
     43    from _tools import run_module_suite
     44    run_module_suite()
  • python/tests/test_musicutils.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    43import numpy as np
    54from numpy.testing import TestCase
    6 from numpy.testing.utils import assert_equal, assert_almost_equal
     5from numpy.testing import assert_equal, assert_almost_equal
    76from aubio import window, level_lin, db_spl, silence_detection, level_detection
    87from aubio import fvec, float_type
     
    8685
    8786if __name__ == '__main__':
     87    from unittest import main
    8888    main()
  • python/tests/test_note2midi.py

    reba24c59 r5573a6b  
    55
    66from aubio import note2midi, freq2note, note2freq, float_type
    7 from nose2.tools import params
    8 import unittest
     7from numpy.testing import TestCase
     8from _tools import parametrize, assert_raises, skipTest
    99
    1010list_of_known_notes = (
     
    4545        )
    4646
    47 class note2midi_good_values(unittest.TestCase):
     47class Test_note2midi_good_values(object):
    4848
    49     @params(*list_of_known_notes)
     49    @parametrize('note, midi', list_of_known_notes)
    5050    def test_note2midi_known_values(self, note, midi):
    5151        " known values are correctly converted "
    52         self.assertEqual ( note2midi(note), midi )
     52        assert note2midi(note) == midi
    5353
    54     @params(*list_of_known_notes_with_unicode_issues)
     54    @parametrize('note, midi', list_of_known_notes_with_unicode_issues)
    5555    def test_note2midi_known_values_with_unicode_issues(self, note, midi):
    56         " known values are correctly converted, unless decoding is expected to fail"
     56        " difficult values are correctly converted unless expected failure "
    5757        try:
    58             self.assertEqual ( note2midi(note), midi )
     58            assert 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
    6063            import sys
    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
     64            strmsg = "len(u'\\U0001D12A') != 1, expected decoding failure"
     65            strmsg += " | upgrade to Python 3 to fix"
     66            strmsg += " | {:s} | {:s} {:s}"
    6467            if len('\U0001D12A') != 1 and sys.version[0] == '2':
    65                 self.skipTest(strres + " | upgrade to Python 3 to fix")
     68                skipTest(strmsg.format(repr(e), sys.platform, sys.version))
    6669            else:
    6770                raise
    6871
    69 class note2midi_wrong_values(unittest.TestCase):
     72class note2midi_wrong_values(TestCase):
    7073
    7174    def test_note2midi_missing_octave(self):
     
    105108        self.assertRaises(ValueError, note2midi, 'CB+-3')
    106109
    107     @params(*list_of_unknown_notes)
     110class Test_note2midi_unknown_values(object):
     111
     112    @parametrize('note', list_of_unknown_notes)
    108113    def test_note2midi_unknown_values(self, note):
    109114        " unknown values throw out an error "
    110         self.assertRaises(ValueError, note2midi, note)
     115        assert_raises(ValueError, note2midi, note)
    111116
    112 class freq2note_simple_test(unittest.TestCase):
     117class freq2note_simple_test(TestCase):
    113118
    114119    def test_freq2note_above(self):
     
    120125        self.assertEqual("A4", freq2note(439))
    121126
    122 class note2freq_simple_test(unittest.TestCase):
     127class note2freq_simple_test(TestCase):
    123128
    124129    def test_note2freq(self):
     
    134139
    135140if __name__ == '__main__':
    136     import nose2
    137     nose2.main()
     141    from _tools import run_module_suite
     142    run_module_suite()
  • python/tests/test_notes.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    43from numpy.testing import TestCase, assert_equal, assert_almost_equal
    5 from aubio import notes
     4from aubio import notes, source
     5import numpy as np
     6from utils import list_all_sounds
     7
     8list_of_sounds = list_all_sounds('sounds')
    69
    710AUBIO_DEFAULT_NOTES_SILENCE = -70.
     
    5356            self.o.set_release_drop(val)
    5457
    55 from .utils import list_all_sounds
    56 list_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
    6361        win_s = 512 # fft size
    6462        hop_s = 256 # hop size
     
    9391
    9492if __name__ == '__main__':
     93    from unittest import main
    9594    main()
  • python/tests/test_onset.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    43from numpy.testing import TestCase, assert_equal, assert_almost_equal
    54from aubio import onset, fvec
     
    117116
    118117if __name__ == '__main__':
     118    from unittest import main
    119119    main()
  • python/tests/test_phasevoc.py

    reba24c59 r5573a6b  
    22
    33from numpy.testing import TestCase, assert_equal, assert_array_less
     4from _tools import parametrize
    45from aubio import fvec, cvec, pvoc, float_type
    5 from nose2 import main
    6 from nose2.tools import params
    76import numpy as np
    87
     
    1918    return np.random.rand(hop_s).astype(float_type) * 2. - 1.
    2019
    21 class aubio_pvoc_test_case(TestCase):
     20class Test_aubio_pvoc_test_case(object):
    2221    """ pvoc object test case """
    2322
     
    6665            assert_equal ( t, 0.)
    6766
    68     @params(
     67    resynth_noise_args = "hop_s, ratio"
     68    resynth_noise_values = [
    6969            ( 256, 8),
    7070            ( 256, 4),
     
    8888            (8192, 4),
    8989            (8192, 2),
    90             )
     90            ]
     91
     92    @parametrize(resynth_noise_args, resynth_noise_values)
    9193    def test_resynth_steps_noise(self, hop_s, ratio):
    9294        """ check the resynthesis of a random signal is correct """
     
    9496        self.reconstruction(sigin, hop_s, ratio)
    9597
    96     @params(
     98    resynth_sine_args = "samplerate, hop_s, ratio, freq"
     99    resynth_sine_values = [
    97100            (44100,  256, 8,   441),
    98101            (44100,  256, 4,  1203),
     
    109112            (96000, 1024, 8, 47000),
    110113            (96000, 1024, 8,    20),
    111             )
     114            ]
     115
     116    @parametrize(resynth_sine_args, resynth_sine_values)
    112117    def test_resynth_steps_sine(self, samplerate, hop_s, ratio, freq):
    113118        """ check the resynthesis of a sine is correct """
     
    200205
    201206if __name__ == '__main__':
     207    from unittest import main
    202208    main()
    203 
  • python/tests/test_pitch.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from unittest import TestCase, main
    4 from numpy.testing import assert_equal
     3from numpy.testing import TestCase, assert_equal
    54from numpy import sin, arange, mean, median, isnan, pi
    65from aubio import fvec, pitch, freqtomidi, float_type
     
    117116for algo in pitch_algorithms:
    118117    for mode in signal_modes:
    119         test_method = create_test (algo, mode)
    120         test_method.__name__ = 'test_pitch_%s_%d_%d_%dHz_sin_%.0f' % ( algo,
     118        _test_method = create_test (algo, mode)
     119        _test_method.__name__ = 'test_pitch_%s_%d_%d_%dHz_sin_%.0f' % ( algo,
    121120                mode[0], mode[1], mode[2], mode[3] )
    122         setattr (aubio_pitch_Sinusoid, test_method.__name__, test_method)
     121        setattr (aubio_pitch_Sinusoid, _test_method.__name__, _test_method)
    123122
    124123if __name__ == '__main__':
     124    from unittest import main
    125125    main()
  • python/tests/test_sink.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from nose2 import main
    4 from nose2.tools import params
    53from numpy.testing import TestCase
    64from aubio import fvec, source, sink
    7 from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
    8 
    9 import warnings
    10 warnings.filterwarnings('ignore', category=UserWarning, append=True)
     5from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
     6from _tools import parametrize, skipTest, assert_raises
    117
    128list_of_sounds = list_all_sounds('sounds')
     
    2420            all_params.append((hop_size, samplerate, soundfile))
    2521
    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\'')
     22class Test_aubio_sink(object):
    3123
    3224    def test_wrong_filename(self):
    33         with self.assertRaises(RuntimeError):
     25        with assert_raises(RuntimeError):
    3426            sink('')
    3527
    3628    def test_wrong_samplerate(self):
    37         with self.assertRaises(RuntimeError):
     29        with assert_raises(RuntimeError):
    3830            sink(get_tmp_sink_path(), -1)
    3931
    4032    def test_wrong_samplerate_too_large(self):
    41         with self.assertRaises(RuntimeError):
     33        with assert_raises(RuntimeError):
    4234            sink(get_tmp_sink_path(), 1536001, 2)
    4335
    4436    def test_wrong_channels(self):
    45         with self.assertRaises(RuntimeError):
     37        with assert_raises(RuntimeError):
    4638            sink(get_tmp_sink_path(), 44100, -1)
    4739
    4840    def test_wrong_channels_too_large(self):
    49         with self.assertRaises(RuntimeError):
     41        with assert_raises(RuntimeError):
    5042            sink(get_tmp_sink_path(), 44100, 202020)
    5143
     
    6759        shutil.rmtree(tmpdir)
    6860
    69     @params(*all_params)
     61    @parametrize('hop_size, samplerate, path', all_params)
    7062    def test_read_and_write(self, hop_size, samplerate, path):
    71 
    7263        try:
    7364            f = source(path, samplerate, hop_size)
    7465        except RuntimeError as e:
    75             self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
     66            err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
     67            skipTest(err_msg.format(str(e), hop_size, samplerate))
    7668        if samplerate == 0: samplerate = f.samplerate
    7769        sink_path = get_tmp_sink_path()
     
    8577        del_tmp_sink_path(sink_path)
    8678
    87     @params(*all_params)
     79    @parametrize('hop_size, samplerate, path', all_params)
    8880    def test_read_and_write_multi(self, hop_size, samplerate, path):
    8981        try:
    9082            f = source(path, samplerate, hop_size)
    9183        except RuntimeError as e:
    92             self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
     84            err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
     85            skipTest(err_msg.format(str(e), hop_size, samplerate))
    9386        if samplerate == 0: samplerate = f.samplerate
    9487        sink_path = get_tmp_sink_path()
     
    126119
    127120if __name__ == '__main__':
    128     main()
     121    from _tools import run_module_suite
     122    run_module_suite()
  • python/tests/test_slicing.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    43from numpy.testing import TestCase, assert_equal
    54from aubio import slice_source_at_stamps
    6 from .utils import count_files_in_directory, get_default_test_sound
    7 from .utils import count_samples_in_directory, count_samples_in_file
     5from utils import count_files_in_directory, get_default_test_sound
     6from utils import count_samples_in_directory, count_samples_in_file
    87
    98import tempfile
     
    168167
    169168if __name__ == '__main__':
     169    from unittest import main
    170170    main()
  • python/tests/test_source.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from nose2 import main
    4 from nose2.tools import params
     3
    54from numpy.testing import TestCase, assert_equal
    65from aubio import source
    7 from .utils import list_all_sounds
    8 
    9 import warnings
    10 warnings.filterwarnings('ignore', category=UserWarning, append=True)
     6from utils import list_all_sounds
     7import unittest
     8from _tools import parametrize, assert_raises, assert_equal, skipTest
    119
    1210list_of_sounds = list_all_sounds('sounds')
     
    1412hop_sizes = [512, 1024, 64]
    1513
    16 path = None
     14default_test_sound = len(list_of_sounds) and list_of_sounds[0] or None
    1715
    1816all_params = []
     
    2220            all_params.append((hop_size, samplerate, soundfile))
    2321
     22no_sounds_msg = "no test sounds, add some in 'python/tests/sounds/'!"
    2423
    25 class aubio_source_test_case_base(TestCase):
     24_debug = False
    2625
    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]
     26class Test_aubio_source_test_case(object):
    3127
    32 class aubio_source_test_case(aubio_source_test_case_base):
    33 
    34     @params(*list_of_sounds)
     28    @parametrize('filename', list_of_sounds)
    3529    def test_close_file(self, filename):
    3630        samplerate = 0 # use native samplerate
     
    3933        f.close()
    4034
    41     @params(*list_of_sounds)
     35    @parametrize('filename', list_of_sounds)
    4236    def test_close_file_twice(self, filename):
    4337        samplerate = 0 # use native samplerate
     
    4741        f.close()
    4842
    49 class aubio_source_read_test_case(aubio_source_test_case_base):
     43class Test_aubio_source_read(object):
    5044
    5145    def read_from_source(self, f):
     
    5751                assert_equal(samples[read:], 0)
    5852                break
    59         #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"
    60         #result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri
    61         #print (result_str.format(*result_params))
     53        if _debug:
     54            result_str = "read {:.2f}s ({:d} frames"
     55            result_str += " in {:d} blocks at {:d}Hz) from {:s}"
     56            result_params = total_frames / float(f.samplerate), total_frames, \
     57                    total_frames//f.hop_size, f.samplerate, f.uri
     58            print (result_str.format(*result_params))
    6259        return total_frames
    6360
    64     @params(*all_params)
     61    @parametrize('hop_size, samplerate, soundfile', all_params)
    6562    def test_samplerate_hopsize(self, hop_size, samplerate, soundfile):
    6663        try:
    6764            f = source(soundfile, samplerate, hop_size)
    6865        except RuntimeError as e:
    69             self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
     66            err_msg = 'failed opening with hop_s={:d}, samplerate={:d} ({:s})'
     67            skipTest(err_msg.format(hop_size, samplerate, str(e)))
    7068        assert f.samplerate != 0
    7169        read_frames = self.read_from_source(f)
    7270        if 'f_' in soundfile and samplerate == 0:
    7371            import re
    74             f = re.compile('.*_\([0:9]*f\)_.*')
     72            f = re.compile(r'.*_\([0:9]*f\)_.*')
    7573            match_f = re.findall('([0-9]*)f_', soundfile)
    7674            if len(match_f) == 1:
    7775                expected_frames = int(match_f[0])
    78                 self.assertEqual(expected_frames, read_frames)
     76                assert_equal(expected_frames, read_frames)
    7977
    80     @params(*list_of_sounds)
     78    @parametrize('p', list_of_sounds)
    8179    def test_samplerate_none(self, p):
    8280        f = source(p)
     
    8482        self.read_from_source(f)
    8583
    86     @params(*list_of_sounds)
     84    @parametrize('p', list_of_sounds)
    8785    def test_samplerate_0(self, p):
    8886        f = source(p, 0)
     
    9088        self.read_from_source(f)
    9189
    92     @params(*list_of_sounds)
     90    @parametrize('p', list_of_sounds)
    9391    def test_zero_hop_size(self, p):
    9492        f = source(p, 0, 0)
     
    9795        self.read_from_source(f)
    9896
    99     @params(*list_of_sounds)
     97    @parametrize('p', list_of_sounds)
    10098    def test_seek_to_half(self, p):
    10199        from random import randint
     
    109107        assert a == b + c
    110108
    111     @params(*list_of_sounds)
     109    @parametrize('p', list_of_sounds)
    112110    def test_duration(self, p):
    113111        total_frames = 0
     
    118116            total_frames += read
    119117            if read < f.hop_size: break
    120         self.assertEqual(duration, total_frames)
     118        assert_equal (duration, total_frames)
    121119
    122120
    123 class aubio_source_test_wrong_params(TestCase):
     121class Test_aubio_source_wrong_params(object):
    124122
    125123    def test_wrong_file(self):
    126         with self.assertRaises(RuntimeError):
     124        with assert_raises(RuntimeError):
    127125            source('path_to/unexisting file.mp3')
    128126
    129 class aubio_source_test_wrong_params_with_file(aubio_source_test_case_base):
     127@unittest.skipIf(default_test_sound is None, no_sounds_msg)
     128class Test_aubio_source_wrong_params_with_file(TestCase):
    130129
    131130    def test_wrong_samplerate(self):
    132         with self.assertRaises(ValueError):
    133             source(self.default_test_sound, -1)
     131        with assert_raises(ValueError):
     132            source(default_test_sound, -1)
    134133
    135134    def test_wrong_hop_size(self):
    136         with self.assertRaises(ValueError):
    137             source(self.default_test_sound, 0, -1)
     135        with assert_raises(ValueError):
     136            source(default_test_sound, 0, -1)
    138137
    139138    def test_wrong_channels(self):
    140         with self.assertRaises(ValueError):
    141             source(self.default_test_sound, 0, 0, -1)
     139        with assert_raises(ValueError):
     140            source(default_test_sound, 0, 0, -1)
    142141
    143142    def test_wrong_seek(self):
    144         f = source(self.default_test_sound)
    145         with self.assertRaises(ValueError):
     143        f = source(default_test_sound)
     144        with assert_raises(ValueError):
    146145            f.seek(-1)
    147146
    148147    def test_wrong_seek_too_large(self):
    149         f = source(self.default_test_sound)
     148        f = source(default_test_sound)
    150149        try:
    151             with self.assertRaises(ValueError):
     150            with assert_raises(ValueError):
    152151                f.seek(f.duration + f.samplerate * 10)
    153         except AssertionError:
    154             self.skipTest('seeking after end of stream failed raising ValueError')
     152        except:
     153            skipTest('seeking after end of stream failed raising ValueError')
    155154
    156 class aubio_source_readmulti_test_case(aubio_source_read_test_case):
     155class Test_aubio_source_readmulti(Test_aubio_source_read):
    157156
    158157    def read_from_source(self, f):
     
    164163                assert_equal(samples[:,read:], 0)
    165164                break
    166         #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"
    167         #result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri
    168         #print (result_str.format(*result_params))
     165        if _debug:
     166            result_str = "read {:.2f}s ({:d} frames in {:d} channels"
     167            result_str += " and {:d} blocks at {:d}Hz) from {:s}"
     168            result_params = total_frames / float(f.samplerate), total_frames, \
     169                    f.channels, int(total_frames/f.hop_size), \
     170                    f.samplerate, f.uri
     171            print (result_str.format(*result_params))
    169172        return total_frames
    170173
    171 class aubio_source_with(aubio_source_test_case_base):
     174class Test_aubio_source_with(object):
    172175
    173     #@params(*list_of_sounds)
    174     @params(*list_of_sounds)
     176    @parametrize('filename', list_of_sounds)
    175177    def test_read_from_mono(self, filename):
    176178        total_frames = 0
     
    186188
    187189if __name__ == '__main__':
    188     main()
     190    from _tools import run_module_suite
     191    run_module_suite()
  • python/tests/test_source_channels.py

    reba24c59 r5573a6b  
    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

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    43from numpy.testing import TestCase, assert_equal, assert_almost_equal
    54from numpy import random, arange, log, zeros
     
    230229
    231230if __name__ == '__main__':
     231    from unittest import main
    232232    main()
  • python/tests/test_zero_crossing_rate.py

    reba24c59 r5573a6b  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    43from numpy.testing import TestCase
    54from aubio import fvec, zero_crossing_rate
     
    4443
    4544if __name__ == '__main__':
     45    from unittest import main
    4646    main()
  • python/tests/utils.py

    reba24c59 r5573a6b  
    99
    1010def array_from_text_file(filename, dtype = 'float'):
    11     filename = os.path.join(os.path.dirname(__file__), filename)
    12     with open(filename) as f:
    13         lines = f.readlines()
    14     return np.array([line.split() for line in lines],
    15             dtype = dtype)
     11    realpathname = os.path.join(os.path.dirname(__file__), filename)
     12    return np.loadtxt(realpathname, dtype = dtype)
    1613
    1714def list_all_sounds(rel_dir):
     
    3936        os.unlink(path)
    4037    except WindowsError as e:
    41         print("deleting {:s} failed ({:s}), reopening".format(path, repr(e)))
    42         with open(path, 'wb') as f:
    43             f.close()
    44         try:
    45             os.unlink(path)
    46         except WindowsError as f:
    47             print("deleting {:s} failed ({:s}), aborting".format(path, repr(e)))
     38        # removing the temporary directory sometimes fails on windows
     39        import warnings
     40        errmsg = "failed deleting temporary file {:s} ({:s})"
     41        warnings.warn(UserWarning(errmsg.format(path, repr(e))))
    4842
    4943def array_from_yaml_file(filename):
  • requirements.txt

    reba24c59 r5573a6b  
    11numpy
    2 nose2
     2pytest
  • setup.py

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

    reba24c59 r5573a6b  
    3232#include <AudioToolbox/AudioToolbox.h>
    3333
    34 #define FLOAT_TO_SHORT(x) (short)(x * 32768)
    35 
    36 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
     34extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
    3735extern void freeAudioBufferList(AudioBufferList *bufferList);
    3836extern CFURLRef createURLFromPath(const char * path);
     
    7775    return s;
    7876  }
     77
    7978  // invalid samplerate given, abort
    8079  if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
     
    151150  CFURLRef fileURL = createURLFromPath(s->path);
    152151  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;
    153164  OSStatus err = noErr;
    154165  err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL,
     
    162173    goto beach;
    163174  }
    164   if (createAubioBufferList(&s->bufferList, s->channels, s->max_frames * s->channels)) {
     175
     176  err = ExtAudioFileSetProperty(s->audioFile,
     177      kExtAudioFileProperty_ClientDataFormat,
     178      sizeof(AudioStreamBasicDescription), &inputFormat);
     179  if (err) {
     180    char_t errorstr[20];
     181    AUBIO_ERR("sink_apple_audio: error when trying to set output format on %s "
     182        "(%s)\n", s->path, getPrintableOSStatusError(errorstr, err));
     183    goto beach;
     184  }
     185
     186  if (createAudioBufferList(&s->bufferList, s->channels, s->max_frames * s->channels)) {
    165187    AUBIO_ERR("sink_apple_audio: error when creating buffer list for %s, "
    166188        "out of memory? \n", s->path);
     
    175197void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) {
    176198  UInt32 c, v;
    177   short *data = (short*)s->bufferList.mBuffers[0].mData;
     199  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    178200  uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,
    179201      s->max_frames, write_data->length, write);
     
    181203  for (c = 0; c < s->channels; c++) {
    182204    for (v = 0; v < length; v++) {
    183       data[v * s->channels + c] = FLOAT_TO_SHORT(write_data->data[v]);
     205      data[v * s->channels + c] = write_data->data[v];
    184206    }
    185207  }
     
    190212void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) {
    191213  UInt32 c, v;
    192   short *data = (short*)s->bufferList.mBuffers[0].mData;
     214  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    193215  uint_t channels = aubio_sink_validate_input_channels("sink_apple_audio",
    194216      s->path, s->channels, write_data->height);
     
    198220  for (c = 0; c < channels; c++) {
    199221    for (v = 0; v < length; v++) {
    200       data[v * s->channels + c] = FLOAT_TO_SHORT(write_data->data[c][v]);
     222      data[v * s->channels + c] = write_data->data[c][v];
    201223    }
    202224  }
     
    207229void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) {
    208230  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);
    209235  if (s->async) {
    210236    err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
  • src/io/source_apple_audio.c

    reba24c59 r5573a6b  
    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)
    3836
    3937struct _aubio_source_apple_audio_t {
     
    4947};
    5048
    51 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
     49extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
    5250extern void freeAudioBufferList(AudioBufferList *bufferList);
    5351extern CFURLRef createURLFromPath(const char * path);
     
    139137
    140138  AudioStreamBasicDescription clientFormat;
    141   propSize = sizeof(clientFormat);
     139  propSize = sizeof(AudioStreamBasicDescription);
    142140  memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription));
    143141  clientFormat.mFormatID         = kAudioFormatLinearPCM;
    144142  clientFormat.mSampleRate       = (Float64)(s->samplerate);
    145   clientFormat.mFormatFlags      = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
     143  clientFormat.mFormatFlags      = kAudioFormatFlagIsFloat;
    146144  clientFormat.mChannelsPerFrame = s->channels;
    147   clientFormat.mBitsPerChannel   = sizeof(short) * 8;
     145  clientFormat.mBitsPerChannel   = sizeof(smpl_t) * 8;
    148146  clientFormat.mFramesPerPacket  = 1;
    149147  clientFormat.mBytesPerFrame    = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8;
    150148  clientFormat.mBytesPerPacket   = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame;
    151   clientFormat.mReserved         = 0;
    152149
    153150  // set the client format description
     
    187184  // allocate the AudioBufferList
    188185  freeAudioBufferList(&s->bufferList);
    189   if (createAubioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {
     186  if (createAudioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {
    190187    AUBIO_ERR("source_apple_audio: failed creating bufferList\n");
    191188    goto beach;
     
    196193}
    197194
    198 void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to, uint_t * read) {
    199   UInt32 c, v, loadedPackets = s->block_size;
     195static UInt32 aubio_source_apple_audio_read_frame(aubio_source_apple_audio_t *s)
     196{
     197  UInt32 loadedPackets = s->block_size;
    200198  OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
    201199  if (err) {
     
    204202        "with ExtAudioFileRead (%s)\n", s->path,
    205203        getPrintableOSStatusError(errorstr, err));
    206     goto beach;
    207   }
    208 
    209   short *data = (short*)s->bufferList.mBuffers[0].mData;
    210 
    211   smpl_t *buf = read_to->data;
     204  }
     205  return loadedPackets;
     206}
     207
     208void 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;
    212213
    213214  for (v = 0; v < loadedPackets; v++) {
    214     buf[v] = 0.;
     215    read_to->data[v] = 0.;
    215216    for (c = 0; c < s->channels; c++) {
    216       buf[v] += SHORT_TO_FLOAT(data[ v * s->channels + c]);
    217     }
    218     buf[v] /= (smpl_t)s->channels;
     217      read_to->data[v] += data[ v * s->channels + c];
     218    }
     219    read_to->data[v] /= (smpl_t)s->channels;
    219220  }
    220221  // short read, fill with zeros
    221222  if (loadedPackets < s->block_size) {
    222223    for (v = loadedPackets; v < s->block_size; v++) {
    223       buf[v] = 0.;
     224      read_to->data[v] = 0.;
    224225    }
    225226  }
     
    227228  *read = (uint_t)loadedPackets;
    228229  return;
    229 beach:
    230   *read = 0;
    231   return;
    232230}
    233231
    234232void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) {
    235   UInt32 c, v, loadedPackets = s->block_size;
    236   OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
    237   if (err) {
    238     char_t errorstr[20];
    239     AUBIO_ERROR("source_apple_audio: error while reading %s "
    240         "with ExtAudioFileRead (%s)\n", s->path,
    241         getPrintableOSStatusError(errorstr, err));
    242     goto beach;
    243   }
    244 
    245   short *data = (short*)s->bufferList.mBuffers[0].mData;
    246 
    247   smpl_t **buf = read_to->data;
     233  uint_t c, v;
     234  UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
     235  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    248236
    249237  for (v = 0; v < loadedPackets; v++) {
    250238    for (c = 0; c < read_to->height; c++) {
    251       buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + c]);
     239      read_to->data[c][v] = data[ v * s->channels + c];
    252240    }
    253241  }
     
    257245    for (v = 0; v < loadedPackets; v++) {
    258246      for (c = s->channels; c < read_to->height; c++) {
    259         buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + (s->channels - 1)]);
     247        read_to->data[c][v] = data[ v * s->channels + (s->channels - 1)];
    260248      }
    261249    }
     
    265253    for (v = loadedPackets; v < s->block_size; v++) {
    266254      for (c = 0; c < read_to->height; c++) {
    267         buf[c][v] = 0.;
     255        read_to->data[c][v] = 0.;
    268256      }
    269257    }
    270258  }
     259
    271260  *read = (uint_t)loadedPackets;
    272   return;
    273 beach:
    274   *read = 0;
    275261  return;
    276262}
     
    323309  // after a short read, the bufferList size needs to resetted to prepare for a full read
    324310  AudioBufferList *bufferList = &s->bufferList;
    325   bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (short);
     311  bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (smpl_t);
    326312  // do the actual seek
    327313  err = ExtAudioFileSeek(s->audioFile, resampled_pos);
  • src/io/utils_apple_audio.c

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

    reba24c59 r5573a6b  
    2626  char_t *sink_path = argv[2];
    2727
     28  aubio_source_t *src = NULL;
     29  aubio_sink_custom_t *snk = NULL;
     30
    2831  if ( argc >= 4 ) samplerate = atoi(argv[3]);
    2932  if ( argc >= 5 ) hop_size = atoi(argv[4]);
    3033
    3134  fvec_t *vec = new_fvec(hop_size);
     35  if (!vec) { err = 1; goto failure; }
    3236
    33   aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
    34   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
     37  src = new_aubio_source(source_path, samplerate, hop_size);
     38  if (!src) { err = 1; goto failure; }
     39  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(src);
    3540
    36   aubio_sink_custom_t *o = new_aubio_sink_custom(sink_path, samplerate);
    37 
    38   if (!vec || !i || !o) { err = 1; goto failure; }
     41  snk = new_aubio_sink_custom(sink_path, samplerate);
     42  if (!snk) { err = 1; goto failure; }
    3943
    4044  do {
    41     aubio_source_do(i, vec, &read);
    42     aubio_sink_custom_do(o, vec, read);
     45    aubio_source_do(src, vec, &read);
     46    aubio_sink_custom_do(snk, vec, read);
    4347    n_frames += read;
    4448  } while ( read == hop_size );
     
    4953
    5054  // close sink now (optional)
    51   aubio_sink_custom_close(o);
     55  aubio_sink_custom_close(snk);
    5256
    5357failure:
    54   if (o)
    55     del_aubio_sink_custom(o);
    56   if (i)
    57     del_aubio_source(i);
     58  if (snk)
     59    del_aubio_sink_custom(snk);
     60  if (src)
     61    del_aubio_source(src);
    5862  if (vec)
    5963    del_fvec(vec);
  • tests/src/io/test-sink.c

    reba24c59 r5573a6b  
    2222  char_t *sink_path = argv[2];
    2323
     24  aubio_source_t *src = NULL;
     25  aubio_sink_t *snk = NULL;
     26
    2427  if ( argc >= 4 ) samplerate = atoi(argv[3]);
    2528  if ( argc >= 5 ) hop_size = atoi(argv[4]);
    2629
    2730  fvec_t *vec = new_fvec(hop_size);
     31  if (!vec) { err = 1; goto failure; }
    2832
    29   aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
    30   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
     33  src = new_aubio_source(source_path, samplerate, hop_size);
     34  if (!src) { err = 1; goto failure; }
     35  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(src);
    3136
    32   aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
    33 
    34   if (!vec || !i || !o) { err = 1; goto failure; }
     37  snk = new_aubio_sink(sink_path, samplerate);
     38  if (!snk) { err = 1; goto failure; }
    3539
    3640  do {
    37     aubio_source_do(i, vec, &read);
    38     aubio_sink_do(o, vec, read);
     41    aubio_source_do(src, vec, &read);
     42    aubio_sink_do(snk, vec, read);
    3943    n_frames += read;
    4044  } while ( read == hop_size );
     
    4549
    4650  // close sink now (optional)
    47   aubio_sink_close(o);
     51  aubio_sink_close(snk);
    4852
    4953failure:
    50   if (o)
    51     del_aubio_sink(o);
    52   if (i)
    53     del_aubio_source(i);
     54  if (snk)
     55    del_aubio_sink(snk);
     56  if (src)
     57    del_aubio_source(src);
    5458  if (vec)
    5559    del_fvec(vec);
  • tests/src/onset/test-onset.c

    reba24c59 r5573a6b  
    7070  uint_t samplerate = 44100;
    7171  // hop_size < 1
    72   if (new_aubio_onset("default", 5, 0, samplerate))
    73     return 1;
     72  if (new_aubio_onset("default", 5, 0, samplerate)) return 1;
     73
    7474  // buf_size < 2
    75   if (new_aubio_onset("default", 1, 1, samplerate))
    76     return 1;
     75  if (new_aubio_onset("default", 1, 1, samplerate)) return 1;
     76
    7777  // buf_size < hop_size
    78   if (new_aubio_onset("default", hop_size, win_size, samplerate))
    79     return 1;
     78  if (new_aubio_onset("default", hop_size, win_size, samplerate)) return 1;
     79
    8080  // samplerate < 1
    81   if (new_aubio_onset("default", 1024, 512, 0))
    82     return 1;
     81  if (new_aubio_onset("default", 1024, 512, 0)) return 1;
    8382
    8483  // specdesc creation failed
    85   if (new_aubio_onset("abcd", win_size, win_size/2, samplerate))
    86     return 1;
     84  if (new_aubio_onset("abcd", win_size, win_size/2, samplerate)) return 1;
    8785
    8886  aubio_onset_t *o;
     
    9391
    9492  o = new_aubio_onset("default", win_size, hop_size, samplerate);
    95   if (!aubio_onset_set_default_parameters(o, "wrong_type"))
    96     return 1;
     93  if (!aubio_onset_set_default_parameters(o, "wrong_type")) return 1;
    9794  del_aubio_onset(o);
    9895
  • tests/src/tempo/test-tempo.c

    reba24c59 r5573a6b  
    8282
    8383  // test wrong method fails
    84   if (new_aubio_tempo("unexisting_method", win_size, hop_size, samplerate))
    85     return 1;
     84  if (new_aubio_tempo("undefined", win_size, hop_size, samplerate)) return 1;
    8685
    8786  // test hop > win fails
    88   if (new_aubio_tempo("default", hop_size, win_size, samplerate))
    89     return 1;
     87  if (new_aubio_tempo("default", hop_size, win_size, samplerate)) return 1;
    9088
    9189  // test null hop_size fails
    92   if (new_aubio_tempo("default", win_size, 0, samplerate))
    93     return 1;
     90  if (new_aubio_tempo("default", win_size, 0, samplerate)) return 1;
    9491
    9592  // test 1 buf_size fails
    96   if (new_aubio_tempo("default", 1, 1, samplerate))
    97     return 1;
     93  if (new_aubio_tempo("default", 1, 1, samplerate)) return 1;
    9894
    9995  // test null samplerate fails
    100   if (new_aubio_tempo("default", win_size, hop_size, 0))
    101     return 1;
     96  if (new_aubio_tempo("default", win_size, hop_size, 0)) return 1;
    10297
    10398  // test short sizes workaround
    10499  t = new_aubio_tempo("default", 2048, 2048, 500);
    105   if (!t)
    106     return 1;
     100  if (!t) return 1;
    107101
    108102  del_aubio_tempo(t);
    109103
    110104  t = new_aubio_tempo("default", win_size, hop_size, samplerate);
    111   if (!t)
    112     return 1;
     105  if (!t) return 1;
    113106
    114107  in = new_fvec(hop_size);
  • tests/src/temporal/test-filter.c

    reba24c59 r5573a6b  
    1010  aubio_filter_t *o = new_aubio_filter_c_weighting (44100);
    1111
    12   if (new_aubio_filter(0))
    13     return 1;
     12  if (new_aubio_filter(0)) return 1;
    1413
    15   if (aubio_filter_get_samplerate(o) != 44100)
    16     return 1;
     14  if (aubio_filter_get_samplerate(o) != 44100) return 1;
    1715
    18   if (aubio_filter_set_c_weighting (o, -1) == 0)
    19     return 1;
     16  if (aubio_filter_set_c_weighting (o, -1) == 0) return 1;
    2017
    21   if (aubio_filter_set_c_weighting (0, 32000) == 0)
    22     return 1;
     18  if (aubio_filter_set_c_weighting (0, 32000) == 0) return 1;
    2319
    2420  in->data[impulse_at] = 0.5;
     
    3026  o = new_aubio_filter_a_weighting (32000);
    3127
    32   if (aubio_filter_set_a_weighting (o, -1) == 0)
    33     return 1;
    34   if (aubio_filter_set_a_weighting (0, 32000) == 0)
    35     return 1;
     28  if (aubio_filter_set_a_weighting (o, -1) == 0) return 1;
     29
     30  if (aubio_filter_set_a_weighting (0, 32000) == 0) return 1;
    3631
    3732  in->data[impulse_at] = 0.5;
Note: See TracChangeset for help on using the changeset viewer.