From 5fdcf5cd320abef2c685630e3edf3598645d141e Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 5 Sep 2022 02:03:24 +0300 Subject: [PATCH] spu: support master volume --- plugins/dfsound/externals.h | 4 +++- plugins/dfsound/freeze.c | 2 +- plugins/dfsound/registers.c | 2 +- plugins/dfsound/spu.c | 18 ++++++++++++------ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/plugins/dfsound/externals.h b/plugins/dfsound/externals.h index 09426647..2bc2fc0e 100644 --- a/plugins/dfsound/externals.h +++ b/plugins/dfsound/externals.h @@ -232,7 +232,9 @@ typedef struct unsigned short regArea[0x400]; } SPUInfo; -#define regAreaGet(ch,offset) \ +#define regAreaGet(offset) \ + spu.regArea[((offset) - 0xc00)>>1] +#define regAreaGetCh(ch, offset) \ spu.regArea[((ch<<4)|(offset))>>1] /////////////////////////////////////////////////////////// diff --git a/plugins/dfsound/freeze.c b/plugins/dfsound/freeze.c index a9843aeb..4866df89 100644 --- a/plugins/dfsound/freeze.c +++ b/plugins/dfsound/freeze.c @@ -145,7 +145,7 @@ static void save_channel(SPUCHAN_orig *d, const SPUCHAN *s, int ch) d->spos = s->spos; d->sinc = s->sinc; memcpy(d->SB, spu.SB + ch * SB_SIZE, sizeof(d->SB[0]) * SB_SIZE); - d->iStart = (regAreaGet(ch,6)&~1)<<3; + d->iStart = (regAreaGetCh(ch, 6) & ~1) << 3; d->iCurr = 0; // set by the caller d->iLoop = 0; // set by the caller d->bOn = !!(spu.dwChannelsAudible & (1<>=1) // loop channels { - if((val&1) && regAreaGet(ch,6)) // mmm... start has to be set before key on !?! + if((val&1) && regAreaGetCh(ch, 6)) // mmm... start has to be set before key on !?! { spu.s_chan[ch].bIgnoreLoop = 0; spu.dwNewChannel|=(1<iSBPos=27; s_chan->spos=0; - s_chan->pCurr = spu.spuMemC+((regAreaGet(ch,6)&~1)<<3); + s_chan->pCurr = spu.spuMemC + ((regAreaGetCh(ch, 6) & ~1) << 3); spu.dwNewChannel&=~(1<> 17; + int vol_r = ((int)regAreaGet(H_SPUmvolR) << 17) >> 17; int ns; int d; @@ -1192,23 +1193,28 @@ static void do_samples_finish(int *SSumLR, int ns_to, } MixXA(SSumLR, ns_to, decode_pos); - - if((spu.spuCtrl&0x4000)==0) // muted? (rare, don't optimize for this) + + vol_l = vol_l * spu_config.iVolume >> 10; + vol_r = vol_r * spu_config.iVolume >> 10; + + if (!(spu.spuCtrl & 0x4000) || !(vol_l | vol_r)) { + // muted? (rare) memset(spu.pS, 0, ns_to * 2 * sizeof(spu.pS[0])); + memset(SSumLR, 0, ns_to * 2 * sizeof(SSumLR[0])); spu.pS += ns_to * 2; } else for (ns = 0; ns < ns_to * 2; ) { d = SSumLR[ns]; SSumLR[ns] = 0; - d = d * volmult >> 10; + d = d * vol_l >> 15; ssat32_to_16(d); *spu.pS++ = d; ns++; d = SSumLR[ns]; SSumLR[ns] = 0; - d = d * volmult >> 10; + d = d * vol_r >> 15; ssat32_to_16(d); *spu.pS++ = d; ns++; -- 2.39.5