# HG changeset patch # User Chris Cannam # Date 1441370908 -3600 # Node ID 1522e2f6d7005e094b56caebc91e181cbbf76296 # Parent 6f88563ea26fc3b2a6cc3230ad37675d56278b01 Fix handling of output sample rate in buffering adapter in case where SampleType is Fixed but no sample rate provided (which is invalid behaviour from the plugin, but we might as well do the right thing with it) diff -r 6f88563ea26f -r 1522e2f6d700 src/vamp-hostsdk/PluginBufferingAdapter.cpp --- a/src/vamp-hostsdk/PluginBufferingAdapter.cpp Fri Sep 04 13:47:25 2015 +0100 +++ b/src/vamp-hostsdk/PluginBufferingAdapter.cpp Fri Sep 04 13:48:28 2015 +0100 @@ -41,6 +41,10 @@ #include #include +#include +using std::cerr; +using std::endl; + using std::vector; using std::map; @@ -512,13 +516,13 @@ case OutputDescriptor::OneSamplePerStep: outs[i].sampleType = OutputDescriptor::FixedSampleRate; - outs[i].sampleRate = (1.f / m_inputSampleRate) * m_stepSize; + outs[i].sampleRate = m_inputSampleRate / m_stepSize; m_rewriteOutputTimes[i] = true; break; case OutputDescriptor::FixedSampleRate: if (outs[i].sampleRate == 0.f) { - outs[i].sampleRate = (1.f / m_inputSampleRate) * m_stepSize; + outs[i].sampleRate = m_inputSampleRate / m_stepSize; } // We actually only need to rewrite output times for // features that don't have timestamps already, but we @@ -615,16 +619,25 @@ PluginBufferingAdapter::Impl::adjustFixedRateFeatureTime(int outputNo, Feature &feature) { +// cerr << "adjustFixedRateFeatureTime: from " << feature.timestamp; + + double rate = m_outputs[outputNo].sampleRate; + if (rate == 0.0) { + rate = m_inputSampleRate / m_stepSize; + } + if (feature.hasTimestamp) { double secs = feature.timestamp.sec; secs += feature.timestamp.nsec / 1e9; - m_fixedRateFeatureNos[outputNo] = - int(secs * double(m_outputs[outputNo].sampleRate) + 0.5); + m_fixedRateFeatureNos[outputNo] = int(secs * rate + 0.5); +// cerr << " [secs = " << secs << ", no = " << m_fixedRateFeatureNos[outputNo] << "]"; } feature.timestamp = RealTime::fromSeconds - (m_fixedRateFeatureNos[outputNo] / double(m_outputs[outputNo].sampleRate)); + (m_fixedRateFeatureNos[outputNo] / rate); +// cerr << " to " << feature.timestamp << " (rate = " << rate << ", hasTimestamp = " << feature.hasTimestamp << ")" << endl; + feature.hasTimestamp = true; m_fixedRateFeatureNos[outputNo] = m_fixedRateFeatureNos[outputNo] + 1;