Chris@37
|
1 /*
|
Chris@37
|
2 jVamp
|
Chris@37
|
3
|
Chris@37
|
4 A Java host interface for Vamp audio analysis plugins
|
Chris@37
|
5
|
Chris@37
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@37
|
7 Copyright 2012 Chris Cannam and QMUL.
|
Chris@37
|
8
|
Chris@37
|
9 Permission is hereby granted, free of charge, to any person
|
Chris@37
|
10 obtaining a copy of this software and associated documentation
|
Chris@37
|
11 files (the "Software"), to deal in the Software without
|
Chris@37
|
12 restriction, including without limitation the rights to use, copy,
|
Chris@37
|
13 modify, merge, publish, distribute, sublicense, and/or sell copies
|
Chris@37
|
14 of the Software, and to permit persons to whom the Software is
|
Chris@37
|
15 furnished to do so, subject to the following conditions:
|
Chris@37
|
16
|
Chris@37
|
17 The above copyright notice and this permission notice shall be
|
Chris@37
|
18 included in all copies or substantial portions of the Software.
|
Chris@37
|
19
|
Chris@37
|
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Chris@37
|
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
Chris@37
|
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
Chris@37
|
23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
Chris@37
|
24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
Chris@37
|
25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
Chris@37
|
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Chris@37
|
27
|
Chris@37
|
28 Except as contained in this notice, the names of the Centre for
|
Chris@37
|
29 Digital Music; Queen Mary, University of London; and Chris Cannam
|
Chris@37
|
30 shall not be used in advertising or otherwise to promote the sale,
|
Chris@37
|
31 use or other dealings in this Software without prior written
|
Chris@37
|
32 authorization.
|
Chris@37
|
33 */
|
Chris@0
|
34
|
Chris@0
|
35 package org.vamp_plugins;
|
Chris@0
|
36
|
Chris@23
|
37 /**
|
Chris@23
|
38 * PluginLoader loads a Vamp plugin by searching the standard Vamp
|
Chris@23
|
39 * installation path, and returns a Plugin object wrapping the native
|
Chris@23
|
40 * plugin.
|
Chris@23
|
41 *
|
Chris@23
|
42 * To load a plugin call PluginLoader.getInstance().loadPlugin(key,
|
Chris@23
|
43 * rate), where rate is the processing sample rate and key is the
|
Chris@23
|
44 * plugin key consisting of the plugin's library base name and its
|
Chris@23
|
45 * identifier, colon-separated. For example,
|
Chris@23
|
46 *
|
Chris@23
|
47 * Plugin p = PluginLoader.getInstance().loadPlugin("vamp-example-plugins:percussiononsets", 44100);
|
Chris@23
|
48 */
|
Chris@0
|
49 public class PluginLoader
|
Chris@0
|
50 {
|
Chris@0
|
51 public class LoadFailedException extends Exception { };
|
Chris@0
|
52
|
Chris@23
|
53 /**
|
Chris@23
|
54 * PluginLoader is a singleton. Return the instance of it.
|
Chris@23
|
55 */
|
Chris@0
|
56 public static synchronized PluginLoader getInstance() {
|
Chris@0
|
57 if (inst == null) {
|
Chris@0
|
58 inst = new PluginLoader();
|
Chris@0
|
59 inst.initialise();
|
Chris@0
|
60 }
|
Chris@0
|
61 return inst;
|
Chris@0
|
62 }
|
Chris@0
|
63
|
Chris@23
|
64 /**
|
Chris@23
|
65 * Search for all available Vamp plugins, and return a list of
|
Chris@23
|
66 * their plugin keys (suitable for passing to loadPlugin) in the
|
Chris@23
|
67 * order in which they were found.
|
Chris@23
|
68 */
|
Chris@24
|
69 public native String[] listPlugins();
|
Chris@23
|
70
|
Chris@23
|
71 /**
|
Chris@29
|
72 * AdapterFlags contains a set of values that may be OR'd together
|
Chris@29
|
73 * and passed to loadPlugin() to indicate which of the properties
|
Chris@29
|
74 * of a plugin the host would like PluginLoader to take care of
|
Chris@29
|
75 * for it, rather than having to handle itself.
|
Chris@29
|
76 *
|
Chris@29
|
77 * Use of these flags permits the host to cater more easily for
|
Chris@29
|
78 * plugins with varying requirements for their input formats, at
|
Chris@29
|
79 * some expense in flexibility.
|
Chris@29
|
80 */
|
Chris@29
|
81 public class AdapterFlags {
|
Chris@29
|
82
|
Chris@29
|
83 /**
|
Chris@29
|
84 * ADAPT_INPUT_DOMAIN - If the plugin expects frequency domain
|
Chris@29
|
85 * input, automatically convert it to one that expects
|
Chris@29
|
86 * time-domain input by interpolating an adapter that carries
|
Chris@29
|
87 * out the FFT conversion silently.
|
Chris@29
|
88 *
|
Chris@29
|
89 * This enables a host to accommodate time- and
|
Chris@29
|
90 * frequency-domain plugins without needing to do any
|
Chris@29
|
91 * conversion itself, but it means the host gets no control
|
Chris@29
|
92 * over the windowing and FFT methods used. A Hann window is
|
Chris@29
|
93 * used, and the FFT is unlikely to be the fastest native
|
Chris@29
|
94 * implementation available.
|
Chris@29
|
95 */
|
Chris@29
|
96 public static final int ADAPT_INPUT_DOMAIN = 1;
|
Chris@29
|
97
|
Chris@29
|
98 /**
|
Chris@29
|
99 * ADAPT_CHANNEL_COUNT - Automatically handle any discrepancy
|
Chris@29
|
100 * between the number of channels supported by the plugin and
|
Chris@29
|
101 * the number provided by the host when calling
|
Chris@29
|
102 * Plugin.initialise(). This enables a host to use plugins
|
Chris@29
|
103 * that may require the input to be mixed down to mono, etc.,
|
Chris@29
|
104 * without having to worry about doing that itself.
|
Chris@29
|
105 */
|
Chris@29
|
106 public static final int ADAPT_CHANNEL_COUNT = 2;
|
Chris@29
|
107
|
Chris@29
|
108 /**
|
Chris@29
|
109 * ADAPT_BUFFER_SIZE - Permit the host to ignore the preferred
|
Chris@29
|
110 * step and block size reported by the plugin when calling
|
Chris@29
|
111 * initialise(), and to provide whatever step and block size
|
Chris@29
|
112 * are most convenient instead.
|
Chris@29
|
113 *
|
Chris@29
|
114 * This may require modifying the sample type and rate
|
Chris@29
|
115 * specifications for the plugin outputs and modifying the
|
Chris@29
|
116 * timestamps on the output features in order to obtain
|
Chris@29
|
117 * correct time stamping.
|
Chris@29
|
118 */
|
Chris@39
|
119 public static final int ADAPT_BUFFER_SIZE = 4;
|
Chris@29
|
120
|
Chris@29
|
121 /**
|
Chris@29
|
122 * ADAPT_ALL - Perform all available adaptations that are
|
Chris@29
|
123 * meaningful for the plugin.
|
Chris@29
|
124 */
|
Chris@29
|
125 public static final int ADAPT_ALL = 255;
|
Chris@29
|
126
|
Chris@29
|
127 /**
|
Chris@29
|
128 * ADAPT_NONE - If passed to loadPlugin as the adapterFlags
|
Chris@29
|
129 * value, causes no adaptations to be done.
|
Chris@29
|
130 */
|
Chris@29
|
131 public static final int ADAPT_NONE = 0;
|
Chris@29
|
132 };
|
Chris@29
|
133
|
Chris@29
|
134 /**
|
Chris@23
|
135 * Load a native Vamp plugin from the plugin path. If the plugin
|
Chris@23
|
136 * cannot be loaded, throw LoadFailedException.
|
Chris@23
|
137 *
|
Chris@23
|
138 * key is the plugin key consisting of the plugin's library base
|
Chris@23
|
139 * name and its identifier, colon-separated; inputSampleRate is
|
Chris@23
|
140 * the processing sample rate for input audio.
|
Chris@23
|
141 *
|
Chris@29
|
142 * adapterFlags should contain an OR of the desired AdapterFlags
|
Chris@29
|
143 * options for the plugin, or AdapterFlags.ADAPT_NONE if no
|
Chris@29
|
144 * automatic adaptations are to be made.
|
Chris@23
|
145 */
|
Chris@29
|
146 public Plugin loadPlugin(String key,
|
Chris@29
|
147 float inputSampleRate,
|
Chris@29
|
148 int adapterFlags)
|
Chris@0
|
149 throws LoadFailedException {
|
Chris@29
|
150 long handle = loadPluginNative(key, inputSampleRate, adapterFlags);
|
Chris@0
|
151 if (handle != 0) return new Plugin(handle);
|
Chris@0
|
152 else throw new LoadFailedException();
|
Chris@0
|
153 }
|
Chris@0
|
154
|
Chris@23
|
155 /**
|
Chris@23
|
156 * Return the category hierarchy for a Vamp plugin, given its
|
Chris@23
|
157 * identifying key. The hierarchy is a sequence of category names
|
Chris@23
|
158 * giving the location of a plugin within a category forest,
|
Chris@23
|
159 * containing the human-readable names of the plugin's category
|
Chris@23
|
160 * tree root, followed by each of the nodes down to the leaf
|
Chris@23
|
161 * containing the plugin.
|
Chris@23
|
162 *
|
Chris@23
|
163 * If the plugin has no category information, return an empty
|
Chris@23
|
164 * list.
|
Chris@23
|
165 */
|
Chris@24
|
166 public native String[] getPluginCategory(String key);
|
Chris@23
|
167
|
Chris@45
|
168 /**
|
Chris@45
|
169 * Return the plugin path, that is, the series of local file
|
Chris@45
|
170 * folders that will be searched for plugin files. This is
|
Chris@45
|
171 * platform-specific; it may be a default path, or it may be
|
Chris@45
|
172 * determined by factors such as the VAMP_PATH environment
|
Chris@45
|
173 * variable.
|
Chris@45
|
174 */
|
Chris@45
|
175 public native String[] getPluginPath();
|
Chris@45
|
176
|
Chris@0
|
177 private PluginLoader() { initialise(); }
|
Chris@29
|
178 private native long loadPluginNative(String key, float inputSampleRate,
|
Chris@29
|
179 int adapterFlags);
|
Chris@0
|
180 private native void initialise();
|
Chris@0
|
181 private static PluginLoader inst;
|
Chris@0
|
182 private long nativeHandle;
|
Chris@0
|
183
|
Chris@0
|
184 static {
|
Chris@0
|
185 System.loadLibrary("vamp-jni");
|
Chris@0
|
186 }
|
Chris@0
|
187 }
|
Chris@0
|
188
|