fazekasgy@37
|
1
|
fazekasgy@58
|
2 * Vampy is a wrapper for the Vamp audio analysis plugin API.
|
fazekasgy@58
|
3 (http://www.vamp-plugins.org/) It allows for writing Vamp
|
fazekasgy@58
|
4 plugins in Python.
|
fazekasgy@37
|
5
|
fazekasgy@38
|
6
|
fazekasgy@37
|
7 WHAT IS IT FOR?
|
fazekasgy@58
|
8
|
fazekasgy@58
|
9 Vamp is an audio analysis and feature extraction plugin system
|
fazekasgy@58
|
10 with a C/C++ Application Programming Interface (API).
|
fazekasgy@58
|
11
|
fazekasgy@58
|
12 Typical applications of Vamp plugins include visualisation, using
|
fazekasgy@58
|
13 a host such as Sonic Visualiser (http://www.sonicvisualiser.org/),
|
fazekasgy@58
|
14 or batch feature extraction from audio, using Sonic Annotator
|
fazekasgy@58
|
15 (http://www.omras2.org/SonicAnnotator).
|
fazekasgy@58
|
16
|
fazekasgy@58
|
17 Vamp plugins are typically written in C++. Although currently
|
fazekasgy@58
|
18 available plugin hosts are valuable tools in audio research,
|
fazekasgy@58
|
19 the long and tedious development cycle of plugins does not
|
fazekasgy@58
|
20 support quick prototyping of feature extraction algorithms.
|
fazekasgy@58
|
21 Learning the extra skills needed for plugin development or using
|
fazekasgy@58
|
22 scientific libraries available for C and C++ is often outside
|
fazekasgy@58
|
23 the interest of audio researches typically using MATLAB or other
|
fazekasgy@58
|
24 high-level development environments.
|
fazekasgy@37
|
25
|
fazekasgy@58
|
26 This package aims at easing Vamp plugin development, prototyping
|
fazekasgy@58
|
27 or deployment by using the high-level Python scripting language.
|
fazekasgy@37
|
28
|
fazekasgy@37
|
29
|
fazekasgy@37
|
30 WHY PYTHON?
|
fazekasgy@58
|
31
|
fazekasgy@58
|
32 The Python programming language is rapidly gaining popularity
|
fazekasgy@58
|
33 in the scientific community. Besides being a high-productivity
|
fazekasgy@58
|
34 interpreted language, it has extensions for scientific computing
|
fazekasgy@58
|
35 such as Numpy, an efficient numerical library and SciPy, a
|
fazekasgy@58
|
36 collection of Python modules for signal processing,
|
fazekasgy@58
|
37 linear algebra, statistics and machine learning ...
|
fazekasgy@58
|
38 (www.SciPy.org). These packages together with matplotlib
|
fazekasgy@58
|
39 (http://matplotlib.sourceforge.net/) provide similar capabilities
|
fazekasgy@58
|
40 to most commercial modelling environments. As a further advantage,
|
fazekasgy@58
|
41 Python is a general purpose language which also supports
|
fazekasgy@58
|
42 the functional programming style.
|
fazekasgy@37
|
43
|
fazekasgy@58
|
44
|
fazekasgy@58
|
45 HOW DOES IT WORK?
|
fazekasgy@58
|
46
|
fazekasgy@58
|
47 Vampy acts like a bridge between a Vamp plugin host application
|
fazekasgy@58
|
48 and Python scripts. It translates host function calls to Python
|
fazekasgy@58
|
49 interpreter calls and converts Python data types to C++ and Vamp
|
fazekasgy@58
|
50 defined data structures.
|
fazekasgy@58
|
51
|
fazekasgy@58
|
52 Vampy is distributed and can be installed like any other ordinary
|
fazekasgy@58
|
53 Vamp plugin. When it is installed, any appropriately structured
|
fazekasgy@58
|
54 Python script in its script directory will be presented to
|
fazekasgy@58
|
55 host programs as if they were native Vamp plugins written in C++.
|
fazekasgy@58
|
56
|
fazekasgy@58
|
57 Vampy embeds the Python interpreter dynamically, and also extends
|
fazekasgy@58
|
58 it with data types defined by the Vamp C++ API, all within a
|
fazekasgy@58
|
59 single shared library.
|
fazekasgy@58
|
60
|
fazekasgy@58
|
61
|
fazekasgy@58
|
62 OBTAINING VAMPY:
|
fazekasgy@58
|
63
|
fazekasgy@58
|
64 Vampy is a free, cross platform, open source package. The source
|
fazekasgy@58
|
65 code is available from the Vamp-Plugins subversion repository
|
fazekasgy@58
|
66 on SourceForge. (http://vamp.svn.sourceforge.net/)
|
fazekasgy@58
|
67
|
fazekasgy@58
|
68 * Binary distributions are available for Windows, Mac OS/X,
|
fazekasgy@58
|
69 Linux and Solaris Unix.
|
fazekasgy@58
|
70
|
fazekasgy@58
|
71 * The source code can be obtained using the SVN command:
|
fazekasgy@58
|
72 svn co https://vamp.svn.sourceforge.net/svnroot/vamp/vamp-vampy vampy
|
fazekasgy@58
|
73
|
fazekasgy@58
|
74
|
fazekasgy@58
|
75 DEPENDENCIES:
|
fazekasgy@58
|
76
|
fazekasgy@58
|
77 * Vampy requires Python 2.5 or greater.
|
fazekasgy@58
|
78
|
fazekasgy@58
|
79 Note that Vampy does not support the new flavour of Python (3.x)
|
fazekasgy@58
|
80 which breaks language compatibility with the 2.x series.
|
fazekasgy@58
|
81
|
fazekasgy@58
|
82 * Vampy supports Numpy 1.1. or greater.
|
fazekasgy@58
|
83
|
fazekasgy@58
|
84 Using Numpy is optional, however writing plugins in pure Python
|
fazekasgy@58
|
85 results in significantly longer processing times.
|
fazekasgy@58
|
86
|
fazekasgy@58
|
87
|
fazekasgy@58
|
88 BUILDING VAMPY:
|
fazekasgy@58
|
89
|
fazekasgy@58
|
90 It is advised to use a binary distribution if available for
|
fazekasgy@58
|
91 your platform and Python/Numpy versions before attempting to
|
fazekasgy@58
|
92 compile it from source. If you decide to do so, please use the
|
fazekasgy@58
|
93 make files provided. Make sure the correct include locations
|
fazekasgy@58
|
94 are set for Python, Numpy, and the Vamp plugin SDK.
|
fazekasgy@58
|
95
|
fazekasgy@58
|
96
|
fazekasgy@58
|
97 COMPILER OPTIONS:
|
fazekasgy@58
|
98
|
fazekasgy@58
|
99 HAVE_NUMPY : compile with Numpy array interface support
|
fazekasgy@58
|
100
|
fazekasgy@58
|
101 NUMPY_SHORTVERSION : set to the minimum version of Numpy you have,
|
fazekasgy@58
|
102 as a floating-point value; the default is 1.1, which should be
|
fazekasgy@58
|
103 OK for using the plugin with Numpy 1.1, 1.2 and 1.3
|
fazekasgy@58
|
104
|
fazekasgy@58
|
105 simple debugging (for developers):
|
fazekasgy@58
|
106 _DEBUG : print more detailed messages while Vampy is in use
|
fazekasgy@58
|
107 _DEBUG_VALUES : print all converted values to stderr
|
fazekasgy@37
|
108
|
fazekasgy@38
|
109
|
fazekasgy@38
|
110 UPDATES IN THIS VERSION (Vampy 2.0):
|
fazekasgy@37
|
111
|
fazekasgy@58
|
112 * More complete, two-way Numpy support
|
fazekasgy@37
|
113 * Embedded extension module exposing Vamp defined names
|
fazekasgy@37
|
114 e.g. ParameterDescriptor. This allows easier porting to C++.
|
fazekasgy@37
|
115 * Support RealTime time stamps
|
fazekasgy@37
|
116 * Support byte compiled Python scripts (.pyc)
|
fazekasgy@58
|
117 * Environment variables
|
fazekasgy@58
|
118 * Flags to control how Vampy works with each plugin
|
fazekasgy@58
|
119 * Flexible type inference to take advantage of dynamic typing
|
fazekasgy@58
|
120 * More complete error checking for all Python/C API calls
|
fazekasgy@37
|
121 * Various optimisations and speed-ups
|
fazekasgy@38
|
122
|
fazekasgy@38
|
123 Vampy now supports two main use cases:
|
fazekasgy@38
|
124 1) Prototyping C++ Vamp plugins in Python.
|
fazekasgy@38
|
125 2) Develop Vampy plugins in Python to allow the use of a vamp
|
fazekasgy@38
|
126 hosts for e.g. batch processing or visualisation.
|
fazekasgy@38
|
127
|
fazekasgy@38
|
128 Vampy provides an extension module which allows the use of
|
fazekasgy@58
|
129 data types defined in the Vamp API; such as FeatureSet() or
|
fazekasgy@58
|
130 RealTime() in Vampy plugins.
|
fazekasgy@37
|
131
|
fazekasgy@37
|
132
|
fazekasgy@58
|
133 BACKWARD COMPATIBILITY (Read this if you used Vampy 1):
|
fazekasgy@58
|
134
|
fazekasgy@58
|
135 This is the second version of Vampy. It is largely compatible
|
fazekasgy@58
|
136 with the previous version and it is able to run plugins
|
fazekasgy@58
|
137 written for it. However, due to some bug fixes in this release,
|
fazekasgy@58
|
138 it may be required to modify old plugins to work correctly
|
fazekasgy@58
|
139 with Vampy 2.0:
|
fazekasgy@58
|
140
|
fazekasgy@58
|
141 * The size of the input buffers of frequency domain plugins
|
fazekasgy@58
|
142 are now longer by one element corresponding to the Nyquist
|
fazekasgy@58
|
143 frequency output of the FFT.
|
fazekasgy@58
|
144
|
fazekasgy@58
|
145 * The legacy interface now uses complex numbers to pass the
|
fazekasgy@58
|
146 FFT output to frequency domain plugins in Vampy 2.0 instead
|
fazekasgy@58
|
147 of floating point values.
|
fazekasgy@58
|
148
|
fazekasgy@58
|
149 * Consequently, the size of the input buffer for each
|
fazekasgy@58
|
150 audio channel is blockSize/2 + 1 if the legacy interface
|
fazekasgy@58
|
151 is used and blockSize+2 if the buffer interface is used
|
fazekasgy@58
|
152 in frequency domain plugins. Time domain plugins however
|
fazekasgy@58
|
153 do not require any change.
|
fazekasgy@58
|
154
|
fazekasgy@58
|
155 * Vampy 1 had two types of process interfaces; the legacy
|
fazekasgy@58
|
156 and the buffer interface (for Numpy support). They were
|
fazekasgy@58
|
157 selected based on the name of the process method.
|
fazekasgy@58
|
158 A process() implementation used the legacy interface,
|
fazekasgy@58
|
159 a processN() implementation used the Numpy buffer interface.
|
fazekasgy@58
|
160 This behaviour is retained for backward compatibility but
|
fazekasgy@58
|
161 only if no flags are set. The use of processN() is now
|
fazekasgy@58
|
162 obsolete, since the standard process() implementation can
|
fazekasgy@58
|
163 be configured to use any of the available interfaces by
|
fazekasgy@58
|
164 setting the flags appropriately.
|
fazekasgy@37
|
165
|
fazekasgy@38
|
166
|
fazekasgy@58
|
167 USING VAMPY:
|
fazekasgy@38
|
168
|
fazekasgy@58
|
169 (1) Make sure you have Python 2.5 or greater installed and you
|
fazekasgy@58
|
170 have a recent Vamp plugin host application.
|
fazekasgy@58
|
171 (e.g. Sonic Visualier)
|
fazekasgy@38
|
172
|
fazekasgy@58
|
173 (2) Download a version of Vampy compatible with your
|
fazekasgy@58
|
174 operating system and Python distribution.
|
fazekasgy@58
|
175
|
fazekasgy@58
|
176 (3) Unzip the package and copy the shared library
|
fazekasgy@58
|
177 (Windows: vampy.dll, Linux: vampy.so, MacOS: vampy.dylib)
|
fazekasgy@58
|
178 to your Vamp plugin path.
|
fazekasgy@58
|
179
|
fazekasgy@58
|
180 (4) Copy the example plugins (.py files) from the
|
fazekasgy@58
|
181 'Example VamPy plugins' directory to the same place.
|
fazekasgy@58
|
182 (without the example directory itself)
|
fazekasgy@58
|
183
|
fazekasgy@58
|
184 (5) If you are familiar with Python, it is straightforward
|
fazekasgy@58
|
185 to start writing your own plugins by following these examples.
|
fazekasgy@58
|
186
|
fazekasgy@58
|
187 Note: The interpreter automatically generates a compiled version
|
fazekasgy@58
|
188 of each plugin when their source file is first imported. This
|
fazekasgy@58
|
189 file can be distributed alone is so desired. Compiled or compiled
|
fazekasgy@58
|
190 and optimised versions of a plugin can also be obtained using the
|
fazekasgy@58
|
191 'py_compile' standard library module. (Note that Python byte
|
fazekasgy@58
|
192 compiled binaries are easier to reverse than C++ binaries.)
|
fazekasgy@58
|
193
|
fazekasgy@58
|
194 Some familiarity with the Vamp plugin SDK and Vamp Plugin
|
fazekasgy@58
|
195 documentation is assumed before one would start writing a plugin
|
fazekasgy@58
|
196 using Vampy. Only the particularities of Vampy plugins are
|
fazekasgy@58
|
197 covered here. The Vamp plugin documentation is available at:
|
fazekasgy@58
|
198 * http://www.vamp-plugins.org/code-doc/index.html
|
fazekasgy@58
|
199 * http://www.vamp-plugins.org/guide.pdf
|
fazekasgy@58
|
200
|
fazekasgy@58
|
201
|
fazekasgy@58
|
202 BASIC RULES:
|
fazekasgy@58
|
203
|
fazekasgy@58
|
204 Only the Python scripts that follow some basic rules qualify as
|
fazekasgy@58
|
205 Vampy plugins:
|
fazekasgy@58
|
206
|
fazekasgy@58
|
207 (1) Each plugin must contain a single class with the
|
fazekasgy@58
|
208 same name as the script file name.
|
fazekasgy@58
|
209
|
fazekasgy@58
|
210 e.g. PyZeroCrossing.py -> class PyZeroCrossing
|
fazekasgy@58
|
211
|
fazekasgy@58
|
212 (2) Vampy plugins have to be in a specific directory designated
|
fazekasgy@58
|
213 to Vamp plugins. The exact location is platform specific.
|
fazekasgy@58
|
214 Additionally, you can use the VAMPY_EXTPATH environment
|
fazekasgy@58
|
215 variable to specify a separate path for Vampy plugins.
|
fazekasgy@58
|
216
|
fazekasgy@58
|
217 (3) Vampy plugins can be used and distributed as Python scripts
|
fazekasgy@58
|
218 (.py) or byte compiled Python binaries (.pyc / .pyo).
|
fazekasgy@58
|
219
|
fazekasgy@58
|
220 When a script is present with the same name as a compiled
|
fazekasgy@58
|
221 file on any of the valid paths, the script will be preferred.
|
fazekasgy@58
|
222
|
fazekasgy@58
|
223 (4) Vampy may decide to reject some scripts after some basic
|
fazekasgy@58
|
224 validation is performed:
|
fazekasgy@58
|
225
|
fazekasgy@58
|
226 * Scripts with syntax errors in them are ignored.
|
fazekasgy@58
|
227
|
fazekasgy@58
|
228 * Scripts not containing a class with the exact same name
|
fazekasgy@58
|
229 as the file name are ignored. (Python is case sensitive!)
|
fazekasgy@58
|
230
|
fazekasgy@58
|
231 * Scripts with the wrong number of arguments to the plugin
|
fazekasgy@58
|
232 class's __init__() function will be avoided.
|
fazekasgy@58
|
233
|
fazekasgy@58
|
234 (5) Unknown scripts may cause undesired behaviour (or a crash).
|
fazekasgy@58
|
235 Don't put arbitrary Python scripts in your Vamp directory,
|
fazekasgy@58
|
236 you may use a subdirectory for that.
|
fazekasgy@58
|
237
|
fazekasgy@58
|
238
|
fazekasgy@58
|
239 PLUGIN ERRORS:
|
fazekasgy@58
|
240
|
fazekasgy@58
|
241 Script validation is performed by the interpreter itself
|
fazekasgy@58
|
242 using the same rules as module compilation. This means that
|
fazekasgy@58
|
243 while most syntax errors will be noted when Vampy is first
|
fazekasgy@58
|
244 used by a host, runtime errors can still occur during
|
fazekasgy@58
|
245 execution. For example, a plugin calculating the dot product
|
fazekasgy@58
|
246 of two vectors with different sizes will produce a runtime error.
|
fazekasgy@58
|
247
|
fazekasgy@58
|
248 Error messages from Vampy are printed on the standard output.
|
fazekasgy@58
|
249 If you're using a graphical host (such as Sonic Visualiser)
|
fazekasgy@58
|
250 you may start the application from a command line terminal
|
fazekasgy@58
|
251 in order to see these messages.
|
fazekasgy@58
|
252
|
fazekasgy@58
|
253 Exceptions:
|
fazekasgy@58
|
254
|
fazekasgy@58
|
255 * Runtime errors occurring in the plugin's __init__() function
|
fazekasgy@58
|
256 will prevent the host from loading the plugin.
|
fazekasgy@58
|
257
|
fazekasgy@58
|
258 * Runtime errors in the plugin's initialise() function will
|
fazekasgy@58
|
259 prevent the host from using the plugin.
|
fazekasgy@58
|
260
|
fazekasgy@58
|
261 * Module level errors resulting from importing a non-existent
|
fazekasgy@58
|
262 module or source file or an error occurring on an imported
|
fazekasgy@58
|
263 module's source tree will prevent the plugin from loading.
|
fazekasgy@58
|
264
|
fazekasgy@58
|
265 Any other error, including those during the process will
|
fazekasgy@58
|
266 only be noted on the terminal output. Processing errors will
|
fazekasgy@58
|
267 generally result in a blank screen or no results displayed by
|
fazekasgy@58
|
268 graphical hosts.
|
fazekasgy@58
|
269
|
fazekasgy@58
|
270
|
fazekasgy@58
|
271 EXTENSION MODULE:
|
fazekasgy@58
|
272
|
fazekasgy@58
|
273 Vampy extends Python with some useful data types defined
|
fazekasgy@58
|
274 by the Vamp plugin API. This extension module is embedded
|
fazekasgy@58
|
275 into the Vampy shared library, therefore it doesn't need
|
fazekasgy@58
|
276 to be installed separately. However, it works very similarly
|
fazekasgy@58
|
277 to any third party Python extension within a Vampy plugin.
|
fazekasgy@58
|
278
|
fazekasgy@58
|
279 You may import the extension in the usual manner using
|
fazekasgy@58
|
280 " import vampy " and " from vampy import * ". (Note that
|
fazekasgy@58
|
281 currently the extension module is not available as a
|
fazekasgy@58
|
282 separate package, therefore this will only work if the
|
fazekasgy@58
|
283 plugin is executed by Vampy within a usual host context.)
|
fazekasgy@58
|
284
|
fazekasgy@58
|
285 You can use any standard Python statement involving
|
fazekasgy@58
|
286 modules such as " dir(vampy) " to print the names exported
|
fazekasgy@58
|
287 by the module. The use of the extension in entirely optional,
|
fazekasgy@58
|
288 however its use is strongly advised for the following reasons:
|
fazekasgy@58
|
289
|
fazekasgy@58
|
290 * Using the module hides the mapping between Python and
|
fazekasgy@58
|
291 C++ data types and provides improved plugin portability.
|
fazekasgy@58
|
292
|
fazekasgy@58
|
293 * Returning types exported by the module is often faster.
|
fazekasgy@58
|
294
|
fazekasgy@58
|
295 * In future releases its use may become mandatory.
|
fazekasgy@58
|
296
|
fazekasgy@58
|
297
|
fazekasgy@58
|
298 PROCESS INTERFACES:
|
fazekasgy@58
|
299
|
fazekasgy@58
|
300 Most computationally intensive processing takes place in
|
fazekasgy@58
|
301 the plugin's process() method. This method has two arguments,
|
fazekasgy@58
|
302 (besides the 'self' argument mandatory in all Python class methods).
|
fazekasgy@58
|
303
|
fazekasgy@58
|
304 * The fist argument is used to pass audio samples (in time
|
fazekasgy@58
|
305 domain plugins) or frequency samples (complex FFT output)
|
fazekasgy@58
|
306 in frequency domain plugins. This argument is always a
|
fazekasgy@58
|
307 Python list object where each element of the list corresponds
|
fazekasgy@58
|
308 to an audio channel. (The length of this list can not be zero.)
|
fazekasgy@58
|
309 The actual element types contained in this list depends
|
fazekasgy@58
|
310 on the domain type of the plugin (time/frequency domain) and
|
fazekasgy@58
|
311 the selected process interface. (explained below)
|
fazekasgy@58
|
312
|
fazekasgy@58
|
313 * The second argument is the time stamp of the processing
|
fazekasgy@58
|
314 block passed to the plugin. This time stamp is either
|
fazekasgy@58
|
315 a long integer corresponding to a sample number, or a
|
fazekasgy@58
|
316 RealTime data type exposed by the vampy module.
|
fazekasgy@58
|
317 The use of the time stamp is different in time and frequency
|
fazekasgy@58
|
318 domain plugins. Please refer to the Vamp plugin documentation
|
fazekasgy@58
|
319 for more details.
|
fazekasgy@58
|
320
|
fazekasgy@58
|
321 Vampy supports three interfaces to process() function.
|
fazekasgy@58
|
322 The interface type can be selected using the flags indicated
|
fazekasgy@58
|
323 next to the process name below. The detailed use of these
|
fazekasgy@58
|
324 flags will be explained later.
|
fazekasgy@58
|
325
|
fazekasgy@58
|
326 INTERFACE TYPES:
|
fazekasgy@58
|
327
|
fazekasgy@58
|
328 (1) Legacy interface (default, slowest):
|
fazekasgy@58
|
329
|
fazekasgy@58
|
330 Vampy passes a Python List of List of values to the
|
fazekasgy@58
|
331 plugin corresponding to each audio channel, and the
|
fazekasgy@58
|
332 time or frequency domain samples of each channel:
|
fazekasgy@58
|
333
|
fazekasgy@58
|
334 * Audio samples are passed as an N element list
|
fazekasgy@58
|
335 of floating point values in time domain plugins,
|
fazekasgy@58
|
336 (where N equals to the block size parameter of the plugin).
|
fazekasgy@58
|
337
|
fazekasgy@58
|
338 * Frequency Domain plugins are passed an N element list
|
fazekasgy@58
|
339 of complex numbers, where N = (blockSize/2) + 1. This list
|
fazekasgy@58
|
340 includes the DC and the Nyquist frequency FFT oputputs.
|
fazekasgy@58
|
341
|
fazekasgy@58
|
342 Note: This is the only available interface which can be used
|
fazekasgy@58
|
343 without Numpy or a compatible numerical library.
|
fazekasgy@58
|
344
|
fazekasgy@58
|
345 (2) Buffer interface (vf_BUFFER, fast):
|
fazekasgy@58
|
346
|
fazekasgy@58
|
347 * Both time and frequency domain plugins are passed a list
|
fazekasgy@58
|
348 of shared memory buffer objects where each buffer corresponds
|
fazekasgy@58
|
349 to an audio channel. The length of these buffers is blockSize
|
fazekasgy@58
|
350 in time domain plugins and blockSize+2 in frequency domain
|
fazekasgy@58
|
351 plugins. The easiest way to access the data in the buffers
|
fazekasgy@58
|
352 is the use of Numpy's frombuffer() command. See the Numpy
|
fazekasgy@58
|
353 documentation or the Vampy example plugins for more details.
|
fazekasgy@58
|
354
|
fazekasgy@58
|
355 Note that this interface is very similar to how the data is
|
fazekasgy@58
|
356 passed to Vamp plugins in C++.
|
fazekasgy@58
|
357
|
fazekasgy@58
|
358 (3) Numpy Array interface (vf_ARRAY, fast):
|
fazekasgy@58
|
359
|
fazekasgy@58
|
360 Vampy passes a list of Numpy arrays to the process()
|
fazekasgy@58
|
361 corresponding to each audio channel.
|
fazekasgy@58
|
362
|
fazekasgy@58
|
363 * Time Domain plugins are passed an array of numpy.float32
|
fazekasgy@58
|
364 values where the array size is N = blockSize.
|
fazekasgy@58
|
365
|
fazekasgy@58
|
366 * Frequency Domain plugins are passed an array of
|
fazekasgy@58
|
367 numpy.complex64 values where the size N = (blockSize/2) + 1.
|
fazekasgy@58
|
368
|
fazekasgy@58
|
369
|
fazekasgy@58
|
370 RETURNING VALUES:
|
fazekasgy@58
|
371
|
fazekasgy@58
|
372 Python is a dynamically typed language, which means
|
fazekasgy@58
|
373 that the programmer is not forced to declare variable
|
fazekasgy@58
|
374 types strictly and specifically, they can be decided
|
fazekasgy@58
|
375 or changed at runtime. This leads to different programming
|
fazekasgy@58
|
376 styles compared to using statically typed languages such
|
fazekasgy@58
|
377 as C++. The Vamp API is declared using C++ and expects
|
fazekasgy@58
|
378 statically declared types returned by the plugin.
|
fazekasgy@58
|
379 This leads to difficulties to the Python programmer, and
|
fazekasgy@58
|
380 requires a detailed knowledge of the API which otherwise
|
fazekasgy@58
|
381 would be unnecessary. Vampy relaxes this requirement by
|
fazekasgy@58
|
382 using a runtime type inference mechanism.
|
fazekasgy@58
|
383
|
fazekasgy@58
|
384 Vampy can convert just about any suitable Python data
|
fazekasgy@58
|
385 object to the appropriate C++ data type expected by a
|
fazekasgy@58
|
386 Vamp plugin host. This includes Numpy data types such as
|
fazekasgy@58
|
387 numpy.float32 or a Numpy array. The type conversion is
|
fazekasgy@58
|
388 dynamic and it is decided based on the plugin context and
|
fazekasgy@58
|
389 the expected data type defined by the Vamp plugin API
|
fazekasgy@58
|
390 in that context. This mechanism also takes advantage of the
|
fazekasgy@58
|
391 higher level Python number, sequence and mapping protocols.
|
fazekasgy@58
|
392
|
fazekasgy@58
|
393 For example if the Vamp API expects a floating point value,
|
fazekasgy@58
|
394 any returned Python object will be attempted to cast
|
fazekasgy@58
|
395 to a floating point value first and returned to the host.
|
fazekasgy@58
|
396 If the value can not be converted, an error message is
|
fazekasgy@58
|
397 displayed.
|
fazekasgy@58
|
398
|
fazekasgy@58
|
399 Similarly, any returned value will be converted to a vector of
|
fazekasgy@58
|
400 the appropriate element type when the expected return type is
|
fazekasgy@58
|
401 a sequence of values. This allows the programmer to omit
|
fazekasgy@58
|
402 unnecessary conversions, when, for example, a one element
|
fazekasgy@58
|
403 list (vector) would be returned.
|
fazekasgy@58
|
404
|
fazekasgy@58
|
405 The type conversion can be controlled specifically for
|
fazekasgy@58
|
406 each plugin. Vampy supports the use case of prototyping
|
fazekasgy@58
|
407 C++ Vamp plugins in Python by using a more strict type
|
fazekasgy@58
|
408 conversion mechanism which would issue an error message
|
fazekasgy@58
|
409 if the Python object does not correspond to a C++ type
|
fazekasgy@58
|
410 according to a strict one-to-one mapping. This mapping
|
fazekasgy@58
|
411 can be briefly outlined as follows:
|
fazekasgy@58
|
412
|
fazekasgy@58
|
413 * numerical types require direct correspondence
|
fazekasgy@58
|
414 between Python and C++ types when available
|
fazekasgy@58
|
415 e.g. C++ float -> Python float
|
fazekasgy@58
|
416
|
fazekasgy@58
|
417 * Data structures defined in the Vamp Plugin API require
|
fazekasgy@58
|
418 a type exported be the vampy extension module.
|
fazekasgy@58
|
419 Vamp::FeatureSet() -> vampy.FeatureSet()
|
fazekasgy@58
|
420 Vamp::RealTime() -> vampy.RealTime()
|
fazekasgy@58
|
421
|
fazekasgy@58
|
422 The strict type conversion method can be selected using
|
fazekasgy@58
|
423 the Vampy flag: vf_STRICT (explained in the FLAGS section).
|
fazekasgy@58
|
424
|
fazekasgy@58
|
425
|
fazekasgy@58
|
426 TIME STAMPS :
|
fazekasgy@58
|
427
|
fazekasgy@58
|
428 Vamp uses RealTime time stamps to indicate the position of
|
fazekasgy@58
|
429 a processing block passed to the plugin, or the position of
|
fazekasgy@58
|
430 any returned features relative to the start of the audio.
|
fazekasgy@58
|
431 RealTime uses two integer values to represent time values
|
fazekasgy@58
|
432 to nanosecond precision. Vampy provides a Python compatible
|
fazekasgy@58
|
433 representation of this this type which can be imported and
|
fazekasgy@58
|
434 used in any Vampy plugin.
|
fazekasgy@58
|
435
|
fazekasgy@58
|
436 * Vampy RealTime objects can be initialised using integers
|
fazekasgy@58
|
437 corresponding to second and nanosecond values, or seconds (floats).
|
fazekasgy@58
|
438 e.g.:
|
fazekasgy@58
|
439 timestamp1 = RealTime(2,0)
|
fazekasgy@58
|
440 timestamp2 = RealTime('seconds',2.123)
|
fazekasgy@58
|
441
|
fazekasgy@58
|
442 Please note that only the following methods are available:
|
fazekasgy@58
|
443
|
fazekasgy@58
|
444 * values() : returns a tuple of integers (sec,nsec)
|
fazekasgy@58
|
445 * toFloat() : return a floating point representation (in seconds)
|
fazekasgy@58
|
446 * toFrame(samplerate) : convert to frame
|
fazekasgy@58
|
447 (sample number) given the audio sample rate
|
fazekasgy@58
|
448 * toString() : human readable string representation
|
fazekasgy@58
|
449 * a limited set of arithmetic operators (+,-)
|
fazekasgy@58
|
450
|
fazekasgy@58
|
451 Additionally Vampy provides a function to convert frame
|
fazekasgy@58
|
452 counts (in audio samples) to RealTime:
|
fazekasgy@58
|
453
|
fazekasgy@58
|
454 timestamp = frame2RealTime(frameCount,inputSampleRate)
|
fazekasgy@58
|
455
|
fazekasgy@58
|
456 For the detailed use of time stamps, refer to the Vamp plugin
|
fazekasgy@58
|
457 documentation. i.e. Section 5, "Sample Types and Timestamps"
|
fazekasgy@58
|
458 in the Vamp plugin guide, and the Vamp SDK documentation:
|
fazekasgy@58
|
459 http://vamp-plugins.org/code-doc/classVamp_1_1Plugin.html
|
fazekasgy@58
|
460 on how time stamps are used in process calls.
|
fazekasgy@58
|
461
|
fazekasgy@58
|
462 Note: The support for RealTime time stamps is new in this
|
fazekasgy@58
|
463 version of Vampy. Vampy 1 used long integer sample counts
|
fazekasgy@58
|
464 instead. This is still accepted for backward compatibility,
|
fazekasgy@58
|
465 but the use of RealTime is encouraged whenever possible.
|
fazekasgy@58
|
466 By default sample counts are used, please set the falg:
|
fazekasgy@58
|
467 vf_REALTIME to obtain RealTime time stamps in process calls.
|
fazekasgy@58
|
468
|
fazekasgy@58
|
469
|
fazekasgy@58
|
470 VAMPY FLAGS :
|
fazekasgy@58
|
471
|
fazekasgy@58
|
472 The execution of Vampy plugins can be controlled using a set
|
fazekasgy@58
|
473 of flags. (Each control flag is prefixed by vf_)
|
fazekasgy@58
|
474
|
fazekasgy@58
|
475 vf_NULL : zero value, default for Vampy version 1 behaviour
|
fazekasgy@38
|
476 vf_DEBUG : print debug messages to standard error
|
fazekasgy@58
|
477 vf_STRICT : strict type conversion (follows the C++ API more closely)
|
fazekasgy@38
|
478 vf_QUIT : quit the host process on hard errors
|
fazekasgy@38
|
479 vf_REALTIME : use RealTime time stamps
|
fazekasgy@58
|
480 vf_BUFFER : use the Numpy Buffer interface
|
fazekasgy@58
|
481 vf_ARRAY : use the numpy Array interface
|
fazekasgy@38
|
482 vf_DEFAULT_V2 : default Vampy version 2 behaviour
|
fazekasgy@58
|
483 (equals to setting: vf_ARRAY | vf_REALTIME)
|
fazekasgy@38
|
484
|
fazekasgy@58
|
485 The use of flags is optional. The default behaviour is that
|
fazekasgy@58
|
486 of Vampy version 1.
|
fazekasgy@38
|
487
|
fazekasgy@38
|
488 To set the flags, place a variable called 'vampy_flags' in
|
fazekasgy@38
|
489 your plugin class's __init__() function.
|
fazekasgy@38
|
490
|
fazekasgy@38
|
491 Example:
|
fazekasgy@38
|
492
|
fazekasgy@38
|
493 class PyMFCC(melScaling):
|
fazekasgy@38
|
494 def __init__(self,inputSampleRate):
|
fazekasgy@38
|
495 self.vampy_flags = vf_DEBUG | vf_ARRAY | vf_REALTIME
|
fazekasgy@38
|
496
|
fazekasgy@38
|
497
|
fazekasgy@38
|
498 ENVIRONMENT VARIABLES:
|
fazekasgy@38
|
499
|
cannam@57
|
500 Vampy recognises three optional environment variables:
|
fazekasgy@38
|
501
|
fazekasgy@38
|
502 VAMPY_COMPILED=1 recognise byte compiled python plugins (default)
|
fazekasgy@38
|
503 VAMPY_COMPILED=0 ignore them
|
cannam@57
|
504
|
fazekasgy@38
|
505 VAMPY_EXTPATH: if given, searches this path for vampy plugins.
|
fazekasgy@58
|
506 This is useful if you want to keep your python plugins
|
fazekasgy@58
|
507 separate. Only a single absolute path name is recognised.
|
fazekasgy@58
|
508
|
fazekasgy@58
|
509 Example:
|
fazekasgy@58
|
510 export VAMPY_EXTPATH="/Users/Shared/Development/vampy-path"
|
cannam@57
|
511
|
cannam@57
|
512 VAMPY_PYLIB: path to the Python shared library to be preloaded
|
cannam@57
|
513 before scripts are run. The preload is necessary on some
|
cannam@57
|
514 systems to support plugins that load additional Python modules.
|
cannam@57
|
515 Vampy will attempt to preload the right library by default, but
|
cannam@57
|
516 it sometimes fails; if so, set this variable to override it.
|
fazekasgy@37
|
517
|
cannam@50
|
518
|
fazekasgy@37
|
519 HISTORY:
|
fazekasgy@37
|
520
|
fazekasgy@38
|
521 v1:
|
fazekasgy@51
|
522 * added support for Numpy arrays in processN()
|
fazekasgy@58
|
523 * framecount is now passed also to legacy process()
|
fazekasgy@58
|
524 and fixed resulting bugs in the PyZeroCrossing plugin
|
fazekasgy@38
|
525 * added two examples which use Frequency Domain input in processN()
|
fazekasgy@38
|
526
|
fazekasgy@38
|
527 v2.0:
|
fazekasgy@58
|
528 * complete rewrite using generic functions for
|
fazekasgy@58
|
529 implementing full error checking on Python/C API calls
|
fazekasgy@58
|
530 * added extension module;
|
fazekasgy@58
|
531 supports RealTime and other Vamp type wrappers
|
fazekasgy@58
|
532 enables a much more readable syntax
|
fazekasgy@51
|
533 * added Numpy Array interface
|
fazekasgy@51
|
534 * added flags
|
fazekasgy@38
|
535 * added environment variables
|
fazekasgy@58
|
536 * recognise byte compiled python scripts
|
fazekasgy@58
|
537 * new example plugin PyMFCC
|
fazekasgy@58
|
538 * modified all examples for the new syntax
|
fazekasgy@58
|
539 * bug fix: Nyquist frequency FFT output is now passed correctly
|
fazekasgy@58
|
540
|
fazekasgy@58
|
541
|
fazekasgy@58
|
542 TODO:
|
fazekasgy@58
|
543 * Vamp 'programs' not implemented
|
fazekasgy@58
|
544 * support multiple classes per script in scanner
|
fazekasgy@58
|
545 * implement missing methods of vampy.RealTime type
|
fazekasgy@58
|
546
|
fazekasgy@38
|
547
|
cannam@50
|
548 LICENCE:
|
cannam@50
|
549
|
cannam@50
|
550 VamPy is distributed under a "new-style BSD" license; see the
|
cannam@50
|
551 file COPYING for details. You may modify and redistribute it
|
cannam@50
|
552 within any commercial or non-commercial, proprietary or
|
cannam@50
|
553 open-source context. VamPy imposes no limitation on how you
|
cannam@50
|
554 may choose to license your own plugin scripts. Note that
|
cannam@50
|
555 these happen to be the same terms as the Vamp SDK itself.
|
cannam@50
|
556
|
cannam@50
|
557 VamPy was written by Gyorgy Fazekas at the Centre for Digital
|
cannam@50
|
558 Music, Queen Mary University of London.
|
cannam@50
|
559 Copyright 2008-2009 Gyorgy Fazekas.
|
fazekasgy@38
|
560
|
fazekasgy@38
|
561
|