Skip to Content
The Alchemy Project

Sound and music

This page is a guide to the games/tla/src/sound/ folder of the Alchemy project, where the high-level music and sound effects code that scores Golden Sun: The Lost Age is kept.

Every town theme, battle track, jingle, and spell sound runs through sySoundPlay in sound.c, which also manages BGM volume ramps, the debug sound test, and the heard-track bitfield for the Battle Arena. To hold the sequel's larger soundtrack, The Lost Age extends BGM into the 700+ range and layers five TLA-specific files into sdk/.

The notes below cover sound ID ranges, four-player SFX fallback, area and battle music rules, the IWRAM mixer, and MIDI and WAV naming, followed by the file map. Sound ID ranges, player fallback, and VBlank ducking concepts are explained in Graphics & Sound.

How it works, and sdk/ overrides

  • ID dispatch and 4-player SFX fallback (sound.c, include/sounds.h): IDs 0–79 loop as BGM, 80–99 play as jingles, and 100–699 play as SFX (with unused rows named SE_UNUSED_*). IDs 700+ hold 31 additional TLA BGM tracks. sySoundFlagSet marks every played ID for the Battle Arena sound test, where L + R + Select unlocks all tracks. Sounds assigned to MUSIC_PLAYER_SE_LAST search back through 3 prior SFX players (4 total) for an idle slot before cutting off their own channel.
  • Area and battle rules (field/music_rules.s, field/field_engine_encounter.c): fdChooseMusic scans priority-ordered area, entrance, and flag rules (Daila has 2 rules, and the World Map has 6). Normal battle themes pick sea music while sailing before the ship gains wings, or choose a theme by front-row party lead (Felix, Isaac, or Jenna). Bosses override the theme through EncounterBattleMusic (field/battle_music.c).
  • IWRAM mixer and sdk/: Reconstructed m4a routines are kept in common/sdk/sound (SDK notes). Camelot's 528-sample-per-frame IWRAM mixer (31,536 Hz) places resident_mixer.s in system/ to share the -fcall-used-r4 ABI. sdk/ adds six TLA-specific files:
    • mplay_main.s: TLA's MPlayMain, ply_note, stereo volume calculation, channel unlink, and unreferenced m4aSoundInitWorkCopy ROM copies.
    • leftover_driver.s, leftover_modulation_helpers.c: Unreferenced older fragments of MPlayMain, ply_note, the modulation commands' helpers, and MidiKeyToFreq preserved in ROM.
    • player_work_copy.c, dummy_func_work_copy.c, and bios_sound_driver_mode.s: TLA-specific m4a work copies and BIOS wrappers (BiosSoundDriverMode, BiosSwi23).
  • MIDI and WAV naming (sound/): Music samples take their names from General MIDI voices or drum key slots, such as timpani.pcm8.wav and side_stick.pcm8.wav. SFX samples are named for the sound itself, such as rumble.pcm8.wav.

File map

PathRole
sound.c, sound_test.c, stubs.ssySoundPlay, sySoundFlagSet, sySoundUpdateBGMRamps, debug sound test, and stubs
sounds.h, sound_driver_symbols.hAll MUS_* and SE_* enums, player indices, 700+ range, and reverb definitions
music_rules.s, battle_music.c, field_engine_encounter.cArea music rules (fdChooseMusic), boss battle tracks (EncounterBattleMusic), and ship- and front-row-aware battle music (fdEncounterSelectBattleMusic)
resident_mixer.s, system/channel_update_entry.sCamelot's 528-sample-per-frame IWRAM mixer (-fcall-used-r4, 31,536 Hz)
common/sdk/sound and sdk/Reconstructed m4a routines plus TLA overrides and leftover ROM fragments
soundMIDI songs (songs/*.mid), 8-bit PCM WAV samples (direct_sound_samples/*.pcm8.wav), voice groups, and song_table.s

Source files

src/sound/

FileDescription
sdk/dummy_func_work_copy.cAn older copy of the sound driver's empty callback, which the ROM keeps beside the driver with the player functions of player_work_copy.c.
sdk/leftover_modulation_helpers.cThe older copies of the LFOS and MOD commands' helpers that the cartridge keeps with the leftover driver functions of leftover_driver.s, which alone call them: their bytes are those of clear_modM and ld_r3_tp_adr_i_unchecked (games/common/sdk/sound/modulation_helpers.c).
sdk/player_work_copy.cTwo player functions of an older copy of the SDK's sound library that the ROM keeps beside the driver.
sound.cThe game's own sound code over the sound driver, as The Broken Seal's: sySoundPlay, which takes every sound number, the music's volume and tempo ramps, and the music's return after a jingle.
sound_test.cThe sound test, which nothing in the game calls; the heard-sound flags the link lobby offers its tunes by; and the fixed 31536 Hz output rate the game sets at start-up.

include/sound/

FileDescription
sound.hThe game's sound: sySoundPlay and the music's volume and tempo ramps (sound.c), the sound test and the heard-sound flags (sound_test.c), over the development kit's sound driver (sdk/sound_driver.h).
sound_driver_symbols.hWhat the game sets over the sound driver: the music's player, the sound numbers sySoundPlay takes and their ranges, the music players by row, the mixer's reverb codes, and the music's volume and tempo ramps.
stubs.hThe stub calls into the sound module, as the other modules' code calls them.