You've already forked torvalds-GuitarPedal
mirror of
https://github.com/torvalds/GuitarPedal.git
synced 2026-06-20 05:31:55 +00:00
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>
20 lines
516 B
C
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;
|
|
}
|