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