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