shithub: aubio

Download patch

ref: e893e6fe954265cd404fd49b4676db50a558d4d0
parent: bf3f09b5a18deb2d308292b855e895ec86d85ca0
parent: c4a8bc138e49de8b43fcd2221ef84dfa5073208f
author: Paul Brossier <piem@piem.org>
date: Thu Nov 22 13:41:41 EST 2018

Merge branch 'master' into feature/pytest

--- a/.travis.yml
+++ b/.travis.yml
@@ -62,15 +62,17 @@
     - libfftw3-dev
     - sox
     - lcov
+  homebrew:
+    packages:
+    - sox
+    - ffmpeg
+    - libsndfile
+    - lcov
+    #update: true
 
 before_install:
    - |
      if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
-       brew update
-       brew install sox
-       brew install ffmpeg
-       brew install libsndfile
-       brew install lcov
        export PATH="$HOME/Library/Python/2.7/bin/:$PATH"
      fi;
 
@@ -83,8 +85,6 @@
   - travis_retry make getwaf expandwaf deps_python
   - which pip
   - pip --version
-  - pip install python-coveralls
-  - gem install coveralls-lcov
 
 script:
   - make create_test_sounds
@@ -99,10 +99,6 @@
 after_success:
   - |
     if [[ -z "$AUBIO_NOTESTS" ]]; then
-      # upload lcov coverage to coveralls.io
-      coveralls-lcov build/coverage.info
-      # upload python coverage
-      #coveralls
       # upload to codecov
       bash <(curl -s https://codecov.io/bash)
     fi
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,79 @@
+2018-11-21 Paul Brossier <piem@aubio.org>
+
+	[ Overview ]
+
+	* VERSION: bump to 0.4.8
+	* notes: new option release_drop (gh-203)
+	* spectral: new parameters added to filterbank and mfcc (gh-206)
+	* python: start documenting module (gh-73, debian #480018), improve build for
+	win-amd64 (gh-154, gh-199, gh-208)
+	* fixes: prevent crash when using fft sizes unsupported by vDSP (gh-207),
+	prevent saturation when down-mixing a multi-channel source (avcodec/ffmpeg)
+
+	[ Fixes ]
+
+	* avcodec: prevent saturation when down-mixing a multi-channel source, emit
+	a warning if compiling against avutil < 53 (gh-137), wrap long lines
+	* examples/: avoid hiding global and unreachable code
+	* fft: limit to r*2*n sizes, with r in [1, 3, 5, 15] (vDSP only) (gh-207)
+	* fft: fix reconstruction for odd sizes (fftw only)
+	* pvoc: add missing implementations for aubio_pvoc_get_hop/win
+	* mathutils: increase ln(2) precision of in freqtomidi/miditofreq
+	* wavetable: stop sets playing to 0, add dummy implementation for _load
+
+	[ New features ]
+
+	* src/musicutils.h: new aubio_meltohz, aubio_hztomel, with _htk versions
+	* src/spectral/filterbank.h: new set_mel_coeffs, set_mel_coeffs_htk,
+	set_power, and set_norm methods, improved set_triangle_bands
+	* src/spectral/mfcc.h: new set_scale, set_power, set_norm, set_mel_coeffs,
+	set_mel_coeffs_htk, set_mel_coeffs_slaney
+	* src/mathutils.h: new fvec_mul
+	* src/notes: new option release_drop to prevent missing note-offs (gh-203)
+
+	[ Python module ]
+
+	* fix: rounding to nearest integer in midi2note and freq2note
+	* general: supports code generation of setters with none or multiple
+	parameters
+	* documentation: add docstrings do fvec, cvec, source, sink, pvoc, frequency
+	conversion and level detection routines (gh-73, debian #480018)
+	* slicing: improve and document slice_source_at_stamps
+	* module: new note2freq function, recover error log when raising exceptions
+	on failed set_ methods, prevent cyclic import, coding style improvements
+	* demos: improve coding style, fix bpm_extract arguments
+	* MANIFEST.in: exclude *.pyc, improve patterns
+
+	[ Documentation ]
+
+	* doc/: use sphinx autodoc to load docstrings from aubio module, reorganize
+	python module documentation, add a note about double precision, use https
+	when possible
+	* src/spectral/: update Auditory Toolbox url, update copyright year
+
+	[ Tools ]
+
+	* aubionotes: add --release-drop option
+	* aubio: add --release-drop and --silence options to `aubio notes`,
+	workaround for -V to really show version (py2)
+	* aubiocut: add option --create-first to always create first slice
+
+	[ Tests ]
+
+	* tests/, python/tests: add tests for new methods, check source channel
+	down-mix, improve coverage
+
+	[ Build system ]
+
+	* Makefile: disable docs when measuring coverage, add branch coverage
+	option, add coverage_zero_counters target, improve html report
+	* waf: update to 2.0.12, improve wscript style, prevent shipping some
+	generated files
+	* python: always show compiler warnings when pre-processing headers,
+	workaround to fix code generation for win-amd64 (gh-154, gh-199, gh-208).
+	* continuous integration: add azure pipelines, update and improve
+	configurations for appveyor, circleci, and travis.
+
 2018-09-22 Paul Brossier <piem@aubio.org>
 
 	[ Overview ]
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,6 +1,7 @@
 include AUTHORS COPYING README.md VERSION ChangeLog
 include python/README.md
 include this_version.py
+include waf_gensyms.py
 include waf
 recursive-include waflib *.py
 include Makefile wscript */wscript_build
--- a/Makefile
+++ b/Makefile
@@ -42,6 +42,8 @@
 
 TESTSOUNDS := python/tests/sounds
 
+LCOVOPTS += --rc lcov_branch_coverage=1
+
 all: build
 
 checkwaf:
@@ -243,22 +245,36 @@
 coverage: export LD_LIBRARY_PATH=$(PWD)/build/src
 coverage: force_uninstall_python deps_python \
 	clean_python clean distclean build local_dylib
-	lcov --capture --no-external --directory . --output-file build/coverage_lib.info
+	# capture coverage after running c tests
+	lcov $(LCOVOPTS) --capture --no-external --directory . \
+		--output-file build/coverage_lib.info
+	# build and test python
 	pip install -v -e .
+	# run tests, with python coverage
 	coverage run `which pytest`
-	lcov --capture --no-external --directory . --output-file build/coverage_python.info
-	lcov -a build/coverage_python.info -a build/coverage_lib.info -o build/coverage.info
+	# capture coverage again
+	lcov $(LCOVOPTS) --capture --no-external --directory . \
+		--output-file build/coverage_python.info
+	# merge both coverage info files
+	lcov $(LCOVOPTS) -a build/coverage_python.info -a build/coverage_lib.info \
+		--output-file build/coverage.info
+	# remove tests
+	lcov $(LCOVOPTS) --remove build/coverage.info '*/tests/*' '*/ooura_fft8g*' \
+		--output-file build/coverage_lib.info
 
 # make sure we don't build the doc, which builds a temporary python module
 coverage_report: export WAFOPTS += --disable-docs
 coverage_report: coverage
-	genhtml build/coverage.info --output-directory lcov_html
-	mkdir -p gcovr_html/
-	gcovr -r . --html --html-details \
-		--output gcovr_html/index.html \
-		--exclude ".*tests/.*" --exclude ".*examples/.*"
+	# create coverage report dir
+	mkdir -p build/coverage/
+	# generate report with lcov's genhtml
+	genhtml build/coverage_lib.info --output-directory build/coverage/lcov \
+		--branch-coverage --highlight --legend
+	# generate python report with coverage python package
 	coverage report
-	coverage html
+	coverage html -d build/coverage/coverage
+	# show links to generated reports
+	for i in $$(ls build/coverage/*/index.html); do echo file://$(PWD)/$$i; done
 
 sphinx: configure
 	$(WAFCMD) sphinx $(WAFOPTS)
--- a/VERSION
+++ b/VERSION
@@ -1,7 +1,7 @@
 AUBIO_MAJOR_VERSION=0
 AUBIO_MINOR_VERSION=4
 AUBIO_PATCH_VERSION=8
-AUBIO_VERSION_STATUS='~alpha'
+AUBIO_VERSION_STATUS=''
 LIBAUBIO_LT_CUR=5
-LIBAUBIO_LT_REV=3
-LIBAUBIO_LT_AGE=7
+LIBAUBIO_LT_REV=4
+LIBAUBIO_LT_AGE=8
--- a/doc/aubiocut.txt
+++ b/doc/aubiocut.txt
@@ -50,6 +50,8 @@
   --cut-until-nslices n  How many extra slices should be added at the end of
   each slice (default 0).
 
+  --create-first  Alway create first slice.
+
   -h, --help  Print a short help message and exit.
 
   -v, --verbose  Be verbose.
--- a/doc/python_module.rst
+++ b/doc/python_module.rst
@@ -3,28 +3,50 @@
 Installing aubio for Python
 ===========================
 
-The aubio extension for Python is available for Python 2.7 and Python 3.
+aubio is available as a package for Python 2.7 and Python 3. The aubio
+extension is written C using the `Python/C`_ and the `Numpy/C`_ APIs.
 
+.. _Python/C: https://docs.python.org/c-api/index.html
+.. _Numpy/C: https://docs.scipy.org/doc/numpy/reference/c-api.html
+
+For general documentation on how to install Python packages, see `Installing
+Packages`_.
+
 Installing aubio with pip
 -------------------------
 
-aubio can now be installed using ``pip``:
+aubio can be installed from `PyPI`_ using ``pip``:
 
 .. code-block:: console
 
     $ pip install aubio
 
-Building the module
--------------------
+See also `Installing from PyPI`_ for general documentation.
 
-From ``aubio`` source directory, run the following:
+.. note::
 
+  aubio is currently a `source only`_ package, so you will need a compiler to
+  install it from `PyPI`_. See also `Installing aubio with conda`_ for
+  pre-compiled binaries.
+
+.. _PyPI: https://pypi.python.org/pypi/aubio
+.. _Installing Packages: https://packaging.python.org/tutorials/installing-packages/
+.. _Installing from PyPI: https://packaging.python.org/tutorials/installing-packages/#installing-from-pypi
+.. _source only: https://packaging.python.org/tutorials/installing-packages/#source-distributions-vs-wheels
+
+Installing aubio with conda
+---------------------------
+
+`Conda packages`_ are available through the `conda-forge`_ channel for Linux,
+macOS, and Windows:
+
 .. code-block:: console
 
-    $ ./setup.py clean
-    $ ./setup.py build
-    $ sudo ./setup.py install
+    $ conda config --add channels conda-forge
+    $ conda install -c conda-forge aubio
 
+.. _Conda packages: https://anaconda.org/conda-forge/aubio
+.. _conda-forge: https://conda-forge.org/
 
 .. _py-doubleprecision:
 
@@ -67,14 +89,15 @@
 Python tests
 ------------
 
-A number of python tests are provided. To run them, use [pytest] from the
-aubio source tree:
+A number of Python tests are provided in the `python/tests`_ folder. To run
+them, install `pytest`_ and run it from the aubio source directory:
 
+.. code-block:: console
+
+    $ pip install pytest
+    $ git clone https://git.aubio.org/aubio/aubio
     $ cd aubio
     $ pytest
 
-Each test script can also be called individually. For instance:
-
-    $ ./python/tests/test_note2midi.py -v
-
-[pytest]: https://pytest.org
+.. _python/tests: https://github.com/aubio/aubio/blob/master/python/tests
+.. _pytest: https://pytest.org
--- a/doc/requirements.rst
+++ b/doc/requirements.rst
@@ -302,10 +302,38 @@
 Double precision
 ................
 
+The datatype used to store real numbers in aubio is named `smpl_t`. By default,
+`smpl_t` is defined as `float`, a `single-precision format
+<https://en.wikipedia.org/wiki/Single-precision_floating-point_format>`_
+(32-bit).  Some algorithms require a floating point representation with a
+higher precision, for instance to prevent arithmetic underflow in recursive
+filters.  In aubio, these special samples are named `lsmp_t` and defined as
+`double` by default (64-bit).
+
+Sometimes it may be useful to compile aubio in `double-precision`, for instance
+to reproduce numerical results obtained with 64-bit routines. In this case,
+`smpl_t` will be defined as `double`.
+
+The following table shows how `smpl_t` and `lsmp_t` are defined in single- and
+double-precision modes:
+
+.. list-table:: Single and double-precision modes
+   :align: center
+
+   * -
+     - single
+     - double
+   * - `smpl_t`
+     - ``float``
+     - ``double``
+   * - `lsmp_t`
+     - ``double``
+     - ``long double``
+
 To compile aubio in double precision mode, configure with ``--enable-double``.
 
-To compile aubio in single precision mode, use ``--disable-double`` (default,
-recommended).
+To compile in single-precision mode (default), use ``--disable-double`` (or
+simply none of these two options).
 
 Disabling the tests
 ...................
--- a/python/README.md
+++ b/python/README.md
@@ -1,105 +1,109 @@
-Python aubio module
-===================
+aubio
+=====
 
-This module wraps the aubio library for Python using the numpy module.
+aubio is a collection of tools for music and audio analysis.
 
-Using the Python aubio module
------------------------------
+This package integrates the aubio library with [NumPy] to provide a set of
+efficient tools to process and analyse audio signals, including:
 
-After installing python-aubio, you will be able to import the aubio module:
+- read audio from any media file, including videos and remote streams
+- high quality phase vocoder, spectral filterbanks, and linear filters
+- Mel-Frequency Cepstrum Coefficients and standard spectral descriptors
+- detection of note attacks (onset)
+- pitch tracking (fundamental frequency estimation)
+- beat detection and tempo tracking
 
-    $ python
-    [...]
-    >>> import aubio
-    >>> help(aubio.miditofreq)
+aubio works with both Python 2 and Python 3.
 
-Finding some inspiration
-------------------------
+Links
+-----
 
-Some examples are available in the `python/demos` directory. These scripts are
-small programs written in python and using python-aubio.
+- [module documentation][doc_python]
+- [installation instructions][doc_python_install]
+- [aubio manual][manual]
+- [aubio homepage][homepage]
+- [issue tracker][bugtracker]
 
-For instance, `demo_source.py` reads a media file.
+Demos
+-----
 
-    $ ./python/demos/demo_source.py /path/to/sound/sample.wav
+Some examples are available in the [`python/demos`][demos_dir] folder. Each
+script is a command line program which accepts one ore more argument.
 
-and `demo_timestretch_online.py` stretches the original file into a new one:
+**Notes**: installing additional modules is required to run some of the demos.
 
-    $ ./python/demo/demo_timestretch_online.py loop.wav stretched_loop.wav 0.92`
+### Analysis
 
-Note: you might need to install additional modules to run some of the demos.
-Some demos use [matplotlib](http://matplotlib.org/) to draw plots, others use
-[PySoundCard](https://github.com/bastibe/PySoundCard) to play and record
-sounds.
+- `demo_source.py` uses aubio to read audio samples from media files
+- `demo_onset_plot.py` detects attacks in a sound file and plots the results
+  using [matplotlib]
+- `demo_pitch.py` looks for fundamental frequency in a sound file and plots the
+  results using [matplotlib]
+- `demo_spectrogram.py`, `demo_specdesc.py`, `demo_mfcc.py` for spectral
+  analysis.
 
-Testing the Python module
--------------------------
+### Real-time
 
-Python tests are in `python/tests` and use [pytest].
+- `demo_pyaudio.py` and `demo_tapthebeat.py` use [pyaudio]
+- `demo_pysoundcard_play.py`, `demo_pysoundcard.py` use [PySoundCard]
+- `demo_alsa.py` uses [pyalsaaudio]
 
-To run the all the python tests:
+### Others
 
-    $ cd aubio
-    $ pytest
+- `demo_timestretch.py` can change the duration of an input file and write the
+  new sound to disk,
+- `demo_wav2midi.py` detects the notes in a file and uses [mido] to write the
+  results into a MIDI file
 
-Each test script can also be called one at a time. For instance:
+### Example
 
-    $ pytest -v python/tests/test_note2midi.py
+Use `demo_timestretch_online.py` to slow down `loop.wav`, write the results in
+`stretched_loop.wav`:
 
-[pytest]: https://pytest.org
+    $ python demo_timestretch_online.py loop.wav stretched_loop.wav 0.92
 
-Install in a virtualenv
------------------------
+Built with
+----------
 
-You should be able to install python-aubio directly from the top source
-directory of aubio.
+The core of aubio is written in C for portability and speed. In addition to
+[NumPy], aubio can be optionally built to use one or more of the following
+libraries:
 
-First, create a virtualenv to hold the required python module:
+- media file reading:
 
-    $ virtualenv pyaubio
-    $ source pyaubio/bin/activate
+    - [ffmpeg] / [avcodec] to decode and read audio from almost any format,
+    - [libsndfile] to read audio from uncompressed sound files,
+    - [libsamplerate] to re-sample audio signals,
+    - [CoreAudio] to read all media formats supported by macOS, iOS, and tvOS.
 
-Now install and build the python extension using:
+- hardware acceleration:
 
-    $ pip install .
+    - [Atlas] and [Blas], for accelerated vector and matrix computations,
+    - [fftw3], to compute fast Fourier Transforms of any size,
+    - [Accelerate] for accelerated FFT and matrix computations (macOS/iOS),
+    - [Intel IPP], accelerated vector computation and FFT implementation.
 
-Install requirements
---------------------
+[ffmpeg]: https://ffmpeg.org
+[avcodec]: https://libav.org
+[libsndfile]: http://www.mega-nerd.com/libsndfile/
+[libsamplerate]: http://www.mega-nerd.com/SRC/
+[CoreAudio]: https://developer.apple.com/reference/coreaudio
+[Atlas]: http://math-atlas.sourceforge.net/
+[Blas]: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms
+[fftw3]: http://fftw.org
+[Accelerate]: https://developer.apple.com/reference/accelerate
+[Intel IPP]: https://software.intel.com/en-us/intel-ipp
 
-Before compiling this module, you must have compiled libaubio.
+[demos_dir]:https://github.com/aubio/aubio/tree/master/python/demos
+[pyaudio]:https://people.csail.mit.edu/hubert/pyaudio/
+[PySoundCard]:https://github.com/bastibe/PySoundCard
+[pyalsaaudio]:https://larsimmisch.github.io/pyalsaaudio/
+[mido]:https://mido.readthedocs.io
 
-A simple way to do this is with pip:
-
-    $ pip install -r requirements.txt
-
-For more information about how this module works, please refer to the [Python/C
-API Reference Manual] (http://docs.python.org/c-api/index.html) and the
-[Numpy/C API Reference](http://docs.scipy.org/doc/numpy/reference/c-api.html).
-
-Compiling python aubio
-----------------------
-
-To build the aubio Python module, run the following command from the top source
-directory of aubio:
-
-    $ ./setup.py build
-
-Note: if libaubio was previously built using waf, the script will use it.
-Otherwise, the entire library will be built inside the python extension.
-
-To find out more about `setup.py` options:
-
-    $ ./setup.py --help
-
-Installing
-----------
-
-To install the Python module:
-
-    $ ./setup.py install
-
-Alternatively, you may want to use the Python module without installing it by
-setting your PYTHONPATH, for instance as follows:
-
-    $ export PYTHONPATH=$PYTHONPATH:$PWD/`ls -rtd build/lib.* | head -1`:$PWD/tests
-
+[manual]: https://aubio.org/manual/latest/
+[doc_python]: https://aubio.org/manual/latest/python.html
+[doc_python_install]: https://aubio.org/manual/latest/python_module.html
+[homepage]: https://aubio.org
+[NumPy]: https://www.numpy.org
+[bugtracker]: https://github.com/aubio/aubio/issues
+[matplotlib]:https://matplotlib.org/
--- a/python/tests/test_source_channels.py
+++ b/python/tests/test_source_channels.py
@@ -8,7 +8,7 @@
 import aubio
 import numpy as np
 from numpy.testing import assert_equal
-from utils import get_tmp_sink_path
+from .utils import get_tmp_sink_path
 
 class aubio_source_test_case(unittest.TestCase):
 
--- a/setup.py
+++ b/setup.py
@@ -62,6 +62,11 @@
     'GNU General Public License v3 or later (GPLv3+)',
     ]
 
+thisdir = os.path.abspath(os.path.dirname(__file__))
+py_readme_file = os.path.join(thisdir, 'python', 'README.md')
+with open(py_readme_file, 'r') as fp:
+    long_description = ''.join(fp.readlines()[3:])
+
 distrib = setup(name='aubio',
     version = __version__,
     packages = ['aubio'],
@@ -68,7 +73,8 @@
     package_dir = {'aubio': 'python/lib/aubio'},
     ext_modules = [aubio_extension],
     description = 'a collection of tools for music analysis',
-    long_description = 'a collection of tools for music analysis',
+    long_description = long_description,
+    long_description_content_type = 'text/markdown',
     license = 'GNU/GPL version 3',
     author = 'Paul Brossier',
     author_email = 'piem@aubio.org',
--- a/src/spectral/mfcc.h
+++ b/src/spectral/mfcc.h
@@ -152,7 +152,6 @@
 /** Mel filterbank initialization (Auditory Toolbox's parameters)
 
   \param mf mfcc object
-  \param samplerate audio sampling rate, in Hz
 
   The filter coefficients are built to match exactly Malcolm Slaney's Auditory
   Toolbox implementation. The number of filters should be 40.
--- a/src/synth/wavetable.c
+++ b/src/synth/wavetable.c
@@ -167,6 +167,13 @@
   return aubio_wavetable_set_playing (s, 0);
 }
 
+uint_t
+aubio_wavetable_load ( aubio_wavetable_t *s UNUSED, const char_t *uri UNUSED)
+{
+  AUBIO_ERR("wavetable: load method not implemented yet, see sampler\n");
+  return AUBIO_FAIL;
+}
+
 uint_t aubio_wavetable_set_freq ( aubio_wavetable_t * s, smpl_t freq )
 {
   return aubio_parameter_set_target_value ( s->freq, freq );
--- a/src/synth/wavetable.h
+++ b/src/synth/wavetable.h
@@ -51,6 +51,18 @@
 */
 aubio_wavetable_t * new_aubio_wavetable(uint_t samplerate, uint_t hop_size);
 
+/** load source in wavetable
+
+  TODO: This function is not implemented yet. See new_aubio_sampler() instead.
+
+  \param o wavetable, created by new_aubio_wavetable()
+  \param uri the uri of the source to load
+
+  \return 0 if successful, non-zero otherwise
+
+*/
+uint_t aubio_wavetable_load( aubio_wavetable_t * o, const char_t * uri );
+
 /** process wavetable function
 
   \param o wavetable, created by new_aubio_wavetable()
--- a/wscript
+++ b/wscript
@@ -618,6 +618,7 @@
     ctx.excl += ' **/python/*.db'
     ctx.excl += ' **/python.old/*'
     ctx.excl += ' **/python/*/*.old'
+    ctx.excl += ' **/python/lib/aubio/*.so'
     ctx.excl += ' **/python/tests/sounds'
     ctx.excl += ' **/**.asc'
     ctx.excl += ' **/dist*'
@@ -627,4 +628,4 @@
     ctx.excl += ' **/.appveyor.yml'
     ctx.excl += ' **/.circleci/*'
     ctx.excl += ' **/azure-pipelines.yml'
-    ctx.excl += ' **/.coveragerc'
+    ctx.excl += ' **/.coverage*'