Mercurial > hg > tuning-difference
comparison chroma-compare-plugin/TuningDifference.cpp @ 19:9c5ec36c223e
Return values through plugin outputs
author | Chris Cannam |
---|---|
date | Thu, 05 Feb 2015 09:43:31 +0000 |
parents | c40c58215162 |
children | 331a520cdadb |
comparison
equal
deleted
inserted
replaced
18:c40c58215162 | 19:9c5ec36c223e |
---|---|
376 | 376 |
377 cerr << "best is " << best << endl; | 377 cerr << "best is " << best << endl; |
378 return best; | 378 return best; |
379 } | 379 } |
380 | 380 |
381 double | 381 pair<int, double> |
382 TuningDifference::findFineFrequency(int coarseCents, double coarseScore) | 382 TuningDifference::findFineFrequency(int coarseCents, double coarseScore) |
383 { | 383 { |
384 int coarseResolution = 1200 / m_bpo; | 384 int coarseResolution = 1200 / m_bpo; |
385 int searchDistance = coarseResolution/2 - 1; | 385 int searchDistance = coarseResolution/2 - 1; |
386 | 386 |
387 double bestScore = coarseScore; | 387 double bestScore = coarseScore; |
388 int bestCents = coarseCents; | |
388 double bestHz = frequencyForCentsAbove440(coarseCents); | 389 double bestHz = frequencyForCentsAbove440(coarseCents); |
389 | 390 |
390 cerr << "corresponding coarse Hz " << bestHz << " scores " << coarseScore << endl; | 391 cerr << "corresponding coarse Hz " << bestHz << " scores " << coarseScore << endl; |
391 cerr << "searchDistance = " << searchDistance << endl; | 392 cerr << "searchDistance = " << searchDistance << endl; |
392 | 393 |
406 << " (best score so far " << bestScore << ")" << endl; | 407 << " (best score so far " << bestScore << ")" << endl; |
407 | 408 |
408 if (fineScore < bestScore) { | 409 if (fineScore < bestScore) { |
409 cerr << "is good!" << endl; | 410 cerr << "is good!" << endl; |
410 bestScore = fineScore; | 411 bestScore = fineScore; |
412 bestCents = fineCents; | |
411 bestHz = fineHz; | 413 bestHz = fineHz; |
412 } else { | 414 } else { |
413 break; | 415 break; |
414 } | 416 } |
415 } | 417 } |
416 } | 418 } |
417 | 419 |
418 return bestHz; | 420 return pair<int, double>(bestCents, bestHz); |
419 } | 421 } |
420 | 422 |
421 TuningDifference::FeatureSet | 423 TuningDifference::FeatureSet |
422 TuningDifference::getRemainingFeatures() | 424 TuningDifference::getRemainingFeatures() |
423 { | 425 { |
448 TFeature coarseFeature = computeFeatureFromSignal(m_other, coarseHz); | 450 TFeature coarseFeature = computeFeatureFromSignal(m_other, coarseHz); |
449 double coarseScore = featureDistance(coarseFeature); | 451 double coarseScore = featureDistance(coarseFeature); |
450 | 452 |
451 cerr << "corresponding Hz " << coarseHz << " scores " << coarseScore << endl; | 453 cerr << "corresponding Hz " << coarseHz << " scores " << coarseScore << endl; |
452 | 454 |
455 //!!! This should be returning the fine chroma, not the coarse | |
453 f.values.clear(); | 456 f.values.clear(); |
454 for (auto v: coarseFeature) f.values.push_back(v); | 457 for (auto v: coarseFeature) f.values.push_back(v); |
455 fs[m_outputs["rotfeature"]].push_back(f); | 458 fs[m_outputs["rotfeature"]].push_back(f); |
456 | 459 |
457 double fineHz = findFineFrequency(coarseCents, coarseScore); | 460 pair<int, double> fine = findFineFrequency(coarseCents, coarseScore); |
458 | 461 int fineCents = fine.first; |
462 double fineHz = fine.second; | |
463 | |
464 f.values.clear(); | |
465 f.values.push_back(fineHz); | |
466 fs[m_outputs["tuningfreq"]].push_back(f); | |
467 | |
468 f.values.clear(); | |
469 f.values.push_back(fineCents); | |
470 fs[m_outputs["cents"]].push_back(f); | |
471 | |
459 cerr << "overall best Hz = " << fineHz << endl; | 472 cerr << "overall best Hz = " << fineHz << endl; |
460 | 473 |
461 return fs; | 474 return fs; |
462 } | 475 } |
463 | 476 |