diff --git a/src/engine/engine.h b/src/engine/engine.h index 3a5b1b044..ba2cf567b 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -39,6 +39,8 @@ #include #include +class DivWorkPool; + #define addWarning(x) \ if (warnings.empty()) { \ warnings+=x; \ @@ -485,6 +487,8 @@ class DivEngine { size_t totalProcessed; + DivWorkPool* renderPool; + // MIDI stuff std::function midiCallback=[](const TAMidiMessage&) -> int {return -2;}; diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 270dd7f79..0b21dc57f 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -22,6 +22,7 @@ #define _USE_MATH_DEFINES #include "dispatch.h" #include "engine.h" +#include "workPool.h" #include "../ta-log.h" #include @@ -1788,6 +1789,11 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi std::chrono::steady_clock::time_point ts_processBegin=std::chrono::steady_clock::now(); + if (renderPool==NULL) { + // TODO: test this + renderPool=new DivWorkPool(0); + } + // process MIDI events (TODO: everything) if (output) if (output->midiIn) while (!output->midiIn->queue.empty()) { TAMidiMessage& msg=output->midiIn->queue.front(); @@ -2061,20 +2067,28 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi // 5. tick the clock and fill buffers as needed if (cyclespush([this,size](void* d) { + DivDispatchContainer* dc=(DivDispatchContainer*)d; + int total=(cycles*dc->runtotal)/(size<acquire(dc->runPos,total); + dc->runLeft-=total; + dc->runPos+=total; + },&disCont[i]); } + renderPool->wait(); runLeftG-=cycles; cycles=0; } else { cycles-=runLeftG; runLeftG=0; for (int i=0; ipush([](void* d) { + DivDispatchContainer* dc=(DivDispatchContainer*)d; + dc->acquire(dc->runPos,dc->runLeft); + dc->runLeft=0; + },&disCont[i]); } + renderPool->wait(); } } } diff --git a/src/engine/workPool.cpp b/src/engine/workPool.cpp index a62f4ff7a..fa67aeb50 100644 --- a/src/engine/workPool.cpp +++ b/src/engine/workPool.cpp @@ -50,7 +50,9 @@ void DivWorkThread::run() { task.func(task.funcArg); - parent->busyCount--; + if (--parent->busyCount<0) { + logE("oh no PROBLEM..."); + } parent->notify.notify_one(); } } @@ -125,8 +127,8 @@ void DivWorkPool::wait() { } // wait - while (busyCount!=0) { - if (notify.wait_for(unique,std::chrono::milliseconds(100))==std::cv_status::timeout) { + while (busyCount>0) { + if (notify.wait_for(unique,std::chrono::milliseconds(30))==std::cv_status::timeout) { logW("DivWorkPool: wait() timed out!"); } }