Chris@25: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@25: Chris@25: /* Chris@25: Vamp Chris@25: Chris@25: An API for audio analysis and feature extraction plugins. Chris@25: Chris@25: Centre for Digital Music, Queen Mary, University of London. Chris@25: Copyright 2006-2009 Chris Cannam and QMUL. Chris@25: This file by Mark Levy and Chris Cannam, Copyright 2007-2008 QMUL. Chris@25: Chris@25: Permission is hereby granted, free of charge, to any person Chris@25: obtaining a copy of this software and associated documentation Chris@25: files (the "Software"), to deal in the Software without Chris@25: restriction, including without limitation the rights to use, copy, Chris@25: modify, merge, publish, distribute, sublicense, and/or sell copies Chris@25: of the Software, and to permit persons to whom the Software is Chris@25: furnished to do so, subject to the following conditions: Chris@25: Chris@25: The above copyright notice and this permission notice shall be Chris@25: included in all copies or substantial portions of the Software. Chris@25: Chris@25: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Chris@25: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF Chris@25: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND Chris@25: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR Chris@25: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF Chris@25: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION Chris@25: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Chris@25: Chris@25: Except as contained in this notice, the names of the Centre for Chris@25: Digital Music; Queen Mary, University of London; and Chris Cannam Chris@25: shall not be used in advertising or otherwise to promote the sale, Chris@25: use or other dealings in this Software without prior written Chris@25: authorization. Chris@25: */ Chris@25: Chris@25: #ifndef _VAMP_PLUGIN_BUFFERING_ADAPTER_H_ Chris@25: #define _VAMP_PLUGIN_BUFFERING_ADAPTER_H_ Chris@25: Chris@25: #include "hostguard.h" Chris@25: #include "PluginWrapper.h" Chris@25: Chris@25: _VAMP_SDK_HOSTSPACE_BEGIN(PluginBufferingAdapter.h) Chris@25: Chris@25: namespace Vamp { Chris@25: Chris@25: namespace HostExt { Chris@25: Chris@25: /** Chris@25: * \class PluginBufferingAdapter PluginBufferingAdapter.h Chris@25: * Chris@25: * PluginBufferingAdapter is a Vamp plugin adapter that allows plugins Chris@25: * to be used by a host supplying an audio stream in non-overlapping Chris@25: * buffers of arbitrary size. Chris@25: * Chris@25: * A host using PluginBufferingAdapter may ignore the preferred step Chris@25: * and block size reported by the plugin, and still expect the plugin Chris@25: * to run. The value of blockSize and stepSize passed to initialise Chris@25: * should be the size of the buffer which the host will supply; the Chris@25: * stepSize should be equal to the blockSize. Chris@25: * Chris@25: * If the internal step size used for the plugin differs from that Chris@25: * supplied by the host, the adapter will modify the sample type and Chris@25: * rate specifications for the plugin outputs appropriately, and set Chris@25: * timestamps on the output features for outputs that formerly used a Chris@25: * different sample rate specification. This is necessary in order to Chris@25: * obtain correct time stamping. Chris@25: * Chris@25: * In other respects, the PluginBufferingAdapter behaves identically Chris@25: * to the plugin that it wraps. The wrapped plugin will be deleted Chris@25: * when the wrapper is deleted. Chris@25: */ Chris@25: Chris@25: class PluginBufferingAdapter : public PluginWrapper Chris@25: { Chris@25: public: Chris@25: /** Chris@25: * Construct a PluginBufferingAdapter wrapping the given plugin. Chris@25: * The adapter takes ownership of the plugin, which will be Chris@25: * deleted when the adapter is deleted. Chris@25: */ Chris@25: PluginBufferingAdapter(Plugin *plugin); Chris@25: virtual ~PluginBufferingAdapter(); Chris@25: Chris@25: /** Chris@25: * Return the preferred step size for this adapter. Chris@25: * Chris@25: * Because of the way this adapter works, its preferred step size Chris@25: * will always be the same as its preferred block size. This may Chris@25: * or may not be the same as the preferred step size of the Chris@25: * underlying plugin, which may be obtained by calling Chris@25: * getPluginPreferredStepSize(). Chris@25: */ Chris@25: size_t getPreferredStepSize() const; Chris@25: Chris@25: /** Chris@25: * Return the preferred block size for this adapter. Chris@25: * Chris@25: * This may or may not be the same as the preferred block size of Chris@25: * the underlying plugin, which may be obtained by calling Chris@25: * getPluginPreferredBlockSize(). Chris@25: * Chris@25: * Note that this adapter may be initialised with any block size, Chris@25: * not just its supposedly preferred one. Chris@25: */ Chris@25: size_t getPreferredBlockSize() const; Chris@25: Chris@25: /** Chris@25: * Initialise the adapter (and therefore the plugin) for the given Chris@25: * number of channels. Initialise the adapter for the given step Chris@25: * and block size, which must be equal. Chris@25: * Chris@25: * The step and block size used for the underlying plugin will Chris@25: * depend on its preferences, or any values previously passed to Chris@25: * setPluginStepSize and setPluginBlockSize. Chris@25: */ Chris@25: bool initialise(size_t channels, size_t stepSize, size_t blockSize); Chris@25: Chris@25: /** Chris@25: * Return the preferred step size of the plugin wrapped by this Chris@25: * adapter. Chris@25: * Chris@25: * This is included mainly for informational purposes. This value Chris@25: * is not likely to be a valid step size for the adapter itself, Chris@25: * and it is not usually of any use in interpreting the results Chris@25: * (because the adapter re-writes OneSamplePerStep outputs to Chris@25: * FixedSampleRate so that the hop size no longer needs to be Chris@25: * known beforehand in order to interpret them). Chris@25: */ Chris@25: size_t getPluginPreferredStepSize() const; Chris@25: Chris@25: /** Chris@25: * Return the preferred block size of the plugin wrapped by this Chris@25: * adapter. Chris@25: * Chris@25: * This is included mainly for informational purposes. Chris@25: */ Chris@25: size_t getPluginPreferredBlockSize() const; Chris@25: Chris@25: /** Chris@25: * Set the step size that will be used for the underlying plugin Chris@25: * when initialise() is called. If this is not set, the plugin's Chris@25: * own preferred step size will be used. You will not usually Chris@25: * need to call this function. If you do call it, it must be Chris@25: * before the first call to initialise(). Chris@25: */ Chris@25: void setPluginStepSize(size_t stepSize); Chris@25: Chris@25: /** Chris@25: * Set the block size that will be used for the underlying plugin Chris@25: * when initialise() is called. If this is not set, the plugin's Chris@25: * own preferred block size will be used. You will not usually Chris@25: * need to call this function. If you do call it, it must be Chris@25: * before the first call to initialise(). Chris@25: */ Chris@25: void setPluginBlockSize(size_t blockSize); Chris@25: Chris@25: /** Chris@25: * Return the step and block sizes that were actually used when Chris@25: * initialising the underlying plugin. Chris@25: * Chris@25: * This is included mainly for informational purposes. You will Chris@25: * not usually need to call this function. If this is called Chris@25: * before initialise(), it will return 0 for both values. If it Chris@25: * is called after a failed call to initialise(), it will return Chris@25: * the values that were used in the failed call to the plugin's Chris@25: * initialise() function. Chris@25: */ Chris@25: void getActualStepAndBlockSizes(size_t &stepSize, size_t &blockSize); Chris@25: Chris@25: void setParameter(std::string, float); Chris@25: void selectProgram(std::string); Chris@25: Chris@25: OutputList getOutputDescriptors() const; Chris@25: Chris@25: void reset(); Chris@25: Chris@25: FeatureSet process(const float *const *inputBuffers, RealTime timestamp); Chris@25: Chris@25: FeatureSet getRemainingFeatures(); Chris@25: Chris@25: protected: Chris@25: class Impl; Chris@25: Impl *m_impl; Chris@25: }; Chris@25: Chris@25: } Chris@25: Chris@25: } Chris@25: Chris@25: _VAMP_SDK_HOSTSPACE_END(PluginBufferingAdapter.h) Chris@25: Chris@25: #endif