comparison transform/FeatureExtractionModelTransformer.cpp @ 779:15cd67fcbdad

Fix calculation of timestamps for fixed-rate features
author Chris Cannam
date Wed, 27 Mar 2013 15:27:33 +0000
parents d373ced0e6e9
children cf466a5d411e
comparison
equal deleted inserted replaced
778:d373ced0e6e9 779:15cd67fcbdad
39 FeatureExtractionModelTransformer::FeatureExtractionModelTransformer(Input in, 39 FeatureExtractionModelTransformer::FeatureExtractionModelTransformer(Input in,
40 const Transform &transform) : 40 const Transform &transform) :
41 ModelTransformer(in, transform), 41 ModelTransformer(in, transform),
42 m_plugin(0), 42 m_plugin(0),
43 m_descriptor(0), 43 m_descriptor(0),
44 m_outputNo(0) 44 m_outputNo(0),
45 m_fixedRateFeatureNo(-1) // we increment before use
45 { 46 {
46 // SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: plugin " << pluginId << ", outputName " << m_transform.getOutput() << endl; 47 // SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: plugin " << pluginId << ", outputName " << m_transform.getOutput() << endl;
47 48
48 QString pluginId = transform.getPluginIdentifier(); 49 QString pluginId = transform.getPluginIdentifier();
49 50
660 } 661 }
661 662
662 } else if (m_descriptor->sampleType == 663 } else if (m_descriptor->sampleType ==
663 Vamp::Plugin::OutputDescriptor::FixedSampleRate) { 664 Vamp::Plugin::OutputDescriptor::FixedSampleRate) {
664 665
666 if (!feature.hasTimestamp) {
667 ++m_fixedRateFeatureNo;
668 } else {
669 RealTime ts(feature.timestamp.sec, feature.timestamp.nsec);
670 m_fixedRateFeatureNo =
671 lrint(ts.toDouble() * m_descriptor->sampleRate);
672 }
673
674 frame = lrintf((m_fixedRateFeatureNo / m_descriptor->sampleRate)
675 * inputRate);
676 /*
665 if (feature.hasTimestamp) { 677 if (feature.hasTimestamp) {
666 //!!! warning: sampleRate may be non-integral 678 //!!! warning: sampleRate may be non-integral
667 frame = Vamp::RealTime::realTime2Frame(feature.timestamp, 679 frame = Vamp::RealTime::realTime2Frame(feature.timestamp,
668 //!!! see comment above when setting up modelResolution and modelRate 680 //!!! see comment above when setting up modelResolution and modelRate
669 // lrintf(m_descriptor->sampleRate)); 681 // lrintf(m_descriptor->sampleRate));
670 inputRate); 682 inputRate);
671 } else { 683 } else {
672 frame = m_output->getEndFrame(); 684 frame = m_output->getEndFrame();
673 } 685 }
674 686 */
675 // std::cerr << "Feature hasTimestamp = " << feature.hasTimestamp << ", timestamp = " << feature.timestamp << ", frame works out to " << frame << std::endl; 687 std::cerr << "Feature hasTimestamp = " << feature.hasTimestamp << ", timestamp = " << feature.timestamp << ", frame works out to " << frame << std::endl;
676 688
677 } 689 }
678 690
679 // Rather than repeat the complicated tests from the constructor 691 // Rather than repeat the complicated tests from the constructor
680 // to determine what sort of model we must be adding the features 692 // to determine what sort of model we must be adding the features