Changes in / [868c6b8:dfe6ab6]


Ignore:
Files:
2 added
4 deleted
70 edited

Legend:

Unmodified
Added
Removed
  • .appveyor.yml

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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    33matrix:
    44  include:
    5     - python: 3.5
    6       os: linux
    7       compiler: gcc
    8     - python: 3.4
    9       os: linux
    10       compiler: gcc
    11     - python: 2.7
     5    - python: 3.6
    126      os: linux
    137      compiler: gcc
     
    159      os: linux
    1610      compiler: gcc
    17       env: CFLAGS="-Os" WAFOPTS="--disable-samplerate --disable-sndfile"
    18     - python: 3.4
     11      env: WAFOPTS="--build-type=debug"
     12    - python: 2.7
     13      os: linux
     14      compiler: gcc
     15    - python: "pypy3.5"
     16      os: linux
     17      compiler: gcc
     18      env: CFLAGS="-Os" WAFOPTS="--disable-avcodec"
     19    - python: 3.6
     20      os: linux
     21      compiler: gcc
     22      env: CFLAGS="-Os" WAFOPTS="--disable-samplerate"
     23    - python: 3.5
    1924      os: linux
    2025      compiler: gcc
     
    8691  - which pip
    8792  - pip --version
     93  - pip install coverage
    8894
    8995script:
  • ChangeLog

    r868c6b8 rdfe6ab6  
     12018-12-19 Paul Brossier <piem@aubio.org>
     2
     3        [ Overview ]
     4
     5        * VERSION: bump to 0.4.9
     6        * library: improve stability, fixing potential crashes and memory leaks on
     7        invalid arguments; improve library messages and reporting of system errors
     8        * tests/: major clean-up, check return codes, increase code coverage
     9        * python/tests/: switch to pytest (closes gh-163), check emitted warnings
     10        * python/: add pages to manual with brief descriptions of classes
     11
     12        [ Fixes ]
     13
     14        * security: improve arguments validation in new_aubio_filterbank (prevent
     15        possible null-pointer dereference on invalid n_filters, CVE-2018-19801),
     16        new_aubio-tempo (prevent possible buffer overflow, CVE-2018-19800), and
     17        new_aubio_onset (prevent null-pointer dereference, CVE-2018-19802). Thanks
     18        to Guoxiang Niu (@niugx), from the EaglEye Team for reporting these issues.
     19        * tempo: fix delay_ms methods
     20        * filterbank: fix aubio_filterbank_get_power (thanks to @romanbsd who
     21        also noticed this issue)
     22        * dct: creation fail on negative sizes or invalid accelerate radix,
     23        fix typo in error and warning messages, prevent possible memory leak
     24        * pitch: prevent null pointer dereference in yinfast, comment out unused
     25        functions in mcomb and yin, prevent possible leak in specacf
     26        * mfcc: always use dct module, strengthen input validation, change
     27        get_{scale,power} to return smpl_t
     28        * specdesc: improve error message
     29        * notes: prevent null pointer dereference
     30        * hist: add validation for size argument, prevent possible leak
     31        * awhitening: use shortest length available (closes gh-216)
     32        * io: add macros to display system errors, add helpers to validate input
     33        arguments of source and sink methods, always clean-up after failure
     34        * source: validate input sizes to prevent invalid reads
     35        * apple_audio: use native format conversions in source and sink, prevent
     36        possible apple_audio crash on empty string, get_duration returns 0 on failure
     37        * ffmpeg/avcodec: prevent deprecation warnings, read after close, and skipped
     38        samples warnings, improve warning messages, only show a warning when
     39        swr_convert failed, prevent possible memory leak when closing swr context
     40        * wavwrite: copy to all channels if needed, check fseek and fwrite return
     41        values, call fflush in open to return failure on full disk-system
     42        * source_sndfile: fix reading sizes when resampling, set error message when
     43        reading after close
     44        * aubio_priv.h: include blas first (see gh-225), add STRERROR macros
     45
     46        [ Python ]
     47
     48        * documentation: add pages to manual, add minimal docstrings for fft,
     49        digital_filter, and generated objects, improve specdesc documentation
     50        * filterbank: add get_norm/power documentation
     51        * source: take a copy of the last frame before resizing it, raise an
     52        exception when read failed, fix compilation warning
     53        * fixes: remove unneeded check convert with PyFloat_FromDouble or
     54        PyFloat_FromDouble, check if sink, digital_filter, were created before
     55        deleting
     56
     57        [ Tests ]
     58
     59        * python/tests/: switch to pytest (slightly slower than nose2 but better at
     60        capturing warnings and parametrization), improve coding style and coverage.
     61        Tests should now be run with `pytest`.
     62        * tests/: Each test program in C must now return 0, otherwise the test will
     63        fail. Examples have been modified to run themselves on a test audio file,
     64        but can still be run with arguments. Tests for `source` and `sink` have been
     65        factorised, and some code cleaning. A python script is used to create a
     66        test sound file. Tested on linux, macos, and windows, improvements to
     67        test-mfcc (closes gh-219).
     68
     69        [ Build system ]
     70
     71        * waf: upgrade to 2.0.14, check the return code of each test program,
     72        update rules to build manual and api documentation into build/, check
     73        for errno.h
     74        * osx: use -Os in scripts/build_apple_frameworks
     75        * Makefile: improve coverage reports
     76        * appveyor, travis, circleci: switch to pytest, set one travis config to use
     77        sndfile only
     78        * travis: add py3.6, drop py3.4, use py3.5 to test debug mode
     79        * azure: add basic configuration
     80
    1812018-11-21 Paul Brossier <piem@aubio.org>
    282
  • MANIFEST.in

    r868c6b8 rdfe6ab6  
    77include Makefile wscript */wscript_build
    88include aubio.pc.in
    9 include nose2.cfg
    109include requirements.txt
    1110include src/*.c src/*.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

    r868c6b8 rdfe6ab6  
    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 . \
  • README.md

    r868c6b8 rdfe6ab6  
    44[![Travis build status](https://travis-ci.org/aubio/aubio.svg?branch=master)](https://travis-ci.org/aubio/aubio "Travis build status")
    55[![Appveyor build status](https://img.shields.io/appveyor/ci/piem/aubio/master.svg)](https://ci.appveyor.com/project/piem/aubio "Appveyor build status")
    6 [![Landscape code health](https://landscape.io/github/aubio/aubio/master/landscape.svg?style=flat)](https://landscape.io/github/aubio/aubio/master "Landscape code health")
    76[![Commits since last release](https://img.shields.io/github/commits-since/aubio/aubio/latest.svg)](https://github.com/aubio/aubio "Commits since last release")
    87
  • VERSION

    r868c6b8 rdfe6ab6  
    11AUBIO_MAJOR_VERSION=0
    2 AUBIO_MINOR_VERSION=4
    3 AUBIO_PATCH_VERSION=9
     2AUBIO_MINOR_VERSION=5
     3AUBIO_PATCH_VERSION=0
    44AUBIO_VERSION_STATUS='~alpha'
    55LIBAUBIO_LT_CUR=5
  • azure-pipelines.yml

    r868c6b8 rdfe6ab6  
    44- job: linux
    55  pool:
    6     vmImage: 'Ubuntu 16.04'
     6    vmImage: 'ubuntu-16.04'
    77  steps:
    88  - script: |
     
    1414- job: windows
    1515  pool:
    16     vmIMage: 'VS2017-Win2016'
     16    vmImage: 'vs2017-win2016'
    1717  steps:
    1818  - script: |
     
    2525- job: macos
    2626  pool:
    27     vmIMage: macOS-10.13
     27    vmImage: 'macos-10.13'
    2828  steps:
    2929  - script: |
  • doc/python_module.rst

    r868c6b8 rdfe6ab6  
    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
  • doc/statuslinks.rst

    r868c6b8 rdfe6ab6  
    1010   :alt: Appveyor build status
    1111
    12 .. image:: https://landscape.io/github/aubio/aubio/master/landscape.svg?style=flat
    13    :target: https://landscape.io/github/aubio/aubio/master
    14    :alt: Landscape code health
    15 
    1612.. image:: https://readthedocs.org/projects/aubio/badge/?version=latest
    1713   :target: https://aubio.readthedocs.io/en/latest/?badge=latest
  • examples/utils.c

    r868c6b8 rdfe6ab6  
    185185
    186186    del_aubio_source (this_source);
    187     del_aubio_sink   (this_sink);
     187    if (this_sink)
     188      del_aubio_sink   (this_sink);
    188189
    189190  }
  • python/demos/demo_wav2midi.py

    r868c6b8 rdfe6ab6  
    6464        if new_note[2] > 0:
    6565            track.append(Message('note_off', note=int(new_note[2]),
    66                 velocity=127, time=0)
     66                velocity=127, time=delta)
    6767                )
    6868        track.append(Message('note_on',
  • python/ext/py-filter.c

    r868c6b8 rdfe6ab6  
    110110{
    111111  Py_XDECREF(self->out);
    112   del_aubio_filter (self->o);
     112  if (self->o)
     113    del_aubio_filter (self->o);
    113114  Py_TYPE(self)->tp_free ((PyObject *) self);
    114115}
  • python/ext/py-sink.c

    r868c6b8 rdfe6ab6  
    151151Py_sink_del (Py_sink *self, PyObject *unused)
    152152{
    153   del_aubio_sink(self->o);
    154   free(self->mwrite_data.data);
     153  if (self->o) {
     154    del_aubio_sink(self->o);
     155    free(self->mwrite_data.data);
     156  }
    155157  if (self->uri) {
    156158    free(self->uri);
  • python/ext/py-source.c

    r868c6b8 rdfe6ab6  
    437437  aubio_source_do (self->o, &(self->c_read_to), &read);
    438438
     439  if (PyErr_Occurred() != NULL) {
     440    return NULL;
     441  }
     442
    439443  outputs = PyTuple_New(2);
    440444  PyTuple_SetItem( outputs, 0, self->read_to );
     
    457461  /* compute _do function */
    458462  aubio_source_do_multi (self->o, &(self->c_mread_to), &read);
     463
     464  if (PyErr_Occurred() != NULL) {
     465    return NULL;
     466  }
    459467
    460468  outputs = PyTuple_New(2);
     
    574582    } else if (PyLong_AsLong(size) > 0) {
    575583      // short read, return a shorter array
    576       PyArrayObject *shortread = (PyArrayObject*)PyTuple_GetItem(done, 0);
     584      PyObject *vec = PyTuple_GetItem(done, 0);
     585      // take a copy to prevent resizing internal arrays
     586      PyArrayObject *shortread = (PyArrayObject*)PyArray_FROM_OTF(vec,
     587          NPY_NOTYPE, NPY_ARRAY_ENSURECOPY);
    577588      PyArray_Dims newdims;
    578589      PyObject *reshaped;
     
    587598      reshaped = PyArray_Newshape(shortread, &newdims, NPY_CORDER);
    588599      Py_DECREF(shortread);
     600      Py_DECREF(vec);
    589601      return reshaped;
    590602    } else {
  • python/lib/moresetuptools.py

    r868c6b8 rdfe6ab6  
    6969    for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H',
    7070                         'HAVE_MATH_H', 'HAVE_STRING_H',
    71                          'HAVE_C99_VARARGS_MACROS',
     71                         'HAVE_ERRNO_H', 'HAVE_C99_VARARGS_MACROS',
    7272                         'HAVE_LIMITS_H', 'HAVE_STDARG_H',
    7373                         'HAVE_MEMCPY_HACKS']:
  • python/tests/test_aubio.py

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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 utils import parse_file_samplerate
     7from _tools import parametrize, skipTest, assert_raises, assert_warns
    118
    129list_of_sounds = list_all_sounds('sounds')
     
    2421            all_params.append((hop_size, samplerate, soundfile))
    2522
    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\'')
     23class Test_aubio_sink(object):
    3124
    3225    def test_wrong_filename(self):
    33         with self.assertRaises(RuntimeError):
     26        with assert_raises(RuntimeError):
    3427            sink('')
    3528
    3629    def test_wrong_samplerate(self):
    37         with self.assertRaises(RuntimeError):
     30        with assert_raises(RuntimeError):
    3831            sink(get_tmp_sink_path(), -1)
    3932
    4033    def test_wrong_samplerate_too_large(self):
    41         with self.assertRaises(RuntimeError):
     34        with assert_raises(RuntimeError):
    4235            sink(get_tmp_sink_path(), 1536001, 2)
    4336
    4437    def test_wrong_channels(self):
    45         with self.assertRaises(RuntimeError):
     38        with assert_raises(RuntimeError):
    4639            sink(get_tmp_sink_path(), 44100, -1)
    4740
    4841    def test_wrong_channels_too_large(self):
    49         with self.assertRaises(RuntimeError):
     42        with assert_raises(RuntimeError):
    5043            sink(get_tmp_sink_path(), 44100, 202020)
    5144
     
    6760        shutil.rmtree(tmpdir)
    6861
    69     @params(*all_params)
     62    @parametrize('hop_size, samplerate, path', all_params)
    7063    def test_read_and_write(self, hop_size, samplerate, path):
    71 
     64        orig_samplerate = parse_file_samplerate(soundfile)
    7265        try:
    73             f = source(path, samplerate, hop_size)
     66            if orig_samplerate is not None and orig_samplerate < samplerate:
     67                # upsampling should emit a warning
     68                with assert_warns(UserWarning):
     69                    f = source(soundfile, samplerate, hop_size)
     70            else:
     71                f = source(soundfile, samplerate, hop_size)
    7472        except RuntimeError as e:
    75             self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
     73            err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
     74            skipTest(err_msg.format(str(e), hop_size, samplerate))
    7675        if samplerate == 0: samplerate = f.samplerate
    7776        sink_path = get_tmp_sink_path()
     
    8584        del_tmp_sink_path(sink_path)
    8685
    87     @params(*all_params)
     86    @parametrize('hop_size, samplerate, path', all_params)
    8887    def test_read_and_write_multi(self, hop_size, samplerate, path):
     88        orig_samplerate = parse_file_samplerate(soundfile)
    8989        try:
    90             f = source(path, samplerate, hop_size)
     90            if orig_samplerate is not None and orig_samplerate < samplerate:
     91                # upsampling should emit a warning
     92                with assert_warns(UserWarning):
     93                    f = source(soundfile, samplerate, hop_size)
     94            else:
     95                f = source(soundfile, samplerate, hop_size)
    9196        except RuntimeError as e:
    92             self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
     97            err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
     98            skipTest(err_msg.format(str(e), hop_size, samplerate))
    9399        if samplerate == 0: samplerate = f.samplerate
    94100        sink_path = get_tmp_sink_path()
     
    126132
    127133if __name__ == '__main__':
    128     main()
     134    from _tools import run_module_suite
     135    run_module_suite()
  • python/tests/test_slicing.py

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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, parse_file_samplerate
     7import unittest
     8from _tools import assert_raises, assert_equal, assert_warns
     9from _tools import parametrize, skipTest
    1110
    1211list_of_sounds = list_all_sounds('sounds')
     
    1413hop_sizes = [512, 1024, 64]
    1514
    16 path = None
     15default_test_sound = len(list_of_sounds) and list_of_sounds[0] or None
    1716
    1817all_params = []
     
    2221            all_params.append((hop_size, samplerate, soundfile))
    2322
    24 
    25 class aubio_source_test_case_base(TestCase):
     23no_sounds_msg = "no test sounds, add some in 'python/tests/sounds/'!"
     24
     25_debug = False
     26
     27
     28class Test_aubio_source_test_case(TestCase):
    2629
    2730    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]
    31 
    32 class aubio_source_test_case(aubio_source_test_case_base):
    33 
    34     @params(*list_of_sounds)
    35     def test_close_file(self, filename):
     31        if not default_test_sound:
     32            skipTest(no_sounds_msg)
     33
     34    def test_close_file(self):
    3635        samplerate = 0 # use native samplerate
    3736        hop_size = 256
    38         f = source(filename, samplerate, hop_size)
    39         f.close()
    40 
    41     @params(*list_of_sounds)
    42     def test_close_file_twice(self, filename):
     37        f = source(default_test_sound, samplerate, hop_size)
     38        f.close()
     39
     40    def test_close_file_twice(self):
    4341        samplerate = 0 # use native samplerate
    4442        hop_size = 256
    45         f = source(filename, samplerate, hop_size)
    46         f.close()
    47         f.close()
    48 
    49 class aubio_source_read_test_case(aubio_source_test_case_base):
     43        f = source(default_test_sound, samplerate, hop_size)
     44        f.close()
     45        f.close()
     46
     47    def test_read_after_close(self):
     48        samplerate = 0 # use native samplerate
     49        hop_size = 256
     50        f = source(default_test_sound, samplerate, hop_size)
     51        read, frames = f()
     52        f.close()
     53        with assert_raises(RuntimeError):
     54            read, frames = f()
     55        with assert_raises(RuntimeError):
     56            read, frames = f.do_multi()
     57
     58
     59class Test_aubio_source_read(object):
    5060
    5161    def read_from_source(self, f):
     
    5767                assert_equal(samples[read:], 0)
    5868                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))
     69        if _debug:
     70            result_str = "read {:.2f}s ({:d} frames"
     71            result_str += " in {:d} blocks at {:d}Hz) from {:s}"
     72            result_params = total_frames / float(f.samplerate), total_frames, \
     73                    total_frames//f.hop_size, f.samplerate, f.uri
     74            print (result_str.format(*result_params))
    6275        return total_frames
    6376
    64     @params(*all_params)
     77    @parametrize('hop_size, samplerate, soundfile', all_params)
    6578    def test_samplerate_hopsize(self, hop_size, samplerate, soundfile):
     79        orig_samplerate = parse_file_samplerate(soundfile)
    6680        try:
    67             f = source(soundfile, samplerate, hop_size)
     81            if orig_samplerate is not None and orig_samplerate < samplerate:
     82                # upsampling should emit a warning
     83                with assert_warns(UserWarning):
     84                    f = source(soundfile, samplerate, hop_size)
     85            else:
     86                f = source(soundfile, samplerate, hop_size)
    6887        except RuntimeError as e:
    69             self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
     88            err_msg = 'failed opening with hop_s={:d}, samplerate={:d} ({:s})'
     89            skipTest(err_msg.format(hop_size, samplerate, str(e)))
    7090        assert f.samplerate != 0
    7191        read_frames = self.read_from_source(f)
    7292        if 'f_' in soundfile and samplerate == 0:
    7393            import re
    74             f = re.compile('.*_\([0:9]*f\)_.*')
     94            f = re.compile(r'.*_\([0:9]*f\)_.*')
    7595            match_f = re.findall('([0-9]*)f_', soundfile)
    7696            if len(match_f) == 1:
    7797                expected_frames = int(match_f[0])
    78                 self.assertEqual(expected_frames, read_frames)
    79 
    80     @params(*list_of_sounds)
     98                assert_equal(expected_frames, read_frames)
     99
     100    @parametrize('p', list_of_sounds)
    81101    def test_samplerate_none(self, p):
    82102        f = source(p)
     
    84104        self.read_from_source(f)
    85105
    86     @params(*list_of_sounds)
     106    @parametrize('p', list_of_sounds)
    87107    def test_samplerate_0(self, p):
    88108        f = source(p, 0)
     
    90110        self.read_from_source(f)
    91111
    92     @params(*list_of_sounds)
     112    @parametrize('p', list_of_sounds)
    93113    def test_zero_hop_size(self, p):
    94114        f = source(p, 0, 0)
     
    97117        self.read_from_source(f)
    98118
    99     @params(*list_of_sounds)
     119    @parametrize('p', list_of_sounds)
    100120    def test_seek_to_half(self, p):
    101121        from random import randint
     
    109129        assert a == b + c
    110130
    111     @params(*list_of_sounds)
     131    @parametrize('p', list_of_sounds)
    112132    def test_duration(self, p):
    113133        total_frames = 0
     
    118138            total_frames += read
    119139            if read < f.hop_size: break
    120         self.assertEqual(duration, total_frames)
    121 
    122 
    123 class aubio_source_test_wrong_params(TestCase):
     140        assert_equal (duration, total_frames)
     141
     142
     143class Test_aubio_source_wrong_params(object):
    124144
    125145    def test_wrong_file(self):
    126         with self.assertRaises(RuntimeError):
     146        with assert_raises(RuntimeError):
    127147            source('path_to/unexisting file.mp3')
    128148
    129 class aubio_source_test_wrong_params_with_file(aubio_source_test_case_base):
     149@unittest.skipIf(default_test_sound is None, no_sounds_msg)
     150class Test_aubio_source_wrong_params_with_file(TestCase):
    130151
    131152    def test_wrong_samplerate(self):
    132         with self.assertRaises(ValueError):
    133             source(self.default_test_sound, -1)
     153        with assert_raises(ValueError):
     154            source(default_test_sound, -1)
    134155
    135156    def test_wrong_hop_size(self):
    136         with self.assertRaises(ValueError):
    137             source(self.default_test_sound, 0, -1)
     157        with assert_raises(ValueError):
     158            source(default_test_sound, 0, -1)
    138159
    139160    def test_wrong_channels(self):
    140         with self.assertRaises(ValueError):
    141             source(self.default_test_sound, 0, 0, -1)
     161        with assert_raises(ValueError):
     162            source(default_test_sound, 0, 0, -1)
    142163
    143164    def test_wrong_seek(self):
    144         f = source(self.default_test_sound)
    145         with self.assertRaises(ValueError):
     165        f = source(default_test_sound)
     166        with assert_raises(ValueError):
    146167            f.seek(-1)
    147168
    148169    def test_wrong_seek_too_large(self):
    149         f = source(self.default_test_sound)
     170        f = source(default_test_sound)
    150171        try:
    151             with self.assertRaises(ValueError):
     172            with assert_raises(ValueError):
    152173                f.seek(f.duration + f.samplerate * 10)
    153         except AssertionError:
    154             self.skipTest('seeking after end of stream failed raising ValueError')
    155 
    156 class aubio_source_readmulti_test_case(aubio_source_read_test_case):
     174        except:
     175            skipTest('seeking after end of stream failed raising ValueError')
     176
     177class Test_aubio_source_readmulti(Test_aubio_source_read):
    157178
    158179    def read_from_source(self, f):
     
    164185                assert_equal(samples[:,read:], 0)
    165186                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))
     187        if _debug:
     188            result_str = "read {:.2f}s ({:d} frames in {:d} channels"
     189            result_str += " and {:d} blocks at {:d}Hz) from {:s}"
     190            result_params = total_frames / float(f.samplerate), total_frames, \
     191                    f.channels, int(total_frames/f.hop_size), \
     192                    f.samplerate, f.uri
     193            print (result_str.format(*result_params))
    169194        return total_frames
    170195
    171 class aubio_source_with(aubio_source_test_case_base):
    172 
    173     #@params(*list_of_sounds)
    174     @params(*list_of_sounds)
     196class Test_aubio_source_with(object):
     197
     198    @parametrize('filename', list_of_sounds)
    175199    def test_read_from_mono(self, filename):
    176200        total_frames = 0
     
    186210
    187211if __name__ == '__main__':
    188     main()
     212    from _tools import run_module_suite
     213    run_module_suite()
  • python/tests/test_source_channels.py

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    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

    r868c6b8 rdfe6ab6  
    22
    33import os
     4import re
    45import glob
    56import numpy as np
     
    910
    1011def 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)
     12    realpathname = os.path.join(os.path.dirname(__file__), filename)
     13    return np.loadtxt(realpathname, dtype = dtype)
    1614
    1715def list_all_sounds(rel_dir):
     
    3937        os.unlink(path)
    4038    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)))
     39        # removing the temporary directory sometimes fails on windows
     40        import warnings
     41        errmsg = "failed deleting temporary file {:s} ({:s})"
     42        warnings.warn(UserWarning(errmsg.format(path, repr(e))))
    4843
    4944def array_from_yaml_file(filename):
     
    8479                    total_files += 1
    8580    return total_files
     81
     82def parse_file_samplerate(soundfile):
     83    samplerate = None
     84    # parse samplerate
     85    re_sr = re.compile(r'/([0-9]{4,})Hz_.*')
     86    match_samplerate = re_sr.findall(soundfile)
     87    if match_samplerate:
     88        samplerate = int(match_samplerate[0])
     89    else:
     90        import warnings
     91        warnings.warn(UserWarning("could not parse samplerate for {:s}"
     92            .format(soundfile)))
     93    return samplerate
  • requirements.txt

    r868c6b8 rdfe6ab6  
    11numpy
    2 nose2
     2pytest
  • scripts/build_apple_frameworks

    r868c6b8 rdfe6ab6  
    1414#VERSION+=+$(git log --pretty=format:"%h" -1)
    1515
    16 CFLAGS="-Werror -Ofast"
     16CFLAGS="-Werror -Os"
    1717WAFCONF="--disable-sndfile --disable-avcodec --disable-samplerate --enable-fat" # --disable-memcpy --disable-accelerate"
    1818
  • scripts/get_waf.sh

    r868c6b8 rdfe6ab6  
    44#set -x
    55
    6 WAFVERSION=2.0.13
     6WAFVERSION=2.0.14
    77WAFTARBALL=waf-$WAFVERSION.tar.bz2
    88WAFURL=https://waf.io/$WAFTARBALL
  • setup.py

    r868c6b8 rdfe6ab6  
    9696        ],
    9797    },
    98     test_suite = 'nose2.collector.collector',
    99     extras_require = {
    100         'tests': ['numpy'],
    101         },
    10298    )
  • src/aubio_priv.h

    r868c6b8 rdfe6ab6  
    6363#endif
    6464
     65#ifdef HAVE_ERRNO_H
     66#include <errno.h>
     67#endif
     68
    6569#ifdef HAVE_LIMITS_H
    6670#include <limits.h> // for CHAR_BIT, in C99 standard
     
    7175#endif
    7276
    73 #if defined(HAVE_ACCELERATE)
    74 #define HAVE_ATLAS 1
    75 #define HAVE_BLAS 1
    76 #include <Accelerate/Accelerate.h>
    77 #elif defined(HAVE_ATLAS_CBLAS_H)
    78 #elif defined(HAVE_BLAS)
     77#if defined(HAVE_BLAS) // --enable-blas=true
     78// check which cblas header we found
    7979#if defined(HAVE_ATLAS_CBLAS_H)
    8080#define HAVE_ATLAS 1
     
    8484#elif defined(HAVE_CBLAS_H)
    8585#include <cblas.h>
    86 #endif
    87 #endif
    88 
    89 #ifdef HAVE_ACCELERATE
     86#elif !defined(HAVE_ACCELERATE)
     87#error "HAVE_BLAS was defined, but no blas header was found"
     88#endif /* end of cblas includes */
     89#endif
     90
     91#if defined(HAVE_ACCELERATE)
     92// include accelerate framework after blas
     93#define HAVE_ATLAS 1
     94#define HAVE_BLAS 1
    9095#include <Accelerate/Accelerate.h>
     96
    9197#ifndef HAVE_AUBIO_DOUBLE
    9298#define aubio_vDSP_mmov       vDSP_mmov
     
    325331#endif
    326332
     333#if !defined(_MSC_VER)
     334#define AUBIO_STRERROR(errno,buf,len) strerror_r(errno, buf, len)
     335#else
     336#define AUBIO_STRERROR(errno,buf,len) strerror_s(buf, len, errno)
     337#endif
     338
     339#ifdef HAVE_C99_VARARGS_MACROS
     340#define AUBIO_STRERR(...)            \
     341    char errorstr[256]; \
     342    AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); \
     343    AUBIO_ERR(__VA_ARGS__)
     344#else
     345#define AUBIO_STRERR(format, args...)   \
     346    char errorstr[256]; \
     347    AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); \
     348    AUBIO_ERR(format, ##args)
     349#endif
     350
    327351/* handy shortcuts */
    328352#define DB2LIN(g) (POW(10.0,(g)*0.05f))
  • src/io/ioutils.c

    r868c6b8 rdfe6ab6  
    2020
    2121#include "aubio_priv.h"
     22#include "fmat.h"
    2223
    2324uint_t
     
    5152  }
    5253  return AUBIO_OK;
     54}
     55
     56uint_t
     57aubio_source_validate_input_length(const char_t *kind, const char_t *path,
     58    uint_t hop_size, uint_t read_data_length)
     59{
     60  uint_t length = hop_size;
     61  if (hop_size < read_data_length) {
     62    AUBIO_WRN("%s: partial read from %s, trying to read %d frames, but"
     63        " hop_size is %d\n", kind, path, read_data_length, hop_size);
     64  } else if (hop_size > read_data_length) {
     65    AUBIO_WRN("%s: partial read from %s, trying to read %d frames into"
     66        " a buffer of length %d\n", kind, path, hop_size, read_data_length);
     67    length = read_data_length;
     68  }
     69  return length;
     70}
     71
     72uint_t
     73aubio_source_validate_input_channels(const char_t *kind, const char_t *path,
     74    uint_t source_channels, uint_t read_data_height)
     75{
     76  uint_t channels = source_channels;
     77  if (read_data_height < source_channels) {
     78    AUBIO_WRN("%s: partial read from %s, trying to read %d channels,"
     79        " but found output of height %d\n", kind, path, source_channels,
     80        read_data_height);
     81    channels = read_data_height;
     82  } else if (read_data_height > source_channels) {
     83    // do not show a warning when trying to read into more channels than
     84    // the input source.
     85#if 0
     86    AUBIO_WRN("%s: partial read from %s, trying to read %d channels,"
     87        " but found output of height %d\n", kind, path, source_channels,
     88        read_data_height);
     89#endif
     90    channels = source_channels;
     91  }
     92  return channels;
     93}
     94
     95void
     96aubio_source_pad_output (fvec_t *read_data, uint_t source_read)
     97{
     98  if (source_read < read_data->length) {
     99    AUBIO_MEMSET(read_data->data + source_read, 0,
     100        (read_data->length - source_read) * sizeof(smpl_t));
     101  }
     102}
     103
     104void
     105aubio_source_pad_multi_output (fmat_t *read_data,
     106    uint_t source_channels, uint_t source_read) {
     107  uint_t i;
     108  if (source_read < read_data->length) {
     109    for (i = 0; i < read_data->height; i++) {
     110      AUBIO_MEMSET(read_data->data[i] + source_read, 0,
     111          (read_data->length - source_read) * sizeof(smpl_t));
     112    }
     113  }
     114
     115  // destination matrix has more channels than the file
     116  // copy channels from the source to extra output channels
     117  if (read_data->height > source_channels) {
     118    for (i = source_channels; i < read_data->height; i++) {
     119      AUBIO_MEMCPY(read_data->data[i], read_data->data[i % source_channels],
     120          sizeof(smpl_t) * read_data->length);
     121    }
     122  }
    53123}
    54124
  • src/io/ioutils.h

    r868c6b8 rdfe6ab6  
    5454    uint_t channels);
    5555
    56 /** validate length of input
     56/** validate length of source output
     57
     58  \param kind       the object kind to report on
     59  \param path       the path to report on
     60  \param hop_size   number of frames to be read
     61  \param read_data_length actual length of input
     62
     63  \return hop_size or the maximum number of frames that can be written
     64*/
     65uint_t
     66aubio_source_validate_input_length(const char_t *kind, const char_t *path,
     67    uint_t hop_size, uint_t read_data_length);
     68
     69/** validate height of source output
     70
     71  \param kind       the object kind to report on
     72  \param path       the path to report on
     73  \param source_channels maximum number of channels that can be written
     74  \param read_data_height actual height of input
     75
     76  \return write_data_height or the maximum number of channels
     77*/
     78uint_t
     79aubio_source_validate_input_channels(const char_t *kind, const char_t *path,
     80    uint_t source_channels, uint_t read_data_height);
     81
     82/** pad end of source output vector with zeroes
     83
     84  \param read_data   output vector to pad
     85  \param source_read number of frames read
     86
     87*/
     88void
     89aubio_source_pad_output (fvec_t *read_data, uint_t source_read);
     90
     91/** pad end of source output matrix with zeroes
     92
     93  \param read_data   output matrix to pad
     94  \param source_channels number of channels in the source
     95  \param source_read number of frames read
     96
     97*/
     98void
     99aubio_source_pad_multi_output (fmat_t *read_data, uint_t source_channels,
     100        uint_t source_read);
     101
     102/** validate length of sink input
    57103
    58104  \param kind       the object kind to report on
    59105  \param path       the path to report on
    60106  \param max_size   maximum number of frames that can be written
    61   \param write_data_length actual length of input vector/matrix
     107  \param write_data_length actual length of input
    62108  \param write number of samples asked
    63109
     
    68114    uint_t max_size, uint_t write_data_length, uint_t write);
    69115
    70 /** validate height of input
     116/** validate height of sink input
    71117
    72118  \param kind       the object kind to report on
    73119  \param path       the path to report on
    74   \param max_size  maximum number of channels that can be written
     120  \param sink_channels maximum number of channels that can be written
    75121  \param write_data_height actual height of input matrix
    76122
  • src/io/sink.c

    r868c6b8 rdfe6ab6  
    136136
    137137void del_aubio_sink(aubio_sink_t * s) {
    138   AUBIO_ASSERT(s);
    139   if (s->s_del && s->sink)
     138  //AUBIO_ASSERT(s);
     139  if (s && s->s_del && s->sink)
    140140    s->s_del((void *)s->sink);
    141141  AUBIO_FREE(s);
  • src/io/sink_wavwrite.c

    r868c6b8 rdfe6ab6  
    2828#include "io/sink_wavwrite.h"
    2929#include "io/ioutils.h"
    30 
    31 #include <errno.h>
    3230
    3331#define MAX_SIZE 4096
     
    163161  unsigned char buf[5];
    164162  uint_t byterate, blockalign;
     163  size_t written = 0;
    165164
    166165  /* open output file */
    167166  s->fid = fopen((const char *)s->path, "wb");
    168167  if (!s->fid) {
    169     AUBIO_ERR("sink_wavwrite: could not open %s (%s)\n", s->path, strerror(errno));
     168    AUBIO_STRERR("sink_wavwrite: could not open %s (%s)\n", s->path, errorstr);
    170169    goto beach;
    171170  }
    172171
    173172  // ChunkID
    174   fwrite("RIFF", 4, 1, s->fid);
     173  written += fwrite("RIFF", 4, 1, s->fid);
    175174
    176175  // ChunkSize (0 for now, actual size will be written in _close)
    177   fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);
     176  written += fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);
    178177
    179178  // Format
    180   fwrite("WAVE", 4, 1, s->fid);
     179  written += fwrite("WAVE", 4, 1, s->fid);
    181180
    182181  // Subchunk1ID
    183   fwrite("fmt ", 4, 1, s->fid);
     182  written += fwrite("fmt ", 4, 1, s->fid);
    184183
    185184  // Subchunk1Size
    186   fwrite(write_little_endian(16, buf, 4), 4, 1, s->fid);
     185  written += fwrite(write_little_endian(16, buf, 4), 4, 1, s->fid);
    187186
    188187  // AudioFormat
    189   fwrite(write_little_endian(1, buf, 2), 2, 1, s->fid);
     188  written += fwrite(write_little_endian(1, buf, 2), 2, 1, s->fid);
    190189
    191190  // NumChannels
    192   fwrite(write_little_endian(s->channels, buf, 2), 2, 1, s->fid);
     191  written += fwrite(write_little_endian(s->channels, buf, 2), 2, 1, s->fid);
    193192
    194193  // SampleRate
    195   fwrite(write_little_endian(s->samplerate, buf, 4), 4, 1, s->fid);
     194  written += fwrite(write_little_endian(s->samplerate, buf, 4), 4, 1, s->fid);
    196195
    197196  // ByteRate
    198197  byterate = s->samplerate * s->channels * s->bitspersample / 8;
    199   fwrite(write_little_endian(byterate, buf, 4), 4, 1, s->fid);
     198  written += fwrite(write_little_endian(byterate, buf, 4), 4, 1, s->fid);
    200199
    201200  // BlockAlign
    202201  blockalign = s->channels * s->bitspersample / 8;
    203   fwrite(write_little_endian(blockalign, buf, 2), 2, 1, s->fid);
     202  written += fwrite(write_little_endian(blockalign, buf, 2), 2, 1, s->fid);
    204203
    205204  // BitsPerSample
    206   fwrite(write_little_endian(s->bitspersample, buf, 2), 2, 1, s->fid);
     205  written += fwrite(write_little_endian(s->bitspersample, buf, 2), 2, 1, s->fid);
    207206
    208207  // Subchunk2ID
    209   fwrite("data", 4, 1, s->fid);
     208  written += fwrite("data", 4, 1, s->fid);
    210209
    211210  // Subchunk1Size (0 for now, actual size will be written in _close)
    212   fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);
     211  written += fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);
     212
     213  // fwrite(*, *, 1, s->fid) was called 13 times, check success
     214  if (written != 13 || fflush(s->fid)) {
     215    AUBIO_STRERR("sink_wavwrite: writing header to %s failed"
     216        " (wrote %d/%d, %s)\n", s->path, written, 13, errorstr);
     217    fclose(s->fid);
     218    s->fid = NULL;
     219    return AUBIO_FAIL;
     220  }
    213221
    214222  s->scratch_size = s->max_size * s->channels;
     
    227235}
    228236
     237static
     238void aubio_sink_wavwrite_write_frames(aubio_sink_wavwrite_t *s, uint_t write)
     239{
     240  uint_t written_frames = 0;
     241
     242  written_frames = fwrite(s->scratch_data, 2 * s->channels, write, s->fid);
     243
     244  if (written_frames != write) {
     245    AUBIO_STRERR("sink_wavwrite: trying to write %d frames to %s, but only %d"
     246        " could be written (%s)\n", write, s->path, written_frames, errorstr);
     247  }
     248  s->total_frames_written += written_frames;
     249}
    229250
    230251void aubio_sink_wavwrite_do(aubio_sink_wavwrite_t *s, fvec_t * write_data, uint_t write){
    231   uint_t c = 0, i = 0, written_frames = 0;
     252  uint_t c = 0, i = 0;
    232253  uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path,
    233254      s->max_size, write_data->length, write);
     
    238259    }
    239260  }
    240   written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
    241 
    242   if (written_frames != write) {
    243     AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
    244         "but only %d could be written\n", write, s->path, written_frames);
    245   }
    246   s->total_frames_written += written_frames;
    247   return;
     261
     262  aubio_sink_wavwrite_write_frames(s, length);
    248263}
    249264
    250265void aubio_sink_wavwrite_do_multi(aubio_sink_wavwrite_t *s, fmat_t * write_data, uint_t write){
    251   uint_t c = 0, i = 0, written_frames = 0;
     266  uint_t c = 0, i = 0;
    252267
    253268  uint_t channels = aubio_sink_validate_input_channels("sink_wavwrite", s->path,
     
    261276    }
    262277  }
    263   written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
    264 
    265   if (written_frames != write * s->channels) {
    266     AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
    267         "but only %d could be written\n", write, s->path, written_frames / s->channels);
    268   }
    269   s->total_frames_written += written_frames;
    270   return;
     278
     279  aubio_sink_wavwrite_write_frames(s, length);
    271280}
    272281
     
    274283  uint_t data_size = s->total_frames_written * s->bitspersample * s->channels / 8;
    275284  unsigned char buf[5];
     285  size_t written = 0, err = 0;
    276286  if (!s->fid) return AUBIO_FAIL;
    277287  // ChunkSize
    278   fseek(s->fid, 4, SEEK_SET);
    279   fwrite(write_little_endian(data_size + 36, buf, 4), 4, 1, s->fid);
     288  err += fseek(s->fid, 4, SEEK_SET);
     289  written += fwrite(write_little_endian(data_size + 36, buf, 4), 4, 1, s->fid);
    280290  // Subchunk2Size
    281   fseek(s->fid, 40, SEEK_SET);
    282   fwrite(write_little_endian(data_size, buf, 4), 4, 1, s->fid);
     291  err += fseek(s->fid, 40, SEEK_SET);
     292  written += fwrite(write_little_endian(data_size, buf, 4), 4, 1, s->fid);
     293  if (written != 2 || err != 0) {
     294    AUBIO_STRERR("sink_wavwrite: updating header of %s failed, expected %d"
     295        " write but got only %d (%s)\n", s->path, 2, written, errorstr);
     296  }
    283297  // close file
    284298  if (fclose(s->fid)) {
    285     AUBIO_ERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, strerror(errno));
     299    AUBIO_STRERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, errorstr);
    286300  }
    287301  s->fid = NULL;
  • src/io/source.c

    r868c6b8 rdfe6ab6  
    139139
    140140void del_aubio_source(aubio_source_t * s) {
    141   AUBIO_ASSERT(s);
    142   if (s->s_del && s->source)
     141  //AUBIO_ASSERT(s);
     142  if (s && s->s_del && s->source)
    143143    s->s_del((void *)s->source);
    144144  AUBIO_FREE(s);
  • src/io/source_apple_audio.c

    r868c6b8 rdfe6ab6  
    2525#include "fvec.h"
    2626#include "fmat.h"
     27#include "ioutils.h"
    2728#include "io/source_apple_audio.h"
    2829
     
    210211  uint_t c, v;
    211212  UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
     213  uint_t length = aubio_source_validate_input_length("source_apple_audio",
     214      s->path, s->block_size, read_to->length);
    212215  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    213216
    214   for (v = 0; v < loadedPackets; v++) {
     217  length = MIN(loadedPackets, length);
     218
     219  for (v = 0; v < length; v++) {
    215220    read_to->data[v] = 0.;
    216221    for (c = 0; c < s->channels; c++) {
     
    220225  }
    221226  // short read, fill with zeros
    222   if (loadedPackets < s->block_size) {
    223     for (v = loadedPackets; v < s->block_size; v++) {
    224       read_to->data[v] = 0.;
    225     }
    226   }
    227 
    228   *read = (uint_t)loadedPackets;
    229   return;
     227  aubio_source_pad_output(read_to, length);
     228
     229  *read = (uint_t)length;
    230230}
    231231
    232232void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) {
    233233  uint_t c, v;
     234  uint_t length = aubio_source_validate_input_length("source_apple_audio",
     235      s->path, s->block_size, read_to->length);
     236  uint_t channels = aubio_source_validate_input_channels("source_apple_audio",
     237      s->path, s->channels, read_to->height);
    234238  UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
    235239  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    236240
    237   for (v = 0; v < loadedPackets; v++) {
    238     for (c = 0; c < read_to->height; c++) {
     241  length = MIN(loadedPackets, length);
     242
     243  for (v = 0; v < length; v++) {
     244    for (c = 0; c < channels; c++) {
    239245      read_to->data[c][v] = data[ v * s->channels + c];
    240246    }
    241247  }
    242   // if read_data has more channels than the file
    243   if (read_to->height > s->channels) {
    244     // copy last channel to all additional channels
    245     for (v = 0; v < loadedPackets; v++) {
    246       for (c = s->channels; c < read_to->height; c++) {
    247         read_to->data[c][v] = data[ v * s->channels + (s->channels - 1)];
    248       }
    249     }
    250   }
    251   // short read, fill with zeros
    252   if (loadedPackets < s->block_size) {
    253     for (v = loadedPackets; v < s->block_size; v++) {
    254       for (c = 0; c < read_to->height; c++) {
    255         read_to->data[c][v] = 0.;
    256       }
    257     }
    258   }
    259 
    260   *read = (uint_t)loadedPackets;
    261   return;
     248
     249  aubio_source_pad_multi_output(read_to, s->channels, (uint_t)length);
     250
     251  *read = (uint_t)length;
    262252}
    263253
     
    355345        "error in ExtAudioFileGetProperty (%s)\n", s->path,
    356346        getPrintableOSStatusError(errorstr, err));
    357     return err;
     347    return 0;
    358348  }
    359349  return (uint_t)fileLengthFrames;
  • src/io/source_avcodec.c

    r868c6b8 rdfe6ab6  
    3131#endif
    3232#include <libavutil/opt.h>
    33 #include <stdlib.h>
    3433
    3534// determine whether we use libavformat from ffmpeg or from libav
     
    6160#include "fvec.h"
    6261#include "fmat.h"
     62#include "ioutils.h"
    6363#include "source_avcodec.h"
    6464
     
    120120    uint_t samplerate, uint_t hop_size) {
    121121  aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t);
    122   AVFormatContext *avFormatCtx = s->avFormatCtx;
    123   AVCodecContext *avCodecCtx = s->avCodecCtx;
    124   AVFrame *avFrame = s->avFrame;
     122  AVFormatContext *avFormatCtx = NULL;
     123  AVCodecContext *avCodecCtx = NULL;
     124  AVFrame *avFrame = NULL;
    125125  sint_t selected_stream = -1;
    126126#if FF_API_LAVF_AVCTX
     
    464464      (const uint8_t **)avFrame->data, in_samples);
    465465#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    466   if (out_samples <= 0) {
    467     AUBIO_WRN("source_avcodec: no sample found while converting frame (%s)\n",
    468         s->path);
     466  if (out_samples < 0) {
     467    AUBIO_WRN("source_avcodec: error while resampling %s (%d)\n",
     468        s->path, out_samples);
    469469    goto beach;
    470470  }
     
    473473
    474474beach:
    475   s->avFormatCtx = avFormatCtx;
    476   s->avCodecCtx = avCodecCtx;
    477   s->avFrame = avFrame;
    478 #if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
    479   s->avr = avr;
    480 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    481   s->output = output;
    482 
    483475  av_packet_unref(&avPacket);
    484476}
     
    489481  uint_t end = 0;
    490482  uint_t total_wrote = 0;
    491   while (total_wrote < s->hop_size) {
    492     end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     483  uint_t length = aubio_source_validate_input_length("source_avcodec", s->path,
     484      s->hop_size, read_data->length);
     485  if (!s->avr || !s->avFormatCtx || !s->avCodecCtx) {
     486    AUBIO_ERR("source_avcodec: could not read from %s (file was closed)\n",
     487        s->path);
     488    *read= 0;
     489    return;
     490  }
     491  while (total_wrote < length) {
     492    end = MIN(s->read_samples - s->read_index, length - total_wrote);
    493493    for (i = 0; i < end; i++) {
    494494      read_data->data[i + total_wrote] = 0.;
     
    500500    }
    501501    total_wrote += end;
    502     if (total_wrote < s->hop_size) {
     502    if (total_wrote < length) {
    503503      uint_t avcodec_read = 0;
    504504      aubio_source_avcodec_readframe(s, &avcodec_read);
     
    512512    }
    513513  }
    514   if (total_wrote < s->hop_size) {
    515     for (i = total_wrote; i < s->hop_size; i++) {
    516       read_data->data[i] = 0.;
    517     }
    518   }
     514
     515  aubio_source_pad_output(read_data, total_wrote);
     516
    519517  *read = total_wrote;
    520518}
     
    525523  uint_t end = 0;
    526524  uint_t total_wrote = 0;
    527   while (total_wrote < s->hop_size) {
    528     end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
    529     for (j = 0; j < read_data->height; j++) {
     525  uint_t length = aubio_source_validate_input_length("source_avcodec", s->path,
     526      s->hop_size, read_data->length);
     527  uint_t channels = aubio_source_validate_input_channels("source_avcodec",
     528      s->path, s->input_channels, read_data->height);
     529  if (!s->avr || !s->avFormatCtx || !s->avCodecCtx) {
     530    AUBIO_ERR("source_avcodec: could not read from %s (file was closed)\n",
     531        s->path);
     532    *read= 0;
     533    return;
     534  }
     535  while (total_wrote < length) {
     536    end = MIN(s->read_samples - s->read_index, length - total_wrote);
     537    for (j = 0; j < channels; j++) {
    530538      for (i = 0; i < end; i++) {
    531539        read_data->data[j][i + total_wrote] =
     
    534542    }
    535543    total_wrote += end;
    536     if (total_wrote < s->hop_size) {
     544    if (total_wrote < length) {
    537545      uint_t avcodec_read = 0;
    538546      aubio_source_avcodec_readframe(s, &avcodec_read);
     
    546554    }
    547555  }
    548   if (total_wrote < s->hop_size) {
    549     for (j = 0; j < read_data->height; j++) {
    550       for (i = total_wrote; i < s->hop_size; i++) {
    551         read_data->data[j][i] = 0.;
    552       }
    553     }
    554   }
     556
     557  aubio_source_pad_multi_output(read_data, s->input_channels, total_wrote);
     558
    555559  *read = total_wrote;
    556560}
     
    616620#ifdef HAVE_AVRESAMPLE
    617621    avresample_close( s->avr );
     622    av_free ( s->avr );
    618623#elif defined(HAVE_SWRESAMPLE)
    619624    swr_close ( s->avr );
    620 #endif
    621     av_free ( s->avr );
     625    swr_free ( &s->avr );
     626#endif
    622627  }
    623628  s->avr = NULL;
  • src/io/source_sndfile.c

    r868c6b8 rdfe6ab6  
    2727#include "fvec.h"
    2828#include "fmat.h"
     29#include "ioutils.h"
    2930#include "source_sndfile.h"
    3031
     
    170171  uint_t i,j, input_channels = s->input_channels;
    171172  /* read from file into scratch_data */
    172   sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
     173  uint_t length = aubio_source_validate_input_length("source_sndfile", s->path,
     174      s->hop_size, read_data->length);
     175  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data,
     176      s->scratch_size);
     177  uint_t read_length = read_samples / s->input_channels;
    173178
    174179  /* where to store de-interleaved data */
    175180  smpl_t *ptr_data;
     181
     182  if (!s->handle) {
     183    AUBIO_ERR("source_sndfile: could not read from %s (file was closed)\n",
     184        s->path);
     185    *read = 0;
     186    return;
     187  }
     188
    176189#ifdef HAVE_SAMPLERATE
    177190  if (s->ratio != 1) {
     
    180193#endif /* HAVE_SAMPLERATE */
    181194  {
     195    read_length = MIN(length, read_length);
    182196    ptr_data = read_data->data;
    183197  }
    184198
    185199  /* de-interleaving and down-mixing data  */
    186   for (j = 0; j < read_samples / input_channels; j++) {
     200  for (j = 0; j < read_length; j++) {
    187201    ptr_data[j] = 0;
    188202    for (i = 0; i < input_channels; i++) {
     
    198212#endif /* HAVE_SAMPLERATE */
    199213
    200   *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5);
    201 
    202   if (*read < s->hop_size) {
    203     for (j = *read; j < s->hop_size; j++) {
    204       read_data->data[j] = 0;
    205     }
    206   }
     214  *read = MIN(length, (uint_t)FLOOR(s->ratio * read_length + .5));
     215
     216  aubio_source_pad_output (read_data, *read);
    207217
    208218}
     
    211221  uint_t i,j, input_channels = s->input_channels;
    212222  /* do actual reading */
    213   sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
     223  uint_t length = aubio_source_validate_input_length("source_sndfile", s->path,
     224      s->hop_size, read_data->length);
     225  uint_t channels = aubio_source_validate_input_channels("source_sndfile",
     226      s->path, s->input_channels, read_data->height);
     227  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data,
     228      s->scratch_size);
     229  uint_t read_length = read_samples / s->input_channels;
    214230
    215231  /* where to store de-interleaved data */
    216232  smpl_t **ptr_data;
     233
     234  if (!s->handle) {
     235    AUBIO_ERR("source_sndfile: could not read from %s (file was closed)\n",
     236        s->path);
     237    *read = 0;
     238    return;
     239  }
     240
    217241#ifdef HAVE_SAMPLERATE
    218242  if (s->ratio != 1) {
     
    221245#endif /* HAVE_SAMPLERATE */
    222246  {
     247    read_length = MIN(read_length, length);
    223248    ptr_data = read_data->data;
    224249  }
    225250
    226   if (read_data->height < input_channels) {
    227     // destination matrix has less channels than the file; copy only first
    228     // channels of the file, de-interleaving data
    229     for (j = 0; j < read_samples / input_channels; j++) {
    230       for (i = 0; i < read_data->height; i++) {
    231         ptr_data[i][j] = s->scratch_data[j * input_channels + i];
    232       }
    233     }
    234   } else {
    235     // destination matrix has as many or more channels than the file; copy each
    236     // channel from the file to the destination matrix, de-interleaving data
    237     for (j = 0; j < read_samples / input_channels; j++) {
    238       for (i = 0; i < input_channels; i++) {
    239         ptr_data[i][j] = s->scratch_data[j * input_channels + i];
    240       }
    241     }
    242   }
    243 
    244   if (read_data->height > input_channels) {
    245     // destination matrix has more channels than the file; copy last channel
    246     // of the file to each additional channels, de-interleaving data
    247     for (j = 0; j < read_samples / input_channels; j++) {
    248       for (i = input_channels; i < read_data->height; i++) {
    249         ptr_data[i][j] = s->scratch_data[j * input_channels + (input_channels - 1)];
    250       }
     251  for (j = 0; j < read_length; j++) {
     252    for (i = 0; i < channels; i++) {
     253      ptr_data[i][j] = s->scratch_data[j * input_channels + i];
    251254    }
    252255  }
     
    265268#endif /* HAVE_SAMPLERATE */
    266269
    267   *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5);
    268 
    269   if (*read < s->hop_size) {
    270     for (i = 0; i < read_data->height; i++) {
    271       for (j = *read; j < s->hop_size; j++) {
    272         read_data->data[i][j] = 0.;
    273       }
    274     }
    275   }
    276 
     270  *read = MIN(length, (uint_t)FLOOR(s->ratio * read_length + .5));
     271
     272  aubio_source_pad_multi_output(read_data, input_channels, *read);
    277273}
    278274
  • src/io/source_wavread.c

    r868c6b8 rdfe6ab6  
    2525#include "fvec.h"
    2626#include "fmat.h"
     27#include "ioutils.h"
    2728#include "source_wavread.h"
    2829
    29 #include <errno.h>
    30 
    3130#define AUBIO_WAVREAD_BUFSIZE 1024
    3231
    33 #define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
     32//#define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
    3433
    3534struct _aubio_source_wavread_t {
     
    10099  s->fid = fopen((const char *)path, "rb");
    101100  if (!s->fid) {
    102     AUBIO_ERR("source_wavread: Failed opening %s (System error: %s)\n", s->path, strerror(errno));
     101    AUBIO_STRERR("source_wavread: Failed opening %s (%s)\n", s->path, errorstr);
    103102    goto beach;
    104103  }
     
    133132    bytes_junk += read_little_endian(buf, 4);
    134133    if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) {
    135       AUBIO_ERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n",
    136           s->path, strerror(errno));
     134      AUBIO_STRERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n",
     135          s->path, errorstr);
    137136      goto beach;
    138137    }
     
    261260    bytes_junk += read_little_endian(buf, 4);
    262261    if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) {
    263       AUBIO_ERR("source_wavread: could not seek past unknown chunk in %s (%s)\n",
    264           s->path, strerror(errno));
     262      AUBIO_STRERR("source_wavread: could not seek past unknown chunk in %s (%s)\n",
     263          s->path, errorstr);
    265264      goto beach;
    266265    }
     
    348347  uint_t end = 0;
    349348  uint_t total_wrote = 0;
     349  uint_t length = aubio_source_validate_input_length("source_wavread", s->path,
     350      s->hop_size, read_data->length);
    350351  if (s->fid == NULL) {
    351352    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     
    353354    return;
    354355  }
    355   while (total_wrote < s->hop_size) {
    356     end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     356  while (total_wrote < length) {
     357    end = MIN(s->read_samples - s->read_index, length - total_wrote);
    357358    for (i = 0; i < end; i++) {
    358359      read_data->data[i + total_wrote] = 0;
     
    363364    }
    364365    total_wrote += end;
    365     if (total_wrote < s->hop_size) {
     366    if (total_wrote < length) {
    366367      uint_t wavread_read = 0;
    367368      aubio_source_wavread_readframe(s, &wavread_read);
     
    375376    }
    376377  }
    377   if (total_wrote < s->hop_size) {
    378     for (i = end; i < s->hop_size; i++) {
    379       read_data->data[i] = 0.;
    380     }
    381   }
     378
     379  aubio_source_pad_output (read_data, total_wrote);
     380
    382381  *read = total_wrote;
    383382}
     
    387386  uint_t end = 0;
    388387  uint_t total_wrote = 0;
     388  uint_t length = aubio_source_validate_input_length("source_wavread", s->path,
     389      s->hop_size, read_data->length);
     390  uint_t channels = aubio_source_validate_input_channels("source_wavread",
     391      s->path, s->input_channels, read_data->height);
    389392  if (s->fid == NULL) {
    390393    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     
    392395    return;
    393396  }
    394   while (total_wrote < s->hop_size) {
    395     end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
    396     for (j = 0; j < read_data->height; j++) {
     397  while (total_wrote < length) {
     398    end = MIN(s->read_samples - s->read_index, length - total_wrote);
     399    for (j = 0; j < channels; j++) {
    397400      for (i = 0; i < end; i++) {
    398401        read_data->data[j][i + total_wrote] = s->output->data[j][i];
     
    400403    }
    401404    total_wrote += end;
    402     if (total_wrote < s->hop_size) {
     405    if (total_wrote < length) {
    403406      uint_t wavread_read = 0;
    404407      aubio_source_wavread_readframe(s, &wavread_read);
     
    412415    }
    413416  }
    414   if (total_wrote < s->hop_size) {
    415     for (j = 0; j < read_data->height; j++) {
    416       for (i = end; i < s->hop_size; i++) {
    417         read_data->data[j][i] = 0.;
    418       }
    419     }
    420   }
     417
     418  aubio_source_pad_multi_output(read_data, s->input_channels, total_wrote);
     419
    421420  *read = total_wrote;
    422421}
     
    442441  ret = fseek(s->fid, s->seek_start + pos * s->blockalign, SEEK_SET);
    443442  if (ret != 0) {
    444     AUBIO_ERR("source_wavread: could not seek %s at %d (%s)\n", s->path, pos, strerror(errno));
     443    AUBIO_STRERR("source_wavread: could not seek %s at %d (%s)\n", s->path, pos, errorstr);
    445444    return AUBIO_FAIL;
    446445  }
     
    463462  }
    464463  if (fclose(s->fid)) {
    465     AUBIO_ERR("source_wavread: could not close %s (%s)\n", s->path, strerror(errno));
     464    AUBIO_STRERR("source_wavread: could not close %s (%s)\n", s->path, errorstr);
    466465    return AUBIO_FAIL;
    467466  }
  • tests/src/io/base-sink_custom.h

    r868c6b8 rdfe6ab6  
    152152  close_temp_sink(sink_path, fd);
    153153
     154  // shouldn't crash on null (bypassed, only check del_aubio_sink)
     155  // del_aubio_sink_custom(NULL);
     156
    154157  return run_on_default_source_and_sink(base_main);
    155158}
  • tests/src/io/base-source_custom.h

    r868c6b8 rdfe6ab6  
    9494  if (read != hop_size) return 1;
    9595
     96  // read again in undersized vector
     97  del_fvec(vec);
     98  vec = new_fvec(hop_size - 1);
     99  aubio_source_custom_do(s, vec, &read);
     100  if (read != hop_size - 1) return 1;
     101
     102  // read again in oversized vector
     103  del_fvec(vec);
     104  vec = new_fvec(hop_size + 1);
     105  aubio_source_custom_do(s, vec, &read);
     106  if (read != hop_size) return 1;
     107
    96108  // seek to 0
    97109  if(aubio_source_custom_seek(s, 0)) return 1;
    98110
    99111  // read again as multiple channels
     112  aubio_source_custom_do_multi(s, mat, &read);
     113  if (read != hop_size) return 1;
     114
     115  // read again as multiple channels in an undersized matrix
     116  del_fmat(mat);
     117  mat = new_fmat(channels - 1, hop_size);
     118  aubio_source_custom_do_multi(s, mat, &read);
     119  if (read != hop_size) return 1;
     120
     121  // read again as multiple channels in an undersized matrix
     122  del_fmat(mat);
     123  mat = new_fmat(channels, hop_size - 1);
     124  aubio_source_custom_do_multi(s, mat, &read);
     125  if (read != hop_size - 1) return 1;
     126
     127  // read again as multiple channels in an oversized matrix
     128  del_fmat(mat);
     129  mat = new_fmat(channels + 1, hop_size);
     130  aubio_source_custom_do_multi(s, mat, &read);
     131  if (read != hop_size) return 1;
     132
     133  // read again as multiple channels in an oversized matrix
     134  del_fmat(mat);
     135  mat = new_fmat(channels, hop_size + 1);
    100136  aubio_source_custom_do_multi(s, mat, &read);
    101137  if (read != hop_size) return 1;
     
    106142  aubio_source_custom_close(s);
    107143
     144  // reading after close fails
     145  del_fvec(vec);
     146  vec = new_fvec(hop_size);
     147  aubio_source_custom_do(s, vec, &read);
     148  del_fmat(mat);
     149  mat = new_fmat(channels, hop_size);
     150  aubio_source_custom_do_multi(s, mat, &read);
     151
    108152  del_aubio_source_custom(s);
    109153  del_fmat(mat);
    110154  del_fvec(vec);
     155
     156  // shouldn't crash on null (bypassed, only check del_aubio_source)
     157  // del_aubio_source_custom(NULL);
    111158
    112159  return run_on_default_source(base_main);
  • tests/src/io/test-sink.c

    r868c6b8 rdfe6ab6  
    148148  close_temp_sink(sink_path, fd);
    149149
     150  // shouldn't crash on null
     151  del_aubio_sink(NULL);
     152
    150153  return run_on_default_source_and_sink(main);
    151154}
  • tests/src/io/test-source.c

    r868c6b8 rdfe6ab6  
    9090  if (read != hop_size) return 1;
    9191
     92  // read again in undersized vector
     93  del_fvec(vec);
     94  vec = new_fvec(hop_size - 1);
     95  aubio_source_do(s, vec, &read);
     96  if (read != hop_size - 1) return 1;
     97
     98  // read again in oversized vector
     99  del_fvec(vec);
     100  vec = new_fvec(hop_size + 1);
     101  aubio_source_do(s, vec, &read);
     102  if (read != hop_size) return 1;
     103
    92104  // seek to 0
    93105  if(aubio_source_seek(s, 0)) return 1;
    94106
    95107  // read again as multiple channels
     108  aubio_source_do_multi(s, mat, &read);
     109  if (read != hop_size) return 1;
     110
     111  // read again as multiple channels in an undersized matrix
     112  del_fmat(mat);
     113  mat = new_fmat(channels - 1, hop_size);
     114  aubio_source_do_multi(s, mat, &read);
     115  if (read != hop_size) return 1;
     116
     117  // read again as multiple channels in an undersized matrix
     118  del_fmat(mat);
     119  mat = new_fmat(channels, hop_size - 1);
     120  aubio_source_do_multi(s, mat, &read);
     121  if (read != hop_size - 1) return 1;
     122
     123  // read again as multiple channels in an oversized matrix
     124  del_fmat(mat);
     125  mat = new_fmat(channels + 1, hop_size);
     126  aubio_source_do_multi(s, mat, &read);
     127  if (read != hop_size) return 1;
     128
     129  // read again as multiple channels in an oversized matrix
     130  del_fmat(mat);
     131  mat = new_fmat(channels, hop_size + 1);
    96132  aubio_source_do_multi(s, mat, &read);
    97133  if (read != hop_size) return 1;
     
    102138  aubio_source_close(s);
    103139
     140  // reading after close fails
     141  del_fvec(vec);
     142  vec = new_fvec(hop_size);
     143  aubio_source_do(s, vec, &read);
     144  del_fmat(mat);
     145  mat = new_fmat(channels, hop_size);
     146  aubio_source_do_multi(s, mat, &read);
     147
    104148  del_aubio_source(s);
    105149  del_fmat(mat);
    106150  del_fvec(vec);
    107151
     152  // shouldn't crash on null
     153  del_aubio_source(NULL);
     154
    108155  return run_on_default_source(main);
    109156}
  • tests/src/spectral/test-mfcc.c

    r868c6b8 rdfe6ab6  
    3434  aubio_mfcc_t *mfcc = 0;
    3535
    36   fvec_t *in = new_fvec (win_s); // input buffer
    37   cvec_t *fftgrain = new_cvec (win_s); // input buffer
    38   fvec_t *out = new_fvec (n_coeffs); // output coefficients
     36  fvec_t *in = new_fvec (hop_s);       // phase vocoder input
     37  cvec_t *fftgrain = new_cvec (win_s); // pvoc output / mfcc input
     38  fvec_t *out = new_fvec (n_coeffs);   // mfcc output
    3939
    4040  if (!in || !fftgrain || !out) { err = 1; goto failure; }
  • tests/src/test-cvec.c

    r868c6b8 rdfe6ab6  
    44int main (void)
    55{
    6   uint_t i, window_size = 16; // window size
    7   cvec_t * complex_vector = new_cvec (window_size); // input buffer
    8   uint_t rand_times = 4;
     6  uint_t i, window_size = 16;
     7  cvec_t * complex_vector = new_cvec(window_size);
     8  cvec_t * other_cvector = new_cvec(window_size);
    99
    10   utils_init_random();
     10  assert(cvec_norm_get_data(complex_vector) == complex_vector->norm);
     11  assert(cvec_phas_get_data(complex_vector) == complex_vector->phas);
     12  assert(complex_vector->length == window_size / 2 + 1);
    1113
    12   while (rand_times -- ) {
    13     // fill with random phas and norm
    14     for ( i = 0; i < complex_vector->length; i++ ) {
    15       complex_vector->norm[i] = ( 2. / RAND_MAX * random() - 1. );
    16       complex_vector->phas[i] = ( 2. / RAND_MAX * random() - 1. ) * M_PI;
    17     }
    18     // print the vector
    19     cvec_print(complex_vector);
     14  // all elements are initialized to 0
     15  for ( i = 0; i < complex_vector->length; i++ ) {
     16    assert( complex_vector->norm[i] == 0. );
     17    assert( complex_vector->phas[i] == 0. );
    2018  }
    2119
    22   // set all vector elements to `0`
     20  cvec_norm_set_sample(complex_vector, 2., 1);
     21  assert(cvec_norm_get_sample(complex_vector, 1));
     22
     23  cvec_phas_set_sample(complex_vector, 2., 1);
     24  assert(cvec_phas_get_sample(complex_vector, 1));
     25
     26  cvec_print(complex_vector);
     27
     28  // set all norm and phas elements to 0
     29  cvec_zeros(complex_vector);
     30  for ( i = 0; i < complex_vector->length; i++ ) {
     31    assert( complex_vector->norm[i] == 0. );
     32    assert( complex_vector->phas[i] == 0. );
     33  }
     34
     35  // set all norm elements to 1
     36  cvec_norm_ones(complex_vector);
     37  for ( i = 0; i < complex_vector->length; i++ ) {
     38    assert( complex_vector->norm[i] == 1. );
     39  }
     40
     41  // set all norm elements to 0
    2342  cvec_norm_zeros(complex_vector);
    2443  for ( i = 0; i < complex_vector->length; i++ ) {
    2544    assert( complex_vector->norm[i] == 0. );
    26     // assert( complex_vector->phas[i] == 0 );
    2745  }
    28   cvec_print(complex_vector);
    2946
    30   // set all vector elements to `1`
    31   cvec_norm_ones(complex_vector);
     47  // set all phas elements to 1
     48  cvec_phas_ones(complex_vector);
    3249  for ( i = 0; i < complex_vector->length; i++ ) {
    33     assert( complex_vector->norm[i] == 1. );
    34     // assert( complex_vector->phas[i] == 0 );
     50    assert( complex_vector->phas[i] == 1. );
    3551  }
    36   cvec_print(complex_vector);
    3752
    38   cvec_zeros(complex_vector);
     53  // set all phas elements to 0
    3954  cvec_phas_zeros(complex_vector);
    40   cvec_norm_zeros(complex_vector);
    41   cvec_norm_ones(complex_vector);
    42   cvec_phas_ones(complex_vector);
     55  for ( i = 0; i < complex_vector->length; i++ ) {
     56    assert( complex_vector->phas[i] == 0. );
     57  }
     58
     59  cvec_copy(complex_vector, other_cvector);
     60  // copy to self
    4361  cvec_copy(complex_vector, complex_vector);
     62  // copy to a different size fails
     63  del_cvec(other_cvector);
     64  other_cvector = new_cvec(window_size + 2);
     65  cvec_copy(complex_vector, other_cvector);
    4466
    45   // destroy it
    46   del_cvec(complex_vector);
     67  if (complex_vector)
     68    del_cvec(complex_vector);
     69  if (other_cvector)
     70    del_cvec(other_cvector);
     71
     72  // wrong parameters
     73  assert(new_cvec(-1) == NULL);
     74  assert(new_cvec(0) == NULL);
     75
    4776  return 0;
    4877}
  • tests/src/test-fmat.c

    r868c6b8 rdfe6ab6  
    55// and j the column.
    66
     7void assert_fmat_all_equal(fmat_t *mat, smpl_t scalar)
     8{
     9  uint_t i, j;
     10  for ( i = 0; i < mat->height; i++ ) {
     11    for ( j = 0; j < mat->length; j++ ) {
     12      assert(mat->data[i][j] == scalar);
     13    }
     14  }
     15}
     16
    717int main (void)
    818{
    9   uint_t height = 3, length = 9, i, j;
     19  uint_t i, j;
     20  uint_t height = 3, length = 9;
     21
    1022  // create fmat_t object
    11   fmat_t * mat = new_fmat (height, length);
    12   for ( i = 0; i < mat->height; i++ ) {
    13     for ( j = 0; j < mat->length; j++ ) {
     23  fmat_t * mat = new_fmat(height, length);
     24  fmat_t * other_mat = new_fmat(height, length);
     25
     26  assert(mat);
     27  assert(other_mat);
     28
     29  assert(mat->length == length);
     30  assert(mat->height == height);
     31
     32  for (i = 0; i < mat->height; i++) {
     33    for (j = 0; j < mat->length; j++) {
    1434      // all elements are already initialized to 0.
    1535      assert(mat->data[i][j] == 0);
    1636      // setting element of row i, column j
    17       mat->data[i][j] = i * 1. + j *.1;
     37      mat->data[i][j] = i * 10. + j;
    1838    }
    1939  }
     40
     41  // print out matrix
     42  fmat_print(mat);
     43
     44  // helpers
     45  fmat_rev(mat);
     46  fmat_print(mat);
     47  for (i = 0; i < mat->height; i++) {
     48    for (j = 0; j < mat->length; j++) {
     49      assert(mat->data[i][j] == i * 10. + mat->length - 1. - j);
     50    }
     51  }
     52
     53  fmat_set_sample(mat, 3, 1, 1);
     54  assert(fmat_get_sample(mat, 1, 1) == 3.);
     55
     56  fmat_ones(mat);
     57  assert_fmat_all_equal(mat, 1.);
     58
     59  fmat_set(other_mat, .5);
     60  assert_fmat_all_equal(other_mat, .5);
     61
     62  fmat_weight(mat, other_mat);
     63  assert_fmat_all_equal(mat, .5);
     64
    2065  fvec_t channel_onstack;
    2166  fvec_t *channel = &channel_onstack;
    2267  fmat_get_channel(mat, 1, channel);
    23   fvec_print (channel);
    24   // print out matrix
    25   fmat_print(mat);
    26   // destroy it
    27   del_fmat(mat);
     68  assert(channel->data == mat->data[1]);
     69
     70  // copy of the same size
     71  fmat_copy(mat, other_mat);
     72  del_fmat(other_mat);
     73
     74  // copy to undersized
     75  other_mat = new_fmat(height - 1, length);
     76  fmat_copy(mat, other_mat);
     77  del_fmat(other_mat);
     78
     79  // copy from undersized
     80  other_mat = new_fmat(height, length + 1);
     81  fmat_copy(mat, other_mat);
     82
     83  // wrong parameters
     84  assert(new_fmat(-1, length) == NULL);
     85  assert(new_fmat(height, -1) == NULL);
     86
     87  // methods for wrappers with opaque structure
     88  assert (fmat_get_channel_data(mat, 0) == mat->data[0]);
     89  assert (fmat_get_data(mat) == mat->data);
     90
     91  if (mat)
     92    del_fmat(mat);
     93  if (other_mat)
     94    del_fmat(other_mat);
    2895  return 0;
    2996}
    30 
  • tests/src/test-fvec.c

    r868c6b8 rdfe6ab6  
    22#include "utils_tests.h"
    33
     4void assert_fvec_all_equal(fvec_t *vec, smpl_t scalar)
     5{
     6  uint_t i;
     7  for (i = 0; i < vec->length; i++) {
     8    assert(vec->data[i] == scalar);
     9  }
     10}
     11
    412int main (void)
    513{
    6   uint_t vec_size = 10, i;
    7   fvec_t * vec = new_fvec (vec_size);
     14  uint_t length = 10;
     15  uint_t i;
     16
     17  fvec_t * vec = new_fvec (length);
     18  fvec_t * other_vec = new_fvec (length);
     19
     20  assert (vec);
     21  assert (other_vec);
    822
    923  // vec->length matches requested size
    10   assert(vec->length == vec_size);
     24  assert(vec->length == length);
    1125
    1226  // all elements are initialized to `0.`
     
    1529  }
    1630
     31  // all elements can be set to `1.`
     32  fvec_ones(vec);
     33  assert_fvec_all_equal(vec, 1.);
     34
    1735  // all elements can be set to `0.`
    1836  fvec_zeros(vec);
    19   for ( i = 0; i < vec->length; i++ ) {
    20     assert(vec->data[i] == 0.);
    21   }
    22   fvec_print(vec);
    23 
    24   // all elements can be set to `1.`
    25   fvec_ones(vec);
    26   for ( i = 0; i < vec->length; i++ ) {
    27     assert(vec->data[i] == 1.);
    28   }
    29   fvec_print(vec);
     37  assert_fvec_all_equal(vec, 0.);
    3038
    3139  // each element can be accessed directly
     
    3644  fvec_print(vec);
    3745
     46  fvec_set_sample(vec, 3, 2);
     47  assert(fvec_get_sample(vec, 2) == 3);
     48
     49  assert(fvec_get_data(vec) == vec->data);
     50
     51  // wrong parameters
     52  assert(new_fvec(-1) == NULL);
     53
     54  // copy to an identical size works
     55  fvec_copy(vec, other_vec);
     56  del_fvec(other_vec);
     57
     58  // copy to a different size fail
     59  other_vec = new_fvec(length + 1);
     60  fvec_copy(vec, other_vec);
     61  del_fvec(other_vec);
     62
     63  // copy to a different size fail
     64  other_vec = new_fvec(length - 1);
     65  fvec_copy(vec, other_vec);
     66
    3867  // now destroys the vector
    39   del_fvec(vec);
    40 
     68  if (vec)
     69    del_fvec(vec);
     70  if (other_vec)
     71    del_fvec(other_vec);
    4172  return 0;
    4273}
    43 
  • tests/src/test-lvec.c

    r868c6b8 rdfe6ab6  
    22#include "utils_tests.h"
    33
     4void assert_lvec_all_equal(lvec_t *vec, lsmp_t scalar)
     5{
     6  uint_t i;
     7  for (i = 0; i < vec->length; i++) {
     8    assert(vec->data[i] == scalar);
     9  }
     10}
     11
    412int main (void)
    513{
    6   uint_t win_s = 32; // window size
    7   lvec_t * sp = new_lvec (win_s); // input buffer
    8   lvec_set_sample (sp, 2./3., 0);
    9   PRINT_MSG(AUBIO_LSMP_FMT "\n", lvec_get_sample (sp, 0));
    10   lvec_print (sp);
    11   lvec_ones (sp);
    12   lvec_print (sp);
    13   lvec_set_all (sp, 3./5.);
    14   lvec_print (sp);
    15   del_lvec(sp);
     14  uint_t length = 32; // window size
     15
     16  lvec_t * vec = new_lvec (length); // input buffer
     17
     18  assert(vec);
     19
     20  assert(vec->length == length);
     21
     22  lvec_set_sample (vec, 3., 0);
     23  assert(lvec_get_sample(vec, 0) == 3.);
     24
     25  assert(lvec_get_data(vec) == vec->data);
     26
     27  lvec_print (vec);
     28  // note AUBIO_LSMP_FMT can be used to print lsmp_t
     29  PRINT_MSG(AUBIO_LSMP_FMT "\n", lvec_get_sample (vec, 0));
     30
     31  lvec_set_all (vec, 2.);
     32  assert_lvec_all_equal(vec, 2.);
     33
     34  lvec_ones (vec);
     35  assert_lvec_all_equal(vec, 1.);
     36
     37  lvec_zeros (vec);
     38  assert_lvec_all_equal(vec, 0.);
     39
     40  del_lvec(vec);
     41
     42  // wrong parameters
     43  assert(new_lvec(0) == NULL);
     44  assert(new_lvec(-1) == NULL);
     45
    1646  return 0;
    1747}
    18 
  • tests/src/test-mathutils-window.c

    r868c6b8 rdfe6ab6  
    88  uint_t lengths[4] = { 8, 10, 15, 16 };
    99  char *method = "default";
    10   char *window_types[10] = { "default",
    11     "rectangle", "hamming", "hanning", "hanningz",
     10  char *window_types[11] = { "default",
     11    "ones", "rectangle", "hamming", "hanning", "hanningz",
    1212    "blackman", "blackman_harris", "gaussian", "welch", "parzen"};
    1313
     
    2727    }
    2828  }
     29
     30  assert (new_aubio_window("parzen", -1) == NULL);
     31  assert (new_aubio_window(NULL, length) == NULL);
     32  assert (new_aubio_window("\0", length) == NULL);
    2933  return 0;
    3034}
  • wscript

    r868c6b8 rdfe6ab6  
    140140    ctx.check(header_name='math.h')
    141141    ctx.check(header_name='string.h')
     142    ctx.check(header_name='errno.h')
    142143    ctx.check(header_name='limits.h')
    143144    ctx.check(header_name='stdarg.h')
     
    630631    ctx.excl += ' **/.cache'
    631632    ctx.excl += ' **/**.zip **/**.tar.bz2'
    632     ctx.excl += ' **.tar.bz2'
     633    ctx.excl += ' **.tar.bz2**'
    633634    ctx.excl += ' **/doc/full/* **/doc/web/*'
    634635    ctx.excl += ' **/doc/full.cfg'
     
    642643    ctx.excl += ' **/.DS_Store'
    643644    ctx.excl += ' **/.travis.yml'
    644     ctx.excl += ' **/.landscape.yml'
    645645    ctx.excl += ' **/.appveyor.yml'
    646646    ctx.excl += ' **/.circleci/*'
Note: See TracChangeset for help on using the changeset viewer.