From 397ab43ffd25bb213f3517518b74c8f18630507e Mon Sep 17 00:00:00 2001 From: tildearrow Date: Fri, 15 Apr 2022 01:20:09 -0500 Subject: [PATCH] C64: better muting strategy now directly inside reSID rather than in the DivDispatch fixes #285 --- src/engine/platform/c64.cpp | 24 ++++++++++++++---------- src/engine/platform/c64.h | 1 + src/engine/platform/sound/c64/sid.cc | 17 +++++++++++++++-- src/engine/platform/sound/c64/sid.h | 3 +++ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/engine/platform/c64.cpp b/src/engine/platform/c64.cpp index b7521f035..f8b014c8a 100644 --- a/src/engine/platform/c64.cpp +++ b/src/engine/platform/c64.cpp @@ -168,16 +168,16 @@ void DivPlatformC64::tick() { } if (chan[i].testWhen>0) { if (--chan[i].testWhen<1) { - if (!chan[i].resetMask && !isMuted[i]) { + if (!chan[i].resetMask) { rWrite(i*7+5,0); rWrite(i*7+6,0); - rWrite(i*7+4,(isMuted[i]?8:(chan[i].wave<<4))|8|(chan[i].ring<<2)|(chan[i].sync<<1)); + rWrite(i*7+4,(chan[i].wave<<4)|8|(chan[i].ring<<2)|(chan[i].sync<<1)); } } } if (chan[i].std.wave.had) { chan[i].wave=chan[i].std.wave.val; - rWrite(i*7+4,(isMuted[i]?8:(chan[i].wave<<4))|(chan[i].ring<<2)|(chan[i].sync<<1)|(int)(chan[i].active)); + rWrite(i*7+4,(chan[i].wave<<4)|(chan[i].ring<<2)|(chan[i].sync<<1)|(int)(chan[i].active)); } if (chan[i].std.ex1.had) { filtControl=chan[i].std.ex1.val&15; @@ -199,12 +199,12 @@ void DivPlatformC64::tick() { if (chan[i].keyOn) { rWrite(i*7+5,(chan[i].attack<<4)|(chan[i].decay)); rWrite(i*7+6,(chan[i].sustain<<4)|(chan[i].release)); - rWrite(i*7+4,(isMuted[i]?8:(chan[i].wave<<4))|(chan[i].ring<<2)|(chan[i].sync<<1)|1); + rWrite(i*7+4,(chan[i].wave<<4)|(chan[i].ring<<2)|(chan[i].sync<<1)|1); } - if (chan[i].keyOff && !isMuted[i]) { + if (chan[i].keyOff) { rWrite(i*7+5,(chan[i].attack<<4)|(chan[i].decay)); rWrite(i*7+6,(chan[i].sustain<<4)|(chan[i].release)); - rWrite(i*7+4,(isMuted[i]?8:(chan[i].wave<<4))|(chan[i].ring<<2)|(chan[i].sync<<1)|0); + rWrite(i*7+4,(chan[i].wave<<4)|(chan[i].ring<<2)|(chan[i].sync<<1)|0); } rWrite(i*7,chan[i].freq&0xff); rWrite(i*7+1,chan[i].freq>>8); @@ -330,7 +330,7 @@ int DivPlatformC64::dispatch(DivCommand c) { break; case DIV_CMD_WAVE: chan[c.chan].wave=c.value; - rWrite(c.chan*7+4,(isMuted[c.chan]?8:(chan[c.chan].wave<<4))|(chan[c.chan].ring<<2)|(chan[c.chan].sync<<1)|(int)(chan[c.chan].active)); + rWrite(c.chan*7+4,(chan[c.chan].wave<<4)|(chan[c.chan].ring<<2)|(chan[c.chan].sync<<1)|(int)(chan[c.chan].active)); break; case DIV_CMD_LEGATO: chan[c.chan].baseFreq=NOTE_FREQUENCY(c.value+((chan[c.chan].std.arp.will && !chan[c.chan].std.arp.mode)?(chan[c.chan].std.arp.val):(0))); @@ -411,11 +411,11 @@ int DivPlatformC64::dispatch(DivCommand c) { break; case 4: chan[c.chan].ring=c.value; - rWrite(c.chan*7+4,(isMuted[c.chan]?8:(chan[c.chan].wave<<4))|(chan[c.chan].ring<<2)|(chan[c.chan].sync<<1)|(int)(chan[c.chan].active)); + rWrite(c.chan*7+4,(chan[c.chan].wave<<4)|(chan[c.chan].ring<<2)|(chan[c.chan].sync<<1)|(int)(chan[c.chan].active)); break; case 5: chan[c.chan].sync=c.value; - rWrite(c.chan*7+4,(isMuted[c.chan]?8:(chan[c.chan].wave<<4))|(chan[c.chan].ring<<2)|(chan[c.chan].sync<<1)|(int)(chan[c.chan].active)); + rWrite(c.chan*7+4,(chan[c.chan].wave<<4)|(chan[c.chan].ring<<2)|(chan[c.chan].sync<<1)|(int)(chan[c.chan].active)); break; case 6: filtControl&=7; @@ -434,7 +434,7 @@ int DivPlatformC64::dispatch(DivCommand c) { void DivPlatformC64::muteChannel(int ch, bool mute) { isMuted[ch]=mute; - rWrite(ch*7+4,(isMuted[ch]?8:(chan[ch].wave<<4))|(chan[ch].ring<<2)|(chan[ch].sync<<1)|(int)(chan[ch].active)); + sid.set_is_muted(ch,mute); } void DivPlatformC64::forceIns() { @@ -475,6 +475,10 @@ int DivPlatformC64::getRegisterPoolSize() { return 32; } +bool DivPlatformC64::getDCOffRequired() { + return true; +} + void DivPlatformC64::reset() { for (int i=0; i<3; i++) { chan[i]=DivPlatformC64::Channel(); diff --git a/src/engine/platform/c64.h b/src/engine/platform/c64.h index 9045e3332..e288940e5 100644 --- a/src/engine/platform/c64.h +++ b/src/engine/platform/c64.h @@ -87,6 +87,7 @@ class DivPlatformC64: public DivDispatch { void muteChannel(int ch, bool mute); void setFlags(unsigned int flags); void notifyInsChange(int ins); + bool getDCOffRequired(); void notifyInsDeletion(void* ins); void poke(unsigned int addr, unsigned short val); void poke(std::vector& wlist); diff --git a/src/engine/platform/sound/c64/sid.cc b/src/engine/platform/sound/c64/sid.cc index 73d5c2bb3..d33a0d350 100644 --- a/src/engine/platform/sound/c64/sid.cc +++ b/src/engine/platform/sound/c64/sid.cc @@ -18,6 +18,7 @@ // --------------------------------------------------------------------------- #include "sid.h" +#include #include // ---------------------------------------------------------------------------- @@ -39,6 +40,10 @@ SID::SID() bus_value_ttl = 0; ext_in = 0; + + isMuted[0]=false; + isMuted[1]=false; + isMuted[2]=false; } @@ -51,6 +56,14 @@ SID::~SID() delete[] fir; } +// ---------------------------------------------------------------------------- +// Mute/unmute channel. +// ---------------------------------------------------------------------------- +void SID::set_is_muted(int ch, bool val) { + if (ch<0 || ch>2) return; + isMuted[ch]=val; +} + // ---------------------------------------------------------------------------- // Set chip model. @@ -626,7 +639,7 @@ void SID::clock() } // Clock filter. - filter.clock(voice[0].output(), voice[1].output(), voice[2].output(), ext_in); + filter.clock(isMuted[0]?0:voice[0].output(), isMuted[1]?0:voice[1].output(), isMuted[2]?0:voice[2].output(), ext_in); // Clock external filter. extfilt.clock(filter.output()); @@ -706,7 +719,7 @@ void SID::clock(cycle_count delta_t) // Clock filter. filter.clock(delta_t, - voice[0].output(), voice[1].output(), voice[2].output(), ext_in); + isMuted[0]?0:voice[0].output(), isMuted[1]?0:voice[1].output(), isMuted[2]?0:voice[2].output(), ext_in); // Clock external filter. extfilt.clock(delta_t, filter.output()); diff --git a/src/engine/platform/sound/c64/sid.h b/src/engine/platform/sound/c64/sid.h index 3292cd8fc..6dbe6c599 100644 --- a/src/engine/platform/sound/c64/sid.h +++ b/src/engine/platform/sound/c64/sid.h @@ -32,6 +32,7 @@ public: SID(); ~SID(); + void set_is_muted(int ch, bool val); void set_chip_model(chip_model model); void enable_filter(bool enable); void enable_external_filter(bool enable); @@ -102,6 +103,8 @@ protected: Potentiometer potx; Potentiometer poty; + bool isMuted[3]; + reg8 bus_value; cycle_count bus_value_ttl;