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