More descriptive variables and comments

This commit is contained in:
Aria 2025-08-29 14:33:14 -05:00
parent 9eeb6da3e6
commit e4070b86f8

View file

@ -936,25 +936,29 @@ class EnvelopeProcessor extends AudioWorkletProcessor {
this.attackStart = 0; this.attackStart = 0;
} }
_shape(u, c) { _warp(phase, curvature, strength = 8) {
if (c === 0) return u; if (phase === 0 || phase === 1) return phase; // fast exit
const k = 8; if (curvature > 0) {
if (c > 0) { // snappier
const p = 1 + k * c; const exp = 1 + strength * curvature;
return 1 - Math.pow(1 - u, p); return 1 - Math.pow(1 - phase, exp);
} else { } else {
const p = 1 + k * -c; // more calm
return Math.pow(u, p); const exp = 1 - strength * curvature;
return Math.pow(phase, exp);
} }
} }
_advance(start, target, time, curve) { _advance(start, target, time, curvature) {
if (time === 0 || start === target) { if (time === 0 || start === target) {
this.val = target; this.val = target;
} else { } else {
const u = Math.min(1, (currentTime - this.beginTime) / time); // We compute our progress through this section of the envelope in time
const us = this._shape(u, curve); // as a `phase` value, which is warped by the curvature, and then used
this.val = start + (target - start) * us; // to compute the value of the envelope at that time
const phase = Math.min(1, (currentTime - this.beginTime) / time);
const phaseWarped = this._warp(phase, curvature);
this.val = start + (target - start) * phaseWarped;
} }
} }