annotate org/vamp_plugins/PluginLoader.java @ 29:7d1118b3860d

Add adapter flags
author Chris Cannam
date Thu, 22 Nov 2012 11:35:17 +0000
parents cd430fbf6795
children c9515589be7d
rev   line source
Chris@0 1
Chris@0 2 package org.vamp_plugins;
Chris@0 3
Chris@23 4 /**
Chris@23 5 * PluginLoader loads a Vamp plugin by searching the standard Vamp
Chris@23 6 * installation path, and returns a Plugin object wrapping the native
Chris@23 7 * plugin.
Chris@23 8 *
Chris@23 9 * To load a plugin call PluginLoader.getInstance().loadPlugin(key,
Chris@23 10 * rate), where rate is the processing sample rate and key is the
Chris@23 11 * plugin key consisting of the plugin's library base name and its
Chris@23 12 * identifier, colon-separated. For example,
Chris@23 13 *
Chris@23 14 * Plugin p = PluginLoader.getInstance().loadPlugin("vamp-example-plugins:percussiononsets", 44100);
Chris@23 15 */
Chris@0 16 public class PluginLoader
Chris@0 17 {
Chris@0 18 public class LoadFailedException extends Exception { };
Chris@0 19
Chris@23 20 /**
Chris@23 21 * PluginLoader is a singleton. Return the instance of it.
Chris@23 22 */
Chris@0 23 public static synchronized PluginLoader getInstance() {
Chris@0 24 if (inst == null) {
Chris@0 25 inst = new PluginLoader();
Chris@0 26 inst.initialise();
Chris@0 27 }
Chris@0 28 return inst;
Chris@0 29 }
Chris@0 30
Chris@23 31 /**
Chris@23 32 * Search for all available Vamp plugins, and return a list of
Chris@23 33 * their plugin keys (suitable for passing to loadPlugin) in the
Chris@23 34 * order in which they were found.
Chris@23 35 */
Chris@24 36 public native String[] listPlugins();
Chris@23 37
Chris@23 38 /**
Chris@29 39 * AdapterFlags contains a set of values that may be OR'd together
Chris@29 40 * and passed to loadPlugin() to indicate which of the properties
Chris@29 41 * of a plugin the host would like PluginLoader to take care of
Chris@29 42 * for it, rather than having to handle itself.
Chris@29 43 *
Chris@29 44 * Use of these flags permits the host to cater more easily for
Chris@29 45 * plugins with varying requirements for their input formats, at
Chris@29 46 * some expense in flexibility.
Chris@29 47 */
Chris@29 48 public class AdapterFlags {
Chris@29 49
Chris@29 50 /**
Chris@29 51 * ADAPT_INPUT_DOMAIN - If the plugin expects frequency domain
Chris@29 52 * input, automatically convert it to one that expects
Chris@29 53 * time-domain input by interpolating an adapter that carries
Chris@29 54 * out the FFT conversion silently.
Chris@29 55 *
Chris@29 56 * This enables a host to accommodate time- and
Chris@29 57 * frequency-domain plugins without needing to do any
Chris@29 58 * conversion itself, but it means the host gets no control
Chris@29 59 * over the windowing and FFT methods used. A Hann window is
Chris@29 60 * used, and the FFT is unlikely to be the fastest native
Chris@29 61 * implementation available.
Chris@29 62 */
Chris@29 63 public static final int ADAPT_INPUT_DOMAIN = 1;
Chris@29 64
Chris@29 65 /**
Chris@29 66 * ADAPT_CHANNEL_COUNT - Automatically handle any discrepancy
Chris@29 67 * between the number of channels supported by the plugin and
Chris@29 68 * the number provided by the host when calling
Chris@29 69 * Plugin.initialise(). This enables a host to use plugins
Chris@29 70 * that may require the input to be mixed down to mono, etc.,
Chris@29 71 * without having to worry about doing that itself.
Chris@29 72 */
Chris@29 73 public static final int ADAPT_CHANNEL_COUNT = 2;
Chris@29 74
Chris@29 75 /**
Chris@29 76 * ADAPT_BUFFER_SIZE - Permit the host to ignore the preferred
Chris@29 77 * step and block size reported by the plugin when calling
Chris@29 78 * initialise(), and to provide whatever step and block size
Chris@29 79 * are most convenient instead.
Chris@29 80 *
Chris@29 81 * This may require modifying the sample type and rate
Chris@29 82 * specifications for the plugin outputs and modifying the
Chris@29 83 * timestamps on the output features in order to obtain
Chris@29 84 * correct time stamping.
Chris@29 85 */
Chris@29 86 public static final int ADAPT_BUFFER_SIZE = 3;
Chris@29 87
Chris@29 88 /**
Chris@29 89 * ADAPT_ALL - Perform all available adaptations that are
Chris@29 90 * meaningful for the plugin.
Chris@29 91 */
Chris@29 92 public static final int ADAPT_ALL = 255;
Chris@29 93
Chris@29 94 /**
Chris@29 95 * ADAPT_NONE - If passed to loadPlugin as the adapterFlags
Chris@29 96 * value, causes no adaptations to be done.
Chris@29 97 */
Chris@29 98 public static final int ADAPT_NONE = 0;
Chris@29 99 };
Chris@29 100
Chris@29 101 /**
Chris@23 102 * Load a native Vamp plugin from the plugin path. If the plugin
Chris@23 103 * cannot be loaded, throw LoadFailedException.
Chris@23 104 *
Chris@23 105 * key is the plugin key consisting of the plugin's library base
Chris@23 106 * name and its identifier, colon-separated; inputSampleRate is
Chris@23 107 * the processing sample rate for input audio.
Chris@23 108 *
Chris@29 109 * adapterFlags should contain an OR of the desired AdapterFlags
Chris@29 110 * options for the plugin, or AdapterFlags.ADAPT_NONE if no
Chris@29 111 * automatic adaptations are to be made.
Chris@23 112 */
Chris@29 113 public Plugin loadPlugin(String key,
Chris@29 114 float inputSampleRate,
Chris@29 115 int adapterFlags)
Chris@0 116 throws LoadFailedException {
Chris@29 117 long handle = loadPluginNative(key, inputSampleRate, adapterFlags);
Chris@0 118 if (handle != 0) return new Plugin(handle);
Chris@0 119 else throw new LoadFailedException();
Chris@0 120 }
Chris@0 121
Chris@23 122 /**
Chris@23 123 * Return the category hierarchy for a Vamp plugin, given its
Chris@23 124 * identifying key. The hierarchy is a sequence of category names
Chris@23 125 * giving the location of a plugin within a category forest,
Chris@23 126 * containing the human-readable names of the plugin's category
Chris@23 127 * tree root, followed by each of the nodes down to the leaf
Chris@23 128 * containing the plugin.
Chris@23 129 *
Chris@23 130 * If the plugin has no category information, return an empty
Chris@23 131 * list.
Chris@23 132 */
Chris@24 133 public native String[] getPluginCategory(String key);
Chris@23 134
Chris@0 135 private PluginLoader() { initialise(); }
Chris@29 136 private native long loadPluginNative(String key, float inputSampleRate,
Chris@29 137 int adapterFlags);
Chris@0 138 private native void initialise();
Chris@0 139 private static PluginLoader inst;
Chris@0 140 private long nativeHandle;
Chris@0 141
Chris@0 142 static {
Chris@0 143 System.loadLibrary("vamp-jni");
Chris@0 144 }
Chris@0 145 }
Chris@0 146