Page 1 of 1

Fade In LFO - Best Technique

Posted: Thu Jul 17, 2014 2:59 pm
by Tronic
Which technique you use to implement a fade-in to a LFO?
The concept would be to have a single envelope with attack and control the amplitude-stream of the LFO,
but as you well know to implement an envelope is always linked to a stressful computing for CPU,
you know or use other techniques to do this?

Re: Fade In LFO - Best Technique

Posted: Thu Jul 17, 2014 4:58 pm
by Exo
For a synth?
Something like this should be enough....

Code: Select all

streamin lfo;
streamin fadeInTime;
streamin sampleRate;
streamout fadeInLfo;
float increment;
float fadeIn;
stage(0)
{
   increment = fadeInTime / sampleRate ;
   fadeIn = 0; //reset for every new voice
}

fadeInLfo = fadeIn * lfo;

fadeIn = min(fadeIn + increment, 1);
   


That should work for you. I don't think there is a simpler way than that.

Re: Fade In LFO - Best Technique

Posted: Thu Jul 17, 2014 5:37 pm
by KG_is_back
Or alternatively you may use exponential fade in (basically the same idea of implementation as Exo's but different envelope shape)

Code: Select all

streamin lfo;
streamin fadeCoeff; //this is number usually around 0.9 (always 0-1 range)
streamout out;

float cut=1;

out=lfo*(1-cut); //cut is 1 on start and decays to zero over time

cut= cut*fadeCoeff; //fade coeff controls how fast cud decays


fadeCoef has to be calculated too. Generally it is e^(-1/T) where T is release time in samples.

Note that Release time is not the time it takes for the decay to reach 0, but 0.3679 instead. (exponential curve never really reaches 0).
Exponential curves often sound more natural to human eat than linear.

Re: Fade In LFO - Best Technique

Posted: Fri Jul 18, 2014 6:33 pm
by Tronic
Thx for this code hint.