changeset 1071:f4ad0bfceeb7

Handle case where plugin erroneously returns sample rate 0 for fixed-rate output
author Chris Cannam
date Thu, 14 May 2015 14:04:41 +0100
parents b8a788c9a6f1
children 882d448c8a6d d4212687520e
files transform/FeatureExtractionModelTransformer.cpp
diffstat 1 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/transform/FeatureExtractionModelTransformer.cpp	Tue May 12 16:19:45 2015 +0100
+++ b/transform/FeatureExtractionModelTransformer.cpp	Thu May 14 14:04:41 2015 +0100
@@ -280,6 +280,9 @@
         //!!! data with a higher resolution than the base model at all
         if (m_descriptors[n]->sampleRate > input->getSampleRate()) {
             modelResolution = 1;
+        } else if (m_descriptors[n]->sampleRate <= 0.0) {
+            cerr << "WARNING: Fixed sample-rate plugin reports invalid sample rate " << m_descriptors[n]->sampleRate << "; defaulting to input rate of " << input->getSampleRate() << endl;
+            modelResolution = 1;
         } else {
             modelResolution = int(round(modelRate / m_descriptors[n]->sampleRate));
         }
@@ -842,24 +845,30 @@
 	    frame = RealTime::realTime2Frame(feature.timestamp, inputRate);
 	}
 
+//        cerr << "variable sample rate: timestamp = " << feature.timestamp
+//             << " at input rate " << inputRate << " -> " << frame << endl;
+        
     } else if (m_descriptors[n]->sampleType ==
 	       Vamp::Plugin::OutputDescriptor::FixedSampleRate) {
 
+        sv_samplerate_t rate = m_descriptors[n]->sampleRate;
+        if (rate <= 0.0) {
+            rate = inputRate;
+        }
+        
         if (!feature.hasTimestamp) {
             ++m_fixedRateFeatureNos[n];
         } else {
             RealTime ts(feature.timestamp.sec, feature.timestamp.nsec);
-            m_fixedRateFeatureNos[n] = (int)
-                lrint(ts.toDouble() * m_descriptors[n]->sampleRate);
+            m_fixedRateFeatureNos[n] = (int)lrint(ts.toDouble() * rate);
         }
 
-//        cerr << "m_fixedRateFeatureNo = " << m_fixedRateFeatureNo 
-//             << ", m_descriptor->sampleRate = " << m_descriptor->sampleRate
+//        cerr << "m_fixedRateFeatureNo = " << m_fixedRateFeatureNos[n]
+//             << ", m_descriptor->sampleRate = " << m_descriptors[n]->sampleRate
 //             << ", inputRate = " << inputRate
 //             << " giving frame = ";
-        frame = lrint((double(m_fixedRateFeatureNos[n])
-                       / m_descriptors[n]->sampleRate)
-                      * inputRate);
+        frame = lrint((double(m_fixedRateFeatureNos[n]) / rate) * inputRate);
+//        cerr << frame << endl;
     }
 
     if (frame < 0) {