At a glance

Hardware
The SPU: 24 voices, 512 KB of its own RAM, ADSR envelopes, one global reverb. Retail runs reverb Studio C, always on, on every voice
Music
Every real track lives in the music_01 bank as a self-contained [VAB][SEQ] pair; scenes pick one by script (field-VM op 0x35, id 2000 + slot). No BGM table exists
Effects
100 static descriptors at DAT_8006F198; a descriptor's category byte names the VAB slot the cue plays from
Voices
CD-XA streams: arts shouts from XA2 / XA4 / XA6, the blocked-strike grunt from XA30, victory lines from the tail of monster.snd
Libraries
Sony's PsyQ libsnd (sequencer, 0x80061..0x80067) and libspu (0x80068..0x8006D), statically linked and traceable
In the port
crates/engine-audio: a from-scratch SPU, a sample-locked sequencer, the SFX bank, XA mixing; a WebAudio backend for the browser

Three roads to the speaker

music scene scriptop 0x35: track id BGM pollerid to PROT entry [VAB][SEQ] entrybank into SPU RAM sequencerlibsnd: note on / off effects actor / scriptnames a cue id descriptor8 bytes per cue VAB slotpicked by category key-onone voice per count SPU 24 voices ADPCM + ADSR 512 KB RAM reverb: Studio C streamed voice art / strike / movieasks for a clip CD-XA sectorsfile + channel CD drivedecodes ADPCM itself mixerto the speakers CD input - skips the voices
Music and effects both end as SPU voice key-ons, from different banks; streamed CD-XA audio never touches the 24 voices and enters the mix from the CD input. That is why a port that wires up only the SPU stays silent when a character shouts.

The SPU cannot be driven from main RAM directly; games go through Sony's libsnd (sequencer playback) and libspu (voices and registers). Legaia links both statically, so they are part of the game binary and can be traced and named like any other code. Legaia's own layer above them is small: two loaders, one bank installer, one SFX helper, one BGM poller and one CD-XA clip player.

Music: which track plays

Walk into Rim Elm and the town theme starts; walk into a fight and the battle theme takes over. Nothing in the executable maps a place to a tune. The scene's own script says “play track 2016” through field-VM op 0x35, and a per-frame poller turns that id into a disc entry by arithmetic - the archive is the table.

Changing track on cue

A cutscene can choose the exact beat the outgoing score dies on. The poller walks a short ladder - wait for the CD, let the load settle for 30 frames, tear down the old track unless the script owns the swap, load, install the score, latch - and coordinates with the script through one sound-flag word. A swap started by sub-op 9 keeps the old track playing until the script commits it with sub-op 0xA. The flag bits are on internals.

Sound effects

A menu blip, a chest, a sword clang: each is one 8-byte descriptor, and the actor or script that wants the sound just names its id. The static table holds 100 descriptors; ids at or above 0x200 come from a runtime bank instead - in battle, bse.dat.

+0programu8
+1tone / region baseu8
+2note levelu8
+3voice count + sustained bit 0x20u8
+4category = VAB slotu8
+5unused (zero)3 bytes
History: “a cue plays out of the scene's music VAB”

The current-bank globals are shared with the sequencer, so a save state sampled after a BGM note holds the music bank. That artefact produced the earlier reading; the program-change call inside the voice programmer is what selects the bank per cue.

Sound banks and their slots

An instrument bank (VAB, format on vab) is a set of samples plus the tuning and envelope data that makes them instruments. Legaia keeps several resident at once, each parked in a numbered slot. One installer opens every bank; its argument is the same category byte the SFX descriptors carry.

SlotBankInstalled by
0PROT 0868 system bank (the shared UI cues)resident from boot
1the current track's own VAB (music_01)the BGM poller
2PROT 0869 battle class-2 bank (0875 with Terra on party seat 1); a minigame's own bank in fishing, slots and dancebattle loader, minigame inits
3a vab_01 side-band bankthe BGM poller
6PROT 0876 field bankfield init
7 / 8the active battle's two monster.snd banksmonster bank loader
11PROT 0889 reward bankvictory spoils

Battle voices: shouts and grunts

When Vahn lands a Somersault he shouts. That shout is not an SPU sample - it is a short CD-XA clip streamed off the disc, picked at random from a small per-character channel pool so it does not repeat back to back.

CueSourceWhen
Arts shoutXA2.XA Vahn, XA4.XA Noa, XA6.XA Gala (16-channel mono banks)as an art's staged animation starts; a second trigger fires from the animation's cue track mid-clip
GruntXA30 clip 0x1D, character-spaced channela melee strike the defender blocks; a strike that lands a flinch or knockdown is silent here
Impact stingcue 0x10C through the cue router - an XA27 voice leg for a party target, an element-tinted ring for a monsterthe same melee routine's second emission
Victory linetail clips of monster.sndthe spoils screen (see banks)

Cue tables: legaia_art::arts_voice. The CD contract shows up as two timing behaviours a port has to keep: the shout trails its clip install by roughly 150 ms, and a new request while a clip is sounding replaces it - there is one drive, and the shout site does not wait for it to be free.

CD-XA streaming Confirmed

Cutscene audio and voice clips are streamed CD-XA: the drive plays them directly, interleaved with video sectors, without the CPU or the SPU voices in the loop. crates/xa decodes the 4-bit ADPCM bit-exactly against an external lossless reference; the demuxer splits raw 2352-byte sectors by (file, channel), which a 2048-byte ISO view strips. Format on xa.

Two stages sit between the decoded PCM and the speaker. The CD decoder converts 37.8 kHz to 44.1 kHz with a fixed 29-tap "zig-zag" filter (seven outputs per six inputs), which passes the band at about 0.906 and suppresses the image a linear interpolator would leave. Then the SPU scales the stream by its CD-input volume: every voice cue starts at register 0x75EA (libsnd level 117, about 0.921), set by the clip player's CD callback once the drive starts reading, while a movie plays at full scale. A cue does not keep that level through a change of the game's audio level: the frame driver hands each change to a routine that first resets the CD input to full scale, so a summon whose duck is still ramping when its voice starts plays the rest of the line at full CD volume. The port runs both stages and lifts a sounding clip on every level step.

History: the “non-standard interleave” reading

An earlier reading had most XA sound groups failing validation and inferred a bespoke interleave. That was Form-1 truncation damage in the old extractor, not the format. See do-not-re-walk.

An enemy's swing already sounds as it should. Given the same swings and the same dice as a recording of the original, nearly every fight we measured puts each swing, block or flinch voice and impact sound in the same place. Two fights sound different because they deal different hands, not because a sound is wrong. Glare's landing sound and its Stone now come at the moment the stare lands, about two seconds before the cast ends. A heal's voice waits for the monster's idle animation to finish, so how soon you hear it depends on where that loop stood.

A summon's voice waits for its module. The line is called on one step of the cast, after the module has parked the drive and polled it, so Theeder's line comes about two seconds after the cast begins and Juggernaut's almost at once. That seek usually queues behind one the battle had just issued for the caster's fanfare, and the game loop stops until the earlier one ends; the port runs the drive on the same seek law, which brings Orb's and Swordie's lines within a few frames of retail's (the seek-then-poll sequence). The drive then takes its own time: under mednafen about 77 ms with the head already in the clip's file and 371 ms from the next file along, plus one sector for each channel the clip sits into the file. No console has been timed. Enemies with shared spell code pick their line by who is casting: only Zora speaks Zora's line over Glare. A module can also pick by its own branch: Call Wave speaks its own line, not Big Wave's, which shares its image.

What a cold scene entry owes

Music does not start because a scene loads. It starts because the scene's entry script reaches op 0x35, and the id it names reaches a director that knows the track carries its own instruments. Anything that drops the engine into a scene from cold - both play hosts and every headless driver - owes the same three steps in this order, and each one is separately load-bearing.

host / driver world + field VM scene router BGM director mixer 1. story baseline 2. enter field live entry script runs op 0x35, global id BGM event 3. owned-VAB start upload VAB + sequencer
The three numbered calls are the host's debt. Everything between them is the engine doing what the disc's script says.
StepKernelWhat skipping it sounds like
1. Free-roam story stagingWorld::seed_free_roam_story_baselineThe entry script's authored pause parks the track: a sequencer attaches on the first frame and its playhead never leaves tick 0
2. Live field entryBootSession::enter_field_liveLoading the scene alone installs no field record, so the field VM steps nothing and op 0x35 never executes
3. Global-pool start hookBgmDirector::start_owned_vabEvery real music cue is a global id, so a director that leaves this hook on its no-op default plays nothing while looking fully wired

All three failures read identically from outside - silence - which is why a driver missing any one of them reports as “the engine starts no music on scene entry”.

The battle music timeline

The spin into a fight is the cue alone, for over two seconds; the theme arrives with the fight. Logged per vsync from a walked retail fight (teien_field_run, a set-0 fight), counted from the mode-8 store:

Tmode 8 T + 3field track stops, notes cut T + 7battle-start cue, three voices T + 80last field envelopes reach 0 T + 139mode 0x14, battle theme attaches
Drawn to scale. The field track is stopped by the intro init, not by the theme’s start, so nothing plays under the spin but the cue. A sound set above 0 leaves the field track alone until the attach, and -1 plays it through.

At the fight’s end the battle sequence plays on, ramps down over 129 vsyncs while the map reads, and the field source restarts from its head before the first field frame. The port takes the opening as measured (World::silence_field_audio_for_intro, World::enter_battle_from_formation, both hosts through route_bgm_events). Its load is instant, so the 250 vsyncs of battle theme over retail’s loading screen collapse. A fight on the park word 0x1000 ends the music: the return loads what the word names, which is nothing, and both are silent until a scene starts a track.

The field script picks the fight's music

Which track a fight plays is the field script's choice, not the formation's. Op 0x35 sub-op 7 stores a battle sound set number, and the scene's map init zeroes it on every entry. The battle intro reads it: set N ≥ 0 loads battle bundle 0x36F + N and starts its score; set -1 loads nothing and leaves whatever the event was already playing. That is how a boss fight keeps the boss theme its cutscene started one line earlier. Each bundle of the battle bank carries a byte-identical copy of one music_01 score.

What pitch a note keys at

Both key-on paths - a sequencer note and a one-shot cue - converge on one arithmetic, and its result is written straight into the SPU voice's pitch register. Nothing rescales it afterwards.

n     = note + 60 - center + carry
pitch = PITCH[(n % 12) * 16 + fine]  shifted by  (n / 12 - 5)

PITCH is a 192-entry table at DAT_8007A940 holding one octave at 1/16-semitone resolution; every entry is exactly floor(0x1000 × 2^(k/192)), so the port computes it instead of carrying it.

The law is measured as well as read: across the catalogued save states, 126 of 128 sounding voices hold exactly the pitch it computes from their staged note against the live bank. The two misses are voices whose bank was swapped after the key-on. Port: compute_pitch in engine-audio::vab_bind.

Three format traps that silence or speed up music

Scripted field cues ride a four-slot ring

A door creak or a switch click placed by a scene script does not go through the per-actor helper. The field VM's op 0x36 and the motion VM's op 0x09 push the cue id onto a four-slot ring, with an optional countdown, and a drainer keys each one when its countdown ends.

Seated partstager 0x4001, op 0x34 Silentfocus outside the box Soundingvolume = depth in box key on release what keys the voices off The arm focus leaves the box, or the side-band request goes unsettled FUN_800250D4 The part is freed its script halts; the actor walk frees it one walk later FUN_8002519C → FUN_800250D4 The next field init voices 0x10..0x17 zeroed, keyed off unless op 0x35 sub-op 6 kept them FUN_801D6704
The arm has no halt case: a part whose script halts stops ticking with its voices still keyed, and only the free releases them. That is how Octam’s collapse rumble ends with its beat; the field init is why an emitter still looping at a door does not follow the player into the next scene.

Is the port playing what retail plays?

The script's track word says which track was asked for. The sweep reads what the sound library is actually playing in every retail save state - which track each open sequence holds, whether it is playing, at what volume and tempo, and which sound effects ring beside it - then seeds the port into the same state and compares.

In the port

crates/engine-audio rebuilds the stack from this page, the libspu API surface and the public SPU register layout - no Sony bytes. It models the 24 voices with Gaussian resampling, the envelope, the ADPCM decoder, the reverb network (set to Studio C on every voice, as retail runs it) and a sequencer counted in whole output samples that spends retail's tick budget once per vsync period, so playback is locked to the audio clock, lands its key-ons where retail's do, and is bit-deterministic for replays. Both play hosts and the minigames page drive it through the same director (engine-session). Module map, the sequencer details and how the port's sound is measured against retail, down to real retail PCM note by note: internals.

See also

Reference Audio internals VAB sound bank SEQ sequence CD-XA SFX table Sound-driver outputs Music tracks Field VM op 0x35 Cutscene / STR Media page Full doc