annotate src/vamp-plugin-sdk-2.5/vamp-sdk/Plugin.h @ 169:223a55898ab9 tip default

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