mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-11 14:12:26 -05:00
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;
|
struct GWaveform * wf;
|
||||||
int delta;
|
int delta;
|
||||||
int decay;
|
int decay;
|
||||||
unsigned int cp;
|
unsigned int cp; /* unsigned int */
|
||||||
int state, loopState, loopDir;
|
int state, loopState, loopDir;
|
||||||
int note, vol, ch, isUsed;
|
int note, vol, ch, isUsed;
|
||||||
int curRate, curOffset, targetOffset;
|
int curRate, curOffset, targetOffset;
|
||||||
|
|
|
||||||
|
|
@ -119,12 +119,13 @@ long pitchTbl[] ICONST_ATTR={
|
||||||
73297,73330,73363,73396,73429,73462,73495,73528
|
73297,73330,73363,73396,73429,73462,73495,73528
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void findDelta(struct SynthObject * so, int ch, int note)
|
void findDelta(struct SynthObject * so, int ch, int note)
|
||||||
{
|
{
|
||||||
|
|
||||||
struct GWaveform * wf = patchSet[chPat[ch]]->waveforms[patchSet[chPat[ch]]->noteTable[note]];
|
struct GWaveform * wf = patchSet[chPat[ch]]->waveforms[patchSet[chPat[ch]]->noteTable[note]];
|
||||||
so->wf=wf;
|
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 = (((gustable[note]<<FRACTSIZE) / (wf->rootFreq)) * wf->sampRate / (SAMPLE_RATE));
|
||||||
delta = (delta * pitchTbl[chPW[ch]])>> 16;
|
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)
|
void releaseNote(int ch, int note)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(ch==9)
|
if(ch==9)
|
||||||
return;
|
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.
|
* 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);
|
so->targetOffset = so->wf->envOffset[pt]<<(20);
|
||||||
|
|
@ -251,9 +251,9 @@ inline void stopVoice(struct SynthObject * so)
|
||||||
{
|
{
|
||||||
if(so->state == STATE_RAMPDOWN)
|
if(so->state == STATE_RAMPDOWN)
|
||||||
return;
|
return;
|
||||||
|
// so->isUsed = 0;
|
||||||
so->state = STATE_RAMPDOWN;
|
so->state = STATE_RAMPDOWN;
|
||||||
so->decay = 0;
|
so->decay = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signed short int synthVoice(struct SynthObject * so)
|
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)
|
if(so->decay < 10 && so->decay > -10)
|
||||||
so->isUsed = 0;
|
so->isUsed = 0;
|
||||||
|
|
||||||
return so->decay*so->volscale>>14;
|
return so->decay;
|
||||||
}
|
}
|
||||||
} else /* OK to advance voice */
|
} else /* OK to advance voice */
|
||||||
{
|
{
|
||||||
|
|
@ -287,13 +287,7 @@ signed short int synthVoice(struct SynthObject * so)
|
||||||
|
|
||||||
cpShifted = so->cp >> FRACTSIZE; //Was 10
|
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);
|
s2 = getSample((cpShifted)+1, wf);
|
||||||
|
|
||||||
|
|
@ -307,8 +301,8 @@ signed short int synthVoice(struct SynthObject * so)
|
||||||
s2=getSample((cpShifted), wf);
|
s2=getSample((cpShifted), wf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
so->delta = -so->delta;
|
so->delta = -so->delta;
|
||||||
so->loopDir = LOOPDIR_FORWARD;
|
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 */
|
/* Better, working, linear interpolation */
|
||||||
s1=getSample((cpShifted), wf);
|
s1=getSample((cpShifted), wf);
|
||||||
|
|
||||||
|
|
@ -337,8 +345,10 @@ signed short int synthVoice(struct SynthObject * so)
|
||||||
/* ADSR COMMENT WOULD GO FROM HERE.........*/
|
/* ADSR COMMENT WOULD GO FROM HERE.........*/
|
||||||
|
|
||||||
if(so->curRate == 0)
|
if(so->curRate == 0)
|
||||||
|
{
|
||||||
stopVoice(so);
|
stopVoice(so);
|
||||||
|
// printf("OV2");
|
||||||
|
}
|
||||||
|
|
||||||
if(so->ch != 9 && so->state != STATE_RAMPDOWN) /* Stupid ADSR code... and don't do ADSR for drums */
|
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)
|
if(so->curPoint != 5)
|
||||||
setPoint(so, so->curPoint+1);
|
setPoint(so, so->curPoint+1);
|
||||||
else
|
else
|
||||||
|
{
|
||||||
stopVoice(so);
|
stopVoice(so);
|
||||||
|
// printf("OV3");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
|
@ -361,22 +374,29 @@ signed short int synthVoice(struct SynthObject * so)
|
||||||
if(so->curPoint != 5)
|
if(so->curPoint != 5)
|
||||||
setPoint(so, so->curPoint+1);
|
setPoint(so, so->curPoint+1);
|
||||||
else
|
else
|
||||||
|
{
|
||||||
stopVoice(so);
|
stopVoice(so);
|
||||||
|
// printf("OV4");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(so->curOffset < 0)
|
if(so->curOffset < 0)
|
||||||
|
{
|
||||||
stopVoice(so);
|
stopVoice(so);
|
||||||
|
// printf("OV5");
|
||||||
|
}
|
||||||
s = (s * (so->curOffset >> 22) >> 8);
|
s = (s * (so->curOffset >> 22) >> 8);
|
||||||
|
|
||||||
|
|
||||||
/* need to set ramp beginning */
|
/* need to set ramp beginning */
|
||||||
if(so->state == STATE_RAMPDOWN && so->decay == 0)
|
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…
Add table
Add a link
Reference in a new issue