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