0
mirror of https://github.com/torvalds/GuitarPedal.git synced 2026-06-20 05:31:55 +00:00
Files
Linus Torvalds 78f38416b4 Abstract out the envelope follower code
The noise gate and compressor both had the same envelope code, and I'm
looking at some more users, so let's just abstract it out and make it
more legible in the process.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2026-06-06 12:40:35 -07:00

20 lines
516 B
C

// Simple envelope follower helper
struct envelope {
float value, attack, release;
};
static inline void envelope_init(struct envelope *env, float attack_ms, float release_ms)
{
env->attack = time_constant(attack_ms);
env->release = time_constant(release_ms);
}
static inline float envelope_step(struct envelope *env, float in)
{
float curr = fabsf(in), prev = env->value;
float coef = (curr > prev) ? env->attack : env->release;
float value = linear(coef, curr, prev);
env->value = value;
return value;
}