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