/** * Janggi sounds: thick octagonal wooden blocks, so a lower, heavier "clack" than the chess "tok" * (site volume is applied inside feedback.ts). */ import { noise, sfx, tone } from '../../lib/feedback'; import type { JanggiCue } from './fx'; /** A heavy wooden block put down on the board: a low knock plus a short dry crack. */ function clack(delay = 0, pitch = 1, gain = 1): void { tone(330 * pitch, 80, 'triangle', 0.2 * gain, delay, { slideTo: 220 * pitch }); noise(50, 0.11 * gain, delay, 'bandpass', 1250 * pitch, 1.1); noise(18, 0.05 * gain, delay, 'highpass', 3200); } /** Each cue starts `d` ms from now (when the sliding piece lands). */ const PLAY: Record void> = { move: (d) => clack(d), // The piece lands, then the taken block is knocked against it. capture: (d) => { clack(d, 1.08); clack(d + 60, 0.82, 0.75); noise(70, 0.06, d + 70, 'lowpass', 700); }, // 한수쉼: just a light tap on the board edge. pass: (d) => { tone(520, 40, 'triangle', 0.06, d, { slideTo: 420 }); noise(40, 0.03, d, 'bandpass', 1800, 0.8); }, // "장군!": a short rising call. janggun: (d) => { tone(659, 90, 'triangle', 0.1, d + 70); tone(880, 150, 'triangle', 0.09, d + 160); }, // "멍군!": the answer, falling back down. meonggun: (d) => { tone(880, 90, 'triangle', 0.08, d + 70); tone(659, 150, 'triangle', 0.07, d + 160); }, // 빅장: the two 궁 face each other; a small "standoff" figure. bikjang: (d) => [587, 698, 587].forEach((f, i) => tone(f, 110, 'sine', 0.09, d + 260 + i * 100)), // 외통: a low ringing chord as the last move lands (the win / lose jingle comes from the result screen). mate: (d) => { tone(294, 360, 'triangle', 0.12, d + 80); tone(440, 380, 'triangle', 0.08, d + 110); tone(587, 420, 'sine', 0.07, d + 140); }, undo: () => sfx.whoosh(), }; export function playJanggi(cues: JanggiCue[], delayMs = 0): void { for (const c of cues) PLAY[c](delayMs); } /** 상차림 pieces put down one after another. */ export function setupSound(n: number, gapMs: number): void { for (let i = 0; i < Math.min(n, 8); i++) clack(i * gapMs, 1.05 + (i % 2) * 0.06, 0.6); } /** Picking up one of my pieces: a very quiet low tick (lower than chess). */ export const pickSound = () => tone(820, 28, 'triangle', 0.06); /** A tap that does nothing: soft and low. */ export const nopeSound = () => tone(200, 90, 'triangle', 0.06, 0, { slideTo: 160 });