SPU2: Make sure cache hits match previous block decoded samples

Caching blocks of ADPCM is a bit sketchy because the previous samples (which it uses to generate the new ones) can change, so you can end up with blips and glitches in the sample stream, this should avoid that problem whilst not making the cache completely unusable.
This commit is contained in:
refractionpcsx2 2021-02-03 10:57:33 +00:00
parent 97ed78109c
commit 712a922cc5
2 changed files with 7 additions and 1 deletions

View File

@ -217,7 +217,7 @@ static __forceinline s32 GetNextDataBuffered(V_Core& thiscore, uint voiceidx)
PcmCacheEntry& cacheLine = pcm_cache_data[cacheIdx];
vc.SBuffer = cacheLine.Sampledata;
if (cacheLine.Validated)
if (cacheLine.Validated && vc.Prev1 == cacheLine.Prev1 && vc.Prev2 == cacheLine.Prev2)
{
// Cached block! Read from the cache directly.
// Make sure to propagate the prev1/prev2 ADPCM:
@ -234,7 +234,11 @@ static __forceinline s32 GetNextDataBuffered(V_Core& thiscore, uint voiceidx)
{
// Only flag the cache if it's a non-dynamic memory range.
if (vc.NextA >= SPU2_DYN_MEMLINE)
{
cacheLine.Validated = true;
cacheLine.Prev1 = vc.Prev1;
cacheLine.Prev2 = vc.Prev2;
}
if (IsDevBuild)
{

View File

@ -598,6 +598,8 @@ struct PcmCacheEntry
{
bool Validated;
s16 Sampledata[pcm_DecodedSamplesPerBlock];
s32 Prev1;
s32 Prev2;
};
extern PcmCacheEntry* pcm_cache_data;