# HG changeset patch # User cannam # Date 1216986546 0 # Node ID af8e59f43d1d0ad10a62abd04940b357e4aaae56 # Parent 006a775133b1532b38b55d8e83091c45cec2dff6 * Add capability for setting underlying plugin's step and block sizes to PluginBufferingAdapter diff -r 006a775133b1 -r af8e59f43d1d vamp-sdk/hostext/PluginBufferingAdapter.cpp --- a/vamp-sdk/hostext/PluginBufferingAdapter.cpp Thu Jul 24 16:50:11 2008 +0000 +++ b/vamp-sdk/hostext/PluginBufferingAdapter.cpp Fri Jul 25 11:49:06 2008 +0000 @@ -52,7 +52,10 @@ public: Impl(Plugin *plugin, float inputSampleRate); ~Impl(); - + + void setPluginStepSize(size_t stepSize); + void setPluginBlockSize(size_t blockSize); + bool initialise(size_t channels, size_t stepSize, size_t blockSize); OutputList getOutputDescriptors() const; @@ -219,10 +222,12 @@ }; Plugin *m_plugin; - size_t m_inputStepSize; - size_t m_inputBlockSize; - size_t m_stepSize; - size_t m_blockSize; + size_t m_inputStepSize; // value passed to wrapper initialise() + size_t m_inputBlockSize; // value passed to wrapper initialise() + size_t m_setStepSize; // value passed to setPluginStepSize() + size_t m_setBlockSize; // value passed to setPluginBlockSize() + size_t m_stepSize; // value actually used to initialise plugin + size_t m_blockSize; // value actually used to initialise plugin size_t m_channels; vector m_queue; float **m_buffers; @@ -245,6 +250,42 @@ { delete m_impl; } + +size_t +PluginBufferingAdapter::getPreferredStepSize() const +{ + return getPreferredBlockSize(); +} + +size_t +PluginBufferingAdapter::getPreferredBlockSize() const +{ + return PluginWrapper::getPreferredBlockSize(); +} + +size_t +PluginBufferingAdapter::getPluginPreferredStepSize() const +{ + return PluginWrapper::getPreferredStepSize(); +} + +size_t +PluginBufferingAdapter::getPluginPreferredBlockSize() const +{ + return PluginWrapper::getPreferredBlockSize(); +} + +void +PluginBufferingAdapter::setPluginStepSize(size_t stepSize) +{ + m_impl->setPluginStepSize(stepSize); +} + +void +PluginBufferingAdapter::setPluginBlockSize(size_t blockSize) +{ + m_impl->setPluginBlockSize(blockSize); +} bool PluginBufferingAdapter::initialise(size_t channels, size_t stepSize, size_t blockSize) @@ -281,6 +322,8 @@ m_plugin(plugin), m_inputStepSize(0), m_inputBlockSize(0), + m_setStepSize(0), + m_setBlockSize(0), m_stepSize(0), m_blockSize(0), m_channels(0), @@ -303,13 +346,27 @@ } delete[] m_buffers; } - -size_t -PluginBufferingAdapter::getPreferredStepSize() const + +void +PluginBufferingAdapter::Impl::setPluginStepSize(size_t stepSize) { - return getPreferredBlockSize(); + if (m_inputStepSize != 0) { + std::cerr << "PluginBufferingAdapter::setPluginStepSize: ERROR: Cannot be called after initialise()" << std::endl; + return; + } + m_setStepSize = stepSize; } +void +PluginBufferingAdapter::Impl::setPluginBlockSize(size_t blockSize) +{ + if (m_inputBlockSize != 0) { + std::cerr << "PluginBufferingAdapter::setPluginBlockSize: ERROR: Cannot be called after initialise()" << std::endl; + return; + } + m_setBlockSize = blockSize; +} + bool PluginBufferingAdapter::Impl::initialise(size_t channels, size_t stepSize, size_t blockSize) { @@ -321,37 +378,59 @@ m_channels = channels; m_inputStepSize = stepSize; m_inputBlockSize = blockSize; + + // if the user has requested particular step or block sizes, use + // those; otherwise use the step and block sizes which the plugin + // prefers + + m_stepSize = 0; + m_blockSize = 0; + + if (m_setStepSize > 0) { + m_stepSize = m_setStepSize; + } + if (m_setBlockSize > 0) { + m_blockSize = m_setBlockSize; + } + + if (m_stepSize == 0 && m_blockSize == 0) { + m_stepSize = m_plugin->getPreferredStepSize(); + m_blockSize = m_plugin->getPreferredBlockSize(); + } - // use the step and block sizes which the plugin prefers - m_stepSize = m_plugin->getPreferredStepSize(); - m_blockSize = m_plugin->getPreferredBlockSize(); + bool freq = (m_plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain); // or sensible defaults if it has no preference if (m_blockSize == 0) { - m_blockSize = 1024; - } - if (m_stepSize == 0) { - if (m_plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) { + if (m_stepSize == 0) { + m_blockSize = 1024; + } else if (freq) { + m_blockSize = m_stepSize * 2; + } else { + m_blockSize = m_stepSize; + } + } else if (m_stepSize == 0) { // m_blockSize != 0 (that was handled above) + if (freq) { m_stepSize = m_blockSize/2; } else { m_stepSize = m_blockSize; } - } else if (m_stepSize > m_blockSize) { - if (m_plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) { - m_blockSize = m_stepSize * 2; - } else { - m_blockSize = m_stepSize; - } } - std::cerr << "PluginBufferingAdapter::initialise: stepSize " << m_inputStepSize << " -> " << m_stepSize - << ", blockSize " << m_inputBlockSize << " -> " << m_blockSize << std::endl; - // current implementation breaks if step is greater than block if (m_stepSize > m_blockSize) { - std::cerr << "PluginBufferingAdapter::initialise: plugin's preferred stepSize greater than blockSize, giving up!" << std::endl; - return false; + size_t newBlockSize; + if (freq) { + newBlockSize = m_stepSize * 2; + } else { + newBlockSize = m_stepSize; + } + std::cerr << "PluginBufferingAdapter::initialise: WARNING: step size " << m_stepSize << " is greater than block size " << m_blockSize << ": cannot handle this in adapter; adjusting block size to " << newBlockSize << std::endl; + m_blockSize = newBlockSize; } + + std::cerr << "PluginBufferingAdapter::initialise: NOTE: stepSize " << m_inputStepSize << " -> " << m_stepSize + << ", blockSize " << m_inputBlockSize << " -> " << m_blockSize << std::endl; m_buffers = new float *[m_channels]; @@ -417,6 +496,11 @@ PluginBufferingAdapter::Impl::process(const float *const *inputBuffers, RealTime timestamp) { + if (m_inputStepSize == 0) { + std::cerr << "PluginBufferingAdapter::process: ERROR: Plugin has not been initialised" << std::endl; + return FeatureSet(); + } + FeatureSet allFeatureSets; if (m_unrun) { diff -r 006a775133b1 -r af8e59f43d1d vamp-sdk/hostext/PluginBufferingAdapter.h --- a/vamp-sdk/hostext/PluginBufferingAdapter.h Thu Jul 24 16:50:11 2008 +0000 +++ b/vamp-sdk/hostext/PluginBufferingAdapter.h Fri Jul 25 11:49:06 2008 +0000 @@ -74,11 +74,80 @@ public: PluginBufferingAdapter(Plugin *plugin); // I take ownership of plugin virtual ~PluginBufferingAdapter(); - + + /** + * Return the preferred step size for this adapter. + * + * Because of the way this adapter works, its preferred step size + * will always be the same as its preferred block size. This may + * or may not be the same as the preferred step size of the + * underlying plugin, which may be obtained by calling + * getPluginPreferredStepSize(). + */ + size_t getPreferredStepSize() const; + + /** + * Return the preferred block size for this adapter. + * + * This may or may not be the same as the preferred block size of + * the underlying plugin, which may be obtained by calling + * getPluginPreferredBlockSize(). + * + * Note that this adapter may be initialised with any block size, + * not just its supposedly preferred one. + */ + size_t getPreferredBlockSize() const; + + /** + * Return the preferred step size of the plugin wrapped by this + * adapter. + * + * This is included mainly for informational purposes. This value + * is not likely to be a valid step size for the adapter itself, + * and it is not usually of any use in interpreting the results + * (because the adapter re-writes OneSamplePerStep outputs to + * FixedSampleRate so that the hop size no longer needs to be + * known beforehand in order to interpret them). + */ + size_t getPluginPreferredStepSize() const; + + /** + * Return the preferred block size of the plugin wrapped by this + * adapter. + * + * This is included mainly for informational purposes. + */ + size_t getPluginPreferredBlockSize() const; + + /** + * Set the step size that will be used for the underlying plugin + * when initialise() is called. If this is not set, the plugin's + * own preferred step size will be used. You will not usually + * need to call this function. If you do call it, it must be + * before the first call to initialise(). + */ + void setPluginStepSize(size_t stepSize); + + /** + * Set the block size that will be used for the underlying plugin + * when initialise() is called. If this is not set, the plugin's + * own preferred block size will be used. You will not usually + * need to call this function. If you do call it, it must be + * before the first call to initialise(). + */ + void setPluginBlockSize(size_t blockSize); + + /** + * Initialise the adapter (and therefore the plugin) for the given + * number of channels. Initialise the adapter for the given step + * and block size, which must be equal. + * + * The step and block size used for the underlying plugin will + * depend on its preferences, or any values previously passed to + * setPluginStepSize and setPluginBlockSize. + */ bool initialise(size_t channels, size_t stepSize, size_t blockSize); - size_t getPreferredStepSize() const; - OutputList getOutputDescriptors() const; void reset();