 |
Envelope detector
References : Posted by Bram
Notes : Basicaly a one-pole LP filter with different coefficients for attack and release fed by the abs() of the signal. If you don't need different attack and decay settings, just use in->abs()->LP
Code : //attack and release in milliseconds
float ga = (float) exp(-1/(SampleRate*attack));
float gr = (float) exp(-1/(SampleRate*release));
float envelope=0;
for(...)
{
//get your data into 'input'
EnvIn = abs(input);
if(envelope < EnvIn)
{
envelope *= ga;
envelope += (1-ga)*EnvIn;
}
else
{
envelope *= gr;
envelope += (1-gr)*EnvIn;
}
//envelope now contains.........the envelope ;)
} |
Comments
Added on : 15/04/02 by arguru[ AT ]smartelectronix Comment : Nice , just a typo: //attack and release is entered in SECONDS actually in this code ;)
Added on : 17/05/05 by antiprosynthesis[ AT ]gmail[ DOT ]com Comment : // Slightly faster version of the envelope follower using one multiply form.
// attTime and relTime is in seconds
float ga = exp(-1.0f/(sampleRate*attTime));
float gr = exp(-1.0f/(sampleRate*relTime));
float envOut = 0.0f;
for( ... )
{
// get your data into 'input'
envIn = fabs(input);
if( envOut < envIn )
envOut = envIn + ga * (envOut - envIn);
else
envOut = envIn + gr * (envOut - envIn);
// envOut now contains the envelope
}
Added on : 14/11/05 by madgel79[ AT ]nate[ DOT ]com Comment : in my code , attack_coef and release_coef are always '0'.
If I use only 'abs()' , it also work well.
why can it be possible?
Would you please give me some infomation about this problem.
Thanks.
Added on : 19/05/09 by bob[ AT ]yahoob[ DOT ]com Comment : Should use "fabsf" really. :)
|
Add your own comment
Comments are displayed in fixed width, no HTML code allowed! |
|
|
 |
|