Skip to content

Add the sound to the golden_line example - #358

Merged
ASDAlexander77 merged 1 commit into
mainfrom
golden-line-sound
Dec 5, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
golden-line-sound

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

  • core/web_audio.cpp: Web Audio on miniaudio, following Chrome's rendering. It renders 128-frame quanta, with calls applied at each quantum start. It also mirrors these Chrome behaviours:

    • sources compute their params only while sounding;
    • a-rate and k-rate setTargetAtTime use Chrome's recursions;
    • event times are clamped to the current time.

    It is linked into donut_interop_shared via FetchContent, with a realtime or an offline context.

  • core/golden_line_soundbank.ts and core/golden_line_sound.ts: the original's soundbank and sound engine:

    • graph;
    • layers: rails, loco, rolling, whistle, ambience and cabin;
    • listener, occlusion and Doppler.

    The bank is built a few ms per frame, and the convolver impulses load a moment after the rest. Both modules pass the own memory model, with the shared desk, graph and RNG held as Shared<T>.

  • HUD sound button (on/off/unavailable icons) and the M key mute and unmute. -nosound turns sound off, and -test never opens an audio device.

Verification

  • Calls: over the whole ride, the Web Audio calls (recorded with a wrapper in Chrome against our SnDesk log) are identical within 1e-11 relative.
  • Audio:
    • Our ride audio matches Chrome's replay of the same calls at about 33 dB overall.
    • By stretch: 40–79 dB on most of it, about 25 dB trackside (48–59 s), and about 30 dB in the tunnel and cab. The cause of this gap is not known yet.
    • Chrome is itself non-deterministic at about 84 dB.
  • Tests: gc, rc and own all build, and golden_line passes 6 of 6 tests in each.
  • Test frames: byte-identical to main, except cab on Vulkan, which also varies from run to run on main.
  • Live runs: short live runs with sound on exit cleanly in all three builds.

Not ported

  • Pausing the sound when the window is hidden or the page is suspended.

🤖 Generated with Claude Code

A Web Audio implementation on miniaudio (core/web_audio.cpp, linked by
donut_interop_shared) that follows Chrome's rendering: 128-frame quanta,
commands taken at quantum starts, sources that compute their params only
while sounding, Chrome's a-rate and k-rate setTargetAtTime recursions and
event-time clamping. The soundbank and the sound engine (rails, loco,
rolling, whistle, ambience, cabin) are ported from the original; their
Web Audio calls match Chrome's over the whole ride.

The HUD's sound button and the M key mute and unmute; -nosound turns the
sound off, and -test never opens a device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 1ff9c6d into main Dec 5, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the golden-line-sound branch December 5, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant