annotate osx/include/vamp-hostsdk/PluginInputDomainAdapter.h @ 110:4c576e416934

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