comparison win32-mingw/include/vamp-hostsdk/PluginInputDomainAdapter.h @ 99:c6e1ae789cfb

Add Vamp builds
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 20 Mar 2013 16:05:58 +0000
parents
children
comparison
equal deleted inserted replaced
98:4188fd8db918 99:c6e1ae789cfb
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.
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.
94 */
95 PluginInputDomainAdapter(Plugin *plugin);
96 virtual ~PluginInputDomainAdapter();
97
98 bool initialise(size_t channels, size_t stepSize, size_t blockSize);
99 void reset();
100
101 InputDomain getInputDomain() const;
102
103 size_t getPreferredStepSize() const;
104 size_t getPreferredBlockSize() const;
105
106 FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
107
108 /**
109 * ProcessTimestampMethod determines how the
110 * PluginInputDomainAdapter handles timestamps for the data passed
111 * to the process() function of the plugin it wraps, in the case
112 * where the plugin is expecting frequency-domain data.
113 *
114 * The Vamp specification requires that the timestamp passed to
115 * the plugin for frequency-domain input should be that of the
116 * centre of the processing block, rather than the start as is the
117 * case for time-domain input.
118 *
119 * Since PluginInputDomainAdapter aims to be transparent in use,
120 * it needs to handle this timestamp adjustment itself. However,
121 * some control is available over the method used for adjustment,
122 * by means of the ProcessTimestampMethod setting.
123 *
124 * If ProcessTimestampMethod is set to ShiftTimestamp (the
125 * default), then the data passed to the wrapped plugin will be
126 * calculated from the same input data block as passed to the
127 * wrapper, but the timestamp passed to the plugin will be
128 * advanced by half of the window size.
129 *
130 * If ProcessTimestampMethod is set to ShiftData, then the
131 * timestamp passed to the wrapped plugin will be the same as that
132 * passed to the process call of the wrapper, but the data block
133 * used to calculate the input will be shifted back (earlier) by
134 * half of the window size, with half a block of zero padding at
135 * the start of the first process call. This has the advantage of
136 * preserving the first half block of audio without any
137 * deterioration from window shaping.
138 *
139 * If ProcessTimestampMethod is set to NoShift, then no adjustment
140 * will be made and the timestamps will be incorrect.
141 */
142 enum ProcessTimestampMethod {
143 ShiftTimestamp,
144 ShiftData,
145 NoShift
146 };
147
148 /**
149 * Set the method used for timestamp adjustment in plugins taking
150 * frequency-domain input. See the ProcessTimestampMethod
151 * documentation for details.
152 *
153 * This function must be called before the first call to
154 * process().
155 */
156 void setProcessTimestampMethod(ProcessTimestampMethod);
157
158 /**
159 * Retrieve the method used for timestamp adjustment in plugins
160 * taking frequency-domain input. See the ProcessTimestampMethod
161 * documentation for details.
162 */
163 ProcessTimestampMethod getProcessTimestampMethod() const;
164
165 /**
166 * Return the amount by which the timestamps supplied to process()
167 * are being incremented when they are passed to the plugin's own
168 * process() implementation.
169 *
170 * The Vamp API mandates that the timestamp passed to the plugin
171 * for time-domain input should be the time of the first sample in
172 * the block, but the timestamp passed for frequency-domain input
173 * should be the timestamp of the centre of the block.
174 *
175 * The PluginInputDomainAdapter adjusts its timestamps properly so
176 * that the plugin receives correct times, but in some
177 * circumstances (such as for establishing the correct timing of
178 * implicitly-timed features, i.e. features without their own
179 * timestamps) the host may need to be aware that this adjustment
180 * is taking place.
181 *
182 * If the plugin requires time-domain input or the
183 * PluginInputDomainAdapter is configured with its
184 * ProcessTimestampMethod set to ShiftData instead of
185 * ShiftTimestamp, then this function will return zero.
186 *
187 * The result of calling this function before initialise() has
188 * been called is undefined.
189 */
190 RealTime getTimestampAdjustment() const;
191
192 /**
193 * The set of supported window shapes.
194 */
195 enum WindowType {
196
197 RectangularWindow = 0,
198
199 BartlettWindow = 1, /// synonym for RectangularWindow
200 TriangularWindow = 1, /// synonym for BartlettWindow
201
202 HammingWindow = 2,
203
204 HanningWindow = 3, /// synonym for HannWindow
205 HannWindow = 3, /// synonym for HanningWindow
206
207 BlackmanWindow = 4,
208
209 NuttallWindow = 7,
210
211 BlackmanHarrisWindow = 8
212 };
213
214 /**
215 * Return the current window shape. The default is HanningWindow.
216 */
217 WindowType getWindowType() const;
218
219 /**
220 * Set the current window shape.
221 */
222 void setWindowType(WindowType type);
223
224
225 protected:
226 class Impl;
227 Impl *m_impl;
228 };
229
230 }
231
232 }
233
234 _VAMP_SDK_HOSTSPACE_END(PluginInputDomainAdapter.h)
235
236 #endif