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