annotate win32-mingw/include/vamp-sdk/Plugin.h @ 105:c83a7e2af39c

Ranlib
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 25 Mar 2013 16:28:19 +0000
parents c6e1ae789cfb
children 619f715526df
rev   line source
cannam@99 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@99 2
cannam@99 3 /*
cannam@99 4 Vamp
cannam@99 5
cannam@99 6 An API for audio analysis and feature extraction plugins.
cannam@99 7
cannam@99 8 Centre for Digital Music, Queen Mary, University of London.
cannam@99 9 Copyright 2006 Chris Cannam.
cannam@99 10
cannam@99 11 Permission is hereby granted, free of charge, to any person
cannam@99 12 obtaining a copy of this software and associated documentation
cannam@99 13 files (the "Software"), to deal in the Software without
cannam@99 14 restriction, including without limitation the rights to use, copy,
cannam@99 15 modify, merge, publish, distribute, sublicense, and/or sell copies
cannam@99 16 of the Software, and to permit persons to whom the Software is
cannam@99 17 furnished to do so, subject to the following conditions:
cannam@99 18
cannam@99 19 The above copyright notice and this permission notice shall be
cannam@99 20 included in all copies or substantial portions of the Software.
cannam@99 21
cannam@99 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@99 23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@99 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cannam@99 25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
cannam@99 26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@99 27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@99 28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@99 29
cannam@99 30 Except as contained in this notice, the names of the Centre for
cannam@99 31 Digital Music; Queen Mary, University of London; and Chris Cannam
cannam@99 32 shall not be used in advertising or otherwise to promote the sale,
cannam@99 33 use or other dealings in this Software without prior written
cannam@99 34 authorization.
cannam@99 35 */
cannam@99 36
cannam@99 37 #ifndef _VAMP_SDK_PLUGIN_H_
cannam@99 38 #define _VAMP_SDK_PLUGIN_H_
cannam@99 39
cannam@99 40 #include <string>
cannam@99 41 #include <vector>
cannam@99 42 #include <map>
cannam@99 43
cannam@99 44 #include "PluginBase.h"
cannam@99 45 #include "RealTime.h"
cannam@99 46
cannam@99 47 #include "plugguard.h"
cannam@99 48 _VAMP_SDK_PLUGSPACE_BEGIN(Plugin.h)
cannam@99 49
cannam@99 50 namespace Vamp {
cannam@99 51
cannam@99 52 /**
cannam@99 53 * \class Plugin Plugin.h <vamp-sdk/Plugin.h>
cannam@99 54 *
cannam@99 55 * Vamp::Plugin is a base class for plugin instance classes
cannam@99 56 * that provide feature extraction from audio or related data.
cannam@99 57 *
cannam@99 58 * In most cases, the input will be audio and the output will be a
cannam@99 59 * stream of derived data at a lower sampling resolution than the
cannam@99 60 * input.
cannam@99 61 *
cannam@99 62 * Note that this class inherits several abstract methods from
cannam@99 63 * PluginBase. These must be implemented by the subclass.
cannam@99 64 *
cannam@99 65 *
cannam@99 66 * PLUGIN LIFECYCLE
cannam@99 67 *
cannam@99 68 * Feature extraction plugins are managed differently from real-time
cannam@99 69 * plugins (such as VST effects). The main difference is that the
cannam@99 70 * parameters for a feature extraction plugin are configured before
cannam@99 71 * the plugin is used, and do not change during use.
cannam@99 72 *
cannam@99 73 * 1. Host constructs the plugin, passing it the input sample rate.
cannam@99 74 * The plugin may do basic initialisation, but should not do anything
cannam@99 75 * computationally expensive at this point. You must make sure your
cannam@99 76 * plugin is cheap to construct, otherwise you'll seriously affect the
cannam@99 77 * startup performance of almost all hosts. If you have serious
cannam@99 78 * initialisation to do, the proper place is in initialise() (step 5).
cannam@99 79 *
cannam@99 80 * 2. Host may query the plugin's available outputs.
cannam@99 81 *
cannam@99 82 * 3. Host queries programs and parameter descriptors, and may set
cannam@99 83 * some or all of them. Parameters that are not explicitly set should
cannam@99 84 * take their default values as specified in the parameter descriptor.
cannam@99 85 * When a program is set, the parameter values may change and the host
cannam@99 86 * will re-query them to check.
cannam@99 87 *
cannam@99 88 * 4. Host queries the preferred step size, block size and number of
cannam@99 89 * channels. These may all vary depending on the parameter values.
cannam@99 90 * (Note however that you cannot make the number of distinct outputs
cannam@99 91 * dependent on parameter values.)
cannam@99 92 *
cannam@99 93 * 5. Plugin is properly initialised with a call to initialise. This
cannam@99 94 * fixes the step size, block size, and number of channels, as well as
cannam@99 95 * all of the parameter and program settings. If the values passed in
cannam@99 96 * to initialise do not match the plugin's advertised preferred values
cannam@99 97 * from step 4, the plugin may refuse to initialise and return false
cannam@99 98 * (although if possible it should accept the new values). Any
cannam@99 99 * computationally expensive setup code should take place here.
cannam@99 100 *
cannam@99 101 * 6. Host finally checks the number of values, resolution, extents
cannam@99 102 * etc per output (which may vary depending on the number of channels,
cannam@99 103 * step size and block size as well as the parameter values).
cannam@99 104 *
cannam@99 105 * 7. Host will repeatedly call the process method to pass in blocks
cannam@99 106 * of input data. This method may return features extracted from that
cannam@99 107 * data (if the plugin is causal).
cannam@99 108 *
cannam@99 109 * 8. Host will call getRemainingFeatures exactly once, after all the
cannam@99 110 * input data has been processed. This may return any non-causal or
cannam@99 111 * leftover features.
cannam@99 112 *
cannam@99 113 * 9. At any point after initialise was called, the host may
cannam@99 114 * optionally call the reset method and restart processing. (This
cannam@99 115 * does not mean it can change the parameters, which are fixed from
cannam@99 116 * initialise until destruction.)
cannam@99 117 *
cannam@99 118 * A plugin does not need to handle the case where setParameter or
cannam@99 119 * selectProgram is called after initialise has been called. It's the
cannam@99 120 * host's responsibility not to do that. Similarly, the plugin may
cannam@99 121 * safely assume that initialise is called no more than once.
cannam@99 122 */
cannam@99 123
cannam@99 124 class Plugin : public PluginBase
cannam@99 125 {
cannam@99 126 public:
cannam@99 127 virtual ~Plugin() { }
cannam@99 128
cannam@99 129 /**
cannam@99 130 * Initialise a plugin to prepare it for use with the given number
cannam@99 131 * of input channels, step size (window increment, in sample
cannam@99 132 * frames) and block size (window size, in sample frames).
cannam@99 133 *
cannam@99 134 * The input sample rate should have been already specified at
cannam@99 135 * construction time.
cannam@99 136 *
cannam@99 137 * Return true for successful initialisation, false if the number
cannam@99 138 * of input channels, step size and/or block size cannot be
cannam@99 139 * supported.
cannam@99 140 */
cannam@99 141 virtual bool initialise(size_t inputChannels,
cannam@99 142 size_t stepSize,
cannam@99 143 size_t blockSize) = 0;
cannam@99 144
cannam@99 145 /**
cannam@99 146 * Reset the plugin after use, to prepare it for another clean
cannam@99 147 * run. Not called for the first initialisation (i.e. initialise
cannam@99 148 * must also do a reset).
cannam@99 149 */
cannam@99 150 virtual void reset() = 0;
cannam@99 151
cannam@99 152 enum InputDomain { TimeDomain, FrequencyDomain };
cannam@99 153
cannam@99 154 /**
cannam@99 155 * Get the plugin's required input domain.
cannam@99 156 *
cannam@99 157 * If this is TimeDomain, the samples provided to the process()
cannam@99 158 * function (below) will be in the time domain, as for a
cannam@99 159 * traditional audio processing plugin.
cannam@99 160 *
cannam@99 161 * If this is FrequencyDomain, the host will carry out a windowed
cannam@99 162 * FFT of size equal to the negotiated block size on the data
cannam@99 163 * before passing the frequency bin data in to process(). The
cannam@99 164 * input data for the FFT will be rotated so as to place the
cannam@99 165 * origin in the centre of the block.
cannam@99 166 * The plugin does not get to choose the window type -- the host
cannam@99 167 * will either let the user do so, or will use a Hanning window.
cannam@99 168 */
cannam@99 169 virtual InputDomain getInputDomain() const = 0;
cannam@99 170
cannam@99 171 /**
cannam@99 172 * Get the preferred block size (window size -- the number of
cannam@99 173 * sample frames passed in each block to the process() function).
cannam@99 174 * This should be called before initialise().
cannam@99 175 *
cannam@99 176 * A plugin that can handle any block size may return 0. The
cannam@99 177 * final block size will be set in the initialise() call.
cannam@99 178 */
cannam@99 179 virtual size_t getPreferredBlockSize() const { return 0; }
cannam@99 180
cannam@99 181 /**
cannam@99 182 * Get the preferred step size (window increment -- the distance
cannam@99 183 * in sample frames between the start frames of consecutive blocks
cannam@99 184 * passed to the process() function) for the plugin. This should
cannam@99 185 * be called before initialise().
cannam@99 186 *
cannam@99 187 * A plugin may return 0 if it has no particular interest in the
cannam@99 188 * step size. In this case, the host should make the step size
cannam@99 189 * equal to the block size if the plugin is accepting input in the
cannam@99 190 * time domain. If the plugin is accepting input in the frequency
cannam@99 191 * domain, the host may use any step size. The final step size
cannam@99 192 * will be set in the initialise() call.
cannam@99 193 */
cannam@99 194 virtual size_t getPreferredStepSize() const { return 0; }
cannam@99 195
cannam@99 196 /**
cannam@99 197 * Get the minimum supported number of input channels.
cannam@99 198 */
cannam@99 199 virtual size_t getMinChannelCount() const { return 1; }
cannam@99 200
cannam@99 201 /**
cannam@99 202 * Get the maximum supported number of input channels.
cannam@99 203 */
cannam@99 204 virtual size_t getMaxChannelCount() const { return 1; }
cannam@99 205
cannam@99 206 struct OutputDescriptor
cannam@99 207 {
cannam@99 208 /**
cannam@99 209 * The name of the output, in computer-usable form. Should be
cannam@99 210 * reasonably short and without whitespace or punctuation, using
cannam@99 211 * the characters [a-zA-Z0-9_-] only.
cannam@99 212 * Example: "zero_crossing_count"
cannam@99 213 */
cannam@99 214 std::string identifier;
cannam@99 215
cannam@99 216 /**
cannam@99 217 * The human-readable name of the output.
cannam@99 218 * Example: "Zero Crossing Counts"
cannam@99 219 */
cannam@99 220 std::string name;
cannam@99 221
cannam@99 222 /**
cannam@99 223 * A human-readable short text describing the output. May be
cannam@99 224 * empty if the name has said it all already.
cannam@99 225 * Example: "The number of zero crossing points per processing block"
cannam@99 226 */
cannam@99 227 std::string description;
cannam@99 228
cannam@99 229 /**
cannam@99 230 * The unit of the output, in human-readable form.
cannam@99 231 */
cannam@99 232 std::string unit;
cannam@99 233
cannam@99 234 /**
cannam@99 235 * True if the output has the same number of values per sample
cannam@99 236 * for every output sample. Outputs for which this is false
cannam@99 237 * are unlikely to be very useful in a general-purpose host.
cannam@99 238 */
cannam@99 239 bool hasFixedBinCount;
cannam@99 240
cannam@99 241 /**
cannam@99 242 * The number of values per result of the output. Undefined
cannam@99 243 * if hasFixedBinCount is false. If this is zero, the output
cannam@99 244 * is point data (i.e. only the time of each output is of
cannam@99 245 * interest, the value list will be empty).
cannam@99 246 */
cannam@99 247 size_t binCount;
cannam@99 248
cannam@99 249 /**
cannam@99 250 * The (human-readable) names of each of the bins, if
cannam@99 251 * appropriate. This is always optional.
cannam@99 252 */
cannam@99 253 std::vector<std::string> binNames;
cannam@99 254
cannam@99 255 /**
cannam@99 256 * True if the results in each output bin fall within a fixed
cannam@99 257 * numeric range (minimum and maximum values). Undefined if
cannam@99 258 * binCount is zero.
cannam@99 259 */
cannam@99 260 bool hasKnownExtents;
cannam@99 261
cannam@99 262 /**
cannam@99 263 * Minimum value of the results in the output. Undefined if
cannam@99 264 * hasKnownExtents is false or binCount is zero.
cannam@99 265 */
cannam@99 266 float minValue;
cannam@99 267
cannam@99 268 /**
cannam@99 269 * Maximum value of the results in the output. Undefined if
cannam@99 270 * hasKnownExtents is false or binCount is zero.
cannam@99 271 */
cannam@99 272 float maxValue;
cannam@99 273
cannam@99 274 /**
cannam@99 275 * True if the output values are quantized to a particular
cannam@99 276 * resolution. Undefined if binCount is zero.
cannam@99 277 */
cannam@99 278 bool isQuantized;
cannam@99 279
cannam@99 280 /**
cannam@99 281 * Quantization resolution of the output values (e.g. 1.0 if
cannam@99 282 * they are all integers). Undefined if isQuantized is false
cannam@99 283 * or binCount is zero.
cannam@99 284 */
cannam@99 285 float quantizeStep;
cannam@99 286
cannam@99 287 enum SampleType {
cannam@99 288
cannam@99 289 /// Results from each process() align with that call's block start
cannam@99 290 OneSamplePerStep,
cannam@99 291
cannam@99 292 /// Results are evenly spaced in time (sampleRate specified below)
cannam@99 293 FixedSampleRate,
cannam@99 294
cannam@99 295 /// Results are unevenly spaced and have individual timestamps
cannam@99 296 VariableSampleRate
cannam@99 297 };
cannam@99 298
cannam@99 299 /**
cannam@99 300 * Positioning in time of the output results.
cannam@99 301 */
cannam@99 302 SampleType sampleType;
cannam@99 303
cannam@99 304 /**
cannam@99 305 * Sample rate of the output results, as samples per second.
cannam@99 306 * Undefined if sampleType is OneSamplePerStep.
cannam@99 307 *
cannam@99 308 * If sampleType is VariableSampleRate and this value is
cannam@99 309 * non-zero, then it may be used to calculate a resolution for
cannam@99 310 * the output (i.e. the "duration" of each sample, in time,
cannam@99 311 * will be 1/sampleRate seconds). It's recommended to set
cannam@99 312 * this to zero if that behaviour is not desired.
cannam@99 313 */
cannam@99 314 float sampleRate;
cannam@99 315
cannam@99 316 /**
cannam@99 317 * True if the returned results for this output are known to
cannam@99 318 * have a duration field.
cannam@99 319 */
cannam@99 320 bool hasDuration;
cannam@99 321
cannam@99 322 OutputDescriptor() : // defaults for mandatory non-class-type members
cannam@99 323 hasFixedBinCount(false), hasKnownExtents(false), isQuantized(false),
cannam@99 324 sampleType(OneSamplePerStep), hasDuration(false) { }
cannam@99 325 };
cannam@99 326
cannam@99 327 typedef std::vector<OutputDescriptor> OutputList;
cannam@99 328
cannam@99 329 /**
cannam@99 330 * Get the outputs of this plugin. An output's index in this list
cannam@99 331 * is used as its numeric index when looking it up in the
cannam@99 332 * FeatureSet returned from the process() call.
cannam@99 333 */
cannam@99 334 virtual OutputList getOutputDescriptors() const = 0;
cannam@99 335
cannam@99 336 struct Feature
cannam@99 337 {
cannam@99 338 /**
cannam@99 339 * True if an output feature has its own timestamp. This is
cannam@99 340 * mandatory if the output has VariableSampleRate, optional if
cannam@99 341 * the output has FixedSampleRate, and unused if the output
cannam@99 342 * has OneSamplePerStep.
cannam@99 343 */
cannam@99 344 bool hasTimestamp;
cannam@99 345
cannam@99 346 /**
cannam@99 347 * Timestamp of the output feature. This is mandatory if the
cannam@99 348 * output has VariableSampleRate or if the output has
cannam@99 349 * FixedSampleRate and hasTimestamp is true, and unused
cannam@99 350 * otherwise.
cannam@99 351 */
cannam@99 352 RealTime timestamp;
cannam@99 353
cannam@99 354 /**
cannam@99 355 * True if an output feature has a specified duration. This
cannam@99 356 * is optional if the output has VariableSampleRate or
cannam@99 357 * FixedSampleRate, and and unused if the output has
cannam@99 358 * OneSamplePerStep.
cannam@99 359 */
cannam@99 360 bool hasDuration;
cannam@99 361
cannam@99 362 /**
cannam@99 363 * Duration of the output feature. This is mandatory if the
cannam@99 364 * output has VariableSampleRate or FixedSampleRate and
cannam@99 365 * hasDuration is true, and unused otherwise.
cannam@99 366 */
cannam@99 367 RealTime duration;
cannam@99 368
cannam@99 369 /**
cannam@99 370 * Results for a single sample of this feature. If the output
cannam@99 371 * hasFixedBinCount, there must be the same number of values
cannam@99 372 * as the output's binCount count.
cannam@99 373 */
cannam@99 374 std::vector<float> values;
cannam@99 375
cannam@99 376 /**
cannam@99 377 * Label for the sample of this feature.
cannam@99 378 */
cannam@99 379 std::string label;
cannam@99 380
cannam@99 381 Feature() : // defaults for mandatory non-class-type members
cannam@99 382 hasTimestamp(false), hasDuration(false) { }
cannam@99 383 };
cannam@99 384
cannam@99 385 typedef std::vector<Feature> FeatureList;
cannam@99 386
cannam@99 387 typedef std::map<int, FeatureList> FeatureSet; // key is output no
cannam@99 388
cannam@99 389 /**
cannam@99 390 * Process a single block of input data.
cannam@99 391 *
cannam@99 392 * If the plugin's inputDomain is TimeDomain, inputBuffers will
cannam@99 393 * point to one array of floats per input channel, and each of
cannam@99 394 * these arrays will contain blockSize consecutive audio samples
cannam@99 395 * (the host will zero-pad as necessary). The timestamp in this
cannam@99 396 * case will be the real time in seconds of the start of the
cannam@99 397 * supplied block of samples.
cannam@99 398 *
cannam@99 399 * If the plugin's inputDomain is FrequencyDomain, inputBuffers
cannam@99 400 * will point to one array of floats per input channel, and each
cannam@99 401 * of these arrays will contain blockSize/2+1 consecutive pairs of
cannam@99 402 * real and imaginary component floats corresponding to bins
cannam@99 403 * 0..(blockSize/2) of the FFT output. That is, bin 0 (the first
cannam@99 404 * pair of floats) contains the DC output, up to bin blockSize/2
cannam@99 405 * which contains the Nyquist-frequency output. There will
cannam@99 406 * therefore be blockSize+2 floats per channel in total. The
cannam@99 407 * timestamp will be the real time in seconds of the centre of the
cannam@99 408 * FFT input window (i.e. the very first block passed to process
cannam@99 409 * might contain the FFT of half a block of zero samples and the
cannam@99 410 * first half-block of the actual data, with a timestamp of zero).
cannam@99 411 *
cannam@99 412 * Return any features that have become available after this
cannam@99 413 * process call. (These do not necessarily have to fall within
cannam@99 414 * the process block, except for OneSamplePerStep outputs.)
cannam@99 415 */
cannam@99 416 virtual FeatureSet process(const float *const *inputBuffers,
cannam@99 417 RealTime timestamp) = 0;
cannam@99 418
cannam@99 419 /**
cannam@99 420 * After all blocks have been processed, calculate and return any
cannam@99 421 * remaining features derived from the complete input.
cannam@99 422 */
cannam@99 423 virtual FeatureSet getRemainingFeatures() = 0;
cannam@99 424
cannam@99 425 /**
cannam@99 426 * Used to distinguish between Vamp::Plugin and other potential
cannam@99 427 * sibling subclasses of PluginBase. Do not reimplement this
cannam@99 428 * function in your subclass.
cannam@99 429 */
cannam@99 430 virtual std::string getType() const { return "Feature Extraction Plugin"; }
cannam@99 431
cannam@99 432 protected:
cannam@99 433 Plugin(float inputSampleRate) :
cannam@99 434 m_inputSampleRate(inputSampleRate) { }
cannam@99 435
cannam@99 436 float m_inputSampleRate;
cannam@99 437 };
cannam@99 438
cannam@99 439 }
cannam@99 440
cannam@99 441 _VAMP_SDK_PLUGSPACE_END(Plugin.h)
cannam@99 442
cannam@99 443 #endif
cannam@99 444
cannam@99 445
cannam@99 446