comparison org/vamp_plugins/Plugin.java @ 28:f2914a92b553

Docs
author Chris Cannam
date Mon, 19 Nov 2012 15:12:44 +0000
parents b568b30c167f
children c9515589be7d
comparison
equal deleted inserted replaced
27:59b4150c69cb 28:f2914a92b553
2 package org.vamp_plugins; 2 package org.vamp_plugins;
3 3
4 import java.util.TreeMap; 4 import java.util.TreeMap;
5 import java.util.ArrayList; 5 import java.util.ArrayList;
6 6
7 /**
8 * A Java wrapper for a native-code Vamp plugin. Plugins are obtained
9 * using PluginLoader and must be freed by calling dispose() after use
10 * (being native code they cannot be garbage collected).
11 *
12 * The plugin lifecycle looks roughly like this, from the host's
13 * perspective:
14 *
15 * - Plugin is loaded using PluginLoader
16 *
17 * - Host may query the plugin's available outputs with
18 * getOutputDescriptors(). This will report what outputs exist,
19 * but their properties (e.g. resolution, value count, extents)
20 * are not yet fixed
21 *
22 * - Host may query and set the plugin's programs and parameters with
23 * getPrograms(), getParameterDescriptors(), setParameter() etc
24 *
25 * - After all parameters are set, host queries the plugin's preferred
26 * step size, block size, and channel count (which may depend on
27 * the parameter settings)
28 *
29 * - Host initialises plugin by calling initialise(). If it returns
30 * false, initialise failed -- most likely because the step size,
31 * block size, or channel count was rejected
32 *
33 * - Host may now get final values for the output properties using
34 * getOutputDescriptors()
35 *
36 * - Host calls process() repeatedly to process data. This may return
37 * some results as it goes along (if the plugin is causal)
38 *
39 * - Host calls getRemainingFeatures() exactly once when all input has
40 * been processed, to obtain any non-causal or leftover features.
41 *
42 * - At any point after initialise() has been called, host may call
43 * reset() to restart processing. Parameter values remain fixed
44 * across reset() calls.
45 *
46 * - When host is finished with plugin, it calls dispose().
47 *
48 * The host may not change any parameter or program settings after
49 * calling initialise(), and may not call initialise() more than once
50 * on any given plugin.
51 *
52 * See the PluginBase and Plugin classes in the C++ Vamp plugin SDK
53 * for further documentation.
54 */
7 public class Plugin 55 public class Plugin
8 { 56 {
9 private long nativeHandle; 57 private long nativeHandle;
10 protected Plugin(long handle) { nativeHandle = handle; } 58 protected Plugin(long handle) { nativeHandle = handle; }
11 59
60 /**
61 * Dispose of this Plugin. Call this when you have finished using
62 * it to ensure the native code object is released.
63 */
12 public native void dispose(); 64 public native void dispose();
13 65
14 // PluginBase methods 66 /**
15 67 * Get the Vamp API compatibility level of the plugin.
68 */
16 public native int getVampApiVersion(); 69 public native int getVampApiVersion();
70
71 /**
72 * Get the computer-usable name of the plugin. This will contain
73 * only the characters [a-zA-Z0-9_-]. This is the authoritative
74 * way for a host to identify a plugin within a given library, but
75 * it is not the primary label shown to the user (that will be the
76 * name, below).
77 */
17 public native String getIdentifier(); 78 public native String getIdentifier();
79
80 /**
81 * Get a human-readable name or title of the plugin. This is the
82 * main identifying label shown to the user.
83 */
18 public native String getName(); 84 public native String getName();
85
86 /**
87 * Get a human-readable description for the plugin, typically
88 * a line of text that may optionally be displayed in addition
89 * to the plugin's "name". May be empty if the name has said
90 * it all already.
91 */
19 public native String getDescription(); 92 public native String getDescription();
93
94 /**
95 * Get the name of the author or vendor of the plugin in
96 * human-readable form. This should be short enough to be used to
97 * label plugins from the same source in a tree or menu if
98 * appropriate.
99 */
20 public native String getMaker(); 100 public native String getMaker();
101
102 /**
103 * Get the copyright statement or licensing summary for the
104 * plugin.
105 */
21 public native String getCopyright(); 106 public native String getCopyright();
107
108 /**
109 * Get the version number of the plugin.
110 */
22 public native int getPluginVersion(); 111 public native int getPluginVersion();
23 112
113 /**
114 * Get the controllable parameters of this plugin.
115 */
24 public native ParameterDescriptor[] getParameterDescriptors(); 116 public native ParameterDescriptor[] getParameterDescriptors();
117
118 /**
119 * Get the value of a named parameter. The argument is the identifier
120 * field from that parameter's descriptor.
121 */
25 public native float getParameter(String identifier); 122 public native float getParameter(String identifier);
123
124 /**
125 * Set a named parameter. The first argument is the identifier field
126 * from that parameter's descriptor.
127 */
26 public native void setParameter(String identifier, float value); 128 public native void setParameter(String identifier, float value);
27 129
130 /**
131 * Get the program settings available in this plugin. A program
132 * is a named shorthand for a set of parameter values; changing
133 * the program may cause the plugin to alter the values of its
134 * published parameters (and/or non-public internal processing
135 * parameters). The host should re-read the plugin's parameter
136 * values after setting a new program.
137 *
138 * The programs must have unique names.
139 */
28 public native String[] getPrograms(); 140 public native String[] getPrograms();
141
142 /**
143 * Get the current program (if any).
144 */
29 public native String getCurrentProgram(); 145 public native String getCurrentProgram();
146
147 /**
148 * Select a program. (If the given program name is not one of the
149 * available programs, do nothing.)
150 */
30 public native void selectProgram(String program); 151 public native void selectProgram(String program);
31 152
32 // Plugin methods 153 /**
33 154 * Initialise a plugin to prepare it for use with the given number
155 * of input channels, step size (window increment, in sample
156 * frames) and block size (window size, in sample frames).
157 *
158 * The input sample rate should have been already specified when
159 * loading the plugin.
160 *
161 * Return true for successful initialisation, false if the number
162 * of input channels, step size and/or block size cannot be
163 * supported.
164 */
34 public native boolean initialise(int inputChannels, 165 public native boolean initialise(int inputChannels,
35 int stepSize, 166 int stepSize,
36 int blockSize); 167 int blockSize);
37 168
169 /**
170 * Reset the plugin after use, to prepare it for another clean
171 * run.
172 */
38 public native void reset(); 173 public native void reset();
39 174
40 public static enum InputDomain { TIME_DOMAIN, FREQUENCY_DOMAIN }; 175 public static enum InputDomain { TIME_DOMAIN, FREQUENCY_DOMAIN };
176
177 /**
178 * Get the plugin's required input domain.
179 *
180 * If this is TimeDomain, the samples provided to the process()
181 * function (below) must be in the time domain, as for a
182 * traditional audio processing plugin.
183 *
184 * If this is FrequencyDomain, the host must carry out a windowed
185 * FFT of size equal to the negotiated block size on the data
186 * before passing the frequency bin data in to process(). The
187 * input data for the FFT will be rotated so as to place the
188 * origin in the centre of the block. The plugin does not get to
189 * choose the window type -- the host will either let the user do
190 * so, or will use a Hanning window.
191 */
41 public native InputDomain getInputDomain(); 192 public native InputDomain getInputDomain();
42 193
194 /**
195 * Get the preferred block size (window size -- the number of
196 * sample frames passed in each block to the process() function).
197 * This should be called before initialise().
198 *
199 * A plugin that can handle any block size may return 0. The
200 * final block size will be set in the initialise() call.
201 */
43 public native int getPreferredBlockSize(); 202 public native int getPreferredBlockSize();
203
204 /**
205 * Get the preferred step size (window increment -- the distance
206 * in sample frames between the start frames of consecutive blocks
207 * passed to the process() function) for the plugin. This should
208 * be called before initialise().
209 *
210 * A plugin may return 0 if it has no particular interest in the
211 * step size. In this case, the host should make the step size
212 * equal to the block size if the plugin is accepting input in the
213 * time domain. If the plugin is accepting input in the frequency
214 * domain, the host may use any step size. The final step size
215 * will be set in the initialise() call.
216 */
44 public native int getPreferredStepSize(); 217 public native int getPreferredStepSize();
218
219 /**
220 * Get the minimum supported number of input channels.
221 */
45 public native int getMinChannelCount(); 222 public native int getMinChannelCount();
223
224 /**
225 * Get the maximum supported number of input channels.
226 */
46 public native int getMaxChannelCount(); 227 public native int getMaxChannelCount();
47 228
229 /**
230 * Get the outputs of this plugin. An output's index in this list
231 * is used as its numeric index when looking it up in the
232 * FeatureSet returned from the process() call.
233 */
48 public native OutputDescriptor[] getOutputDescriptors(); 234 public native OutputDescriptor[] getOutputDescriptors();
49 235
50 // "Pseudo-typedef antipattern - don't do this": http://www.ibm.com/developerworks/java/library/j-jtp02216/index.html 236 /**
51 // (I would like to!) 237 * Process a single block of input data.
52 // public class FeatureList extends ArrayList<Feature>; 238 *
53 // public class FeatureSet extends TreeMap<Integer, FeatureList>; 239 * If the plugin's inputDomain is TimeDomain, inputBuffers must
54 240 * contain one array of floats per input channel, and each of
241 * these arrays will contain blockSize consecutive audio samples
242 * (the host will zero-pad as necessary). The timestamp in this
243 * case will be the real time in seconds of the start of the
244 * supplied block of samples.
245 *
246 * If the plugin's inputDomain is FrequencyDomain, inputBuffers
247 * must contain one array of floats per input channel, and each of
248 * these arrays will contain blockSize/2+1 consecutive pairs of
249 * real and imaginary component floats corresponding to bins
250 * 0..(blockSize/2) of the FFT output. That is, bin 0 (the first
251 * pair of floats) contains the DC output, up to bin blockSize/2
252 * which contains the Nyquist-frequency output. There will
253 * therefore be blockSize+2 floats per channel in total. The
254 * timestamp will be the real time in seconds of the centre of the
255 * FFT input window (i.e. the very first block passed to process
256 * might contain the FFT of half a block of zero samples and the
257 * first half-block of the actual data, with a timestamp of zero).
258 *
259 * Return any features that have become available after this
260 * process call. (These do not necessarily have to fall within
261 * the process block, except for OneSamplePerStep outputs.)
262 */
55 public TreeMap<Integer, ArrayList<Feature>> 263 public TreeMap<Integer, ArrayList<Feature>>
56 process(float[][] inputBuffers, 264 process(float[][] inputBuffers,
57 RealTime timestamp) { 265 RealTime timestamp) {
58 return process(inputBuffers, 0, timestamp); 266 return process(inputBuffers, 0, timestamp);
59 } 267 }
60 268
269 /**
270 * As process() above, but taking input data starting at the given
271 * offset from within each of the channel arrays. Provided to
272 * avoid potentially having to extract a set of sub-arrays from
273 * longer arrays (fiddly in Java).
274 */
61 public native TreeMap<Integer, ArrayList<Feature>> 275 public native TreeMap<Integer, ArrayList<Feature>>
62 process(float[][] inputBuffers, 276 process(float[][] inputBuffers,
63 int offset, 277 int offset,
64 RealTime timestamp); 278 RealTime timestamp);
65 279
280 /**
281 * After all blocks have been processed, calculate and return any
282 * remaining features derived from the complete input.
283 */
66 public native TreeMap<Integer, ArrayList<Feature>> 284 public native TreeMap<Integer, ArrayList<Feature>>
67 getRemainingFeatures(); 285 getRemainingFeatures();
68 } 286 }
69 287