1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Nils Wallménius 2007-10-04 19:36:42 +00:00
parent cc5b50b231
commit e1940b87b0
5 changed files with 20 additions and 27 deletions

View file

@ -22,8 +22,7 @@
extern struct plugin_api * rb; extern struct plugin_api * rb;
int chVol[16] IBSS_ATTR; /* Channel volume */ int chVol[16] IBSS_ATTR; /* Channel volume */
int chPanLeft[16] IBSS_ATTR; /* Channel panning */ int chPan[16] IBSS_ATTR; /* Channel panning */
int chPanRight[16] IBSS_ATTR;
int chPat[16] IBSS_ATTR; /* Channel patch */ int chPat[16] IBSS_ATTR; /* Channel patch */
int chPW[16] IBSS_ATTR; /* Channel pitch wheel, MSB only */ int chPW[16] IBSS_ATTR; /* Channel pitch wheel, MSB only */

View file

@ -152,8 +152,7 @@ void * my_malloc(int size);
extern struct SynthObject voices[MAX_VOICES]; extern struct SynthObject voices[MAX_VOICES];
extern int chVol[16]; /* Channel volume */ extern int chVol[16]; /* Channel volume */
extern int chPanLeft[16]; /* Channel panning */ extern int chPan[16]; /* Channel panning */
extern int chPanRight[16];
extern int chPat[16]; /* Channel patch */ extern int chPat[16]; /* Channel patch */
extern int chPW[16]; /* Channel pitch wheel, MSB only */ extern int chPW[16]; /* Channel pitch wheel, MSB only */

View file

@ -46,15 +46,6 @@ static inline void setVol(int ch, int vol)
setVolScale(a); 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) static inline void setPatch(int ch, int pat)
{ {
chPat[ch]=pat; chPat[ch]=pat;
@ -286,7 +277,7 @@ static void sendEvent(struct Event * ev)
} }
case CTRL_PANNING: case CTRL_PANNING:
{ {
setPan((status_low), d2); chPan[status_low]=d2;
return; return;
} }
} }

View file

@ -62,10 +62,9 @@ int initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
for(a=0; a<16; a++) for(a=0; a<16; a++)
{ {
chVol[a]=100; /* Default, not quite full blast.. */ chVol[a]=100; /* Default, not quite full blast.. */
chPanLeft[a]=64; /* Center */ chPan[a]=64; /* Center */
chPanRight[a]=64; /* Center */
chPat[a]=0; /* Ac Gr Piano */ chPat[a]=0; /* Ac Gr Piano */
chPW[a]=256; /* .. not .. bent ? */ chPW[a]=256; /* .. not .. bent ? */
} }
for(a=0; a<128; a++) for(a=0; a<128; a++)
{ {

View file

@ -25,7 +25,7 @@ static inline void synthSample(int * mixL, int * mixR)
int i; int i;
register int dL=0; register int dL=0;
register int dR=0; register int dR=0;
register short sample = 0; register int sample = 0;
register struct SynthObject *voicept=voices; register struct SynthObject *voicept=voices;
for(i=MAX_VOICES/2; i > 0; i--) for(i=MAX_VOICES/2; i > 0; i--)
@ -33,15 +33,17 @@ static inline void synthSample(int * mixL, int * mixR)
if(voicept->isUsed==1) if(voicept->isUsed==1)
{ {
sample = synthVoice(voicept); sample = synthVoice(voicept);
dL += (sample*chPanLeft[voicept->ch])>>7; dL += sample;
dR += (sample*chPanRight[voicept->ch])>>7; sample *= chPan[voicept->ch];
dR += sample;
} }
voicept++; voicept++;
if(voicept->isUsed==1) if(voicept->isUsed==1)
{ {
sample = synthVoice(voicept); sample = synthVoice(voicept);
dL += (sample*chPanLeft[voicept->ch])>>7; dL += sample;
dR += (sample*chPanRight[voicept->ch])>>7; sample *= chPan[voicept->ch];
dR += sample;
} }
voicept++; voicept++;
} }
@ -51,19 +53,22 @@ static inline void synthSample(int * mixL, int * mixR)
if(voicept->isUsed==1) if(voicept->isUsed==1)
{ {
sample = synthVoice(voicept); sample = synthVoice(voicept);
dL += (sample*chPanLeft[voicept->ch])>>7; dL += sample;
dR += (sample*chPanRight[voicept->ch])>>7; sample *= chPan[voicept->ch];
dR += sample;
} }
voicept++; voicept++;
} }
*mixL=dL; dL = (dL << 7) - dR;
*mixR=dR;
*mixL=dL >> 7;
*mixR=dR >> 7;
/* TODO: Automatic Gain Control, anyone? */ /* TODO: Automatic Gain Control, anyone? */
/* Or, should this be implemented on the DSP's output volume instead? */ /* 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) static inline struct Event * getEvent(struct Track * tr, int evNum)