Skip to content

Commit

Permalink
fixed snare tone issue
Browse files Browse the repository at this point in the history
  • Loading branch information
spiricom committed Dec 4, 2023
1 parent 56fca74 commit 8a600df
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
4 changes: 3 additions & 1 deletion leaf/Inc/leaf-physical.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,15 @@ typedef struct _tSimpleLivingString5
tWavefolder wf2;
tWavefolder wf3;
tWavefolder wf4;
tExpSmooth wlSmooth, prepPosSmooth, prepIndexSmooth;
tExpSmooth wlSmooth, prepPosSmooth, prepIndexSmooth, pluckPosSmooth;
int oversampling;
Lfloat sampleRate;
Lfloat rippleGain;
Lfloat rippleDelay;
Lfloat ff;
Lfloat fb;
Lfloat fbSample1;
Lfloat fbSample2;
} _tSimpleLivingString5;

typedef _tSimpleLivingString5* tSimpleLivingString5;
Expand Down
1 change: 1 addition & 0 deletions leaf/Src/leaf-envelopes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,7 @@ void tSlide_init (tSlide* const sl, Lfloat upSlide, Lfloat downSlide
tSlide_initToPool (sl, upSlide, downSlide, &leaf->mempool);
}

//upslide and downslide are in samples
void tSlide_initToPool (tSlide* const sl, Lfloat upSlide, Lfloat downSlide, tMempool* const mp)
{
_tMempool* m = *mp;
Expand Down
4 changes: 2 additions & 2 deletions leaf/Src/leaf-instruments.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ static Lfloat tone[2];
Lfloat t808Snare_tick(t808Snare* const snareInst)
{
_t808Snare* snare = *snareInst;

Lfloat tone[2];
for (int i = 0; i < 2; i++)
{
tTriangle_setFreq(&snare->tone[i], snare->tone1Freq + (20.0f * tEnvelope_tick(&snare->toneEnvOsc[i])));
Expand Down Expand Up @@ -622,7 +622,7 @@ void t808SnareSmall_setNoiseFilterQ(t808SnareSmall* const snareInst, Lfloat nois
Lfloat t808SnareSmall_tick(t808SnareSmall* const snareInst)
{
_t808SnareSmall* snare = *snareInst;

Lfloat tone[2];
for (int i = 0; i < 2; i++)
{
tPBTriangle_setFreq(&snare->tone[i], snare->tone1Freq + (20.0f * tADSRS_tick(&snare->toneEnvOsc[i])));
Expand Down
36 changes: 26 additions & 10 deletions leaf/Src/leaf-physical.c
Original file line number Diff line number Diff line change
Expand Up @@ -1306,10 +1306,13 @@ void tSimpleLivingString5_initToPool (tSimpleLivingString5* const pl, int ov
p->prepPos = prepPos;
p->prepIndex = prepIndex;
p->pluckPosition = pluckPos;
tExpSmooth_initToPool(&p->prepPosSmooth, prepPos, 0.01f, mp);
tExpSmooth_initToPool(&p->prepIndexSmooth, prepIndex, 0.01f, mp);
tExpSmooth_initToPool(&p->prepPosSmooth, prepPos, 0.002f / oversampling, mp);
tExpSmooth_initToPool(&p->prepIndexSmooth, prepIndex, 0.002f / oversampling, mp);

tExpSmooth_initToPool(&p->wlSmooth, p->sampleRate/freq/2.0f, 0.01f, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
tExpSmooth_initToPool(&p->wlSmooth, p->sampleRate/freq/2.0f, 0.002f / oversampling, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)

tExpSmooth_initToPool(&p->pluckPosSmooth, pluckPos, 0.002f / oversampling, mp);

tLinearDelay_initToPool(&p->delUF,p->waveLengthInSamples, p->maxLength, mp);
tLinearDelay_initToPool(&p->delUB,p->waveLengthInSamples, p->maxLength, mp);
tLinearDelay_initToPool(&p->delLF,p->waveLengthInSamples, p->maxLength, mp);
Expand Down Expand Up @@ -1386,6 +1389,7 @@ void tSimpleLivingString5_free (tSimpleLivingString5* const pl)
tExpSmooth_free(&p->wlSmooth);
tExpSmooth_free(&p->prepIndexSmooth);
tExpSmooth_free(&p->prepPosSmooth);
tExpSmooth_free(&p->pluckPosSmooth);
tLinearDelay_free(&p->delUF);
tLinearDelay_free(&p->delUB);
tLinearDelay_free(&p->delLF);
Expand Down Expand Up @@ -1462,11 +1466,13 @@ void tSimpleLivingString5_setPrepPosition(tSimpleLivingString5* const pl, Lflo
{
_tSimpleLivingString5* p = *pl;
p->prepPos = prepPosition;
tExpSmooth_setDest(&p->prepPosSmooth, prepPosition);
}
void tSimpleLivingString5_setPrepIndex(tSimpleLivingString5* const pl, Lfloat prepIndex)
{
_tSimpleLivingString5* p = *pl;
p->prepIndex = prepIndex;
tExpSmooth_setDest(&p->prepIndexSmooth, prepIndex);
}

void tSimpleLivingString5_setTargetLev(tSimpleLivingString5* const pl, Lfloat targetLev)
Expand Down Expand Up @@ -1502,6 +1508,8 @@ void tSimpleLivingString5_setPluckPosition(tSimpleLivingString5* const pl, Lfl
{
_tSimpleLivingString5* p = *pl;
p->pluckPosition = position;
tExpSmooth_setDest(&p->pluckPosSmooth, position);

}


Expand Down Expand Up @@ -1640,6 +1648,7 @@ Lfloat tSimpleLivingString5_tick(tSimpleLivingString5* const pl, Lfloat input)

//p->changeGainCompensator = 1.0f;
Lfloat wl = tExpSmooth_tick(&p->wlSmooth);

//volatile Lfloat changeInDelayTime = -0.01875f*(wl*0.5f - p->prevDelayLength*0.5f);
//if (changeInDelayTime < -0.1f)
{
Expand All @@ -1649,16 +1658,17 @@ Lfloat tSimpleLivingString5_tick(tSimpleLivingString5* const pl, Lfloat input)
{
// p->changeGainCompensator = 1.0f;
}
Lfloat FLen = wl*(1.0f-p->prepPos);
Lfloat prepPosSmoothed = tExpSmooth_tick(&p->prepPosSmooth);
Lfloat FLen = wl*(1.0f-prepPosSmoothed);
uint32_t FLenInt = (uint32_t)FLen;
Lfloat BLen = wl*p->prepPos;
Lfloat BLen = wl*prepPosSmoothed;
uint32_t BLenInt = (uint32_t)BLen;
tLinearDelay_setDelay(&p->delUF, FLen);
tLinearDelay_setDelay(&p->delUB, BLen);
tLinearDelay_setDelay(&p->delLF, FLen);
tLinearDelay_setDelay(&p->delLB, BLen);

Lfloat pluckPosInSamples = p->pluckPosition * wl;
Lfloat pluckPosSmoothed = tExpSmooth_tick(&p->pluckPosSmooth);
Lfloat pluckPosInSamples = pluckPosSmoothed * wl;
uint32_t pluckPosInSamplesInt = (uint32_t) pluckPosInSamples;
Lfloat alpha = pluckPosInSamples - pluckPosInSamplesInt;

Expand Down Expand Up @@ -1696,9 +1706,14 @@ Lfloat tSimpleLivingString5_tick(tSimpleLivingString5* const pl, Lfloat input)
Lfloat fromLF=tLinearDelay_tickOut(&p->delLF);
Lfloat fromLB=tLinearDelay_tickOut(&p->delLB);
Lfloat fromUB=tLinearDelay_tickOut(&p->delUB);

fromUF = tWavefolder_tick(&p->wf1, fromUF);
fromLB = tWavefolder_tick(&p->wf2, fromLB);
//fromUF = tanhf(p->fbSample1) * p->fb + fromUF*0.1f;
//fromLB = tanhf(p->fbSample2) * p->fb + fromLB*0.1f;
//p->fbSample1 = fromUF;
//p->fbSample2 = fromLB;
//fromUF = fromUF * 1.0f / (1.0f+p->fb);
//fromLB = fromLB * 1.0f / (1.0f+p->fb);
//fromUF = tWavefolder_tick(&p->wf1, fromUF);
//fromLB = tWavefolder_tick(&p->wf2, fromLB);


#if 0
Expand Down Expand Up @@ -1869,6 +1884,7 @@ void tSimpleLivingString5_setSampleRate(tSimpleLivingString5* const pl, Lfloat
void tSimpleLivingString5_setFBAmount(tSimpleLivingString5* const pl, Lfloat fb)
{
_tSimpleLivingString5* p = *pl;
p->fb = fb;
tWavefolder_setFBAmount(&p->wf1, fb);
tWavefolder_setFBAmount(&p->wf2, fb);
}
Expand Down

0 comments on commit 8a600df

Please sign in to comment.