cannam@110: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ cannam@110: cannam@110: /* cannam@110: Vamp cannam@110: cannam@110: An API for audio analysis and feature extraction plugins. cannam@110: cannam@110: Centre for Digital Music, Queen Mary, University of London. cannam@110: Copyright 2006 Chris Cannam. cannam@110: cannam@110: Permission is hereby granted, free of charge, to any person cannam@110: obtaining a copy of this software and associated documentation cannam@110: files (the "Software"), to deal in the Software without cannam@110: restriction, including without limitation the rights to use, copy, cannam@110: modify, merge, publish, distribute, sublicense, and/or sell copies cannam@110: of the Software, and to permit persons to whom the Software is cannam@110: furnished to do so, subject to the following conditions: cannam@110: cannam@110: The above copyright notice and this permission notice shall be cannam@110: included in all copies or substantial portions of the Software. cannam@110: cannam@110: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, cannam@110: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF cannam@110: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND cannam@110: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR cannam@110: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF cannam@110: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION cannam@110: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cannam@110: cannam@110: Except as contained in this notice, the names of the Centre for cannam@110: Digital Music; Queen Mary, University of London; and Chris Cannam cannam@110: shall not be used in advertising or otherwise to promote the sale, cannam@110: use or other dealings in this Software without prior written cannam@110: authorization. cannam@110: */ cannam@110: cannam@110: #ifndef VAMP_HEADER_INCLUDED cannam@110: #define VAMP_HEADER_INCLUDED cannam@110: cannam@110: #ifdef __cplusplus cannam@110: extern "C" { cannam@110: #endif cannam@110: cannam@110: /** cannam@110: * Plugin API version. This is incremented when a change is made that cannam@110: * changes the binary layout of the descriptor records. When this cannam@110: * happens, there should be a mechanism for retaining compatibility cannam@110: * with older hosts and/or plugins. cannam@110: * cannam@110: * See also the vampApiVersion field in the plugin descriptor, and the cannam@110: * hostApiVersion argument to the vampGetPluginDescriptor function. cannam@110: */ cannam@110: #define VAMP_API_VERSION 2 cannam@110: cannam@110: /** cannam@110: * C language API for Vamp plugins. cannam@110: * cannam@110: * This is the formal plugin API for Vamp. Plugin authors may prefer cannam@110: * to use the C++ classes provided in the Vamp plugin SDK, instead of cannam@110: * using this API directly. There is an adapter class provided that cannam@110: * makes C++ plugins available using this C API with relatively little cannam@110: * work, and the C++ headers are more thoroughly documented. cannam@110: * cannam@110: * IMPORTANT: The comments in this file summarise the purpose of each cannam@110: * of the declared fields and functions, but do not provide a complete cannam@110: * guide to their permitted values and expected usage. Please refer cannam@110: * to the C++ headers in the Vamp plugin SDK for further details and cannam@110: * plugin lifecycle documentation. cannam@110: */ cannam@110: cannam@110: typedef struct _VampParameterDescriptor cannam@110: { cannam@110: /** Computer-usable name of the parameter. Must not change. [a-zA-Z0-9_] */ cannam@110: const char *identifier; cannam@110: cannam@110: /** Human-readable name of the parameter. May be translatable. */ cannam@110: const char *name; cannam@110: cannam@110: /** Human-readable short text about the parameter. May be translatable. */ cannam@110: const char *description; cannam@110: cannam@110: /** Human-readable unit of the parameter. */ cannam@110: const char *unit; cannam@110: cannam@110: /** Minimum value. */ cannam@110: float minValue; cannam@110: cannam@110: /** Maximum value. */ cannam@110: float maxValue; cannam@110: cannam@110: /** Default value. Plugin is responsible for setting this on initialise. */ cannam@110: float defaultValue; cannam@110: cannam@110: /** 1 if parameter values are quantized to a particular resolution. */ cannam@110: int isQuantized; cannam@110: cannam@110: /** Quantization resolution, if isQuantized. */ cannam@110: float quantizeStep; cannam@110: cannam@110: /** Human-readable names of the values, if isQuantized. May be NULL. */ cannam@110: const char **valueNames; cannam@110: cannam@110: } VampParameterDescriptor; cannam@110: cannam@110: typedef enum cannam@110: { cannam@110: /** Each process call returns results aligned with call's block start. */ cannam@110: vampOneSamplePerStep, cannam@110: cannam@110: /** Returned results are evenly spaced at samplerate specified below. */ cannam@110: vampFixedSampleRate, cannam@110: cannam@110: /** Returned results have their own individual timestamps. */ cannam@110: vampVariableSampleRate cannam@110: cannam@110: } VampSampleType; cannam@110: cannam@110: typedef struct _VampOutputDescriptor cannam@110: { cannam@110: /** Computer-usable name of the output. Must not change. [a-zA-Z0-9_] */ cannam@110: const char *identifier; cannam@110: cannam@110: /** Human-readable name of the output. May be translatable. */ cannam@110: const char *name; cannam@110: cannam@110: /** Human-readable short text about the output. May be translatable. */ cannam@110: const char *description; cannam@110: cannam@110: /** Human-readable name of the unit of the output. */ cannam@110: const char *unit; cannam@110: cannam@110: /** 1 if output has equal number of values for each returned result. */ cannam@110: int hasFixedBinCount; cannam@110: cannam@110: /** Number of values per result, if hasFixedBinCount. */ cannam@110: unsigned int binCount; cannam@110: cannam@110: /** Names of returned value bins, if hasFixedBinCount. May be NULL. */ cannam@110: const char **binNames; cannam@110: cannam@110: /** 1 if each returned value falls within the same fixed min/max range. */ cannam@110: int hasKnownExtents; cannam@110: cannam@110: /** Minimum value for a returned result in any bin, if hasKnownExtents. */ cannam@110: float minValue; cannam@110: cannam@110: /** Maximum value for a returned result in any bin, if hasKnownExtents. */ cannam@110: float maxValue; cannam@110: cannam@110: /** 1 if returned results are quantized to a particular resolution. */ cannam@110: int isQuantized; cannam@110: cannam@110: /** Quantization resolution for returned results, if isQuantized. */ cannam@110: float quantizeStep; cannam@110: cannam@110: /** Time positioning method for returned results (see VampSampleType). */ cannam@110: VampSampleType sampleType; cannam@110: cannam@110: /** Sample rate of returned results, if sampleType is vampFixedSampleRate. cannam@110: "Resolution" of result, if sampleType is vampVariableSampleRate. */ cannam@110: float sampleRate; cannam@110: cannam@110: /** 1 if the returned results for this output are known to have a cannam@110: duration field. cannam@110: cannam@110: This field is new in Vamp API version 2; it must not be tested cannam@110: for plugins that report an older API version in their plugin cannam@110: descriptor. cannam@110: */ cannam@110: int hasDuration; cannam@110: cannam@110: } VampOutputDescriptor; cannam@110: cannam@110: typedef struct _VampFeature cannam@110: { cannam@110: /** 1 if the feature has a timestamp (i.e. if vampVariableSampleRate). */ cannam@110: int hasTimestamp; cannam@110: cannam@110: /** Seconds component of timestamp. */ cannam@110: int sec; cannam@110: cannam@110: /** Nanoseconds component of timestamp. */ cannam@110: int nsec; cannam@110: cannam@110: /** Number of values. Must be binCount if hasFixedBinCount. */ cannam@110: unsigned int valueCount; cannam@110: cannam@110: /** Values for this returned sample. */ cannam@110: float *values; cannam@110: cannam@110: /** Label for this returned sample. May be NULL. */ cannam@110: char *label; cannam@110: cannam@110: } VampFeature; cannam@110: cannam@110: typedef struct _VampFeatureV2 cannam@110: { cannam@110: /** 1 if the feature has a duration. */ cannam@110: int hasDuration; cannam@110: cannam@110: /** Seconds component of duratiion. */ cannam@110: int durationSec; cannam@110: cannam@110: /** Nanoseconds component of duration. */ cannam@110: int durationNsec; cannam@110: cannam@110: } VampFeatureV2; cannam@110: cannam@110: typedef union _VampFeatureUnion cannam@110: { cannam@110: // sizeof(featureV1) >= sizeof(featureV2) for backward compatibility cannam@110: VampFeature v1; cannam@110: VampFeatureV2 v2; cannam@110: cannam@110: } VampFeatureUnion; cannam@110: cannam@110: typedef struct _VampFeatureList cannam@110: { cannam@110: /** Number of features in this feature list. */ cannam@110: unsigned int featureCount; cannam@110: cannam@110: /** Features in this feature list. May be NULL if featureCount is cannam@110: zero. cannam@110: cannam@110: If present, this array must contain featureCount feature cannam@110: structures for a Vamp API version 1 plugin, or 2*featureCount cannam@110: feature unions for a Vamp API version 2 plugin. cannam@110: cannam@110: The features returned by an API version 2 plugin must consist cannam@110: of the same feature structures as in API version 1 for the cannam@110: first featureCount array elements, followed by featureCount cannam@110: unions that contain VampFeatureV2 structures (or NULL pointers cannam@110: if no V2 feature structures are present). cannam@110: */ cannam@110: VampFeatureUnion *features; cannam@110: cannam@110: } VampFeatureList; cannam@110: cannam@110: typedef enum cannam@110: { cannam@110: vampTimeDomain, cannam@110: vampFrequencyDomain cannam@110: cannam@110: } VampInputDomain; cannam@110: cannam@110: typedef void *VampPluginHandle; cannam@110: cannam@110: typedef struct _VampPluginDescriptor cannam@110: { cannam@110: /** API version with which this descriptor is compatible. */ cannam@110: unsigned int vampApiVersion; cannam@110: cannam@110: /** Computer-usable name of the plugin. Must not change. [a-zA-Z0-9_] */ cannam@110: const char *identifier; cannam@110: cannam@110: /** Human-readable name of the plugin. May be translatable. */ cannam@110: const char *name; cannam@110: cannam@110: /** Human-readable short text about the plugin. May be translatable. */ cannam@110: const char *description; cannam@110: cannam@110: /** Human-readable name of plugin's author or vendor. */ cannam@110: const char *maker; cannam@110: cannam@110: /** Version number of the plugin. */ cannam@110: int pluginVersion; cannam@110: cannam@110: /** Human-readable summary of copyright or licensing for plugin. */ cannam@110: const char *copyright; cannam@110: cannam@110: /** Number of parameter inputs. */ cannam@110: unsigned int parameterCount; cannam@110: cannam@110: /** Fixed descriptors for parameter inputs. */ cannam@110: const VampParameterDescriptor **parameters; cannam@110: cannam@110: /** Number of programs. */ cannam@110: unsigned int programCount; cannam@110: cannam@110: /** Fixed names for programs. */ cannam@110: const char **programs; cannam@110: cannam@110: /** Preferred input domain for audio input (time or frequency). */ cannam@110: VampInputDomain inputDomain; cannam@110: cannam@110: /** Create and return a new instance of this plugin. */ cannam@110: VampPluginHandle (*instantiate)(const struct _VampPluginDescriptor *, cannam@110: float inputSampleRate); cannam@110: cannam@110: /** Destroy an instance of this plugin. */ cannam@110: void (*cleanup)(VampPluginHandle); cannam@110: cannam@110: /** Initialise an instance following parameter configuration. */ cannam@110: int (*initialise)(VampPluginHandle, cannam@110: unsigned int inputChannels, cannam@110: unsigned int stepSize, cannam@110: unsigned int blockSize); cannam@110: cannam@110: /** Reset an instance, ready to use again on new input data. */ cannam@110: void (*reset)(VampPluginHandle); cannam@110: cannam@110: /** Get a parameter value. */ cannam@110: float (*getParameter)(VampPluginHandle, int); cannam@110: cannam@110: /** Set a parameter value. May only be called before initialise. */ cannam@110: void (*setParameter)(VampPluginHandle, int, float); cannam@110: cannam@110: /** Get the current program (if programCount > 0). */ cannam@110: unsigned int (*getCurrentProgram)(VampPluginHandle); cannam@110: cannam@110: /** Set the current program. May only be called before initialise. */ cannam@110: void (*selectProgram)(VampPluginHandle, unsigned int); cannam@110: cannam@110: /** Get the plugin's preferred processing window increment in samples. */ cannam@110: unsigned int (*getPreferredStepSize)(VampPluginHandle); cannam@110: cannam@110: /** Get the plugin's preferred processing window size in samples. */ cannam@110: unsigned int (*getPreferredBlockSize)(VampPluginHandle); cannam@110: cannam@110: /** Get the minimum number of input channels this plugin can handle. */ cannam@110: unsigned int (*getMinChannelCount)(VampPluginHandle); cannam@110: cannam@110: /** Get the maximum number of input channels this plugin can handle. */ cannam@110: unsigned int (*getMaxChannelCount)(VampPluginHandle); cannam@110: cannam@110: /** Get the number of feature outputs (distinct sets of results). */ cannam@110: unsigned int (*getOutputCount)(VampPluginHandle); cannam@110: cannam@110: /** Get a descriptor for a given feature output. Returned pointer cannam@110: is valid only until next call to getOutputDescriptor for this cannam@110: handle, or releaseOutputDescriptor for this descriptor. Host cannam@110: must call releaseOutputDescriptor after use. */ cannam@110: VampOutputDescriptor *(*getOutputDescriptor)(VampPluginHandle, cannam@110: unsigned int); cannam@110: cannam@110: /** Destroy a descriptor for a feature output. */ cannam@110: void (*releaseOutputDescriptor)(VampOutputDescriptor *); cannam@110: cannam@110: /** Process an input block and return a set of features. Returned cannam@110: pointer is valid only until next call to process, cannam@110: getRemainingFeatures, or cleanup for this handle, or cannam@110: releaseFeatureSet for this feature set. Host must call cannam@110: releaseFeatureSet after use. */ cannam@110: VampFeatureList *(*process)(VampPluginHandle, cannam@110: const float *const *inputBuffers, cannam@110: int sec, cannam@110: int nsec); cannam@110: cannam@110: /** Return any remaining features at the end of processing. */ cannam@110: VampFeatureList *(*getRemainingFeatures)(VampPluginHandle); cannam@110: cannam@110: /** Release a feature set returned from process or getRemainingFeatures. */ cannam@110: void (*releaseFeatureSet)(VampFeatureList *); cannam@110: cannam@110: } VampPluginDescriptor; cannam@110: cannam@110: cannam@110: /** Get the descriptor for a given plugin index in this library. cannam@110: Return NULL if the index is outside the range of valid indices for cannam@110: this plugin library. cannam@110: cannam@110: The hostApiVersion argument tells the library code the highest cannam@110: Vamp API version supported by the host. The function should cannam@110: return a plugin descriptor compatible with the highest API version cannam@110: supported by the library that is no higher than that supported by cannam@110: the host. Provided the descriptor has the correct vampApiVersion cannam@110: field for its actual compatibility level, the host should be able cannam@110: to do the right thing with it: use it if possible, discard it cannam@110: otherwise. cannam@110: cannam@110: This is the only symbol that a Vamp plugin actually needs to cannam@110: export from its shared object; all others can be hidden. See the cannam@110: accompanying documentation for notes on how to achieve this with cannam@110: certain compilers. cannam@110: */ cannam@110: const VampPluginDescriptor *vampGetPluginDescriptor cannam@110: (unsigned int hostApiVersion, unsigned int index); cannam@110: cannam@110: cannam@110: /** Function pointer type for vampGetPluginDescriptor. */ cannam@110: typedef const VampPluginDescriptor *(*VampGetPluginDescriptorFunction) cannam@110: (unsigned int, unsigned int); cannam@110: cannam@110: #ifdef __cplusplus cannam@110: } cannam@110: #endif cannam@110: cannam@110: #endif