From df211c994d2ed795036da9e8a1d831a60df55095 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sat, 16 Sep 2023 00:44:03 +0200 Subject: [PATCH] anchored fenv, more logical with negative values - defaulting to .5 for now... --- packages/superdough/helpers.mjs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/superdough/helpers.mjs b/packages/superdough/helpers.mjs index 45371500..0f50a527 100644 --- a/packages/superdough/helpers.mjs +++ b/packages/superdough/helpers.mjs @@ -87,14 +87,15 @@ export function createFilter(context, type, frequency, Q, attack, decay, sustain // Apply ADSR to filter frequency if (fenv !== 0) { - 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); + let anchor = 0.5; + let offset = fenv * anchor; + let min = 2 ** -offset; + let max = 2 ** (fenv - offset); + min *= frequency; + max *= frequency; + + //console.log('min', min, 'max', max); + min = clamp(min + frequency, 0, 20000); max = clamp(max + frequency, 0, 20000); getParamADSR(filter.frequency, attack, decay, sustain, release, min, max, start, end);