# HG changeset patch # User Chris Cannam # Date 1364403019 0 # Node ID 8037a36dcf9ecc4e92c42639d2e9d6607f181c3b # Parent efb69fd6f27f02b6a6c331895a670713a420eeba Fix incorrect handling of FixedSampleRate outputs in PluginBufferingAdapter diff -r efb69fd6f27f -r 8037a36dcf9e src/vamp-hostsdk/PluginBufferingAdapter.cpp --- a/src/vamp-hostsdk/PluginBufferingAdapter.cpp Wed Mar 20 16:05:12 2013 +0000 +++ b/src/vamp-hostsdk/PluginBufferingAdapter.cpp Wed Mar 27 16:50:19 2013 +0000 @@ -244,8 +244,10 @@ bool m_unrun; mutable OutputList m_outputs; mutable std::map m_rewriteOutputTimes; + std::map m_fixedRateFeatureNos; // output no -> feature no void processBlock(FeatureSet& allFeatureSets); + void adjustFixedRateFeatureTime(int outputNo, Feature &); }; PluginBufferingAdapter::PluginBufferingAdapter(Plugin *plugin) : @@ -607,6 +609,26 @@ return allFeatureSets; } +void +PluginBufferingAdapter::Impl::adjustFixedRateFeatureTime(int outputNo, + Feature &feature) +{ + if (feature.hasTimestamp) { + double secs = feature.timestamp.sec; + secs += feature.timestamp.nsec / 1e9; + double eps = 0.00001; + m_fixedRateFeatureNos[outputNo] = + int(secs * m_outputs[outputNo].sampleRate + 0.5); + } + + feature.timestamp = RealTime::fromSeconds + (m_fixedRateFeatureNos[outputNo] / m_outputs[outputNo].sampleRate); + + feature.hasTimestamp = true; + + m_fixedRateFeatureNos[outputNo] = m_fixedRateFeatureNos[outputNo] + 1; +} + PluginBufferingAdapter::FeatureSet PluginBufferingAdapter::Impl::getRemainingFeatures() { @@ -631,9 +653,18 @@ for (map::iterator iter = featureSet.begin(); iter != featureSet.end(); ++iter) { + + int outputNo = iter->first; FeatureList featureList = iter->second; + for (size_t i = 0; i < featureList.size(); ++i) { - allFeatureSets[iter->first].push_back(featureList[i]); + + if (m_outputs[outputNo].sampleType == + OutputDescriptor::FixedSampleRate) { + adjustFixedRateFeatureTime(outputNo, featureList[i]); + } + + allFeatureSets[outputNo].push_back(featureList[i]); } } @@ -681,15 +712,12 @@ break; case OutputDescriptor::FixedSampleRate: - // use our internal timestamp if feature lacks one - if (!featureList[i].hasTimestamp) { - featureList[i].timestamp = timestamp + adjustment; - featureList[i].hasTimestamp = true; - } + adjustFixedRateFeatureTime(outputNo, featureList[i]); break; case OutputDescriptor::VariableSampleRate: - break; // plugin must set timestamp + // plugin must set timestamp + break; default: break;