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