frontend: enable SPUIRQWait by default
[pcsx_rearmed.git] / plugins / dfsound / spu.c
index c086c06..c455d3d 100644 (file)
@@ -245,15 +245,16 @@ INLINE void StartSound(int ch)
  StartADSR(ch);
  StartREVERB(ch);
 
  StartADSR(ch);
  StartREVERB(ch);
 
- s_chan[ch].pCurr=s_chan[ch].pStart;                   // set sample start
+ // fussy timing issues - do in VoiceOn
+ //s_chan[ch].pCurr=s_chan[ch].pStart;                   // set sample start
+ //s_chan[ch].bStop=0;
+ //s_chan[ch].bOn=1;
 
  s_chan[ch].s_1=0;                                     // init mixing vars
  s_chan[ch].s_2=0;
  s_chan[ch].iSBPos=28;
 
  s_chan[ch].bNew=0;                                    // init channel flags
 
  s_chan[ch].s_1=0;                                     // init mixing vars
  s_chan[ch].s_2=0;
  s_chan[ch].iSBPos=28;
 
  s_chan[ch].bNew=0;                                    // init channel flags
- s_chan[ch].bStop=0;
- s_chan[ch].bOn=1;
 
  s_chan[ch].SB[29]=0;                                  // init our interpolation helpers
  s_chan[ch].SB[30]=0;
 
  s_chan[ch].SB[29]=0;                                  // init our interpolation helpers
  s_chan[ch].SB[30]=0;
@@ -440,8 +441,8 @@ INLINE int iGetInterpolationVal(int ch)
 
 static void *MAINThread(void *arg)
 {
 
 static void *MAINThread(void *arg)
 {
- int s_1,s_2,fa,ns;
-#ifndef _MACOSX
+ int s_1,s_2,fa,ns,ns_from,ns_to;
+#if !defined(_MACOSX) && !defined(__arm__)
  int voldiv = iVolume;
 #else
  const int voldiv = 2;
  int voldiv = iVolume;
 #else
  const int voldiv = 2;
@@ -479,17 +480,19 @@ static void *MAINThread(void *arg)
 
    //--------------------------------------------------// continue from irq handling in timer mode? 
 
 
    //--------------------------------------------------// continue from irq handling in timer mode? 
 
+   ns_from=0;
+   ns_to=NSSIZE;
+   ch=0;
    if(lastch>=0)                                       // will be -1 if no continue is pending
     {
    if(lastch>=0)                                       // will be -1 if no continue is pending
     {
-     ch=lastch; ns=lastns; lastch=-1;                  // -> setup all kind of vars to continue
-     goto GOON;                                        // -> directly jump to the continue point
+     ch=lastch; ns_from=lastns+1; lastch=-1;           // -> setup all kind of vars to continue
     }
 
    //--------------------------------------------------//
    //- main channel loop                              -// 
    //--------------------------------------------------//
     {
     }
 
    //--------------------------------------------------//
    //- main channel loop                              -// 
    //--------------------------------------------------//
     {
-     for(ch=0;ch<MAXCHAN;ch++)                         // loop em all... we will collect 1 ms of sound of each playing channel
+     for(;ch<MAXCHAN;ch++)                             // loop em all... we will collect 1 ms of sound of each playing channel
       {
        if(s_chan[ch].bNew) StartSound(ch);             // start new sound
        if(!s_chan[ch].bOn) continue;                   // channel not playing? next
       {
        if(s_chan[ch].bNew) StartSound(ch);             // start new sound
        if(!s_chan[ch].bOn) continue;                   // channel not playing? next
@@ -497,8 +500,7 @@ static void *MAINThread(void *arg)
        if(s_chan[ch].iActFreq!=s_chan[ch].iUsedFreq)   // new psx frequency?
         VoiceChangeFrequency(ch);
 
        if(s_chan[ch].iActFreq!=s_chan[ch].iUsedFreq)   // new psx frequency?
         VoiceChangeFrequency(ch);
 
-       ns=0;
-       while(ns<NSSIZE)                                // loop until 1 ms of data is reached
+       for(ns=ns_from;ns<ns_to;ns++)                   // loop until 1 ms of data is reached
         {
          if(s_chan[ch].bFMod==1 && iFMod[ns])          // fmod freq channel
           FModChangeFrequency(ch,ns);
         {
          if(s_chan[ch].bFMod==1 && iFMod[ns])          // fmod freq channel
           FModChangeFrequency(ch,ns);
@@ -569,6 +571,9 @@ static void *MAINThread(void *arg)
                   {
                    iSpuAsyncWait=1;
                    bIRQReturn=1;
                   {
                    iSpuAsyncWait=1;
                    bIRQReturn=1;
+                   lastch=ch; 
+                   lastns=ns;
+                   ns_to=ns+1;
                   }
                 }
               }
                   }
                 }
               }
@@ -596,26 +601,6 @@ static void *MAINThread(void *arg)
              s_chan[ch].s_1=s_1;
              s_chan[ch].s_2=s_2;
 
              s_chan[ch].s_1=s_1;
              s_chan[ch].s_2=s_2;
 
-             if(bIRQReturn)                            // special return for "spu irq - wait for cpu action"
-              {
-               bIRQReturn=0;
-               if(iUseTimer!=2)
-                { 
-                 DWORD dwWatchTime=timeGetTime_spu()+2500;
-
-                 while(iSpuAsyncWait && !bEndThread && 
-                       timeGetTime_spu()<dwWatchTime)
-                     usleep(1000L);
-                }
-               else
-                {
-                 lastch=ch; 
-                 lastns=ns;
-
-                 return 0;
-                }
-              }
-
 GOON: ;
             }
 
 GOON: ;
             }
 
@@ -656,14 +641,31 @@ GOON: ;
          ////////////////////////////////////////////////
          // ok, go on until 1 ms data of this channel is collected
 
          ////////////////////////////////////////////////
          // ok, go on until 1 ms data of this channel is collected
 
-         ns++;
          s_chan[ch].spos += s_chan[ch].sinc;
          s_chan[ch].spos += s_chan[ch].sinc;
-
         }
 ENDX:   ;
       }
     }
 
         }
 ENDX:   ;
       }
     }
 
+    if(bIRQReturn)                            // special return for "spu irq - wait for cpu action"
+     {
+      bIRQReturn=0;
+      if(iUseTimer!=2)
+       { 
+        DWORD dwWatchTime=timeGetTime_spu()+2500;
+
+        while(iSpuAsyncWait && !bEndThread && 
+              timeGetTime_spu()<dwWatchTime)
+            usleep(1000L);
+       continue;
+       }
+      else
+       {
+        return 0;
+       }
+     }
+
+
   //---------------------------------------------------//
   //- here we have another 1 ms of sound data
   //---------------------------------------------------//
   //---------------------------------------------------//
   //- here we have another 1 ms of sound data
   //---------------------------------------------------//
@@ -923,10 +925,10 @@ long CALLBACK SPUinit(void)
  pMixIrq = 0;
  memset((void *)s_chan, 0, (MAXCHAN + 1) * sizeof(SPUCHAN));
  pSpuIrq = 0;
  pMixIrq = 0;
  memset((void *)s_chan, 0, (MAXCHAN + 1) * sizeof(SPUCHAN));
  pSpuIrq = 0;
iSPUIRQWait = 1;
//iSPUIRQWait = 0;
  lastch = -1;
 
  lastch = -1;
 
ReadConfig();                                         // read user stuff
//ReadConfigSPU();                                      // read user stuff
  SetupStreams();                                       // prepare streaming
 
  return 0;
  SetupStreams();                                       // prepare streaming
 
  return 0;
@@ -979,7 +981,7 @@ long CALLBACK SPUconfigure(void)
 #ifdef _MACOSX
  DoConfiguration();
 #else
 #ifdef _MACOSX
  DoConfiguration();
 #else
- StartCfgTool("CFG");
+// StartCfgTool("CFG");
 #endif
  return 0;
 }
 #endif
  return 0;
 }
@@ -990,7 +992,7 @@ void CALLBACK SPUabout(void)
 #ifdef _MACOSX
  DoAbout();
 #else
 #ifdef _MACOSX
  DoAbout();
 #else
- StartCfgTool("ABOUT");
+// StartCfgTool("ABOUT");
 #endif
 }
 
 #endif
 }
 
@@ -1008,6 +1010,7 @@ void CALLBACK SPUregisterCDDAVolume(void (CALLBACK *CDDAVcallback)(unsigned shor
 }
 
 // COMMON PLUGIN INFO FUNCS
 }
 
 // COMMON PLUGIN INFO FUNCS
+/*
 char * CALLBACK PSEgetLibName(void)
 {
  return _(libraryName);
 char * CALLBACK PSEgetLibName(void)
 {
  return _(libraryName);
@@ -1027,3 +1030,4 @@ char * SPUgetLibInfos(void)
 {
  return _(libraryInfo);
 }
 {
  return _(libraryInfo);
 }
+*/