Skip to content

Commit c9e8eb7

Browse files
Merge pull request #35 from kchrzanowski3/feat/louder-tv-alerts
feat(thanksgiving): louder broadcast TV alert fanfares + Turducken mode
2 parents 45e179f + 7232861 commit c9e8eb7

6 files changed

Lines changed: 269 additions & 48 deletions

File tree

‎docs/thanksgiving-spec.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ the browser allows it); "Exit full screen" or Esc closes it. Nothing is tucked a
228228
- A persistent **Last Big Play** strip below the score header that stays up until replaced by the next big play
229229
(scoring plays, banked categories, turnovers, 3-point category lead changes, overall 1st-place changes, or Game
230230
Final), paired with brief green/blue row flashes in the category table, `▲` rank-up pulses in the standings, and
231-
an optional **Muted / Sound on** Web Audio chime toggle in the top bar (muted by default; chimes on banked points
232-
and Game Final).
231+
an optional **Muted / Sound on** broadcast horn & chime toggle in the top bar (muted by default; plays loud
232+
distinct fanfares on every TV alert, with an optional **Turducken** gobble + callout toggle when sound is on).
233233
- A table of every category: its full name, worth ("3 pts"), the value so far, **every player who's right, by
234234
name**, and its status (check Final / circle Live).
235235
- The overall standings in a box at the right, sized to its content: rank, player, **Live** and **✓ Banked**

‎src/components/thanksgiving/TvView.tsx‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { useEffect, useRef, useState } from 'react';
66
import type { GameAlert } from '../../lib/thanksgiving/alerts';
77
import type { CategoryKey, Standings as StandingsData } from '../../lib/thanksgiving/scoring';
8-
import { playChime } from '../../lib/thanksgiving/sound';
8+
import { alertChimeKind, playChime } from '../../lib/thanksgiving/sound';
99
import { formatPoints } from '../../lib/thanksgiving/projection';
1010
import { etDateTime } from '../../lib/thanksgiving/config';
1111
import {
@@ -80,17 +80,17 @@ export function TvView({
8080
const root = useRef<HTMLDivElement>(null);
8181
const [sortBy, setSortBy] = useState<StandingsSort>('live');
8282
const [soundOn, setSoundOn] = useState(false);
83+
const [turduckenMode, setTurduckenMode] = useState(false);
8384
const lastChimedId = useRef<string | null>(latestAlert?.id ?? null);
8485
useWakeLock();
8586

86-
// Play a subtle chime (only when user unmuted) on banked points or Game Final.
87+
// Play a loud broadcast fanfare (when unmuted) on every TV play alert.
8788
useEffect(() => {
8889
if (!latestAlert || latestAlert.id === lastChimedId.current) return;
8990
lastChimedId.current = latestAlert.id;
9091
if (!soundOn) return;
91-
if (latestAlert.kind === 'final') playChime('final');
92-
else if (latestAlert.banked.length > 0) playChime('banked');
93-
}, [latestAlert, soundOn]);
92+
playChime(alertChimeKind(latestAlert), { turducken: turduckenMode });
93+
}, [latestAlert, soundOn, turduckenMode]);
9494

9595
// Full screen when the browser allows it; leaving full screen (Esc) closes the scoreboard.
9696
useEffect(() => {
@@ -128,7 +128,15 @@ export function TvView({
128128
const toggleSound = () => {
129129
setSoundOn((prev) => {
130130
const next = !prev;
131-
if (next) playChime('confirm');
131+
if (next) playChime('confirm', { turducken: turduckenMode });
132+
return next;
133+
});
134+
};
135+
136+
const toggleTurducken = () => {
137+
setTurduckenMode((prev) => {
138+
const next = !prev;
139+
if (next) playChime('confirm', { turducken: true });
132140
return next;
133141
});
134142
};
@@ -175,11 +183,23 @@ export function TvView({
175183
aria-pressed={soundOn}
176184
onClick={toggleSound}
177185
data-testid="tg-tv-sound-toggle"
178-
title={soundOn ? 'Chime enabled on banked points and game final' : 'Enable chime on banked points and game final'}
186+
title={soundOn ? 'Broadcast alerts enabled on all TV notifications' : 'Enable loud broadcast sound on TV notifications'}
179187
>
180188
<SoundIcon muted={!soundOn} size={15} />
181189
<span>{soundOn ? 'Sound on' : 'Muted'}</span>
182190
</button>
191+
{soundOn && (
192+
<button
193+
type="button"
194+
className={turduckenMode ? 'tg-tv-control tg-tv-turducken-on' : 'tg-tv-control'}
195+
aria-pressed={turduckenMode}
196+
onClick={toggleTurducken}
197+
data-testid="tg-tv-turducken-toggle"
198+
title="Add a turkey gobble and 'Boom! Turducken!' callout to TV alerts"
199+
>
200+
<span>{turduckenMode ? 'Turducken: ON' : 'Turducken'}</span>
201+
</button>
202+
)}
183203
<button type="button" className="tg-tv-exit" onClick={onExit}>Exit full screen</button>
184204
</div>
185205
</header>

‎src/lib/thanksgiving/sound.ts‎

Lines changed: 219 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,237 @@
1-
// Subtle Web Audio chimes for the TV scoreboard (no audio files or external requests).
2-
// Only plays when the user explicitly enables sound in the TV header.
1+
// Loud, broadcast-style Web Audio fanfares for the TV scoreboard (no external audio files).
2+
// Built with a dynamics compressor + bright brass/chime harmonics so alerts cut through a loud
3+
// TV and Thanksgiving living room. Only plays when sound is enabled in the TV header.
34

4-
export type ChimeKind = 'banked' | 'final' | 'confirm';
5+
export type ChimeKind = 'confirm' | 'swing' | 'scoring' | 'banked' | 'final';
6+
7+
export interface ChimeOptions {
8+
/** Adds a turkey gobble + enthusiastic "BOOM! Turducken!" callout via Web Speech. */
9+
turducken?: boolean;
10+
}
511

612
let sharedCtx: AudioContext | null = null;
13+
let masterBus: AudioNode | null = null;
714

8-
function audioContext(): AudioContext | null {
15+
function audioGraph(): { ctx: AudioContext; out: AudioNode } | null {
916
if (typeof window === 'undefined') return null;
1017
const Ctor = window.AudioContext ?? (window as unknown as { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;
1118
if (!Ctor) return null;
1219
try {
13-
if (!sharedCtx) sharedCtx = new Ctor();
20+
if (!sharedCtx) {
21+
sharedCtx = new Ctor();
22+
const comp = sharedCtx.createDynamicsCompressor();
23+
comp.threshold.value = -14;
24+
comp.knee.value = 10;
25+
comp.ratio.value = 8;
26+
comp.attack.value = 0.003;
27+
comp.release.value = 0.14;
28+
29+
const master = sharedCtx.createGain();
30+
master.gain.value = 0.92;
31+
comp.connect(master);
32+
master.connect(sharedCtx.destination);
33+
masterBus = comp;
34+
}
1435
if (sharedCtx.state === 'suspended') void sharedCtx.resume().catch(() => {});
15-
return sharedCtx;
36+
return { ctx: sharedCtx, out: masterBus! };
1637
} catch {
1738
return null;
1839
}
1940
}
2041

21-
const NOTES: Record<ChimeKind, { freq: number; delay: number; duration: number; gain: number }[]> = {
22-
// Soft single-note click confirmation when unmuting.
23-
confirm: [{ freq: 587.33, delay: 0, duration: 0.16, gain: 0.08 }], // D5
24-
// Crisp two-note upward fifth when points get banked mid-game.
25-
banked: [
26-
{ freq: 523.25, delay: 0, duration: 0.22, gain: 0.1 }, // C5
27-
{ freq: 783.99, delay: 0.11, duration: 0.34, gain: 0.11 }, // G5
28-
],
29-
// Warm three-note major triad when a game goes final.
30-
final: [
31-
{ freq: 523.25, delay: 0, duration: 0.22, gain: 0.1 }, // C5
32-
{ freq: 659.25, delay: 0.11, duration: 0.24, gain: 0.1 }, // E5
33-
{ freq: 783.99, delay: 0.22, duration: 0.44, gain: 0.12 }, // G5
34-
],
35-
};
36-
37-
/** Plays a soft chime; safe no-op when audio is unsupported or blocked. */
38-
export function playChime(kind: ChimeKind): void {
39-
const ctx = audioContext();
40-
if (!ctx) return;
42+
/** Punchy NFL-broadcast-style brass horn note (detuned saws + sub square through a bright filter sweep). */
43+
function brassNote(ctx: AudioContext, out: AudioNode, freq: number, start: number, duration: number, level = 0.55): void {
44+
const filter = ctx.createBiquadFilter();
45+
filter.type = 'lowpass';
46+
filter.Q.value = 2.4;
47+
filter.frequency.setValueAtTime(900, start);
48+
filter.frequency.exponentialRampToValueAtTime(3800, start + 0.045);
49+
filter.frequency.exponentialRampToValueAtTime(2100, start + duration);
50+
51+
const env = ctx.createGain();
52+
env.gain.setValueAtTime(0.0001, start);
53+
env.gain.linearRampToValueAtTime(level, start + 0.018);
54+
env.gain.setValueAtTime(level * 0.88, start + Math.max(0.03, duration * 0.65));
55+
env.gain.exponentialRampToValueAtTime(0.0001, start + duration);
56+
57+
filter.connect(env);
58+
env.connect(out);
59+
60+
const voices: { type: OscillatorType; mult: number; detune: number; gain: number }[] = [
61+
{ type: 'sawtooth', mult: 1, detune: -7, gain: 0.45 },
62+
{ type: 'sawtooth', mult: 1, detune: 7, gain: 0.45 },
63+
{ type: 'square', mult: 0.5, detune: 0, gain: 0.35 },
64+
];
65+
66+
for (const v of voices) {
67+
const osc = ctx.createOscillator();
68+
const vg = ctx.createGain();
69+
osc.type = v.type;
70+
osc.frequency.setValueAtTime(freq * v.mult, start);
71+
osc.detune.setValueAtTime(v.detune, start);
72+
vg.gain.value = v.gain;
73+
osc.connect(vg);
74+
vg.connect(filter);
75+
osc.start(start);
76+
osc.stop(start + duration + 0.03);
77+
}
78+
}
79+
80+
/** Crisp high-presence broadcast chime / bell hit that cuts cleanly over room chatter. */
81+
function bellNote(ctx: AudioContext, out: AudioNode, freq: number, start: number, duration: number, level = 0.42): void {
82+
const partials: { mult: number; gain: number; decay: number }[] = [
83+
{ mult: 1, gain: 1.0, decay: duration },
84+
{ mult: 2, gain: 0.48, decay: duration * 0.72 },
85+
{ mult: 2.756, gain: 0.25, decay: duration * 0.45 },
86+
];
87+
for (const p of partials) {
88+
const osc = ctx.createOscillator();
89+
const env = ctx.createGain();
90+
osc.type = p.mult === 1 ? 'triangle' : 'sine';
91+
osc.frequency.setValueAtTime(freq * p.mult, start);
92+
env.gain.setValueAtTime(0.0001, start);
93+
env.gain.linearRampToValueAtTime(level * p.gain, start + 0.008);
94+
env.gain.exponentialRampToValueAtTime(0.0001, start + p.decay);
95+
osc.connect(env);
96+
env.connect(out);
97+
osc.start(start);
98+
osc.stop(start + p.decay + 0.02);
99+
}
100+
}
101+
102+
/** Synthesized loud turkey gobble (rapid FM wobble through a nasal vocal formant filter). */
103+
function playGobble(ctx: AudioContext, out: AudioNode, start: number): void {
104+
const duration = 0.58;
105+
const carrier = ctx.createOscillator();
106+
carrier.type = 'sawtooth';
107+
carrier.frequency.setValueAtTime(780, start);
108+
carrier.frequency.exponentialRampToValueAtTime(520, start + duration);
109+
110+
const lfo = ctx.createOscillator();
111+
lfo.type = 'sine';
112+
lfo.frequency.setValueAtTime(17, start);
113+
const lfoDepth = ctx.createGain();
114+
lfoDepth.gain.setValueAtTime(145, start);
115+
lfo.connect(lfoDepth);
116+
lfoDepth.connect(carrier.frequency);
117+
118+
const formant = ctx.createBiquadFilter();
119+
formant.type = 'bandpass';
120+
formant.frequency.setValueAtTime(1250, start);
121+
formant.Q.value = 3.2;
122+
123+
const env = ctx.createGain();
124+
env.gain.setValueAtTime(0.0001, start);
125+
env.gain.linearRampToValueAtTime(0.75, start + 0.03);
126+
env.gain.setValueAtTime(0.68, start + duration * 0.72);
127+
env.gain.exponentialRampToValueAtTime(0.0001, start + duration);
128+
129+
carrier.connect(formant);
130+
formant.connect(env);
131+
env.connect(out);
132+
133+
carrier.start(start);
134+
lfo.start(start);
135+
carrier.stop(start + duration + 0.03);
136+
lfo.stop(start + duration + 0.03);
137+
}
138+
139+
/** Enthusiastic Web Speech shout for Turducken mode (safe no-op if unsupported). */
140+
function speakTurducken(kind: ChimeKind): void {
141+
if (typeof window === 'undefined' || typeof window.speechSynthesis === 'undefined') return;
142+
try {
143+
const phrase =
144+
kind === 'final'
145+
? 'Boom! Game over! Turducken!'
146+
: kind === 'banked' || kind === 'scoring' || kind === 'confirm'
147+
? 'Boom! Turducken!'
148+
: 'Turducken!';
149+
window.speechSynthesis.cancel();
150+
const utter = new SpeechSynthesisUtterance(phrase);
151+
utter.volume = 1;
152+
utter.rate = 1.05;
153+
utter.pitch = 0.85;
154+
window.speechSynthesis.speak(utter);
155+
} catch {
156+
// Ignore speech synthesis errors on restricted browsers.
157+
}
158+
}
159+
160+
/** Maps a TV alert to its sound cue. */
161+
export function alertChimeKind(alert: { kind: 'final' | 'banked' | 'scoring' | 'swing'; banked: readonly unknown[] }): ChimeKind {
162+
if (alert.kind === 'final') return 'final';
163+
if (alert.kind === 'banked' || alert.banked.length > 0) return 'banked';
164+
if (alert.kind === 'scoring') return 'scoring';
165+
return 'swing';
166+
}
167+
168+
/** Plays a prominent stadium broadcast alert; safe no-op when audio is unsupported or blocked. */
169+
export function playChime(kind: ChimeKind, opts: ChimeOptions = {}): void {
170+
const graph = audioGraph();
171+
if (!graph) return;
172+
const { ctx, out } = graph;
41173
try {
42-
const t0 = ctx.currentTime + 0.01;
43-
for (const note of NOTES[kind]) {
44-
const osc = ctx.createOscillator();
45-
const gain = ctx.createGain();
46-
osc.type = 'triangle';
47-
osc.frequency.setValueAtTime(note.freq, t0 + note.delay);
48-
gain.gain.setValueAtTime(0.0001, t0 + note.delay);
49-
gain.gain.linearRampToValueAtTime(note.gain, t0 + note.delay + 0.02);
50-
gain.gain.exponentialRampToValueAtTime(0.0001, t0 + note.delay + note.duration);
51-
osc.connect(gain);
52-
gain.connect(ctx.destination);
53-
osc.start(t0 + note.delay);
54-
osc.stop(t0 + note.delay + note.duration + 0.02);
174+
const t0 = ctx.currentTime + 0.015;
175+
switch (kind) {
176+
case 'confirm':
177+
// Punchy 2-hit stadium test sting so you can set TV volume right away.
178+
brassNote(ctx, out, 392.0, t0, 0.18, 0.62); // G4
179+
bellNote(ctx, out, 783.99, t0, 0.24, 0.45); // G5
180+
brassNote(ctx, out, 523.25, t0 + 0.16, 0.36, 0.72); // C5
181+
bellNote(ctx, out, 1046.5, t0 + 0.16, 0.48, 0.5); // C6
182+
break;
183+
184+
case 'swing':
185+
// Bright triple broadcast alert bell + brass stab (turnovers, 3-pt swings, 1st overall).
186+
brassNote(ctx, out, 392.0, t0, 0.22, 0.6); // G4
187+
bellNote(ctx, out, 783.99, t0, 0.26, 0.55); // G5
188+
bellNote(ctx, out, 987.77, t0 + 0.13, 0.26, 0.58); // B5
189+
brassNote(ctx, out, 587.33, t0 + 0.26, 0.42, 0.68); // D5
190+
bellNote(ctx, out, 1174.66, t0 + 0.26, 0.56, 0.6); // D6
191+
break;
192+
193+
case 'scoring':
194+
// Bold 4-note NFL-style scoring brass fanfare (TDs, FGs, safeties).
195+
brassNote(ctx, out, 392.0, t0, 0.16, 0.65); // G4
196+
brassNote(ctx, out, 523.25, t0 + 0.14, 0.16, 0.7); // C5
197+
brassNote(ctx, out, 659.25, t0 + 0.28, 0.18, 0.72); // E5
198+
brassNote(ctx, out, 783.99, t0 + 0.44, 0.58, 0.8); // G5
199+
brassNote(ctx, out, 523.25, t0 + 0.44, 0.58, 0.5); // C5 harmony
200+
bellNote(ctx, out, 1567.98, t0 + 0.44, 0.72, 0.52); // G6 shimmer
201+
break;
202+
203+
case 'banked':
204+
// Celebratory rising stadium horn fanfare + chime chord when points lock in!
205+
brassNote(ctx, out, 523.25, t0, 0.15, 0.68); // C5
206+
bellNote(ctx, out, 1046.5, t0, 0.22, 0.5); // C6
207+
brassNote(ctx, out, 659.25, t0 + 0.14, 0.15, 0.72); // E5
208+
bellNote(ctx, out, 1318.51, t0 + 0.14, 0.22, 0.52); // E6
209+
brassNote(ctx, out, 783.99, t0 + 0.28, 0.18, 0.76); // G5
210+
bellNote(ctx, out, 1567.98, t0 + 0.28, 0.28, 0.55); // G6
211+
brassNote(ctx, out, 1046.5, t0 + 0.46, 0.68, 0.82); // C6
212+
brassNote(ctx, out, 523.25, t0 + 0.46, 0.68, 0.55); // C5
213+
bellNote(ctx, out, 2093.0, t0 + 0.46, 0.85, 0.52); // C7
214+
break;
215+
216+
case 'final':
217+
// Big full victory brass + bell fanfare on Game Final.
218+
brassNote(ctx, out, 392.0, t0, 0.14, 0.68); // G4
219+
brassNote(ctx, out, 523.25, t0 + 0.13, 0.14, 0.72); // C5
220+
brassNote(ctx, out, 659.25, t0 + 0.26, 0.14, 0.74); // E5
221+
brassNote(ctx, out, 783.99, t0 + 0.39, 0.22, 0.78); // G5
222+
brassNote(ctx, out, 659.25, t0 + 0.62, 0.16, 0.72); // E5
223+
brassNote(ctx, out, 783.99, t0 + 0.78, 0.82, 0.85); // G5
224+
brassNote(ctx, out, 523.25, t0 + 0.78, 0.82, 0.65); // C5
225+
brassNote(ctx, out, 1046.5, t0 + 0.78, 0.82, 0.72); // C6
226+
bellNote(ctx, out, 1567.98, t0 + 0.78, 1.0, 0.55); // G6
227+
bellNote(ctx, out, 2093.0, t0 + 0.78, 1.0, 0.45); // C7
228+
break;
229+
}
230+
231+
if (opts.turducken) {
232+
const gobbleDelay = kind === 'confirm' ? 0.22 : kind === 'swing' ? 0.35 : 0.52;
233+
playGobble(ctx, out, t0 + gobbleDelay);
234+
speakTurducken(kind);
55235
}
56236
} catch {
57237
// Ignore autoplay / hardware audio failures.

‎src/styles/thanksgiving.css‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,6 +2966,12 @@ body.tg-body .shell {
29662966
color: var(--tg-ok);
29672967
}
29682968

2969+
.tg-tv-turducken-on {
2970+
border-color: rgba(240, 185, 75, 0.72);
2971+
background: rgba(240, 185, 75, 0.22);
2972+
color: #fde68a;
2973+
}
2974+
29692975
.tg-tv-demo-btn {
29702976
border-color: rgba(240, 185, 75, 0.55);
29712977
background: rgba(240, 185, 75, 0.14);

‎tests/e2e/picks.spec.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,14 @@ test('demoAlerts=1 previews TV Last Big Play strip, sound toggle, mobile toast,
389389

390390
const soundBtn = tv.getByTestId('tg-tv-sound-toggle');
391391
await expect(soundBtn).toHaveAttribute('aria-pressed', 'false');
392+
await expect(tv.getByTestId('tg-tv-turducken-toggle')).toHaveCount(0);
392393
await soundBtn.click();
393394
await expect(soundBtn).toHaveAttribute('aria-pressed', 'true');
395+
const turduckenBtn = tv.getByTestId('tg-tv-turducken-toggle');
396+
await expect(turduckenBtn).toBeVisible();
397+
await expect(turduckenBtn).toHaveAttribute('aria-pressed', 'false');
398+
await turduckenBtn.click();
399+
await expect(turduckenBtn).toHaveAttribute('aria-pressed', 'true');
394400

395401
// Cycling through Big Swing -> Halftime -> Game Final updates the persistent strip in place.
396402
await tv.getByTestId('tg-tv-demo-alert').click();

0 commit comments

Comments
 (0)