Skip to content

Commit

Permalink
spu: don't leave garbage in capture buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
notaz committed Mar 25, 2024
1 parent 0500680 commit e2fb138
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/dfsound/externals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions plugins/dfsound/freeze.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions plugins/dfsound/spu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
10 changes: 9 additions & 1 deletion plugins/dfsound/xa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit e2fb138

Please sign in to comment.