| Chris@14 | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */ | 
| Chris@14 | 2 | 
| Chris@14 | 3 /* | 
| Chris@14 | 4     Vamp | 
| Chris@14 | 5 | 
| Chris@14 | 6     An API for audio analysis and feature extraction plugins. | 
| Chris@14 | 7 | 
| Chris@14 | 8     Centre for Digital Music, Queen Mary, University of London. | 
| Chris@14 | 9     Copyright 2006-2009 Chris Cannam and QMUL. | 
| Chris@14 | 10 | 
| Chris@14 | 11     Permission is hereby granted, free of charge, to any person | 
| Chris@14 | 12     obtaining a copy of this software and associated documentation | 
| Chris@14 | 13     files (the "Software"), to deal in the Software without | 
| Chris@14 | 14     restriction, including without limitation the rights to use, copy, | 
| Chris@14 | 15     modify, merge, publish, distribute, sublicense, and/or sell copies | 
| Chris@14 | 16     of the Software, and to permit persons to whom the Software is | 
| Chris@14 | 17     furnished to do so, subject to the following conditions: | 
| Chris@14 | 18 | 
| Chris@14 | 19     The above copyright notice and this permission notice shall be | 
| Chris@14 | 20     included in all copies or substantial portions of the Software. | 
| Chris@14 | 21 | 
| Chris@14 | 22     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | 
| Chris@14 | 23     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | 
| Chris@14 | 24     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | 
| Chris@14 | 25     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR | 
| Chris@14 | 26     ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | 
| Chris@14 | 27     CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 
| Chris@14 | 28     WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 
| Chris@14 | 29 | 
| Chris@14 | 30     Except as contained in this notice, the names of the Centre for | 
| Chris@14 | 31     Digital Music; Queen Mary, University of London; and Chris Cannam | 
| Chris@14 | 32     shall not be used in advertising or otherwise to promote the sale, | 
| Chris@14 | 33     use or other dealings in this Software without prior written | 
| Chris@14 | 34     authorization. | 
| Chris@14 | 35 */ | 
| Chris@14 | 36 | 
| Chris@14 | 37 #ifndef _VAMP_PLUGIN_CHANNEL_ADAPTER_H_ | 
| Chris@14 | 38 #define _VAMP_PLUGIN_CHANNEL_ADAPTER_H_ | 
| Chris@14 | 39 | 
| Chris@14 | 40 #include "hostguard.h" | 
| Chris@14 | 41 #include "PluginWrapper.h" | 
| Chris@14 | 42 | 
| Chris@14 | 43 _VAMP_SDK_HOSTSPACE_BEGIN(PluginChannelAdapter.h) | 
| Chris@14 | 44 | 
| Chris@14 | 45 namespace Vamp { | 
| Chris@14 | 46 | 
| Chris@14 | 47 namespace HostExt { | 
| Chris@14 | 48 | 
| Chris@14 | 49 /** | 
| Chris@14 | 50  * \class PluginChannelAdapter PluginChannelAdapter.h <vamp-hostsdk/PluginChannelAdapter.h> | 
| Chris@14 | 51  * | 
| Chris@14 | 52  * PluginChannelAdapter is a Vamp plugin adapter that implements a | 
| Chris@14 | 53  * policy for management of plugins that expect a different number of | 
| Chris@14 | 54  * input channels from the number actually available in the source | 
| Chris@14 | 55  * audio data. | 
| Chris@14 | 56  * | 
| Chris@14 | 57  * A host using PluginChannelAdapter may ignore the getMinChannelCount | 
| Chris@14 | 58  * and getMaxChannelCount reported by the plugin, and still expect the | 
| Chris@14 | 59  * plugin to run. | 
| Chris@14 | 60  * | 
| Chris@14 | 61  * PluginChannelAdapter implements the following policy: | 
| Chris@14 | 62  * | 
| Chris@14 | 63  *  - If the plugin supports the provided number of channels directly, | 
| Chris@14 | 64  *  PluginChannelAdapter will just run the plugin as normal. | 
| Chris@14 | 65  * | 
| Chris@14 | 66  *  - If the plugin only supports exactly one channel but more than | 
| Chris@14 | 67  *  one channel is provided, PluginChannelAdapter will use the mean of | 
| Chris@14 | 68  *  the channels.  This ensures that the resulting values remain | 
| Chris@14 | 69  *  within the same magnitude range as expected for mono data. | 
| Chris@14 | 70  * | 
| Chris@14 | 71  *  - If the plugin requires more than one channel but exactly one is | 
| Chris@14 | 72  *  provided, the provided channel will be duplicated across all the | 
| Chris@14 | 73  *  plugin input channels. | 
| Chris@14 | 74  * | 
| Chris@14 | 75  * If none of the above apply: | 
| Chris@14 | 76  * | 
| Chris@14 | 77  *  - If the plugin requires more channels than are provided, the | 
| Chris@14 | 78  *  minimum acceptable number of channels will be produced by adding | 
| Chris@14 | 79  *  empty (zero valued) channels to those provided. | 
| Chris@14 | 80  * | 
| Chris@14 | 81  *  - If the plugin requires fewer channels than are provided, the | 
| Chris@14 | 82  *  maximum acceptable number of channels will be produced by | 
| Chris@14 | 83  *  discarding the excess channels. | 
| Chris@14 | 84  * | 
| Chris@14 | 85  * Hosts requiring a different channel policy from the above will need | 
| Chris@14 | 86  * to implement it themselves, instead of using PluginChannelAdapter. | 
| Chris@14 | 87  * | 
| Chris@14 | 88  * Note that PluginChannelAdapter does not override the minimum and | 
| Chris@14 | 89  * maximum channel counts returned by the wrapped plugin.  The host | 
| Chris@14 | 90  * will need to be aware that it is using a PluginChannelAdapter, and | 
| Chris@14 | 91  * be prepared to ignore these counts as necessary.  (This contrasts | 
| Chris@14 | 92  * with the approach used in PluginInputDomainAdapter, which aims to | 
| Chris@14 | 93  * make the host completely unaware of which underlying input domain | 
| Chris@14 | 94  * is in fact in use.) | 
| Chris@14 | 95  * | 
| Chris@14 | 96  * (The rationale for this is that a host may wish to use the | 
| Chris@14 | 97  * PluginChannelAdapter but still discriminate in some way on the | 
| Chris@14 | 98  * basis of the number of channels actually supported.  For example, a | 
| Chris@14 | 99  * simple stereo audio host may prefer to reject plugins that require | 
| Chris@14 | 100  * more than two channels on the grounds that doesn't actually | 
| Chris@14 | 101  * understand what they are for, rather than allow the channel adapter | 
| Chris@14 | 102  * to make a potentially meaningless channel conversion for them.) | 
| Chris@14 | 103  * | 
| Chris@14 | 104  * In every respect other than its management of channels, the | 
| Chris@14 | 105  * PluginChannelAdapter behaves identically to the plugin that it | 
| Chris@14 | 106  * wraps.  The wrapped plugin will be deleted when the wrapper is | 
| Chris@14 | 107  * deleted. | 
| Chris@14 | 108  * | 
| Chris@14 | 109  * \note This class was introduced in version 1.1 of the Vamp plugin SDK. | 
| Chris@14 | 110  */ | 
| Chris@14 | 111 | 
| Chris@14 | 112 class PluginChannelAdapter : public PluginWrapper | 
| Chris@14 | 113 { | 
| Chris@14 | 114 public: | 
| Chris@14 | 115     /** | 
| Chris@14 | 116      * Construct a PluginChannelAdapter wrapping the given plugin. | 
| Chris@14 | 117      * The adapter takes ownership of the plugin, which will be | 
| Chris@14 | 118      * deleted when the adapter is deleted. | 
| Chris@14 | 119      */ | 
| Chris@14 | 120     PluginChannelAdapter(Plugin *plugin); | 
| Chris@14 | 121     virtual ~PluginChannelAdapter(); | 
| Chris@14 | 122 | 
| Chris@14 | 123     bool initialise(size_t channels, size_t stepSize, size_t blockSize); | 
| Chris@14 | 124 | 
| Chris@14 | 125     FeatureSet process(const float *const *inputBuffers, RealTime timestamp); | 
| Chris@14 | 126 | 
| Chris@14 | 127     /** | 
| Chris@14 | 128      * Call process(), providing interleaved audio data with the | 
| Chris@14 | 129      * number of channels passed to initialise().  The adapter will | 
| Chris@14 | 130      * de-interleave into temporary buffers as appropriate before | 
| Chris@14 | 131      * calling process(). | 
| Chris@14 | 132      * | 
| Chris@14 | 133      * \note This function was introduced in version 1.4 of the Vamp | 
| Chris@14 | 134      * plugin SDK. | 
| Chris@14 | 135      */ | 
| Chris@14 | 136     FeatureSet processInterleaved(const float *inputBuffer, RealTime timestamp); | 
| Chris@14 | 137 | 
| Chris@14 | 138 protected: | 
| Chris@14 | 139     class Impl; | 
| Chris@14 | 140     Impl *m_impl; | 
| Chris@14 | 141 }; | 
| Chris@14 | 142 | 
| Chris@14 | 143 } | 
| Chris@14 | 144 | 
| Chris@14 | 145 } | 
| Chris@14 | 146 | 
| Chris@14 | 147 _VAMP_SDK_HOSTSPACE_END(PluginChannelAdapter.h) | 
| Chris@14 | 148 | 
| Chris@14 | 149 #endif |