From 986b64bbf04b02bb89a844d562897e607c22f5c9 Mon Sep 17 00:00:00 2001 From: LTVA1 <87536432+LTVA1@users.noreply.github.com> Date: Sun, 4 Aug 2024 12:19:33 +0300 Subject: [PATCH] better phase mod accuracy, optimized panning reg writes --- src/engine/platform/sid3.cpp | 11 +++++++++-- src/engine/platform/sound/sid3.c | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/engine/platform/sid3.cpp b/src/engine/platform/sid3.cpp index 8b14febd2..b41ff8a3b 100644 --- a/src/engine/platform/sid3.cpp +++ b/src/engine/platform/sid3.cpp @@ -94,7 +94,7 @@ void DivPlatformSID3::acquire(short** buf, size_t len) for(int j = 0; j < SID3_NUM_CHANNELS; j++) { - oscBuf[j]->data[oscBuf[j]->needle++] = sid3->muted[j] ? 0 : sid3->channel_output[j]; + oscBuf[j]->data[oscBuf[j]->needle++] = sid3->muted[j] ? 0 : (sid3->channel_output[j] / 4); } } } @@ -169,6 +169,8 @@ void DivPlatformSID3::tick(bool sysTick) { chan[i].std.next(); + bool panChanged = false; + if (chan[i].std.vol.had) { chan[i].outVol=VOL_SCALE_LINEAR(chan[i].vol&255,MIN(255,chan[i].std.vol.val),255); @@ -202,11 +204,16 @@ void DivPlatformSID3::tick(bool sysTick) updateDuty(i); } if (chan[i].std.panL.had) { + panChanged = true; chan[i].panLeft = chan[i].std.panL.val & 0xff; - updatePanning(i); } if (chan[i].std.panR.had) { + panChanged = true; chan[i].panRight = chan[i].std.panR.val & 0xff; + } + + if(panChanged) + { updatePanning(i); } diff --git a/src/engine/platform/sound/sid3.c b/src/engine/platform/sound/sid3.c index cec277ab2..bd343cc53 100644 --- a/src/engine/platform/sound/sid3.c +++ b/src/engine/platform/sound/sid3.c @@ -2494,7 +2494,7 @@ void sid3_adsr_clock(sid3_channel_adsr* adsr) int32_t sid3_adsr_output(sid3_channel_adsr* adsr, int32_t input) { - return (int32_t)((int64_t)input * (int64_t)adsr->envelope_counter / (int64_t)0xff0000 / (int64_t)8 * (int64_t)adsr->vol / (int64_t)SID3_MAX_VOL); //"/ (int64_t)8" so that there's enough amplitude for all 7 chans! + return (int32_t)((int64_t)input * (int64_t)adsr->envelope_counter / (int64_t)0xff0000 * (int64_t)adsr->vol / (int64_t)SID3_MAX_VOL); } void sid3_set_filter_settings(sid3_filter* filt) @@ -2931,7 +2931,7 @@ void sid3_clock(SID3* sid3) if(ch->flags & SID3_CHAN_ENABLE_PHASE_MOD) { - ch->accumulator += ch->phase_mod_source == SID3_NUM_CHANNELS - 1 ? ((uint64_t)sid3->wave_channel_output << 19) : ((uint64_t)sid3->channel_output[ch->phase_mod_source] << 19); + ch->accumulator += ch->phase_mod_source == SID3_NUM_CHANNELS - 1 ? ((uint64_t)sid3->wave_channel_output << 18) : ((uint64_t)sid3->channel_output[ch->phase_mod_source] << 18); } ch->accumulator &= SID3_ACC_MASK; @@ -2972,8 +2972,8 @@ void sid3_clock(SID3* sid3) if(!sid3->muted[i]) { - sid3->output_l += output * ch->panning_left / 0xff; - sid3->output_r += output * ch->panning_right / 0xff; + sid3->output_l += output * ch->panning_left / 0x8f0; + sid3->output_r += output * ch->panning_right / 0x8f0; } sid3->channel_output[i] = output;