Changes in / [dfe6ab6:868c6b8]


Ignore:
Files:
4 added
2 deleted
70 edited

Legend:

Unmodified
Added
Removed
  • .appveyor.yml

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

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

    rdfe6ab6 r868c6b8  
    33matrix:
    44  include:
    5     - python: 3.6
     5    - python: 3.5
     6      os: linux
     7      compiler: gcc
     8    - python: 3.4
     9      os: linux
     10      compiler: gcc
     11    - python: 2.7
    612      os: linux
    713      compiler: gcc
     
    915      os: linux
    1016      compiler: gcc
    11       env: WAFOPTS="--build-type=debug"
    12     - python: 2.7
    13       os: linux
    14       compiler: gcc
    15     - python: "pypy3.5"
    16       os: linux
    17       compiler: gcc
    18       env: CFLAGS="-Os" WAFOPTS="--disable-avcodec"
    19     - python: 3.6
    20       os: linux
    21       compiler: gcc
    22       env: CFLAGS="-Os" WAFOPTS="--disable-samplerate"
    23     - python: 3.5
     17      env: CFLAGS="-Os" WAFOPTS="--disable-samplerate --disable-sndfile"
     18    - python: 3.4
    2419      os: linux
    2520      compiler: gcc
     
    9186  - which pip
    9287  - pip --version
    93   - pip install coverage
    9488
    9589script:
  • ChangeLog

    rdfe6ab6 r868c6b8  
    1 2018-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 
    8112018-11-21 Paul Brossier <piem@aubio.org>
    822
  • MANIFEST.in

    rdfe6ab6 r868c6b8  
    77include Makefile wscript */wscript_build
    88include aubio.pc.in
     9include nose2.cfg
    910include requirements.txt
    1011include src/*.c src/*.h
     
    1516recursive-include python *.py
    1617include python/README.md
     18include python/tests/run_all_tests
    1719include python/tests/eval_pitch
    1820include python/tests/*.expected
  • Makefile

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

    rdfe6ab6 r868c6b8  
    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")
    67[![Commits since last release](https://img.shields.io/github/commits-since/aubio/aubio/latest.svg)](https://github.com/aubio/aubio "Commits since last release")
    78
  • VERSION

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

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

    rdfe6ab6 r868c6b8  
    9090------------
    9191
    92 A number of Python tests are provided in the `python/tests`_ folder. To run
    93 them, install `pytest`_ and run it from the aubio source directory:
     92A number of Python tests are provided in the `python tests`_. To run them,
     93install `nose2`_ and run the script ``python/tests/run_all_tests``:
    9494
    9595.. code-block:: console
    9696
    97     $ pip install pytest
    98     $ git clone https://git.aubio.org/aubio/aubio
    99     $ cd aubio
    100     $ pytest
     97    $ pip install nose2
     98    $ ./python/tests/run_all_tests
    10199
    102 .. _python/tests: https://github.com/aubio/aubio/blob/master/python/tests
    103 .. _pytest: https://pytest.org
     100.. _demo_filter.py: https://github.com/aubio/aubio/blob/master/python/demos/demo_filter.py
     101.. _python tests: https://github.com/aubio/aubio/blob/master/python/tests
     102.. _nose2: https://github.com/nose-devs/nose2
  • doc/statuslinks.rst

    rdfe6ab6 r868c6b8  
    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
    1216.. image:: https://readthedocs.org/projects/aubio/badge/?version=latest
    1317   :target: https://aubio.readthedocs.io/en/latest/?badge=latest
  • examples/utils.c

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

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

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

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

    rdfe6ab6 r868c6b8  
    437437  aubio_source_do (self->o, &(self->c_read_to), &read);
    438438
    439   if (PyErr_Occurred() != NULL) {
    440     return NULL;
    441   }
    442 
    443439  outputs = PyTuple_New(2);
    444440  PyTuple_SetItem( outputs, 0, self->read_to );
     
    461457  /* compute _do function */
    462458  aubio_source_do_multi (self->o, &(self->c_mread_to), &read);
    463 
    464   if (PyErr_Occurred() != NULL) {
    465     return NULL;
    466   }
    467459
    468460  outputs = PyTuple_New(2);
     
    582574    } else if (PyLong_AsLong(size) > 0) {
    583575      // short read, return a shorter array
    584       PyObject *vec = PyTuple_GetItem(done, 0);
    585       // take a copy to prevent resizing internal arrays
    586       PyArrayObject *shortread = (PyArrayObject*)PyArray_FROM_OTF(vec,
    587           NPY_NOTYPE, NPY_ARRAY_ENSURECOPY);
     576      PyArrayObject *shortread = (PyArrayObject*)PyTuple_GetItem(done, 0);
    588577      PyArray_Dims newdims;
    589578      PyObject *reshaped;
     
    598587      reshaped = PyArray_Newshape(shortread, &newdims, NPY_CORDER);
    599588      Py_DECREF(shortread);
    600       Py_DECREF(vec);
    601589      return reshaped;
    602590    } else {
  • python/lib/moresetuptools.py

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

    rdfe6ab6 r868c6b8  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase
    45
     
    1516
    1617if __name__ == '__main__':
    17     from unittest import main
    1818    main()
     19
  • python/tests/test_aubio_cmd.py

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    rdfe6ab6 r868c6b8  
    11#! /usr/bin/env python
    22
     3from nose2 import main
     4from nose2.tools import params
    35from numpy.testing import TestCase
    46from aubio import fvec, source, sink
    5 from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
    6 from utils import parse_file_samplerate
    7 from _tools import parametrize, skipTest, assert_raises, assert_warns
     7from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
     8
     9import warnings
     10warnings.filterwarnings('ignore', category=UserWarning, append=True)
    811
    912list_of_sounds = list_all_sounds('sounds')
     
    2124            all_params.append((hop_size, samplerate, soundfile))
    2225
    23 class Test_aubio_sink(object):
     26class aubio_sink_test_case(TestCase):
     27
     28    def setUp(self):
     29        if not len(list_of_sounds):
     30            self.skipTest('add some sound files in \'python/tests/sounds\'')
    2431
    2532    def test_wrong_filename(self):
    26         with assert_raises(RuntimeError):
     33        with self.assertRaises(RuntimeError):
    2734            sink('')
    2835
    2936    def test_wrong_samplerate(self):
    30         with assert_raises(RuntimeError):
     37        with self.assertRaises(RuntimeError):
    3138            sink(get_tmp_sink_path(), -1)
    3239
    3340    def test_wrong_samplerate_too_large(self):
    34         with assert_raises(RuntimeError):
     41        with self.assertRaises(RuntimeError):
    3542            sink(get_tmp_sink_path(), 1536001, 2)
    3643
    3744    def test_wrong_channels(self):
    38         with assert_raises(RuntimeError):
     45        with self.assertRaises(RuntimeError):
    3946            sink(get_tmp_sink_path(), 44100, -1)
    4047
    4148    def test_wrong_channels_too_large(self):
    42         with assert_raises(RuntimeError):
     49        with self.assertRaises(RuntimeError):
    4350            sink(get_tmp_sink_path(), 44100, 202020)
    4451
     
    6067        shutil.rmtree(tmpdir)
    6168
    62     @parametrize('hop_size, samplerate, path', all_params)
     69    @params(*all_params)
    6370    def test_read_and_write(self, hop_size, samplerate, path):
    64         orig_samplerate = parse_file_samplerate(soundfile)
     71
    6572        try:
    66             if orig_samplerate is not None and orig_samplerate < samplerate:
    67                 # upsampling should emit a warning
    68                 with assert_warns(UserWarning):
    69                     f = source(soundfile, samplerate, hop_size)
    70             else:
    71                 f = source(soundfile, samplerate, hop_size)
     73            f = source(path, samplerate, hop_size)
    7274        except RuntimeError as e:
    73             err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
    74             skipTest(err_msg.format(str(e), hop_size, samplerate))
     75            self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
    7576        if samplerate == 0: samplerate = f.samplerate
    7677        sink_path = get_tmp_sink_path()
     
    8485        del_tmp_sink_path(sink_path)
    8586
    86     @parametrize('hop_size, samplerate, path', all_params)
     87    @params(*all_params)
    8788    def test_read_and_write_multi(self, hop_size, samplerate, path):
    88         orig_samplerate = parse_file_samplerate(soundfile)
    8989        try:
    90             if orig_samplerate is not None and orig_samplerate < samplerate:
    91                 # upsampling should emit a warning
    92                 with assert_warns(UserWarning):
    93                     f = source(soundfile, samplerate, hop_size)
    94             else:
    95                 f = source(soundfile, samplerate, hop_size)
     90            f = source(path, samplerate, hop_size)
    9691        except RuntimeError as e:
    97             err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
    98             skipTest(err_msg.format(str(e), hop_size, samplerate))
     92            self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
    9993        if samplerate == 0: samplerate = f.samplerate
    10094        sink_path = get_tmp_sink_path()
     
    132126
    133127if __name__ == '__main__':
    134     from _tools import run_module_suite
    135     run_module_suite()
     128    main()
  • python/tests/test_slicing.py

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

    rdfe6ab6 r868c6b8  
    11#! /usr/bin/env python
    22
    3 
     3from nose2 import main
     4from nose2.tools import params
    45from numpy.testing import TestCase, assert_equal
    56from aubio import source
    6 from utils import list_all_sounds, parse_file_samplerate
    7 import unittest
    8 from _tools import assert_raises, assert_equal, assert_warns
    9 from _tools import parametrize, skipTest
     7from .utils import list_all_sounds
     8
     9import warnings
     10warnings.filterwarnings('ignore', category=UserWarning, append=True)
    1011
    1112list_of_sounds = list_all_sounds('sounds')
     
    1314hop_sizes = [512, 1024, 64]
    1415
    15 default_test_sound = len(list_of_sounds) and list_of_sounds[0] or None
     16path = None
    1617
    1718all_params = []
     
    2122            all_params.append((hop_size, samplerate, soundfile))
    2223
    23 no_sounds_msg = "no test sounds, add some in 'python/tests/sounds/'!"
    2424
    25 _debug = False
    26 
    27 
    28 class Test_aubio_source_test_case(TestCase):
     25class aubio_source_test_case_base(TestCase):
    2926
    3027    def setUp(self):
    31         if not default_test_sound:
    32             skipTest(no_sounds_msg)
     28        if not len(list_of_sounds):
     29            self.skipTest('add some sound files in \'python/tests/sounds\'')
     30        self.default_test_sound = list_of_sounds[0]
    3331
    34     def test_close_file(self):
     32class aubio_source_test_case(aubio_source_test_case_base):
     33
     34    @params(*list_of_sounds)
     35    def test_close_file(self, filename):
    3536        samplerate = 0 # use native samplerate
    3637        hop_size = 256
    37         f = source(default_test_sound, samplerate, hop_size)
     38        f = source(filename, samplerate, hop_size)
    3839        f.close()
    3940
    40     def test_close_file_twice(self):
     41    @params(*list_of_sounds)
     42    def test_close_file_twice(self, filename):
    4143        samplerate = 0 # use native samplerate
    4244        hop_size = 256
    43         f = source(default_test_sound, samplerate, hop_size)
     45        f = source(filename, samplerate, hop_size)
    4446        f.close()
    4547        f.close()
    4648
    47     def test_read_after_close(self):
    48         samplerate = 0 # use native samplerate
    49         hop_size = 256
    50         f = source(default_test_sound, samplerate, hop_size)
    51         read, frames = f()
    52         f.close()
    53         with assert_raises(RuntimeError):
    54             read, frames = f()
    55         with assert_raises(RuntimeError):
    56             read, frames = f.do_multi()
    57 
    58 
    59 class Test_aubio_source_read(object):
     49class aubio_source_read_test_case(aubio_source_test_case_base):
    6050
    6151    def read_from_source(self, f):
     
    6757                assert_equal(samples[read:], 0)
    6858                break
    69         if _debug:
    70             result_str = "read {:.2f}s ({:d} frames"
    71             result_str += " in {:d} blocks at {:d}Hz) from {:s}"
    72             result_params = total_frames / float(f.samplerate), total_frames, \
    73                     total_frames//f.hop_size, f.samplerate, f.uri
    74             print (result_str.format(*result_params))
     59        #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"
     60        #result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri
     61        #print (result_str.format(*result_params))
    7562        return total_frames
    7663
    77     @parametrize('hop_size, samplerate, soundfile', all_params)
     64    @params(*all_params)
    7865    def test_samplerate_hopsize(self, hop_size, samplerate, soundfile):
    79         orig_samplerate = parse_file_samplerate(soundfile)
    8066        try:
    81             if orig_samplerate is not None and orig_samplerate < samplerate:
    82                 # upsampling should emit a warning
    83                 with assert_warns(UserWarning):
    84                     f = source(soundfile, samplerate, hop_size)
    85             else:
    86                 f = source(soundfile, samplerate, hop_size)
     67            f = source(soundfile, samplerate, hop_size)
    8768        except RuntimeError as e:
    88             err_msg = 'failed opening with hop_s={:d}, samplerate={:d} ({:s})'
    89             skipTest(err_msg.format(hop_size, samplerate, str(e)))
     69            self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
    9070        assert f.samplerate != 0
    9171        read_frames = self.read_from_source(f)
    9272        if 'f_' in soundfile and samplerate == 0:
    9373            import re
    94             f = re.compile(r'.*_\([0:9]*f\)_.*')
     74            f = re.compile('.*_\([0:9]*f\)_.*')
    9575            match_f = re.findall('([0-9]*)f_', soundfile)
    9676            if len(match_f) == 1:
    9777                expected_frames = int(match_f[0])
    98                 assert_equal(expected_frames, read_frames)
     78                self.assertEqual(expected_frames, read_frames)
    9979
    100     @parametrize('p', list_of_sounds)
     80    @params(*list_of_sounds)
    10181    def test_samplerate_none(self, p):
    10282        f = source(p)
     
    10484        self.read_from_source(f)
    10585
    106     @parametrize('p', list_of_sounds)
     86    @params(*list_of_sounds)
    10787    def test_samplerate_0(self, p):
    10888        f = source(p, 0)
     
    11090        self.read_from_source(f)
    11191
    112     @parametrize('p', list_of_sounds)
     92    @params(*list_of_sounds)
    11393    def test_zero_hop_size(self, p):
    11494        f = source(p, 0, 0)
     
    11797        self.read_from_source(f)
    11898
    119     @parametrize('p', list_of_sounds)
     99    @params(*list_of_sounds)
    120100    def test_seek_to_half(self, p):
    121101        from random import randint
     
    129109        assert a == b + c
    130110
    131     @parametrize('p', list_of_sounds)
     111    @params(*list_of_sounds)
    132112    def test_duration(self, p):
    133113        total_frames = 0
     
    138118            total_frames += read
    139119            if read < f.hop_size: break
    140         assert_equal (duration, total_frames)
     120        self.assertEqual(duration, total_frames)
    141121
    142122
    143 class Test_aubio_source_wrong_params(object):
     123class aubio_source_test_wrong_params(TestCase):
    144124
    145125    def test_wrong_file(self):
    146         with assert_raises(RuntimeError):
     126        with self.assertRaises(RuntimeError):
    147127            source('path_to/unexisting file.mp3')
    148128
    149 @unittest.skipIf(default_test_sound is None, no_sounds_msg)
    150 class Test_aubio_source_wrong_params_with_file(TestCase):
     129class aubio_source_test_wrong_params_with_file(aubio_source_test_case_base):
    151130
    152131    def test_wrong_samplerate(self):
    153         with assert_raises(ValueError):
    154             source(default_test_sound, -1)
     132        with self.assertRaises(ValueError):
     133            source(self.default_test_sound, -1)
    155134
    156135    def test_wrong_hop_size(self):
    157         with assert_raises(ValueError):
    158             source(default_test_sound, 0, -1)
     136        with self.assertRaises(ValueError):
     137            source(self.default_test_sound, 0, -1)
    159138
    160139    def test_wrong_channels(self):
    161         with assert_raises(ValueError):
    162             source(default_test_sound, 0, 0, -1)
     140        with self.assertRaises(ValueError):
     141            source(self.default_test_sound, 0, 0, -1)
    163142
    164143    def test_wrong_seek(self):
    165         f = source(default_test_sound)
    166         with assert_raises(ValueError):
     144        f = source(self.default_test_sound)
     145        with self.assertRaises(ValueError):
    167146            f.seek(-1)
    168147
    169148    def test_wrong_seek_too_large(self):
    170         f = source(default_test_sound)
     149        f = source(self.default_test_sound)
    171150        try:
    172             with assert_raises(ValueError):
     151            with self.assertRaises(ValueError):
    173152                f.seek(f.duration + f.samplerate * 10)
    174         except:
    175             skipTest('seeking after end of stream failed raising ValueError')
     153        except AssertionError:
     154            self.skipTest('seeking after end of stream failed raising ValueError')
    176155
    177 class Test_aubio_source_readmulti(Test_aubio_source_read):
     156class aubio_source_readmulti_test_case(aubio_source_read_test_case):
    178157
    179158    def read_from_source(self, f):
     
    185164                assert_equal(samples[:,read:], 0)
    186165                break
    187         if _debug:
    188             result_str = "read {:.2f}s ({:d} frames in {:d} channels"
    189             result_str += " and {:d} blocks at {:d}Hz) from {:s}"
    190             result_params = total_frames / float(f.samplerate), total_frames, \
    191                     f.channels, int(total_frames/f.hop_size), \
    192                     f.samplerate, f.uri
    193             print (result_str.format(*result_params))
     166        #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"
     167        #result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri
     168        #print (result_str.format(*result_params))
    194169        return total_frames
    195170
    196 class Test_aubio_source_with(object):
     171class aubio_source_with(aubio_source_test_case_base):
    197172
    198     @parametrize('filename', list_of_sounds)
     173    #@params(*list_of_sounds)
     174    @params(*list_of_sounds)
    199175    def test_read_from_mono(self, filename):
    200176        total_frames = 0
     
    210186
    211187if __name__ == '__main__':
    212     from _tools import run_module_suite
    213     run_module_suite()
     188    main()
  • python/tests/test_source_channels.py

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

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

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

    rdfe6ab6 r868c6b8  
    22
    33import os
    4 import re
    54import glob
    65import numpy as np
     
    109
    1110def array_from_text_file(filename, dtype = 'float'):
    12     realpathname = os.path.join(os.path.dirname(__file__), filename)
    13     return np.loadtxt(realpathname, dtype = dtype)
     11    filename = os.path.join(os.path.dirname(__file__), filename)
     12    with open(filename) as f:
     13        lines = f.readlines()
     14    return np.array([line.split() for line in lines],
     15            dtype = dtype)
    1416
    1517def list_all_sounds(rel_dir):
     
    3739        os.unlink(path)
    3840    except WindowsError as e:
    39         # removing the temporary directory sometimes fails on windows
    40         import warnings
    41         errmsg = "failed deleting temporary file {:s} ({:s})"
    42         warnings.warn(UserWarning(errmsg.format(path, repr(e))))
     41        print("deleting {:s} failed ({:s}), reopening".format(path, repr(e)))
     42        with open(path, 'wb') as f:
     43            f.close()
     44        try:
     45            os.unlink(path)
     46        except WindowsError as f:
     47            print("deleting {:s} failed ({:s}), aborting".format(path, repr(e)))
    4348
    4449def array_from_yaml_file(filename):
     
    7984                    total_files += 1
    8085    return total_files
    81 
    82 def 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

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

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

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

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

    rdfe6ab6 r868c6b8  
    6363#endif
    6464
    65 #ifdef HAVE_ERRNO_H
    66 #include <errno.h>
    67 #endif
    68 
    6965#ifdef HAVE_LIMITS_H
    7066#include <limits.h> // for CHAR_BIT, in C99 standard
     
    7571#endif
    7672
    77 #if defined(HAVE_BLAS) // --enable-blas=true
    78 // check which cblas header we found
     73#if defined(HAVE_ACCELERATE)
     74#define HAVE_ATLAS 1
     75#define HAVE_BLAS 1
     76#include <Accelerate/Accelerate.h>
     77#elif defined(HAVE_ATLAS_CBLAS_H)
     78#elif defined(HAVE_BLAS)
    7979#if defined(HAVE_ATLAS_CBLAS_H)
    8080#define HAVE_ATLAS 1
     
    8484#elif defined(HAVE_CBLAS_H)
    8585#include <cblas.h>
    86 #elif !defined(HAVE_ACCELERATE)
    87 #error "HAVE_BLAS was defined, but no blas header was found"
    88 #endif /* end of cblas includes */
    89 #endif
    90 
    91 #if defined(HAVE_ACCELERATE)
    92 // include accelerate framework after blas
    93 #define HAVE_ATLAS 1
    94 #define HAVE_BLAS 1
     86#endif
     87#endif
     88
     89#ifdef HAVE_ACCELERATE
    9590#include <Accelerate/Accelerate.h>
    96 
    9791#ifndef HAVE_AUBIO_DOUBLE
    9892#define aubio_vDSP_mmov       vDSP_mmov
     
    331325#endif
    332326
    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 
    351327/* handy shortcuts */
    352328#define DB2LIN(g) (POW(10.0,(g)*0.05f))
  • src/io/ioutils.c

    rdfe6ab6 r868c6b8  
    2020
    2121#include "aubio_priv.h"
    22 #include "fmat.h"
    2322
    2423uint_t
     
    5251  }
    5352  return AUBIO_OK;
    54 }
    55 
    56 uint_t
    57 aubio_source_validate_input_length(const char_t *kind, const char_t *path,
    58     uint_t hop_size, uint_t read_data_length)
    59 {
    60   uint_t length = hop_size;
    61   if (hop_size < read_data_length) {
    62     AUBIO_WRN("%s: partial read from %s, trying to read %d frames, but"
    63         " hop_size is %d\n", kind, path, read_data_length, hop_size);
    64   } else if (hop_size > read_data_length) {
    65     AUBIO_WRN("%s: partial read from %s, trying to read %d frames into"
    66         " a buffer of length %d\n", kind, path, hop_size, read_data_length);
    67     length = read_data_length;
    68   }
    69   return length;
    70 }
    71 
    72 uint_t
    73 aubio_source_validate_input_channels(const char_t *kind, const char_t *path,
    74     uint_t source_channels, uint_t read_data_height)
    75 {
    76   uint_t channels = source_channels;
    77   if (read_data_height < source_channels) {
    78     AUBIO_WRN("%s: partial read from %s, trying to read %d channels,"
    79         " but found output of height %d\n", kind, path, source_channels,
    80         read_data_height);
    81     channels = read_data_height;
    82   } else if (read_data_height > source_channels) {
    83     // do not show a warning when trying to read into more channels 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 
    95 void
    96 aubio_source_pad_output (fvec_t *read_data, uint_t source_read)
    97 {
    98   if (source_read < read_data->length) {
    99     AUBIO_MEMSET(read_data->data + source_read, 0,
    100         (read_data->length - source_read) * sizeof(smpl_t));
    101   }
    102 }
    103 
    104 void
    105 aubio_source_pad_multi_output (fmat_t *read_data,
    106     uint_t source_channels, uint_t source_read) {
    107   uint_t i;
    108   if (source_read < read_data->length) {
    109     for (i = 0; i < read_data->height; i++) {
    110       AUBIO_MEMSET(read_data->data[i] + source_read, 0,
    111           (read_data->length - source_read) * sizeof(smpl_t));
    112     }
    113   }
    114 
    115   // destination matrix has more channels than the 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   }
    12353}
    12454
  • src/io/ioutils.h

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

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

    rdfe6ab6 r868c6b8  
    2828#include "io/sink_wavwrite.h"
    2929#include "io/ioutils.h"
     30
     31#include <errno.h>
    3032
    3133#define MAX_SIZE 4096
     
    161163  unsigned char buf[5];
    162164  uint_t byterate, blockalign;
    163   size_t written = 0;
    164165
    165166  /* open output file */
    166167  s->fid = fopen((const char *)s->path, "wb");
    167168  if (!s->fid) {
    168     AUBIO_STRERR("sink_wavwrite: could not open %s (%s)\n", s->path, errorstr);
     169    AUBIO_ERR("sink_wavwrite: could not open %s (%s)\n", s->path, strerror(errno));
    169170    goto beach;
    170171  }
    171172
    172173  // ChunkID
    173   written += fwrite("RIFF", 4, 1, s->fid);
     174  fwrite("RIFF", 4, 1, s->fid);
    174175
    175176  // ChunkSize (0 for now, actual size will be written in _close)
    176   written += fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);
     177  fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);
    177178
    178179  // Format
    179   written += fwrite("WAVE", 4, 1, s->fid);
     180  fwrite("WAVE", 4, 1, s->fid);
    180181
    181182  // Subchunk1ID
    182   written += fwrite("fmt ", 4, 1, s->fid);
     183  fwrite("fmt ", 4, 1, s->fid);
    183184
    184185  // Subchunk1Size
    185   written += fwrite(write_little_endian(16, buf, 4), 4, 1, s->fid);
     186  fwrite(write_little_endian(16, buf, 4), 4, 1, s->fid);
    186187
    187188  // AudioFormat
    188   written += fwrite(write_little_endian(1, buf, 2), 2, 1, s->fid);
     189  fwrite(write_little_endian(1, buf, 2), 2, 1, s->fid);
    189190
    190191  // NumChannels
    191   written += fwrite(write_little_endian(s->channels, buf, 2), 2, 1, s->fid);
     192  fwrite(write_little_endian(s->channels, buf, 2), 2, 1, s->fid);
    192193
    193194  // SampleRate
    194   written += fwrite(write_little_endian(s->samplerate, buf, 4), 4, 1, s->fid);
     195  fwrite(write_little_endian(s->samplerate, buf, 4), 4, 1, s->fid);
    195196
    196197  // ByteRate
    197198  byterate = s->samplerate * s->channels * s->bitspersample / 8;
    198   written += fwrite(write_little_endian(byterate, buf, 4), 4, 1, s->fid);
     199  fwrite(write_little_endian(byterate, buf, 4), 4, 1, s->fid);
    199200
    200201  // BlockAlign
    201202  blockalign = s->channels * s->bitspersample / 8;
    202   written += fwrite(write_little_endian(blockalign, buf, 2), 2, 1, s->fid);
     203  fwrite(write_little_endian(blockalign, buf, 2), 2, 1, s->fid);
    203204
    204205  // BitsPerSample
    205   written += fwrite(write_little_endian(s->bitspersample, buf, 2), 2, 1, s->fid);
     206  fwrite(write_little_endian(s->bitspersample, buf, 2), 2, 1, s->fid);
    206207
    207208  // Subchunk2ID
    208   written += fwrite("data", 4, 1, s->fid);
     209  fwrite("data", 4, 1, s->fid);
    209210
    210211  // Subchunk1Size (0 for now, actual size will be written in _close)
    211   written += fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);
    212 
    213   // fwrite(*, *, 1, s->fid) was called 13 times, check success
    214   if (written != 13 || fflush(s->fid)) {
    215     AUBIO_STRERR("sink_wavwrite: writing header to %s failed"
    216         " (wrote %d/%d, %s)\n", s->path, written, 13, errorstr);
    217     fclose(s->fid);
    218     s->fid = NULL;
    219     return AUBIO_FAIL;
    220   }
     212  fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);
    221213
    222214  s->scratch_size = s->max_size * s->channels;
     
    235227}
    236228
    237 static
    238 void aubio_sink_wavwrite_write_frames(aubio_sink_wavwrite_t *s, uint_t write)
    239 {
    240   uint_t written_frames = 0;
    241 
    242   written_frames = fwrite(s->scratch_data, 2 * s->channels, write, s->fid);
    243 
    244   if (written_frames != write) {
    245     AUBIO_STRERR("sink_wavwrite: trying to write %d frames to %s, but only %d"
    246         " could be written (%s)\n", write, s->path, written_frames, errorstr);
    247   }
    248   s->total_frames_written += written_frames;
    249 }
    250229
    251230void aubio_sink_wavwrite_do(aubio_sink_wavwrite_t *s, fvec_t * write_data, uint_t write){
    252   uint_t c = 0, i = 0;
     231  uint_t c = 0, i = 0, written_frames = 0;
    253232  uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path,
    254233      s->max_size, write_data->length, write);
     
    259238    }
    260239  }
    261 
    262   aubio_sink_wavwrite_write_frames(s, length);
     240  written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
     241
     242  if (written_frames != write) {
     243    AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
     244        "but only %d could be written\n", write, s->path, written_frames);
     245  }
     246  s->total_frames_written += written_frames;
     247  return;
    263248}
    264249
    265250void aubio_sink_wavwrite_do_multi(aubio_sink_wavwrite_t *s, fmat_t * write_data, uint_t write){
    266   uint_t c = 0, i = 0;
     251  uint_t c = 0, i = 0, written_frames = 0;
    267252
    268253  uint_t channels = aubio_sink_validate_input_channels("sink_wavwrite", s->path,
     
    276261    }
    277262  }
    278 
    279   aubio_sink_wavwrite_write_frames(s, length);
     263  written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
     264
     265  if (written_frames != write * s->channels) {
     266    AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
     267        "but only %d could be written\n", write, s->path, written_frames / s->channels);
     268  }
     269  s->total_frames_written += written_frames;
     270  return;
    280271}
    281272
     
    283274  uint_t data_size = s->total_frames_written * s->bitspersample * s->channels / 8;
    284275  unsigned char buf[5];
    285   size_t written = 0, err = 0;
    286276  if (!s->fid) return AUBIO_FAIL;
    287277  // ChunkSize
    288   err += fseek(s->fid, 4, SEEK_SET);
    289   written += fwrite(write_little_endian(data_size + 36, buf, 4), 4, 1, s->fid);
     278  fseek(s->fid, 4, SEEK_SET);
     279  fwrite(write_little_endian(data_size + 36, buf, 4), 4, 1, s->fid);
    290280  // Subchunk2Size
    291   err += fseek(s->fid, 40, SEEK_SET);
    292   written += fwrite(write_little_endian(data_size, buf, 4), 4, 1, s->fid);
    293   if (written != 2 || err != 0) {
    294     AUBIO_STRERR("sink_wavwrite: updating header of %s failed, expected %d"
    295         " write but got only %d (%s)\n", s->path, 2, written, errorstr);
    296   }
     281  fseek(s->fid, 40, SEEK_SET);
     282  fwrite(write_little_endian(data_size, buf, 4), 4, 1, s->fid);
    297283  // close file
    298284  if (fclose(s->fid)) {
    299     AUBIO_STRERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, errorstr);
     285    AUBIO_ERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, strerror(errno));
    300286  }
    301287  s->fid = NULL;
  • src/io/source.c

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

    rdfe6ab6 r868c6b8  
    2525#include "fvec.h"
    2626#include "fmat.h"
    27 #include "ioutils.h"
    2827#include "io/source_apple_audio.h"
    2928
     
    211210  uint_t c, v;
    212211  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);
    215212  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    216213
    217   length = MIN(loadedPackets, length);
    218 
    219   for (v = 0; v < length; v++) {
     214  for (v = 0; v < loadedPackets; v++) {
    220215    read_to->data[v] = 0.;
    221216    for (c = 0; c < s->channels; c++) {
     
    225220  }
    226221  // short read, fill with zeros
    227   aubio_source_pad_output(read_to, length);
    228 
    229   *read = (uint_t)length;
     222  if (loadedPackets < s->block_size) {
     223    for (v = loadedPackets; v < s->block_size; v++) {
     224      read_to->data[v] = 0.;
     225    }
     226  }
     227
     228  *read = (uint_t)loadedPackets;
     229  return;
    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);
    238234  UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
    239235  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    240236
    241   length = MIN(loadedPackets, length);
    242 
    243   for (v = 0; v < length; v++) {
    244     for (c = 0; c < channels; c++) {
     237  for (v = 0; v < loadedPackets; v++) {
     238    for (c = 0; c < read_to->height; c++) {
    245239      read_to->data[c][v] = data[ v * s->channels + c];
    246240    }
    247241  }
    248 
    249   aubio_source_pad_multi_output(read_to, s->channels, (uint_t)length);
    250 
    251   *read = (uint_t)length;
     242  // if read_data has more channels than the file
     243  if (read_to->height > s->channels) {
     244    // copy last channel to all additional channels
     245    for (v = 0; v < loadedPackets; v++) {
     246      for (c = s->channels; c < read_to->height; c++) {
     247        read_to->data[c][v] = data[ v * s->channels + (s->channels - 1)];
     248      }
     249    }
     250  }
     251  // short read, fill with zeros
     252  if (loadedPackets < s->block_size) {
     253    for (v = loadedPackets; v < s->block_size; v++) {
     254      for (c = 0; c < read_to->height; c++) {
     255        read_to->data[c][v] = 0.;
     256      }
     257    }
     258  }
     259
     260  *read = (uint_t)loadedPackets;
     261  return;
    252262}
    253263
     
    345355        "error in ExtAudioFileGetProperty (%s)\n", s->path,
    346356        getPrintableOSStatusError(errorstr, err));
    347     return 0;
     357    return err;
    348358  }
    349359  return (uint_t)fileLengthFrames;
  • src/io/source_avcodec.c

    rdfe6ab6 r868c6b8  
    3131#endif
    3232#include <libavutil/opt.h>
     33#include <stdlib.h>
    3334
    3435// determine whether we use libavformat from ffmpeg or from libav
     
    6061#include "fvec.h"
    6162#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 = NULL;
    123   AVCodecContext *avCodecCtx = NULL;
    124   AVFrame *avFrame = NULL;
     122  AVFormatContext *avFormatCtx = s->avFormatCtx;
     123  AVCodecContext *avCodecCtx = s->avCodecCtx;
     124  AVFrame *avFrame = s->avFrame;
    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: error while resampling %s (%d)\n",
    468         s->path, out_samples);
     466  if (out_samples <= 0) {
     467    AUBIO_WRN("source_avcodec: no sample found while converting frame (%s)\n",
     468        s->path);
    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
    475483  av_packet_unref(&avPacket);
    476484}
     
    481489  uint_t end = 0;
    482490  uint_t total_wrote = 0;
    483   uint_t length = aubio_source_validate_input_length("source_avcodec", s->path,
    484       s->hop_size, read_data->length);
    485   if (!s->avr || !s->avFormatCtx || !s->avCodecCtx) {
    486     AUBIO_ERR("source_avcodec: could not read from %s (file was closed)\n",
    487         s->path);
    488     *read= 0;
    489     return;
    490   }
    491   while (total_wrote < length) {
    492     end = MIN(s->read_samples - s->read_index, length - total_wrote);
     491  while (total_wrote < s->hop_size) {
     492    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
    493493    for (i = 0; i < end; i++) {
    494494      read_data->data[i + total_wrote] = 0.;
     
    500500    }
    501501    total_wrote += end;
    502     if (total_wrote < length) {
     502    if (total_wrote < s->hop_size) {
    503503      uint_t avcodec_read = 0;
    504504      aubio_source_avcodec_readframe(s, &avcodec_read);
     
    512512    }
    513513  }
    514 
    515   aubio_source_pad_output(read_data, total_wrote);
    516 
     514  if (total_wrote < s->hop_size) {
     515    for (i = total_wrote; i < s->hop_size; i++) {
     516      read_data->data[i] = 0.;
     517    }
     518  }
    517519  *read = total_wrote;
    518520}
     
    523525  uint_t end = 0;
    524526  uint_t total_wrote = 0;
    525   uint_t length = aubio_source_validate_input_length("source_avcodec", s->path,
    526       s->hop_size, read_data->length);
    527   uint_t channels = aubio_source_validate_input_channels("source_avcodec",
    528       s->path, s->input_channels, read_data->height);
    529   if (!s->avr || !s->avFormatCtx || !s->avCodecCtx) {
    530     AUBIO_ERR("source_avcodec: could not read from %s (file was closed)\n",
    531         s->path);
    532     *read= 0;
    533     return;
    534   }
    535   while (total_wrote < length) {
    536     end = MIN(s->read_samples - s->read_index, length - total_wrote);
    537     for (j = 0; j < channels; j++) {
     527  while (total_wrote < s->hop_size) {
     528    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     529    for (j = 0; j < read_data->height; j++) {
    538530      for (i = 0; i < end; i++) {
    539531        read_data->data[j][i + total_wrote] =
     
    542534    }
    543535    total_wrote += end;
    544     if (total_wrote < length) {
     536    if (total_wrote < s->hop_size) {
    545537      uint_t avcodec_read = 0;
    546538      aubio_source_avcodec_readframe(s, &avcodec_read);
     
    554546    }
    555547  }
    556 
    557   aubio_source_pad_multi_output(read_data, s->input_channels, total_wrote);
    558 
     548  if (total_wrote < s->hop_size) {
     549    for (j = 0; j < read_data->height; j++) {
     550      for (i = total_wrote; i < s->hop_size; i++) {
     551        read_data->data[j][i] = 0.;
     552      }
     553    }
     554  }
    559555  *read = total_wrote;
    560556}
     
    620616#ifdef HAVE_AVRESAMPLE
    621617    avresample_close( s->avr );
     618#elif defined(HAVE_SWRESAMPLE)
     619    swr_close ( s->avr );
     620#endif
    622621    av_free ( s->avr );
    623 #elif defined(HAVE_SWRESAMPLE)
    624     swr_close ( s->avr );
    625     swr_free ( &s->avr );
    626 #endif
    627622  }
    628623  s->avr = NULL;
  • src/io/source_sndfile.c

    rdfe6ab6 r868c6b8  
    2727#include "fvec.h"
    2828#include "fmat.h"
    29 #include "ioutils.h"
    3029#include "source_sndfile.h"
    3130
     
    171170  uint_t i,j, input_channels = s->input_channels;
    172171  /* read from file into scratch_data */
    173   uint_t length = aubio_source_validate_input_length("source_sndfile", s->path,
    174       s->hop_size, read_data->length);
    175   sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data,
    176       s->scratch_size);
    177   uint_t read_length = read_samples / s->input_channels;
     172  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
    178173
    179174  /* where to store de-interleaved data */
    180175  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 
    189176#ifdef HAVE_SAMPLERATE
    190177  if (s->ratio != 1) {
     
    193180#endif /* HAVE_SAMPLERATE */
    194181  {
    195     read_length = MIN(length, read_length);
    196182    ptr_data = read_data->data;
    197183  }
    198184
    199185  /* de-interleaving and down-mixing data  */
    200   for (j = 0; j < read_length; j++) {
     186  for (j = 0; j < read_samples / input_channels; j++) {
    201187    ptr_data[j] = 0;
    202188    for (i = 0; i < input_channels; i++) {
     
    212198#endif /* HAVE_SAMPLERATE */
    213199
    214   *read = MIN(length, (uint_t)FLOOR(s->ratio * read_length + .5));
    215 
    216   aubio_source_pad_output (read_data, *read);
     200  *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5);
     201
     202  if (*read < s->hop_size) {
     203    for (j = *read; j < s->hop_size; j++) {
     204      read_data->data[j] = 0;
     205    }
     206  }
    217207
    218208}
     
    221211  uint_t i,j, input_channels = s->input_channels;
    222212  /* do actual reading */
    223   uint_t length = aubio_source_validate_input_length("source_sndfile", s->path,
    224       s->hop_size, read_data->length);
    225   uint_t channels = aubio_source_validate_input_channels("source_sndfile",
    226       s->path, s->input_channels, read_data->height);
    227   sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data,
    228       s->scratch_size);
    229   uint_t read_length = read_samples / s->input_channels;
     213  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
    230214
    231215  /* where to store de-interleaved data */
    232216  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 
    241217#ifdef HAVE_SAMPLERATE
    242218  if (s->ratio != 1) {
     
    245221#endif /* HAVE_SAMPLERATE */
    246222  {
    247     read_length = MIN(read_length, length);
    248223    ptr_data = read_data->data;
    249224  }
    250225
    251   for (j = 0; j < read_length; j++) {
    252     for (i = 0; i < channels; i++) {
    253       ptr_data[i][j] = s->scratch_data[j * input_channels + i];
     226  if (read_data->height < input_channels) {
     227    // destination matrix has less channels than the file; copy only first
     228    // channels of the file, de-interleaving data
     229    for (j = 0; j < read_samples / input_channels; j++) {
     230      for (i = 0; i < read_data->height; i++) {
     231        ptr_data[i][j] = s->scratch_data[j * input_channels + i];
     232      }
     233    }
     234  } else {
     235    // destination matrix has as many or more channels than the file; copy each
     236    // channel from the file to the destination matrix, de-interleaving data
     237    for (j = 0; j < read_samples / input_channels; j++) {
     238      for (i = 0; i < input_channels; i++) {
     239        ptr_data[i][j] = s->scratch_data[j * input_channels + i];
     240      }
     241    }
     242  }
     243
     244  if (read_data->height > input_channels) {
     245    // destination matrix has more channels than the file; copy last channel
     246    // of the file to each additional channels, de-interleaving data
     247    for (j = 0; j < read_samples / input_channels; j++) {
     248      for (i = input_channels; i < read_data->height; i++) {
     249        ptr_data[i][j] = s->scratch_data[j * input_channels + (input_channels - 1)];
     250      }
    254251    }
    255252  }
     
    268265#endif /* HAVE_SAMPLERATE */
    269266
    270   *read = MIN(length, (uint_t)FLOOR(s->ratio * read_length + .5));
    271 
    272   aubio_source_pad_multi_output(read_data, input_channels, *read);
     267  *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5);
     268
     269  if (*read < s->hop_size) {
     270    for (i = 0; i < read_data->height; i++) {
     271      for (j = *read; j < s->hop_size; j++) {
     272        read_data->data[i][j] = 0.;
     273      }
     274    }
     275  }
     276
    273277}
    274278
  • src/io/source_wavread.c

    rdfe6ab6 r868c6b8  
    2525#include "fvec.h"
    2626#include "fmat.h"
    27 #include "ioutils.h"
    2827#include "source_wavread.h"
    2928
     29#include <errno.h>
     30
    3031#define AUBIO_WAVREAD_BUFSIZE 1024
    3132
    32 //#define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
     33#define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
    3334
    3435struct _aubio_source_wavread_t {
     
    99100  s->fid = fopen((const char *)path, "rb");
    100101  if (!s->fid) {
    101     AUBIO_STRERR("source_wavread: Failed opening %s (%s)\n", s->path, errorstr);
     102    AUBIO_ERR("source_wavread: Failed opening %s (System error: %s)\n", s->path, strerror(errno));
    102103    goto beach;
    103104  }
     
    132133    bytes_junk += read_little_endian(buf, 4);
    133134    if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) {
    134       AUBIO_STRERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n",
    135           s->path, errorstr);
     135      AUBIO_ERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n",
     136          s->path, strerror(errno));
    136137      goto beach;
    137138    }
     
    260261    bytes_junk += read_little_endian(buf, 4);
    261262    if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) {
    262       AUBIO_STRERR("source_wavread: could not seek past unknown chunk in %s (%s)\n",
    263           s->path, errorstr);
     263      AUBIO_ERR("source_wavread: could not seek past unknown chunk in %s (%s)\n",
     264          s->path, strerror(errno));
    264265      goto beach;
    265266    }
     
    347348  uint_t end = 0;
    348349  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);
    351350  if (s->fid == NULL) {
    352351    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     
    354353    return;
    355354  }
    356   while (total_wrote < length) {
    357     end = MIN(s->read_samples - s->read_index, length - total_wrote);
     355  while (total_wrote < s->hop_size) {
     356    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
    358357    for (i = 0; i < end; i++) {
    359358      read_data->data[i + total_wrote] = 0;
     
    364363    }
    365364    total_wrote += end;
    366     if (total_wrote < length) {
     365    if (total_wrote < s->hop_size) {
    367366      uint_t wavread_read = 0;
    368367      aubio_source_wavread_readframe(s, &wavread_read);
     
    376375    }
    377376  }
    378 
    379   aubio_source_pad_output (read_data, total_wrote);
    380 
     377  if (total_wrote < s->hop_size) {
     378    for (i = end; i < s->hop_size; i++) {
     379      read_data->data[i] = 0.;
     380    }
     381  }
    381382  *read = total_wrote;
    382383}
     
    386387  uint_t end = 0;
    387388  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);
    392389  if (s->fid == NULL) {
    393390    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     
    395392    return;
    396393  }
    397   while (total_wrote < length) {
    398     end = MIN(s->read_samples - s->read_index, length - total_wrote);
    399     for (j = 0; j < channels; j++) {
     394  while (total_wrote < s->hop_size) {
     395    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     396    for (j = 0; j < read_data->height; j++) {
    400397      for (i = 0; i < end; i++) {
    401398        read_data->data[j][i + total_wrote] = s->output->data[j][i];
     
    403400    }
    404401    total_wrote += end;
    405     if (total_wrote < length) {
     402    if (total_wrote < s->hop_size) {
    406403      uint_t wavread_read = 0;
    407404      aubio_source_wavread_readframe(s, &wavread_read);
     
    415412    }
    416413  }
    417 
    418   aubio_source_pad_multi_output(read_data, s->input_channels, total_wrote);
    419 
     414  if (total_wrote < s->hop_size) {
     415    for (j = 0; j < read_data->height; j++) {
     416      for (i = end; i < s->hop_size; i++) {
     417        read_data->data[j][i] = 0.;
     418      }
     419    }
     420  }
    420421  *read = total_wrote;
    421422}
     
    441442  ret = fseek(s->fid, s->seek_start + pos * s->blockalign, SEEK_SET);
    442443  if (ret != 0) {
    443     AUBIO_STRERR("source_wavread: could not seek %s at %d (%s)\n", s->path, pos, errorstr);
     444    AUBIO_ERR("source_wavread: could not seek %s at %d (%s)\n", s->path, pos, strerror(errno));
    444445    return AUBIO_FAIL;
    445446  }
     
    462463  }
    463464  if (fclose(s->fid)) {
    464     AUBIO_STRERR("source_wavread: could not close %s (%s)\n", s->path, errorstr);
     465    AUBIO_ERR("source_wavread: could not close %s (%s)\n", s->path, strerror(errno));
    465466    return AUBIO_FAIL;
    466467  }
  • tests/src/io/base-sink_custom.h

    rdfe6ab6 r868c6b8  
    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 
    157154  return run_on_default_source_and_sink(base_main);
    158155}
  • tests/src/io/base-source_custom.h

    rdfe6ab6 r868c6b8  
    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 
    10896  // seek to 0
    10997  if(aubio_source_custom_seek(s, 0)) return 1;
    11098
    11199  // 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);
    136100  aubio_source_custom_do_multi(s, mat, &read);
    137101  if (read != hop_size) return 1;
     
    142106  aubio_source_custom_close(s);
    143107
    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 
    152108  del_aubio_source_custom(s);
    153109  del_fmat(mat);
    154110  del_fvec(vec);
    155 
    156   // shouldn't crash on null (bypassed, only check del_aubio_source)
    157   // del_aubio_source_custom(NULL);
    158111
    159112  return run_on_default_source(base_main);
  • tests/src/io/test-sink.c

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

    rdfe6ab6 r868c6b8  
    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 
    10492  // seek to 0
    10593  if(aubio_source_seek(s, 0)) return 1;
    10694
    10795  // 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);
    13296  aubio_source_do_multi(s, mat, &read);
    13397  if (read != hop_size) return 1;
     
    138102  aubio_source_close(s);
    139103
    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 
    148104  del_aubio_source(s);
    149105  del_fmat(mat);
    150106  del_fvec(vec);
    151107
    152   // shouldn't crash on null
    153   del_aubio_source(NULL);
    154 
    155108  return run_on_default_source(main);
    156109}
  • tests/src/spectral/test-mfcc.c

    rdfe6ab6 r868c6b8  
    3434  aubio_mfcc_t *mfcc = 0;
    3535
    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
     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
    3939
    4040  if (!in || !fftgrain || !out) { err = 1; goto failure; }
  • tests/src/test-cvec.c

    rdfe6ab6 r868c6b8  
    44int main (void)
    55{
    6   uint_t i, window_size = 16;
    7   cvec_t * complex_vector = new_cvec(window_size);
    8   cvec_t * other_cvector = new_cvec(window_size);
     6  uint_t i, window_size = 16; // window size
     7  cvec_t * complex_vector = new_cvec (window_size); // input buffer
     8  uint_t rand_times = 4;
    99
    10   assert(cvec_norm_get_data(complex_vector) == complex_vector->norm);
    11   assert(cvec_phas_get_data(complex_vector) == complex_vector->phas);
    12   assert(complex_vector->length == window_size / 2 + 1);
     10  utils_init_random();
    1311
    14   // all elements are initialized to 0
     12  while (rand_times -- ) {
     13    // fill with random phas and norm
     14    for ( i = 0; i < complex_vector->length; i++ ) {
     15      complex_vector->norm[i] = ( 2. / RAND_MAX * random() - 1. );
     16      complex_vector->phas[i] = ( 2. / RAND_MAX * random() - 1. ) * M_PI;
     17    }
     18    // print the vector
     19    cvec_print(complex_vector);
     20  }
     21
     22  // set all vector elements to `0`
     23  cvec_norm_zeros(complex_vector);
    1524  for ( i = 0; i < complex_vector->length; i++ ) {
    1625    assert( complex_vector->norm[i] == 0. );
    17     assert( complex_vector->phas[i] == 0. );
     26    // assert( complex_vector->phas[i] == 0 );
    1827  }
    19 
    20   cvec_norm_set_sample(complex_vector, 2., 1);
    21   assert(cvec_norm_get_sample(complex_vector, 1));
    22 
    23   cvec_phas_set_sample(complex_vector, 2., 1);
    24   assert(cvec_phas_get_sample(complex_vector, 1));
    25 
    2628  cvec_print(complex_vector);
    2729
    28   // set all norm and phas elements to 0
    29   cvec_zeros(complex_vector);
    30   for ( i = 0; i < complex_vector->length; i++ ) {
    31     assert( complex_vector->norm[i] == 0. );
    32     assert( complex_vector->phas[i] == 0. );
    33   }
    34 
    35   // set all norm elements to 1
     30  // set all vector elements to `1`
    3631  cvec_norm_ones(complex_vector);
    3732  for ( i = 0; i < complex_vector->length; i++ ) {
    3833    assert( complex_vector->norm[i] == 1. );
     34    // assert( complex_vector->phas[i] == 0 );
    3935  }
     36  cvec_print(complex_vector);
    4037
    41   // set all norm elements to 0
     38  cvec_zeros(complex_vector);
     39  cvec_phas_zeros(complex_vector);
    4240  cvec_norm_zeros(complex_vector);
    43   for ( i = 0; i < complex_vector->length; i++ ) {
    44     assert( complex_vector->norm[i] == 0. );
    45   }
     41  cvec_norm_ones(complex_vector);
     42  cvec_phas_ones(complex_vector);
     43  cvec_copy(complex_vector, complex_vector);
    4644
    47   // set all phas elements to 1
    48   cvec_phas_ones(complex_vector);
    49   for ( i = 0; i < complex_vector->length; i++ ) {
    50     assert( complex_vector->phas[i] == 1. );
    51   }
    52 
    53   // set all phas elements to 0
    54   cvec_phas_zeros(complex_vector);
    55   for ( i = 0; i < complex_vector->length; i++ ) {
    56     assert( complex_vector->phas[i] == 0. );
    57   }
    58 
    59   cvec_copy(complex_vector, other_cvector);
    60   // copy to self
    61   cvec_copy(complex_vector, complex_vector);
    62   // copy to a different size fails
    63   del_cvec(other_cvector);
    64   other_cvector = new_cvec(window_size + 2);
    65   cvec_copy(complex_vector, other_cvector);
    66 
    67   if (complex_vector)
    68     del_cvec(complex_vector);
    69   if (other_cvector)
    70     del_cvec(other_cvector);
    71 
    72   // wrong parameters
    73   assert(new_cvec(-1) == NULL);
    74   assert(new_cvec(0) == NULL);
    75 
     45  // destroy it
     46  del_cvec(complex_vector);
    7647  return 0;
    7748}
  • tests/src/test-fmat.c

    rdfe6ab6 r868c6b8  
    55// and j the column.
    66
    7 void assert_fmat_all_equal(fmat_t *mat, smpl_t scalar)
     7int main (void)
    88{
    9   uint_t i, j;
     9  uint_t height = 3, length = 9, i, j;
     10  // create fmat_t object
     11  fmat_t * mat = new_fmat (height, length);
    1012  for ( i = 0; i < mat->height; i++ ) {
    1113    for ( j = 0; j < mat->length; j++ ) {
    12       assert(mat->data[i][j] == scalar);
    13     }
    14   }
    15 }
    16 
    17 int main (void)
    18 {
    19   uint_t i, j;
    20   uint_t height = 3, length = 9;
    21 
    22   // create fmat_t object
    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++) {
    3414      // all elements are already initialized to 0.
    3515      assert(mat->data[i][j] == 0);
    3616      // setting element of row i, column j
    37       mat->data[i][j] = i * 10. + j;
     17      mat->data[i][j] = i * 1. + j *.1;
    3818    }
    3919  }
    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 
    6520  fvec_t channel_onstack;
    6621  fvec_t *channel = &channel_onstack;
    6722  fmat_get_channel(mat, 1, channel);
    68   assert(channel->data == mat->data[1]);
    69 
    70   // copy of the same size
    71   fmat_copy(mat, other_mat);
    72   del_fmat(other_mat);
    73 
    74   // copy to undersized
    75   other_mat = new_fmat(height - 1, length);
    76   fmat_copy(mat, other_mat);
    77   del_fmat(other_mat);
    78 
    79   // copy from undersized
    80   other_mat = new_fmat(height, length + 1);
    81   fmat_copy(mat, other_mat);
    82 
    83   // wrong parameters
    84   assert(new_fmat(-1, length) == NULL);
    85   assert(new_fmat(height, -1) == NULL);
    86 
    87   // methods for wrappers with opaque structure
    88   assert (fmat_get_channel_data(mat, 0) == mat->data[0]);
    89   assert (fmat_get_data(mat) == mat->data);
    90 
    91   if (mat)
    92     del_fmat(mat);
    93   if (other_mat)
    94     del_fmat(other_mat);
     23  fvec_print (channel);
     24  // print out matrix
     25  fmat_print(mat);
     26  // destroy it
     27  del_fmat(mat);
    9528  return 0;
    9629}
     30
  • tests/src/test-fvec.c

    rdfe6ab6 r868c6b8  
    22#include "utils_tests.h"
    33
    4 void assert_fvec_all_equal(fvec_t *vec, smpl_t scalar)
    5 {
    6   uint_t i;
    7   for (i = 0; i < vec->length; i++) {
    8     assert(vec->data[i] == scalar);
    9   }
    10 }
    11 
    124int main (void)
    135{
    14   uint_t length = 10;
    15   uint_t i;
    16 
    17   fvec_t * vec = new_fvec (length);
    18   fvec_t * other_vec = new_fvec (length);
    19 
    20   assert (vec);
    21   assert (other_vec);
     6  uint_t vec_size = 10, i;
     7  fvec_t * vec = new_fvec (vec_size);
    228
    239  // vec->length matches requested size
    24   assert(vec->length == length);
     10  assert(vec->length == vec_size);
    2511
    2612  // all elements are initialized to `0.`
     
    2915  }
    3016
     17  // all elements can be set to `0.`
     18  fvec_zeros(vec);
     19  for ( i = 0; i < vec->length; i++ ) {
     20    assert(vec->data[i] == 0.);
     21  }
     22  fvec_print(vec);
     23
    3124  // all elements can be set to `1.`
    3225  fvec_ones(vec);
    33   assert_fvec_all_equal(vec, 1.);
    34 
    35   // all elements can be set to `0.`
    36   fvec_zeros(vec);
    37   assert_fvec_all_equal(vec, 0.);
     26  for ( i = 0; i < vec->length; i++ ) {
     27    assert(vec->data[i] == 1.);
     28  }
     29  fvec_print(vec);
    3830
    3931  // each element can be accessed directly
     
    4436  fvec_print(vec);
    4537
    46   fvec_set_sample(vec, 3, 2);
    47   assert(fvec_get_sample(vec, 2) == 3);
     38  // now destroys the vector
     39  del_fvec(vec);
    4840
    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 
    67   // now destroys the vector
    68   if (vec)
    69     del_fvec(vec);
    70   if (other_vec)
    71     del_fvec(other_vec);
    7241  return 0;
    7342}
     43
  • tests/src/test-lvec.c

    rdfe6ab6 r868c6b8  
    22#include "utils_tests.h"
    33
    4 void assert_lvec_all_equal(lvec_t *vec, lsmp_t scalar)
     4int main (void)
    55{
    6   uint_t i;
    7   for (i = 0; i < vec->length; i++) {
    8     assert(vec->data[i] == scalar);
    9   }
     6  uint_t win_s = 32; // window size
     7  lvec_t * sp = new_lvec (win_s); // input buffer
     8  lvec_set_sample (sp, 2./3., 0);
     9  PRINT_MSG(AUBIO_LSMP_FMT "\n", lvec_get_sample (sp, 0));
     10  lvec_print (sp);
     11  lvec_ones (sp);
     12  lvec_print (sp);
     13  lvec_set_all (sp, 3./5.);
     14  lvec_print (sp);
     15  del_lvec(sp);
     16  return 0;
    1017}
    1118
    12 int main (void)
    13 {
    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 
    46   return 0;
    47 }
  • tests/src/test-mathutils-window.c

    rdfe6ab6 r868c6b8  
    88  uint_t lengths[4] = { 8, 10, 15, 16 };
    99  char *method = "default";
    10   char *window_types[11] = { "default",
    11     "ones", "rectangle", "hamming", "hanning", "hanningz",
     10  char *window_types[10] = { "default",
     11    "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);
    3329  return 0;
    3430}
  • wscript

    rdfe6ab6 r868c6b8  
    140140    ctx.check(header_name='math.h')
    141141    ctx.check(header_name='string.h')
    142     ctx.check(header_name='errno.h')
    143142    ctx.check(header_name='limits.h')
    144143    ctx.check(header_name='stdarg.h')
     
    631630    ctx.excl += ' **/.cache'
    632631    ctx.excl += ' **/**.zip **/**.tar.bz2'
    633     ctx.excl += ' **.tar.bz2**'
     632    ctx.excl += ' **.tar.bz2'
    634633    ctx.excl += ' **/doc/full/* **/doc/web/*'
    635634    ctx.excl += ' **/doc/full.cfg'
     
    643642    ctx.excl += ' **/.DS_Store'
    644643    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.