Apply perceptual curve to media and emit volume

This commit is contained in:
Jage9
2026-02-22 20:42:05 -05:00
parent 6f50169805
commit 1b5acd9381
4 changed files with 14 additions and 6 deletions

View File

@@ -0,0 +1,8 @@
/** Converts a 0-100 slider value into gain using a perceptual smoothstep curve. */
export function volumePercentToGain(value: unknown, fallbackPercent: number): number {
const raw = Number(value);
const normalized = Number.isFinite(raw) ? Math.max(0, Math.min(100, raw)) / 100 : Math.max(0, Math.min(100, fallbackPercent)) / 100;
// Smoothstep keeps 0->0, 50->0.5, 100->1 while easing low/high ranges.
return normalized * normalized * (3 - 2 * normalized);
}