Repository navigation
Sound: audio.play in @threert/gameplay, played by the engine on every platform - #77
Merged
Merged
Conversation
… platform
- packages/gameplay/src/audio.ts: `audio.play(sound, { at, gain, pitch, loop, key, falloff })`, `stop`, `move`,
`preload`, posted on the host channel (`audio.*`). A sound is a file of the game's package.
- renderer/src/audio (the `audio` feature, on by default): decoding by Symphonia (WAV, Ogg Vorbis, MP3, FLAC), placing
against the listener (the frame's camera: falloff / distance, equal-power pan to 80 %, a low pass far and behind),
mixing (48 voices, 8 copies of a file, ramps, fades, a soft limiter) and the device: cpal on macOS, iOS and Windows,
ALSA on Linux and AAudio on Android loaded at run time (no sound library linked). Apps hand it the posts and the
camera; the device opens on the first sound, closes with the game and in the background.
- `threert-render play` plays a game's sound; the three.js view plays it on Web Audio by the same numbers
(tools/three/audio.ts, held to mix.rs by a test).
- docs/RUNTIME.md "Sound": the contract.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r a path needs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Games had no sound: the engine had no audio, and every app would have had to invent its own. This makes sound a runtime capability, the same everywhere.
Game side —
packages/gameplay/src/audio.ts:A sound is a file of the game's package; the listener is the frame's camera (nothing to send).
Engine side —
renderer/src/audio(featureaudio, on by default):mix.rs): level tofalloff, then falloff / distance, fade out 100–120 m; equal-power pan capped at 80 %; a low pass with distance and behind;out.rs, the only per-platform part): cpal on macOS / iOS / Windows; ALSA (Linux, Steam Deck) and AAudio (Android) loaded at run time, so nothing new is linked there.threert-render playplays a game's sound.Browser — the three.js view plays the same messages on Web Audio with the same numbers (
tools/three/audio.ts;tools/three/test/audio.test.tsholds it tomix.rs).Docs — docs/RUNTIME.md "Sound" is the contract.
Tested: unit tests (mixer, decoder,
Audio, gameplay posts, page parity);threert-render playon macOS (Core Audio, 48 kHz); in the ThreeRT clients on an AYN Thor (AAudio stream, usage GAME, released in the background and reopened on return) and a Steam Deck (ALSA → PipeWire stream), and the three.js page in Chrome (both formats fetched and decoded, no errors).🤖 Generated with Claude Code