diff --git a/src/engine/platform/pcspkr.cpp b/src/engine/platform/pcspkr.cpp index 593c41b8a..bd49c9e68 100644 --- a/src/engine/platform/pcspkr.cpp +++ b/src/engine/platform/pcspkr.cpp @@ -373,6 +373,9 @@ void DivPlatformPCSpeaker::tick(bool sysTick) { if (chan[i].keyOff) { on=false; } + if (freq!=chan[i].freq && resetPhase) { + pos=0; + } freq=chan[i].freq; if (chan[i].keyOn) chan[i].keyOn=false; if (chan[i].keyOff) chan[i].keyOff=false; @@ -610,6 +613,7 @@ void DivPlatformPCSpeaker::setFlags(const DivConfig& flags) { CHECK_CUSTOM_CLOCK; rate=chipClock/PCSPKR_DIVIDER; speakerType=flags.getInt("speakerType",0)&3; + resetPhase=flags.getBool("resetPhase",false); oscBuf->rate=rate; switch (speakerType) { diff --git a/src/engine/platform/pcspkr.h b/src/engine/platform/pcspkr.h index b1a394444..758111259 100644 --- a/src/engine/platform/pcspkr.h +++ b/src/engine/platform/pcspkr.h @@ -51,7 +51,7 @@ class DivPlatformPCSpeaker: public DivDispatch { FixedQueue realQueue; std::mutex realQueueLock; bool isMuted[1]; - bool on, flip, lastOn, realOutEnabled; + bool on, flip, lastOn, realOutEnabled, resetPhase; int pos, speakerType, beepFD, realOutMethod; float low, band; float low2, high2, band2; diff --git a/src/gui/sysConf.cpp b/src/gui/sysConf.cpp index 99baf47e4..f7ef4b925 100644 --- a/src/gui/sysConf.cpp +++ b/src/gui/sysConf.cpp @@ -997,6 +997,7 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl case DIV_SYSTEM_PCSPKR: { int clockSel=flags.getInt("clockSel",0); int speakerType=flags.getInt("speakerType",0); + bool resetPhase=flags.getBool("resetPhase",false); ImGui::Text("Clock rate:"); ImGui::Indent(); @@ -1034,10 +1035,15 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl } ImGui::Unindent(); + if (ImGui::Checkbox("Reset phase on frequency change",&resetPhase)) { + altered=true; + } + if (altered) { e->lockSave([&]() { flags.set("clockSel",clockSel); flags.set("speakerType",speakerType); + flags.set("resetPhase",resetPhase); }); } break;