Mercurial > hg > vamp-plugin-sdk
comparison examples/FixedTempoEstimator.cpp @ 199:84c4bb209227
* A few tweaks to fixed-tempo estimator
author | cannam |
---|---|
date | Wed, 08 Oct 2008 19:48:21 +0000 |
parents | e3e61b7e9661 |
children | a86e777bf9a6 |
comparison
equal
deleted
inserted
replaced
198:e3e61b7e9661 | 199:84c4bb209227 |
---|---|
285 ++m_n; | 285 ++m_n; |
286 return fs; | 286 return fs; |
287 } | 287 } |
288 | 288 |
289 float | 289 float |
290 FixedTempoEstimator::lag2tempo(int lag) { | 290 FixedTempoEstimator::lag2tempo(int lag) |
291 { | |
291 return 60.f / ((lag * m_stepSize) / m_inputSampleRate); | 292 return 60.f / ((lag * m_stepSize) / m_inputSampleRate); |
292 } | 293 } |
293 | 294 |
294 FixedTempoEstimator::FeatureSet | 295 FixedTempoEstimator::FeatureSet |
295 FixedTempoEstimator::calculateFeatures() | 296 FixedTempoEstimator::calculateFeatures() |
312 float *f = m_df; | 313 float *f = m_df; |
313 | 314 |
314 for (int i = 0; i < n; ++i) { | 315 for (int i = 0; i < n; ++i) { |
315 feature.timestamp = RealTime::frame2RealTime(i * m_stepSize, | 316 feature.timestamp = RealTime::frame2RealTime(i * m_stepSize, |
316 m_inputSampleRate); | 317 m_inputSampleRate); |
317 std::cerr << "step = " << m_stepSize << ", timestamp = " << feature.timestamp << std::endl; | |
318 feature.values[0] = f[i]; | 318 feature.values[0] = f[i]; |
319 feature.label = ""; | 319 feature.label = ""; |
320 fs[1].push_back(feature); | 320 fs[1].push_back(feature); |
321 } | 321 } |
322 | 322 |
330 r[i] += f[j] * f[j - i]; | 330 r[i] += f[j] * f[j - i]; |
331 } | 331 } |
332 r[i] /= n - i - 1; | 332 r[i] /= n - i - 1; |
333 } | 333 } |
334 | 334 |
335 for (int i = 0; i < n/2; ++i) { | 335 for (int i = 1; i < n/2; ++i) { |
336 feature.timestamp = RealTime::frame2RealTime(i * m_stepSize, | 336 feature.timestamp = RealTime::frame2RealTime(i * m_stepSize, |
337 m_inputSampleRate); | 337 m_inputSampleRate); |
338 feature.values[0] = r[i]; | 338 feature.values[0] = r[i]; |
339 sprintf(buffer, "%f bpm", lag2tempo(i)); | 339 sprintf(buffer, "%.1f bpm", lag2tempo(i)); |
340 feature.label = buffer; | 340 feature.label = buffer; |
341 fs[2].push_back(feature); | 341 fs[2].push_back(feature); |
342 } | 342 } |
343 | 343 |
344 float max = 0.f; | 344 float max = 0.f; |
386 | 386 |
387 // int fi = i - p0; | 387 // int fi = i - p0; |
388 | 388 |
389 float filtered = 0.f; | 389 float filtered = 0.f; |
390 | 390 |
391 for (int j = 1; j <= (n/2)/p1; ++j) { | 391 for (int j = 1; j <= (n/2 - 1)/i; ++j) { |
392 std::cerr << "j = " << j << ", i = " << i << std::endl; | 392 // std::cerr << "j = " << j << ", i = " << i << std::endl; |
393 filtered += r[i * j]; | 393 filtered += r[i * j]; |
394 } | 394 } |
395 filtered /= (n/2 - 1)/i; | |
395 | 396 |
396 if (i == p0 || filtered > maxp) { | 397 if (i == p0 || filtered > maxp) { |
397 maxp = filtered; | 398 maxp = filtered; |
398 maxpi = i; | 399 maxpi = i; |
399 } | 400 } |
400 | 401 |
401 feature.timestamp = RealTime::frame2RealTime(i * m_stepSize, | 402 feature.timestamp = RealTime::frame2RealTime(i * m_stepSize, |
402 m_inputSampleRate); | 403 m_inputSampleRate); |
403 feature.values[0] = filtered; | 404 feature.values[0] = filtered; |
404 sprintf(buffer, "%f bpm", lag2tempo(i)); | 405 sprintf(buffer, "%.1f bpm", lag2tempo(i)); |
405 feature.label = buffer; | 406 feature.label = buffer; |
406 fs[3].push_back(feature); | 407 fs[3].push_back(feature); |
407 } | 408 } |
408 | 409 |
409 std::cerr << "maxpi = " << maxpi << " for tempo " << lag2tempo(maxpi) << " (value = " << maxp << ")" << std::endl; | 410 std::cerr << "maxpi = " << maxpi << " for tempo " << lag2tempo(maxpi) << " (value = " << maxp << ")" << std::endl; |
418 feature.hasDuration = true; | 419 feature.hasDuration = true; |
419 feature.duration = m_lasttime - m_start; | 420 feature.duration = m_lasttime - m_start; |
420 | 421 |
421 feature.values[0] = tempo; | 422 feature.values[0] = tempo; |
422 | 423 |
424 sprintf(buffer, "%.1f bpm", tempo); | |
425 feature.label = buffer; | |
426 | |
423 fs[0].push_back(feature); | 427 fs[0].push_back(feature); |
424 | 428 |
425 return fs; | 429 return fs; |
426 } | 430 } |