From 41e59cee5f0e13e0f960b9d15e03e1e802ef5c35 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 23 Apr 2024 19:55:17 -0500 Subject: [PATCH] Dave: implement sample offset --- src/engine/platform/dave.cpp | 18 +++++++++++++++--- src/engine/platform/dave.h | 5 +++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/engine/platform/dave.cpp b/src/engine/platform/dave.cpp index 92e03c482..b84ebb61e 100644 --- a/src/engine/platform/dave.cpp +++ b/src/engine/platform/dave.cpp @@ -70,7 +70,7 @@ void DivPlatformDave::acquire(short** buf, size_t len) { chan[i].dacPeriod+=chan[i].dacRate; while (chan[i].dacPeriod>rate) { DivSample* s=parent->getSample(chan[i].dacSample); - if (s->samples<=0) { + if (s->samples<=0 || chan[i].dacPos>=s->samples) { chan[i].dacSample=-1; writeControl=true; chan[0].writeVol=true; @@ -196,7 +196,11 @@ void DivPlatformDave::tick(bool sysTick) { if (chan[i].std.phaseReset.had && chan[i].std.phaseReset.val==1) { if (i>=4) { if (chan[i].active && chan[i].dacSample>=0 && chan[i].dacSamplesong.sampleLen) { - chan[i].dacPos=0; + if (chan[i].setPos) { + chan[i].setPos=false; + } else { + chan[i].dacPos=0; + } chan[i].dacPeriod=0; chan[i].keyOn=true; } @@ -324,7 +328,11 @@ int DivPlatformDave::dispatch(DivCommand c) { chan[c.chan].freqChanged=true; chan[c.chan].note=c.value; } - chan[c.chan].dacPos=0; + if (chan[c.chan].setPos) { + chan[c.chan].setPos=false; + } else { + chan[c.chan].dacPos=0; + } chan[c.chan].dacPeriod=0; writeControl=true; } else { @@ -459,6 +467,10 @@ int DivPlatformDave::dispatch(DivCommand c) { if (!chan[c.chan].inPorta && c.value && !parent->song.brokenPortaArp && chan[c.chan].std.arp.will && !NEW_ARP_STRAT) chan[c.chan].baseFreq=NOTE_PERIODIC(chan[c.chan].note); chan[c.chan].inPorta=c.value; break; + case DIV_CMD_SAMPLE_POS: + chan[c.chan].dacPos=c.value; + chan[c.chan].setPos=true; + break; case DIV_CMD_GET_VOLMAX: return 63; break; diff --git a/src/engine/platform/dave.h b/src/engine/platform/dave.h index 3b0183d3b..b232218be 100644 --- a/src/engine/platform/dave.h +++ b/src/engine/platform/dave.h @@ -33,7 +33,7 @@ class DivPlatformDave: public DivDispatch { unsigned char panL; unsigned char panR; unsigned char wave; - bool writeVol, highPass, ringMod, swapCounters, lowPass, resetPhase; + bool writeVol, highPass, ringMod, swapCounters, lowPass, resetPhase, setPos; Channel(): SharedChannel(63), dacPeriod(0), @@ -50,7 +50,8 @@ class DivPlatformDave: public DivDispatch { ringMod(false), swapCounters(false), lowPass(false), - resetPhase(false) {} + resetPhase(false), + setPos(false) {} }; Channel chan[6]; DivDispatchOscBuffer* oscBuf[6];