annotate vamp/__init__.py @ 151:5a6b8f4be9b9 tracks tip

Docs
author Chris Cannam
date Fri, 21 Apr 2017 14:33:57 +0100
parents c64295f1cc33
children
rev   line source
Chris@117 1 #!/usr/bin/env python
Chris@117 2
Chris@117 3 # Python Vamp Host
Chris@117 4 # Copyright (c) 2008-2015 Queen Mary, University of London
Chris@117 5 #
Chris@117 6 # Permission is hereby granted, free of charge, to any person
Chris@117 7 # obtaining a copy of this software and associated documentation
Chris@117 8 # files (the "Software"), to deal in the Software without
Chris@117 9 # restriction, including without limitation the rights to use, copy,
Chris@117 10 # modify, merge, publish, distribute, sublicense, and/or sell copies
Chris@117 11 # of the Software, and to permit persons to whom the Software is
Chris@117 12 # furnished to do so, subject to the following conditions:
Chris@117 13 #
Chris@117 14 # The above copyright notice and this permission notice shall be
Chris@117 15 # included in all copies or substantial portions of the Software.
Chris@117 16 #
Chris@117 17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@117 18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@117 19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@117 20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
Chris@117 21 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@117 22 # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@117 23 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@117 24 #
Chris@117 25 # Except as contained in this notice, the names of the Centre for
Chris@117 26 # Digital Music and Queen Mary, University of London shall not be
Chris@117 27 # used in advertising or otherwise to promote the sale, use or other
Chris@117 28 # dealings in this Software without prior written authorization.
Chris@117 29
Chris@129 30 '''
Chris@129 31 Python Vamp plugin host
Chris@129 32 =======================
Chris@129 33
Chris@129 34 This module allows Python code to load and use native-code Vamp
Chris@129 35 plugins (http://vamp-plugins.org) for audio feature analysis.
Chris@129 36
Chris@129 37 The module consists of a native-code extension ("vampyhost") that
Chris@129 38 provides a low-level wrapper for the Vamp plugin SDK, along with a
Chris@129 39 Python wrapper ("vamp") that provides a higher-level abstraction.
Chris@129 40
Chris@129 41 No code for loading audio files is included; you'll need to use some
Chris@129 42 other module for that. This code expects to receive decoded audio data
Chris@129 43 of one or more channels, either as a series of frames or as a single
Chris@129 44 whole buffer.
Chris@129 45
Chris@129 46 Written by Chris Cannam and George Fazekas at the Centre for Digital
Chris@129 47 Music, Queen Mary University of London. Copyright 2008-2015 Queen
Chris@129 48 Mary, University of London. Refer to COPYING.rst for licence details.
Chris@129 49
Chris@129 50 See home page at https://code.soundsoftware.ac.uk/projects/vampy-host
Chris@129 51 for more details.
Chris@129 52
Chris@129 53
Chris@129 54 A simple example
Chris@129 55 ----------------
Chris@129 56
Chris@129 57 Using librosa (http://bmcfee.github.io/librosa/) to read an audio
Chris@129 58 file, and the NNLS Chroma Vamp plugin
Chris@129 59 (https://code.soundsoftware.ac.uk/projects/nnls-chroma/) for
Chris@129 60 analysis::
Chris@129 61
Chris@129 62 >>> import vamp
Chris@129 63 >>> import librosa
Chris@129 64 >>> data, rate = librosa.load("example.wav")
Chris@129 65 >>> chroma = vamp.collect(data, rate, "nnls-chroma:nnls-chroma")
Chris@129 66 >>> chroma
Chris@129 67 {'matrix': ( 0.092879819, array([[ 61.0532608 , 60.27478409, 59.3938446 , ..., 182.13394165,
Chris@129 68 42.40084457, 116.55457306],
Chris@129 69 [ 68.8901825 , 63.98115921, 60.77633667, ..., 245.88218689,
Chris@129 70 68.51251984, 164.70120239],
Chris@129 71 [ 58.59794617, 50.3429184 , 45.44804764, ..., 258.02362061,
Chris@129 72 83.95749664, 179.91200256],
Chris@129 73 ...,
Chris@129 74 [ 0. , 0. , 0. , ..., 0. ,
Chris@129 75 0. , 0. ],
Chris@129 76 [ 0. , 0. , 0. , ..., 0. ,
Chris@129 77 0. , 0. ],
Chris@129 78 [ 0. , 0. , 0. , ..., 0. ,
Chris@129 79 0. , 0. ]], dtype=float32))}
Chris@129 80 >>> stepsize, chromadata = chroma["matrix"]
Chris@129 81 >>> import matplotlib.pyplot as plt
Chris@129 82 >>> plt.imshow(chromadata)
Chris@129 83 <matplotlib.image.AxesImage object at 0x7fe9e0043fd0>
Chris@129 84 >>> plt.show()
Chris@129 85
Chris@129 86 And a pitch-chroma plot appears.
Chris@129 87
Chris@129 88
Chris@129 89 High-level interface (vamp)
Chris@129 90 ---------------------------
Chris@129 91
Chris@129 92 This module contains three sorts of function:
Chris@129 93
Chris@132 94 1. Basic info and lookup functions
Chris@132 95 """"""""""""""""""""""""""""""""""
Chris@129 96
Chris@129 97 * ``vamp.list_plugins``
Chris@129 98 * ``vamp.get_outputs_of``
Chris@144 99 * ``vamp.get_parameters_of``
Chris@129 100 * ``vamp.get_category_of``
Chris@129 101
Chris@129 102 These retrieve the installed plugin keys and get basic information
Chris@129 103 about each plugin. (For more detailed information, load a plugin
Chris@129 104 and inspect it using the low-level interface described below.)
Chris@129 105
Chris@132 106 2. Process functions
Chris@132 107 """"""""""""""""""""
Chris@129 108
Chris@129 109 * ``vamp.process_audio``
Chris@129 110 * ``vamp.process_frames``
Chris@129 111 * ``vamp.process_audio_multiple_outputs``
Chris@129 112 * ``vamp.process_frames_multiple_outputs``
Chris@129 113
Chris@129 114 These accept audio input, and produce output in the form of a list
Chris@129 115 of feature sets structured similarly to those in the C++ Vamp
Chris@129 116 plugin SDK. The plugin to be used is specified by its key (the
Chris@129 117 identifier as returned by ``vamp.list_plugins``). A dictionary of
Chris@129 118 plugin parameter settings may optionally be supplied.
Chris@129 119
Chris@129 120 The ``_audio`` versions take a single (presumably long) array of
Chris@129 121 audio samples as input, and chop it into frames according to the
Chris@129 122 plugin's preferred step and block sizes. The ``_frames`` versions
Chris@129 123 instead accept an enumerable sequence of audio frame arrays.
Chris@129 124
Chris@132 125 3. The process-and-collect function
Chris@132 126 """""""""""""""""""""""""""""""""""
Chris@132 127
Chris@129 128 * ``vamp.collect``
Chris@129 129
Chris@129 130 This accepts a single array of audio samples as input, and returns
Chris@129 131 an output structure that reflects the underlying structure of the
Chris@129 132 feature output (depending on whether it is a curve, grid, etc). The
Chris@129 133 plugin to be used is specified by its key. A dictionary of plugin
Chris@129 134 parameter settings may optionally be supplied.
Chris@129 135
Chris@129 136 The ``collect`` function processes the whole input before returning
Chris@129 137 anything; if you need to supply a streamed input, or retrieve
Chris@129 138 results as they are calculated, then you must use one of the
Chris@129 139 ``process`` functions (above) or else the low-level interface
Chris@129 140 (below).
Chris@129 141
Chris@129 142
Chris@129 143 Low-level interface (vampyhost)
Chris@129 144 -------------------------------
Chris@129 145
Chris@129 146 This extension contains facilities that operate on Vamp plugins in a
Chris@129 147 way analogous to the existing C++ Vamp Host SDK: ``list_plugins``,
Chris@129 148 ``get_plugin_path``, ``get_category_of``, ``get_library_for``,
Chris@129 149 ``get_outputs_of``, ``load_plugin``, and a utility function
Chris@129 150 ``frame_to_realtime``.
Chris@129 151
Chris@129 152 Calling ``load_plugin`` gets you a ``vampyhost.Plugin`` object, which
Chris@129 153 then exposes all of the methods found in the Vamp SDK Plugin class.
Chris@129 154
Chris@129 155 (Note that methods wrapped directly from the Vamp SDK are named using
Chris@129 156 camelCase, so as to match the names found in the C++ SDK. Elsewhere
Chris@129 157 this module follows Python PEP8 naming.)
Chris@129 158
Chris@129 159 See the individual module and function documentation for further
Chris@129 160 details.
Chris@129 161
Chris@124 162 '''
Chris@56 163
Chris@75 164 import vampyhost
Chris@68 165
Chris@144 166 from vamp.load import list_plugins, get_outputs_of, get_parameters_of, get_category_of
Chris@117 167 from vamp.process import process_audio, process_frames, process_audio_multiple_outputs, process_frames_multiple_outputs
Chris@112 168 from vamp.collect import collect
Chris@95 169