전체 소리 2배: 음량 50이 예전 100 크기로 나오도록 마스터 게인을 음량×2로
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -90,7 +90,12 @@ test('chat sound follows the volume setting and is silent when sound is off', as
|
||||
setVolume(50);
|
||||
chatSound();
|
||||
expect(notes.length).toBeGreaterThan(0);
|
||||
expect(master!.value).toBe(0.5);
|
||||
expect(master!.value).toBe(1); // the default 50 plays sounds at their written level
|
||||
notes = [];
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
setVolume(100);
|
||||
chatSound();
|
||||
expect(master!.value).toBe(2); // 100 is twice as loud
|
||||
notes = [];
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
setVolume(50, false);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/**
|
||||
* Synthesized sounds + vibration (no audio files; docs/07 §6).
|
||||
* Every sound goes through one master gain set from the site volume (0~100, default 50; the old sounds at full level
|
||||
* are now volume 100, so the default plays them at half). Games use `sfx.*` (shared palette) or `tone`/`noise`
|
||||
* Every sound goes through one master gain set from the site volume (0~100, default 50). The master gain is
|
||||
* `MASTER_BOOST` × volume, so the default 50 plays the sounds at their written level and 100 plays them twice as loud.
|
||||
* Games use `sfx.*` (shared palette) or `tone`/`noise`
|
||||
* directly for something of their own.
|
||||
*/
|
||||
import { useEffect, useRef } from 'react';
|
||||
@@ -10,6 +11,8 @@ import { useSession } from '../store/session';
|
||||
|
||||
let ctx: AudioContext | null = null;
|
||||
let master: GainNode | null = null;
|
||||
/** Master gain at volume 100 (2 → volume 50 plays every sound at its written level, 100 at double). */
|
||||
export const MASTER_BOOST = 2;
|
||||
|
||||
/** 0~1 from the settings (0 when sound is off). */
|
||||
export function volume01(): number {
|
||||
@@ -28,7 +31,7 @@ function audio(): { a: AudioContext; out: GainNode } | null {
|
||||
master = ctx.createGain();
|
||||
master.connect(ctx.destination);
|
||||
}
|
||||
master.gain.value = v;
|
||||
master.gain.value = v * MASTER_BOOST;
|
||||
return { a: ctx, out: master };
|
||||
} catch {
|
||||
return null;
|
||||
@@ -42,7 +45,7 @@ export interface ToneOpts {
|
||||
attack?: number;
|
||||
}
|
||||
|
||||
/** One enveloped oscillator note. `gain` is the level at volume 100. */
|
||||
/** One enveloped oscillator note. `gain` is the level at volume 50 (the default). */
|
||||
export function tone(freq: number, ms: number, type: OscillatorType = 'sine', gain = 0.15, delay = 0, opts: ToneOpts = {}): void {
|
||||
const au = audio();
|
||||
if (!au) return;
|
||||
@@ -189,7 +192,7 @@ export const sounds = {
|
||||
buzz: () => tone(180, 260, 'square', 0.08),
|
||||
};
|
||||
|
||||
/** The usual level of a game sound at volume 100 (`tone`'s default). */
|
||||
/** The usual level of a game sound at volume 50 (`tone`'s default). */
|
||||
export const GAME_LEVEL = 0.15;
|
||||
/** Chat sound in % of a game sound (admin setting `chatSound`, 0~200, default 80); it also follows the volume setting. */
|
||||
let chatPercent = CHAT_SOUND_DEFAULT;
|
||||
@@ -197,7 +200,7 @@ let chatPercent = CHAT_SOUND_DEFAULT;
|
||||
export function setChatSound(x: unknown): void {
|
||||
chatPercent = clampChatSound(x);
|
||||
}
|
||||
/** Peak level of the chat sound at volume 100 (`percent`: the admin setting unless previewing another value). */
|
||||
/** Peak level of the chat sound at volume 50 (`percent`: the admin setting unless previewing another value). */
|
||||
export const chatLevel = (percent = chatPercent): number => (GAME_LEVEL * clampChatSound(percent)) / 100;
|
||||
let lastChatAt = -Infinity;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user