Chris@56
|
1 '''A high-level interface to the vampyhost extension module, for quickly and easily running Vamp audio analysis plugins on audio files and buffers.'''
|
Chris@56
|
2
|
Chris@56
|
3 import vampyhost
|
Chris@56
|
4
|
Chris@79
|
5 def list_plugins():
|
Chris@98
|
6 """Obtain a list of plugin keys for all currently installed Vamp plugins.
|
Chris@98
|
7
|
Chris@98
|
8 The returned value is a list of strings, each of which is the key
|
Chris@98
|
9 for one plugin. (Note that a plugin may have multiple outputs, if
|
Chris@98
|
10 it computes more than one type of feature.)
|
Chris@98
|
11
|
Chris@98
|
12 To query the available outputs and category of a plugin, you may
|
Chris@98
|
13 use vamp.get_outputs_of() and vamp.get_category_of(). Further
|
Chris@98
|
14 information may be retrieved by loading the plugin and querying
|
Chris@98
|
15 its info dictionary using the low-level functions in the
|
Chris@98
|
16 vamp.vampyhost extension module.
|
Chris@98
|
17
|
Chris@98
|
18 To make use of a plugin to extract features from audio data, pass
|
Chris@98
|
19 the plugin key and optionally an output identifier to
|
Chris@98
|
20 vamp.process() or vamp.collect().
|
Chris@98
|
21 """
|
Chris@79
|
22 return vampyhost.list_plugins()
|
Chris@56
|
23
|
Chris@98
|
24 def get_outputs_of(key):
|
Chris@98
|
25 """Obtain a list of the output identifiers for the given plugin key.
|
Chris@98
|
26 """
|
Chris@98
|
27 return vampyhost.get_outputs_of(key)
|
Chris@98
|
28
|
Chris@98
|
29 def get_category_of(key):
|
Chris@98
|
30 """Obtain the category descriptor, if any, for the given plugin key.
|
Chris@98
|
31
|
Chris@98
|
32 The returned value is a list of descriptor terms, from least
|
Chris@98
|
33 specific to most specific. The list may be empty if no category
|
Chris@98
|
34 information is found for the plugin.
|
Chris@98
|
35 """
|
Chris@98
|
36 return vampyhost.get_category_of(key)
|
Chris@98
|
37
|
Chris@84
|
38 def load_and_configure(data, sample_rate, key, parameters):
|
Chris@98
|
39 """Load the plugin with the given key at a given sample rate,
|
Chris@98
|
40 configure it with the parameter keys and values in the given
|
Chris@98
|
41 parameter dictionary, and initialise it with its preferred step
|
Chris@98
|
42 and block size. The channel count is taken from the shape of the
|
Chris@98
|
43 data array provided.
|
Chris@98
|
44 """
|
Chris@82
|
45
|
Chris@84
|
46 plug = vampyhost.load_plugin(key, sample_rate,
|
Chris@82
|
47 vampyhost.ADAPT_INPUT_DOMAIN +
|
Chris@82
|
48 vampyhost.ADAPT_CHANNEL_COUNT)
|
Chris@64
|
49
|
Chris@80
|
50 plug.set_parameter_values(parameters)
|
Chris@68
|
51
|
Chris@84
|
52 step_size = plug.get_preferred_step_size()
|
Chris@84
|
53 block_size = plug.get_preferred_block_size()
|
Chris@68
|
54
|
Chris@84
|
55 if block_size == 0:
|
Chris@84
|
56 block_size = 1024
|
Chris@84
|
57 if step_size == 0:
|
Chris@84
|
58 step_size = block_size ##!!! or block_size/2, but check this with input domain adapter
|
Chris@68
|
59
|
Chris@68
|
60 channels = 1
|
Chris@68
|
61 if data.ndim > 1:
|
Chris@68
|
62 channels = data.shape[0]
|
Chris@68
|
63
|
Chris@95
|
64 if plug.initialise(channels, step_size, block_size):
|
Chris@95
|
65 return (plug, step_size, block_size)
|
Chris@95
|
66 else:
|
Chris@95
|
67 raise "Failed to initialise plugin"
|