spu: fix wrong volume shift
[pcsx_rearmed.git] / plugins / dfsound / xa.c
index 1241380..f62a12d 100644 (file)
@@ -38,19 +38,18 @@ static int gauss_window[8] = {0, 0, 0, 0, 0, 0, 0, 0};
 // MIX XA & CDDA
 ////////////////////////////////////////////////////////////////////////
 
-INLINE void MixXA(int ns_to, int decode_pos)
+INLINE void MixXA(int *SSumLR, int ns_to, int decode_pos)
 {
  int cursor = decode_pos;
  int ns;
  short l, r;
- uint32_t v;
+ uint32_t v = spu.XALastVal;
 
  if(spu.XAPlay != spu.XAFeed || spu.XARepeat > 0)
  {
   if(spu.XAPlay == spu.XAFeed)
    spu.XARepeat--;
 
-  v = spu.XALastVal;
   for(ns = 0; ns < ns_to*2; )
    {
     if(spu.XAPlay != spu.XAFeed) v=*spu.XAPlay++;
@@ -67,30 +66,40 @@ INLINE void MixXA(int ns_to, int decode_pos)
    }
   spu.XALastVal = v;
  }
+ // occasionally CDDAFeed underflows by a few samples due to poor timing,
+ // hence this 'ns_to < 8'
+ else if(spu.CDDAPlay != spu.CDDAFeed || ns_to < 8)
+ {
+  for(ns = 0; ns < ns_to*2; )
+   {
+    if(spu.CDDAPlay != spu.CDDAFeed) v=*spu.CDDAPlay++;
+    if(spu.CDDAPlay == spu.CDDAEnd) spu.CDDAPlay=spu.CDDAStart;
 
- for(ns = 0; ns < ns_to * 2 && spu.CDDAPlay!=spu.CDDAFeed && (spu.CDDAPlay!=spu.CDDAEnd-1||spu.CDDAFeed!=spu.CDDAStart);)
-  {
-   v=*spu.CDDAPlay++;
-   if(spu.CDDAPlay==spu.CDDAEnd) spu.CDDAPlay=spu.CDDAStart;
-
-   l = ((int)(short)v * spu.iLeftXAVol) >> 15;
-   r = ((int)(short)(v >> 16) * spu.iLeftXAVol) >> 15;
-   SSumLR[ns++] += l;
-   SSumLR[ns++] += r;
+    l = ((int)(short)v * spu.iLeftXAVol) >> 15;
+    r = ((int)(short)(v >> 16) * spu.iLeftXAVol) >> 15;
+    SSumLR[ns++] += l;
+    SSumLR[ns++] += r;
 
-   spu.spuMem[cursor] = v;
-   spu.spuMem[cursor + 0x400/2] = v >> 16;
-   cursor = (cursor + 1) & 0x1ff;
-  }
+    spu.spuMem[cursor] = v;
+    spu.spuMem[cursor + 0x400/2] = v >> 16;
+    cursor = (cursor + 1) & 0x1ff;
+   }
+  spu.XALastVal = v;
+ }
+ else
+  spu.XALastVal = 0;
 }
 
 ////////////////////////////////////////////////////////////////////////
 // small linux time helper... only used for watchdog
 ////////////////////////////////////////////////////////////////////////
 
+#if 0
 static unsigned long timeGetTime_spu()
 {
-#ifdef _WIN32
+#if defined(NO_OS)
+ return 0;
+#elif defined(_WIN32)
  return GetTickCount();
 #else
  struct timeval tv;
@@ -98,6 +107,7 @@ static unsigned long timeGetTime_spu()
  return tv.tv_sec * 1000 + tv.tv_usec/1000;            // to do that, but at least it works
 #endif
 }
+#endif
 
 ////////////////////////////////////////////////////////////////////////
 // FEED XA 
@@ -110,7 +120,7 @@ INLINE void FeedXA(xa_decode_t *xap)
  if(!spu.bSPUIsOpen) return;
 
  spu.xapGlobal = xap;                                  // store info for save states
- spu.XARepeat  = 100;                                  // set up repeat
+ spu.XARepeat  = 3;                                    // set up repeat
 
 #if 0//def XA_HACK
  iSize=((45500*xap->nsamples)/xap->freq);              // get size
@@ -125,6 +135,7 @@ INLINE void FeedXA(xa_decode_t *xap)
  if(iPlace==0) return;                                 // no place at all
 
  //----------------------------------------------------//
+#if 0
  if(spu_config.iXAPitch)                               // pitch change option?
   {
    static DWORD dwLT=0;
@@ -161,6 +172,7 @@ INLINE void FeedXA(xa_decode_t *xap)
      if(iLastSize) iSize=iLastSize;
     }
   }
+#endif
  //----------------------------------------------------//
 
  spos=0x10000L;
@@ -171,6 +183,7 @@ INLINE void FeedXA(xa_decode_t *xap)
    uint32_t * pS=(uint32_t *)xap->pcm;
    uint32_t l=0;
 
+#if 0
    if(spu_config.iXAPitch)
     {
      int32_t l1,l2;short s;
@@ -230,6 +243,7 @@ INLINE void FeedXA(xa_decode_t *xap)
       }
     }
    else
+#endif
     {
      for(i=0;i<iSize;i++)
       {
@@ -282,6 +296,7 @@ INLINE void FeedXA(xa_decode_t *xap)
    unsigned short * pS=(unsigned short *)xap->pcm;
    uint32_t l;short s=0;
 
+#if 0
    if(spu_config.iXAPitch)
     {
      int32_t l1;
@@ -329,6 +344,7 @@ INLINE void FeedXA(xa_decode_t *xap)
       }
     }
    else
+#endif
     {
      for(i=0;i<iSize;i++)
       {