diff transform/FeatureExtractionModelTransformer.cpp @ 822:54829c1e155e tonioni

Merge from the default branch
author Chris Cannam
date Fri, 12 Jul 2013 13:10:28 +0100
parents 4faea021b5c1 98cf98a217d2
children 2d53205f70cd
line wrap: on
line diff
--- a/transform/FeatureExtractionModelTransformer.cpp	Thu Jun 20 13:47:35 2013 +0100
+++ b/transform/FeatureExtractionModelTransformer.cpp	Fri Jul 12 13:10:28 2013 +0100
@@ -43,8 +43,9 @@
     ModelTransformer(in, transform),
     m_plugin(0),
     m_descriptor(0),
-    m_outputFeatureNo(0),
-	m_preferredOutputModel(outputmodel)
+    m_outputNo(0),
+    m_fixedRateFeatureNo(-1), // we increment before use
+    m_preferredOutputModel(outputmodel)
 {
 //    SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: plugin " << pluginId << ", outputName " << m_transform.getOutput() << endl;
 
@@ -158,7 +159,7 @@
 //        SVDEBUG << "comparing output " << i << " name \"" << outputs[i].identifier << "\" with expected \"" << m_transform.getOutput() << "\"" << endl;
 	if (m_transform.getOutput() == "" ||
             outputs[i].identifier == m_transform.getOutput().toStdString()) {
-	    m_outputFeatureNo = i;
+	    m_outputNo = i;
 	    m_descriptor = new Vamp::Plugin::OutputDescriptor(outputs[i]);
 	    break;
 	}
@@ -204,6 +205,14 @@
     size_t modelRate = input->getSampleRate();
     size_t modelResolution = 1;
 
+    if (m_descriptor->sampleType != 
+        Vamp::Plugin::OutputDescriptor::OneSamplePerStep) {
+        if (m_descriptor->sampleRate > input->getSampleRate()) {
+            std::cerr << "WARNING: plugin reports output sample rate as "
+                      << m_descriptor->sampleRate << " (can't display features with finer resolution than the input rate of " << input->getSampleRate() << ")" << std::endl;
+        }
+    }
+
     switch (m_descriptor->sampleType) {
 
     case Vamp::Plugin::OutputDescriptor::VariableSampleRate:
@@ -352,7 +361,7 @@
         }
 
         Vamp::Plugin::OutputList outputs = m_plugin->getOutputDescriptors();
-        model->setScaleUnits(outputs[m_outputFeatureNo].unit.c_str());
+        model->setScaleUnits(outputs[m_outputNo].unit.c_str());
 
         m_output = model;
 
@@ -547,9 +556,8 @@
 
         if (m_abandoned) break;
 
-	for (size_t fi = 0; fi < features[m_outputFeatureNo].size(); ++fi) {
-	    Vamp::Plugin::Feature feature =
-		features[m_outputFeatureNo][fi];
+	for (size_t fi = 0; fi < features[m_outputNo].size(); ++fi) {
+	    Vamp::Plugin::Feature feature = features[m_outputNo][fi];
 	    addFeature(blockFrame, feature);
 	}
 
@@ -564,9 +572,8 @@
     if (!m_abandoned) {
         Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures();
 
-        for (size_t fi = 0; fi < features[m_outputFeatureNo].size(); ++fi) {
-            Vamp::Plugin::Feature feature =
-                features[m_outputFeatureNo][fi];
+        for (size_t fi = 0; fi < features[m_outputNo].size(); ++fi) {
+            Vamp::Plugin::Feature feature = features[m_outputNo][fi];
             addFeature(blockFrame, feature);
         }
     }
@@ -677,15 +684,16 @@
     } else if (m_descriptor->sampleType ==
 	       Vamp::Plugin::OutputDescriptor::FixedSampleRate) {
 
-	if (feature.hasTimestamp) {
-	    //!!! warning: sampleRate may be non-integral
-	    frame = Vamp::RealTime::realTime2Frame(feature.timestamp,
-//!!! see comment above when setting up modelResolution and modelRate
-//                                                   lrintf(m_descriptor->sampleRate));
-                                                   inputRate);
-	} else {
-	    frame = m_output->getEndFrame();
-	}
+        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);
     }
 	
     // Rather than repeat the complicated tests from the constructor