diff --git a/src/engine/dispatchContainer.cpp b/src/engine/dispatchContainer.cpp index 827e9c32e..80ab61927 100644 --- a/src/engine/dispatchContainer.cpp +++ b/src/engine/dispatchContainer.cpp @@ -173,12 +173,12 @@ void DivDispatchContainer::acquire(size_t offset, size_t count) { } } -void DivDispatchContainer::flush(size_t count) { +void DivDispatchContainer::flush(size_t offset, size_t count) { int outs=dispatch->getOutputCount(); for (int i=0; i>12; + filter[outIndex][1]+=(filtConst*(filter[outIndex][0]-filter[outIndex][1]))>>12; + buf[i]=filter[outIndex][1]; + } } void DivPlatformAmiga::irq(int ch) { diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 5a7461a74..c58075c25 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -26,8 +26,6 @@ #include "../ta-log.h" #include -constexpr int MASTER_CLOCK_PREC=(sizeof(void*)==8)?8:0; - void DivEngine::nextOrder() { curRow=0; if (repeatPattern) return; @@ -992,7 +990,7 @@ void DivEngine::processRow(int i, bool afterDelay) { case 0xc0: case 0xc1: case 0xc2: case 0xc3: // set Hz divider=(double)(((effect&0x3)<<8)|effectVal); if (divider<1) divider=1; - cycles=got.rate*pow(2,MASTER_CLOCK_PREC)/divider; + cycles=got.rate/divider; clockDrift=0; subticks=0; break; @@ -1146,7 +1144,7 @@ void DivEngine::processRow(int i, bool afterDelay) { case 0xf0: // set Hz by tempo divider=(double)effectVal*2.0/5.0; if (divider<1) divider=1; - cycles=got.rate*pow(2,MASTER_CLOCK_PREC)/divider; + cycles=got.rate/divider; clockDrift=0; subticks=0; break; @@ -1551,8 +1549,8 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) { tickMult=1; } - cycles=got.rate*pow(2,MASTER_CLOCK_PREC)/(divider*tickMult); - clockDrift+=fmod(got.rate*pow(2,MASTER_CLOCK_PREC),(double)(divider*tickMult)); + cycles=got.rate/(divider*tickMult); + clockDrift+=fmod(got.rate,(double)(divider*tickMult)); if (clockDrift>=(divider*tickMult)) { clockDrift-=(divider*tickMult); cycles++; @@ -2027,7 +2025,7 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) { } int DivEngine::getBufferPos() { - return bufferPos>>MASTER_CLOCK_PREC; + return bufferPos; } void DivEngine::runMidiClock(int totalCycles) { @@ -2053,10 +2051,10 @@ void DivEngine::runMidiClock(int totalCycles) { if (vD<1) vD=1; double bpm=((24.0*divider)/(timeBase*hl*speedSum))*(double)virtualTempoN/vD; if (bpm<1.0) bpm=1.0; - int increment=got.rate*pow(2,MASTER_CLOCK_PREC)/(bpm); + int increment=got.rate/(bpm); midiClockCycles+=increment; - midiClockDrift+=fmod(got.rate*pow(2,MASTER_CLOCK_PREC),(double)(bpm)); + midiClockDrift+=fmod(got.rate,(double)(bpm)); if (midiClockDrift>=(bpm)) { midiClockDrift-=(bpm); midiClockCycles++; @@ -2164,8 +2162,8 @@ void DivEngine::runMidiTime(int totalCycles) { } curMidiTimePiece=(curMidiTimePiece+1)&7; - midiTimeCycles+=got.rate*pow(2,MASTER_CLOCK_PREC)/(frameRate); - midiTimeDrift+=fmod(got.rate*pow(2,MASTER_CLOCK_PREC),(double)(frameRate)); + midiTimeCycles+=got.rate/(frameRate); + midiTimeDrift+=fmod(got.rate,(double)(frameRate)); if (midiTimeDrift>=(frameRate)) { midiTimeDrift-=(frameRate); midiTimeCycles++; @@ -2428,21 +2426,6 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi if (mustPlay) { // logic starts here for (int i=0; i0) { - disCont[i].flush(disCont[i].lastAvail); - } - if (sizedisCont[i].bbInLen) { - logD("growing dispatch %d bbIn to %d",i,disCont[i].runtotal+256); - disCont[i].grow(disCont[i].runtotal+256); - } - disCont[i].runLeft=disCont[i].runtotal; disCont[i].runPos=0; } @@ -2455,10 +2438,10 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi memset(metroTick,0,size); int attempts=0; - int runLeftG=size<>MASTER_CLOCK_PREC); + lastLoopPos=size-runLeftG; logD("last loop pos: %d for a size of %d and runLeftG of %d",lastLoopPos,size,runLeftG); totalLoops++; if (remainingLoops>0) { @@ -2487,7 +2470,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi } } if (pendingMetroTick) { - unsigned int realPos=size-(runLeftG>>MASTER_CLOCK_PREC); + unsigned int realPos=size-runLeftG; if (realPos>=size) realPos=size-1; metroTick[realPos]=pendingMetroTick; pendingMetroTick=0; @@ -2502,30 +2485,70 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi // 5. tick the clock and fill buffers as needed if (cyclespush([](void* d) { DivDispatchContainer* dc=(DivDispatchContainer*)d; - int total=(dc->cycles*dc->runtotal)/(dc->size<acquire(dc->runPos,total); - dc->runLeft-=total; - dc->runPos+=total; + + int lastAvail=blip_samples_avail(dc->bb[0]); + if (lastAvail>0) { + if (lastAvail>=dc->cycles) { + dc->flush(dc->runPos,dc->cycles); + dc->runPos+=dc->cycles; + return; + } else { + dc->flush(dc->runPos,lastAvail); + dc->runPos+=lastAvail; + dc->cycles-=lastAvail; + } + } + + int total=blip_clocks_needed(dc->bb[0],dc->cycles); + if (total>(int)dc->bbInLen) { + logD("growing dispatch %p bbIn to %d",(void*)dc,total+256); + dc->grow(total+256); + } + dc->acquire(0,total); + dc->fillBuf(total,dc->runPos,dc->cycles); + dc->runPos+=dc->cycles; },&disCont[i]); } renderPool->wait(); runLeftG-=cycles; cycles=0; } else { + // run until the end of this audio buffer cycles-=runLeftG; - runLeftG=0; for (int i=0; ipush([](void* d) { DivDispatchContainer* dc=(DivDispatchContainer*)d; - dc->acquire(dc->runPos,dc->runLeft); - dc->runLeft=0; + + int lastAvail=blip_samples_avail(dc->bb[0]); + if (lastAvail>0) { + if (lastAvail>=dc->cycles) { + dc->flush(dc->runPos,dc->cycles); + dc->runPos+=dc->cycles; + return; + } else { + dc->flush(dc->runPos,lastAvail); + dc->runPos+=lastAvail; + dc->cycles-=lastAvail; + } + } + + int total=blip_clocks_needed(dc->bb[0],dc->cycles); + if (total>(int)dc->bbInLen) { + logD("growing dispatch %p bbIn to %d",(void*)dc,total+256); + dc->grow(total+256); + } + dc->acquire(0,total); + dc->fillBuf(total,dc->runPos,dc->cycles); },&disCont[i]); } + runLeftG=0; renderPool->wait(); } } @@ -2538,7 +2561,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi playing=false; extValuePresent=false; } - totalProcessed=size-(runLeftG>>MASTER_CLOCK_PREC); + totalProcessed=size-runLeftG; for (int i=0; ipush([](void* d) { DivDispatchContainer* dc=(DivDispatchContainer*)d; dc->fillBuf(dc->runtotal,dc->lastAvail,dc->size-dc->lastAvail); - },&disCont[i]); + },&disCont[i]);*/ } renderPool->wait(); } diff --git a/src/gui/debug.cpp b/src/gui/debug.cpp index e5a1525c7..22b6dd8c0 100644 --- a/src/gui/debug.cpp +++ b/src/gui/debug.cpp @@ -553,9 +553,12 @@ void putDispatchChip(void* data, int type) { COMMON_CHIP_DEBUG_BOOL; break; } - default: + default: { + DivDispatch* ch=(DivDispatch*)data; + COMMON_CHIP_DEBUG; ImGui::Text("Unimplemented chip! Help!"); break; + } } } void putDispatchChan(void* data, int chanNum, int type) {