diff options
| author | Nils Wallménius <nils@rockbox.org> | 2007-11-11 01:02:45 +0000 |
|---|---|---|
| committer | Nils Wallménius <nils@rockbox.org> | 2007-11-11 01:02:45 +0000 |
| commit | 0fd4c2e455957ec078425361972003e8c3c50fe4 (patch) | |
| tree | dbd1e43836bf567cf8c5bc1f54c9eb4e3c2a77be /apps/plugins | |
| parent | d185f9eba8706fb2415eb6406a0ffd90113e95da (diff) | |
| download | rockbox-0fd4c2e455957ec078425361972003e8c3c50fe4.zip rockbox-0fd4c2e455957ec078425361972003e8c3c50fe4.tar.gz rockbox-0fd4c2e455957ec078425361972003e8c3c50fe4.tar.bz2 rockbox-0fd4c2e455957ec078425361972003e8c3c50fe4.tar.xz | |
Rearrange logic in the synthVoice loop to do less tests and remove need of a struct member for a small speedup, move some memory lookups out of the loop for a small speedup, further cosmetic changes to the synthVoice function. Change isUsed to a bool for clearer logic and also a tiny speedup
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15563 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
| -rw-r--r-- | apps/plugins/midi/midiplay.c | 2 | ||||
| -rw-r--r-- | apps/plugins/midi/midiutil.h | 5 | ||||
| -rw-r--r-- | apps/plugins/midi/sequencer.c | 11 | ||||
| -rw-r--r-- | apps/plugins/midi/synth.c | 70 |
4 files changed, 43 insertions, 45 deletions
diff --git a/apps/plugins/midi/midiplay.c b/apps/plugins/midi/midiplay.c index cc87463..934cea7 100644 --- a/apps/plugins/midi/midiplay.c +++ b/apps/plugins/midi/midiplay.c @@ -263,7 +263,7 @@ static int midimain(void * filename) { notesUsed = 0; for(a=0; a<MAX_VOICES; a++) - if(voices[a].isUsed == 1) + if(voices[a].isUsed) notesUsed++; tick(); } while(notesUsed == 0); diff --git a/apps/plugins/midi/midiutil.h b/apps/plugins/midi/midiutil.h index dfffe39..f26f120 100644 --- a/apps/plugins/midi/midiutil.h +++ b/apps/plugins/midi/midiutil.h @@ -109,11 +109,12 @@ struct SynthObject int delta; int decay; unsigned int cp; /* unsigned int */ - int state, loopState; - int note, vol, ch, isUsed; + int state; + int note, vol, ch; int curRate, curOffset, targetOffset; int curPoint; signed short int volscale; + bool isUsed; }; struct Event diff --git a/apps/plugins/midi/sequencer.c b/apps/plugins/midi/sequencer.c index 4e6c15f..7847c37 100644 --- a/apps/plugins/midi/sequencer.c +++ b/apps/plugins/midi/sequencer.c @@ -156,7 +156,7 @@ static inline void computeDeltas(int ch) int a=0; for(a = 0; a<MAX_VOICES; a++) { - if(voices[a].isUsed==1 && voices[a].ch == ch) + if(voices[a].isUsed && voices[a].ch == ch) { findDelta(&voices[a], ch, voices[a].note); } @@ -202,7 +202,7 @@ inline void pressNote(int ch, int note, int vol) if(voices[a].ch == ch && voices[a].note == note) break; - if(voices[a].isUsed==0) + if(!voices[a].isUsed) break; } if(a==MAX_VOICES) @@ -227,7 +227,6 @@ inline void pressNote(int ch, int note, int vol) setVolScale(a); - voices[a].loopState=STATE_NONLOOPING; /* * OKAY. Gt = Gus Table value * rf = Root Frequency of wave @@ -239,7 +238,7 @@ inline void pressNote(int ch, int note, int vol) { findDelta(&voices[a], ch, note); /* Turn it on */ - voices[a].isUsed=1; + voices[a].isUsed=true; setPoint(&voices[a], 0); } else { @@ -256,7 +255,7 @@ inline void pressNote(int ch, int note, int vol) wf->mode = wf->mode & (255-28); /* Turn it on */ - voices[a].isUsed=1; + voices[a].isUsed=true; setPoint(&voices[a], 0); } else @@ -411,7 +410,7 @@ void seekBackward(int nsec) { notesUsed = 0; for(a=0; a<MAX_VOICES; a++) - if(voices[a].isUsed == 1) + if(voices[a].isUsed) notesUsed++; tick(); } while(notesUsed == 0); diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c index ca59c76..b2efce1 100644 --- a/apps/plugins/midi/synth.c +++ b/apps/plugins/midi/synth.c @@ -51,7 +51,7 @@ void resetControllers() voices[a].cp=0; voices[a].vol=0; voices[a].ch=0; - voices[a].isUsed=0; + voices[a].isUsed=false; voices[a].note=0; } @@ -271,7 +271,6 @@ inline void stopVoice(struct SynthObject * so) static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned int samples) { struct GWaveform * wf; - register int s; register int s1; register int s2; @@ -279,6 +278,9 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i wf = so->wf; + const unsigned int pan = chPan[so->ch]; + const int volscale = so->volscale; + const int mode_mask24 = wf->mode&24; const int mode_mask28 = wf->mode&28; const int mode_mask_looprev = wf->mode&LOOP_REVERSE; @@ -289,9 +291,8 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i const unsigned int start_loop = wf->startLoop << FRACTSIZE; const int diff_loop = end_loop-start_loop; - while(samples > 0) + while(samples-- > 0) { - samples--; /* Is voice being ramped? */ if(so->state == STATE_RAMPDOWN) { @@ -300,12 +301,12 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i so->decay = so->decay / 2; if(so->decay < 10 && so->decay > -10) - so->isUsed = 0; + so->isUsed = false; s1=so->decay; - s2 = s1*chPan[so->ch]; + s2 = s1*pan; s1 = (s1<<7) -s2; - *(out++)+=(((s1&0x7FFF80) << 9) | ((s2&0x7FFF80) >> 7)); + *(out++)+=((s1 << 9) & 0xFFFF0000) | ((s2 >> 7) &0xFFFF); continue; } } else /* OK to advance voice */ @@ -315,23 +316,8 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i s2 = getSample((cp_temp >> FRACTSIZE)+1, wf); - /* LOOP_REVERSE|LOOP_PINGPONG = 24 */ - if(mode_mask24 && so->loopState == STATE_LOOPING && (cp_temp < start_loop)) + if(mode_mask28 && cp_temp >= end_loop) { - if(mode_mask_looprev) - { - cp_temp += diff_loop; - s2=getSample((cp_temp >> FRACTSIZE), wf); - } - else - { - so->delta = -so->delta; /* At this point cp_temp is wrong. We need to take a step */ - } - } - - if(mode_mask28 && (cp_temp >= end_loop)) - { - so->loopState = STATE_LOOPING; if(!mode_mask24) { cp_temp -= diff_loop; @@ -340,6 +326,20 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i else { so->delta = -so->delta; + + /* LOOP_REVERSE|LOOP_PINGPONG = 24 */ + if(cp_temp < start_loop) /* this appears to never be true in here */ + { + if(mode_mask_looprev) + { + cp_temp += diff_loop; + s2=getSample((cp_temp >> FRACTSIZE), wf); + } + else + { + so->delta = -so->delta; /* At this point cp_temp is wrong. We need to take a step */ + } + } } } @@ -354,12 +354,12 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i /* Better, working, linear interpolation */ s1=getSample((cp_temp >> FRACTSIZE), wf); - s = s1 + ((signed)((s2 - s1) * (cp_temp & ((1<<FRACTSIZE)-1)))>>FRACTSIZE); + s1 +=((signed)((s2 - s1) * (cp_temp & ((1<<FRACTSIZE)-1)))>>FRACTSIZE); if(so->curRate == 0) { stopVoice(so); -// so->isUsed = 0; +// so->isUsed = false; } @@ -404,25 +404,23 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i stopVoice(so); } - s = (s * (so->curOffset >> 22) >> 8); + s1 = s1 * (so->curOffset >> 22) >> 8; + + /* Scaling by channel volume and note volume is done in sequencer.c */ + /* That saves us some multiplication and pointer operations */ + s1 = s1 * volscale >> 14; /* need to set ramp beginning */ if(so->state == STATE_RAMPDOWN && so->decay == 0) { - so->decay = s*so->volscale>>14; + so->decay = s1; if(so->decay == 0) so->decay = 1; /* stupid junk.. */ } - - /* Scaling by channel volume and note volume is done in sequencer.c */ - /* That saves us some multiplication and pointer operations */ - s1=s*so->volscale>>14; - - s2 = s1*chPan[so->ch]; + s2 = s1*pan; s1 = (s1<<7) - s2; - *(out++)+=(((s1&0x7FFF80) << 9) | ((s2&0x7FFF80) >> 7)); - + *(out++)+=((s1 << 9) & 0xFFFF0000) | ((s2 >> 7) &0xFFFF); } so->cp=cp_temp; /* store this again */ @@ -451,7 +449,7 @@ void synthSamples(int32_t *buf_ptr, unsigned int num_samples) for(i=0; i < MAX_VOICES; i++) { voicept=&voices[i]; - if(voicept->isUsed==1) + if(voicept->isUsed) { synthVoice(voicept, samp_buf, num_samples); } |