Mercurial > hg > silvet
comparison src/Silvet.cpp @ 317:92293058368a livemode
Some small speed improvements for live mode (+ don't use async for it when there's only one template in the EM process: the overhead isn't worth it)
author | Chris Cannam |
---|---|
date | Tue, 28 Apr 2015 13:55:32 +0100 |
parents | f3e10617a60d |
children | c37da62ba4e5 8f5cfd7dbaa5 |
comparison
equal
deleted
inserted
replaced
316:f3e10617a60d | 317:92293058368a |
---|---|
503 // flaw in the CQ parameter calculations, must check. For | 503 // flaw in the CQ parameter calculations, must check. For |
504 // atomHopFactor == 1, q == 0.8 is fine | 504 // atomHopFactor == 1, q == 0.8 is fine |
505 params.q = (m_mode == HighQualityMode ? 0.95 : 0.8); | 505 params.q = (m_mode == HighQualityMode ? 0.95 : 0.8); |
506 params.atomHopFactor = (m_mode == HighQualityMode ? 0.3 : 1.0); | 506 params.atomHopFactor = (m_mode == HighQualityMode ? 0.3 : 1.0); |
507 params.threshold = 0.0005; | 507 params.threshold = 0.0005; |
508 params.decimator = | |
509 (m_mode == LiveMode ? | |
510 CQParameters::FasterDecimator : CQParameters::BetterDecimator); | |
508 params.window = CQParameters::Hann; | 511 params.window = CQParameters::Hann; |
509 | 512 |
510 m_cq = new CQSpectrogram(params, CQSpectrogram::InterpolateLinear); | 513 m_cq = new CQSpectrogram(params, CQSpectrogram::InterpolateLinear); |
511 | 514 |
512 // cerr << "CQ bins = " << m_cq->getTotalBins() << endl; | 515 // cerr << "CQ bins = " << m_cq->getTotalBins() << endl; |
651 | 654 |
652 #ifndef MAX_EM_THREADS | 655 #ifndef MAX_EM_THREADS |
653 #define MAX_EM_THREADS 8 | 656 #define MAX_EM_THREADS 8 |
654 #endif | 657 #endif |
655 | 658 |
659 int emThreadCount = MAX_EM_THREADS; | |
660 if (m_mode == LiveMode && pack.templates.size() == 1) { | |
661 // The EM step is probably not slow enough to merit it | |
662 emThreadCount = 1; | |
663 } | |
664 | |
656 #if (defined(MAX_EM_THREADS) && (MAX_EM_THREADS > 1)) | 665 #if (defined(MAX_EM_THREADS) && (MAX_EM_THREADS > 1)) |
657 for (int i = 0; i < width; ) { | 666 if (emThreadCount > 1) { |
658 typedef future<pair<vector<double>, vector<int>>> EMFuture; | 667 for (int i = 0; i < width; ) { |
659 vector<EMFuture> results; | 668 typedef future<pair<vector<double>, vector<int>>> EMFuture; |
660 for (int j = 0; j < MAX_EM_THREADS && i + j < width; ++j) { | 669 vector<EMFuture> results; |
661 results.push_back | 670 for (int j = 0; j < emThreadCount && i + j < width; ++j) { |
662 (async(std::launch::async, | 671 results.push_back |
663 [&](int index) { | 672 (async(std::launch::async, |
664 return applyEM(pack, filtered.at(index), wantShifts); | 673 [&](int index) { |
665 }, i + j)); | 674 return applyEM(pack, filtered.at(index), wantShifts); |
666 } | 675 }, i + j)); |
667 for (int j = 0; j < MAX_EM_THREADS && i + j < width; ++j) { | 676 } |
668 auto out = results[j].get(); | 677 for (int j = 0; j < emThreadCount && i + j < width; ++j) { |
669 localPitches[i+j] = out.first; | 678 auto out = results[j].get(); |
670 if (wantShifts) localBestShifts[i+j] = out.second; | 679 localPitches[i+j] = out.first; |
671 } | 680 if (wantShifts) localBestShifts[i+j] = out.second; |
672 i += MAX_EM_THREADS; | 681 } |
673 } | 682 i += emThreadCount; |
674 #else | 683 } |
675 for (int i = 0; i < width; ++i) { | |
676 auto out = applyEM(pack, filtered.at(i), wantShifts); | |
677 localPitches[i] = out.first; | |
678 if (wantShifts) localBestShifts[i] = out.second; | |
679 } | 684 } |
680 #endif | 685 #endif |
686 | |
687 if (emThreadCount == 1) { | |
688 for (int i = 0; i < width; ++i) { | |
689 auto out = applyEM(pack, filtered.at(i), wantShifts); | |
690 localPitches[i] = out.first; | |
691 if (wantShifts) localBestShifts[i] = out.second; | |
692 } | |
693 } | |
681 | 694 |
682 for (int i = 0; i < width; ++i) { | 695 for (int i = 0; i < width; ++i) { |
683 | 696 |
684 // This returns a filtered column, and pushes the | 697 // This returns a filtered column, and pushes the |
685 // up-to-max-polyphony activation column to m_pianoRoll | 698 // up-to-max-polyphony activation column to m_pianoRoll |