Merge pull request 'simplify envValAtTime and remove asymmetric behavior (fix #1653)' (#1815) from pulu/strudel:remove-env-asymmetry into main

Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1815
This commit is contained in:
froos 2025-12-20 22:20:26 +01:00
commit 3922defab9

View file

@ -42,6 +42,7 @@ export const getParamADSR = (
decay, decay,
sustain, sustain,
release, release,
// min = value at start of attack, max = value at end of attack; it is possible that max < min
min, min,
max, max,
begin, begin,
@ -59,17 +60,15 @@ export const getParamADSR = (
max = max === 0 ? 0.001 : max; max = max === 0 ? 0.001 : max;
} }
const range = max - min; const range = max - min;
const peak = max;
const sustainVal = min + sustain * range; const sustainVal = min + sustain * range;
const duration = end - begin; const duration = end - begin;
const envValAtTime = (time) => { const envValAtTime = (time) => {
let val; let val;
if (attack > time) { if (attack > time) {
let slope = getSlope(min, peak, 0, attack); val = time * getSlope(min, max, 0, attack) + min;
val = time * slope + (min > peak ? min : 0);
} else { } else {
val = (time - attack) * getSlope(peak, sustainVal, 0, decay) + peak; val = (time - attack) * getSlope(max, sustainVal, 0, decay) + max;
} }
if (curve === 'exponential') { if (curve === 'exponential') {
val = val || 0.001; val = val || 0.001;