comparison vamp/CQVamp.cpp @ 53:a25abb7a21c0

Further tidying, compensate for latency in Vamp plugin
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 28 Nov 2013 11:46:39 +0000
parents cb072f01435b
children 2a21b4506d7f
comparison
equal deleted inserted replaced
52:99fb93c72053 53:a25abb7a21c0
12 CQVamp::CQVamp(float inputSampleRate) : 12 CQVamp::CQVamp(float inputSampleRate) :
13 Vamp::Plugin(inputSampleRate), 13 Vamp::Plugin(inputSampleRate),
14 m_cq(0), 14 m_cq(0),
15 m_maxFrequency(inputSampleRate/2), 15 m_maxFrequency(inputSampleRate/2),
16 m_minFrequency(46), 16 m_minFrequency(46),
17 m_bpo(24) 17 m_bpo(24),
18 m_haveStartTime(false),
19 m_columnCount(0)
18 { 20 {
19 } 21 }
20 22
21 CQVamp::~CQVamp() 23 CQVamp::~CQVamp()
22 { 24 {
158 delete m_cq; 160 delete m_cq;
159 m_cq = new ConstantQ 161 m_cq = new ConstantQ
160 (m_inputSampleRate, m_minFrequency, m_maxFrequency, m_bpo); 162 (m_inputSampleRate, m_minFrequency, m_maxFrequency, m_bpo);
161 } 163 }
162 m_prevFeature.clear(); 164 m_prevFeature.clear();
165 m_haveStartTime = false;
166 m_columnCount = 0;
163 } 167 }
164 168
165 size_t 169 size_t
166 CQVamp::getPreferredStepSize() const 170 CQVamp::getPreferredStepSize() const
167 { 171 {
195 return list; 199 return list;
196 } 200 }
197 201
198 CQVamp::FeatureSet 202 CQVamp::FeatureSet
199 CQVamp::process(const float *const *inputBuffers, 203 CQVamp::process(const float *const *inputBuffers,
200 Vamp::RealTime /* timestamp */) 204 Vamp::RealTime timestamp)
201 { 205 {
202 if (!m_cq) { 206 if (!m_cq) {
203 cerr << "ERROR: CQVamp::process: " 207 cerr << "ERROR: CQVamp::process: "
204 << "Plugin has not been initialised" 208 << "Plugin has not been initialised"
205 << endl; 209 << endl;
206 return FeatureSet(); 210 return FeatureSet();
207 } 211 }
208 212
213 if (!m_haveStartTime) {
214 m_startTime = timestamp;
215 m_haveStartTime = true;
216 }
217
209 vector<double> data; 218 vector<double> data;
210 for (int i = 0; i < m_blockSize; ++i) data.push_back(inputBuffers[0][i]); 219 for (int i = 0; i < m_blockSize; ++i) data.push_back(inputBuffers[0][i]);
211 220
212 vector<vector<double> > cqout = m_cq->process(data); 221 vector<vector<double> > cqout = m_cq->process(data);
213 return convertToFeatures(cqout); 222 return convertToFeatures(cqout);
221 } 230 }
222 231
223 CQVamp::FeatureSet 232 CQVamp::FeatureSet
224 CQVamp::convertToFeatures(const vector<vector<double> > &cqout) 233 CQVamp::convertToFeatures(const vector<vector<double> > &cqout)
225 { 234 {
226
227 FeatureSet returnFeatures; 235 FeatureSet returnFeatures;
228 236
229 for (int i = 0; i < (int)cqout.size(); ++i) { 237 for (int i = 0; i < (int)cqout.size(); ++i) {
230 238
231 vector<float> column(m_cq->getTotalBins(), 0.f); 239 vector<float> column(m_cq->getTotalBins(), 0.f);
240 } 248 }
241 249
242 m_prevFeature = column; 250 m_prevFeature = column;
243 251
244 Feature feature; 252 Feature feature;
245 feature.hasTimestamp = false; 253 feature.hasTimestamp = true;
254 feature.timestamp = m_startTime + Vamp::RealTime::frame2RealTime
255 (m_columnCount * m_cq->getColumnHop() - m_cq->getLatency(),
256 m_inputSampleRate);
246 feature.values = column; 257 feature.values = column;
247 feature.label = ""; 258 feature.label = "";
248 returnFeatures[0].push_back(feature); 259
260 cerr << "timestamp = " << feature.timestamp << " (latency = " << m_cq->getLatency() << ", sample rate " << m_inputSampleRate << ")" << endl;
261
262 if (feature.timestamp >= m_startTime) {
263 returnFeatures[0].push_back(feature);
264 }
265
266 ++m_columnCount;
249 } 267 }
250 268
251 return returnFeatures; 269 return returnFeatures;
252 } 270 }
253 271