From 5c17544a63788dcd28217b8fad0272c13d67c405 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 21 Apr 2026 17:32:51 +0100 Subject: [PATCH] fix(sounds): fall back to default volume on out-of-range input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolveVolume previously clamped any value >=1 to full blast. If a future settings change ever leaks a 0–100 scale through (instead of 0–1), the user gets jump-scared at max volume. Treat any v>1 as a scale-drift bug and play at DEFAULT_VOLUME instead. Also reject NaN / Infinity explicitly rather than relying on the <=0 branch catching them. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/lib/utils/sounds.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/utils/sounds.ts b/src/lib/utils/sounds.ts index c08b8c3..0de8ef8 100644 --- a/src/lib/utils/sounds.ts +++ b/src/lib/utils/sounds.ts @@ -70,9 +70,11 @@ function playChord(frequencies: number[], volume: number, stagger = 0): void { function resolveVolume(userVolume: number | undefined, enabled: boolean): number { if (!enabled) return 0; const v = typeof userVolume === "number" ? userVolume : DEFAULT_VOLUME; - // Clamp: 0 → silent, 1 → loud. Protect against bad settings. - if (v <= 0) return 0; - if (v >= 1) return 1; + if (!Number.isFinite(v) || v <= 0) return 0; + // Any value >1 means a scale drift somewhere upstream (e.g. a 0–100 + // slider leaking through unscaled). Clamping to 1 would blast the + // user at full volume; fall back to DEFAULT_VOLUME instead. + if (v > 1) return DEFAULT_VOLUME; return v; }