diff transform/CSVFeatureWriter.cpp @ 669:a41b4e30e3d9

* Add sample-timing option for CSV feature writer
author Chris Cannam
date Wed, 02 Mar 2011 15:39:43 +0000
parents 4541581067f3
children 06f13a3b9e9e
line wrap: on
line diff
--- a/transform/CSVFeatureWriter.cpp	Mon Feb 07 21:14:09 2011 +0000
+++ b/transform/CSVFeatureWriter.cpp	Wed Mar 02 15:39:43 2011 +0000
@@ -31,7 +31,8 @@
     FileFeatureWriter(SupportOneFilePerTrackTransform |
                       SupportOneFileTotal,
                       "csv"),
-    m_separator(",")
+    m_separator(","),
+    m_sampleTiming(false)
 {
 }
 
@@ -49,6 +50,11 @@
     p.description = "Column separator for output.  Default is \",\" (comma).";
     p.hasArg = true;
     pl.push_back(p);
+    
+    p.name = "sample-timing";
+    p.description = "Show timings as sample frame counts instead of in seconds.";
+    p.hasArg = false;
+    pl.push_back(p);
 
     return pl;
 }
@@ -64,6 +70,8 @@
         cerr << i->first << " -> " << i->second << endl;
         if (i->first == "separator") {
             m_separator = i->second.c_str();
+        } else if (i->first == "sample-timing") {
+            m_sampleTiming = true;
         }
     }
 }
@@ -96,15 +104,29 @@
             }
         }
 
-        QString timestamp = features[i].timestamp.toString().c_str();
-        timestamp.replace(QRegExp("^ +"), "");
-        stream << timestamp;
+        if (m_sampleTiming) {
 
-        if (features[i].hasDuration) {
-            QString duration = features[i].duration.toString().c_str();
-            duration.replace(QRegExp("^ +"), "");
-            stream << m_separator << duration;
-        }            
+            stream << Vamp::RealTime::realTime2Frame
+                (features[i].timestamp, transform.getSampleRate());
+
+            if (features[i].hasDuration) {
+                stream << m_separator;
+                stream << Vamp::RealTime::realTime2Frame
+                    (features[i].duration, transform.getSampleRate());
+            }
+
+        } else {
+
+            QString timestamp = features[i].timestamp.toString().c_str();
+            timestamp.replace(QRegExp("^ +"), "");
+            stream << timestamp;
+
+            if (features[i].hasDuration) {
+                QString duration = features[i].duration.toString().c_str();
+                duration.replace(QRegExp("^ +"), "");
+                stream << m_separator << duration;
+            }            
+        }
 
         if (summaryType != "") {
             stream << m_separator << summaryType.c_str();