simplify fenv

This commit is contained in:
Felix Roos 2023-09-15 23:37:36 +02:00
parent 88c029202c
commit 9049a8b964

View file

@ -87,18 +87,16 @@ export function createFilter(context, type, frequency, Q, attack, decay, sustain
// Apply ADSR to filter frequency // Apply ADSR to filter frequency
if (fenv !== 0) { if (fenv !== 0) {
let min = 0; let min = frequency;
let max = Math.sign(fenv) * 200 * 2 ** Math.abs(fenv); let max = frequency * 2 ** Math.abs(fenv);
if (max < min) { if (fenv < 0) {
// offset by max: keep range when *penv sign is flipped // flip min max to keep range the same for negative envelope
// comment those lines out to center around cutoff instead peak // comment this out to flip the range as well...
min += Math.abs(max); [min, max] = [max, min];
max += Math.abs(max);
} }
// console.log('min', min, 'max', max);
min = clamp(min + frequency, 0, 20000); min = clamp(min + frequency, 0, 20000);
max = clamp(max + 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); getParamADSR(filter.frequency, attack, decay, sustain, release, min, max, start, end);
return filter; return filter;
} }