From 9049a8b964d277d60071667a247ed37e77d42736 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Fri, 15 Sep 2023 23:37:36 +0200 Subject: [PATCH] simplify fenv --- packages/superdough/helpers.mjs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/superdough/helpers.mjs b/packages/superdough/helpers.mjs index b6530343..45371500 100644 --- a/packages/superdough/helpers.mjs +++ b/packages/superdough/helpers.mjs @@ -87,18 +87,16 @@ export function createFilter(context, type, frequency, Q, attack, decay, sustain // Apply ADSR to filter frequency if (fenv !== 0) { - let min = 0; - let max = Math.sign(fenv) * 200 * 2 ** Math.abs(fenv); - if (max < min) { - // offset by max: keep range when *penv sign is flipped - // comment those lines out to center around cutoff instead peak - min += Math.abs(max); - max += Math.abs(max); + let min = frequency; + let max = frequency * 2 ** Math.abs(fenv); + if (fenv < 0) { + // flip min max to keep range the same for negative envelope + // comment this out to flip the range as well... + [min, max] = [max, min]; } - + // console.log('min', min, 'max', max); min = clamp(min + frequency, 0, 20000); max = clamp(max + frequency, 0, 20000); - // console.log('min', min, 'max', max); getParamADSR(filter.frequency, attack, decay, sustain, release, min, max, start, end); return filter; }