summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2007-10-04 19:36:42 +0000
committerNils Wallménius <nils@rockbox.org>2007-10-04 19:36:42 +0000
commite1940b87b005fdaba38e6230551291001f54e99b (patch)
treed8de240d30e2e497c5822127c20ca4d2b754f437
parentcc5b50b231f53b04d54567489970cdfa0a09e402 (diff)
downloadrockbox-e1940b87b005fdaba38e6230551291001f54e99b.tar.gz
rockbox-e1940b87b005fdaba38e6230551291001f54e99b.zip
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
-rw-r--r--apps/plugins/midi/midiutil.c3
-rw-r--r--apps/plugins/midi/midiutil.h3
-rw-r--r--apps/plugins/midi/sequencer.c11
-rw-r--r--apps/plugins/midi/synth.c5
-rw-r--r--apps/plugins/midi/synth.h25
5 files changed, 20 insertions, 27 deletions
diff --git a/apps/plugins/midi/midiutil.c b/apps/plugins/midi/midiutil.c
index 7cb128fb84..aba56c5a8c 100644
--- a/apps/plugins/midi/midiutil.c
+++ b/apps/plugins/midi/midiutil.c
@@ -22,8 +22,7 @@
22extern struct plugin_api * rb; 22extern struct plugin_api * rb;
23 23
24int chVol[16] IBSS_ATTR; /* Channel volume */ 24int chVol[16] IBSS_ATTR; /* Channel volume */
25int chPanLeft[16] IBSS_ATTR; /* Channel panning */ 25int chPan[16] IBSS_ATTR; /* Channel panning */
26int chPanRight[16] IBSS_ATTR;
27int chPat[16] IBSS_ATTR; /* Channel patch */ 26int chPat[16] IBSS_ATTR; /* Channel patch */
28int chPW[16] IBSS_ATTR; /* Channel pitch wheel, MSB only */ 27int chPW[16] IBSS_ATTR; /* Channel pitch wheel, MSB only */
29 28
diff --git a/apps/plugins/midi/midiutil.h b/apps/plugins/midi/midiutil.h
index 6968c83c9a..3604f422a5 100644
--- a/apps/plugins/midi/midiutil.h
+++ b/apps/plugins/midi/midiutil.h
@@ -152,8 +152,7 @@ void * my_malloc(int size);
152extern struct SynthObject voices[MAX_VOICES]; 152extern struct SynthObject voices[MAX_VOICES];
153 153
154extern int chVol[16]; /* Channel volume */ 154extern int chVol[16]; /* Channel volume */
155extern int chPanLeft[16]; /* Channel panning */ 155extern int chPan[16]; /* Channel panning */
156extern int chPanRight[16];
157extern int chPat[16]; /* Channel patch */ 156extern int chPat[16]; /* Channel patch */
158extern int chPW[16]; /* Channel pitch wheel, MSB only */ 157extern int chPW[16]; /* Channel pitch wheel, MSB only */
159 158
diff --git a/apps/plugins/midi/sequencer.c b/apps/plugins/midi/sequencer.c
index 82da3efbcf..1a00c078c6 100644
--- a/apps/plugins/midi/sequencer.c
+++ b/apps/plugins/midi/sequencer.c
@@ -46,15 +46,6 @@ static inline void setVol(int ch, int vol)
46 setVolScale(a); 46 setVolScale(a);
47} 47}
48 48
49static inline void setPan(int ch, int pan)
50{
51// printf("\npanning[%d] %d ==> %d", ch, chPanRight[ch], pan);
52
53 chPanLeft[ch]=128-pan;
54 chPanRight[ch]=pan;
55}
56
57
58static inline void setPatch(int ch, int pat) 49static inline void setPatch(int ch, int pat)
59{ 50{
60 chPat[ch]=pat; 51 chPat[ch]=pat;
@@ -286,7 +277,7 @@ static void sendEvent(struct Event * ev)
286 } 277 }
287 case CTRL_PANNING: 278 case CTRL_PANNING:
288 { 279 {
289 setPan((status_low), d2); 280 chPan[status_low]=d2;
290 return; 281 return;
291 } 282 }
292 } 283 }
diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c
index 4936afb655..322d0f792d 100644
--- a/apps/plugins/midi/synth.c
+++ b/apps/plugins/midi/synth.c
@@ -62,10 +62,9 @@ int initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
62 for(a=0; a<16; a++) 62 for(a=0; a<16; a++)
63 { 63 {
64 chVol[a]=100; /* Default, not quite full blast.. */ 64 chVol[a]=100; /* Default, not quite full blast.. */
65 chPanLeft[a]=64; /* Center */ 65 chPan[a]=64; /* Center */
66 chPanRight[a]=64; /* Center */
67 chPat[a]=0; /* Ac Gr Piano */ 66 chPat[a]=0; /* Ac Gr Piano */
68 chPW[a]=256; /* .. not .. bent ? */ 67 chPW[a]=256; /* .. not .. bent ? */
69 } 68 }
70 for(a=0; a<128; a++) 69 for(a=0; a<128; a++)
71 { 70 {
diff --git a/apps/plugins/midi/synth.h b/apps/plugins/midi/synth.h
index 223b5974e2..2b7187e819 100644
--- a/apps/plugins/midi/synth.h
+++ b/apps/plugins/midi/synth.h
@@ -25,7 +25,7 @@ static inline void synthSample(int * mixL, int * mixR)
25 int i; 25 int i;
26 register int dL=0; 26 register int dL=0;
27 register int dR=0; 27 register int dR=0;
28 register short sample = 0; 28 register int sample = 0;
29 register struct SynthObject *voicept=voices; 29 register struct SynthObject *voicept=voices;
30 30
31 for(i=MAX_VOICES/2; i > 0; i--) 31 for(i=MAX_VOICES/2; i > 0; i--)
@@ -33,15 +33,17 @@ static inline void synthSample(int * mixL, int * mixR)
33 if(voicept->isUsed==1) 33 if(voicept->isUsed==1)
34 { 34 {
35 sample = synthVoice(voicept); 35 sample = synthVoice(voicept);
36 dL += (sample*chPanLeft[voicept->ch])>>7; 36 dL += sample;
37 dR += (sample*chPanRight[voicept->ch])>>7; 37 sample *= chPan[voicept->ch];
38 dR += sample;
38 } 39 }
39 voicept++; 40 voicept++;
40 if(voicept->isUsed==1) 41 if(voicept->isUsed==1)
41 { 42 {
42 sample = synthVoice(voicept); 43 sample = synthVoice(voicept);
43 dL += (sample*chPanLeft[voicept->ch])>>7; 44 dL += sample;
44 dR += (sample*chPanRight[voicept->ch])>>7; 45 sample *= chPan[voicept->ch];
46 dR += sample;
45 } 47 }
46 voicept++; 48 voicept++;
47 } 49 }
@@ -51,19 +53,22 @@ static inline void synthSample(int * mixL, int * mixR)
51 if(voicept->isUsed==1) 53 if(voicept->isUsed==1)
52 { 54 {
53 sample = synthVoice(voicept); 55 sample = synthVoice(voicept);
54 dL += (sample*chPanLeft[voicept->ch])>>7; 56 dL += sample;
55 dR += (sample*chPanRight[voicept->ch])>>7; 57 sample *= chPan[voicept->ch];
58 dR += sample;
56 } 59 }
57 voicept++; 60 voicept++;
58 } 61 }
59 62
60 *mixL=dL; 63 dL = (dL << 7) - dR;
61 *mixR=dR; 64
65 *mixL=dL >> 7;
66 *mixR=dR >> 7;
62 67
63 /* TODO: Automatic Gain Control, anyone? */ 68 /* TODO: Automatic Gain Control, anyone? */
64 /* Or, should this be implemented on the DSP's output volume instead? */ 69 /* Or, should this be implemented on the DSP's output volume instead? */
65 70
66 return; /* No more ghetto lowpass filter.. linear intrpolation works well. */ 71 return; /* No more ghetto lowpass filter. Linear interpolation works well. */
67} 72}
68 73
69static inline struct Event * getEvent(struct Track * tr, int evNum) 74static inline struct Event * getEvent(struct Track * tr, int evNum)