From 67c020eeafd6d3db7f9d2c314a77990177a1c4ff Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 25 Mar 2024 23:26:10 +0200 Subject: [PATCH] spu: don't leave garbage in capture buffers --- plugins/dfsound/externals.h | 1 + plugins/dfsound/freeze.c | 1 + plugins/dfsound/spu.c | 2 ++ plugins/dfsound/xa.c | 10 +++++++++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/dfsound/externals.h b/plugins/dfsound/externals.h index ac0960f6..8e479c53 100644 --- a/plugins/dfsound/externals.h +++ b/plugins/dfsound/externals.h @@ -214,6 +214,7 @@ typedef struct int iLeftXAVol; int iRightXAVol; + int cdClearSamples; // extra samples to clear the capture buffers struct { // channel volume in the cd controller unsigned char ll, lr, rl, rr; // see cdr.Attenuator* in cdrom.c } cdv; // applied on spu side for easier emulation diff --git a/plugins/dfsound/freeze.c b/plugins/dfsound/freeze.c index bddf0ada..36b89959 100644 --- a/plugins/dfsound/freeze.c +++ b/plugins/dfsound/freeze.c @@ -338,6 +338,7 @@ long CALLBACK SPUfreeze(unsigned int ulFreezeMode, SPUFreeze_t * pF, spu.XAPlay = spu.XAFeed = spu.XAStart; spu.CDDAPlay = spu.CDDAFeed = spu.CDDAStart; + spu.cdClearSamples = 512; if (pFO && pFO->xa_left && pF->xaS.nsamples) { // start xa again FeedXA(&pF->xaS); spu.XAPlay = spu.XAFeed - pFO->xa_left; diff --git a/plugins/dfsound/spu.c b/plugins/dfsound/spu.c index 022a1e3d..ed5b4b5c 100644 --- a/plugins/dfsound/spu.c +++ b/plugins/dfsound/spu.c @@ -1389,6 +1389,7 @@ void CALLBACK SPUplayADPCMchannel(xa_decode_t *xap, unsigned int cycle, int is_s FeedXA(xap); // call main XA feeder spu.xapGlobal = xap; // store info for save states + spu.cdClearSamples = 512; } // CDDA AUDIO @@ -1401,6 +1402,7 @@ int CALLBACK SPUplayCDDAchannel(short *pcm, int nbytes, unsigned int cycle, int do_samples(cycle, 1); // catch up to prevent source underflows later FeedCDDA((unsigned char *)pcm, nbytes); + spu.cdClearSamples = 512; return 0; } diff --git a/plugins/dfsound/xa.c b/plugins/dfsound/xa.c index 6b5433fb..380d1388 100644 --- a/plugins/dfsound/xa.c +++ b/plugins/dfsound/xa.c @@ -152,8 +152,16 @@ INLINE void MixCD(int *SSumLR, int *RVB, int ns_to, int decode_pos) } spu.XALastVal = v; } - else + else if (spu.cdClearSamples > 0) + { + for(ns = 0; ns < ns_to; ns++) + { + spu.spuMem[cursor] = spu.spuMem[cursor + 0x400/2] = 0; + cursor = (cursor + 1) & 0x1ff; + } + spu.cdClearSamples -= ns_to; spu.XALastVal = 0; + } } //////////////////////////////////////////////////////////////////////// -- 2.39.5