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
This commit is contained in:
parent
f5a3569899
commit
c84461fb8f
3 changed files with 40 additions and 18 deletions
|
@ -124,7 +124,7 @@ struct SynthObject
|
|||
struct GWaveform * wf;
|
||||
int delta;
|
||||
int decay;
|
||||
unsigned int cp;
|
||||
unsigned int cp; /* unsigned int */
|
||||
int state, loopState, loopDir;
|
||||
int note, vol, ch, isUsed;
|
||||
int curRate, curOffset, targetOffset;
|
||||
|
|
|
@ -119,12 +119,13 @@ long pitchTbl[] ICONST_ATTR={
|
|||
73297,73330,73363,73396,73429,73462,73495,73528
|
||||
};
|
||||
|
||||
|
||||
void findDelta(struct SynthObject * so, int ch, int note)
|
||||
{
|
||||
|
||||
struct GWaveform * wf = patchSet[chPat[ch]]->waveforms[patchSet[chPat[ch]]->noteTable[note]];
|
||||
so->wf=wf;
|
||||
unsigned long delta= 0; /* More percision- extra bit - not so off-key as before */
|
||||
unsigned int delta= 0;
|
||||
|
||||
delta = (((gustable[note]<<FRACTSIZE) / (wf->rootFreq)) * wf->sampRate / (SAMPLE_RATE));
|
||||
delta = (delta * pitchTbl[chPW[ch]])>> 16;
|
||||
|
@ -248,10 +249,11 @@ void pressNote(int ch, int note, int vol)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void stopVoice(struct SynthObject * so);
|
||||
|
||||
void releaseNote(int ch, int note)
|
||||
{
|
||||
|
||||
if(ch==9)
|
||||
return;
|
||||
|
||||
|
|
|
@ -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.. */
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue