Envelope Follower for Auto-Wah effect

Hello, I’m trying to develop an Auto-Wah effect for a university course. I’ve done some research about the auto-wah and the way to implement it, but I’m completely stuck to the first step, i.e. the envelope follower. I gave a look to different auto-wah projects on github, and none of them was clear to me. I understand that it tracks the amplitude of the signal, and it’s used by the autowah to modulate the center frequency of the Band-Pass filter. I also understand that it needs attack and release values to control the EF. By looking at other projects, I’ve found that these values are usually initialized in this way (which I do not understand):

a = pow( 0.01, 1.0 / ( attackMs * sampleRate * 0.001 ) );
r = pow( 0.01, 1.0 / ( releaseMs * sampleRate * 0.001 ) );

then for each sample in the buffer, the algorithm is usually something like this:

 double v=fabs(sample);
            if( v>envelope )
                    envelope = a * ( envelope - v ) + v;
            else
                    envelope = r * ( envelope - v ) + v;

Can you help to understand how to design a proper envelop filter? Thank you!

juce::dsp::BallisticsFilter is an example of one. It is a digital branching version, so attack and release phases are completely isolated from one another. In the analogue realm, it’s quite common, especially in cheaper and smaller format devices such as pedals, to have envelop circuits which are not decoupled, and changing either attack or release will effect the other, along with the maximum value it can reach.

I suggest reading this for some more insight:

if you want to write your own envelope follower that’s quite easy. first you recitify the input signal into a new buffer. that means calling abs(x) or x * x on each sample. then you let a single float variable follow that signal. if the envelope is lower than the signal it uses attack, else it uses release. if you consider the sampleRate in calculating atk and rls it will have the same effect on different sampleRates. atk and rls are like weights that define how fast it strives towards the signal. different ways to define in which way an envelope follower approaches the signal, post-saturation/lowpass can also shape its character in meaningful ways