comparison vamp-sdk/hostext/PluginInputDomainAdapter.h @ 64:9d3272c7db60

* Merge from host-factory-stuff branch: this adds several helper classes in the hostext directory that should make a host's life much easier. This will become version 1.1 of the SDK, eventually.
author cannam
date Fri, 01 Jun 2007 15:10:17 +0000
parents
children fd58037b4a7b
comparison
equal deleted inserted replaced
54:933fee59d33a 64:9d3272c7db60
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 Chris Cannam.
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 "PluginWrapper.h"
41
42 namespace Vamp {
43
44 namespace HostExt {
45
46 /**
47 * PluginInputDomainAdapter is a Vamp plugin adapter that converts
48 * time-domain input into frequency-domain input for plugins that need
49 * it. This permits a host to use time- and frequency-domain plugins
50 * interchangeably without needing to handle the conversion itself.
51 *
52 * This adapter uses a basic Hanning windowed FFT that supports
53 * power-of-two block sizes only. If a frequency domain plugin
54 * requests a non-power-of-two blocksize, the adapter will adjust it
55 * to a nearby power of two instead. Thus, getPreferredBlockSize()
56 * will always return a power of two if the wrapped plugin is a
57 * frequency domain one. If the plugin doesn't accept the adjusted
58 * power of two block size, initialise() will fail.
59 *
60 * The adapter provides no way for the host to discover whether the
61 * underlying plugin is actually a time or frequency domain plugin
62 * (except that if the preferred block size is not a power of two, it
63 * must be a time domain plugin).
64 *
65 * The FFT implementation is simple and self-contained, but unlikely
66 * to be the fastest available: a host can usually do better if it
67 * cares enough.
68 *
69 * In every respect other than its input domain handling, the
70 * PluginInputDomainAdapter behaves identically to the plugin that it
71 * wraps. The wrapped plugin will be deleted when the wrapper is
72 * deleted.
73 */
74
75 class PluginInputDomainAdapter : public PluginWrapper
76 {
77 public:
78 PluginInputDomainAdapter(Plugin *plugin); // I take ownership of plugin
79 virtual ~PluginInputDomainAdapter();
80
81 bool initialise(size_t channels, size_t stepSize, size_t blockSize);
82
83 InputDomain getInputDomain() const;
84
85 size_t getPreferredStepSize() const;
86 size_t getPreferredBlockSize() const;
87
88 FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
89
90 protected:
91 size_t m_channels;
92 size_t m_blockSize;
93 float **m_freqbuf;
94 double *m_ri;
95 double *m_ro;
96 double *m_io;
97
98 void fft(unsigned int n, bool inverse,
99 double *ri, double *ii, double *ro, double *io);
100
101 size_t makeBlockSizeAcceptable(size_t) const;
102 };
103
104 }
105
106 }
107
108 #endif