From 36411defd22b76cae1231896a9b4c4b6ada920f9 Mon Sep 17 00:00:00 2001 From: LTVA1 <87536432+LTVA1@users.noreply.github.com> Date: Thu, 22 Aug 2024 19:48:35 +0300 Subject: [PATCH] fix software DAC sample rate being dependent on chip clock --- src/engine/platform/sid3.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/engine/platform/sid3.cpp b/src/engine/platform/sid3.cpp index c670d3ff2..dd2cfa725 100644 --- a/src/engine/platform/sid3.cpp +++ b/src/engine/platform/sid3.cpp @@ -111,7 +111,11 @@ void DivPlatformSID3::acquire(short** buf, size_t len) int dacData=s->data16[chan[SID3_NUM_CHANNELS - 1].dacPos] + 32767; chan[SID3_NUM_CHANNELS - 1].dacOut=CLAMP(dacData,0,65535); updateSample = true; - sampleTick = 0; + + if (sampleTick > 2) + { + sampleTick = 0; + } chan[SID3_NUM_CHANNELS - 1].dacPos++; if (s->isLoopable() && chan[SID3_NUM_CHANNELS - 1].dacPos>=(unsigned int)s->loopEnd) @@ -124,6 +128,10 @@ void DivPlatformSID3::acquire(short** buf, size_t len) } chan[SID3_NUM_CHANNELS - 1].dacPeriod-=rate; } + while (chan[SID3_NUM_CHANNELS - 1].dacPeriod > rate) + { + chan[SID3_NUM_CHANNELS - 1].dacPeriod -= rate; + } } sampleTick++; @@ -711,7 +719,7 @@ void DivPlatformSID3::tick(bool sysTick) off=(double)s->centerRate/8363.0; } } - chan[i].dacRate=chan[i].freq*(off / 32.0); + chan[i].dacRate=chan[i].freq*(off / 32.0)*(double)chipClock/1000000.0; } chan[i].noiseFreqChanged = true;