Mercurial > hg > jvamp
changeset 29:7d1118b3860d
Add adapter flags
author | Chris Cannam |
---|---|
date | Thu, 22 Nov 2012 11:35:17 +0000 |
parents | f2914a92b553 |
children | 02db37c2301b |
files | org/vamp_plugins/PluginLoader.java src/PluginLoader.cpp src/org_vamp_plugins_PluginLoader.h test/test.java |
diffstat | 4 files changed, 79 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/org/vamp_plugins/PluginLoader.java Mon Nov 19 15:12:44 2012 +0000 +++ b/org/vamp_plugins/PluginLoader.java Thu Nov 22 11:35:17 2012 +0000 @@ -36,6 +36,69 @@ public native String[] listPlugins(); /** + * AdapterFlags contains a set of values that may be OR'd together + * and passed to loadPlugin() to indicate which of the properties + * of a plugin the host would like PluginLoader to take care of + * for it, rather than having to handle itself. + * + * Use of these flags permits the host to cater more easily for + * plugins with varying requirements for their input formats, at + * some expense in flexibility. + */ + public class AdapterFlags { + + /** + * ADAPT_INPUT_DOMAIN - If the plugin expects frequency domain + * input, automatically convert it to one that expects + * time-domain input by interpolating an adapter that carries + * out the FFT conversion silently. + * + * This enables a host to accommodate time- and + * frequency-domain plugins without needing to do any + * conversion itself, but it means the host gets no control + * over the windowing and FFT methods used. A Hann window is + * used, and the FFT is unlikely to be the fastest native + * implementation available. + */ + public static final int ADAPT_INPUT_DOMAIN = 1; + + /** + * ADAPT_CHANNEL_COUNT - Automatically handle any discrepancy + * between the number of channels supported by the plugin and + * the number provided by the host when calling + * Plugin.initialise(). This enables a host to use plugins + * that may require the input to be mixed down to mono, etc., + * without having to worry about doing that itself. + */ + public static final int ADAPT_CHANNEL_COUNT = 2; + + /** + * ADAPT_BUFFER_SIZE - Permit the host to ignore the preferred + * step and block size reported by the plugin when calling + * initialise(), and to provide whatever step and block size + * are most convenient instead. + * + * This may require modifying the sample type and rate + * specifications for the plugin outputs and modifying the + * timestamps on the output features in order to obtain + * correct time stamping. + */ + public static final int ADAPT_BUFFER_SIZE = 3; + + /** + * ADAPT_ALL - Perform all available adaptations that are + * meaningful for the plugin. + */ + public static final int ADAPT_ALL = 255; + + /** + * ADAPT_NONE - If passed to loadPlugin as the adapterFlags + * value, causes no adaptations to be done. + */ + public static final int ADAPT_NONE = 0; + }; + + /** * Load a native Vamp plugin from the plugin path. If the plugin * cannot be loaded, throw LoadFailedException. * @@ -43,11 +106,15 @@ * name and its identifier, colon-separated; inputSampleRate is * the processing sample rate for input audio. * - *!!! todo: adapter flags + * adapterFlags should contain an OR of the desired AdapterFlags + * options for the plugin, or AdapterFlags.ADAPT_NONE if no + * automatic adaptations are to be made. */ - public Plugin loadPlugin(String key, float inputSampleRate) + public Plugin loadPlugin(String key, + float inputSampleRate, + int adapterFlags) throws LoadFailedException { - long handle = loadPluginNative(key, inputSampleRate); + long handle = loadPluginNative(key, inputSampleRate, adapterFlags); if (handle != 0) return new Plugin(handle); else throw new LoadFailedException(); } @@ -66,7 +133,8 @@ public native String[] getPluginCategory(String key); private PluginLoader() { initialise(); } - private native long loadPluginNative(String key, float inputSampleRate); + private native long loadPluginNative(String key, float inputSampleRate, + int adapterFlags); private native void initialise(); private static PluginLoader inst; private long nativeHandle;
--- a/src/PluginLoader.cpp Mon Nov 19 15:12:44 2012 +0000 +++ b/src/PluginLoader.cpp Thu Nov 22 11:35:17 2012 +0000 @@ -30,11 +30,12 @@ jlong Java_org_vamp_1plugins_PluginLoader_loadPluginNative(JNIEnv *env, jobject obj, - jstring key, jfloat rate) + jstring key, jfloat rate, + jint flags) { PluginLoader *inst = getHandle<PluginLoader>(env, obj); const char *kstr = env->GetStringUTFChars(key, 0); - Plugin *p = inst->loadPlugin(kstr, rate, PluginLoader::ADAPT_ALL); //!!! args! + Plugin *p = inst->loadPlugin(kstr, rate, flags); env->ReleaseStringUTFChars(key, kstr); return (jlong)p; } @@ -55,6 +56,4 @@ return result; } - -//!!! todo: loadPlugin adapters
--- a/src/org_vamp_plugins_PluginLoader.h Mon Nov 19 15:12:44 2012 +0000 +++ b/src/org_vamp_plugins_PluginLoader.h Thu Nov 22 11:35:17 2012 +0000 @@ -9,13 +9,13 @@ #endif JNIEXPORT jlong JNICALL Java_org_vamp_1plugins_PluginLoader_loadPluginNative - (JNIEnv *, jobject, jstring, jfloat); +(JNIEnv *, jobject, jstring, jfloat, jint); JNIEXPORT jobjectArray JNICALL Java_org_vamp_1plugins_PluginLoader_listPlugins (JNIEnv *, jobject); JNIEXPORT void JNICALL Java_org_vamp_1plugins_PluginLoader_initialise - (JNIEnv *, jobject); +(JNIEnv *, jobject); JNIEXPORT jobjectArray JNICALL Java_org_vamp_1plugins_PluginLoader_getPluginCategory (JNIEnv *, jobject, jstring);
--- a/test/test.java Mon Nov 19 15:12:44 2012 +0000 +++ b/test/test.java Thu Nov 22 11:35:17 2012 +0000 @@ -45,7 +45,7 @@ } try { - Plugin p = loader.loadPlugin(key, 44100); + Plugin p = loader.loadPlugin(key, 44100, PluginLoader.AdapterFlags.ADAPT_ALL); String[] cat = loader.getPluginCategory(key); System.out.print("category: "); for (int i = 0; i < cat.length; ++i) { @@ -58,7 +58,7 @@ System.out.println("description: " + p.getDescription()); System.out.println("version: " + p.getPluginVersion()); Plugin.InputDomain domain = p.getInputDomain(); - if (domain == Plugin.InputDomain.TimeDomain) { + if (domain == Plugin.InputDomain.TIME_DOMAIN) { System.out.println("This is a time-domain plugin"); } else { System.out.println("This is a frequency-domain plugin");