comparison transform/CSVFeatureWriter.cpp @ 1006:d954e03274e8

TransformId is not sufficient -- it could be ambiguous (same transform id, different parameters etc). Use the whole transform
author Chris Cannam
date Wed, 15 Oct 2014 17:02:48 +0100
parents c2316a3bbb81
children d74ebd2d2c49
comparison
equal deleted inserted replaced
1005:6b2a8b34e9d3 1006:d954e03274e8
132 132
133 int n = features.size(); 133 int n = features.size();
134 134
135 if (n == 0) return; 135 if (n == 0) return;
136 136
137 TrackTransformPair tt(trackId, transformId); 137 DataId tt(trackId, transform);
138
139 if (m_rates.find(transformId) == m_rates.end()) {
140 m_rates[transformId] = transform.getSampleRate();
141 }
142 138
143 if (m_pending.find(tt) != m_pending.end()) { 139 if (m_pending.find(tt) != m_pending.end()) {
144 writeFeature(tt, 140 writeFeature(tt,
145 stream, 141 stream,
146 m_pending[tt], 142 m_pending[tt],
169 void 165 void
170 CSVFeatureWriter::finish() 166 CSVFeatureWriter::finish()
171 { 167 {
172 for (PendingFeatures::const_iterator i = m_pending.begin(); 168 for (PendingFeatures::const_iterator i = m_pending.begin();
173 i != m_pending.end(); ++i) { 169 i != m_pending.end(); ++i) {
174 TrackTransformPair tt = i->first; 170 DataId tt = i->first;
175 Plugin::Feature f = i->second; 171 Plugin::Feature f = i->second;
176 QTextStream *sptr = getOutputStream(tt.first, tt.second); 172 QTextStream *sptr = getOutputStream(tt.first, tt.second.getIdentifier());
177 if (!sptr) { 173 if (!sptr) {
178 throw FailedToOpenOutputStream(tt.first, tt.second); 174 throw FailedToOpenOutputStream(tt.first, tt.second.getIdentifier());
179 } 175 }
180 QTextStream &stream = *sptr; 176 QTextStream &stream = *sptr;
181 // final feature has its own time as end time (we can't 177 // final feature has its own time as end time (we can't
182 // reliably determine the end of audio file, and because of 178 // reliably determine the end of audio file, and because of
183 // the nature of block processing, the feature could even 179 // the nature of block processing, the feature could even
187 183
188 m_pending.clear(); 184 m_pending.clear();
189 } 185 }
190 186
191 void 187 void
192 CSVFeatureWriter::writeFeature(TrackTransformPair tt, 188 CSVFeatureWriter::writeFeature(DataId tt,
193 QTextStream &stream, 189 QTextStream &stream,
194 const Plugin::Feature &f, 190 const Plugin::Feature &f,
195 const Plugin::Feature *optionalNextFeature, 191 const Plugin::Feature *optionalNextFeature,
196 std::string summaryType) 192 std::string summaryType)
197 { 193 {
198 QString trackId = tt.first; 194 QString trackId = tt.first;
199 TransformId transformId = tt.second; 195 Transform transform = tt.second;
200 196
201 if (!m_omitFilename) { 197 if (!m_omitFilename) {
202 if (m_stdout || m_singleFileName != "") { 198 if (m_stdout || m_singleFileName != "") {
203 if (trackId != m_prevPrintedTrackId) { 199 if (trackId != m_prevPrintedTrackId) {
204 stream << "\"" << trackId << "\"" << m_separator; 200 stream << "\"" << trackId << "\"" << m_separator;
220 haveDuration = false; 216 haveDuration = false;
221 } 217 }
222 218
223 if (m_sampleTiming) { 219 if (m_sampleTiming) {
224 220
225 float rate = m_rates[transformId]; 221 float rate = transform.getSampleRate();
226 222
227 stream << Vamp::RealTime::realTime2Frame(f.timestamp, rate); 223 stream << Vamp::RealTime::realTime2Frame(f.timestamp, rate);
228 224
229 if (haveDuration) { 225 if (haveDuration) {
230 stream << m_separator; 226 stream << m_separator;