Files
isaac-port/notes/systems/music.md
T

14 KiB

Music selection (Repentance+ 1.9.7.17)

Track ids are music.xml ids. EXACT = read in code (address given); INFERRED = from data files only. Room music is chosen in one place, Room::PlayMusic @ 0x007eb1b0, called on every room change (RoomTransition::ChangeRoom @ 0x00830950, except during a boss intro and in Deathmatch), after the boss versus screen (RoomTransition::Update @ 0x008318a0), from Level::Init @ 0x00744940, Level::RestoreGameState @ 0x007475b0, StageTransition::Update @ 0x0092f1c0, Dogma's AI and ItemOverlay::Update. Events (boss/wave/challenge start and end, NPC phases) override it afterwards.

Room::PlayMusic @ 0x007eb1b0, in order

Stage/stageType come from Game; challenge 44 (Red Redemption) uses the room's own stage type (Level::GetRoomStageType), challenge 45 (the TMTRAINER one) rolls a random stage 1..11 and type 0..4 (3 -> 4) from the dungeon placement seed. stageId = RoomConfig::GetStageID(stage, type, -1) @ 0x0082d030; "stage music" below = stages.xml music of that stageId (RoomConfigStage +0xbc, i.e. Game+0x189cc + stageId*0xc4; offset confirmed in RoomConfig::LoadStagesXml @ 0x0082b2f0, atoi store at 0x0082b9f0).

  1. Boss room (type 5): if cleared (descriptor flag 0x1) -> 37. Else jump table on Room::_bossId (0x007eb31b, byte table 0x7eb81c, targets 0x7eb7f4, index bossId-6): 6 Mom -> 20; 8 Mom's Heart, 25 It Lives -> 21; 24 Satan, 55 Mega Satan -> 33 (Devil Room; their AI switches to 23 when they wake); 39 Isaac -> 22; 40 ???, 63 Hush -> 25; 54 Lamb -> 24; 62 Ultra Greed -> 28; 70 Delirium -> 103; 88 Mother -> 43; anything else -> default_boss_music @ 0x008206e0 (FUN_): stageType 4/5 -> 41, else descriptor flag 0x40 (ALT_BOSS_MUSIC) -> 26, else 9. (89 Mom Mausoleum, 90 Mom's Heart Mausoleum, 71 Ultra Greedier, Dogma 99, Beast 100 all take the default.)
  2. Miniboss room (type 6) or Room+0x7228 (= descriptor flag 0x10 SURPRISE_MINIBOSS, copied in Room::Init 0x007f2800): not cleared -> 38, cleared -> 37.
  3. Shop 2 -> 35; Library 12 -> 30; Angel 15 -> 34; Arcade 9 -> 36; Devil 14 -> 33; Secret 7 -> 31; Super secret 8 -> 32; Ultra secret 29 -> 51; Secret exit 27 -> 37; Challenge 11 with flag 0x8 (CHALLENGE_DONE) -> 37.
  4. Everything else (incl. challenge 11 not done): room idx -11 (Gideon's dungeon) -> 37; Planetarium 24 -> 50; Dungeon 16 whose room subtype is 4 (Beast arena) -> 45; Home night (stage 13, type 1): descriptor flags & 5 == 4 (flag 0x4 set, not cleared = Dogma fight) -> 44 played instantly, else stage music; Dungeon 16 subtype 2/3 (Rotgut etc.) -> default_boss_music; Treasure 4 on first visit (Room+1, set by Room::Init when VisitedCount==0) -> stage music plus jingle 87 + (Random() & 3) (87..90); otherwise stage music.
  5. Non-greed stage 9 (Blue Womb), any room that is not a boss room -> stage music (18), jingle dropped.
  6. Level::IsMausoleumHeartStage @ 0x0074e9b0 (Mausoleum/Gehenna II, i.e. effective stage 6 type 4/5 incl. XL, GameStateFlag 46 set, not in the Ascent): room idx -10 -> 0 (fade out); every other room -> 52 instantly.
  7. Dimension 2 (Death Certificate) -> 69.
  8. Else mirror dimension (Level::HasMirrorDimension, dimension 1), room not boss/miniboss/surprise -> 114 (115 if stageId 28 Dross).
  9. Else Level::HasAbandonedMineshaft and dimension 1 -> 116, or 117 once LevelStateFlag 0x400000 is set (set by NpcAI::ENTITY_MOTHERS_SHADOW @ 0x0056ffa0).
  10. Else stage 1..6 with GameStateFlag 48 (0x1000000000000, backwards path / Ascent) -> 118, jingle dropped.

Then the transition (0x007eb635..): crossfade rate 0.08 (0xbaa108); from 104<->114 0.008; from 65 0.01; from 45 a hard Music::Play; while 95/64 (run-start jingle) is current the new id is only queued (plays when the jingle ends); 44 and 52 (and the mausoleum-heart case) use rate 1.0 = Music::Play hard cut; id 0 = fade current out at 0.08. A jingle goes through Music::PlayJingle @ 0x007e2580 (separate stream; refused while current is 52 or 118).

Context table

context id (name) condition where
run_start 95 Game start (jingle); 64 when the Tainted menu was shown starting a run MenuManager::start_game @ 0x00989750 (Crossfade 0.08) EXACT
title 63 Title Screen (Repentance); layer 0 (Twisted) on when PersistentGameData._characterMenuShown == 1 menu init / cutscene end MenuManager::Init @ 0x00987450; Manager::Update @ 0x00954cd0 EXACT
nightmare 96 Nightmare; 65 Nightmare (alt) going to Home night between floors NightmareScene::Show @ 0x00921ce0 (flag from NightmareScene::record_stage @ 0x00923320) EXACT
credits 60 Credits; 70 if achievement 32 (??? unlocked); 71 if achievement 637 (Dead God) or in a daily/debug game credits anm2 part Cutscene::ANM2Part::start @ 0x0095f4f0 (id from cutscenes.xml) EXACT
ending_chest no track: music faded (0.08) and queue cleared, the video has its own audio, then credits 60/70/71 cutscene 17 "Chest" Cutscene::Show @ 0x0095e7c0; video part 0x0095fac0 EXACT
death 93 Game Over (jingle), queued 8 Game Over main player dies PlayerManager::trigger_coop_baby_death @ 0x009bc120 (misnamed: TriggerDeath, variant 0 path) EXACT
library 30 type 12 Room::PlayMusic EXACT
super_secret 32 Secret Room Alt type 8 Room::PlayMusic EXACT
secret 31 type 7 Room::PlayMusic EXACT
angel 34 type 15 Room::PlayMusic EXACT
angel_devil_door 34 (no distinction) type 15 Room::PlayMusic EXACT
devil 33 type 14 Room::PlayMusic EXACT
shop 35 type 2 Room::PlayMusic EXACT
arcade 36 type 9 Room::PlayMusic EXACT
krampus_fight 38 devil room with SURPRISE_MINIBOSS (Krampus roll in Level::InitializeDevilAngelRoom @ 0x007499a0), not cleared Room::PlayMusic EXACT
krampus_won 92 Challenge Room Outro (jingle, as main track), queued 37; revisit 37 Krampus (81.1) dies Room::TriggerBossDeath @ 0x007fec00 (0x007ff7d4 branch) + Room::GetBossVictoryJingle @ 0x00820720 EXACT
ambush_boss 38 (no separate track) boss challenge start Ambush::StartChallenge @ 0x00833420 EXACT
ambush 38 challenge start (type 11) / miniboss room not cleared Ambush::StartChallenge; Room::PlayMusic EXACT
miniboss_won 92 (main track), queued 37; revisit 37 miniboss / surprise miniboss dies Room::TriggerBossDeath + GetBossVictoryJingle EXACT
challenge_won 92 crossfaded (0.08), queued 37; revisit 37 (CHALLENGE_DONE) last wave done Ambush::Update @ 0x00834350 EXACT
greed_challenge_wave 38 for every normal wave on The Shop floor (stageId 24); cleared: 92 then queued 35 greed waves Room::SpawnGreedModeWave @ 0x00816910 (0x00816cdf); Room::SpawnClearAward @ 0x007fb250 (greed switch: 92 at 0x007fd9a4) EXACT
greed_final_wave 23 Boss (Satan) wave 11 (Greed) / 12 (Greedier), the devil wave SpawnGreedModeWave 0x00816c7c EXACT
greed_boss_wave 41 on stageType 4/5, else 26 if ALT_BOSS_MUSIC, else 9 waves 9-10 (Greed) / 10-11 (Greedier) SpawnGreedModeWave 0x00816c95 EXACT
boss_wave 39 Boss Rush; done: 40 crossfaded, queued 37 Boss Rush start (type 17) Ambush::StartChallenge / Ambush::Update EXACT
ultra_greed 28 on entering; then a hard Music::Play(9) when a player walks above y 320 (LevelStateFlag 0x1000, clears ALT flag) greed stage 7 boss room Room::PlayMusic; Room::UpdateGreedWave @ 0x00801ee0 (0x00801ffe) EXACT
ultra_greed_won 37 crossfade (greed boss room, bossId 62); TriggerBossDeath also plays 83 + queue 37 Ultra Greed beaten Room::SpawnClearAward 0x007fda41 (roomType==5 && bossId==0x3e); TriggerBossDeath EXACT
blue_baby 25 Boss (Chest - ???) bossId 40 Room::PlayMusic table EXACT
isaac 22 bossId 39 Room::PlayMusic table EXACT
mom 20 bossId 6 (Depths/Necropolis/Dank II); Mausoleum's Mom (89) gets 41 Room::PlayMusic table EXACT
moms_heart 21 bossId 8 or 25; Mausoleum's heart (90) gets 41 Room::PlayMusic table EXACT
satan 33 on entering, 23 crossfade (0.08) when Satan wakes ("Change"); Mega Satan the same bossId 24 / 55 table; NpcAI::ENTITY_SATAN @ 0x0047f640; NpcAI::ENTITY_MEGA_SATAN @ 0x004c8090 EXACT
boss_alt 41 Boss (alternate alternate) on stageType 4/5; 26 Boss (alternate) when the room rolled ALT_BOSS_MUSIC default boss default_boss_music @ 0x008206e0; flag rolled 50/50 per room on first visit in Room::Init 0x007f36d3 (`Flags = 0x40`)
boss 9 default boss default_boss_music @ 0x008206e0 EXACT
blue_baby_won 83 (97 if ALT flag) as main track, queued 37 ??? dies TriggerBossDeath + GetBossVictoryJingle EXACT
boss_won 83 / 97 (ALT flag) / 42 (stageType 4/5) as main track, queued 37; revisit 37 boss death in boss room (or type 15, or while 9/26/41 plays), no ambush TriggerBossDeath 0x007fed8f.. + GetBossVictoryJingle EXACT
basement..chest (floors) stage music: Basement 1, Cellar 4, Burning 14, Caves 2, Catacombs 5, Flooded 15, Depths 3, Necropolis 6, Dank 16, Womb 7, Utero 19, Scarred 17, Blue Womb 18, Sheol 11, Cathedral 10, Dark Room 12, Chest 13, Void 102, Downpour 104, Dross 108, Mines 105, Ashpit 109, Mausoleum 106, Gehenna 110, Corpse 107, Home 112 (day and night) stageId via GetStageID Room::PlayMusic (table read); ids from stages.xml EXACT code path, ids INFERRED from stages.xml
greed The Shop / Ultra Greed floor 35 / 35 (stageIds 24 / 25) greed stage 6 / 7 same same
mineshaft 116 Mines/Ashpit II mineshaft dimension Room::PlayMusic 0x007eb5da EXACT
mineshaft_escape 66 Mom's Shadow Intro crossfade, queued 117; later rooms 117 Mom's Shadow appears (sets LevelStateFlag 0x400000) NpcAI::ENTITY_MOTHERS_SHADOW @ 0x0056ffa0; Room::PlayMusic EXACT
ascent 118 Genesis (reversed), every room incl. boss rooms; jingles refused stage 1..6 + GameStateFlag 48 Room::PlayMusic 0x007eb60b; layers in 0x007eb870 EXACT

Jingles: 81 Boss (jingle) is a Music::Play at the start of the versus screen (RoomTransition::StartBossIntro @ 0x0082f1c0); the boss track follows from Room::PlayMusic when the versus sprite stops. Victory: Room::GetBossVictoryJingle @ 0x00820720: Home night -> 0; secret exit kind 4 in room -10 -> 0; miniboss/surprise -> 92; stageType 4/5 -> 42; ALT flag -> 97; else 83. Treasure 87-90 (above). 85 Secret Room Find: GridEntity_Door::TryBlowOpen @ 0x0070fb60 (first visit, door variant 7, to secret/super/ultra), NpcHelper::gideon_update_death @ 0x004b3610, Level::raise_mineshaft_rail @ 0x0074eaf0. 68 Strange Door: GridEntity_Door::TryUnlock @ 0x00710480.

Contexts outside that list

  • Planetarium 50; Ultra secret 51 (Secret Room Alt Alt); Gideon dungeon / secret exit room 37 (Room::PlayMusic).
  • Boss Rush 39, done 40 (Ambush). Hush: 25 on entering, 27 crossfade when ???-Hush spawns Hush (407) (NpcAI::ENTITY_ISAAC @ 0x00463100). Delirium 103 (table). Mother 43 (table). Beast arena 45 (dungeon subtype 4), Beast layers 3 (NpcAI::ENTITY_BEAST @ 0x00592460) and 2 (NpcAI::ENTITY_BEAST_ultra_death @ 0x00440f00).
  • Dogma: 67 Dogma Intro crossfade 0.04 when the TV prop spawns Dogma (NpcAI::ENTITY_GENERIC_PROP @ 0x00551d30); 44 from Room::PlayMusic (Dogma AI calls it, NpcAI::ENTITY_DOGMA @ 0x004aafa0); angel phase layers 0/1 and 48 Dogma Death (jingle) crossfade 0.5 (NpcAI::ENTITY_DOGMA_angel @ 0x004ae4d0).
  • Mom's Shadow 66 -> 117 (above). Twisted calm 52 (mausoleum heart stage). Echoes Reverse 69 (Death Certificate).
  • Mirror world 114 / 115. Deathmatch 119: Music::Fadein(119, vol, 0.02) in the Deathmatch state machine FUN_00429810 state 3; rooms play no music while the deathmatch manager is >= 2 (RoomTransition::ChangeRoom).
  • Greed normal waves on other floors: no new track, layer 0 of the floor music is enabled; cleared: layer disabled.
  • Shopkeeper killed into Greed, angel statue destroyed: default boss music (9/26/41) crossfade (NpcAI::ENTITY_SHOPKEEPER @ 0x006c2220 via 0x007ebc40; GridEntity_Statue::Destroy @ 0x00838560).
  • Cutscenes: intro 100, epilogue 101, The Beast ending 113 (cutscenes.xml, played by Cutscene::ANM2Part::start).
  • Continue of a saved challenge / boss rush: 38 / 39 (Game::restore_game_state @ 0x006f8140).
  • Fade-outs (0.01): Dad's Note pickup (Entity_Pickup::HandleCollision @ 0x006e8ae0), collectible 721 first pickup (Entity_Player::AddCollectible @ 0x0075f0e0).
  • No reference found (callers of Play/Crossfade/PlayJingle/Fadein and every _queuedMusicID write checked): 61, 62 (old titles), 47 Mother death, 49 Beast death, 98 Hush death, 84 Holy Room Find, 91 Challenge Room Entry, 94 Devil Room appear. Mods/Lua can still play them.

MusicManager mechanics

  • Music::Play @ 0x007e1d50: hard start on the current channel at the given volume.
  • MusicManager::Crossfade @ 0x007e1e70: same id -> only resets target volume; else the old channel's target -> 0 at fadeRate, the other channel starts at volume 0 -> options music volume at fadeRate; queue cleared.
  • Volume step (MusicChannel::update_volume @ 0x007df8e0, per Music::Update): v += (target - v) * rate, snap when within rate. Default rate 0.08 everywhere (0x3da3d70a).
  • Queue: Music::Update @ 0x007e17b0 starts _queuedMusicID when the current (non-looping) track ends, fading in at 0.08. This is how jingles played as main tracks (83/92/93/95...) hand over to 37/35/8/floor music.
  • PlayJingle sets a 140-tick timer that ducks music toward x0.1 (lerp 0.08); afterwards it returns by 1/30 per tick, or by lerp 0.04 after Room::PlayMusic changes track (it sets the timer to -100).
  • Layers (MusicManager::EnableLayer @ 0x007e2280, 6 per track): each stream fades toward 0/1 at the track's layerfadespeed (default 0.02, Music::LoadConfig @ 0x007dfaf0). layermode default 1 = layer adds over the base; 2 = the base is muted while any layer is on (Utero, Downpour, Dross, Mines, Ashpit, Mausoleum, Gehenna, Home, Dogma, Beast, title 63).
  • Floor layer 0 (0x007eb870, misnamed Level::UpdateBackwardsPathStages; run one frame after entering a room): on when the room's live enemy HP (sum of +0x380 over vulnerable non-friendly NPCs) >= effectiveStage * 14 + 40 (greed: 2*stage-1, Sheol 10), always on with Berserk (effect 704) or in an uncleared room from stage 9 on; Mines rooms with descriptor flag 0x20 and not 0x100 add descriptor+0x54 * 3. Disabled in Room::Update when the room clears (not Home, not Ascent). In the Ascent the six 118 layers are one per chapter still ahead (Basement, Caves, Depths, Downpour, Mines, Mausoleum by stage type).