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