spu: try to clean up the interpolation mess
[pcsx_rearmed.git] / plugins / dfsound / freeze.c
index d4898b4..c4afad8 100644 (file)
@@ -15,6 +15,7 @@
  *                                                                         *\r
  ***************************************************************************/\r
 \r
+#include <assert.h>\r
 #include "stdafx.h"\r
 \r
 #define _IN_FREEZE\r
@@ -145,7 +146,8 @@ static void save_channel(SPUCHAN_orig *d, const SPUCHAN *s, int ch)
  d->iSBPos = s->iSBPos;\r
  d->spos = s->spos;\r
  d->sinc = s->sinc;\r
- memcpy(d->SB, spu.SB + ch * SB_SIZE, sizeof(d->SB[0]) * SB_SIZE);\r
+ assert(sizeof(d->SB) >= sizeof(spu.sb[ch]));\r
+ memcpy(d->SB, &spu.sb[ch], sizeof(spu.sb[ch]));\r
  d->iStart = (regAreaGetCh(ch, 6) & ~1) << 3;\r
  d->iCurr = 0; // set by the caller\r
  d->iLoop = 0; // set by the caller\r
@@ -159,8 +161,8 @@ static void save_channel(SPUCHAN_orig *d, const SPUCHAN *s, int ch)
  d->bIgnoreLoop = (s->prevflags ^ 2) << 1;\r
  d->iRightVolume = s->iRightVolume;\r
  d->iRawPitch = s->iRawPitch;\r
- d->s_1 = spu.SB[ch * SB_SIZE + 27]; // yes it's reversed\r
- d->s_2 = spu.SB[ch * SB_SIZE + 26];\r
+ d->s_1 = spu.sb[ch].SB[27]; // yes it's reversed\r
+ d->s_2 = spu.sb[ch].SB[26];\r
  d->bRVBActive = s->bRVBActive;\r
  d->bNoise = s->bNoise;\r
  d->bFMod = s->bFMod;\r
@@ -187,7 +189,7 @@ static void load_channel(SPUCHAN *d, const SPUCHAN_orig *s, int ch)
  d->spos = s->spos;\r
  d->sinc = s->sinc;\r
  d->sinc_inv = 0;\r
- memcpy(spu.SB + ch * SB_SIZE, s->SB, sizeof(spu.SB[0]) * SB_SIZE);\r
+ memcpy(&spu.sb[ch], s->SB, sizeof(spu.sb[ch]));\r
  d->pCurr = (void *)((uintptr_t)s->iCurr & 0x7fff0);\r
  d->pLoop = (void *)((uintptr_t)s->iLoop & 0x7fff0);\r
  d->bReverb = s->bReverb;\r
@@ -340,7 +342,7 @@ long CALLBACK SPUfreeze(uint32_t ulFreezeMode, SPUFreeze_t * pF,
  load_register(H_CDRight, cycles);\r
 \r
  // fix to prevent new interpolations from crashing\r
for(i=0;i<MAXCHAN;i++) spu.SB[i * SB_SIZE + 28]=0;\r
spu.interpolation = -1;\r
 \r
  ClearWorkingState();\r
 \r