Apply perceptual curve to media and emit volume
This commit is contained in:
8
client/src/audio/volume.ts
Normal file
8
client/src/audio/volume.ts
Normal 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user