From c632283d5c48d7731ec5704c3d5eef54951fec20 Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 12 Jan 2015 03:00:12 +0200 Subject: spu: fix some skip accuracy issues --- plugins/dfsound/adsr.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/plugins/dfsound/adsr.c b/plugins/dfsound/adsr.c index 69e55bd..9e32862 100644 --- a/plugins/dfsound/adsr.c +++ b/plugins/dfsound/adsr.c @@ -221,6 +221,7 @@ static int SkipADSR(ADSRInfoEx *adsr, int ns_to) { int EnvelopeVol = adsr->EnvelopeVol; int ns = 0, val, rto, level; + int64_t v64; if (adsr->State == ADSR_RELEASE) { @@ -236,8 +237,10 @@ static int SkipADSR(ADSRInfoEx *adsr, int ns_to) } else { - EnvelopeVol += val * ns_to; - if (EnvelopeVol > 0) + v64 = EnvelopeVol; + v64 += (int64_t)val * ns_to; + EnvelopeVol = (int)v64; + if (v64 > 0) ns = ns_to; } goto done; @@ -293,24 +296,21 @@ static int SkipADSR(ADSRInfoEx *adsr, int ns_to) case ADSR_SUSTAIN: // -> sustain if (adsr->SustainIncrease) { + ns = ns_to; + if (EnvelopeVol >= 0x7fff0000) - { - ns = ns_to; break; - } rto = 0; if (adsr->SustainModeExp && EnvelopeVol >= 0x60000000) rto = 8; val = RateTableAdd[adsr->SustainRate + rto]; - EnvelopeVol += val * (ns_to - ns); - if ((unsigned int)EnvelopeVol >= 0x7fe00000) - { + v64 = EnvelopeVol; + v64 += (int64_t)val * (ns_to - ns); + EnvelopeVol = (int)v64; + if (v64 >= 0x7fe00000ll) EnvelopeVol = 0x7fffffff; - ns = ns_to; - break; - } } else { @@ -326,8 +326,10 @@ static int SkipADSR(ADSRInfoEx *adsr, int ns_to) } else { - EnvelopeVol += val * (ns_to - ns); - if (EnvelopeVol > 0) + v64 = EnvelopeVol; + v64 += (int64_t)val * (ns_to - ns); + EnvelopeVol = (int)v64; + if (v64 > 0) { ns = ns_to; break; -- cgit v1.2.3