# HG changeset patch # User Chris Cannam # Date 1364398053 0 # Node ID 15cd67fcbdada9734f147bb1024bd914e0dfdb26 # Parent d373ced0e6e9ea7821865a600b8d68ab279a4486 Fix calculation of timestamps for fixed-rate features diff -r d373ced0e6e9 -r 15cd67fcbdad transform/FeatureExtractionModelTransformer.cpp --- a/transform/FeatureExtractionModelTransformer.cpp Wed Mar 27 15:07:27 2013 +0000 +++ b/transform/FeatureExtractionModelTransformer.cpp Wed Mar 27 15:27:33 2013 +0000 @@ -41,7 +41,8 @@ ModelTransformer(in, transform), m_plugin(0), m_descriptor(0), - m_outputNo(0) + m_outputNo(0), + m_fixedRateFeatureNo(-1) // we increment before use { // SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: plugin " << pluginId << ", outputName " << m_transform.getOutput() << endl; @@ -662,6 +663,17 @@ } else if (m_descriptor->sampleType == Vamp::Plugin::OutputDescriptor::FixedSampleRate) { + if (!feature.hasTimestamp) { + ++m_fixedRateFeatureNo; + } else { + RealTime ts(feature.timestamp.sec, feature.timestamp.nsec); + m_fixedRateFeatureNo = + lrint(ts.toDouble() * m_descriptor->sampleRate); + } + + frame = lrintf((m_fixedRateFeatureNo / m_descriptor->sampleRate) + * inputRate); +/* if (feature.hasTimestamp) { //!!! warning: sampleRate may be non-integral frame = Vamp::RealTime::realTime2Frame(feature.timestamp, @@ -671,8 +683,8 @@ } else { frame = m_output->getEndFrame(); } - -// std::cerr << "Feature hasTimestamp = " << feature.hasTimestamp << ", timestamp = " << feature.timestamp << ", frame works out to " << frame << std::endl; +*/ + std::cerr << "Feature hasTimestamp = " << feature.hasTimestamp << ", timestamp = " << feature.timestamp << ", frame works out to " << frame << std::endl; } diff -r d373ced0e6e9 -r 15cd67fcbdad transform/FeatureExtractionModelTransformer.h --- a/transform/FeatureExtractionModelTransformer.h Wed Mar 27 15:07:27 2013 +0000 +++ b/transform/FeatureExtractionModelTransformer.h Wed Mar 27 15:27:33 2013 +0000 @@ -40,6 +40,7 @@ Vamp::Plugin *m_plugin; Vamp::Plugin::OutputDescriptor *m_descriptor; + int m_fixedRateFeatureNo; // to assign times to FixedSampleRate features int m_outputNo; void createOutputModel();