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: This file by Mark Levy and Chris Cannam, Copyright 2007-2008 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_BUFFERING_ADAPTER_H_ Chris@23: #define _VAMP_PLUGIN_BUFFERING_ADAPTER_H_ Chris@23: Chris@23: #include "hostguard.h" Chris@23: #include "PluginWrapper.h" Chris@23: Chris@23: _VAMP_SDK_HOSTSPACE_BEGIN(PluginBufferingAdapter.h) Chris@23: Chris@23: namespace Vamp { Chris@23: Chris@23: namespace HostExt { Chris@23: Chris@23: /** Chris@23: * \class PluginBufferingAdapter PluginBufferingAdapter.h Chris@23: * Chris@23: * PluginBufferingAdapter is a Vamp plugin adapter that allows plugins Chris@23: * to be used by a host supplying an audio stream in non-overlapping Chris@23: * buffers of arbitrary size. Chris@23: * Chris@23: * A host using PluginBufferingAdapter may ignore the preferred step Chris@23: * and block size reported by the plugin, and still expect the plugin Chris@23: * to run. The value of blockSize and stepSize passed to initialise Chris@23: * should be the size of the buffer which the host will supply; the Chris@23: * stepSize should be equal to the blockSize. Chris@23: * Chris@23: * If the internal step size used for the plugin differs from that Chris@23: * supplied by the host, the adapter will modify the sample type and Chris@23: * rate specifications for the plugin outputs appropriately, and set Chris@23: * timestamps on the output features for outputs that formerly used a Chris@23: * different sample rate specification. This is necessary in order to Chris@23: * obtain correct time stamping. Chris@23: * Chris@23: * In other respects, the PluginBufferingAdapter behaves identically Chris@23: * to the plugin that it wraps. The wrapped plugin will be deleted Chris@23: * when the wrapper is deleted. Chris@23: */ Chris@23: Chris@23: class PluginBufferingAdapter : public PluginWrapper Chris@23: { Chris@23: public: Chris@23: /** Chris@23: * Construct a PluginBufferingAdapter 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: PluginBufferingAdapter(Plugin *plugin); Chris@23: virtual ~PluginBufferingAdapter(); Chris@23: Chris@23: /** Chris@23: * Return the preferred step size for this adapter. Chris@23: * Chris@23: * Because of the way this adapter works, its preferred step size Chris@23: * will always be the same as its preferred block size. This may Chris@23: * or may not be the same as the preferred step size of the Chris@23: * underlying plugin, which may be obtained by calling Chris@23: * getPluginPreferredStepSize(). Chris@23: */ Chris@23: size_t getPreferredStepSize() const; Chris@23: Chris@23: /** Chris@23: * Return the preferred block size for this adapter. Chris@23: * Chris@23: * This may or may not be the same as the preferred block size of Chris@23: * the underlying plugin, which may be obtained by calling Chris@23: * getPluginPreferredBlockSize(). Chris@23: * Chris@23: * Note that this adapter may be initialised with any block size, Chris@23: * not just its supposedly preferred one. Chris@23: */ Chris@23: size_t getPreferredBlockSize() const; Chris@23: Chris@23: /** Chris@23: * Initialise the adapter (and therefore the plugin) for the given Chris@23: * number of channels. Initialise the adapter for the given step Chris@23: * and block size, which must be equal. Chris@23: * Chris@23: * The step and block size used for the underlying plugin will Chris@23: * depend on its preferences, or any values previously passed to Chris@23: * setPluginStepSize and setPluginBlockSize. Chris@23: */ Chris@23: bool initialise(size_t channels, size_t stepSize, size_t blockSize); Chris@23: Chris@23: /** Chris@23: * Return the preferred step size of the plugin wrapped by this Chris@23: * adapter. Chris@23: * Chris@23: * This is included mainly for informational purposes. This value Chris@23: * is not likely to be a valid step size for the adapter itself, Chris@23: * and it is not usually of any use in interpreting the results Chris@23: * (because the adapter re-writes OneSamplePerStep outputs to Chris@23: * FixedSampleRate so that the hop size no longer needs to be Chris@23: * known beforehand in order to interpret them). Chris@23: */ Chris@23: size_t getPluginPreferredStepSize() const; Chris@23: Chris@23: /** Chris@23: * Return the preferred block size of the plugin wrapped by this Chris@23: * adapter. Chris@23: * Chris@23: * This is included mainly for informational purposes. Chris@23: */ Chris@23: size_t getPluginPreferredBlockSize() const; Chris@23: Chris@23: /** Chris@23: * Set the step size that will be used for the underlying plugin Chris@23: * when initialise() is called. If this is not set, the plugin's Chris@23: * own preferred step size will be used. You will not usually Chris@23: * need to call this function. If you do call it, it must be Chris@23: * before the first call to initialise(). Chris@23: */ Chris@23: void setPluginStepSize(size_t stepSize); Chris@23: Chris@23: /** Chris@23: * Set the block size that will be used for the underlying plugin Chris@23: * when initialise() is called. If this is not set, the plugin's Chris@23: * own preferred block size will be used. You will not usually Chris@23: * need to call this function. If you do call it, it must be Chris@23: * before the first call to initialise(). Chris@23: */ Chris@23: void setPluginBlockSize(size_t blockSize); Chris@23: Chris@23: /** Chris@23: * Return the step and block sizes that were actually used when Chris@23: * initialising the underlying plugin. Chris@23: * Chris@23: * This is included mainly for informational purposes. You will Chris@23: * not usually need to call this function. If this is called Chris@23: * before initialise(), it will return 0 for both values. If it Chris@23: * is called after a failed call to initialise(), it will return Chris@23: * the values that were used in the failed call to the plugin's Chris@23: * initialise() function. Chris@23: */ Chris@23: void getActualStepAndBlockSizes(size_t &stepSize, size_t &blockSize); Chris@23: Chris@23: void setParameter(std::string, float); Chris@23: void selectProgram(std::string); Chris@23: Chris@23: OutputList getOutputDescriptors() const; Chris@23: Chris@23: void reset(); Chris@23: Chris@23: FeatureSet process(const float *const *inputBuffers, RealTime timestamp); Chris@23: Chris@23: FeatureSet getRemainingFeatures(); 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(PluginBufferingAdapter.h) Chris@23: Chris@23: #endif