From 1d5d35bc9d0d3d84873cd1d31870d09248ddc05b Mon Sep 17 00:00:00 2001
From: notaz <notasas@gmail.com>
Date: Thu, 3 Nov 2022 22:49:08 +0200
Subject: [PATCH] spu: fix a wrong assumption

from 5aa94fa080e1b0a661b23aa912022dd464d41110
libretro/pcsx_rearmed#704
---
 plugins/dfsound/registers.c | 6 ++----
 plugins/dfsound/spu.c       | 4 ++--
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/plugins/dfsound/registers.c b/plugins/dfsound/registers.c
index e75f7086..e00939e6 100644
--- a/plugins/dfsound/registers.c
+++ b/plugins/dfsound/registers.c
@@ -505,10 +505,8 @@ static void SetPitch(int ch,unsigned short val)               // SET PITCH
  spu.s_chan[ch].sinc = NP << 4;
  spu.s_chan[ch].sinc_inv = 0;
  spu.SB[ch * SB_SIZE + 32] = 1; // -> freq change in simple interpolation mode: set flag
- if (val)
-  spu.dwChannelsAudible |= 1u << ch;
- else
-  spu.dwChannelsAudible &= ~(1u << ch);
+
+ // don't mess spu.dwChannelsAudible as adsr runs independently
 }
 
 ////////////////////////////////////////////////////////////////////////
diff --git a/plugins/dfsound/spu.c b/plugins/dfsound/spu.c
index 3b4c051d..1127cd71 100644
--- a/plugins/dfsound/spu.c
+++ b/plugins/dfsound/spu.c
@@ -251,8 +251,7 @@ static void StartSoundMain(int ch)
 
  spu.dwNewChannel&=~(1<<ch);                           // clear new channel bit
  spu.dwChannelDead&=~(1<<ch);
- if (s_chan->iRawPitch)
-  spu.dwChannelsAudible|=1<<ch;
+ spu.dwChannelsAudible|=1<<ch;
 }
 
 static void StartSound(int ch)
@@ -950,6 +949,7 @@ static void queue_channel_work(int ns_to, unsigned int silentch)
    d = SkipADSR(&s_chan->ADSRX, d);
    if (d < ns_to) {
     spu.dwChannelsAudible &= ~(1 << ch);
+    s_chan->ADSRX.State = ADSR_RELEASE;
     s_chan->ADSRX.EnvelopeVol = 0;
    }
   }
-- 
2.39.5