From c84461fb8f9404b2b32d90a649b63b669e1a6bb8 Mon Sep 17 00:00:00 2001 From: Stepan Moskovchenko Date: Tue, 3 Oct 2006 21:09:47 +0000 Subject: More adsr related nonsense, argh! Fix adsr related problem on some notes being stopped instead of looped. Ramping code still not quite right, but dont want to lose this. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11117 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/midi/synth.c | 50 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'apps/plugins/midi/synth.c') diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c index d844cc05ad..95bb88f8c6 100644 --- a/apps/plugins/midi/synth.c +++ b/apps/plugins/midi/synth.c @@ -238,7 +238,7 @@ void setPoint(struct SynthObject * so, int pt) * * Or just move the 1 up one line to optimize a tiny bit. */ -/* so->curRate = so->curRate << 1;*/ + so->curRate = so->curRate << 1; so->targetOffset = so->wf->envOffset[pt]<<(20); @@ -251,9 +251,9 @@ inline void stopVoice(struct SynthObject * so) { if(so->state == STATE_RAMPDOWN) return; + // so->isUsed = 0; so->state = STATE_RAMPDOWN; so->decay = 0; - } signed short int synthVoice(struct SynthObject * so) @@ -277,7 +277,7 @@ signed short int synthVoice(struct SynthObject * so) if(so->decay < 10 && so->decay > -10) so->isUsed = 0; - return so->decay*so->volscale>>14; + return so->decay; } } else /* OK to advance voice */ { @@ -287,13 +287,7 @@ signed short int synthVoice(struct SynthObject * so) cpShifted = so->cp >> FRACTSIZE; //Was 10 - /* Have we overrun? */ - if( (cpShifted >= (wf->numSamples-1))) - { - so->cp -= so->delta; - cpShifted = so->cp >> FRACTSIZE; - stopVoice(so); - } + s2 = getSample((cpShifted)+1, wf); @@ -307,8 +301,8 @@ signed short int synthVoice(struct SynthObject * so) s2=getSample((cpShifted), wf); } else - { - so->delta = -so->delta; + { + so->delta = -so->delta; so->loopDir = LOOPDIR_FORWARD; } } @@ -329,6 +323,20 @@ signed short int synthVoice(struct SynthObject * so) } } + + /* Have we overrun? */ + if( (cpShifted >= (wf->numSamples-1))) + { + so->cp -= so->delta; + + cpShifted = so->cp >> FRACTSIZE; + s2 = getSample((cpShifted)+1, wf); + // if((wf->mode & (28))) + // printf("OV1 (loop 2)"); + stopVoice(so); + } + + /* Better, working, linear interpolation */ s1=getSample((cpShifted), wf); @@ -337,8 +345,10 @@ signed short int synthVoice(struct SynthObject * so) /* ADSR COMMENT WOULD GO FROM HERE.........*/ if(so->curRate == 0) + { stopVoice(so); - +// printf("OV2"); + } if(so->ch != 9 && so->state != STATE_RAMPDOWN) /* Stupid ADSR code... and don't do ADSR for drums */ { @@ -350,7 +360,10 @@ signed short int synthVoice(struct SynthObject * so) if(so->curPoint != 5) setPoint(so, so->curPoint+1); else + { stopVoice(so); +// printf("OV3"); + } } } else { @@ -361,22 +374,29 @@ signed short int synthVoice(struct SynthObject * so) if(so->curPoint != 5) setPoint(so, so->curPoint+1); else + { stopVoice(so); +// printf("OV4"); + } } } } if(so->curOffset < 0) + { stopVoice(so); - +// printf("OV5"); + } s = (s * (so->curOffset >> 22) >> 8); /* need to set ramp beginning */ if(so->state == STATE_RAMPDOWN && so->decay == 0) { - so->decay = s; + so->decay = s*so->volscale>>14; + if(so->decay == 0) + so->decay = 1; /* stupid junk.. */ } -- cgit v1.2.3