changeset 348:8037a36dcf9e

Fix incorrect handling of FixedSampleRate outputs in PluginBufferingAdapter
author Chris Cannam
date Wed, 27 Mar 2013 16:50:19 +0000
parents efb69fd6f27f
children dc40fff9f20b
files src/vamp-hostsdk/PluginBufferingAdapter.cpp
diffstat 1 files changed, 35 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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<int, bool> m_rewriteOutputTimes;
+    std::map<int, int> 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<int, FeatureList>::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;