From 0165a19630b518c83e0d9dea522d005f62ccde4a Mon Sep 17 00:00:00 2001 From: tildearrow Date: Fri, 10 Feb 2023 16:25:51 -0500 Subject: [PATCH] SoundUnit: change 1-bit PDM mode to 8-bit TDM --- src/engine/platform/sound/su.cpp | 49 +++++++++----------------------- src/engine/platform/sound/su.h | 2 +- src/gui/sysConf.cpp | 2 +- 3 files changed, 15 insertions(+), 38 deletions(-) diff --git a/src/engine/platform/sound/su.cpp b/src/engine/platform/sound/su.cpp index 0a0b38b45..8d5373cef 100644 --- a/src/engine/platform/sound/su.cpp +++ b/src/engine/platform/sound/su.cpp @@ -258,11 +258,17 @@ void SoundUnit::NextSample(short* l, short* r) { } // mix - tnsL=(nsL[0]+nsL[1]+nsL[2]+nsL[3]+nsL[4]+nsL[5]+nsL[6]+nsL[7])>>2; - tnsR=(nsR[0]+nsR[1]+nsR[2]+nsR[3]+nsR[4]+nsR[5]+nsR[6]+nsR[7])>>2; + if (dsOut) { + tnsL=nsL[dsChannel]<<1; + tnsR=nsR[dsChannel]<<1; + dsChannel=(dsChannel+1)&7; + } else { + tnsL=(nsL[0]+nsL[1]+nsL[2]+nsL[3]+nsL[4]+nsL[5]+nsL[6]+nsL[7])>>2; + tnsR=(nsR[0]+nsR[1]+nsR[2]+nsR[3]+nsR[4]+nsR[5]+nsR[6]+nsR[7])>>2; - IL1=minval(32767,maxval(-32767,tnsL))>>8; - IL2=minval(32767,maxval(-32767,tnsR))>>8; + IL1=minval(32767,maxval(-32767,tnsL))>>8; + IL2=minval(32767,maxval(-32767,tnsR))>>8; + } // write input lines to sample memory if (ILSIZE&64) { @@ -324,36 +330,8 @@ void SoundUnit::NextSample(short* l, short* r) { } if (dsOut) { - tnsL=minval(32767,maxval(-32767,tnsL<<1)); - tnsR=minval(32767,maxval(-32767,tnsR<<1)); - - short accumL=0; - short accumR=0; - - for (int i=0; i<4; i++) { - if ((tnsL>>8)==0 && dsCounterL>0) dsCounterL=0; - dsCounterL+=tnsL>>8; - if (dsCounterL>=0) { - accumL+=4095; - dsCounterL-=127; - } else { - accumL+=-4095; - dsCounterL+=127; - } - - if ((tnsR>>8)==0 && dsCounterR>0) dsCounterR=0; - dsCounterR+=tnsR>>8; - if (dsCounterR>=0) { - accumR+=4095; - dsCounterR-=127; - } else { - accumR+=-4095; - dsCounterR+=127; - } - } - - *l=accumL; - *r=accumR; + *l=minval(32767,maxval(-32767,tnsL))&0xff00; + *r=minval(32767,maxval(-32767,tnsR))&0xff00; } else { *l=minval(32767,maxval(-32767,tnsL)); *r=minval(32767,maxval(-32767,tnsR)); @@ -402,8 +380,7 @@ void SoundUnit::Reset() { oldfreq[i]=0; pcmdec[i]=0; } - dsCounterL=0; - dsCounterR=0; + dsChannel=0; tnsL=0; tnsR=0; ilBufPos=0; diff --git a/src/engine/platform/sound/su.h b/src/engine/platform/sound/su.h index 51c769e38..8e8009568 100644 --- a/src/engine/platform/sound/su.h +++ b/src/engine/platform/sound/su.h @@ -47,7 +47,7 @@ class SoundUnit { unsigned short oldfreq[8]; unsigned int pcmSize; bool dsOut; - short dsCounterL, dsCounterR; + unsigned char dsChannel; public: unsigned short resetfreq[8]; unsigned short voldcycles[8]; diff --git a/src/gui/sysConf.cpp b/src/gui/sysConf.cpp index a11ccdd48..c07fcaf02 100644 --- a/src/gui/sysConf.cpp +++ b/src/gui/sysConf.cpp @@ -239,7 +239,7 @@ bool FurnaceGUI::drawSysConf(int chan, DivSystem type, DivConfig& flags, bool mo pdm=false; altered=true; } - if (ImGui::RadioButton("1-bit PDM (rev C/E)",pdm==1)) { + if (ImGui::RadioButton("8-bit + TDM (rev C/E)",pdm==1)) { pdm=true; altered=true; }