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