spu: check buffer state less often
[pcsx_rearmed.git] / plugins / dfsound / spu.c
index bbbe1e3..1456a21 100644 (file)
@@ -24,7 +24,8 @@
 
 #include "externals.h"
 #include "registers.h"
-#include "dsoundoss.h"
+#include "out.h"
+#include "arm_features.h"
 
 #ifdef ENABLE_NLS
 #include <libintl.h>
@@ -615,7 +616,7 @@ static int do_samples_noise(int ch, int ns, int ns_to)
  return ret;
 }
 
-#ifdef __arm__
+#ifdef HAVE_ARMV5
 // asm code; lv and rv must be 0-3fff
 extern void mix_chan(int start, int count, int lv, int rv);
 extern void mix_chan_rvb(int start, int count, int lv, int rv);
@@ -688,25 +689,18 @@ static int do_samples(int forced_updates)
  int ch,d,silentch;
  int bIRQReturn=0;
 
- while(1)
-  {
-   // ok, at the beginning we are looking if there is
-   // enuff free place in the dsound/oss buffer to
-   // fill in new data, or if there is a new channel to start.
-   // if not, we wait (thread) or return (timer/spuasync)
-   // until enuff free place is available/a new channel gets
-   // started
-
-   if(!forced_updates && SoundGetBytesBuffered())      // still enuff data in sound buffer?
-    {
-     return 0;
-    }
+ // ok, at the beginning we are looking if there is
+ // enuff free place in the dsound/oss buffer to
+ // fill in new data, or if there is a new channel to start.
+ // if not, we return until enuff free place is available
+ // /a new channel gets started
 
-   cycles_since_update = 0;
-   if(forced_updates > 0)
-    forced_updates--;
+ if(!forced_updates && out_current->busy())            // still enuff data in sound buffer?
+  return 0;
 
-   //--------------------------------------------------// continue from irq handling in timer mode? 
+ while(!bIRQReturn)
+  {
+   cycles_since_update = 0;
 
    ns_from=0;
    ns_to=NSSIZE;
@@ -862,6 +856,7 @@ static int do_samples(int forced_updates)
      {
       //printf("decoder irq %x\n", decode_pos);
       do_irq();
+      bIRQReturn = 1;
      }
    }
   decode_pos = (decode_pos + NSSIZE) & 0x1ff;
@@ -870,12 +865,21 @@ static int do_samples(int forced_updates)
 
   // feed the sound
   // wanna have around 1/60 sec (16.666 ms) updates
-  if (iCycle++ > 16/FRAG_MSECS)
+  if (iCycle++ >= 16/FRAG_MSECS)
    {
-    SoundFeedStreamData((unsigned char *)pSpuBuffer,
-                        ((unsigned char *)pS) - ((unsigned char *)pSpuBuffer));
+    out_current->feed(pSpuBuffer, (unsigned char *)pS - pSpuBuffer);
     pS = (short *)pSpuBuffer;
     iCycle = 0;
+
+    if(!forced_updates && out_current->busy())
+     break;
+   }
+
+  if(forced_updates > 0)
+   {
+    forced_updates--;
+    if(forced_updates == 0 && out_current->busy())
+     break;
    }
  }
 
@@ -1056,7 +1060,7 @@ long CALLBACK SPUclose(void)
 
  bSPUIsOpen = 0;                                       // no more open
 
RemoveSound();                                        // no more sound handling
out_current->finish();                                // no more sound handling
 
  return 0;
 }