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