RaceAudio.module
README.md
RaceAudio
Every sound the race makes, behind one interface. RaceDirector calls it; no
one else needs to know how the mix is wired.
The module owns no geometry. On the first call it spawns its own temporary,
internal audio entities under a RaceAudioRig root and attaches an Audio
component to each — four looping beds and six one-shots — then finds them by
name ever after, so a second setup() rebuilds rather than duplicates and a
scene reload costs one rebuild. Every function is safe to call before setup,
and none of them throws: a clip that will not resolve leaves that one voice
silent and is reported, never raised.
What it exports
| Function | What it does |
|---|---|
setup() | Idempotent. Builds the ten voices once, then settles the mix into whichever state the race is in: the menu bed when nothing runs, the race beds when one does. Every volume it owns is re-asserted, so a second call also undoes drift. |
startRace() | The gates open — the claxon and its crowd roar, hooves away, the race bed under them, the start-screen theme out of the way, and the grandstand swelling. |
stop() | The race is over — race bed, hooves and the caller go quiet, the crowd settles to its between-races level, and the menu bed comes back under the result screen. |
setCrowd(level) | 0..1 excitement, mapped onto the grandstand bed's volume. Recorded even before setup, applied as soon as the bed is alive. |
sting(kind) | "win" or "lose" — the result sting. Any other value is a quiet no-op. |
say(text) | Plays the race-caller reading of a commentary line, if one exists for that text. Otherwise silent. The same line will not retrigger within 2.5 s. |
Which clip plays where
All clips live in /zero/source/audio/ and were generated for this game.
| Clip | Used for | Mix |
|---|---|---|
race_day_theme | Start screen and result screen — golden-hour fanfare, strings and brass, 54 s loop | music channel, 0.55 |
race_bed | The field running — string ostinato under taiko, 60 s loop | music channel, 0.52 |
start_gate_claxon | The gates opening — bell over a crowd roar, 2.5 s one-shot | sfx, 0.9 |
crowd_bed | The packed grandstand, 8 s loop, always under everything | ambient, 0.10 → 0.72 with setCrowd |
hooves_turf | The pack passing — hoofbeats on turf, 4 s loop, races only | sfx, 0.5 |
sting_win | First place — brass flourish and a cheer, 4 s | sfx, 0.9 |
sting_lose | Anything else — muted trombone and a sigh, 3 s | sfx, 0.9 |
lines/line_start · lines/line_final · lines/line_hold | Race-caller commentary — 「各馬スタートしました!」, 「最後の直線、外から1番が伸びてくる!」, 「そのまま押し切る!」 | sfx, 0.9 |
All four looping beds read seamless on clipRef:loopSeam(), so none of them
ticks at the wrap.
say matches a commentary line exactly first, then falls back to a keyword
(スタートしました, 最後の直線, 押し切) so the director's dynamic lines — the
leader's number, the finishing call — borrow the nearest reading instead of
going silent.
Adding a line
Drop the clip under audio/lines/, resolve it in the REF table from its
literal identity, add a voice to VOICES, list it in LINES, and point the
commentary text at it in SPEECH.
One entity per spoken line, on purpose: a voice whose clip is swapped mid-flight loses the source it was playing, so lines never share one.
Identities are written as literals: a computed asset.resolve records nothing
in the world's reference table, so the clip would not travel with the world.