comparison vamp-sdk/hostext/PluginChannelAdapter.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_CHANNEL_ADAPTER_H_
38 #define _VAMP_PLUGIN_CHANNEL_ADAPTER_H_
39
40 #include "PluginWrapper.h"
41
42 namespace Vamp {
43
44 namespace HostExt {
45
46 /**
47 * PluginChannelAdapter is a Vamp plugin adapter that implements a
48 * policy for management of plugins that expect a different number of
49 * input channels from the number actually available in the source
50 * audio data.
51 *
52 * A host using PluginChannelAdapter may ignore the getMinChannelCount
53 * and getMaxChannelCount reported by the plugin, and still expect the
54 * plugin to run.
55 *
56 * PluginChannelAdapter implements the following policy:
57 *
58 * -- If the plugin supports the provided number of channels directly,
59 * PluginChannelAdapter will just run the plugin as normal.
60 *
61 * -- If the plugin only supports exactly one channel but more than
62 * one channel is provided, PluginChannelAdapter will use the mean of
63 * the channels. This ensures that the resulting values remain within
64 * the same magnitude range as expected for mono data.
65 *
66 * -- If the plugin requires more than one channel but exactly one is
67 * provided, the provided channel will be duplicated across all the
68 * plugin input channels.
69 *
70 * If none of the above apply:
71 *
72 * -- If the plugin requires more channels than are provided, the
73 * minimum acceptable number of channels will be produced by adding
74 * empty (zero valued) channels to those provided.
75 *
76 * -- If the plugin requires fewer channels than are provided, the
77 * maximum acceptable number of channels will be produced by
78 * discarding the excess channels.
79 *
80 * Hosts requiring a different channel policy from the above will need
81 * to implement it themselves, instead of using PluginChannelAdapter.
82 *
83 * Note that PluginChannelAdapter does not override the minimum and
84 * maximum channel counts returned by the wrapped plugin. The host
85 * will need to be aware that it is using a PluginChannelAdapter, and
86 * be prepared to ignore these counts as necessary. (This contrasts
87 * with the approach used in PluginInputDomainAdapter, which aims to
88 * make the host completely unaware of which underlying input domain
89 * is in fact in use.)
90 *
91 * (The rationale for this is that a host may wish to use the
92 * PluginChannelAdapter but still discriminate in some way on the
93 * basis of the number of channels actually supported. For example, a
94 * simple stereo audio host may prefer to reject plugins that require
95 * more than two channels on the grounds that doesn't actually
96 * understand what they are for, rather than allow the channel adapter
97 * to make a potentially meaningless channel conversion for them.)
98 *
99 * In every respect other than its management of channels, the
100 * PluginChannelAdapter behaves identically to the plugin that it
101 * wraps. The wrapped plugin will be deleted when the wrapper is
102 * deleted.
103 */
104
105 class PluginChannelAdapter : public PluginWrapper
106 {
107 public:
108 PluginChannelAdapter(Plugin *plugin); // I take ownership of plugin
109 virtual ~PluginChannelAdapter();
110
111 bool initialise(size_t channels, size_t stepSize, size_t blockSize);
112
113 FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
114
115 protected:
116 size_t m_blockSize;
117 size_t m_inputChannels;
118 size_t m_pluginChannels;
119 float **m_buffer;
120 const float **m_forwardPtrs;
121 };
122
123 }
124
125 }
126
127 #endif