annotate src/vamp-plugin-sdk-2.4/vamp-hostsdk/PluginInputDomainAdapter.h @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents b7bda433d832
children
rev   line source
Chris@12 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@12 2
Chris@12 3 /*
Chris@12 4 Vamp
Chris@12 5
Chris@12 6 An API for audio analysis and feature extraction plugins.
Chris@12 7
Chris@12 8 Centre for Digital Music, Queen Mary, University of London.
Chris@12 9 Copyright 2006-2009 Chris Cannam and QMUL.
Chris@12 10
Chris@12 11 Permission is hereby granted, free of charge, to any person
Chris@12 12 obtaining a copy of this software and associated documentation
Chris@12 13 files (the "Software"), to deal in the Software without
Chris@12 14 restriction, including without limitation the rights to use, copy,
Chris@12 15 modify, merge, publish, distribute, sublicense, and/or sell copies
Chris@12 16 of the Software, and to permit persons to whom the Software is
Chris@12 17 furnished to do so, subject to the following conditions:
Chris@12 18
Chris@12 19 The above copyright notice and this permission notice shall be
Chris@12 20 included in all copies or substantial portions of the Software.
Chris@12 21
Chris@12 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@12 23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@12 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@12 25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
Chris@12 26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@12 27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@12 28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@12 29
Chris@12 30 Except as contained in this notice, the names of the Centre for
Chris@12 31 Digital Music; Queen Mary, University of London; and Chris Cannam
Chris@12 32 shall not be used in advertising or otherwise to promote the sale,
Chris@12 33 use or other dealings in this Software without prior written
Chris@12 34 authorization.
Chris@12 35 */
Chris@12 36
Chris@12 37 #ifndef _VAMP_PLUGIN_INPUT_DOMAIN_ADAPTER_H_
Chris@12 38 #define _VAMP_PLUGIN_INPUT_DOMAIN_ADAPTER_H_
Chris@12 39
Chris@12 40 #include "hostguard.h"
Chris@12 41 #include "PluginWrapper.h"
Chris@12 42
Chris@12 43 _VAMP_SDK_HOSTSPACE_BEGIN(PluginInputDomainAdapter.h)
Chris@12 44
Chris@12 45 namespace Vamp {
Chris@12 46
Chris@12 47 namespace HostExt {
Chris@12 48
Chris@12 49 /**
Chris@12 50 * \class PluginInputDomainAdapter PluginInputDomainAdapter.h <vamp-hostsdk/PluginInputDomainAdapter.h>
Chris@12 51 *
Chris@12 52 * PluginInputDomainAdapter is a Vamp plugin adapter that converts
Chris@12 53 * time-domain input into frequency-domain input for plugins that need
Chris@12 54 * it. This permits a host to use time- and frequency-domain plugins
Chris@12 55 * interchangeably without needing to handle the conversion itself.
Chris@12 56 *
Chris@12 57 * This adapter uses a basic windowed FFT (using Hann window by
Chris@12 58 * default) that supports power-of-two block sizes only. If a
Chris@12 59 * frequency domain plugin requests a non-power-of-two blocksize, the
Chris@12 60 * adapter will adjust it to a nearby power of two instead. Thus,
Chris@12 61 * getPreferredBlockSize() will always return a power of two if the
Chris@12 62 * wrapped plugin is a frequency domain one. If the plugin doesn't
Chris@12 63 * accept the adjusted power of two block size, initialise() will
Chris@12 64 * fail.
Chris@12 65 *
Chris@12 66 * The adapter provides no way for the host to discover whether the
Chris@12 67 * underlying plugin is actually a time or frequency domain plugin
Chris@12 68 * (except that if the preferred block size is not a power of two, it
Chris@12 69 * must be a time domain plugin).
Chris@12 70 *
Chris@12 71 * The FFT implementation is simple and self-contained, but unlikely
Chris@12 72 * to be the fastest available: a host can usually do better if it
Chris@12 73 * cares enough.
Chris@12 74 *
Chris@12 75 * The window shape for the FFT frame can be set using setWindowType
Chris@12 76 * and the current shape retrieved using getWindowType. (This was
Chris@12 77 * added in v2.3 of the SDK.)
Chris@12 78 *
Chris@12 79 * In every respect other than its input domain handling, the
Chris@12 80 * PluginInputDomainAdapter behaves identically to the plugin that it
Chris@12 81 * wraps. The wrapped plugin will be deleted when the wrapper is
Chris@12 82 * deleted.
Chris@12 83 *
Chris@12 84 * \note This class was introduced in version 1.1 of the Vamp plugin SDK.
Chris@12 85 */
Chris@12 86
Chris@12 87 class PluginInputDomainAdapter : public PluginWrapper
Chris@12 88 {
Chris@12 89 public:
Chris@12 90 /**
Chris@12 91 * Construct a PluginInputDomainAdapter wrapping the given plugin.
Chris@12 92 * The adapter takes ownership of the plugin, which will be
Chris@12 93 * deleted when the adapter is deleted.
Chris@12 94 */
Chris@12 95 PluginInputDomainAdapter(Plugin *plugin);
Chris@12 96 virtual ~PluginInputDomainAdapter();
Chris@12 97
Chris@12 98 bool initialise(size_t channels, size_t stepSize, size_t blockSize);
Chris@12 99 void reset();
Chris@12 100
Chris@12 101 InputDomain getInputDomain() const;
Chris@12 102
Chris@12 103 size_t getPreferredStepSize() const;
Chris@12 104 size_t getPreferredBlockSize() const;
Chris@12 105
Chris@12 106 FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
Chris@12 107
Chris@12 108 /**
Chris@12 109 * ProcessTimestampMethod determines how the
Chris@12 110 * PluginInputDomainAdapter handles timestamps for the data passed
Chris@12 111 * to the process() function of the plugin it wraps, in the case
Chris@12 112 * where the plugin is expecting frequency-domain data.
Chris@12 113 *
Chris@12 114 * The Vamp specification requires that the timestamp passed to
Chris@12 115 * the plugin for frequency-domain input should be that of the
Chris@12 116 * centre of the processing block, rather than the start as is the
Chris@12 117 * case for time-domain input.
Chris@12 118 *
Chris@12 119 * Since PluginInputDomainAdapter aims to be transparent in use,
Chris@12 120 * it needs to handle this timestamp adjustment itself. However,
Chris@12 121 * some control is available over the method used for adjustment,
Chris@12 122 * by means of the ProcessTimestampMethod setting.
Chris@12 123 *
Chris@12 124 * If ProcessTimestampMethod is set to ShiftTimestamp (the
Chris@12 125 * default), then the data passed to the wrapped plugin will be
Chris@12 126 * calculated from the same input data block as passed to the
Chris@12 127 * wrapper, but the timestamp passed to the plugin will be
Chris@12 128 * advanced by half of the window size.
Chris@12 129 *
Chris@12 130 * If ProcessTimestampMethod is set to ShiftData, then the
Chris@12 131 * timestamp passed to the wrapped plugin will be the same as that
Chris@12 132 * passed to the process call of the wrapper, but the data block
Chris@12 133 * used to calculate the input will be shifted back (earlier) by
Chris@12 134 * half of the window size, with half a block of zero padding at
Chris@12 135 * the start of the first process call. This has the advantage of
Chris@12 136 * preserving the first half block of audio without any
Chris@12 137 * deterioration from window shaping.
Chris@12 138 *
Chris@12 139 * If ProcessTimestampMethod is set to NoShift, then no adjustment
Chris@12 140 * will be made and the timestamps will be incorrect.
Chris@12 141 */
Chris@12 142 enum ProcessTimestampMethod {
Chris@12 143 ShiftTimestamp,
Chris@12 144 ShiftData,
Chris@12 145 NoShift
Chris@12 146 };
Chris@12 147
Chris@12 148 /**
Chris@12 149 * Set the method used for timestamp adjustment in plugins taking
Chris@12 150 * frequency-domain input. See the ProcessTimestampMethod
Chris@12 151 * documentation for details.
Chris@12 152 *
Chris@12 153 * This function must be called before the first call to
Chris@12 154 * process().
Chris@12 155 */
Chris@12 156 void setProcessTimestampMethod(ProcessTimestampMethod);
Chris@12 157
Chris@12 158 /**
Chris@12 159 * Retrieve the method used for timestamp adjustment in plugins
Chris@12 160 * taking frequency-domain input. See the ProcessTimestampMethod
Chris@12 161 * documentation for details.
Chris@12 162 */
Chris@12 163 ProcessTimestampMethod getProcessTimestampMethod() const;
Chris@12 164
Chris@12 165 /**
Chris@12 166 * Return the amount by which the timestamps supplied to process()
Chris@12 167 * are being incremented when they are passed to the plugin's own
Chris@12 168 * process() implementation.
Chris@12 169 *
Chris@12 170 * The Vamp API mandates that the timestamp passed to the plugin
Chris@12 171 * for time-domain input should be the time of the first sample in
Chris@12 172 * the block, but the timestamp passed for frequency-domain input
Chris@12 173 * should be the timestamp of the centre of the block.
Chris@12 174 *
Chris@12 175 * The PluginInputDomainAdapter adjusts its timestamps properly so
Chris@12 176 * that the plugin receives correct times, but in some
Chris@12 177 * circumstances (such as for establishing the correct timing of
Chris@12 178 * implicitly-timed features, i.e. features without their own
Chris@12 179 * timestamps) the host may need to be aware that this adjustment
Chris@12 180 * is taking place.
Chris@12 181 *
Chris@12 182 * If the plugin requires time-domain input or the
Chris@12 183 * PluginInputDomainAdapter is configured with its
Chris@12 184 * ProcessTimestampMethod set to ShiftData instead of
Chris@12 185 * ShiftTimestamp, then this function will return zero.
Chris@12 186 *
Chris@12 187 * The result of calling this function before initialise() has
Chris@12 188 * been called is undefined.
Chris@12 189 */
Chris@12 190 RealTime getTimestampAdjustment() const;
Chris@12 191
Chris@12 192 /**
Chris@12 193 * The set of supported window shapes.
Chris@12 194 */
Chris@12 195 enum WindowType {
Chris@12 196
Chris@12 197 RectangularWindow = 0,
Chris@12 198
Chris@12 199 BartlettWindow = 1, /// synonym for RectangularWindow
Chris@12 200 TriangularWindow = 1, /// synonym for BartlettWindow
Chris@12 201
Chris@12 202 HammingWindow = 2,
Chris@12 203
Chris@12 204 HanningWindow = 3, /// synonym for HannWindow
Chris@12 205 HannWindow = 3, /// synonym for HanningWindow
Chris@12 206
Chris@12 207 BlackmanWindow = 4,
Chris@12 208
Chris@12 209 NuttallWindow = 7,
Chris@12 210
Chris@12 211 BlackmanHarrisWindow = 8
Chris@12 212 };
Chris@12 213
Chris@12 214 /**
Chris@12 215 * Return the current window shape. The default is HanningWindow.
Chris@12 216 */
Chris@12 217 WindowType getWindowType() const;
Chris@12 218
Chris@12 219 /**
Chris@12 220 * Set the current window shape.
Chris@12 221 */
Chris@12 222 void setWindowType(WindowType type);
Chris@12 223
Chris@12 224
Chris@12 225 protected:
Chris@12 226 class Impl;
Chris@12 227 Impl *m_impl;
Chris@12 228 };
Chris@12 229
Chris@12 230 }
Chris@12 231
Chris@12 232 }
Chris@12 233
Chris@12 234 _VAMP_SDK_HOSTSPACE_END(PluginInputDomainAdapter.h)
Chris@12 235
Chris@12 236 #endif