spu: don't leave garbage in capture buffers
authornotaz <notasas@gmail.com>
Mon, 25 Mar 2024 21:26:10 +0000 (23:26 +0200)
committernotaz <notasas@gmail.com>
Mon, 25 Mar 2024 21:36:23 +0000 (23:36 +0200)
plugins/dfsound/externals.h
plugins/dfsound/freeze.c
plugins/dfsound/spu.c
plugins/dfsound/xa.c

index ac0960f..8e479c5 100644 (file)
@@ -214,6 +214,7 @@ typedef struct
  int             iLeftXAVol;\r
  int             iRightXAVol;\r
 \r
+ int             cdClearSamples;       // extra samples to clear the capture buffers\r
  struct {                              // channel volume in the cd controller\r
   unsigned char  ll, lr, rl, rr;       // see cdr.Attenuator* in cdrom.c\r
  } cdv;                                // applied on spu side for easier emulation\r
index bddf0ad..36b8995 100644 (file)
@@ -338,6 +338,7 @@ long CALLBACK SPUfreeze(unsigned int ulFreezeMode, SPUFreeze_t * pF,
 \r
  spu.XAPlay = spu.XAFeed = spu.XAStart;\r
  spu.CDDAPlay = spu.CDDAFeed = spu.CDDAStart;\r
+ spu.cdClearSamples = 512;\r
  if (pFO && pFO->xa_left && pF->xaS.nsamples) {        // start xa again\r
   FeedXA(&pF->xaS);\r
   spu.XAPlay = spu.XAFeed - pFO->xa_left;\r
index 022a1e3..ed5b4b5 100644 (file)
@@ -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;
 }
 
index 6b5433f..380d138 100644 (file)
@@ -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;
+ }
 }
 
 ////////////////////////////////////////////////////////////////////////