Chris@23: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@23: Chris@23: /* Chris@23: Vamp Chris@23: Chris@23: An API for audio analysis and feature extraction plugins. Chris@23: Chris@23: Centre for Digital Music, Queen Mary, University of London. Chris@23: Copyright 2006-2009 Chris Cannam and QMUL. Chris@23: Chris@23: Permission is hereby granted, free of charge, to any person Chris@23: obtaining a copy of this software and associated documentation Chris@23: files (the "Software"), to deal in the Software without Chris@23: restriction, including without limitation the rights to use, copy, Chris@23: modify, merge, publish, distribute, sublicense, and/or sell copies Chris@23: of the Software, and to permit persons to whom the Software is Chris@23: furnished to do so, subject to the following conditions: Chris@23: Chris@23: The above copyright notice and this permission notice shall be Chris@23: included in all copies or substantial portions of the Software. Chris@23: Chris@23: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Chris@23: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF Chris@23: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND Chris@23: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR Chris@23: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF Chris@23: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION Chris@23: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Chris@23: Chris@23: Except as contained in this notice, the names of the Centre for Chris@23: Digital Music; Queen Mary, University of London; and Chris Cannam Chris@23: shall not be used in advertising or otherwise to promote the sale, Chris@23: use or other dealings in this Software without prior written Chris@23: authorization. Chris@23: */ Chris@23: Chris@23: #ifndef _VAMP_PLUGIN_CHANNEL_ADAPTER_H_ Chris@23: #define _VAMP_PLUGIN_CHANNEL_ADAPTER_H_ Chris@23: Chris@23: #include "hostguard.h" Chris@23: #include "PluginWrapper.h" Chris@23: Chris@23: _VAMP_SDK_HOSTSPACE_BEGIN(PluginChannelAdapter.h) Chris@23: Chris@23: namespace Vamp { Chris@23: Chris@23: namespace HostExt { Chris@23: Chris@23: /** Chris@23: * \class PluginChannelAdapter PluginChannelAdapter.h Chris@23: * Chris@23: * PluginChannelAdapter is a Vamp plugin adapter that implements a Chris@23: * policy for management of plugins that expect a different number of Chris@23: * input channels from the number actually available in the source Chris@23: * audio data. Chris@23: * Chris@23: * A host using PluginChannelAdapter may ignore the getMinChannelCount Chris@23: * and getMaxChannelCount reported by the plugin, and still expect the Chris@23: * plugin to run. Chris@23: * Chris@23: * PluginChannelAdapter implements the following policy: Chris@23: * Chris@23: * - If the plugin supports the provided number of channels directly, Chris@23: * PluginChannelAdapter will just run the plugin as normal. Chris@23: * Chris@23: * - If the plugin only supports exactly one channel but more than Chris@23: * one channel is provided, PluginChannelAdapter will use the mean of Chris@23: * the channels. This ensures that the resulting values remain Chris@23: * within the same magnitude range as expected for mono data. Chris@23: * Chris@23: * - If the plugin requires more than one channel but exactly one is Chris@23: * provided, the provided channel will be duplicated across all the Chris@23: * plugin input channels. Chris@23: * Chris@23: * If none of the above apply: Chris@23: * Chris@23: * - If the plugin requires more channels than are provided, the Chris@23: * minimum acceptable number of channels will be produced by adding Chris@23: * empty (zero valued) channels to those provided. Chris@23: * Chris@23: * - If the plugin requires fewer channels than are provided, the Chris@23: * maximum acceptable number of channels will be produced by Chris@23: * discarding the excess channels. Chris@23: * Chris@23: * Hosts requiring a different channel policy from the above will need Chris@23: * to implement it themselves, instead of using PluginChannelAdapter. Chris@23: * Chris@23: * Note that PluginChannelAdapter does not override the minimum and Chris@23: * maximum channel counts returned by the wrapped plugin. The host Chris@23: * will need to be aware that it is using a PluginChannelAdapter, and Chris@23: * be prepared to ignore these counts as necessary. (This contrasts Chris@23: * with the approach used in PluginInputDomainAdapter, which aims to Chris@23: * make the host completely unaware of which underlying input domain Chris@23: * is in fact in use.) Chris@23: * Chris@23: * (The rationale for this is that a host may wish to use the Chris@23: * PluginChannelAdapter but still discriminate in some way on the Chris@23: * basis of the number of channels actually supported. For example, a Chris@23: * simple stereo audio host may prefer to reject plugins that require Chris@23: * more than two channels on the grounds that doesn't actually Chris@23: * understand what they are for, rather than allow the channel adapter Chris@23: * to make a potentially meaningless channel conversion for them.) Chris@23: * Chris@23: * In every respect other than its management of channels, the Chris@23: * PluginChannelAdapter behaves identically to the plugin that it Chris@23: * wraps. The wrapped plugin will be deleted when the wrapper is Chris@23: * deleted. Chris@23: * Chris@23: * \note This class was introduced in version 1.1 of the Vamp plugin SDK. Chris@23: */ Chris@23: Chris@23: class PluginChannelAdapter : public PluginWrapper Chris@23: { Chris@23: public: Chris@23: /** Chris@23: * Construct a PluginChannelAdapter wrapping the given plugin. Chris@23: * The adapter takes ownership of the plugin, which will be Chris@23: * deleted when the adapter is deleted. Chris@23: */ Chris@23: PluginChannelAdapter(Plugin *plugin); Chris@23: virtual ~PluginChannelAdapter(); Chris@23: Chris@23: bool initialise(size_t channels, size_t stepSize, size_t blockSize); Chris@23: Chris@23: FeatureSet process(const float *const *inputBuffers, RealTime timestamp); Chris@23: Chris@23: /** Chris@23: * Call process(), providing interleaved audio data with the Chris@23: * number of channels passed to initialise(). The adapter will Chris@23: * de-interleave into temporary buffers as appropriate before Chris@23: * calling process(). Chris@23: * Chris@23: * \note This function was introduced in version 1.4 of the Vamp Chris@23: * plugin SDK. Chris@23: */ Chris@23: FeatureSet processInterleaved(const float *inputBuffer, RealTime timestamp); Chris@23: Chris@23: protected: Chris@23: class Impl; Chris@23: Impl *m_impl; Chris@23: }; Chris@23: Chris@23: } Chris@23: Chris@23: } Chris@23: Chris@23: _VAMP_SDK_HOSTSPACE_END(PluginChannelAdapter.h) Chris@23: Chris@23: #endif