spu: rework synchronization
[pcsx_rearmed.git] / plugins / dfsound / xa.c
index 1c5425e..4c016aa 100644 (file)
@@ -56,7 +56,7 @@ static int gauss_window[8] = {0, 0, 0, 0, 0, 0, 0, 0};
 // MIX XA & CDDA
 ////////////////////////////////////////////////////////////////////////
 
-INLINE void MixXA(void)
+INLINE void MixXA(int ns_to)
 {
  int ns;
  short l, r;
@@ -69,7 +69,7 @@ INLINE void MixXA(void)
    XARepeat--;
 
   v = XALastVal;
-  for(ns=0;ns<NSSIZE*2;)
+  for(ns = 0; ns < ns_to*2; )
    {
     if(XAPlay != XAFeed) v=*XAPlay++;
     if(XAPlay == XAEnd) XAPlay=XAStart;
@@ -78,14 +78,15 @@ INLINE void MixXA(void)
     r = ((int)(short)(v >> 16) * iLeftXAVol) >> 15;
     SSumLR[ns++] += l;
     SSumLR[ns++] += r;
-    spuMem[cursor] = l;
-    spuMem[cursor + 0x400/2] = r;
+
+    spuMem[cursor] = v;
+    spuMem[cursor + 0x400/2] = v >> 16;
     cursor = (cursor + 1) & 0x1ff;
    }
   XALastVal = v;
  }
 
- for(ns=0;ns<NSSIZE*2 && CDDAPlay!=CDDAFeed && (CDDAPlay!=CDDAEnd-1||CDDAFeed!=CDDAStart);)
+ for(ns = 0; ns < ns_to * 2 && CDDAPlay!=CDDAFeed && (CDDAPlay!=CDDAEnd-1||CDDAFeed!=CDDAStart);)
   {
    v=*CDDAPlay++;
    if(CDDAPlay==CDDAEnd) CDDAPlay=CDDAStart;
@@ -94,8 +95,9 @@ INLINE void MixXA(void)
    r = ((int)(short)(v >> 16) * iLeftXAVol) >> 15;
    SSumLR[ns++] += l;
    SSumLR[ns++] += r;
-   spuMem[cursor] = l;
-   spuMem[cursor + 0x400/2] = r;
+
+   spuMem[cursor] = v;
+   spuMem[cursor + 0x400/2] = v >> 16;
    cursor = (cursor + 1) & 0x1ff;
   }
 }