From: notaz Date: Wed, 9 Aug 2023 23:29:53 +0000 (+0300) Subject: spu: some cdda/xa reverb support X-Git-Tag: r24~215 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73d2a9037e5ea290cac10a9f26860a6405b55a0c;p=pcsx_rearmed.git spu: some cdda/xa reverb support not for threaded spu as it'd race with writes and I don't want to use a mutex or do extra copying there libretro/pcsx_rearmed#733 --- diff --git a/plugins/dfsound/registers.h b/plugins/dfsound/registers.h index 28641b81..a296431f 100644 --- a/plugins/dfsound/registers.h +++ b/plugins/dfsound/registers.h @@ -145,8 +145,10 @@ #define H_SPU_ADSRLevel22 0x0d68 #define H_SPU_ADSRLevel23 0x0d78 -#define CTRL_IRQ 0x40 -#define CTRL_REVERB 0x80 +#define CTRL_CD 0x0001 +#define CTRL_CDREVERB 0x0004 +#define CTRL_IRQ 0x0040 +#define CTRL_REVERB 0x0080 #define CTRL_NOISE 0x3f00 #define CTRL_MUTE 0x4000 #define CTRL_ON 0x8000 diff --git a/plugins/dfsound/spu.c b/plugins/dfsound/spu.c index f6730d64..038f946e 100644 --- a/plugins/dfsound/spu.c +++ b/plugins/dfsound/spu.c @@ -814,6 +814,8 @@ static void do_channels(int ns_to) mix_chan(spu.SSumLR, ns_to, s_chan->iLeftVolume, s_chan->iRightVolume); } + MixXA(spu.SSumLR, RVB, ns_to, spu.decode_pos); + if (spu.rvb->StartAddr) { if (do_rvb) REVERBDo(spu.SSumLR, RVB, ns_to, spu.rvb->CurrAddr); @@ -1066,6 +1068,7 @@ static void sync_worker_thread(int force) work = &worker->i[worker->i_reaped & WORK_I_MASK]; thread_work_wait_sync(work, force); + MixXA(work->SSumLR, RVB, work->ns_to, work->decode_pos); do_samples_finish(work->SSumLR, work->ns_to, work->channels_silent, work->decode_pos); @@ -1192,12 +1195,10 @@ static void do_samples_finish(int *SSumLR, int ns_to, spu.decode_dirty_ch &= ~(1<<3); } - MixXA(SSumLR, ns_to, decode_pos); - vol_l = vol_l * spu_config.iVolume >> 10; vol_r = vol_r * spu_config.iVolume >> 10; - if (!(spu.spuCtrl & 0x4000) || !(vol_l | vol_r)) + if (!(spu.spuCtrl & CTRL_MUTE) || !(vol_l | vol_r)) { // muted? (rare) memset(spu.pS, 0, ns_to * 2 * sizeof(spu.pS[0])); diff --git a/plugins/dfsound/xa.c b/plugins/dfsound/xa.c index 397ed592..23924d3b 100644 --- a/plugins/dfsound/xa.c +++ b/plugins/dfsound/xa.c @@ -39,7 +39,7 @@ static int gauss_window[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // MIX XA & CDDA //////////////////////////////////////////////////////////////////////// -INLINE void MixXA(int *SSumLR, int ns_to, int decode_pos) +INLINE void MixXA(int *SSumLR, int *RVB, int ns_to, int decode_pos) { int cursor = decode_pos; int ns; @@ -51,15 +51,23 @@ INLINE void MixXA(int *SSumLR, int ns_to, int decode_pos) if(spu.XAPlay == spu.XAFeed) spu.XARepeat--; - for(ns = 0; ns < ns_to*2; ) + for(ns = 0; ns < ns_to*2; ns += 2) { if(spu.XAPlay != spu.XAFeed) v=*spu.XAPlay++; if(spu.XAPlay == spu.XAEnd) spu.XAPlay=spu.XAStart; l = ((int)(short)v * spu.iLeftXAVol) >> 15; r = ((int)(short)(v >> 16) * spu.iLeftXAVol) >> 15; - SSumLR[ns++] += l; - SSumLR[ns++] += r; + if (spu.spuCtrl & CTRL_CD) + { + SSumLR[ns+0] += l; + SSumLR[ns+1] += r; + } + if (unlikely(spu.spuCtrl & CTRL_CDREVERB)) + { + RVB[ns+0] += l; + RVB[ns+1] += r; + } spu.spuMem[cursor] = HTOLE16(v); spu.spuMem[cursor + 0x400/2] = HTOLE16(v >> 16); @@ -71,15 +79,23 @@ INLINE void MixXA(int *SSumLR, int ns_to, int decode_pos) // hence this 'ns_to < 8' else if(spu.CDDAPlay != spu.CDDAFeed || ns_to < 8) { - for(ns = 0; ns < ns_to*2; ) + for(ns = 0; ns < ns_to*2; ns += 2) { if(spu.CDDAPlay != spu.CDDAFeed) v=*spu.CDDAPlay++; if(spu.CDDAPlay == spu.CDDAEnd) spu.CDDAPlay=spu.CDDAStart; l = ((int)(short)v * spu.iLeftXAVol) >> 15; r = ((int)(short)(v >> 16) * spu.iLeftXAVol) >> 15; - SSumLR[ns++] += l; - SSumLR[ns++] += r; + if (spu.spuCtrl & CTRL_CD) + { + SSumLR[ns+0] += l; + SSumLR[ns+1] += r; + } + if (unlikely(spu.spuCtrl & CTRL_CDREVERB)) + { + RVB[ns+0] += l; + RVB[ns+1] += r; + } spu.spuMem[cursor] = HTOLE16(v); spu.spuMem[cursor + 0x400/2] = HTOLE16(v >> 16); @@ -420,3 +436,4 @@ INLINE int FeedCDDA(unsigned char *pcm, int nBytes) } #endif +// vim:shiftwidth=1:expandtab diff --git a/plugins/dfsound/xa.h b/plugins/dfsound/xa.h deleted file mode 100644 index 137fe436..00000000 --- a/plugins/dfsound/xa.h +++ /dev/null @@ -1,25 +0,0 @@ -/*************************************************************************** - xa.h - description - ------------------- - begin : Wed May 15 2002 - copyright : (C) 2002 by Pete Bernert - email : BlackDove@addcom.de - ***************************************************************************/ -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. See also the license.txt file for * - * additional informations. * - * * - ***************************************************************************/ - -#ifndef __P_XA_H__ -#define __P_XA_H__ - -INLINE void MixXA(void); -INLINE void FeedXA(xa_decode_t *xap); -INLINE int FeedCDDA(unsigned char *pcm, int nBytes); - -#endif /* __P_XA_H__ */