Mercurial > hg > silvet
comparison src/Silvet.cpp @ 312:796d403dc83b
Replace OpenMP usage with (hopefully more portable) C++11 async. Define MAX_EM_THREADS=1 if you don't want to use it.
author | Chris Cannam |
---|---|
date | Tue, 28 Apr 2015 10:02:36 +0100 |
parents | 99af9557dfc1 |
children | fa2ffbb786df |
comparison
equal
deleted
inserted
replaced
311:99af9557dfc1 | 312:796d403dc83b |
---|---|
21 #include "MedianFilter.h" | 21 #include "MedianFilter.h" |
22 #include "constant-q-cpp/src/dsp/Resampler.h" | 22 #include "constant-q-cpp/src/dsp/Resampler.h" |
23 #include "flattendynamics-ladspa.h" | 23 #include "flattendynamics-ladspa.h" |
24 | 24 |
25 #include <vector> | 25 #include <vector> |
26 #include <future> | |
26 | 27 |
27 #include <cstdio> | 28 #include <cstdio> |
28 | 29 |
29 using std::vector; | 30 using std::vector; |
30 using std::cout; | 31 using std::cout; |
31 using std::cerr; | 32 using std::cerr; |
32 using std::endl; | 33 using std::endl; |
33 using std::pair; | 34 using std::pair; |
35 using std::future; | |
36 using std::async; | |
34 using Vamp::RealTime; | 37 using Vamp::RealTime; |
35 | 38 |
36 static int processingSampleRate = 44100; | 39 static int processingSampleRate = 44100; |
37 static int processingBPO = 60; | 40 static int processingBPO = 60; |
38 | 41 |
553 vector<vector<int> > localBestShifts; | 556 vector<vector<int> > localBestShifts; |
554 if (wantShifts) { | 557 if (wantShifts) { |
555 localBestShifts = vector<vector<int> >(width); | 558 localBestShifts = vector<vector<int> >(width); |
556 } | 559 } |
557 | 560 |
561 #ifndef MAX_EM_THREADS | |
562 #define MAX_EM_THREADS 8 | |
563 #endif | |
564 | |
565 #if (defined(MAX_EM_THREADS) && (MAX_EM_THREADS > 1)) | |
566 for (int i = 0; i < width; ) { | |
567 typedef future<pair<vector<double>, vector<int>>> EMFuture; | |
568 vector<EMFuture> results; | |
569 for (int j = 0; j < MAX_EM_THREADS && i + j < width; ++j) { | |
570 results.push_back | |
571 (async(std::launch::async, | |
572 [&](int index) { | |
573 return applyEM(pack, filtered.at(index), wantShifts); | |
574 }, i + j)); | |
575 } | |
576 for (int j = 0; j < MAX_EM_THREADS && i + j < width; ++j) { | |
577 auto out = results[j].get(); | |
578 localPitches[i+j] = out.first; | |
579 if (wantShifts) localBestShifts[i+j] = out.second; | |
580 } | |
581 i += MAX_EM_THREADS; | |
582 } | |
583 #else | |
558 for (int i = 0; i < width; ++i) { | 584 for (int i = 0; i < width; ++i) { |
559 auto out = applyEM(pack, filtered.at(i), wantShifts); | 585 auto out = applyEM(pack, filtered.at(i), wantShifts); |
560 localPitches[i] = out.first; | 586 localPitches[i] = out.first; |
561 if (wantShifts) localBestShifts[i] = out.second; | 587 if (wantShifts) localBestShifts[i] = out.second; |
562 } | 588 } |
563 | 589 #endif |
590 | |
564 for (int i = 0; i < width; ++i) { | 591 for (int i = 0; i < width; ++i) { |
565 | 592 |
566 // This returns a filtered column, and pushes the | 593 // This returns a filtered column, and pushes the |
567 // up-to-max-polyphony activation column to m_pianoRoll | 594 // up-to-max-polyphony activation column to m_pianoRoll |
568 vector<double> filtered = postProcess | 595 vector<double> filtered = postProcess |