comparison 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
comparison
equal deleted inserted replaced
668:ad7c96620886 669:a41b4e30e3d9
29 29
30 CSVFeatureWriter::CSVFeatureWriter() : 30 CSVFeatureWriter::CSVFeatureWriter() :
31 FileFeatureWriter(SupportOneFilePerTrackTransform | 31 FileFeatureWriter(SupportOneFilePerTrackTransform |
32 SupportOneFileTotal, 32 SupportOneFileTotal,
33 "csv"), 33 "csv"),
34 m_separator(",") 34 m_separator(","),
35 m_sampleTiming(false)
35 { 36 {
36 } 37 }
37 38
38 CSVFeatureWriter::~CSVFeatureWriter() 39 CSVFeatureWriter::~CSVFeatureWriter()
39 { 40 {
47 48
48 p.name = "separator"; 49 p.name = "separator";
49 p.description = "Column separator for output. Default is \",\" (comma)."; 50 p.description = "Column separator for output. Default is \",\" (comma).";
50 p.hasArg = true; 51 p.hasArg = true;
51 pl.push_back(p); 52 pl.push_back(p);
53
54 p.name = "sample-timing";
55 p.description = "Show timings as sample frame counts instead of in seconds.";
56 p.hasArg = false;
57 pl.push_back(p);
52 58
53 return pl; 59 return pl;
54 } 60 }
55 61
56 void 62 void
62 for (map<string, string>::iterator i = params.begin(); 68 for (map<string, string>::iterator i = params.begin();
63 i != params.end(); ++i) { 69 i != params.end(); ++i) {
64 cerr << i->first << " -> " << i->second << endl; 70 cerr << i->first << " -> " << i->second << endl;
65 if (i->first == "separator") { 71 if (i->first == "separator") {
66 m_separator = i->second.c_str(); 72 m_separator = i->second.c_str();
73 } else if (i->first == "sample-timing") {
74 m_sampleTiming = true;
67 } 75 }
68 } 76 }
69 } 77 }
70 78
71 void 79 void
94 } else { 102 } else {
95 stream << m_separator; 103 stream << m_separator;
96 } 104 }
97 } 105 }
98 106
99 QString timestamp = features[i].timestamp.toString().c_str(); 107 if (m_sampleTiming) {
100 timestamp.replace(QRegExp("^ +"), "");
101 stream << timestamp;
102 108
103 if (features[i].hasDuration) { 109 stream << Vamp::RealTime::realTime2Frame
104 QString duration = features[i].duration.toString().c_str(); 110 (features[i].timestamp, transform.getSampleRate());
105 duration.replace(QRegExp("^ +"), ""); 111
106 stream << m_separator << duration; 112 if (features[i].hasDuration) {
107 } 113 stream << m_separator;
114 stream << Vamp::RealTime::realTime2Frame
115 (features[i].duration, transform.getSampleRate());
116 }
117
118 } else {
119
120 QString timestamp = features[i].timestamp.toString().c_str();
121 timestamp.replace(QRegExp("^ +"), "");
122 stream << timestamp;
123
124 if (features[i].hasDuration) {
125 QString duration = features[i].duration.toString().c_str();
126 duration.replace(QRegExp("^ +"), "");
127 stream << m_separator << duration;
128 }
129 }
108 130
109 if (summaryType != "") { 131 if (summaryType != "") {
110 stream << m_separator << summaryType.c_str(); 132 stream << m_separator << summaryType.c_str();
111 } 133 }
112 134