/** Gain curve for a musical fade-out: cos², so -6 dB at the midpoint and the drop concentrated at the end. */ export function fadeCurve(from: number, n = 128): Float32Array { const c = new Float32Array(n); for (let i = 0; i < n; i++) c[i] = from * Math.cos((Math.PI / 2) * (i / (n - 1))) ** 2; return c; }