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
This commit is contained in:
tildearrow 2022-01-12 17:45:07 -05:00
parent fa5b99b46a
commit cd739f5fde
3 changed files with 42 additions and 78 deletions

View File

@ -2225,12 +2225,10 @@ void DivEngine::playSub(bool preserveDrift) {
int goal=curOrder;
curOrder=0;
curRow=0;
int prevDrift[32];
for (int i=0; i<song.systemLen; i++) {
prevDrift[i]=disCont[i].clockDrift;
disCont[i].clockDrift=0;
disCont[i].cycles=0;
}
int prevDrift;
prevDrift=clockDrift;
clockDrift=0;
cycles=0;
if (preserveDrift) {
endOfSong=false;
} else {
@ -2250,13 +2248,11 @@ void DivEngine::playSub(bool preserveDrift) {
for (int i=0; i<song.systemLen; i++) disCont[i].dispatch->forceIns();
}
repeatPattern=oldRepeatPattern;
for (int i=0; i<song.systemLen; i++) {
if (preserveDrift) {
disCont[i].clockDrift=prevDrift[i];
} else {
disCont[i].clockDrift=0;
disCont[i].cycles=0;
}
if (preserveDrift) {
clockDrift=prevDrift;
} else {
clockDrift=0;
cycles=0;
}
if (!preserveDrift) {
ticks=1;
@ -2846,7 +2842,6 @@ void DivEngine::setSongRate(int hz, bool pal) {
for (int i=0; i<song.systemLen; i++) {
disCont[i].dispatch->setPAL((!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; i<song.systemLen; i++) {
disCont[i].quit();
disCont[i].cycles=0;
disCont[i].clockDrift=0;
}
cycles=0;
clockDrift=0;
chans=0;
playing=false;
speedAB=false;

View File

@ -87,8 +87,6 @@ struct DivDispatchContainer {
short* bbIn[2];
short* bbOut[2];
int cycles, clockDrift;
void setRates(double gotRate);
void acquire(size_t offset, size_t count);
void fillBuf(size_t runtotal, size_t size);
@ -102,9 +100,7 @@ struct DivDispatchContainer {
temp{0,0},
prevSample{0,0},
bbIn{NULL,NULL},
bbOut{NULL,NULL},
cycles(0),
clockDrift(0) {}
bbOut{NULL,NULL} {}
};
class DivEngine {
@ -122,6 +118,7 @@ class DivEngine {
bool repeatPattern;
bool metronome;
int ticks, curRow, curOrder, remainingLoops, nextSpeed, divider;
int cycles, clockDrift;
int changeOrd, changePos, totalSeconds, totalTicks, totalTicksR, totalCmds, lastCmds, cmdsPerSecond, globalPitch;
unsigned char extValue;
unsigned char speed1, speed2;
@ -442,6 +439,8 @@ class DivEngine {
remainingLoops(-1),
nextSpeed(3),
divider(60),
cycles(0),
clockDrift(0),
changeOrd(-1),
changePos(0),
totalSeconds(0),

View File

@ -509,10 +509,8 @@ void DivEngine::processRow(int i, bool afterDelay) {
case 0xc0: case 0xc1: case 0xc2: case 0xc3: // set Hz
divider=((effect&0x3)<<8)|effectVal;
if (divider<10) divider=10;
for (int i=0; i<song.systemLen; i++) {
disCont[i].cycles=disCont[i].dispatch->rate/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; i<song.systemLen; i++) {
DivDispatchContainer& dc=disCont[i];
dc.cycles=dc.dispatch->rate/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; i<song.systemLen; i++) {
logD("runLeft[%d]=%d\n",i,runLeft[i]);
if (runLeft[i]>0) {
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; i<song.systemLen; i++) {
logD("disCont[%d].cycles=%d\n",i,disCont[i].cycles);
if (disCont[i].cycles>0) {
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; i<song.systemLen; i++) {
logD("filling buf %d...\n",i);
if (runLeft[i]<=0) {
logD("runLeft[%d]<=0\n",i,runLeft[i]);
continue;
}
int total=runLeft[i];
if (total>disCont[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<runLeftG) {
for (int i=0; i<song.systemLen; i++) {
int total=cycles*runtotal[i]/(size<<8);
disCont[i].acquire(runPos[i],total);
runLeft[i]-=total;
runPos[i]+=total;
}
runLeftG-=cycles;
cycles=0;
} else {
logD("total is %d\n",total);
cycles-=runLeftG;
runLeftG=0;
for (int i=0; i<song.systemLen; i++) {
disCont[i].acquire(runPos[i],runLeft[i]);
runLeft[i]=0;
}
}
runLeft[i]-=total;
disCont[i].cycles-=total;
disCont[i].acquire(runPos[i],total);
runPos[i]+=total;
logD("runPos is %d\n",runPos[i]);
}
}
logD("attempts: %d\n",attempts);