From 215ff9e69c0b845f24e7a3aa9faeef06d9276145 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 27 Dec 2014 23:24:15 +0200 Subject: spu: handle stop better, split main func more --- plugins/dfsound/adsr.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'plugins/dfsound/adsr.c') diff --git a/plugins/dfsound/adsr.c b/plugins/dfsound/adsr.c index c1e98b3..976315d 100644 --- a/plugins/dfsound/adsr.c +++ b/plugins/dfsound/adsr.c @@ -63,10 +63,10 @@ INLINE void StartADSR(int ch) // MIX ADSR //////////////////////////////////////////////////////////////////////// -static void MixADSR(int ch, int ns, int ns_to) // MIX ADSR +static int MixADSR(int ch, int ns_to) // MIX ADSR { int EnvelopeVol = s_chan[ch].ADSRX.EnvelopeVol; - int val, rto, level; + int ns = 0, val, rto, level; if (s_chan[ch].bStop) // should be stopped: { // do release @@ -97,9 +97,6 @@ static void MixADSR(int ch, int ns, int ns_to) // MIX ADSR } } - if (EnvelopeVol <= 0) - goto stop; - goto done; } @@ -160,7 +157,10 @@ static void MixADSR(int ch, int ns, int ns_to) // MIX ADSR if (s_chan[ch].ADSRX.SustainIncrease) { if (EnvelopeVol >= 0x7fff0000) + { + ns = ns_to; break; + } rto = 0; if (s_chan[ch].ADSRX.SustainModeExp && EnvelopeVol >= 0x60000000) @@ -173,6 +173,7 @@ static void MixADSR(int ch, int ns, int ns_to) // MIX ADSR if ((unsigned int)EnvelopeVol >= 0x7fe00000) { EnvelopeVol = 0x7fffffff; + ns = ns_to; break; } @@ -189,7 +190,7 @@ static void MixADSR(int ch, int ns, int ns_to) // MIX ADSR { EnvelopeVol += ((long long)val * EnvelopeVol) >> (15+16); if (EnvelopeVol < 0) - goto stop; + break; ChanBuf[ns] *= EnvelopeVol >> 21; ChanBuf[ns] >>= 10; @@ -201,7 +202,7 @@ static void MixADSR(int ch, int ns, int ns_to) // MIX ADSR { EnvelopeVol += val; if (EnvelopeVol < 0) - goto stop; + break; ChanBuf[ns] *= EnvelopeVol >> 21; ChanBuf[ns] >>= 10; @@ -213,12 +214,7 @@ static void MixADSR(int ch, int ns, int ns_to) // MIX ADSR done: s_chan[ch].ADSRX.EnvelopeVol = EnvelopeVol; - return; - -stop: - memset(&ChanBuf[ns], 0, (ns_to - ns) * sizeof(ChanBuf[0])); - s_chan[ch].ADSRX.EnvelopeVol = 0; - spu.dwChannelOn &= ~(1<