From cd739f5fdede9ad3914b77aab0378586aa156082 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 12 Jan 2022 17:45:07 -0500 Subject: [PATCH] change master clock to sampleRate*256 this hopefully fixes the hang by doing all clock ops on a master clock rather than one clock per system --- src/engine/engine.cpp | 27 ++++++------- src/engine/engine.h | 9 ++--- src/engine/playback.cpp | 84 +++++++++++++---------------------------- 3 files changed, 42 insertions(+), 78 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index ecfa1bcf2..d74dcbf34 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -2225,12 +2225,10 @@ void DivEngine::playSub(bool preserveDrift) { int goal=curOrder; curOrder=0; curRow=0; - int prevDrift[32]; - for (int i=0; iforceIns(); } repeatPattern=oldRepeatPattern; - for (int i=0; isetPAL((!song.pal) || (song.customTempo!=0 && song.hz<53)); disCont[i].setRates(got.rate); - disCont[i].clockDrift=0; } divider=60; if (song.customTempo) { @@ -2896,9 +2891,9 @@ void DivEngine::quitDispatch() { isBusy.lock(); for (int i=0; irate/divider; - disCont[i].clockDrift=0; - } + cycles=((int)(got.rate)<<8)/divider; + clockDrift=0; break; case 0xc4: // set Hz by tempo // TODO @@ -701,14 +699,11 @@ bool DivEngine::nextTick(bool noAccum) { bool ret=false; if (divider<10) divider=10; - for (int i=0; irate/divider; - dc.clockDrift+=dc.dispatch->rate%divider; - if (dc.clockDrift>=divider) { - dc.clockDrift-=divider; - dc.cycles++; - } + cycles=((int)(got.rate)<<8)/divider; + clockDrift+=((int)(got.rate)<<8)%divider; + if (clockDrift>=divider) { + clockDrift-=divider; + cycles++; } while (!pendingNotes.empty()) { @@ -899,37 +894,14 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi memset(metroTick,0,size); int attempts=0; - logI("--------\n"); + int runLeftG=size<<8; while (++attempts<100) { - logI("ATTEMPT %d\n",attempts); - bool allDone=true; - bool getOut=true; // 1. check whether we are done with all buffers - for (int i=0; i0) { - getOut=false; - logD("no getOut because runLeft[%d]=%d\n",i,runLeft[i]); - break; - } - } - if (getOut) { - logD("GETTING OUT\n"); - break; - } + if (runLeftG<=0) break; // 2. check whether we gonna tick - for (int i=0; i0) { - allDone=false; - logD("not allDone because disCont[%d].cycles=%d\n",i,disCont[i].cycles); - break; - } - } - if (allDone) { + if (cycles<=0) { // we have to tick - logD("ticking\n"); unsigned int realPos=(runPos[0]*size)/runtotal[0]; if (realPos>=size) realPos=size-1; if (song.hilightA>0) { @@ -944,27 +916,25 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi if (!remainingLoops) logI("end of song!\n"); } } - } - - // 3. fill buffers as needed - for (int i=0; idisCont[i].cycles) { - logD("total set to cycles: %d\n",disCont[i].cycles); - total=disCont[i].cycles; + } else { + // 3. tick the clock and fill buffers as needed + if (cycles