Optimisation of the midi player, reducing the number of multiplications and memory accesses inside a very frequently executed loop, also does shifting of the whole sample when synthing is done which improves accurracy slightly, ~10% fewer buffer misses

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14983 a1c6a512-1295-4272-9138-f99709370657
diff --git a/apps/plugins/midi/midiutil.c b/apps/plugins/midi/midiutil.c
index 7cb128f..aba56c5 100644
--- a/apps/plugins/midi/midiutil.c
+++ b/apps/plugins/midi/midiutil.c
@@ -22,8 +22,7 @@
 extern struct plugin_api * rb;
 
 int chVol[16] IBSS_ATTR;       /* Channel volume                */
-int chPanLeft[16] IBSS_ATTR;   /* Channel panning               */
-int chPanRight[16] IBSS_ATTR;
+int chPan[16] IBSS_ATTR;       /* Channel panning               */
 int chPat[16] IBSS_ATTR;                  /* Channel patch                 */
 int chPW[16] IBSS_ATTR;                   /* Channel pitch wheel, MSB only */
 
diff --git a/apps/plugins/midi/midiutil.h b/apps/plugins/midi/midiutil.h
index 6968c83..3604f42 100644
--- a/apps/plugins/midi/midiutil.h
+++ b/apps/plugins/midi/midiutil.h
@@ -152,8 +152,7 @@
 extern struct SynthObject voices[MAX_VOICES];
 
 extern int chVol[16];       /* Channel volume                */
-extern int chPanLeft[16];   /* Channel panning               */
-extern int chPanRight[16];
+extern int chPan[16];       /* Channel panning               */
 extern int chPat[16];       /* Channel patch                 */
 extern int chPW[16];        /* Channel pitch wheel, MSB only */
 
diff --git a/apps/plugins/midi/sequencer.c b/apps/plugins/midi/sequencer.c
index 82da3ef..1a00c07 100644
--- a/apps/plugins/midi/sequencer.c
+++ b/apps/plugins/midi/sequencer.c
@@ -46,15 +46,6 @@
             setVolScale(a);
 }
 
-static inline void setPan(int ch, int pan)
-{
-//    printf("\npanning[%d]  %d ==> %d", ch, chPanRight[ch], pan);
-
-    chPanLeft[ch]=128-pan;
-    chPanRight[ch]=pan;
-}
-
-
 static inline void setPatch(int ch, int pat)
 {
     chPat[ch]=pat;
@@ -286,7 +277,7 @@
                 }
                 case CTRL_PANNING:
                 {
-                    setPan((status_low), d2);
+                    chPan[status_low]=d2;
                     return;
                 }
             }
diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c
index 4936afb..322d0f7 100644
--- a/apps/plugins/midi/synth.c
+++ b/apps/plugins/midi/synth.c
@@ -62,10 +62,9 @@
     for(a=0; a<16; a++)
     {
         chVol[a]=100;            /* Default, not quite full blast.. */
-            chPanLeft[a]=64;     /* Center                          */
-        chPanRight[a]=64;        /* Center                          */
+        chPan[a]=64;             /* Center                          */
         chPat[a]=0;              /* Ac Gr Piano                     */
-        chPW[a]=256;              /* .. not .. bent ?                */
+        chPW[a]=256;             /* .. not .. bent ?                */
     }
     for(a=0; a<128; a++)
     {
diff --git a/apps/plugins/midi/synth.h b/apps/plugins/midi/synth.h
index 223b597..2b7187e 100644
--- a/apps/plugins/midi/synth.h
+++ b/apps/plugins/midi/synth.h
@@ -25,7 +25,7 @@
     int i;
     register int dL=0;
     register int dR=0;
-    register short sample = 0;
+    register int sample = 0;
     register struct SynthObject *voicept=voices;
 
     for(i=MAX_VOICES/2; i > 0; i--)
@@ -33,15 +33,17 @@
         if(voicept->isUsed==1)
         {
             sample = synthVoice(voicept);
-            dL += (sample*chPanLeft[voicept->ch])>>7;
-            dR += (sample*chPanRight[voicept->ch])>>7;
+            dL += sample;
+            sample *= chPan[voicept->ch];
+            dR += sample;
         }
         voicept++;
         if(voicept->isUsed==1)
         {
             sample = synthVoice(voicept);
-            dL += (sample*chPanLeft[voicept->ch])>>7;
-            dR += (sample*chPanRight[voicept->ch])>>7;
+            dL += sample;
+            sample *= chPan[voicept->ch];
+            dR += sample;
         }
         voicept++;
     }
@@ -51,19 +53,22 @@
         if(voicept->isUsed==1)
         {
             sample = synthVoice(voicept);
-            dL += (sample*chPanLeft[voicept->ch])>>7;
-            dR += (sample*chPanRight[voicept->ch])>>7;
+            dL += sample;
+            sample *= chPan[voicept->ch];
+            dR += sample;
         }
         voicept++;
     }
 
-   *mixL=dL;
-   *mixR=dR;
+    dL = (dL << 7) - dR;
+
+    *mixL=dL >> 7;
+    *mixR=dR >> 7;
 
     /* TODO: Automatic Gain Control, anyone? */
     /* Or, should this be implemented on the DSP's output volume instead? */
 
-    return;  /* No more ghetto lowpass filter.. linear intrpolation works well. */
+    return;  /* No more ghetto lowpass filter. Linear interpolation works well. */
 }
 
 static inline struct Event * getEvent(struct Track * tr, int evNum)