upgrade VAMP SDK to latest (or newer) version
[ardour.git] / libs / vamp-sdk / vamp-hostsdk / PluginInputDomainAdapter.h
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 Hanning windowed FFT that supports
58  * power-of-two block sizes only.  If a frequency domain plugin
59  * requests a non-power-of-two blocksize, the adapter will adjust it
60  * to a nearby power of two instead.  Thus, getPreferredBlockSize()
61  * will always return a power of two if the wrapped plugin is a
62  * frequency domain one.  If the plugin doesn't accept the adjusted
63  * power of two block size, initialise() will fail.
64  *
65  * The adapter provides no way for the host to discover whether the
66  * underlying plugin is actually a time or frequency domain plugin
67  * (except that if the preferred block size is not a power of two, it
68  * must be a time domain plugin).
69  *
70  * The FFT implementation is simple and self-contained, but unlikely
71  * to be the fastest available: a host can usually do better if it
72  * cares enough.
73  *
74  * In every respect other than its input domain handling, the
75  * PluginInputDomainAdapter behaves identically to the plugin that it
76  * wraps.  The wrapped plugin will be deleted when the wrapper is
77  * deleted.
78  *
79  * \note This class was introduced in version 1.1 of the Vamp plugin SDK.
80  */
81
82 class PluginInputDomainAdapter : public PluginWrapper
83 {
84 public:
85     /**
86      * Construct a PluginInputDomainAdapter wrapping the given plugin.
87      * The adapter takes ownership of the plugin, which will be
88      * deleted when the adapter is deleted.
89      */
90     PluginInputDomainAdapter(Plugin *plugin);
91     virtual ~PluginInputDomainAdapter();
92     
93     bool initialise(size_t channels, size_t stepSize, size_t blockSize);
94     void reset();
95
96     InputDomain getInputDomain() const;
97
98     size_t getPreferredStepSize() const;
99     size_t getPreferredBlockSize() const;
100
101     FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
102
103     /**
104      * ProcessTimestampMethod determines how the
105      * PluginInputDomainAdapter handles timestamps for the data passed
106      * to the process() function of the plugin it wraps, in the case
107      * where the plugin is expecting frequency-domain data.
108      *
109      * The Vamp specification requires that the timestamp passed to
110      * the plugin for frequency-domain input should be that of the
111      * centre of the processing block, rather than the start as is the
112      * case for time-domain input.
113      *
114      * Since PluginInputDomainAdapter aims to be transparent in use,
115      * it needs to handle this timestamp adjustment itself.  However,
116      * some control is available over the method used for adjustment,
117      * by means of the ProcessTimestampMethod setting.
118      *
119      * If ProcessTimestampMethod is set to ShiftTimestamp (the
120      * default), then the data passed to the wrapped plugin will be
121      * calculated from the same input data block as passed to the
122      * wrapper, but the timestamp passed to the plugin will be
123      * advanced by half of the window size.
124      * 
125      * If ProcessTimestampMethod is set to ShiftData, then the
126      * timestamp passed to the wrapped plugin will be the same as that
127      * passed to the process call of the wrapper, but the data block
128      * used to calculate the input will be shifted back (earlier) by
129      * half of the window size, with half a block of zero padding at
130      * the start of the first process call.  This has the advantage of
131      * preserving the first half block of audio without any
132      * deterioration from window shaping.
133      * 
134      * If ProcessTimestampMethod is set to NoShift, then no adjustment
135      * will be made and the timestamps will be incorrect.
136      */
137     enum ProcessTimestampMethod {
138         ShiftTimestamp,
139         ShiftData,
140         NoShift
141     };
142
143     /**
144      * Set the method used for timestamp adjustment in plugins taking
145      * frequency-domain input.  See the ProcessTimestampMethod
146      * documentation for details.
147      *
148      * This function must be called before the first call to
149      * process().
150      */
151     void setProcessTimestampMethod(ProcessTimestampMethod);
152
153     /**
154      * Retrieve the method used for timestamp adjustment in plugins
155      * taking frequency-domain input.  See the ProcessTimestampMethod
156      * documentation for details.
157      */
158     ProcessTimestampMethod getProcessTimestampMethod() const;
159
160     /**
161      * Return the amount by which the timestamps supplied to process()
162      * are being incremented when they are passed to the plugin's own
163      * process() implementation.
164      *
165      * The Vamp API mandates that the timestamp passed to the plugin
166      * for time-domain input should be the time of the first sample in
167      * the block, but the timestamp passed for frequency-domain input
168      * should be the timestamp of the centre of the block.
169      *
170      * The PluginInputDomainAdapter adjusts its timestamps properly so
171      * that the plugin receives correct times, but in some
172      * circumstances (such as for establishing the correct timing of
173      * implicitly-timed features, i.e. features without their own
174      * timestamps) the host may need to be aware that this adjustment
175      * is taking place.
176      *
177      * If the plugin requires time-domain input or the
178      * PluginInputDomainAdapter is configured with its
179      * ProcessTimestampMethod set to ShiftData instead of
180      * ShiftTimestamp, then this function will return zero.
181      *
182      * The result of calling this function before initialise() has
183      * been called is undefined.
184      */
185     RealTime getTimestampAdjustment() const;
186
187 protected:
188     class Impl;
189     Impl *m_impl;
190 };
191
192 }
193
194 }
195
196 _VAMP_SDK_HOSTSPACE_END(PluginInputDomainAdapter.h)
197
198 #endif