ref: cb0d7d08c80bfd1ca37329e6083e0ce3f0dd63ce
parent: 6e157df38d1a9acb48810660b7b8f1a9e7d87a7e
parent: d0f19a71ca5f83aa4e64de03faf4bafffea838ba
author: Paul Brossier <piem@piem.org>
date: Wed Dec 19 14:31:45 EST 2018
Merge branch 'feature/pitchshift' into feature/timestretch
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -75,4 +75,4 @@
test_script:
- "python python\\demos\\demo_create_test_sounds.py"
- - "nose2 --verbose"
+ - "pytest --verbose"
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -19,16 +19,16 @@
command: |
pip install --user dist/aubio*.whl
-test-nose2: &test-nose2
+test-pytest: &test-pytest
name: Test python wheel
command: |
make create_test_sounds
- PATH=/home/circleci/.local/bin:$PATH nose2 -v
+ PATH=/home/circleci/.local/bin:$PATH pytest -v
-test-nose2-nosounds: &test-nose2-nosounds
+test-pytest-nosounds: &test-pytest-nosounds
name: Test python wheel
command: |
- PATH=/home/circleci/.local/bin:$PATH nose2 -v
+ PATH=/home/circleci/.local/bin:$PATH pytest -v
uninstall-wheel: &uninstall-wheel
name: Uninstall python wheel
@@ -47,7 +47,7 @@
- run: *pip-install
- run: *build-wheel
- run: *install-wheel
- - run: *test-nose2
+ - run: *test-pytest
- run: *uninstall-wheel
- store_artifacts:
path: dist/
@@ -61,7 +61,7 @@
- run: *pip-install
- run: *build-wheel
- run: *install-wheel
- - run: *test-nose2
+ - run: *test-pytest
- run: *uninstall-wheel
- store_artifacts:
path: dist/
@@ -75,7 +75,7 @@
- run: *pip-install
- run: *build-wheel
- run: *install-wheel
- - run: *test-nose2
+ - run: *test-pytest
- run: *uninstall-wheel
- store_artifacts:
path: dist/
@@ -88,7 +88,7 @@
- run: *pip-install
- run: *build-wheel
- run: *install-wheel
- - run: *test-nose2-nosounds
+ - run: *test-pytest-nosounds
- run: *uninstall-wheel
- store_artifacts:
path: dist/
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,8 @@
# gcov generated files
*.gcno
*.gcda
+python/lib/aubio/_aubio.*.so
+.coverage
# ignore compiled examples
RE:examples/[a-z]*
--- a/.travis.yml
+++ b/.travis.yml
@@ -88,6 +88,7 @@
- travis_retry make getwaf expandwaf deps_python
- which pip
- pip --version
+ - pip install coverage
script:
- make create_test_sounds
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -6,16 +6,14 @@
recursive-include waflib *.py
include Makefile wscript */wscript_build
include aubio.pc.in
-include nose2.cfg
include requirements.txt
include src/*.c src/*.h
include src/*/*.c src/*/*.h
include examples/*.c examples/*.h
-include tests/*.h tests/*/*.c tests/*/*/*.c
+recursive-include tests *.h *.c *.py
include python/ext/*.h
recursive-include python *.py
include python/README.md
-include python/tests/run_all_tests
include python/tests/eval_pitch
include python/tests/*.expected
include doc/*.txt doc/*.rst doc/*.cfg doc/Makefile doc/make.bat doc/conf.py
--- a/Makefile
+++ b/Makefile
@@ -35,8 +35,8 @@
DATAROOTDIR?=$(PREFIX)/share
MANDIR?=$(DATAROOTDIR)/man
-# default nose2 command
-NOSE2?=nose2 -N 4 --verbose
+# default python test command
+PYTEST?=pytest --verbose
SOX=sox
@@ -140,9 +140,7 @@
test_python: export PYTHONPATH=$(PYDESTDIR)/$(LIBDIR)
test_python: local_dylib
# run test with installed package
- # ./python/tests/run_all_tests --verbose
- # run with nose2, multiple processes
- $(NOSE2)
+ $(PYTEST)
clean_python:
./setup.py clean
@@ -253,7 +251,7 @@
# build and test python
pip install -v -e .
# run tests, with python coverage
- coverage run `which nose2`
+ coverage run `which pytest`
# capture coverage again
lcov $(LCOVOPTS) --capture --no-external --directory . \
--output-file build/coverage_python.info
--- /dev/null
+++ b/doc/py_analysis.rst
@@ -1,0 +1,15 @@
+.. currentmodule:: aubio
+.. default-domain:: py
+
+Analysis
+--------
+
+.. members of generated classes are not shown
+
+.. autoclass:: onset
+
+.. autoclass:: pitch
+
+.. autoclass:: tempo
+
+.. autoclass:: notes
--- /dev/null
+++ b/doc/py_spectral.rst
@@ -1,0 +1,34 @@
+.. currentmodule:: aubio
+.. default-domain:: py
+
+.. members of generated classes are not yet documented
+
+Spectral features
+-----------------
+
+This section contains the documentation for:
+
+- :class:`dct`
+- :class:`fft`
+- :class:`filterbank`
+- :class:`mfcc`
+- :class:`pvoc`
+- :class:`specdesc`
+- :class:`tss`
+
+.. autoclass:: dct
+
+.. autoclass:: fft
+ :members:
+
+.. autoclass:: filterbank
+ :members:
+
+.. autoclass:: mfcc
+
+.. autoclass:: pvoc
+ :members:
+
+.. autoclass:: specdesc
+
+.. autoclass:: tss
--- /dev/null
+++ b/doc/py_synth.rst
@@ -1,0 +1,9 @@
+.. currentmodule:: aubio
+.. default-domain:: py
+
+Synthesis
+---------
+
+.. autoclass:: sampler
+
+.. autoclass:: wavetable
--- /dev/null
+++ b/doc/py_temporal.rst
@@ -1,0 +1,8 @@
+.. currentmodule:: aubio
+.. default-domain:: py
+
+Digital filters
+---------------
+
+.. autoclass:: digital_filter
+ :members:
--- a/doc/python.rst
+++ b/doc/python.rst
@@ -30,6 +30,10 @@
py_datatypes
py_io
+ py_temporal
+ py_spectral
+ py_analysis
+ py_synth
py_utils
py_examples
--- a/doc/python_module.rst
+++ b/doc/python_module.rst
@@ -89,14 +89,15 @@
Python tests
------------
-A number of Python tests are provided in the `python tests`_. To run them,
-install `nose2`_ and run the script ``python/tests/run_all_tests``:
+A number of Python tests are provided in the `python/tests`_ folder. To run
+them, install `pytest`_ and run it from the aubio source directory:
.. code-block:: console
- $ pip install nose2
- $ ./python/tests/run_all_tests
+ $ pip install pytest
+ $ git clone https://git.aubio.org/aubio/aubio
+ $ cd aubio
+ $ pytest
-.. _demo_filter.py: https://github.com/aubio/aubio/blob/master/python/demos/demo_filter.py
-.. _python tests: https://github.com/aubio/aubio/blob/master/python/tests
-.. _nose2: https://github.com/nose-devs/nose2
+.. _python/tests: https://github.com/aubio/aubio/blob/master/python/tests
+.. _pytest: https://pytest.org
--- a/examples/aubiomfcc.c
+++ b/examples/aubiomfcc.c
@@ -68,7 +68,7 @@
goto beach;
}
- examples_common_process((aubio_process_func_t)process_block, process_print);
+ examples_common_process(process_block, process_print);
del_aubio_pvoc (pv);
del_cvec (fftgrain);
--- a/examples/aubionotes.c
+++ b/examples/aubionotes.c
@@ -90,7 +90,7 @@
}
}
- examples_common_process((aubio_process_func_t)process_block, process_print);
+ examples_common_process(process_block, process_print);
// send a last note off if required
if (lastmidi) {
--- a/examples/aubioonset.c
+++ b/examples/aubioonset.c
@@ -86,7 +86,7 @@
aubio_wavetable_set_freq ( wavetable, 2450.);
//aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff");
- examples_common_process((aubio_process_func_t)process_block, process_print);
+ examples_common_process(process_block, process_print);
// send a last note off
if (usejack) {
--- a/examples/aubiopitch.c
+++ b/examples/aubiopitch.c
@@ -79,7 +79,7 @@
wavetable = new_aubio_wavetable (samplerate, hop_size);
aubio_wavetable_play ( wavetable );
- examples_common_process((aubio_process_func_t)process_block,process_print);
+ examples_common_process(process_block, process_print);
del_aubio_pitch (o);
del_aubio_wavetable (wavetable);
--- a/examples/aubioquiet.c
+++ b/examples/aubioquiet.c
@@ -55,7 +55,7 @@
verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
verbmsg ("buffer_size: %d, ", buffer_size);
verbmsg ("hop_size: %d\n", hop_size);
- examples_common_process((aubio_process_func_t)process_block,process_print);
+ examples_common_process(process_block, process_print);
examples_common_del();
return 0;
}
--- a/examples/aubiotrack.c
+++ b/examples/aubiotrack.c
@@ -87,7 +87,7 @@
aubio_wavetable_set_freq ( wavetable, 2450.);
//aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff");
- examples_common_process((aubio_process_func_t)process_block,process_print);
+ examples_common_process(process_block, process_print);
// send a last note off
if (usejack) {
--- a/nose2.cfg
+++ /dev/null
@@ -1,6 +1,0 @@
-[unittest]
-start-dir = python/tests/
-plugins = nose2.plugins.mp
-
-[multiprocess]
-always-on = false
--- a/python/README.md
+++ b/python/README.md
@@ -27,7 +27,7 @@
Demos
-----
-Some examples are available in the [`python/demos`][demos_dir] folder. Each
+Some examples are available in the [`python/demos` folder][demos_dir]. Each
script is a command line program which accepts one ore more argument.
**Notes**: installing additional modules is required to run some of the demos.
--- /dev/null
+++ b/python/ext/aubio-docstrings.h
@@ -1,0 +1,143 @@
+#define PYAUBIO_dct_doc \
+ "dct(size=1024)\n"\
+ "\n"\
+ "Compute Discrete Fourier Transorms of Type-II.\n"\
+ "\n"\
+ "Parameters\n"\
+ "----------\n"\
+ "size : int\n"\
+ " size of the DCT to compute\n"\
+ "\n"\
+ "Example\n"\
+ "-------\n"\
+ ">>> d = aubio.dct(16)\n"\
+ ">>> d.size\n"\
+ "16\n"\
+ ">>> x = aubio.fvec(np.ones(d.size))\n"\
+ ">>> d(x)\n"\
+ "array([4., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n"\
+ " dtype=float32)\n"\
+ ">>> d.rdo(d(x))\n"\
+ "array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n"\
+ " dtype=float32)\n"\
+ "\n"\
+ "References\n"\
+ "----------\n"\
+ "`DCT-II in Discrete Cosine Transform\n"\
+ "<https://en.wikipedia.org/wiki/Discrete_cosine_transform#DCT-II>`_\n"\
+ "on Wikipedia.\n"
+
+#define PYAUBIO_mfcc_doc \
+ "mfcc(buf_size=1024, n_filters=40, n_coeffs=13, samplerate=44100)\n"\
+ "\n"\
+ "Compute Mel Frequency Cepstrum Coefficients (MFCC).\n"\
+ "\n"\
+ "`mfcc` creates a callable which takes a `cvec` as input.\n"\
+ "\n"\
+ "If `n_filters = 40`, the filterbank will be initialized with\n"\
+ ":meth:`filterbank.set_mel_coeffs_slaney`. Otherwise, if `n_filters`\n"\
+ "is greater than `0`, it will be initialized with\n"\
+ ":meth:`filterbank.set_mel_coeffs` using `fmin = 0`,\n"\
+ "`fmax = samplerate/`.\n"\
+ "\n"\
+ "Example\n"\
+ "-------\n"\
+ ">>> buf_size = 2048; n_filters = 128; n_coeffs = 13; samplerate = 44100\n"\
+ ">>> mf = aubio.mfcc(buf_size, n_filters, n_coeffs, samplerate)\n"\
+ ">>> fftgrain = aubio.cvec(buf_size)\n"\
+ ">>> mf(fftgrain).shape\n"\
+ "(13,)\n"\
+ ""
+
+#define PYAUBIO_notes_doc \
+ "notes(method=\"default\", buf_size=1024, hop_size=512, samplerate=44100)\n"\
+ "\n"\
+ "Note detection\n"
+
+#define PYAUBIO_onset_doc \
+ "onset(method=\"default\", buf_size=1024, hop_size=512, samplerate=44100)\n"\
+ "\n"\
+ "Onset detection object. `method` should be one of method supported by\n"\
+ ":class:`specdesc`.\n"
+
+#define PYAUBIO_pitch_doc \
+ "pitch(method=\"default\", buf_size=1024, hop_size=512, samplerate=44100)\n"\
+ "\n"\
+ "Pitch detection.\n"\
+ "\n"\
+ "Supported methods: `yinfft`, `yin`, `yinfast`, `fcomb`, `mcomb`,\n"\
+ "`schmitt`, `specacf`, `default` (`yinfft`).\n"
+
+#define PYAUBIO_sampler_doc \
+ "sampler(hop_size=512, samplerate=44100)\n"\
+ "\n"\
+ "Sampler.\n"
+
+#define PYAUBIO_specdesc_doc \
+ "specdesc(method=\"default\", buf_size=1024)\n"\
+ "\n"\
+ "Spectral description functions. Creates a callable that takes a\n"\
+ ":class:`cvec` as input, typically created by :class:`pvoc` for\n"\
+ "overlap and windowing, and returns a single float.\n"\
+ "\n"\
+ "`method` can be any of the values listed below. If `default` is used\n"\
+ "the `hfc` function will be selected.\n"\
+ "\n"\
+ "Onset novelty functions:\n"\
+ "\n"\
+ "- `energy`: local energy,\n"\
+ "- `hfc`: high frequency content,\n"\
+ "- `complex`: complex domain,\n"\
+ "- `phase`: phase-based method,\n"\
+ "- `wphase`: weighted phase deviation,\n"\
+ "- `specdiff`: spectral difference,\n"\
+ "- `kl`: Kullback-Liebler,\n"\
+ "- `mkl`: modified Kullback-Liebler,\n"\
+ "- `specflux`: spectral flux.\n"\
+ "\n"\
+ "Spectral shape functions:\n"\
+ "\n"\
+ "- `centroid`: spectral centroid (barycenter of the norm vector),\n"\
+ "- `spread`: variance around centroid,\n"\
+ "- `skewness`: third order moment,\n"\
+ "- `kurtosis`: a measure of the flatness of the spectrum,\n"\
+ "- `slope`: decreasing rate of the amplitude,\n"\
+ "- `decrease`: perceptual based measurement of the decreasing rate,\n"\
+ "- `rolloff`: 95th energy percentile.\n"\
+ "\n"\
+ "Parameters\n"\
+ "----------\n"\
+ "method : str\n"\
+ " Onset novelty or spectral shape function.\n"\
+ "buf_size : int\n"\
+ " Length of the input frame.\n"\
+ "\n"\
+ "Example\n"\
+ "-------\n"\
+ ">>> win_s = 1024; hop_s = win_s // 2\n"\
+ ">>> pv = aubio.pvoc(win_s, hop_s)\n"\
+ ">>> sd = aubio.specdesc(\"mkl\", win_s)\n"\
+ ">>> sd(pv(aubio.fvec(hop_s))).shape\n"\
+ "(1,)\n"\
+ "\n"\
+ "References\n"\
+ "----------\n"\
+ "`Detailed description "\
+ "<https://aubio.org/doc/latest/specdesc_8h.html#details>`_ in\n"\
+ "`aubio API documentation <https://aubio.org/doc/latest/index.html>`_.\n"\
+ ""
+
+#define PYAUBIO_tempo_doc \
+ "tempo(method=\"default\", buf_size=1024, hop_size=512, samplerate=44100)\n"\
+ "\n"\
+ "Tempo detection and beat tracking.\n"
+
+#define PYAUBIO_tss_doc \
+ "tss(buf_size=1024, hop_size=512)\n"\
+ "\n"\
+ "Transient/Steady-state separation.\n"
+
+#define PYAUBIO_wavetable_doc \
+ "wavetable(samplerate=44100, hop_size=512)\n"\
+ "\n"\
+ "Wavetable synthesis.\n"
--- a/python/ext/aubio-types.h
+++ b/python/ext/aubio-types.h
@@ -1,6 +1,7 @@
#include <Python.h>
#include <structmember.h>
+#include "aubio-docstrings.h"
#include "aubio-generated.h"
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
--- a/python/ext/aubiomodule.c
+++ b/python/ext/aubiomodule.c
@@ -223,7 +223,7 @@
}
// compute the function
- result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, fvec_alpha_norm (&vec, alpha));
+ result = PyFloat_FromDouble(fvec_alpha_norm (&vec, alpha));
if (result == NULL) {
return NULL;
}
@@ -319,7 +319,7 @@
}
// compute the function
- result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, aubio_zero_crossing_rate (&vec));
+ result = PyFloat_FromDouble(aubio_zero_crossing_rate (&vec));
if (result == NULL) {
return NULL;
}
--- a/python/ext/py-cvec.c
+++ b/python/ext/py-cvec.c
@@ -136,7 +136,7 @@
goto fail;
}
- args = Py_BuildValue ("I", self->length);
+ args = PyLong_FromLong(self->length);
if (args == NULL) {
goto fail;
}
--- a/python/ext/py-fft.c
+++ b/python/ext/py-fft.c
@@ -1,6 +1,24 @@
#include "aubio-types.h"
-static char Py_fft_doc[] = "fft object";
+static char Py_fft_doc[] = ""
+"fft(size=1024)\n"
+"\n"
+"Compute Fast Fourier Transorms.\n"
+"\n"
+"Parameters\n"
+"----------\n"
+"size : int\n"
+" size of the FFT to compute\n"
+"\n"
+"Example\n"
+"-------\n"
+">>> x = aubio.fvec(512)\n"
+">>> f = aubio.fft(512)\n"
+">>> c = f(x); c\n"
+"aubio cvec of 257 elements\n"
+">>> x2 = f.rdo(c); x2.shape\n"
+"(512,)\n"
+"";
typedef struct
{
--- a/python/ext/py-filter.c
+++ b/python/ext/py-filter.c
@@ -10,8 +10,59 @@
fvec_t c_out;
} Py_filter;
-static char Py_filter_doc[] = "filter object";
+static char Py_filter_doc[] = ""
+"digital_filter(order=7)\n"
+"\n"
+"Create a digital filter.\n"
+"";
+static char Py_filter_set_c_weighting_doc[] = ""
+"set_c_weighting(samplerate)\n"
+"\n"
+"Set filter coefficients to C-weighting.\n"
+"\n"
+"`samplerate` should be one of 8000, 11025, 16000, 22050, 24000, 32000,\n"
+"44100, 48000, 88200, 96000, or 192000. `order` of the filter should be 5.\n"
+"\n"
+"Parameters\n"
+"----------\n"
+"samplerate : int\n"
+" Sampling-rate of the input signal, in Hz.\n"
+"";
+
+static char Py_filter_set_a_weighting_doc[] = ""
+"set_a_weighting(samplerate)\n"
+"\n"
+"Set filter coefficients to A-weighting.\n"
+"\n"
+"`samplerate` should be one of 8000, 11025, 16000, 22050, 24000, 32000,\n"
+"44100, 48000, 88200, 96000, or 192000. `order` of the filter should be 7.\n"
+"\n"
+"Parameters\n"
+"----------\n"
+"samplerate : int\n"
+" Sampling-rate of the input signal.\n"
+"";
+
+static char Py_filter_set_biquad_doc[] = ""
+"set_biquad(b0, b1, b2, a1, a2)\n"
+"\n"
+"Set biquad coefficients. `order` of the filter should be 3.\n"
+"\n"
+"Parameters\n"
+"----------\n"
+"b0 : float\n"
+" Forward filter coefficient.\n"
+"b1 : float\n"
+" Forward filter coefficient.\n"
+"b2 : float\n"
+" Forward filter coefficient.\n"
+"a1 : float\n"
+" Feedback filter coefficient.\n"
+"a2 : float\n"
+" Feedback filter coefficient.\n"
+"";
+
static PyObject *
Py_filter_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
{
@@ -156,11 +207,11 @@
static PyMethodDef Py_filter_methods[] = {
{"set_c_weighting", (PyCFunction) Py_filter_set_c_weighting, METH_VARARGS,
- "set filter coefficients to C-weighting"},
+ Py_filter_set_c_weighting_doc},
{"set_a_weighting", (PyCFunction) Py_filter_set_a_weighting, METH_VARARGS,
- "set filter coefficients to A-weighting"},
+ Py_filter_set_a_weighting_doc},
{"set_biquad", (PyCFunction) Py_filter_set_biquad, METH_VARARGS,
- "set b0, b1, b2, a1, a2 biquad coefficients"},
+ Py_filter_set_biquad_doc},
{NULL}
};
--- a/python/ext/py-filterbank.c
+++ b/python/ext/py-filterbank.c
@@ -1,7 +1,189 @@
#include "aubio-types.h"
-static char Py_filterbank_doc[] = "filterbank object";
+static char Py_filterbank_doc[] = ""
+"filterbank(n_filters=40, win_s=1024)\n"
+"\n"
+"Create a bank of spectral filters. Each instance is a callable\n"
+"that holds a matrix of coefficients.\n"
+"\n"
+"See also :meth:`set_mel_coeffs`, :meth:`set_mel_coeffs_htk`,\n"
+":meth:`set_mel_coeffs_slaney`, :meth:`set_triangle_bands`, and\n"
+":meth:`set_coeffs`.\n"
+"\n"
+"Parameters\n"
+"----------\n"
+"n_filters : int\n"
+" Number of filters to create.\n"
+"win_s : int\n"
+" Size of the input spectrum to process.\n"
+"\n"
+"Examples\n"
+"--------\n"
+">>> f = aubio.filterbank(128, 1024)\n"
+">>> f.set_mel_coeffs(44100, 0, 10000)\n"
+">>> c = aubio.cvec(1024)\n"
+">>> f(c).shape\n"
+"(128, )\n"
+"";
+static char Py_filterbank_set_triangle_bands_doc[] =""
+"set_triangle_bands(freqs, samplerate)\n"
+"\n"
+"Set triangular bands. The coefficients will be set to triangular\n"
+"overlapping windows using the boundaries specified by `freqs`.\n"
+"\n"
+"`freqs` should contain `n_filters + 2` frequencies in Hz, ordered\n"
+"by value, from smallest to largest. The first element should be greater\n"
+"or equal to zero; the last element should be smaller or equal to\n"
+"`samplerate / 2`.\n"
+"\n"
+"Parameters\n"
+"----------\n"
+"freqs: fvec\n"
+" List of frequencies, in Hz.\n"
+"samplerate : float\n"
+" Sampling-rate of the expected input.\n"
+"\n"
+"Example\n"
+"-------\n"
+">>> fb = aubio.filterbank(n_filters=100, win_s=2048)\n"
+">>> samplerate = 44100; freqs = np.linspace(0, 20200, 102)\n"
+">>> fb.set_triangle_bands(aubio.fvec(freqs), samplerate)\n"
+"";
+
+static char Py_filterbank_set_mel_coeffs_slaney_doc[] = ""
+"set_mel_coeffs_slaney(samplerate)\n"
+"\n"
+"Set coefficients of filterbank to match Slaney's Auditory Toolbox.\n"
+"\n"
+"The filter coefficients will be set as in Malcolm Slaney's\n"
+"implementation. The filterbank should have been created with\n"
+"`n_filters = 40`.\n"
+"\n"
+"This is approximately equivalent to using :meth:`set_mel_coeffs` with\n"
+"`fmin = 400./3., fmax = 6853.84`.\n"
+"\n"
+"Parameters\n"
+"----------\n"
+"samplerate : float\n"
+" Sampling-rate of the expected input.\n"
+"\n"
+"References\n"
+"----------\n"
+"\n"
+"Malcolm Slaney, `Auditory Toolbox Version 2, Technical Report #1998-010\n"
+"<https://engineering.purdue.edu/~malcolm/interval/1998-010/>`_\n"
+"";
+
+static char Py_filterbank_set_mel_coeffs_doc[] = ""
+"set_mel_coeffs(samplerate, fmin, fmax)\n"
+"\n"
+"Set coefficients of filterbank to linearly spaced mel scale.\n"
+"\n"
+"Parameters\n"
+"----------\n"
+"samplerate : float\n"
+" Sampling-rate of the expected input.\n"
+"fmin : float\n"
+" Lower frequency boundary of the first filter.\n"
+"fmax : float\n"
+" Upper frequency boundary of the last filter.\n"
+"\n"
+"See also\n"
+"--------\n"
+"hztomel\n"
+"";
+
+static char Py_filterbank_set_mel_coeffs_htk_doc[] = ""
+"set_mel_coeffs_htk(samplerate, fmin, fmax)\n"
+"\n"
+"Set coefficients of the filters to be linearly spaced in the HTK mel scale.\n"
+"\n"
+"Parameters\n"
+"----------\n"
+"samplerate : float\n"
+" Sampling-rate of the expected input.\n"
+"fmin : float\n"
+" Lower frequency boundary of the first filter.\n"
+"fmax : float\n"
+" Upper frequency boundary of the last filter.\n"
+"\n"
+"See also\n"
+"--------\n"
+"hztomel with `htk=True`\n"
+"";
+
+static char Py_filterbank_get_coeffs_doc[] = ""
+"get_coeffs()\n"
+"\n"
+"Get coefficients matrix of filterbank.\n"
+"\n"
+"Returns\n"
+"-------\n"
+"array_like\n"
+" Array of shape (n_filters, win_s/2+1) containing the coefficients.\n"
+"";
+
+static char Py_filterbank_set_coeffs_doc[] = ""
+"set_coeffs(coeffs)\n"
+"\n"
+"Set coefficients of filterbank.\n"
+"\n"
+"Parameters\n"
+"----------\n"
+"coeffs : fmat\n"
+" Array of shape (n_filters, win_s/2+1) containing the coefficients.\n"
+"";
+
+static char Py_filterbank_set_power_doc[] = ""
+"set_power(power)\n"
+"\n"
+"Set power applied to input spectrum of filterbank.\n"
+"\n"
+"Parameters\n"
+"----------\n"
+"power : float\n"
+" Power to raise input spectrum to before computing the filters.\n"
+"";
+
+static char Py_filterbank_get_power_doc[] = ""
+"get_power()\n"
+"\n"
+"Get power applied to filterbank.\n"
+"\n"
+"Returns\n"
+"-------\n"
+"float\n"
+" Power parameter.\n"
+"";
+
+static char Py_filterbank_set_norm_doc[] = ""
+"set_norm(norm)\n"
+"\n"
+"Set norm parameter. If set to `0`, the filters will not be normalized.\n"
+"If set to `1`, the filters will be normalized to one. Default to `1`.\n"
+"\n"
+"This function should be called *before* :meth:`set_triangle_bands`,\n"
+":meth:`set_mel_coeffs`, :meth:`set_mel_coeffs_htk`, or\n"
+":meth:`set_mel_coeffs_slaney`.\n"
+"\n"
+"Parameters\n"
+"----------\n"
+"norm : int\n"
+" `0` to disable, `1` to enable\n"
+"";
+
+static char Py_filterbank_get_norm_doc[] = ""
+"get_norm()\n"
+"\n"
+"Get norm parameter of filterbank.\n"
+"\n"
+"Returns\n"
+"-------\n"
+"float\n"
+" Norm parameter.\n"
+"";
+
typedef struct
{
PyObject_HEAD
@@ -289,6 +471,13 @@
}
static PyObject *
+Py_filterbank_get_power (Py_filterbank * self, PyObject *unused)
+{
+ smpl_t power = aubio_filterbank_get_power(self->o);
+ return (PyObject *)PyFloat_FromDouble (power);
+}
+
+static PyObject *
Py_filterbank_set_norm(Py_filterbank *self, PyObject *args)
{
smpl_t norm;
@@ -311,23 +500,34 @@
Py_RETURN_NONE;
}
+static PyObject *
+Py_filterbank_get_norm (Py_filterbank * self, PyObject *unused)
+{
+ smpl_t norm = aubio_filterbank_get_norm(self->o);
+ return (PyObject *)PyFloat_FromDouble (norm);
+}
+
static PyMethodDef Py_filterbank_methods[] = {
{"set_triangle_bands", (PyCFunction) Py_filterbank_set_triangle_bands,
- METH_VARARGS, "set coefficients of filterbanks"},
+ METH_VARARGS, Py_filterbank_set_triangle_bands_doc},
{"set_mel_coeffs_slaney", (PyCFunction) Py_filterbank_set_mel_coeffs_slaney,
- METH_VARARGS, "set coefficients of filterbank as in Auditory Toolbox"},
+ METH_VARARGS, Py_filterbank_set_mel_coeffs_slaney_doc},
{"set_mel_coeffs", (PyCFunction) Py_filterbank_set_mel_coeffs,
- METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"},
+ METH_VARARGS, Py_filterbank_set_mel_coeffs_doc},
{"set_mel_coeffs_htk", (PyCFunction) Py_filterbank_set_mel_coeffs_htk,
- METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"},
+ METH_VARARGS, Py_filterbank_set_mel_coeffs_htk_doc},
{"get_coeffs", (PyCFunction) Py_filterbank_get_coeffs,
- METH_NOARGS, "get coefficients of filterbank"},
+ METH_NOARGS, Py_filterbank_get_coeffs_doc},
{"set_coeffs", (PyCFunction) Py_filterbank_set_coeffs,
- METH_VARARGS, "set coefficients of filterbank"},
+ METH_VARARGS, Py_filterbank_set_coeffs_doc},
{"set_power", (PyCFunction) Py_filterbank_set_power,
- METH_VARARGS, "set power applied to filterbank input spectrum"},
+ METH_VARARGS, Py_filterbank_set_power_doc},
+ {"get_power", (PyCFunction) Py_filterbank_get_power,
+ METH_NOARGS, Py_filterbank_get_power_doc},
{"set_norm", (PyCFunction) Py_filterbank_set_norm,
- METH_VARARGS, "set norm applied to filterbank input spectrum"},
+ METH_VARARGS, Py_filterbank_set_norm_doc},
+ {"get_norm", (PyCFunction) Py_filterbank_get_norm,
+ METH_NOARGS, Py_filterbank_get_norm_doc},
{NULL}
};
--- a/python/ext/py-musicutils.c
+++ b/python/ext/py-musicutils.c
@@ -39,7 +39,7 @@
return NULL;
}
- level_lin = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_lin(&vec));
+ level_lin = PyFloat_FromDouble(aubio_level_lin(&vec));
if (level_lin == NULL) {
PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
return NULL;
@@ -67,7 +67,7 @@
return NULL;
}
- db_spl = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_db_spl(&vec));
+ db_spl = PyFloat_FromDouble(aubio_db_spl(&vec));
if (db_spl == NULL) {
PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
return NULL;
@@ -96,7 +96,7 @@
return NULL;
}
- silence_detection = Py_BuildValue("I", aubio_silence_detection(&vec, threshold));
+ silence_detection = PyLong_FromLong(aubio_silence_detection(&vec, threshold));
if (silence_detection == NULL) {
PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");
return NULL;
@@ -125,7 +125,7 @@
return NULL;
}
- level_detection = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_detection(&vec, threshold));
+ level_detection = PyFloat_FromDouble(aubio_level_detection(&vec, threshold));
if (level_detection == NULL) {
PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
return NULL;
@@ -194,9 +194,9 @@
return NULL;
}
if (htk != NULL && PyObject_IsTrue(htk) == 1)
- return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));
+ return PyFloat_FromDouble(aubio_hztomel_htk(v));
else
- return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel(v));
+ return PyFloat_FromDouble(aubio_hztomel(v));
}
PyObject*
@@ -211,9 +211,9 @@
return NULL;
}
if (htk != NULL && PyObject_IsTrue(htk) == 1)
- return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v));
+ return PyFloat_FromDouble(aubio_meltohz_htk(v));
else
- return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz(v));
+ return PyFloat_FromDouble(aubio_meltohz(v));
}
PyObject*
@@ -223,7 +223,7 @@
if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) {
return NULL;
}
- return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));
+ return PyFloat_FromDouble(aubio_hztomel_htk(v));
}
PyObject*
@@ -233,5 +233,5 @@
if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) {
return NULL;
}
- return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v));
+ return PyFloat_FromDouble(aubio_meltohz_htk(v));
}
--- a/python/lib/gen_code.py
+++ b/python/lib/gen_code.py
@@ -234,11 +234,21 @@
return out.format(do_inputs_list = do_inputs_list, **self.__dict__)
def gen_doc(self):
+ sig = []
+ for p in self.input_params:
+ name = p['name']
+ defval = aubiodefvalue[name].replace('"','\\\"')
+ sig.append("{name}={defval}".format(defval=defval, name=name))
out = """
-// TODO: add documentation
-static char Py_{shortname}_doc[] = \"undefined\";
+#ifndef PYAUBIO_{shortname}_doc
+#define PYAUBIO_{shortname}_doc "{shortname}({sig})"
+#endif /* PYAUBIO_{shortname}_doc */
+
+static char Py_{shortname}_doc[] = ""
+PYAUBIO_{shortname}_doc
+"";
"""
- return out.format(**self.__dict__)
+ return out.format(sig=', '.join(sig), **self.__dict__)
def gen_new(self):
out = """
--- a/python/tests/__init__.py
+++ /dev/null
@@ -1,1 +1,0 @@
-
--- /dev/null
+++ b/python/tests/_tools.py
@@ -1,0 +1,41 @@
+"""
+This file imports test methods from different testing modules, in this
+order:
+
+ - try importing 'pytest'
+ - if it fails, fallback to 'numpy.testing'
+
+Nose2 support was removed because of lacking assertWarns on py2.7.
+
+"""
+
+import sys
+
+_has_pytest = False
+
+# check if we have pytest
+try:
+ import pytest
+ parametrize = pytest.mark.parametrize
+ assert_raises = pytest.raises
+ assert_warns = pytest.warns
+ skipTest = pytest.skip
+ _has_pytest = True
+ def run_module_suite():
+ import sys, pytest
+ pytest.main(sys.argv)
+except:
+ pass
+
+# otherwise fallback on numpy.testing
+if not _has_pytest:
+ from numpy.testing import dec, assert_raises, assert_warns
+ from numpy.testing import SkipTest
+ parametrize = dec.parametrize
+ def skipTest(msg):
+ raise SkipTest(msg)
+ from numpy.testing import run_module_suite
+
+# always use numpy's assert_equal
+import numpy
+assert_equal = numpy.testing.assert_equal
--- a/python/tests/run_all_tests
+++ /dev/null
@@ -1,5 +1,0 @@
-#! /usr/bin/env python
-
-if __name__ == '__main__':
- import nose2.main
- nose2.discover()
--- a/python/tests/test_aubio.py
+++ b/python/tests/test_aubio.py
@@ -1,6 +1,5 @@
#! /usr/bin/env python
-from unittest import main
from numpy.testing import TestCase
class aubiomodule_test_case(TestCase):
@@ -15,5 +14,5 @@
self.assertEqual('0', aubio.version[0])
if __name__ == '__main__':
+ from unittest import main
main()
-
--- a/python/tests/test_aubio_cmd.py
+++ b/python/tests/test_aubio_cmd.py
@@ -1,8 +1,7 @@
#! /usr/bin/env python
-import aubio.cmd
-from nose2 import main
from numpy.testing import TestCase
+import aubio.cmd
class aubio_cmd(TestCase):
@@ -31,4 +30,5 @@
"3200\t")
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_aubio_cut.py
+++ b/python/tests/test_aubio_cut.py
@@ -1,7 +1,6 @@
#! /usr/bin/env python
import aubio.cut
-from nose2 import main
from numpy.testing import TestCase
class aubio_cut(TestCase):
@@ -13,4 +12,5 @@
assert self.a_parser.parse_args(['-v']).verbose
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_cvec.py
+++ b/python/tests/test_cvec.py
@@ -1,6 +1,5 @@
#! /usr/bin/env python
-from unittest import main
import numpy as np
from numpy.testing import TestCase, assert_equal
from aubio import cvec, fvec, float_type
@@ -141,4 +140,5 @@
a.norm = np.zeros((512//2+1, 2), dtype = float_type)
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_dct.py
+++ b/python/tests/test_dct.py
@@ -66,3 +66,7 @@
aubio.dct(size)
except AssertionError:
self.skipTest('creating aubio.dct with size %d did not fail' % size)
+
+if __name__ == '__main__':
+ from unittest import main
+ main()
--- a/python/tests/test_fft.py
+++ b/python/tests/test_fft.py
@@ -1,6 +1,5 @@
#! /usr/bin/env python
-from unittest import main
from numpy.testing import TestCase
from numpy.testing import assert_equal, assert_almost_equal
import numpy as np
@@ -212,4 +211,5 @@
fft(win_s)
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_filter.py
+++ b/python/tests/test_filter.py
@@ -1,9 +1,8 @@
#! /usr/bin/env python
-from unittest import main
from numpy.testing import TestCase, assert_equal, assert_almost_equal
from aubio import fvec, digital_filter
-from .utils import array_from_text_file
+from utils import array_from_text_file
class aubio_filter_test_case(TestCase):
@@ -94,4 +93,5 @@
digital_filter(-1)
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_filterbank.py
+++ b/python/tests/test_filterbank.py
@@ -4,7 +4,7 @@
from numpy.testing import TestCase, assert_equal, assert_almost_equal
from aubio import cvec, filterbank, float_type
-from .utils import array_from_text_file
+from utils import array_from_text_file
class aubio_filterbank_test_case(TestCase):
@@ -87,5 +87,5 @@
f(cvec(256))
if __name__ == '__main__':
- import nose2
- nose2.main()
+ from unittest import main
+ main()
--- a/python/tests/test_filterbank_mel.py
+++ b/python/tests/test_filterbank_mel.py
@@ -2,12 +2,10 @@
import numpy as np
from numpy.testing import TestCase, assert_equal, assert_almost_equal
+from _tools import assert_warns
from aubio import fvec, cvec, filterbank, float_type
-import warnings
-warnings.filterwarnings('ignore', category=UserWarning, append=True)
-
class aubio_filterbank_mel_test_case(TestCase):
def test_slaney(self):
@@ -75,8 +73,8 @@
samplerate = 22050
freq_list = [0, samplerate//4, samplerate // 2 + 1]
f = filterbank(len(freq_list)-2, 1024)
- # TODO add assert_warns
- f.set_triangle_bands(fvec(freq_list), samplerate)
+ with assert_warns(UserWarning):
+ f.set_triangle_bands(fvec(freq_list), samplerate)
def test_triangle_freqs_with_not_enough_filters(self):
"""make sure set_triangle_bands warns when not enough filters"""
@@ -83,8 +81,8 @@
samplerate = 22050
freq_list = [0, 100, 1000, 4000, 8000, 10000]
f = filterbank(len(freq_list)-3, 1024)
- # TODO add assert_warns
- f.set_triangle_bands(fvec(freq_list), samplerate)
+ with assert_warns(UserWarning):
+ f.set_triangle_bands(fvec(freq_list), samplerate)
def test_triangle_freqs_with_too_many_filters(self):
"""make sure set_triangle_bands warns when too many filters"""
@@ -91,8 +89,8 @@
samplerate = 22050
freq_list = [0, 100, 1000, 4000, 8000, 10000]
f = filterbank(len(freq_list)-1, 1024)
- # TODO add assert_warns
- f.set_triangle_bands(fvec(freq_list), samplerate)
+ with assert_warns(UserWarning):
+ f.set_triangle_bands(fvec(freq_list), samplerate)
def test_triangle_freqs_with_double_value(self):
"""make sure set_triangle_bands works with 2 duplicate freqs"""
@@ -99,8 +97,8 @@
samplerate = 22050
freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
f = filterbank(len(freq_list)-2, 1024)
- # TODO add assert_warns
- f.set_triangle_bands(fvec(freq_list), samplerate)
+ with assert_warns(UserWarning):
+ f.set_triangle_bands(fvec(freq_list), samplerate)
def test_triangle_freqs_with_triple(self):
"""make sure set_triangle_bands works with 3 duplicate freqs"""
@@ -107,9 +105,10 @@
samplerate = 22050
freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
f = filterbank(len(freq_list)-2, 1024)
- # TODO add assert_warns
- f.set_triangle_bands(fvec(freq_list), samplerate)
+ with assert_warns(UserWarning):
+ f.set_triangle_bands(fvec(freq_list), samplerate)
+
def test_triangle_freqs_without_norm(self):
"""make sure set_triangle_bands works without """
samplerate = 22050
@@ -168,5 +167,5 @@
if __name__ == '__main__':
- import nose2
- nose2.main()
+ from unittest import main
+ main()
--- a/python/tests/test_fvec.py
+++ b/python/tests/test_fvec.py
@@ -1,6 +1,5 @@
#! /usr/bin/env python
-from unittest import main
import numpy as np
from numpy.testing import TestCase, assert_equal, assert_almost_equal
from aubio import fvec, zero_crossing_rate, alpha_norm, min_removal
@@ -148,4 +147,5 @@
del c
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_fvec_shift.py
+++ b/python/tests/test_fvec_shift.py
@@ -30,6 +30,6 @@
def test_can_shift_fvec_odd(self):
self.run_shift_ishift(7)
-from unittest import main
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_hztomel.py
+++ b/python/tests/test_hztomel.py
@@ -3,6 +3,7 @@
from unittest import main
from numpy.testing import TestCase
from numpy.testing import assert_equal, assert_almost_equal
+from _tools import assert_warns
import numpy as np
import aubio
@@ -37,12 +38,12 @@
assert_almost_equal(meltohz(hztomel(f)) - f, 0, decimal=1)
def test_meltohz_negative(self):
- # TODO add assert_warns
- assert_equal(meltohz(-1), 0)
+ with assert_warns(UserWarning):
+ assert_equal(meltohz(-1), 0)
def test_hztomel_negative(self):
- # TODO add assert_warns
- assert_equal(hztomel(-1), 0)
+ with assert_warns(UserWarning):
+ assert_equal(hztomel(-1), 0)
class aubio_hztomel_htk_test_case(TestCase):
@@ -57,14 +58,16 @@
assert_almost_equal(hztomel(6300, htk=True), 2595., decimal=1)
def test_meltohz_negative(self):
- # TODO add assert_warns
- assert_equal(meltohz(-1, htk=True), 0)
+ with assert_warns(UserWarning):
+ assert_equal(meltohz(-1, htk=True), 0)
assert_almost_equal(meltohz(2000, htk=True), 3428.7, decimal=1)
assert_almost_equal(meltohz(1000, htk=True), 1000., decimal=1)
def test_hztomel_negative(self):
- # TODO add assert_warns
- assert_equal(hztomel(-1, htk=True), 0)
+ with assert_warns(UserWarning):
+ assert_equal(meltohz(-1, htk=True), 0)
+ with assert_warns(UserWarning):
+ assert_equal(hztomel(-1, htk=True), 0)
assert_almost_equal(hztomel(1000, htk=True), 1000., decimal=1)
def test_hztomel_htk(self):
--- a/python/tests/test_mathutils.py
+++ b/python/tests/test_mathutils.py
@@ -1,6 +1,5 @@
#! /usr/bin/env python
-from unittest import main
from numpy.testing import TestCase, assert_equal
from numpy import array, arange, isnan, isinf
from aubio import bintomidi, miditobin, freqtobin, bintofreq, freqtomidi, miditofreq
@@ -101,4 +100,5 @@
assert_equal ( array(b) < 0, False )
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_mfcc.py
+++ b/python/tests/test_mfcc.py
@@ -1,7 +1,6 @@
#! /usr/bin/env python
-from nose2 import main
-from nose2.tools import params
+from _tools import parametrize, assert_raises
from numpy import random, count_nonzero
from numpy.testing import TestCase
from aubio import mfcc, cvec, float_type
@@ -15,28 +14,21 @@
new_params = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
new_deflts = [1024, 40, 13, 44100]
-class aubio_mfcc(TestCase):
+class Test_aubio_mfcc(object):
- def setUp(self):
- self.o = mfcc()
+ members_args = 'name'
- def test_default_creation(self):
- pass
-
- def test_delete(self):
- del self.o
-
- @params(*new_params)
+ @parametrize(members_args, new_params)
def test_read_only_member(self, name):
- o = self.o
- with self.assertRaises((TypeError, AttributeError)):
+ o = mfcc()
+ with assert_raises((TypeError, AttributeError)):
setattr(o, name, 0)
- @params(*zip(new_params, new_deflts))
+ @parametrize('name, expected', zip(new_params, new_deflts))
def test_default_param(self, name, expected):
""" test mfcc.{:s} = {:d} """.format(name, expected)
- o = self.o
- self.assertEqual( getattr(o, name), expected)
+ o = mfcc()
+ assert getattr(o, name) == expected
class aubio_mfcc_wrong_params(TestCase):
@@ -82,9 +74,9 @@
#print coeffs
-class aubio_mfcc_all_parameters(TestCase):
+class Test_aubio_mfcc_all_parameters(object):
- @params(
+ run_values = [
(2048, 40, 13, 44100),
(1024, 40, 13, 44100),
(512, 40, 13, 44100),
@@ -100,7 +92,10 @@
#(1024, 30, 20, 44100),
(1024, 40, 40, 44100),
(1024, 40, 3, 44100),
- )
+ ]
+ run_args = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
+
+ @parametrize(run_args, run_values)
def test_run_with_params(self, buf_size, n_filters, n_coeffs, samplerate):
" check mfcc can run with reasonable parameters "
o = mfcc(buf_size, n_filters, n_coeffs, samplerate)
@@ -148,4 +143,5 @@
assert m.get_scale() == 1
if __name__ == '__main__':
- main()
+ from _tools import run_module_suite
+ run_module_suite()
--- a/python/tests/test_midi2note.py
+++ b/python/tests/test_midi2note.py
@@ -2,8 +2,7 @@
# -*- coding: utf-8 -*-
from aubio import midi2note
-from nose2.tools import params
-import unittest
+from _tools import parametrize, assert_raises
list_of_known_midis = (
( 0, 'C-1' ),
@@ -15,31 +14,31 @@
( 127, 'G9' ),
)
-class midi2note_good_values(unittest.TestCase):
+class Test_midi2note_good_values(object):
- @params(*list_of_known_midis)
+ @parametrize('midi, note', list_of_known_midis)
def test_midi2note_known_values(self, midi, note):
" known values are correctly converted "
- self.assertEqual ( midi2note(midi), note )
+ assert midi2note(midi) == (note)
-class midi2note_wrong_values(unittest.TestCase):
+class Test_midi2note_wrong_values(object):
def test_midi2note_negative_value(self):
" fails when passed a negative value "
- self.assertRaises(ValueError, midi2note, -2)
+ assert_raises(ValueError, midi2note, -2)
def test_midi2note_large(self):
" fails when passed a value greater than 127 "
- self.assertRaises(ValueError, midi2note, 128)
+ assert_raises(ValueError, midi2note, 128)
def test_midi2note_floating_value(self):
" fails when passed a floating point "
- self.assertRaises(TypeError, midi2note, 69.2)
+ assert_raises(TypeError, midi2note, 69.2)
def test_midi2note_character_value(self):
" fails when passed a value that can not be transformed to integer "
- self.assertRaises(TypeError, midi2note, "a")
+ assert_raises(TypeError, midi2note, "a")
if __name__ == '__main__':
- import nose2
- nose2.main()
+ from _tools import run_module_suite
+ run_module_suite()
--- a/python/tests/test_musicutils.py
+++ b/python/tests/test_musicutils.py
@@ -1,9 +1,8 @@
#! /usr/bin/env python
-from unittest import main
import numpy as np
from numpy.testing import TestCase
-from numpy.testing.utils import assert_equal, assert_almost_equal
+from numpy.testing import assert_equal, assert_almost_equal
from aubio import window, level_lin, db_spl, silence_detection, level_detection
from aubio import fvec, float_type
@@ -85,4 +84,5 @@
assert level_detection(ones(1024, dtype = float_type), -70) == 0
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_note2midi.py
+++ b/python/tests/test_note2midi.py
@@ -4,8 +4,8 @@
from __future__ import unicode_literals
from aubio import note2midi, freq2note, note2freq, float_type
-from nose2.tools import params
-import unittest
+from numpy.testing import TestCase
+from _tools import parametrize, assert_raises, skipTest
list_of_known_notes = (
( 'C-1', 0 ),
@@ -44,29 +44,32 @@
( '2' ),
)
-class note2midi_good_values(unittest.TestCase):
+class Test_note2midi_good_values(object):
- @params(*list_of_known_notes)
+ @parametrize('note, midi', list_of_known_notes)
def test_note2midi_known_values(self, note, midi):
" known values are correctly converted "
- self.assertEqual ( note2midi(note), midi )
+ assert note2midi(note) == midi
- @params(*list_of_known_notes_with_unicode_issues)
+ @parametrize('note, midi', list_of_known_notes_with_unicode_issues)
def test_note2midi_known_values_with_unicode_issues(self, note, midi):
- " known values are correctly converted, unless decoding is expected to fail"
+ " difficult values are correctly converted unless expected failure "
try:
- self.assertEqual ( note2midi(note), midi )
+ assert note2midi(note) == midi
except UnicodeEncodeError as e:
+ # platforms with decoding failures include:
+ # - osx: python <= 2.7.10
+ # - win: python <= 2.7.12
import sys
- strfmt = "len(u'\\U0001D12A') != 1, excpected decoding failure | {:s} | {:s} {:s}"
- strres = strfmt.format(e, sys.platform, sys.version)
- # happens with: darwin 2.7.10, windows 2.7.12
+ strmsg = "len(u'\\U0001D12A') != 1, expected decoding failure"
+ strmsg += " | upgrade to Python 3 to fix"
+ strmsg += " | {:s} | {:s} {:s}"
if len('\U0001D12A') != 1 and sys.version[0] == '2':
- self.skipTest(strres + " | upgrade to Python 3 to fix")
+ skipTest(strmsg.format(repr(e), sys.platform, sys.version))
else:
raise
-class note2midi_wrong_values(unittest.TestCase):
+class note2midi_wrong_values(TestCase):
def test_note2midi_missing_octave(self):
" fails when passed only one character"
@@ -104,12 +107,14 @@
" fails when passed a note with a note name longer than expected"
self.assertRaises(ValueError, note2midi, 'CB+-3')
- @params(*list_of_unknown_notes)
+class Test_note2midi_unknown_values(object):
+
+ @parametrize('note', list_of_unknown_notes)
def test_note2midi_unknown_values(self, note):
" unknown values throw out an error "
- self.assertRaises(ValueError, note2midi, note)
+ assert_raises(ValueError, note2midi, note)
-class freq2note_simple_test(unittest.TestCase):
+class freq2note_simple_test(TestCase):
def test_freq2note_above(self):
" make sure freq2note(441) == A4 "
@@ -119,7 +124,7 @@
" make sure freq2note(439) == A4 "
self.assertEqual("A4", freq2note(439))
-class note2freq_simple_test(unittest.TestCase):
+class note2freq_simple_test(TestCase):
def test_note2freq(self):
" make sure note2freq('A3') == 220"
@@ -133,5 +138,5 @@
self.assertLess(abs(note2freq("A4")-440), 1.e-12)
if __name__ == '__main__':
- import nose2
- nose2.main()
+ from _tools import run_module_suite
+ run_module_suite()
--- a/python/tests/test_notes.py
+++ b/python/tests/test_notes.py
@@ -1,9 +1,12 @@
#! /usr/bin/env python
-from unittest import main
from numpy.testing import TestCase, assert_equal, assert_almost_equal
-from aubio import notes
+from aubio import notes, source
+import numpy as np
+from utils import list_all_sounds
+list_of_sounds = list_all_sounds('sounds')
+
AUBIO_DEFAULT_NOTES_SILENCE = -70.
AUBIO_DEFAULT_NOTES_RELEASE_DROP = 10.
AUBIO_DEFAULT_NOTES_MINIOI_MS = 30.
@@ -52,14 +55,9 @@
with self.assertRaises(ValueError):
self.o.set_release_drop(val)
-from .utils import list_all_sounds
-list_of_sounds = list_all_sounds('sounds')
-
class aubio_notes_sinewave(TestCase):
def analyze_file(self, filepath, samplerate=0):
- from aubio import source
- import numpy as np
win_s = 512 # fft size
hop_s = 256 # hop size
@@ -92,4 +90,5 @@
assert_equal (results[0][1], [69, 123, -1])
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_onset.py
+++ b/python/tests/test_onset.py
@@ -1,6 +1,5 @@
#! /usr/bin/env python
-from unittest import main
from numpy.testing import TestCase, assert_equal, assert_almost_equal
from aubio import onset, fvec
@@ -116,4 +115,5 @@
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_phasevoc.py
+++ b/python/tests/test_phasevoc.py
@@ -1,9 +1,8 @@
#! /usr/bin/env python
from numpy.testing import TestCase, assert_equal, assert_array_less
+from _tools import parametrize
from aubio import fvec, cvec, pvoc, float_type
-from nose2 import main
-from nose2.tools import params
import numpy as np
if float_type == 'float32':
@@ -18,7 +17,7 @@
def create_noise(hop_s):
return np.random.rand(hop_s).astype(float_type) * 2. - 1.
-class aubio_pvoc_test_case(TestCase):
+class Test_aubio_pvoc_test_case(object):
""" pvoc object test case """
def test_members_automatic_sizes_default(self):
@@ -65,7 +64,8 @@
r = f.rdo(s)
assert_equal ( t, 0.)
- @params(
+ resynth_noise_args = "hop_s, ratio"
+ resynth_noise_values = [
( 256, 8),
( 256, 4),
( 256, 2),
@@ -87,13 +87,16 @@
(8192, 8),
(8192, 4),
(8192, 2),
- )
+ ]
+
+ @parametrize(resynth_noise_args, resynth_noise_values)
def test_resynth_steps_noise(self, hop_s, ratio):
""" check the resynthesis of a random signal is correct """
sigin = create_noise(hop_s)
self.reconstruction(sigin, hop_s, ratio)
- @params(
+ resynth_sine_args = "samplerate, hop_s, ratio, freq"
+ resynth_sine_values = [
(44100, 256, 8, 441),
(44100, 256, 4, 1203),
(44100, 256, 2, 3045),
@@ -108,7 +111,9 @@
(22050, 256, 8, 445),
(96000, 1024, 8, 47000),
(96000, 1024, 8, 20),
- )
+ ]
+
+ @parametrize(resynth_sine_args, resynth_sine_values)
def test_resynth_steps_sine(self, samplerate, hop_s, ratio, freq):
""" check the resynthesis of a sine is correct """
sigin = create_sine(hop_s, freq, samplerate)
@@ -199,5 +204,5 @@
self.skipTest('creating aubio.pvoc with size %d did not fail' % win_s)
if __name__ == '__main__':
+ from unittest import main
main()
-
--- a/python/tests/test_pitch.py
+++ b/python/tests/test_pitch.py
@@ -1,7 +1,6 @@
#! /usr/bin/env python
-from unittest import TestCase, main
-from numpy.testing import assert_equal
+from numpy.testing import TestCase, assert_equal
from numpy import sin, arange, mean, median, isnan, pi
from aubio import fvec, pitch, freqtomidi, float_type
@@ -116,10 +115,11 @@
for algo in pitch_algorithms:
for mode in signal_modes:
- test_method = create_test (algo, mode)
- test_method.__name__ = 'test_pitch_%s_%d_%d_%dHz_sin_%.0f' % ( algo,
+ _test_method = create_test (algo, mode)
+ _test_method.__name__ = 'test_pitch_%s_%d_%d_%dHz_sin_%.0f' % ( algo,
mode[0], mode[1], mode[2], mode[3] )
- setattr (aubio_pitch_Sinusoid, test_method.__name__, test_method)
+ setattr (aubio_pitch_Sinusoid, _test_method.__name__, _test_method)
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_sink.py
+++ b/python/tests/test_sink.py
@@ -1,14 +1,10 @@
#! /usr/bin/env python
-from nose2 import main
-from nose2.tools import params
from numpy.testing import TestCase
from aubio import fvec, source, sink
-from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
+from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
+from _tools import parametrize, skipTest, assert_raises
-import warnings
-warnings.filterwarnings('ignore', category=UserWarning, append=True)
-
list_of_sounds = list_all_sounds('sounds')
samplerates = [0, 44100, 8000, 32000]
hop_sizes = [512, 1024, 64]
@@ -23,30 +19,26 @@
for samplerate in samplerates:
all_params.append((hop_size, samplerate, soundfile))
-class aubio_sink_test_case(TestCase):
+class Test_aubio_sink(object):
- def setUp(self):
- if not len(list_of_sounds):
- self.skipTest('add some sound files in \'python/tests/sounds\'')
-
def test_wrong_filename(self):
- with self.assertRaises(RuntimeError):
+ with assert_raises(RuntimeError):
sink('')
def test_wrong_samplerate(self):
- with self.assertRaises(RuntimeError):
+ with assert_raises(RuntimeError):
sink(get_tmp_sink_path(), -1)
def test_wrong_samplerate_too_large(self):
- with self.assertRaises(RuntimeError):
+ with assert_raises(RuntimeError):
sink(get_tmp_sink_path(), 1536001, 2)
def test_wrong_channels(self):
- with self.assertRaises(RuntimeError):
+ with assert_raises(RuntimeError):
sink(get_tmp_sink_path(), 44100, -1)
def test_wrong_channels_too_large(self):
- with self.assertRaises(RuntimeError):
+ with assert_raises(RuntimeError):
sink(get_tmp_sink_path(), 44100, 202020)
def test_many_sinks(self):
@@ -66,13 +58,13 @@
g.close()
shutil.rmtree(tmpdir)
- @params(*all_params)
+ @parametrize('hop_size, samplerate, path', all_params)
def test_read_and_write(self, hop_size, samplerate, path):
-
try:
f = source(path, samplerate, hop_size)
except RuntimeError as e:
- self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
+ err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
+ skipTest(err_msg.format(str(e), hop_size, samplerate))
if samplerate == 0: samplerate = f.samplerate
sink_path = get_tmp_sink_path()
g = sink(sink_path, samplerate)
@@ -84,12 +76,13 @@
if read < f.hop_size: break
del_tmp_sink_path(sink_path)
- @params(*all_params)
+ @parametrize('hop_size, samplerate, path', all_params)
def test_read_and_write_multi(self, hop_size, samplerate, path):
try:
f = source(path, samplerate, hop_size)
except RuntimeError as e:
- self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
+ err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
+ skipTest(err_msg.format(str(e), hop_size, samplerate))
if samplerate == 0: samplerate = f.samplerate
sink_path = get_tmp_sink_path()
g = sink(sink_path, samplerate, channels = f.channels)
@@ -125,4 +118,5 @@
g(vec, 128)
if __name__ == '__main__':
- main()
+ from _tools import run_module_suite
+ run_module_suite()
--- a/python/tests/test_slicing.py
+++ b/python/tests/test_slicing.py
@@ -1,10 +1,9 @@
#! /usr/bin/env python
-from unittest import main
from numpy.testing import TestCase, assert_equal
from aubio import slice_source_at_stamps
-from .utils import count_files_in_directory, get_default_test_sound
-from .utils import count_samples_in_directory, count_samples_in_file
+from utils import count_files_in_directory, get_default_test_sound
+from utils import count_samples_in_directory, count_samples_in_file
import tempfile
import shutil
@@ -167,4 +166,5 @@
shutil.rmtree(self.output_dir)
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_source.py
+++ b/python/tests/test_source.py
@@ -1,19 +1,17 @@
#! /usr/bin/env python
-from nose2 import main
-from nose2.tools import params
+
from numpy.testing import TestCase, assert_equal
from aubio import source
-from .utils import list_all_sounds
+from utils import list_all_sounds
+import unittest
+from _tools import parametrize, assert_raises, assert_equal, skipTest
-import warnings
-warnings.filterwarnings('ignore', category=UserWarning, append=True)
-
list_of_sounds = list_all_sounds('sounds')
samplerates = [0, 44100, 8000, 32000]
hop_sizes = [512, 1024, 64]
-path = None
+default_test_sound = len(list_of_sounds) and list_of_sounds[0] or None
all_params = []
for soundfile in list_of_sounds:
@@ -21,17 +19,13 @@
for samplerate in samplerates:
all_params.append((hop_size, samplerate, soundfile))
+no_sounds_msg = "no test sounds, add some in 'python/tests/sounds/'!"
-class aubio_source_test_case_base(TestCase):
+_debug = False
- def setUp(self):
- if not len(list_of_sounds):
- self.skipTest('add some sound files in \'python/tests/sounds\'')
- self.default_test_sound = list_of_sounds[0]
+class Test_aubio_source_test_case(object):
-class aubio_source_test_case(aubio_source_test_case_base):
-
- @params(*list_of_sounds)
+ @parametrize('filename', list_of_sounds)
def test_close_file(self, filename):
samplerate = 0 # use native samplerate
hop_size = 256
@@ -38,7 +32,7 @@
f = source(filename, samplerate, hop_size)
f.close()
- @params(*list_of_sounds)
+ @parametrize('filename', list_of_sounds)
def test_close_file_twice(self, filename):
samplerate = 0 # use native samplerate
hop_size = 256
@@ -46,7 +40,7 @@
f.close()
f.close()
-class aubio_source_read_test_case(aubio_source_test_case_base):
+class Test_aubio_source_read(object):
def read_from_source(self, f):
total_frames = 0
@@ -56,40 +50,44 @@
if read < f.hop_size:
assert_equal(samples[read:], 0)
break
- #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"
- #result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri
- #print (result_str.format(*result_params))
+ if _debug:
+ result_str = "read {:.2f}s ({:d} frames"
+ result_str += " in {:d} blocks at {:d}Hz) from {:s}"
+ result_params = total_frames / float(f.samplerate), total_frames, \
+ total_frames//f.hop_size, f.samplerate, f.uri
+ print (result_str.format(*result_params))
return total_frames
- @params(*all_params)
+ @parametrize('hop_size, samplerate, soundfile', all_params)
def test_samplerate_hopsize(self, hop_size, samplerate, soundfile):
try:
f = source(soundfile, samplerate, hop_size)
except RuntimeError as e:
- self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
+ err_msg = 'failed opening with hop_s={:d}, samplerate={:d} ({:s})'
+ skipTest(err_msg.format(hop_size, samplerate, str(e)))
assert f.samplerate != 0
read_frames = self.read_from_source(f)
if 'f_' in soundfile and samplerate == 0:
import re
- f = re.compile('.*_\([0:9]*f\)_.*')
+ f = re.compile(r'.*_\([0:9]*f\)_.*')
match_f = re.findall('([0-9]*)f_', soundfile)
if len(match_f) == 1:
expected_frames = int(match_f[0])
- self.assertEqual(expected_frames, read_frames)
+ assert_equal(expected_frames, read_frames)
- @params(*list_of_sounds)
+ @parametrize('p', list_of_sounds)
def test_samplerate_none(self, p):
f = source(p)
assert f.samplerate != 0
self.read_from_source(f)
- @params(*list_of_sounds)
+ @parametrize('p', list_of_sounds)
def test_samplerate_0(self, p):
f = source(p, 0)
assert f.samplerate != 0
self.read_from_source(f)
- @params(*list_of_sounds)
+ @parametrize('p', list_of_sounds)
def test_zero_hop_size(self, p):
f = source(p, 0, 0)
assert f.samplerate != 0
@@ -96,7 +94,7 @@
assert f.hop_size != 0
self.read_from_source(f)
- @params(*list_of_sounds)
+ @parametrize('p', list_of_sounds)
def test_seek_to_half(self, p):
from random import randint
f = source(p, 0, 0)
@@ -108,7 +106,7 @@
b = self.read_from_source(f)
assert a == b + c
- @params(*list_of_sounds)
+ @parametrize('p', list_of_sounds)
def test_duration(self, p):
total_frames = 0
f = source(p)
@@ -117,43 +115,44 @@
_, read = f()
total_frames += read
if read < f.hop_size: break
- self.assertEqual(duration, total_frames)
+ assert_equal (duration, total_frames)
-class aubio_source_test_wrong_params(TestCase):
+class Test_aubio_source_wrong_params(object):
def test_wrong_file(self):
- with self.assertRaises(RuntimeError):
+ with assert_raises(RuntimeError):
source('path_to/unexisting file.mp3')
-class aubio_source_test_wrong_params_with_file(aubio_source_test_case_base):
+@unittest.skipIf(default_test_sound is None, no_sounds_msg)
+class Test_aubio_source_wrong_params_with_file(TestCase):
def test_wrong_samplerate(self):
- with self.assertRaises(ValueError):
- source(self.default_test_sound, -1)
+ with assert_raises(ValueError):
+ source(default_test_sound, -1)
def test_wrong_hop_size(self):
- with self.assertRaises(ValueError):
- source(self.default_test_sound, 0, -1)
+ with assert_raises(ValueError):
+ source(default_test_sound, 0, -1)
def test_wrong_channels(self):
- with self.assertRaises(ValueError):
- source(self.default_test_sound, 0, 0, -1)
+ with assert_raises(ValueError):
+ source(default_test_sound, 0, 0, -1)
def test_wrong_seek(self):
- f = source(self.default_test_sound)
- with self.assertRaises(ValueError):
+ f = source(default_test_sound)
+ with assert_raises(ValueError):
f.seek(-1)
def test_wrong_seek_too_large(self):
- f = source(self.default_test_sound)
+ f = source(default_test_sound)
try:
- with self.assertRaises(ValueError):
+ with assert_raises(ValueError):
f.seek(f.duration + f.samplerate * 10)
- except AssertionError:
- self.skipTest('seeking after end of stream failed raising ValueError')
+ except:
+ skipTest('seeking after end of stream failed raising ValueError')
-class aubio_source_readmulti_test_case(aubio_source_read_test_case):
+class Test_aubio_source_readmulti(Test_aubio_source_read):
def read_from_source(self, f):
total_frames = 0
@@ -163,15 +162,18 @@
if read < f.hop_size:
assert_equal(samples[:,read:], 0)
break
- #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"
- #result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri
- #print (result_str.format(*result_params))
+ if _debug:
+ result_str = "read {:.2f}s ({:d} frames in {:d} channels"
+ result_str += " and {:d} blocks at {:d}Hz) from {:s}"
+ result_params = total_frames / float(f.samplerate), total_frames, \
+ f.channels, int(total_frames/f.hop_size), \
+ f.samplerate, f.uri
+ print (result_str.format(*result_params))
return total_frames
-class aubio_source_with(aubio_source_test_case_base):
+class Test_aubio_source_with(object):
- #@params(*list_of_sounds)
- @params(*list_of_sounds)
+ @parametrize('filename', list_of_sounds)
def test_read_from_mono(self, filename):
total_frames = 0
hop_size = 2048
@@ -185,4 +187,5 @@
assert_equal(total_frames, input_source.duration)
if __name__ == '__main__':
- main()
+ from _tools import run_module_suite
+ run_module_suite()
--- a/python/tests/test_source_channels.py
+++ b/python/tests/test_source_channels.py
@@ -8,7 +8,7 @@
import aubio
import numpy as np
from numpy.testing import assert_equal
-from .utils import get_tmp_sink_path
+from utils import get_tmp_sink_path
class aubio_source_test_case(unittest.TestCase):
--- a/python/tests/test_specdesc.py
+++ b/python/tests/test_specdesc.py
@@ -1,6 +1,5 @@
#! /usr/bin/env python
-from unittest import main
from numpy.testing import TestCase, assert_equal, assert_almost_equal
from numpy import random, arange, log, zeros
from aubio import specdesc, cvec, float_type
@@ -229,4 +228,5 @@
specdesc("unknown", 512)
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/test_zero_crossing_rate.py
+++ b/python/tests/test_zero_crossing_rate.py
@@ -1,6 +1,5 @@
#! /usr/bin/env python
-from unittest import main
from numpy.testing import TestCase
from aubio import fvec, zero_crossing_rate
@@ -43,4 +42,5 @@
self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
if __name__ == '__main__':
+ from unittest import main
main()
--- a/python/tests/utils.py
+++ b/python/tests/utils.py
@@ -8,11 +8,8 @@
DEFAULT_SOUND = '22050Hz_5s_brownnoise.wav'
def array_from_text_file(filename, dtype = 'float'):
- filename = os.path.join(os.path.dirname(__file__), filename)
- with open(filename) as f:
- lines = f.readlines()
- return np.array([line.split() for line in lines],
- dtype = dtype)
+ realpathname = os.path.join(os.path.dirname(__file__), filename)
+ return np.loadtxt(realpathname, dtype = dtype)
def list_all_sounds(rel_dir):
datadir = os.path.join(os.path.dirname(__file__), rel_dir)
@@ -38,13 +35,10 @@
try:
os.unlink(path)
except WindowsError as e:
- print("deleting {:s} failed ({:s}), reopening".format(path, repr(e)))
- with open(path, 'wb') as f:
- f.close()
- try:
- os.unlink(path)
- except WindowsError as f:
- print("deleting {:s} failed ({:s}), aborting".format(path, repr(e)))
+ # removing the temporary directory sometimes fails on windows
+ import warnings
+ errmsg = "failed deleting temporary file {:s} ({:s})"
+ warnings.warn(UserWarning(errmsg.format(path, repr(e))))
def array_from_yaml_file(filename):
import yaml
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,2 @@
numpy
-nose2
+pytest
--- a/scripts/get_waf.sh
+++ b/scripts/get_waf.sh
@@ -3,7 +3,7 @@
set -e
#set -x
-WAFVERSION=2.0.12
+WAFVERSION=2.0.13
WAFTARBALL=waf-$WAFVERSION.tar.bz2
WAFURL=https://waf.io/$WAFTARBALL
WAFUPSTREAMKEY=https://gitlab.com/ita1024/waf/raw/master/utils/pubkey.asc
--- a/setup.py
+++ b/setup.py
@@ -95,8 +95,4 @@
'aubiocut = aubio.cut:main',
],
},
- test_suite = 'nose2.collector.collector',
- extras_require = {
- 'tests': ['numpy'],
- },
)
--- a/src/aubio_priv.h
+++ b/src/aubio_priv.h
@@ -367,4 +367,11 @@
#endif
#endif /* __STRICT_ANSI__ */
+#if defined(DEBUG)
+#include <assert.h>
+#define AUBIO_ASSERT(x) assert(x)
+#else
+#define AUBIO_ASSERT(x)
+#endif /* DEBUG */
+
#endif /* AUBIO_PRIV_H */
--- a/src/io/ioutils.c
+++ b/src/io/ioutils.c
@@ -51,3 +51,39 @@
}
return AUBIO_OK;
}
+
+uint_t
+aubio_sink_validate_input_length(const char_t *kind, const char_t *path,
+ uint_t max_size, uint_t write_data_length, uint_t write)
+{
+ uint_t can_write = write;
+
+ if (write > max_size) {
+ AUBIO_WRN("%s: partial write to %s, trying to write %d frames,"
+ " at most %d can be written at once\n", kind, path, write, max_size);
+ can_write = max_size;
+ }
+
+ if (can_write > write_data_length) {
+ AUBIO_WRN("%s: partial write to %s, trying to write %d frames,"
+ " but found input of length %d\n", kind, path, write,
+ write_data_length);
+ can_write = write_data_length;
+ }
+
+ return can_write;
+}
+
+uint_t
+aubio_sink_validate_input_channels(const char_t *kind, const char_t *path,
+ uint_t sink_channels, uint_t write_data_height)
+{
+ uint_t channels = sink_channels;
+ if (write_data_height < sink_channels) {
+ AUBIO_WRN("%s: partial write to %s, trying to write %d channels,"
+ " but found input of height %d\n", kind, path, sink_channels,
+ write_data_height);
+ channels = write_data_height;
+ }
+ return channels;
+}
--- a/src/io/ioutils.h
+++ b/src/io/ioutils.h
@@ -53,6 +53,33 @@
uint_t aubio_io_validate_channels(const char_t *kind, const char_t *path,
uint_t channels);
+/** validate length of input
+
+ \param kind the object kind to report on
+ \param path the path to report on
+ \param max_size maximum number of frames that can be written
+ \param write_data_length actual length of input vector/matrix
+ \param write number of samples asked
+
+ \return write or the maximum number of frames that can be written
+*/
+uint_t
+aubio_sink_validate_input_length(const char_t *kind, const char_t *path,
+ uint_t max_size, uint_t write_data_length, uint_t write);
+
+/** validate height of input
+
+ \param kind the object kind to report on
+ \param path the path to report on
+ \param max_size maximum number of channels that can be written
+ \param write_data_height actual height of input matrix
+
+ \return write_data_height or the maximum number of channels
+*/
+uint_t
+aubio_sink_validate_input_channels(const char_t *kind, const char_t *path,
+ uint_t sink_channels, uint_t write_data_height);
+
#ifdef __cplusplus
}
#endif
--- a/src/io/sink.c
+++ b/src/io/sink.c
@@ -102,7 +102,7 @@
!defined(HAVE_SINK_APPLE_AUDIO)
AUBIO_ERROR("sink: failed creating '%s' at %dHz (no sink built-in)\n", uri, samplerate);
#endif
- AUBIO_FREE(s);
+ del_aubio_sink(s);
return NULL;
}
@@ -135,8 +135,8 @@
}
void del_aubio_sink(aubio_sink_t * s) {
- if (!s) return;
- s->s_del((void *)s->sink);
+ AUBIO_ASSERT(s);
+ if (s->s_del && s->sink)
+ s->s_del((void *)s->sink);
AUBIO_FREE(s);
- return;
}
--- a/src/io/sink_apple_audio.c
+++ b/src/io/sink_apple_audio.c
@@ -31,9 +31,7 @@
// ExtAudioFileRef, AudioStreamBasicDescription, AudioBufferList, ...
#include <AudioToolbox/AudioToolbox.h>
-#define FLOAT_TO_SHORT(x) (short)(x * 32768)
-
-extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
+extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
extern void freeAudioBufferList(AudioBufferList *bufferList);
extern CFURLRef createURLFromPath(const char * path);
char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
@@ -61,11 +59,11 @@
s->max_frames = MAX_SIZE;
s->async = false;
- if ( (uri == NULL) || (strlen(uri) < 1) ) {
+ if ( (uri == NULL) || (strnlen(uri, PATH_MAX) < 1) ) {
AUBIO_ERROR("sink_apple_audio: Aborted opening null path\n");
goto beach;
}
- if (s->path != NULL) AUBIO_FREE(s->path);
+
s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1);
strncpy(s->path, uri, strnlen(uri, PATH_MAX) + 1);
@@ -76,6 +74,7 @@
if ((sint_t)samplerate == 0) {
return s;
}
+
// invalid samplerate given, abort
if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
goto beach;
@@ -91,7 +90,7 @@
return s;
beach:
- AUBIO_FREE(s);
+ del_aubio_sink_apple_audio(s);
return NULL;
}
@@ -102,7 +101,7 @@
}
s->samplerate = samplerate;
// automatically open when both samplerate and channels have been set
- if (s->samplerate != 0 && s->channels != 0) {
+ if (/* s->samplerate != 0 && */ s->channels != 0) {
return aubio_sink_apple_audio_open(s);
}
return AUBIO_OK;
@@ -115,7 +114,7 @@
}
s->channels = channels;
// automatically open when both samplerate and channels have been set
- if (s->samplerate != 0 && s->channels != 0) {
+ if (s->samplerate != 0 /* && s->channels != 0 */) {
return aubio_sink_apple_audio_open(s);
}
return AUBIO_OK;
@@ -150,6 +149,18 @@
AudioFileTypeID fileType = kAudioFileWAVEType;
CFURLRef fileURL = createURLFromPath(s->path);
bool overwrite = true;
+
+ // set the in-memory format
+ AudioStreamBasicDescription inputFormat;
+ memset(&inputFormat, 0, sizeof(AudioStreamBasicDescription));
+ inputFormat.mFormatID = kAudioFormatLinearPCM;
+ inputFormat.mSampleRate = (Float64)(s->samplerate);
+ inputFormat.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked;
+ inputFormat.mChannelsPerFrame = s->channels;
+ inputFormat.mBitsPerChannel = sizeof(smpl_t) * 8;
+ inputFormat.mFramesPerPacket = 1;
+ inputFormat.mBytesPerFrame = inputFormat.mBitsPerChannel * inputFormat.mChannelsPerFrame / 8;
+ inputFormat.mBytesPerPacket = inputFormat.mFramesPerPacket * inputFormat.mBytesPerFrame;
OSStatus err = noErr;
err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL,
overwrite ? kAudioFileFlags_EraseFile : 0, &s->audioFile);
@@ -161,7 +172,18 @@
getPrintableOSStatusError(errorstr, err));
goto beach;
}
- if (createAubioBufferList(&s->bufferList, s->channels, s->max_frames * s->channels)) {
+
+ err = ExtAudioFileSetProperty(s->audioFile,
+ kExtAudioFileProperty_ClientDataFormat,
+ sizeof(AudioStreamBasicDescription), &inputFormat);
+ if (err) {
+ char_t errorstr[20];
+ AUBIO_ERR("sink_apple_audio: error when trying to set output format on %s "
+ "(%s)\n", s->path, getPrintableOSStatusError(errorstr, err));
+ goto beach;
+ }
+
+ if (createAudioBufferList(&s->bufferList, s->channels, s->max_frames * s->channels)) {
AUBIO_ERR("sink_apple_audio: error when creating buffer list for %s, "
"out of memory? \n", s->path);
goto beach;
@@ -174,46 +196,42 @@
void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) {
UInt32 c, v;
- short *data = (short*)s->bufferList.mBuffers[0].mData;
- if (write > s->max_frames) {
- AUBIO_WRN("sink_apple_audio: trying to write %d frames, max %d\n", write, s->max_frames);
- write = s->max_frames;
- }
- smpl_t *buf = write_data->data;
+ smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
+ uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,
+ s->max_frames, write_data->length, write);
- if (buf) {
- for (c = 0; c < s->channels; c++) {
- for (v = 0; v < write; v++) {
- data[v * s->channels + c] =
- FLOAT_TO_SHORT(buf[ v * s->channels + c]);
- }
- }
+ for (c = 0; c < s->channels; c++) {
+ for (v = 0; v < length; v++) {
+ data[v * s->channels + c] = write_data->data[v];
+ }
}
- aubio_sink_apple_audio_write(s, write);
+
+ aubio_sink_apple_audio_write(s, length);
}
void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) {
UInt32 c, v;
- short *data = (short*)s->bufferList.mBuffers[0].mData;
- if (write > s->max_frames) {
- AUBIO_WRN("sink_apple_audio: trying to write %d frames, max %d\n", write, s->max_frames);
- write = s->max_frames;
- }
- smpl_t **buf = write_data->data;
+ smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
+ uint_t channels = aubio_sink_validate_input_channels("sink_apple_audio",
+ s->path, s->channels, write_data->height);
+ uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,
+ s->max_frames, write_data->length, write);
- if (buf) {
- for (c = 0; c < s->channels; c++) {
- for (v = 0; v < write; v++) {
- data[v * s->channels + c] =
- FLOAT_TO_SHORT(buf[c][v]);
- }
- }
+ for (c = 0; c < channels; c++) {
+ for (v = 0; v < length; v++) {
+ data[v * s->channels + c] = write_data->data[c][v];
+ }
}
- aubio_sink_apple_audio_write(s, write);
+
+ aubio_sink_apple_audio_write(s, length);
}
void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) {
OSStatus err = noErr;
+ // set mDataByteSize to match the number of frames to be written
+ // see https://www.mail-archive.com/coreaudio-api@lists.apple.com/msg01109.html
+ s->bufferList.mBuffers[0].mDataByteSize = write * s->channels
+ * sizeof(smpl_t);
if (s->async) {
err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
if (err) {
@@ -257,11 +275,13 @@
}
void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
- if (s->audioFile) aubio_sink_apple_audio_close (s);
- if (s->path) AUBIO_FREE(s->path);
+ AUBIO_ASSERT(s);
+ if (s->audioFile)
+ aubio_sink_apple_audio_close (s);
+ if (s->path)
+ AUBIO_FREE(s->path);
freeAudioBufferList(&s->bufferList);
AUBIO_FREE(s);
- return;
}
#endif /* HAVE_SINK_APPLE_AUDIO */
--- a/src/io/sink_sndfile.c
+++ b/src/io/sink_sndfile.c
@@ -58,10 +58,9 @@
if (path == NULL) {
AUBIO_ERR("sink_sndfile: Aborted opening null path\n");
- return NULL;
+ goto beach;
}
- if (s->path) AUBIO_FREE(s->path);
s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
@@ -97,7 +96,7 @@
}
s->samplerate = samplerate;
// automatically open when both samplerate and channels have been set
- if (s->samplerate != 0 && s->channels != 0) {
+ if (/* s->samplerate != 0 && */ s->channels != 0) {
return aubio_sink_sndfile_open(s);
}
return AUBIO_OK;
@@ -110,7 +109,7 @@
}
s->channels = channels;
// automatically open when both samplerate and channels have been set
- if (s->samplerate != 0 && s->channels != 0) {
+ if (s->samplerate != 0 /* && s->channels != 0 */) {
return aubio_sink_sndfile_open(s);
}
return AUBIO_OK;
@@ -147,8 +146,7 @@
s->scratch_size = s->max_size*s->channels;
/* allocate data for de/interleaving reallocated when needed. */
if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) {
- abort();
- AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n",
+ AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum buffer size %d\n",
s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS);
return AUBIO_FAIL;
}
@@ -158,24 +156,17 @@
}
void aubio_sink_sndfile_do(aubio_sink_sndfile_t *s, fvec_t * write_data, uint_t write){
- uint_t i, j, channels = s->channels;
- int nsamples = 0;
- smpl_t *pwrite;
+ uint_t i, j;
sf_count_t written_frames;
+ uint_t channels = s->channels;
+ uint_t length = aubio_sink_validate_input_length("sink_sndfile", s->path,
+ s->max_size, write_data->length, write);
+ int nsamples = channels * length;
- if (write > s->max_size) {
- AUBIO_WRN("sink_sndfile: trying to write %d frames, but only %d can be written at a time\n",
- write, s->max_size);
- write = s->max_size;
- }
-
- nsamples = channels * write;
-
/* interleaving data */
for ( i = 0; i < channels; i++) {
- pwrite = (smpl_t *)write_data->data;
- for (j = 0; j < write; j++) {
- s->scratch_data[channels*j+i] = pwrite[j];
+ for (j = 0; j < length; j++) {
+ s->scratch_data[channels*j+i] = write_data->data[j];
}
}
@@ -188,24 +179,18 @@
}
void aubio_sink_sndfile_do_multi(aubio_sink_sndfile_t *s, fmat_t * write_data, uint_t write){
- uint_t i, j, channels = s->channels;
- int nsamples = 0;
- smpl_t *pwrite;
+ uint_t i, j;
sf_count_t written_frames;
+ uint_t channels = aubio_sink_validate_input_channels("sink_sndfile", s->path,
+ s->channels, write_data->height);
+ uint_t length = aubio_sink_validate_input_length("sink_sndfile", s->path,
+ s->max_size, write_data->length, write);
+ int nsamples = channels * length;
- if (write > s->max_size) {
- AUBIO_WRN("sink_sndfile: trying to write %d frames, but only %d can be written at a time\n",
- write, s->max_size);
- write = s->max_size;
- }
-
- nsamples = channels * write;
-
/* interleaving data */
- for ( i = 0; i < write_data->height; i++) {
- pwrite = (smpl_t *)write_data->data[i];
- for (j = 0; j < write; j++) {
- s->scratch_data[channels*j+i] = pwrite[j];
+ for ( i = 0; i < channels; i++) {
+ for (j = 0; j < length; j++) {
+ s->scratch_data[channels*j+i] = write_data->data[i][j];
}
}
@@ -230,10 +215,13 @@
}
void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s){
- if (!s) return;
- if (s->path) AUBIO_FREE(s->path);
- aubio_sink_sndfile_close(s);
- AUBIO_FREE(s->scratch_data);
+ AUBIO_ASSERT(s);
+ if (s->handle)
+ aubio_sink_sndfile_close(s);
+ if (s->path)
+ AUBIO_FREE(s->path);
+ if (s->scratch_data)
+ AUBIO_FREE(s->scratch_data);
AUBIO_FREE(s);
}
--- a/src/io/sink_wavwrite.c
+++ b/src/io/sink_wavwrite.c
@@ -87,12 +87,7 @@
AUBIO_ERR("sink_wavwrite: Aborted opening null path\n");
goto beach;
}
- if ((sint_t)samplerate < 0) {
- AUBIO_ERR("sink_wavwrite: Can not create %s with samplerate %d\n", path, samplerate);
- goto beach;
- }
- if (s->path) AUBIO_FREE(s->path);
s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
@@ -135,7 +130,7 @@
}
s->samplerate = samplerate;
// automatically open when both samplerate and channels have been set
- if (s->samplerate != 0 && s->channels != 0) {
+ if (/* s->samplerate != 0 && */ s->channels != 0) {
return aubio_sink_wavwrite_open(s);
}
return AUBIO_OK;
@@ -148,7 +143,7 @@
}
s->channels = channels;
// automatically open when both samplerate and channels have been set
- if (s->samplerate != 0 && s->channels != 0) {
+ if (s->samplerate != 0 /* && s->channels != 0 */) {
return aubio_sink_wavwrite_open(s);
}
return AUBIO_OK;
@@ -233,19 +228,17 @@
void aubio_sink_wavwrite_do(aubio_sink_wavwrite_t *s, fvec_t * write_data, uint_t write){
- uint_t i = 0, written_frames = 0;
+ uint_t c = 0, i = 0, written_frames = 0;
+ uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path,
+ s->max_size, write_data->length, write);
- if (write > s->max_size) {
- AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
- "but only %d can be written at a time\n", write, s->path, s->max_size);
- write = s->max_size;
+ for (c = 0; c < s->channels; c++) {
+ for (i = 0; i < length; i++) {
+ s->scratch_data[i * s->channels + c] = HTOLES(FLOAT_TO_SHORT(write_data->data[i]));
+ }
}
+ written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
- for (i = 0; i < write; i++) {
- s->scratch_data[i] = HTOLES(FLOAT_TO_SHORT(write_data->data[i]));
- }
- written_frames = fwrite(s->scratch_data, 2, write, s->fid);
-
if (written_frames != write) {
AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
"but only %d could be written\n", write, s->path, written_frames);
@@ -257,18 +250,17 @@
void aubio_sink_wavwrite_do_multi(aubio_sink_wavwrite_t *s, fmat_t * write_data, uint_t write){
uint_t c = 0, i = 0, written_frames = 0;
- if (write > s->max_size) {
- AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
- "but only %d can be written at a time\n", write, s->path, s->max_size);
- write = s->max_size;
- }
+ uint_t channels = aubio_sink_validate_input_channels("sink_wavwrite", s->path,
+ s->channels, write_data->height);
+ uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path,
+ s->max_size, write_data->length, write);
- for (c = 0; c < s->channels; c++) {
- for (i = 0; i < write; i++) {
+ for (c = 0; c < channels; c++) {
+ for (i = 0; i < length; i++) {
s->scratch_data[i * s->channels + c] = HTOLES(FLOAT_TO_SHORT(write_data->data[c][i]));
}
}
- written_frames = fwrite(s->scratch_data, 2, write * s->channels, s->fid);
+ written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
if (written_frames != write * s->channels) {
AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
@@ -297,10 +289,13 @@
}
void del_aubio_sink_wavwrite(aubio_sink_wavwrite_t * s){
- if (!s) return;
- aubio_sink_wavwrite_close(s);
- if (s->path) AUBIO_FREE(s->path);
- AUBIO_FREE(s->scratch_data);
+ AUBIO_ASSERT(s);
+ if (s->fid)
+ aubio_sink_wavwrite_close(s);
+ if (s->path)
+ AUBIO_FREE(s->path);
+ if (s->scratch_data)
+ AUBIO_FREE(s->scratch_data);
AUBIO_FREE(s);
}
--- a/src/io/source.c
+++ b/src/io/source.c
@@ -121,7 +121,7 @@
AUBIO_ERROR("source: failed creating with %s at %dHz with hop size %d"
" (no source built-in)\n", uri, samplerate, hop_size);
#endif
- AUBIO_FREE(s);
+ del_aubio_source(s);
return NULL;
}
@@ -138,8 +138,9 @@
}
void del_aubio_source(aubio_source_t * s) {
- if (!s) return;
- s->s_del((void *)s->source);
+ AUBIO_ASSERT(s);
+ if (s->s_del && s->source)
+ s->s_del((void *)s->source);
AUBIO_FREE(s);
}
--- a/src/io/source.h
+++ b/src/io/source.h
@@ -59,7 +59,6 @@
A simple source to read from 16-bits PCM RIFF encoded WAV files.
\example io/test-source.c
- \example io/test-source_multi.c
*/
--- a/src/io/source_apple_audio.c
+++ b/src/io/source_apple_audio.c
@@ -34,8 +34,6 @@
#define RT_BYTE3( a ) ( ((a) >> 16) & 0xff )
#define RT_BYTE4( a ) ( ((a) >> 24) & 0xff )
-#define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
-
struct _aubio_source_apple_audio_t {
uint_t channels;
uint_t samplerate; //< requested samplerate
@@ -48,7 +46,7 @@
AudioBufferList bufferList;
};
-extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
+extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
extern void freeAudioBufferList(AudioBufferList *bufferList);
extern CFURLRef createURLFromPath(const char * path);
char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
@@ -59,7 +57,7 @@
{
aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t);
- if (path == NULL) {
+ if (path == NULL || strnlen(path, PATH_MAX) < 1) {
AUBIO_ERROR("source_apple_audio: Aborted opening null path\n");
goto beach;
}
@@ -85,7 +83,7 @@
return s;
beach:
- AUBIO_FREE(s);
+ del_aubio_source_apple_audio(s);
return NULL;
}
@@ -94,7 +92,6 @@
OSStatus err = noErr;
UInt32 propSize;
- if (s->path) AUBIO_FREE(s->path);
s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
@@ -139,17 +136,16 @@
s->channels = fileFormat.mChannelsPerFrame;
AudioStreamBasicDescription clientFormat;
- propSize = sizeof(clientFormat);
+ propSize = sizeof(AudioStreamBasicDescription);
memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription));
clientFormat.mFormatID = kAudioFormatLinearPCM;
clientFormat.mSampleRate = (Float64)(s->samplerate);
- clientFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
+ clientFormat.mFormatFlags = kAudioFormatFlagIsFloat;
clientFormat.mChannelsPerFrame = s->channels;
- clientFormat.mBitsPerChannel = sizeof(short) * 8;
+ clientFormat.mBitsPerChannel = sizeof(smpl_t) * 8;
clientFormat.mFramesPerPacket = 1;
clientFormat.mBytesPerFrame = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8;
clientFormat.mBytesPerPacket = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame;
- clientFormat.mReserved = 0;
// set the client format description
err = ExtAudioFileSetProperty(s->audioFile, kExtAudioFileProperty_ClientDataFormat,
@@ -187,7 +183,7 @@
// allocate the AudioBufferList
freeAudioBufferList(&s->bufferList);
- if (createAubioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {
+ if (createAudioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {
AUBIO_ERR("source_apple_audio: failed creating bufferList\n");
goto beach;
}
@@ -196,8 +192,9 @@
return err;
}
-void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to, uint_t * read) {
- UInt32 c, v, loadedPackets = s->block_size;
+static UInt32 aubio_source_apple_audio_read_frame(aubio_source_apple_audio_t *s)
+{
+ UInt32 loadedPackets = s->block_size;
OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
if (err) {
char_t errorstr[20];
@@ -204,52 +201,42 @@
AUBIO_ERROR("source_apple_audio: error while reading %s "
"with ExtAudioFileRead (%s)\n", s->path,
getPrintableOSStatusError(errorstr, err));
- goto beach;
}
+ return loadedPackets;
+}
- short *data = (short*)s->bufferList.mBuffers[0].mData;
+void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to,
+ uint_t * read) {
+ uint_t c, v;
+ UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
+ smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
- smpl_t *buf = read_to->data;
-
for (v = 0; v < loadedPackets; v++) {
- buf[v] = 0.;
+ read_to->data[v] = 0.;
for (c = 0; c < s->channels; c++) {
- buf[v] += SHORT_TO_FLOAT(data[ v * s->channels + c]);
+ read_to->data[v] += data[ v * s->channels + c];
}
- buf[v] /= (smpl_t)s->channels;
+ read_to->data[v] /= (smpl_t)s->channels;
}
// short read, fill with zeros
if (loadedPackets < s->block_size) {
for (v = loadedPackets; v < s->block_size; v++) {
- buf[v] = 0.;
+ read_to->data[v] = 0.;
}
}
*read = (uint_t)loadedPackets;
return;
-beach:
- *read = 0;
- return;
}
void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) {
- UInt32 c, v, loadedPackets = s->block_size;
- OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
- if (err) {
- char_t errorstr[20];
- AUBIO_ERROR("source_apple_audio: error while reading %s "
- "with ExtAudioFileRead (%s)\n", s->path,
- getPrintableOSStatusError(errorstr, err));
- goto beach;
- }
+ uint_t c, v;
+ UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
+ smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
- short *data = (short*)s->bufferList.mBuffers[0].mData;
-
- smpl_t **buf = read_to->data;
-
for (v = 0; v < loadedPackets; v++) {
for (c = 0; c < read_to->height; c++) {
- buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + c]);
+ read_to->data[c][v] = data[ v * s->channels + c];
}
}
// if read_data has more channels than the file
@@ -257,7 +244,7 @@
// copy last channel to all additional channels
for (v = 0; v < loadedPackets; v++) {
for (c = s->channels; c < read_to->height; c++) {
- buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + (s->channels - 1)]);
+ read_to->data[c][v] = data[ v * s->channels + (s->channels - 1)];
}
}
}
@@ -265,15 +252,13 @@
if (loadedPackets < s->block_size) {
for (v = loadedPackets; v < s->block_size; v++) {
for (c = 0; c < read_to->height; c++) {
- buf[c][v] = 0.;
+ read_to->data[c][v] = 0.;
}
}
}
+
*read = (uint_t)loadedPackets;
return;
-beach:
- *read = 0;
- return;
}
uint_t aubio_source_apple_audio_close (aubio_source_apple_audio_t *s)
@@ -293,11 +278,11 @@
}
void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){
+ AUBIO_ASSERT(s);
aubio_source_apple_audio_close (s);
if (s->path) AUBIO_FREE(s->path);
freeAudioBufferList(&s->bufferList);
AUBIO_FREE(s);
- return;
}
uint_t aubio_source_apple_audio_seek (aubio_source_apple_audio_t * s, uint_t pos) {
@@ -323,7 +308,7 @@
}
// after a short read, the bufferList size needs to resetted to prepare for a full read
AudioBufferList *bufferList = &s->bufferList;
- bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (short);
+ bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (smpl_t);
// do the actual seek
err = ExtAudioFileSeek(s->audioFile, resampled_pos);
if (err) {
--- a/src/io/source_avcodec.c
+++ b/src/io/source_avcodec.c
@@ -46,6 +46,10 @@
#define HAVE_AUBIO_LIBAVCODEC_DEPRECATED 1
#endif
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,3,102)
+#define HAVE_AUBIO_LIBAVCODEC_TIMEBASE_FIX 1
+#endif
+
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
#warning "libavcodec < 56 is deprecated"
#define av_frame_alloc avcodec_alloc_frame
@@ -143,7 +147,6 @@
s->hop_size = hop_size;
s->channels = 1;
- if (s->path) AUBIO_FREE(s->path);
s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
@@ -239,7 +242,12 @@
av_get_media_type_string(AVMEDIA_TYPE_AUDIO), s->path);
goto beach;
}
+#if HAVE_AUBIO_LIBAVCODEC_TIMEBASE_FIX
+ // avoids 'skipped frames warning' with avecodec < 58, deprecated after
+ av_codec_set_pkt_timebase(avCodecCtx,
+ avFormatCtx->streams[selected_stream]->time_base);
#endif
+#endif
if ( ( err = avcodec_open2(avCodecCtx, codec, NULL) ) < 0) {
char errorstr[256];
@@ -630,7 +638,7 @@
}
void del_aubio_source_avcodec(aubio_source_avcodec_t * s){
- if (!s) return;
+ AUBIO_ASSERT(s);
aubio_source_avcodec_close(s);
if (s->output != NULL) {
av_free(s->output);
--- a/src/io/source_sndfile.c
+++ b/src/io/source_sndfile.c
@@ -86,7 +86,6 @@
s->hop_size = hop_size;
s->channels = 1;
- if (s->path) AUBIO_FREE(s->path);
s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
@@ -331,7 +330,7 @@
}
void del_aubio_source_sndfile(aubio_source_sndfile_t * s){
- if (!s) return;
+ AUBIO_ASSERT(s);
aubio_source_sndfile_close(s);
#ifdef HAVE_SAMPLERATE
if (s->resamplers != NULL) {
--- a/src/io/source_wavread.c
+++ b/src/io/source_wavread.c
@@ -91,7 +91,6 @@
goto beach;
}
- if (s->path) AUBIO_FREE(s->path);
s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
@@ -471,7 +470,7 @@
}
void del_aubio_source_wavread(aubio_source_wavread_t * s) {
- if (!s) return;
+ AUBIO_ASSERT(s);
aubio_source_wavread_close(s);
if (s->short_output) AUBIO_FREE(s->short_output);
if (s->output) del_fmat(s->output);
--- a/src/io/utils_apple_audio.c
+++ b/src/io/utils_apple_audio.c
@@ -12,11 +12,12 @@
CFURLRef getURLFromPath(const char * path);
char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
-int createAubioBufferList(AudioBufferList * bufferList, int channels, int max_source_samples) {
+int createAudioBufferList(AudioBufferList * bufferList, int channels,
+ int max_source_samples) {
bufferList->mNumberBuffers = 1;
bufferList->mBuffers[0].mNumberChannels = channels;
- bufferList->mBuffers[0].mData = AUBIO_ARRAY(short, max_source_samples);
- bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(short);
+ bufferList->mBuffers[0].mData = AUBIO_ARRAY(smpl_t, max_source_samples);
+ bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(smpl_t);
return 0;
}
--- /dev/null
+++ b/tests/src/io/base-sink_custom.h
@@ -1,0 +1,167 @@
+// this should be included *after* custom functions have been defined
+
+#ifndef aubio_sink_custom
+#define aubio_sink_custom "undefined"
+#endif /* aubio_sink_custom */
+
+#ifdef HAVE_AUBIO_SINK_CUSTOM
+int test_wrong_params(void);
+
+int base_main(int argc, char **argv)
+{
+ uint_t err = 0;
+ if (argc < 3 || argc >= 6) {
+ PRINT_ERR("wrong number of arguments, running tests\n");
+ err = test_wrong_params();
+ PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n",
+ argv[0]);
+ return err;
+ }
+
+ uint_t samplerate = 0;
+ uint_t hop_size = 512;
+ uint_t n_frames = 0, read = 0;
+
+ char_t *source_path = argv[1];
+ char_t *sink_path = argv[2];
+
+ aubio_source_t *src = NULL;
+ aubio_sink_custom_t *snk = NULL;
+
+ if ( argc >= 4 ) samplerate = atoi(argv[3]);
+ if ( argc >= 5 ) hop_size = atoi(argv[4]);
+
+ fvec_t *vec = new_fvec(hop_size);
+ if (!vec) { err = 1; goto failure; }
+
+ src = new_aubio_source(source_path, samplerate, hop_size);
+ if (!src) { err = 1; goto failure; }
+ if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(src);
+
+ snk = new_aubio_sink_custom(sink_path, samplerate);
+ if (!snk) { err = 1; goto failure; }
+
+ do {
+ aubio_source_do(src, vec, &read);
+ aubio_sink_custom_do(snk, vec, read);
+ n_frames += read;
+ } while ( read == hop_size );
+
+ PRINT_MSG("%d frames at %dHz (%d blocks) read from %s, wrote to %s\n",
+ n_frames, samplerate, n_frames / hop_size,
+ source_path, sink_path);
+
+ // close sink now (optional)
+ aubio_sink_custom_close(snk);
+
+failure:
+ if (snk)
+ del_aubio_sink_custom(snk);
+ if (src)
+ del_aubio_source(src);
+ if (vec)
+ del_fvec(vec);
+
+ return err;
+}
+
+int test_wrong_params(void)
+{
+ fvec_t *vec;
+ fmat_t *mat;
+ aubio_sink_custom_t *s;
+ char_t sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
+ uint_t samplerate = 44100;
+ uint_t hop_size = 256;
+ uint_t oversized_hop_size = 4097;
+ uint_t oversized_samplerate = 192000 * 8 + 1;
+ uint_t channels = 3;
+ uint_t oversized_channels = 1025;
+ // create temp file
+ int fd = create_temp_sink(sink_path);
+
+ if (!fd) return 1;
+
+ if (new_aubio_sink_custom( 0, samplerate)) return 1;
+ if (new_aubio_sink_custom("\0", samplerate)) return 1;
+ if (new_aubio_sink_custom(sink_path, -1)) return 1;
+
+ s = new_aubio_sink_custom(sink_path, 0);
+
+ // check setting wrong parameters fails
+ if (!aubio_sink_custom_preset_samplerate(s, oversized_samplerate)) return 1;
+ if (!aubio_sink_custom_preset_channels(s, oversized_channels)) return 1;
+ if (!aubio_sink_custom_preset_channels(s, -1)) return 1;
+
+ // check setting valid parameters passes
+ if (aubio_sink_custom_preset_samplerate(s, samplerate)) return 1;
+ if (aubio_sink_custom_preset_channels(s, 1)) return 1;
+
+ // check writing a vector with valid length
+ vec = new_fvec(hop_size);
+ aubio_sink_custom_do(s, vec, hop_size);
+ // check writing more than in the input
+ aubio_sink_custom_do(s, vec, hop_size+1);
+ // check write 0 frames
+ aubio_sink_custom_do(s, vec, 0);
+ del_fvec(vec);
+
+ // check writing an oversized vector
+ vec = new_fvec(oversized_hop_size);
+ aubio_sink_custom_do(s, vec, oversized_hop_size);
+ del_fvec(vec);
+
+ // test delete without closing
+ del_aubio_sink_custom(s);
+
+ s = new_aubio_sink_custom(sink_path, 0);
+
+ // preset channels first
+ if (aubio_sink_custom_preset_channels(s, channels)) return 1;
+ if (aubio_sink_custom_preset_samplerate(s, samplerate)) return 1;
+
+ if (aubio_sink_custom_get_samplerate(s) != samplerate) return 1;
+ if (aubio_sink_custom_get_channels(s) != channels) return 1;
+
+ mat = new_fmat(channels, hop_size);
+ // check writing a vector with valid length
+ aubio_sink_custom_do_multi(s, mat, hop_size);
+ // check writing 0 frames
+ aubio_sink_custom_do_multi(s, mat, 0);
+ // check writing more than in the input
+ aubio_sink_custom_do_multi(s, mat, hop_size+1);
+ del_fmat(mat);
+
+ // check writing oversized input
+ mat = new_fmat(channels, oversized_hop_size);
+ aubio_sink_custom_do_multi(s, mat, oversized_hop_size);
+ del_fmat(mat);
+
+ // check writing undersized input
+ mat = new_fmat(channels - 1, hop_size);
+ aubio_sink_custom_do_multi(s, mat, hop_size);
+ del_fmat(mat);
+
+ aubio_sink_custom_close(s);
+ // test closing twice
+ aubio_sink_custom_close(s);
+
+ del_aubio_sink_custom(s);
+
+ // delete temp file
+ close_temp_sink(sink_path, fd);
+
+ return run_on_default_source_and_sink(base_main);
+}
+
+#else /* HAVE_AUBIO_SINK_CUSTOM */
+
+int base_main(int argc, char** argv)
+{
+ PRINT_ERR("aubio was not compiled with aubio_sink_"
+ aubio_sink_custom ", failed running %s with %d args\n",
+ argv[0], argc);
+ return 0;
+}
+
+#endif /* HAVE_AUBIO_SINK_CUSTOM */
--- /dev/null
+++ b/tests/src/io/base-source_custom.h
@@ -1,0 +1,125 @@
+// this should be included *after* custom functions have been defined
+
+#ifndef aubio_source_custom
+#define aubio_source_custom "undefined"
+#endif /* aubio_source_custom */
+
+#ifdef HAVE_AUBIO_SOURCE_CUSTOM
+int test_wrong_params(void);
+
+int base_main(int argc, char **argv)
+{
+ uint_t err = 0;
+ if (argc < 2) {
+ PRINT_ERR("not enough arguments, running tests\n");
+ err = test_wrong_params();
+ PRINT_MSG("read a wave file as a mono vector\n");
+ PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
+ PRINT_MSG("examples:\n");
+ PRINT_MSG(" - read file.wav at original samplerate\n");
+ PRINT_MSG(" %s file.wav\n", argv[0]);
+ PRINT_MSG(" - read file.wav at 32000Hz\n");
+ PRINT_MSG(" %s file.aif 32000\n", argv[0]);
+ PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
+ PRINT_MSG(" %s file.wav 0 4096 \n", argv[0]);
+ return err;
+ }
+
+ uint_t samplerate = 0;
+ uint_t hop_size = 256;
+ uint_t n_frames = 0, read = 0;
+ if ( argc >= 3 ) samplerate = atoi(argv[2]);
+ if ( argc >= 4 ) hop_size = atoi(argv[3]);
+
+ char_t *source_path = argv[1];
+
+ aubio_source_custom_t * s =
+ new_aubio_source_custom(source_path, samplerate, hop_size);
+ fvec_t *vec = new_fvec(hop_size);
+ if (!s || !vec) { err = 1; goto beach; }
+
+ uint_t n_frames_expected = aubio_source_custom_get_duration(s);
+
+ samplerate = aubio_source_custom_get_samplerate(s);
+
+ do {
+ aubio_source_custom_do(s, vec, &read);
+ fvec_print (vec);
+ n_frames += read;
+ } while ( read == hop_size );
+
+ PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
+ n_frames, n_frames_expected, samplerate, n_frames / hop_size,
+ source_path);
+
+ // close the file (optional)
+ aubio_source_custom_close(s);
+
+beach:
+ if (vec)
+ del_fvec(vec);
+ if (s)
+ del_aubio_source_custom(s);
+ return err;
+}
+
+int test_wrong_params(void)
+{
+ char_t *uri = DEFINEDSTRING(AUBIO_TESTS_SOURCE);
+ uint_t samplerate = 44100;
+ uint_t hop_size = 512;
+ uint_t channels, read = 0;
+ fvec_t *vec;
+ fmat_t *mat;
+ aubio_source_custom_t *s;
+
+ if (new_aubio_source_custom(0, samplerate, hop_size)) return 1;
+ if (new_aubio_source_custom("\0", samplerate, hop_size)) return 1;
+ if (new_aubio_source_custom(uri, -1, hop_size)) return 1;
+ if (new_aubio_source_custom(uri, 0, 0)) return 1;
+
+ s = new_aubio_source_custom(uri, samplerate, hop_size);
+ if (!s) return 1;
+ channels = aubio_source_custom_get_channels(s);
+
+ // vector to read downmixed samples
+ vec = new_fvec(hop_size);
+ // matrix to read individual channels
+ mat = new_fmat(channels, hop_size);
+
+ if (aubio_source_custom_get_samplerate(s) != samplerate) return 1;
+
+ // read first hop_size frames
+ aubio_source_custom_do(s, vec, &read);
+ if (read != hop_size) return 1;
+
+ // seek to 0
+ if(aubio_source_custom_seek(s, 0)) return 1;
+
+ // read again as multiple channels
+ aubio_source_custom_do_multi(s, mat, &read);
+ if (read != hop_size) return 1;
+
+ // close the file (optional)
+ aubio_source_custom_close(s);
+ // test closing the file a second time
+ aubio_source_custom_close(s);
+
+ del_aubio_source_custom(s);
+ del_fmat(mat);
+ del_fvec(vec);
+
+ return run_on_default_source(base_main);
+}
+
+#else /* HAVE_AUBIO_SOURCE_CUSTOM */
+
+int base_main(int argc, char** argv)
+{
+ PRINT_ERR("aubio was not compiled with aubio_source_"
+ aubio_source_custom ", failed running %s with %d args\n",
+ argv[0], argc);
+ return 0;
+}
+
+#endif /* HAVE_AUBIO_SOURCE_CUSTOM */
--- a/tests/src/io/test-sink-multi.c
+++ /dev/null
@@ -1,72 +1,0 @@
-#include <aubio.h>
-#include "utils_tests.h"
-
-// same as test-sink.c, but uses aubio_source_do_multi to read multiple
-// channels
-
-int main (int argc, char **argv)
-{
- sint_t err = 0;
-
- if (argc < 3) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source_and_sink(main);
- PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [channels] [hop_size]\n", argv[0]);
- return err;
- }
-
- uint_t samplerate = 0;
- uint_t channels = 0;
- uint_t hop_size = 512;
- uint_t n_frames = 0, read = 0;
-
- char_t *source_path = argv[1];
- char_t *sink_path = argv[2];
-
- if ( argc >= 4 ) samplerate = atoi(argv[3]);
- if ( argc >= 5 ) channels = atoi(argv[4]);
- if ( argc >= 6 ) hop_size = atoi(argv[5]);
- if ( argc >= 7 ) {
- err = 2;
- PRINT_ERR("too many arguments\n");
- return err;
- }
-
- aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
- if (!i) { err = 1; goto beach_source; }
-
- if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
- if (channels == 0 ) channels = aubio_source_get_channels(i);
-
- fmat_t *mat = new_fmat(channels, hop_size);
- if (!mat) { err = 1; goto beach_fmat; }
-
- aubio_sink_t *o = new_aubio_sink(sink_path, 0);
- if (!o) { err = 1; goto beach_sink; }
- err = aubio_sink_preset_samplerate(o, samplerate);
- if (err) { goto beach; }
- err = aubio_sink_preset_channels(o, channels);
- if (err) { goto beach; }
-
- do {
- aubio_source_do_multi(i, mat, &read);
- aubio_sink_do_multi(o, mat, read);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %d frames at %dHz in %d channels (%d blocks) from %s written to %s\n",
- n_frames, samplerate, channels, n_frames / hop_size,
- source_path, sink_path);
- PRINT_MSG("wrote %s with %dHz in %d channels\n", sink_path,
- aubio_sink_get_samplerate(o),
- aubio_sink_get_channels(o) );
-
-beach:
- del_aubio_sink(o);
-beach_sink:
- del_fmat(mat);
-beach_fmat:
- del_aubio_source(i);
-beach_source:
- return err;
-}
--- a/tests/src/io/test-sink.c
+++ b/tests/src/io/test-sink.c
@@ -1,14 +1,16 @@
#include <aubio.h>
#include "utils_tests.h"
-int main (int argc, char **argv)
-{
- sint_t err = 0;
+int test_wrong_params(void);
- if (argc < 3) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source_and_sink(main);
- PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
+int main(int argc, char **argv)
+{
+ uint_t err = 0;
+ if (argc < 3 || argc >= 6) {
+ PRINT_ERR("wrong number of arguments, running tests\n");
+ err = test_wrong_params();
+ PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n",
+ argv[0]);
return err;
}
@@ -19,40 +21,131 @@
char_t *source_path = argv[1];
char_t *sink_path = argv[2];
+ aubio_source_t *src = NULL;
+ aubio_sink_t *snk = NULL;
+
if ( argc >= 4 ) samplerate = atoi(argv[3]);
if ( argc >= 5 ) hop_size = atoi(argv[4]);
- if ( argc >= 6 ) {
- err = 2;
- PRINT_ERR("too many arguments\n");
- return err;
- }
fvec_t *vec = new_fvec(hop_size);
- if (!vec) { err = 1; goto beach_fvec; }
+ if (!vec) { err = 1; goto failure; }
- aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
- if (!i) { err = 1; goto beach_source; }
+ src = new_aubio_source(source_path, samplerate, hop_size);
+ if (!src) { err = 1; goto failure; }
+ if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(src);
- if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
+ snk = new_aubio_sink(sink_path, samplerate);
+ if (!snk) { err = 1; goto failure; }
- aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
- if (!o) { err = 1; goto beach_sink; }
-
do {
- aubio_source_do(i, vec, &read);
- aubio_sink_do(o, vec, read);
+ aubio_source_do(src, vec, &read);
+ aubio_sink_do(snk, vec, read);
n_frames += read;
} while ( read == hop_size );
- PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
+ PRINT_MSG("%d frames read at %dHz (%d blocks) from %s and written to %s\n",
n_frames, samplerate, n_frames / hop_size,
source_path, sink_path);
- del_aubio_sink(o);
-beach_sink:
- del_aubio_source(i);
-beach_source:
- del_fvec(vec);
-beach_fvec:
+ // close sink now (optional)
+ aubio_sink_close(snk);
+
+failure:
+ if (snk)
+ del_aubio_sink(snk);
+ if (src)
+ del_aubio_source(src);
+ if (vec)
+ del_fvec(vec);
+
return err;
+}
+
+int test_wrong_params(void)
+{
+ fvec_t *vec;
+ fmat_t *mat;
+ aubio_sink_t *s;
+ char_t sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
+ uint_t samplerate = 44100;
+ uint_t hop_size = 256;
+ uint_t oversized_hop_size = 4097;
+ uint_t oversized_samplerate = 192000 * 8 + 1;
+ uint_t channels = 3;
+ uint_t oversized_channels = 1025;
+ // create temp file
+ int fd = create_temp_sink(sink_path);
+
+ if (!fd) return 1;
+
+ if (new_aubio_sink( 0, samplerate)) return 1;
+ if (new_aubio_sink("\0", samplerate)) return 1;
+ if (new_aubio_sink(sink_path, -1)) return 1;
+
+ s = new_aubio_sink(sink_path, 0);
+
+ // check setting wrong parameters fails
+ if (!aubio_sink_preset_samplerate(s, oversized_samplerate)) return 1;
+ if (!aubio_sink_preset_channels(s, oversized_channels)) return 1;
+ if (!aubio_sink_preset_channels(s, -1)) return 1;
+
+ // check setting valid parameters passes
+ if (aubio_sink_preset_samplerate(s, samplerate)) return 1;
+ if (aubio_sink_preset_channels(s, 1)) return 1;
+
+ // check writing a vector with valid length
+ vec = new_fvec(hop_size);
+ aubio_sink_do(s, vec, hop_size);
+ // check writing more than in the input
+ aubio_sink_do(s, vec, hop_size+1);
+ // check write 0 frames
+ aubio_sink_do(s, vec, 0);
+ del_fvec(vec);
+
+ // check writing an oversized vector
+ vec = new_fvec(oversized_hop_size);
+ aubio_sink_do(s, vec, oversized_hop_size);
+ del_fvec(vec);
+
+ // test delete without closing
+ del_aubio_sink(s);
+
+ s = new_aubio_sink(sink_path, 0);
+
+ // preset channels first
+ if (aubio_sink_preset_channels(s, channels)) return 1;
+ if (aubio_sink_preset_samplerate(s, samplerate)) return 1;
+
+ if (aubio_sink_get_samplerate(s) != samplerate) return 1;
+ if (aubio_sink_get_channels(s) != channels) return 1;
+
+ mat = new_fmat(channels, hop_size);
+ // check writing a vector with valid length
+ aubio_sink_do_multi(s, mat, hop_size);
+ // check writing 0 frames
+ aubio_sink_do_multi(s, mat, 0);
+ // check writing more than in the input
+ aubio_sink_do_multi(s, mat, hop_size+1);
+ del_fmat(mat);
+
+ // check writing oversized input
+ mat = new_fmat(channels, oversized_hop_size);
+ aubio_sink_do_multi(s, mat, oversized_hop_size);
+ del_fmat(mat);
+
+ // check writing undersized input
+ mat = new_fmat(channels - 1, hop_size);
+ aubio_sink_do_multi(s, mat, hop_size);
+ del_fmat(mat);
+
+ aubio_sink_close(s);
+ // test closing twice
+ aubio_sink_close(s);
+
+ del_aubio_sink(s);
+
+ // delete temp file
+ close_temp_sink(sink_path, fd);
+
+ return run_on_default_source_and_sink(main);
}
--- a/tests/src/io/test-sink_apple_audio-multi.c
+++ /dev/null
@@ -1,78 +1,0 @@
-#define AUBIO_UNSTABLE 1
-#include <aubio.h>
-#include "utils_tests.h"
-
-// this file uses the unstable aubio api to test aubio_sink_apple_audio, please
-// use aubio_sink instead see src/io/sink.h and tests/src/sink/test-sink.c
-
-int main (int argc, char **argv)
-{
- sint_t err = 0;
-
- if (argc < 3) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source_and_sink(main);
- PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [channels] [hop_size]\n", argv[0]);
- return err;
- }
-
-#ifdef HAVE_SINK_APPLE_AUDIO
- uint_t samplerate = 0;
- uint_t channels = 0;
- uint_t hop_size = 512;
- uint_t n_frames = 0, read = 0;
-
- char_t *source_path = argv[1];
- char_t *sink_path = argv[2];
-
- if ( argc >= 4 ) samplerate = atoi(argv[3]);
- if ( argc >= 5 ) channels = atoi(argv[4]);
- if ( argc >= 6 ) hop_size = atoi(argv[5]);
- if ( argc >= 7 ) {
- err = 2;
- PRINT_ERR("too many arguments\n");
- return err;
- }
-
- aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
- if (!i) { err = 1; goto beach_source; }
-
- if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
- if (channels == 0 ) channels = aubio_source_get_channels(i);
-
- fmat_t *mat = new_fmat(channels, hop_size);
- if (!mat) { err = 1; goto beach_fmat; }
-
- aubio_sink_apple_audio_t *o = new_aubio_sink_apple_audio(sink_path, 0);
- if (!o) { err = 1; goto beach_sink; }
- err = aubio_sink_apple_audio_preset_samplerate(o, samplerate);
- if (err) { goto beach; }
- err = aubio_sink_apple_audio_preset_channels(o, channels);
- if (err) { goto beach; }
-
- do {
- aubio_source_do_multi(i, mat, &read);
- aubio_sink_apple_audio_do_multi(o, mat, read);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %d frames at %dHz in %d channels (%d blocks) from %s written to %s\n",
- n_frames, samplerate, channels, n_frames / hop_size,
- source_path, sink_path);
- PRINT_MSG("wrote %s with %dHz in %d channels\n", sink_path,
- aubio_sink_apple_audio_get_samplerate(o),
- aubio_sink_apple_audio_get_channels(o) );
-
-beach:
- del_aubio_sink_apple_audio(o);
-beach_sink:
- del_fmat(mat);
-beach_fmat:
- del_aubio_source(i);
-beach_source:
-#else /* HAVE_SINK_APPLE_AUDIO */
- err = 0;
- PRINT_ERR("aubio was not compiled with aubio_sink_apple_audio\n");
-#endif /* HAVE_SINK_APPLE_AUDIO */
- return err;
-}
--- a/tests/src/io/test-sink_apple_audio.c
+++ b/tests/src/io/test-sink_apple_audio.c
@@ -2,66 +2,28 @@
#include <aubio.h>
#include "utils_tests.h"
-// this file uses the unstable aubio api, please use aubio_sink instead
-// see src/io/sink.h and tests/src/sink/test-sink.c
+#define aubio_sink_custom "apple_audio"
-int main (int argc, char **argv)
-{
- sint_t err = 0;
-
- if (argc < 3) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source_and_sink(main);
- PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
- return err;
- }
-
#ifdef HAVE_SINK_APPLE_AUDIO
- uint_t samplerate = 0;
- uint_t hop_size = 512;
- uint_t n_frames = 0, read = 0;
+#define HAVE_AUBIO_SINK_CUSTOM
+#define aubio_sink_custom_t aubio_sink_apple_audio_t
+#define new_aubio_sink_custom new_aubio_sink_apple_audio
+#define del_aubio_sink_custom del_aubio_sink_apple_audio
+#define aubio_sink_custom_do aubio_sink_apple_audio_do
+#define aubio_sink_custom_do_multi aubio_sink_apple_audio_do_multi
+#define aubio_sink_custom_close aubio_sink_apple_audio_close
+#define aubio_sink_custom_preset_samplerate aubio_sink_apple_audio_preset_samplerate
+#define aubio_sink_custom_preset_channels aubio_sink_apple_audio_preset_channels
+#define aubio_sink_custom_get_samplerate aubio_sink_apple_audio_get_samplerate
+#define aubio_sink_custom_get_channels aubio_sink_apple_audio_get_channels
+#endif /* HAVE_SINK_APPLE_AUDIO */
- char_t *source_path = argv[1];
- char_t *sink_path = argv[2];
+#include "base-sink_custom.h"
- if ( argc >= 4 ) samplerate = atoi(argv[3]);
- if ( argc >= 5 ) hop_size = atoi(argv[4]);
- if ( argc >= 6 ) {
- err = 2;
- PRINT_ERR("too many arguments\n");
- return err;
- }
+// this file uses the unstable aubio api, please use aubio_sink instead
+// see src/io/sink.h and tests/src/sink/test-sink.c
- fvec_t *vec = new_fvec(hop_size);
- if (!vec) { err = 1; goto beach_fvec; }
-
- aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
- if (!i) { err = 1; goto beach_source; }
-
- if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
-
- aubio_sink_apple_audio_t *o = new_aubio_sink_apple_audio(sink_path, samplerate);
- if (!o) { err = 1; goto beach_sink; }
-
- do {
- aubio_source_do(i, vec, &read);
- aubio_sink_apple_audio_do(o, vec, read);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
- n_frames, samplerate, n_frames / hop_size,
- source_path, sink_path);
-
- del_aubio_sink_apple_audio(o);
-beach_sink:
- del_aubio_source(i);
-beach_source:
- del_fvec(vec);
-beach_fvec:
-#else /* HAVE_SINK_APPLE_AUDIO */
- err = 0;
- PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n");
-#endif /* HAVE_SINK_APPLE_AUDIO */
- return err;
+int main (int argc, char **argv)
+{
+ return base_main(argc, argv);
}
--- a/tests/src/io/test-sink_sndfile-multi.c
+++ /dev/null
@@ -1,78 +1,0 @@
-#define AUBIO_UNSTABLE 1
-#include <aubio.h>
-#include "utils_tests.h"
-
-// this file uses the unstable aubio api to test aubio_sink_sndfile, please
-// use aubio_sink instead see src/io/sink.h and tests/src/sink/test-sink.c
-
-int main (int argc, char **argv)
-{
- sint_t err = 0;
-
- if (argc < 3) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source_and_sink(main);
- PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [channels] [hop_size]\n", argv[0]);
- return err;
- }
-
-#ifdef HAVE_SNDFILE
- uint_t samplerate = 0;
- uint_t channels = 0;
- uint_t hop_size = 512;
- uint_t n_frames = 0, read = 0;
-
- char_t *source_path = argv[1];
- char_t *sink_path = argv[2];
-
- if ( argc >= 4 ) samplerate = atoi(argv[3]);
- if ( argc >= 5 ) channels = atoi(argv[4]);
- if ( argc >= 6 ) hop_size = atoi(argv[5]);
- if ( argc >= 7 ) {
- err = 2;
- PRINT_ERR("too many arguments\n");
- return err;
- }
-
- aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
- if (!i) { err = 1; goto beach_source; }
-
- if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
- if (channels == 0 ) channels = aubio_source_get_channels(i);
-
- fmat_t *mat = new_fmat(channels, hop_size);
- if (!mat) { err = 1; goto beach_fmat; }
-
- aubio_sink_sndfile_t *o = new_aubio_sink_sndfile(sink_path, 0);
- if (!o) { err = 1; goto beach_sink; }
- err = aubio_sink_sndfile_preset_samplerate(o, samplerate);
- if (err) { goto beach; }
- err = aubio_sink_sndfile_preset_channels(o, channels);
- if (err) { goto beach; }
-
- do {
- aubio_source_do_multi(i, mat, &read);
- aubio_sink_sndfile_do_multi(o, mat, read);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %d frames at %dHz in %d channels (%d blocks) from %s written to %s\n",
- n_frames, samplerate, channels, n_frames / hop_size,
- source_path, sink_path);
- PRINT_MSG("wrote %s with %dHz in %d channels\n", sink_path,
- aubio_sink_sndfile_get_samplerate(o),
- aubio_sink_sndfile_get_channels(o) );
-
-beach:
- del_aubio_sink_sndfile(o);
-beach_sink:
- del_fmat(mat);
-beach_fmat:
- del_aubio_source(i);
-beach_source:
-#else
- err = 0;
- PRINT_ERR("aubio was not compiled with aubio_sink_sndfile\n");
-#endif /* HAVE_SNDFILE */
- return err;
-}
--- a/tests/src/io/test-sink_sndfile.c
+++ b/tests/src/io/test-sink_sndfile.c
@@ -2,66 +2,28 @@
#include <aubio.h>
#include "utils_tests.h"
-// this file uses the unstable aubio api, please use aubio_sink instead
-// see src/io/sink.h and tests/src/sink/test-sink.c
+#define aubio_sink_custom "sndfile"
-int main (int argc, char **argv)
-{
- sint_t err = 0;
-
- if (argc < 3) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source_and_sink(main);
- PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
- return err;
- }
-
#ifdef HAVE_SNDFILE
- uint_t samplerate = 0;
- uint_t hop_size = 512;
- uint_t n_frames = 0, read = 0;
+#define HAVE_AUBIO_SINK_CUSTOM
+#define aubio_sink_custom_t aubio_sink_sndfile_t
+#define new_aubio_sink_custom new_aubio_sink_sndfile
+#define del_aubio_sink_custom del_aubio_sink_sndfile
+#define aubio_sink_custom_do aubio_sink_sndfile_do
+#define aubio_sink_custom_do_multi aubio_sink_sndfile_do_multi
+#define aubio_sink_custom_close aubio_sink_sndfile_close
+#define aubio_sink_custom_preset_samplerate aubio_sink_sndfile_preset_samplerate
+#define aubio_sink_custom_preset_channels aubio_sink_sndfile_preset_channels
+#define aubio_sink_custom_get_samplerate aubio_sink_sndfile_get_samplerate
+#define aubio_sink_custom_get_channels aubio_sink_sndfile_get_channels
+#endif /* HAVE_SNDFILE */
- char_t *source_path = argv[1];
- char_t *sink_path = argv[2];
+#include "base-sink_custom.h"
- if ( argc >= 4 ) samplerate = atoi(argv[3]);
- if ( argc >= 5 ) hop_size = atoi(argv[4]);
- if ( argc >= 6 ) {
- err = 2;
- PRINT_ERR("too many arguments\n");
- return err;
- }
+// this file uses the unstable aubio api, please use aubio_sink instead
+// see src/io/sink.h and tests/src/sink/test-sink.c
- fvec_t *vec = new_fvec(hop_size);
- if (!vec) { err = 1; goto beach_fvec; }
-
- aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
- if (!i) { err = 1; goto beach_source; }
-
- if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
-
- aubio_sink_sndfile_t *o = new_aubio_sink_sndfile(sink_path, samplerate);
- if (!o) { err = 1; goto beach_sink; }
-
- do {
- aubio_source_do(i, vec, &read);
- aubio_sink_sndfile_do(o, vec, read);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
- n_frames, samplerate, n_frames / hop_size,
- source_path, sink_path);
-
- del_aubio_sink_sndfile(o);
-beach_sink:
- del_aubio_source(i);
-beach_source:
- del_fvec(vec);
-beach_fvec:
-#else
- err = 0;
- PRINT_ERR("aubio was not compiled with aubio_source_sndfile\n");
-#endif /* HAVE_SNDFILE */
- return err;
+int main (int argc, char **argv)
+{
+ return base_main(argc, argv);
}
--- a/tests/src/io/test-sink_wavwrite-multi.c
+++ /dev/null
@@ -1,78 +1,0 @@
-#define AUBIO_UNSTABLE 1
-#include <aubio.h>
-#include "utils_tests.h"
-
-// this file uses the unstable aubio api to test aubio_sink_wavwrite, please
-// use aubio_sink instead see src/io/sink.h and tests/src/sink/test-sink.c
-
-int main (int argc, char **argv)
-{
- sint_t err = 0;
-
- if (argc < 3) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source_and_sink(main);
- PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [channels] [hop_size]\n", argv[0]);
- return err;
- }
-
-#ifdef HAVE_WAVWRITE
- uint_t samplerate = 0;
- uint_t channels = 0;
- uint_t hop_size = 512;
- uint_t n_frames = 0, read = 0;
-
- char_t *source_path = argv[1];
- char_t *sink_path = argv[2];
-
- if ( argc >= 4 ) samplerate = atoi(argv[3]);
- if ( argc >= 5 ) channels = atoi(argv[4]);
- if ( argc >= 6 ) hop_size = atoi(argv[5]);
- if ( argc >= 7 ) {
- err = 2;
- PRINT_ERR("too many arguments\n");
- return err;
- }
-
- aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
- if (!i) { err = 1; goto beach_source; }
-
- if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
- if (channels == 0 ) channels = aubio_source_get_channels(i);
-
- fmat_t *mat = new_fmat(channels, hop_size);
- if (!mat) { err = 1; goto beach_fmat; }
-
- aubio_sink_wavwrite_t *o = new_aubio_sink_wavwrite(sink_path, 0);
- if (!o) { err = 1; goto beach_sink; }
- err = aubio_sink_wavwrite_preset_samplerate(o, samplerate);
- if (err) { goto beach; }
- err = aubio_sink_wavwrite_preset_channels(o, channels);
- if (err) { goto beach; }
-
- do {
- aubio_source_do_multi(i, mat, &read);
- aubio_sink_wavwrite_do_multi(o, mat, read);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %d frames at %dHz in %d channels (%d blocks) from %s written to %s\n",
- n_frames, samplerate, channels, n_frames / hop_size,
- source_path, sink_path);
- PRINT_MSG("wrote %s with %dHz in %d channels\n", sink_path,
- aubio_sink_wavwrite_get_samplerate(o),
- aubio_sink_wavwrite_get_channels(o) );
-
-beach:
- del_aubio_sink_wavwrite(o);
-beach_sink:
- del_fmat(mat);
-beach_fmat:
- del_aubio_source(i);
-beach_source:
-#else
- err = 0;
- PRINT_ERR("aubio was not compiled with aubio_sink_wavwrite\n");
-#endif /* HAVE_WAVWRITE */
- return err;
-}
--- a/tests/src/io/test-sink_wavwrite.c
+++ b/tests/src/io/test-sink_wavwrite.c
@@ -2,66 +2,28 @@
#include <aubio.h>
#include "utils_tests.h"
-// this file uses the unstable aubio api, please use aubio_sink instead
-// see src/io/sink.h and tests/src/sink/test-sink.c
+#define aubio_sink_custom "wavwrite"
-int main (int argc, char **argv)
-{
- sint_t err = 0;
-
- if (argc < 3) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source_and_sink(main);
- PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
- return err;
- }
-
#ifdef HAVE_WAVWRITE
- uint_t samplerate = 0;
- uint_t hop_size = 512;
- uint_t n_frames = 0, read = 0;
+#define HAVE_AUBIO_SINK_CUSTOM
+#define aubio_sink_custom_t aubio_sink_wavwrite_t
+#define new_aubio_sink_custom new_aubio_sink_wavwrite
+#define del_aubio_sink_custom del_aubio_sink_wavwrite
+#define aubio_sink_custom_do aubio_sink_wavwrite_do
+#define aubio_sink_custom_do_multi aubio_sink_wavwrite_do_multi
+#define aubio_sink_custom_close aubio_sink_wavwrite_close
+#define aubio_sink_custom_preset_samplerate aubio_sink_wavwrite_preset_samplerate
+#define aubio_sink_custom_preset_channels aubio_sink_wavwrite_preset_channels
+#define aubio_sink_custom_get_samplerate aubio_sink_wavwrite_get_samplerate
+#define aubio_sink_custom_get_channels aubio_sink_wavwrite_get_channels
+#endif /* HAVE_WAVWRITE */
- char_t *source_path = argv[1];
- char_t *sink_path = argv[2];
+#include "base-sink_custom.h"
- if ( argc >= 4 ) samplerate = atoi(argv[3]);
- if ( argc >= 5 ) hop_size = atoi(argv[4]);
- if ( argc >= 6 ) {
- err = 2;
- PRINT_ERR("too many arguments\n");
- return err;
- }
+// this file uses the unstable aubio api, please use aubio_sink instead
+// see src/io/sink.h and tests/src/sink/test-sink.c
- fvec_t *vec = new_fvec(hop_size);
- if (!vec) { err = 1; goto beach_fvec; }
-
- aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
- if (!i) { err = 1; goto beach_source; }
-
- if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
-
- aubio_sink_wavwrite_t *o = new_aubio_sink_wavwrite(sink_path, samplerate);
- if (!o) { err = 1; goto beach_sink; }
-
- do {
- aubio_source_do(i, vec, &read);
- aubio_sink_wavwrite_do(o, vec, read);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
- n_frames, samplerate, n_frames / hop_size,
- source_path, sink_path);
-
- del_aubio_sink_wavwrite(o);
-beach_sink:
- del_aubio_source(i);
-beach_source:
- del_fvec(vec);
-beach_fvec:
-#else
- err = 0;
- PRINT_ERR("aubio was not compiled with aubio_sink_wavwrite\n");
-#endif /* HAVE_WAVWRITE */
- return err;
+int main (int argc, char **argv)
+{
+ return base_main(argc, argv);
}
--- a/tests/src/io/test-source.c
+++ b/tests/src/io/test-source.c
@@ -1,12 +1,14 @@
#include <aubio.h>
#include "utils_tests.h"
-int main (int argc, char **argv)
+int test_wrong_params(void);
+
+int main(int argc, char **argv)
{
uint_t err = 0;
if (argc < 2) {
PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source(main);
+ err = test_wrong_params();
PRINT_MSG("read a wave file as a mono vector\n");
PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
PRINT_MSG("examples:\n");
@@ -27,11 +29,10 @@
char_t *source_path = argv[1];
-
aubio_source_t* s =
new_aubio_source(source_path, samplerate, hop_size);
- if (!s) { err = 1; goto beach; }
fvec_t *vec = new_fvec(hop_size);
+ if (!s || !vec) { err = 1; goto beach; }
uint_t n_frames_expected = aubio_source_get_duration(s);
@@ -49,11 +50,60 @@
// close the file (optional)
aubio_source_close(s);
- // test closing the file a second time
- aubio_source_close(s);
- del_fvec (vec);
- del_aubio_source (s);
beach:
+ if (vec)
+ del_fvec(vec);
+ if (s)
+ del_aubio_source(s);
return err;
+}
+
+int test_wrong_params(void)
+{
+ char_t *uri = DEFINEDSTRING(AUBIO_TESTS_SOURCE);
+ uint_t samplerate = 44100;
+ uint_t hop_size = 512;
+ uint_t channels, read = 0;
+ fvec_t *vec;
+ fmat_t *mat;
+ aubio_source_t *s;
+
+ if (new_aubio_source(0, samplerate, hop_size)) return 1;
+ if (new_aubio_source("\0", samplerate, hop_size)) return 1;
+ if (new_aubio_source(uri, -1, hop_size)) return 1;
+ if (new_aubio_source(uri, 0, 0)) return 1;
+
+ s = new_aubio_source(uri, samplerate, hop_size);
+ if (!s) return 1;
+ channels = aubio_source_get_channels(s);
+
+ // vector to read downmixed samples
+ vec = new_fvec(hop_size);
+ // matrix to read individual channels
+ mat = new_fmat(channels, hop_size);
+
+ if (aubio_source_get_samplerate(s) != samplerate) return 1;
+
+ // read first hop_size frames
+ aubio_source_do(s, vec, &read);
+ if (read != hop_size) return 1;
+
+ // seek to 0
+ if(aubio_source_seek(s, 0)) return 1;
+
+ // read again as multiple channels
+ aubio_source_do_multi(s, mat, &read);
+ if (read != hop_size) return 1;
+
+ // close the file (optional)
+ aubio_source_close(s);
+ // test closing the file a second time
+ aubio_source_close(s);
+
+ del_aubio_source(s);
+ del_fmat(mat);
+ del_fvec(vec);
+
+ return run_on_default_source(main);
}
--- a/tests/src/io/test-source_apple_audio.c
+++ b/tests/src/io/test-source_apple_audio.c
@@ -2,62 +2,29 @@
#include <aubio.h>
#include "utils_tests.h"
+#define aubio_source_custom "apple_audio"
+
+#ifdef HAVE_SOURCE_APPLE_AUDIO
+#define HAVE_AUBIO_SOURCE_CUSTOM
+#define aubio_source_custom_t aubio_source_apple_audio_t
+#define new_aubio_source_custom new_aubio_source_apple_audio
+#define del_aubio_source_custom del_aubio_source_apple_audio
+#define aubio_source_custom_get_samplerate aubio_source_apple_audio_get_samplerate
+#define aubio_source_custom_get_duration aubio_source_apple_audio_get_duration
+#define aubio_source_custom_do aubio_source_apple_audio_do
+#define aubio_source_custom_do_multi aubio_source_apple_audio_do_multi
+#define aubio_source_custom_seek aubio_source_apple_audio_seek
+#define aubio_source_custom_close aubio_source_apple_audio_close
+#define aubio_source_custom_get_channels aubio_source_apple_audio_get_channels
+#define aubio_source_custom_get_samplerate aubio_source_apple_audio_get_samplerate
+#endif /* HAVE_SOURCE_APPLE_AUDIO */
+
+#include "base-source_custom.h"
+
// this file uses the unstable aubio api, please use aubio_source instead
// see src/io/source.h and tests/src/source/test-source.c
int main (int argc, char **argv)
{
- uint_t err = 0;
- if (argc < 2) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source(main);
- PRINT_MSG("read a wave file as a mono vector\n");
- PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
- PRINT_MSG("examples:\n");
- PRINT_MSG(" - read file.wav at original samplerate\n");
- PRINT_MSG(" %s file.wav\n", argv[0]);
- PRINT_MSG(" - read file.aif at 32000Hz\n");
- PRINT_MSG(" %s file.aif 32000\n", argv[0]);
- PRINT_MSG(" - read file.mp3 at original samplerate with 4096 blocks\n");
- PRINT_MSG(" %s file.mp3 0 4096 \n", argv[0]);
- return err;
- }
-
-#if HAVE_SOURCE_APPLE_AUDIO
- uint_t samplerate = 0;
- uint_t hop_size = 256;
- uint_t n_frames = 0, read = 0;
- if ( argc >= 3 ) samplerate = atoi(argv[2]);
- if ( argc >= 4 ) hop_size = atoi(argv[3]);
-
- char_t *source_path = argv[1];
-
-
- aubio_source_apple_audio_t * s =
- new_aubio_source_apple_audio(source_path, samplerate, hop_size);
- if (!s) { err = 1; goto beach; }
- fvec_t *vec = new_fvec(hop_size);
-
- uint_t n_frames_expected = aubio_source_apple_audio_get_duration(s);
-
- samplerate = aubio_source_apple_audio_get_samplerate(s);
-
- do {
- aubio_source_apple_audio_do(s, vec, &read);
- fvec_print (vec);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
- n_frames, n_frames_expected, samplerate, n_frames / hop_size,
- source_path);
-
- del_fvec (vec);
- del_aubio_source_apple_audio (s);
-beach:
-#else /* HAVE_SOURCE_APPLE_AUDIO */
- err = 0;
- PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n");
-#endif /* HAVE_SOURCE_APPLE_AUDIO */
- return err;
+ return base_main(argc, argv);
}
--- a/tests/src/io/test-source_avcodec.c
+++ b/tests/src/io/test-source_avcodec.c
@@ -2,62 +2,29 @@
#include <aubio.h>
#include "utils_tests.h"
-// this file uses the unstable aubio api, please use aubio_source instead
-// see src/io/source.h and tests/src/source/test-source.c
+#define aubio_source_custom "avcodec"
-int main (int argc, char **argv)
-{
- uint_t err = 0;
- if (argc < 2) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source(main);
- PRINT_MSG("read a wave file as a mono vector\n");
- PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
- PRINT_MSG("examples:\n");
- PRINT_MSG(" - read file.wav at original samplerate\n");
- PRINT_MSG(" %s file.wav\n", argv[0]);
- PRINT_MSG(" - read file.wav at 32000Hz\n");
- PRINT_MSG(" %s file.aif 32000\n", argv[0]);
- PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
- PRINT_MSG(" %s file.wav 0 4096 \n", argv[0]);
- return err;
- }
-
#ifdef HAVE_LIBAV
- uint_t samplerate = 0;
- uint_t hop_size = 256;
- uint_t n_frames = 0, read = 0;
- if ( argc >= 3 ) samplerate = atoi(argv[2]);
- if ( argc >= 4 ) hop_size = atoi(argv[3]);
+#define HAVE_AUBIO_SOURCE_CUSTOM
+#define aubio_source_custom_t aubio_source_avcodec_t
+#define new_aubio_source_custom new_aubio_source_avcodec
+#define del_aubio_source_custom del_aubio_source_avcodec
+#define aubio_source_custom_get_samplerate aubio_source_avcodec_get_samplerate
+#define aubio_source_custom_get_duration aubio_source_avcodec_get_duration
+#define aubio_source_custom_do aubio_source_avcodec_do
+#define aubio_source_custom_do_multi aubio_source_avcodec_do_multi
+#define aubio_source_custom_seek aubio_source_avcodec_seek
+#define aubio_source_custom_close aubio_source_avcodec_close
+#define aubio_source_custom_get_channels aubio_source_avcodec_get_channels
+#define aubio_source_custom_get_samplerate aubio_source_avcodec_get_samplerate
+#endif /* HAVE_LIBAV */
- char_t *source_path = argv[1];
+#include "base-source_custom.h"
+// this file uses the unstable aubio api, please use aubio_source instead
+// see src/io/source.h and tests/src/source/test-source.c
- aubio_source_avcodec_t * s =
- new_aubio_source_avcodec(source_path, samplerate, hop_size);
- if (!s) { err = 1; goto beach; }
- fvec_t *vec = new_fvec(hop_size);
-
- uint_t n_frames_expected = aubio_source_avcodec_get_duration(s);
-
- samplerate = aubio_source_avcodec_get_samplerate(s);
-
- do {
- aubio_source_avcodec_do(s, vec, &read);
- fvec_print (vec);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
- n_frames, n_frames_expected, samplerate, n_frames / hop_size,
- source_path);
-
- del_fvec (vec);
- del_aubio_source_avcodec (s);
-beach:
-#else /* HAVE_LIBAV */
- err = 0;
- PRINT_ERR("aubio was not compiled with aubio_source_avcodec\n");
-#endif /* HAVE_LIBAV */
- return err;
+int main (int argc, char **argv)
+{
+ return base_main(argc, argv);
}
--- a/tests/src/io/test-source_multi.c
+++ /dev/null
@@ -1,57 +1,0 @@
-#include <aubio.h>
-#include "utils_tests.h"
-
-int main (int argc, char **argv)
-{
- sint_t err = 0;
- if (argc < 2) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source(main);
- PRINT_MSG("read a wave file as a mono vector\n");
- PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
- PRINT_MSG("examples:\n");
- PRINT_MSG(" - read file.wav at original samplerate\n");
- PRINT_MSG(" %s file.wav\n", argv[0]);
- PRINT_MSG(" - read file.wav at 32000Hz\n");
- PRINT_MSG(" %s file.aif 32000\n", argv[0]);
- PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
- PRINT_MSG(" %s file.wav 0 4096 \n", argv[0]);
- PRINT_MSG(" - read file.wav at original samplerate with 256 frames blocks, mono\n");
- PRINT_MSG(" %s file.wav 0 4096 1\n", argv[0]);
- return err;
- }
-
- uint_t samplerate = 0;
- uint_t hop_size = 256;
- uint_t n_frames = 0, read = 0;
- uint_t n_channels = 0;
- if ( argc >= 3 ) samplerate = atoi(argv[2]);
- if ( argc >= 4 ) hop_size = atoi(argv[3]);
- if ( argc >= 5 ) n_channels = atoi(argv[4]);
-
- char_t *source_path = argv[1];
-
- aubio_source_t* s = new_aubio_source(source_path, samplerate, hop_size);
- if (!s) { err = -1; goto beach; }
-
- if ( samplerate == 0 ) samplerate = aubio_source_get_samplerate(s);
-
- if ( n_channels == 0 ) n_channels = aubio_source_get_channels(s);
-
- fmat_t *mat = new_fmat(n_channels, hop_size);
-
- do {
- aubio_source_do_multi (s, mat, &read);
- fmat_print (mat);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %d frames in %d channels at %dHz (%d blocks) from %s\n",
- n_frames, n_channels, samplerate, n_frames / hop_size, source_path);
-
- del_fmat (mat);
- del_aubio_source (s);
-beach:
-
- return err;
-}
--- a/tests/src/io/test-source_seek.c
+++ /dev/null
@@ -1,92 +1,0 @@
-#include <aubio.h>
-#include "utils_tests.h"
-
-int main (int argc, char **argv)
-{
- uint_t err = 0;
- if (argc < 2) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source(main);
- PRINT_MSG("read a wave file as a mono vector\n");
- PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
- PRINT_MSG("examples:\n");
- PRINT_MSG(" - read file.wav at original samplerate\n");
- PRINT_MSG(" %s file.wav\n", argv[0]);
- PRINT_MSG(" - read file.wav at 32000Hz\n");
- PRINT_MSG(" %s file.aif 32000\n", argv[0]);
- PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
- PRINT_MSG(" %s file.wav 0 4096 \n", argv[0]);
- return err;
- }
-
- uint_t samplerate = 0;
- uint_t hop_size = 256;
- uint_t n_frames = 0, read = 0;
- uint_t old_n_frames_1 = 0, old_n_frames_2 = 0, old_n_frames_3 = 0;
- if ( argc >= 3 ) samplerate = atoi(argv[2]);
- if ( argc >= 4 ) hop_size = atoi(argv[3]);
-
- char_t *source_path = argv[1];
-
- fvec_t *vec = new_fvec(hop_size);
-
- aubio_source_t* s = new_aubio_source(source_path, samplerate, hop_size);
- if (!s) { err = 1; goto beach; }
-
- if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(s);
-
- do {
- aubio_source_do(s, vec, &read);
- //fvec_print (vec);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
- n_frames * 1. / samplerate,
- n_frames, samplerate,
- n_frames / hop_size, source_path);
-
- old_n_frames_1 = n_frames;
-
- aubio_source_seek (s, 0);
-
- n_frames = 0;
- do {
- aubio_source_do(s, vec, &read);
- //fvec_print (vec);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
- n_frames * 1. / samplerate,
- n_frames, samplerate,
- n_frames / hop_size, source_path);
-
- old_n_frames_2 = n_frames;
-
- aubio_source_seek (s, old_n_frames_1 / 2);
-
- n_frames = 0;
- do {
- aubio_source_do(s, vec, &read);
- //fvec_print (vec);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
- n_frames * 1. / samplerate,
- n_frames, samplerate,
- n_frames / hop_size, source_path);
-
- old_n_frames_3 = n_frames;
-
- del_aubio_source (s);
-beach:
- del_fvec (vec);
-
- // check that we got exactly the same number of frames
- assert ( old_n_frames_2 == old_n_frames_1 );
- // check that we got about half the frames, with 3 decimals
- assert ( roundf(1.e3 * old_n_frames_1 / old_n_frames_3) / 1.e3 == 2.);
- return err;
-}
--- a/tests/src/io/test-source_sndfile.c
+++ b/tests/src/io/test-source_sndfile.c
@@ -2,62 +2,29 @@
#include <aubio.h>
#include "utils_tests.h"
-// this file uses the unstable aubio api, please use aubio_source instead
-// see src/io/source.h and tests/src/source/test-source.c
+#define aubio_source_custom "sndfile"
-int main (int argc, char **argv)
-{
- uint_t err = 0;
- if (argc < 2) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source(main);
- PRINT_MSG("read a wave file as a mono vector\n");
- PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
- PRINT_MSG("examples:\n");
- PRINT_MSG(" - read file.wav at original samplerate\n");
- PRINT_MSG(" %s file.wav\n", argv[0]);
- PRINT_MSG(" - read file.wav at 32000Hz\n");
- PRINT_MSG(" %s file.aif 32000\n", argv[0]);
- PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
- PRINT_MSG(" %s file.wav 0 4096 \n", argv[0]);
- return err;
- }
-
#ifdef HAVE_SNDFILE
- uint_t samplerate = 0;
- uint_t hop_size = 256;
- uint_t n_frames = 0, read = 0;
- if ( argc >= 3 ) samplerate = atoi(argv[2]);
- if ( argc >= 4 ) hop_size = atoi(argv[3]);
+#define HAVE_AUBIO_SOURCE_CUSTOM
+#define aubio_source_custom_t aubio_source_sndfile_t
+#define new_aubio_source_custom new_aubio_source_sndfile
+#define del_aubio_source_custom del_aubio_source_sndfile
+#define aubio_source_custom_get_samplerate aubio_source_sndfile_get_samplerate
+#define aubio_source_custom_get_duration aubio_source_sndfile_get_duration
+#define aubio_source_custom_do aubio_source_sndfile_do
+#define aubio_source_custom_do_multi aubio_source_sndfile_do_multi
+#define aubio_source_custom_seek aubio_source_sndfile_seek
+#define aubio_source_custom_close aubio_source_sndfile_close
+#define aubio_source_custom_get_channels aubio_source_sndfile_get_channels
+#define aubio_source_custom_get_samplerate aubio_source_sndfile_get_samplerate
+#endif /* HAVE_LIBAV */
- char_t *source_path = argv[1];
+#include "base-source_custom.h"
+// this file uses the unstable aubio api, please use aubio_source instead
+// see src/io/source.h and tests/src/source/test-source.c
- aubio_source_sndfile_t * s =
- new_aubio_source_sndfile(source_path, samplerate, hop_size);
- if (!s) { err = 1; goto beach; }
- fvec_t *vec = new_fvec(hop_size);
-
- uint_t n_frames_expected = aubio_source_sndfile_get_duration(s);
-
- samplerate = aubio_source_sndfile_get_samplerate(s);
-
- do {
- aubio_source_sndfile_do(s, vec, &read);
- fvec_print (vec);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
- n_frames, n_frames_expected, samplerate, n_frames / hop_size,
- source_path);
-
- del_fvec (vec);
- del_aubio_source_sndfile (s);
-beach:
-#else
- err = 0;
- PRINT_ERR("aubio was not compiled with aubio_source_sndfile\n");
-#endif /* HAVE_SNDFILE */
- return err;
+int main (int argc, char **argv)
+{
+ return base_main(argc, argv);
}
--- a/tests/src/io/test-source_wavread.c
+++ b/tests/src/io/test-source_wavread.c
@@ -2,62 +2,29 @@
#include <aubio.h>
#include "utils_tests.h"
-// this file uses the unstable aubio api, please use aubio_source instead
-// see src/io/source.h and tests/src/source/test-source.c
+#define aubio_source_custom "wavread"
-int main (int argc, char **argv)
-{
- uint_t err = 0;
- if (argc < 2) {
- PRINT_ERR("not enough arguments, running tests\n");
- err = run_on_default_source(main);
- PRINT_MSG("read a wave file as a mono vector\n");
- PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
- PRINT_MSG("examples:\n");
- PRINT_MSG(" - read file.wav at original samplerate\n");
- PRINT_MSG(" %s file.wav\n", argv[0]);
- PRINT_MSG(" - read file.wav at 32000Hz\n");
- PRINT_MSG(" %s file.aif 32000\n", argv[0]);
- PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
- PRINT_MSG(" %s file.wav 0 4096 \n", argv[0]);
- return err;
- }
-
#ifdef HAVE_WAVREAD
- uint_t samplerate = 0;
- uint_t hop_size = 256;
- uint_t n_frames = 0, read = 0;
- if ( argc >= 3 ) samplerate = atoi(argv[2]);
- if ( argc >= 4 ) hop_size = atoi(argv[3]);
+#define HAVE_AUBIO_SOURCE_CUSTOM
+#define aubio_source_custom_t aubio_source_wavread_t
+#define new_aubio_source_custom new_aubio_source_wavread
+#define del_aubio_source_custom del_aubio_source_wavread
+#define aubio_source_custom_get_samplerate aubio_source_wavread_get_samplerate
+#define aubio_source_custom_get_duration aubio_source_wavread_get_duration
+#define aubio_source_custom_do aubio_source_wavread_do
+#define aubio_source_custom_do_multi aubio_source_wavread_do_multi
+#define aubio_source_custom_seek aubio_source_wavread_seek
+#define aubio_source_custom_close aubio_source_wavread_close
+#define aubio_source_custom_get_channels aubio_source_wavread_get_channels
+#define aubio_source_custom_get_samplerate aubio_source_wavread_get_samplerate
+#endif /* HAVE_WAVREAD */
- char_t *source_path = argv[1];
+#include "base-source_custom.h"
+// this file uses the unstable aubio api, please use aubio_source instead
+// see src/io/source.h and tests/src/source/test-source.c
- aubio_source_wavread_t * s =
- new_aubio_source_wavread(source_path, samplerate, hop_size);
- if (!s) { err = 1; goto beach; }
- fvec_t *vec = new_fvec(hop_size);
-
- uint_t n_frames_expected = aubio_source_wavread_get_duration(s);
-
- samplerate = aubio_source_wavread_get_samplerate(s);
-
- do {
- aubio_source_wavread_do(s, vec, &read);
- fvec_print (vec);
- n_frames += read;
- } while ( read == hop_size );
-
- PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
- n_frames, n_frames_expected, samplerate, n_frames / hop_size,
- source_path);
-
- del_fvec (vec);
- del_aubio_source_wavread (s);
-beach:
-#else
- err = 0;
- PRINT_ERR("aubio was not compiled with aubio_source_wavread\n");
-#endif /* HAVE_WAVREAD */
- return err;
+int main (int argc, char **argv)
+{
+ return base_main(argc, argv);
}
--- a/tests/src/onset/test-onset.c
+++ b/tests/src/onset/test-onset.c
@@ -69,21 +69,19 @@
uint_t hop_size = win_size / 2;
uint_t samplerate = 44100;
// hop_size < 1
- if (new_aubio_onset("default", 5, 0, samplerate))
- return 1;
+ if (new_aubio_onset("default", 5, 0, samplerate)) return 1;
+
// buf_size < 2
- if (new_aubio_onset("default", 1, 1, samplerate))
- return 1;
+ if (new_aubio_onset("default", 1, 1, samplerate)) return 1;
+
// buf_size < hop_size
- if (new_aubio_onset("default", hop_size, win_size, samplerate))
- return 1;
+ if (new_aubio_onset("default", hop_size, win_size, samplerate)) return 1;
+
// samplerate < 1
- if (new_aubio_onset("default", 1024, 512, 0))
- return 1;
+ if (new_aubio_onset("default", 1024, 512, 0)) return 1;
// specdesc creation failed
- if (new_aubio_onset("abcd", win_size, win_size/2, samplerate))
- return 1;
+ if (new_aubio_onset("abcd", win_size, win_size/2, samplerate)) return 1;
aubio_onset_t *o;
@@ -92,8 +90,7 @@
if (o) del_aubio_onset(o);
o = new_aubio_onset("default", win_size, hop_size, samplerate);
- if (!aubio_onset_set_default_parameters(o, "wrong_type"))
- return 1;
+ if (!aubio_onset_set_default_parameters(o, "wrong_type")) return 1;
del_aubio_onset(o);
return run_on_default_source(main);
--- a/tests/src/spectral/test-mfcc.c
+++ b/tests/src/spectral/test-mfcc.c
@@ -1,13 +1,89 @@
#include <aubio.h>
+#include "utils_tests.h"
-int main (void)
+int test_wrong_params(void);
+
+int main (int argc, char** argv)
{
+ sint_t err = 0;
+
+ if (argc < 2) {
+ err = 2;
+ PRINT_WRN("no arguments, running tests\n");
+ err = test_wrong_params();
+ PRINT_MSG("usage: %s <input_path> [samplerate] [hop_size]\n", argv[0]);
+ return err;
+ }
+
+ uint_t win_s; // fft size
+ uint_t hop_s = 256; // block size
+ uint_t samplerate = 0; // samplerate
+ uint_t n_filters = 40; // number of filters
+ uint_t n_coeffs = 13; // number of coefficients
+ uint_t read = 0;
+
+ char_t *source_path = argv[1];
+
+ if ( argc >= 3 ) samplerate = atoi(argv[2]);
+ if ( argc >= 4 ) hop_s = atoi(argv[3]);
+
+ win_s = 2 * hop_s;
+
+ aubio_source_t *source = 0;
+ aubio_pvoc_t *pv = 0;
+ aubio_mfcc_t *mfcc = 0;
+
+ fvec_t *in = new_fvec (win_s); // input buffer
+ cvec_t *fftgrain = new_cvec (win_s); // input buffer
+ fvec_t *out = new_fvec (n_coeffs); // output coefficients
+
+ if (!in || !fftgrain || !out) { err = 1; goto failure; }
+
+ // source
+ source = new_aubio_source(source_path, samplerate, hop_s);
+ if (!source) { err = 1; goto failure; }
+ if (samplerate == 0) samplerate = aubio_source_get_samplerate(source);
+
+ // phase vocoder
+ pv = new_aubio_pvoc(win_s, hop_s);
+ if (!pv) { err = 1; goto failure; }
+
+ // mfcc object
+ mfcc = new_aubio_mfcc (win_s, n_filters, n_coeffs, samplerate);
+ if (!mfcc) { err = 1; goto failure; }
+
+ // processing loop
+ do {
+ aubio_source_do(source, in, &read);
+ aubio_pvoc_do(pv, in, fftgrain);
+ aubio_mfcc_do(mfcc, fftgrain, out);
+ fvec_print(out);
+ } while (read == hop_s);
+
+failure:
+
+ if (mfcc)
+ del_aubio_mfcc(mfcc);
+ if (pv)
+ del_aubio_pvoc(pv);
+ if (source)
+ del_aubio_source(source);
+ if (in)
+ del_fvec(in);
+ if (fftgrain)
+ del_cvec(fftgrain);
+ if (out)
+ del_fvec(out);
+ aubio_cleanup();
+ return err;
+}
+
+int test_wrong_params()
+{
uint_t win_s = 512; // fft size
uint_t n_filters = 40; // number of filters
uint_t n_coeffs = 13; // number of coefficients
smpl_t samplerate = 16000.; // samplerate
- cvec_t *in = new_cvec (win_s); // input buffer
- fvec_t *out = new_fvec (n_coeffs); // output coefficients
if (new_aubio_mfcc( 0, n_filters, n_coeffs, samplerate)) return 1;
if (new_aubio_mfcc(win_s, 0, n_coeffs, samplerate)) return 1;
@@ -14,22 +90,5 @@
if (new_aubio_mfcc(win_s, n_filters, 0, samplerate)) return 1;
if (new_aubio_mfcc(win_s, n_filters, n_coeffs, 0)) return 1;
- // create mfcc object
- aubio_mfcc_t *o = new_aubio_mfcc (win_s, n_filters, n_coeffs, samplerate);
-
- cvec_norm_set_all (in, 1.);
- aubio_mfcc_do (o, in, out);
- fvec_print (out);
-
- cvec_norm_set_all (in, .5);
- aubio_mfcc_do (o, in, out);
- fvec_print (out);
-
- // clean up
- del_aubio_mfcc (o);
- del_cvec (in);
- del_fvec (out);
- aubio_cleanup ();
-
- return 0;
+ return run_on_default_source(main);
}
--- a/tests/src/tempo/test-tempo.c
+++ b/tests/src/tempo/test-tempo.c
@@ -81,35 +81,28 @@
uint_t i;
// test wrong method fails
- if (new_aubio_tempo("unexisting_method", win_size, hop_size, samplerate))
- return 1;
+ if (new_aubio_tempo("undefined", win_size, hop_size, samplerate)) return 1;
// test hop > win fails
- if (new_aubio_tempo("default", hop_size, win_size, samplerate))
- return 1;
+ if (new_aubio_tempo("default", hop_size, win_size, samplerate)) return 1;
// test null hop_size fails
- if (new_aubio_tempo("default", win_size, 0, samplerate))
- return 1;
+ if (new_aubio_tempo("default", win_size, 0, samplerate)) return 1;
// test 1 buf_size fails
- if (new_aubio_tempo("default", 1, 1, samplerate))
- return 1;
+ if (new_aubio_tempo("default", 1, 1, samplerate)) return 1;
// test null samplerate fails
- if (new_aubio_tempo("default", win_size, hop_size, 0))
- return 1;
+ if (new_aubio_tempo("default", win_size, hop_size, 0)) return 1;
// test short sizes workaround
t = new_aubio_tempo("default", 2048, 2048, 500);
- if (!t)
- return 1;
+ if (!t) return 1;
del_aubio_tempo(t);
t = new_aubio_tempo("default", win_size, hop_size, samplerate);
- if (!t)
- return 1;
+ if (!t) return 1;
in = new_fvec(hop_size);
out = new_fvec(1);
--- a/tests/src/temporal/test-filter.c
+++ b/tests/src/temporal/test-filter.c
@@ -9,17 +9,13 @@
aubio_filter_t *o = new_aubio_filter_c_weighting (44100);
- if (new_aubio_filter(0))
- return 1;
+ if (new_aubio_filter(0)) return 1;
- if (aubio_filter_get_samplerate(o) != 44100)
- return 1;
+ if (aubio_filter_get_samplerate(o) != 44100) return 1;
- if (aubio_filter_set_c_weighting (o, -1) == 0)
- return 1;
+ if (aubio_filter_set_c_weighting (o, -1) == 0) return 1;
- if (aubio_filter_set_c_weighting (0, 32000) == 0)
- return 1;
+ if (aubio_filter_set_c_weighting (0, 32000) == 0) return 1;
in->data[impulse_at] = 0.5;
fvec_print (in);
@@ -29,10 +25,9 @@
o = new_aubio_filter_a_weighting (32000);
- if (aubio_filter_set_a_weighting (o, -1) == 0)
- return 1;
- if (aubio_filter_set_a_weighting (0, 32000) == 0)
- return 1;
+ if (aubio_filter_set_a_weighting (o, -1) == 0) return 1;
+
+ if (aubio_filter_set_a_weighting (0, 32000) == 0) return 1;
in->data[impulse_at] = 0.5;
fvec_print (in);
--- a/tests/src/test-delnull.c
+++ /dev/null
@@ -1,24 +1,0 @@
-#include <stdlib.h>
-#include "aubio.h"
-
-// When creating an aubio object, the user should check whether the object is
-// set NULL, indicating the creation failed and the object was not allocated.
-
-int main (void)
-{
- uint_t return_code = 0;
- fvec_t *f = new_fvec(-12);
- cvec_t *c = new_cvec(-12);
- lvec_t *l = new_lvec(-12);
- aubio_fft_t *fft = new_aubio_fft(-12);
- if (f != NULL) {
- return_code = 1;
- } else if (c != NULL) {
- return_code = 2;
- } else if (l != NULL) {
- return_code = 3;
- } else if (fft != NULL) {
- return_code = 3;
- }
- return return_code;
-}
--- a/tests/utils_tests.h
+++ b/tests/utils_tests.h
@@ -55,21 +55,20 @@
#define RAND_MAX 32767
#endif
-// are we on windows ? or are we using -std=c99 ?
-#if defined(HAVE_WIN_HACKS) || defined(__STRICT_ANSI__)
-// http://en.wikipedia.org/wiki/Linear_congruential_generator
-// no srandom/random on win32
+#if defined(HAVE_WIN_HACKS)
-uint_t srandom_seed = 1029;
+// use srand/rand on windows
+#define srandom srand
+#define random rand
-void srandom(uint_t new_seed) {
- srandom_seed = new_seed;
-}
+#elif defined(__STRICT_ANSI__)
-uint_t random(void) {
- srandom_seed = 1664525 * srandom_seed + 1013904223;
- return srandom_seed;
-}
+// workaround to build with -std=c99 (for instance with older cygwin),
+// assuming libbc is recent enough to supports these functions.
+extern void srandom(unsigned);
+extern int random(void);
+extern char mkstemp(const char *pat);
+
#endif
void utils_init_random (void);
--- a/wscript
+++ b/wscript
@@ -555,32 +555,45 @@
# build documentation from source files using doxygen
if bld.env['DOXYGEN']:
bld.env.VERSION = VERSION
- rule = '( cat ${SRC} && echo PROJECT_NUMBER=${VERSION}; )'
+ rule = '( cat ${SRC[0]} && echo PROJECT_NUMBER=${VERSION}'
+ rule += ' && echo OUTPUT_DIRECTORY=%s && echo HTML_OUTPUT=%s )'
rule += ' | doxygen - > /dev/null'
+ rule %= (os.path.abspath(out), 'api')
bld( name = 'doxygen', rule = rule,
- source = 'doc/web.cfg',
- target = '../doc/web/html/index.html',
- cwd = 'doc')
- bld.install_files( '${DATAROOTDIR}' + '/doc/libaubio-doc',
- bld.path.ant_glob('doc/web/html/**'),
- cwd = bld.path.find_dir ('doc/web'),
- relative_trick = True)
+ source = ['doc/web.cfg']
+ + bld.path.find_dir('src').ant_glob('**/*.h'),
+ target = bld.path.find_or_declare('api/index.html'),
+ cwd = bld.path.find_dir('doc'))
+ # evaluate nodes lazily to prevent build directory traversal warnings
+ bld.install_files('${DATAROOTDIR}/doc/libaubio-doc/api',
+ bld.path.find_or_declare('api').ant_glob('**/*',
+ generator=True), cwd=bld.path.find_or_declare('api'),
+ relative_trick=True)
def sphinx(bld):
- # build documentation from source files using sphinx-build note: build in
- # ../doc/_build/html, otherwise waf wont install unsigned files
- if bld.env['SPHINX']:
+ # build documentation from source files using sphinx-build
+ try:
+ import aubio
+ has_aubio = True
+ except ImportError:
+ from waflib import Logs
+ Logs.pprint('YELLOW', "Sphinx manual: install aubio first")
+ has_aubio = False
+ if bld.env['SPHINX'] and has_aubio:
bld.env.VERSION = VERSION
- bld( name = 'sphinx',
- rule = '${SPHINX} -b html -D release=${VERSION}' \
- ' -D version=${VERSION} -a -q' \
- ' `dirname ${SRC}` `dirname ${TGT}`',
- source = 'doc/conf.py',
- target = '../doc/_build/html/index.html')
- bld.install_files( '${DATAROOTDIR}' + '/doc/libaubio-doc/sphinx',
- bld.path.ant_glob('doc/_build/html/**'),
- cwd = bld.path.find_dir('doc/_build/html'),
- relative_trick = True)
+ rule = '${SPHINX} -b html -D release=${VERSION}' \
+ ' -D version=${VERSION} -W -a -q' \
+ ' -d %s ' % os.path.join(os.path.abspath(out), 'doctrees')
+ rule += ' . %s' % os.path.join(os.path.abspath(out), 'manual')
+ bld( name = 'sphinx', rule = rule,
+ cwd = bld.path.find_dir('doc'),
+ source = bld.path.find_dir('doc').ant_glob('*.rst'),
+ target = bld.path.find_or_declare('manual/index.html'))
+ # evaluate nodes lazily to prevent build directory traversal warnings
+ bld.install_files('${DATAROOTDIR}/doc/libaubio-doc/manual',
+ bld.path.find_or_declare('manual').ant_glob('**/*',
+ generator=True), cwd=bld.path.find_or_declare('manual'),
+ relative_trick=True)
# register the previous rules as build rules
from waflib.Build import BuildContext