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