fix(sounds): fall back to default volume on out-of-range input
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) <noreply@anthropic.com>
This commit is contained in:
@@ -70,9 +70,11 @@ function playChord(frequencies: number[], volume: number, stagger = 0): void {
|
|||||||
function resolveVolume(userVolume: number | undefined, enabled: boolean): number {
|
function resolveVolume(userVolume: number | undefined, enabled: boolean): number {
|
||||||
if (!enabled) return 0;
|
if (!enabled) return 0;
|
||||||
const v = typeof userVolume === "number" ? userVolume : DEFAULT_VOLUME;
|
const v = typeof userVolume === "number" ? userVolume : DEFAULT_VOLUME;
|
||||||
// Clamp: 0 → silent, 1 → loud. Protect against bad settings.
|
if (!Number.isFinite(v) || v <= 0) return 0;
|
||||||
if (v <= 0) return 0;
|
// Any value >1 means a scale drift somewhere upstream (e.g. a 0–100
|
||||||
if (v >= 1) return 1;
|
// 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;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user