Mercurial > hg > vamp-plugin-sdk
comparison examples/FixedTempoEstimator.cpp @ 208:df55003e8968
* Slightly different angle on filtering... hmmm
author | cannam |
---|---|
date | Thu, 16 Oct 2008 14:17:07 +0000 |
parents | fa8afbb7221b |
children | 0f6616ef0e18 |
comparison
equal
deleted
inserted
replaced
207:fa8afbb7221b | 208:df55003e8968 |
---|---|
379 cerr << "i = " << i << ": tempo = " << lag2tempo(i) << ", weight = " << weight << endl; | 379 cerr << "i = " << i << ": tempo = " << lag2tempo(i) << ", weight = " << weight << endl; |
380 | 380 |
381 m_fr[i] = m_r[i] * (1 + weight / 3.f); | 381 m_fr[i] = m_r[i] * (1 + weight / 3.f); |
382 } | 382 } |
383 | 383 |
384 float related[4] = { 2, 3, 4 }; | 384 int related[4] = { 2, 3, 4 }; |
385 | |
386 int e = tempo2lag(60.f); | |
387 int universalDiv = (n/2 - 1) / e; | |
388 cerr << "universalDiv = " << universalDiv << endl; | |
385 | 389 |
386 for (int i = 0; i < n/2; ++i) { | 390 for (int i = 0; i < n/2; ++i) { |
387 | 391 |
388 if (i == 0 || i == n/2 - 1 || | 392 if (i == 0 || i == n/2 - 1 |
393 /* | |
394 || | |
389 !(m_fr[i] > m_fr[i-1] && | 395 !(m_fr[i] > m_fr[i-1] && |
390 m_fr[i] >= m_fr[i+1])) { | 396 m_fr[i] >= m_fr[i+1]) |
397 */ | |
398 ) { | |
391 continue; | 399 continue; |
392 } | 400 } |
393 | 401 |
394 int div = 1; | 402 int div = 1; |
395 | 403 |
411 | 419 |
412 if (k == k0 - 2 || m_r[k] < kvmin) { | 420 if (k == k0 - 2 || m_r[k] < kvmin) { |
413 kmin = k; | 421 kmin = k; |
414 kvmin = m_r[k]; | 422 kvmin = m_r[k]; |
415 } | 423 } |
424 } | |
425 | |
426 if (related[j] <= universalDiv) { | |
427 // m_fr[i] += m_fr[kmax]; //!!! | |
428 m_fr[i] += m_r[kmax] / related[j]; | |
416 } | 429 } |
417 | 430 |
418 if (m_r[kmax] > m_r[kmax-1] && | 431 if (m_r[kmax] > m_r[kmax-1] && |
419 m_r[kmax] > m_r[kmax+1] && | 432 m_r[kmax] > m_r[kmax+1] && |
420 kvmax > kvmin * 1.05) { | 433 kvmax > kvmin * 1.05) { |
433 // cerr << "adjusting tempo from " << lag2tempo(i) << " to " | 446 // cerr << "adjusting tempo from " << lag2tempo(i) << " to " |
434 // << m_t[i] << endl; | 447 // << m_t[i] << endl; |
435 // } | 448 // } |
436 } | 449 } |
437 | 450 |
451 /* | |
438 int e = tempo2lag(60.f); | 452 int e = tempo2lag(60.f); |
439 int div = (n/2 - 1) / e; | 453 int div = (n/2 - 1) / e; |
440 | 454 |
441 // cerr << "e = " << e << ", n/2 = " << n/2 << ", div = " << div << endl; | 455 // cerr << "e = " << e << ", n/2 = " << n/2 << ", div = " << div << endl; |
442 if (div > 1) { | 456 if (div > 1) { |
444 for (int i = 1; i <= e; ++i) { | 458 for (int i = 1; i <= e; ++i) { |
445 m_fr[i] += m_fr[i * j] * (1.f / j); | 459 m_fr[i] += m_fr[i * j] * (1.f / j); |
446 } | 460 } |
447 } | 461 } |
448 } | 462 } |
449 | 463 */ |
450 // cerr << "i = " << i << ", (n/2 - 1)/i = " << (n/2 - 1)/i << ", sum = " << m_fr[i] << ", div = " << div << ", val = " << m_fr[i] / div << ", t = " << lag2tempo(i) << endl; | 464 // cerr << "i = " << i << ", (n/2 - 1)/i = " << (n/2 - 1)/i << ", sum = " << m_fr[i] << ", div = " << div << ", val = " << m_fr[i] / div << ", t = " << lag2tempo(i) << endl; |
451 | 465 |
452 | 466 |
453 // } | 467 // } |
454 | 468 |
472 char buffer[40]; | 486 char buffer[40]; |
473 | 487 |
474 int n = m_n; | 488 int n = m_n; |
475 | 489 |
476 for (int i = 0; i < n; ++i) { | 490 for (int i = 0; i < n; ++i) { |
477 feature.timestamp = RealTime::frame2RealTime(i * m_stepSize, | 491 feature.timestamp = m_start + |
478 m_inputSampleRate); | 492 RealTime::frame2RealTime(i * m_stepSize, m_inputSampleRate); |
479 feature.values[0] = m_df[i]; | 493 feature.values[0] = m_df[i]; |
480 feature.label = ""; | 494 feature.label = ""; |
481 fs[DFOutput].push_back(feature); | 495 fs[DFOutput].push_back(feature); |
482 } | 496 } |
483 | 497 |
484 for (int i = 1; i < n/2; ++i) { | 498 for (int i = 1; i < n/2; ++i) { |
485 feature.timestamp = RealTime::frame2RealTime(i * m_stepSize, | 499 feature.timestamp = m_start + |
486 m_inputSampleRate); | 500 RealTime::frame2RealTime(i * m_stepSize, m_inputSampleRate); |
487 feature.values[0] = m_r[i]; | 501 feature.values[0] = m_r[i]; |
488 sprintf(buffer, "%.1f bpm", lag2tempo(i)); | 502 sprintf(buffer, "%.1f bpm", lag2tempo(i)); |
489 if (i == n/2-1) feature.label = ""; | 503 if (i == n/2-1) feature.label = ""; |
490 else feature.label = buffer; | 504 else feature.label = buffer; |
491 fs[ACFOutput].push_back(feature); | 505 fs[ACFOutput].push_back(feature); |
509 | 523 |
510 for (int i = p0; i <= p1 && i < n/2-1; ++i) { | 524 for (int i = p0; i <= p1 && i < n/2-1; ++i) { |
511 | 525 |
512 candidates[m_fr[i]] = i; | 526 candidates[m_fr[i]] = i; |
513 | 527 |
514 feature.timestamp = RealTime::frame2RealTime(i * m_stepSize, | 528 feature.timestamp = m_start + |
515 m_inputSampleRate); | 529 RealTime::frame2RealTime(i * m_stepSize, m_inputSampleRate); |
516 feature.values[0] = m_fr[i]; | 530 feature.values[0] = m_fr[i]; |
517 sprintf(buffer, "%.1f bpm", lag2tempo(i)); | 531 sprintf(buffer, "%.1f bpm", lag2tempo(i)); |
518 if (i == p1 || i == n/2-2) feature.label = ""; | 532 if (i == p1 || i == n/2-2) feature.label = ""; |
519 else feature.label = buffer; | 533 else feature.label = buffer; |
520 fs[FilteredACFOutput].push_back(feature); | 534 fs[FilteredACFOutput].push_back(feature); |