diff options
Diffstat (limited to 'src/sound.c')
-rw-r--r-- | src/sound.c | 100 |
1 files changed, 53 insertions, 47 deletions
diff --git a/src/sound.c b/src/sound.c index 8c3cd3997..ad9993b54 100644 --- a/src/sound.c +++ b/src/sound.c @@ -26,7 +26,7 @@ static u16 sFanfareCounter; bool8 gDisableMusic; extern struct ToneData gCryTable[]; -extern struct ToneData gCryTable2[]; +extern struct ToneData gCryTable_Reverse[]; static void Task_Fanfare(u8 taskId); static void CreateFanfareTask(void); @@ -54,8 +54,6 @@ static const struct Fanfare sFanfares[] = { [FANFARE_REGISTER_MATCH_CALL] = { MUS_REGISTER_MATCH_CALL, 135 }, }; -#define CRY_VOLUME 120 // was 125 in R/S - void InitMapMusic(void) { gDisableMusic = FALSE; @@ -300,73 +298,76 @@ bool8 IsBGMStopped(void) return FALSE; } -void PlayCry1(u16 species, s8 pan) +void PlayCry_Normal(u16 species, s8 pan) { m4aMPlayVolumeControl(&gMPlayInfo_BGM, TRACKS_ALL, 85); - PlayCryInternal(species, pan, CRY_VOLUME, 10, 0); + PlayCryInternal(species, pan, CRY_VOLUME, CRY_PRIORITY_NORMAL, CRY_MODE_NORMAL); gPokemonCryBGMDuckingCounter = 2; RestoreBGMVolumeAfterPokemonCry(); } -void PlayCry2(u16 species, s8 pan, s8 volume, u8 priority) +void PlayCry_NormalNoDucking(u16 species, s8 pan, s8 volume, u8 priority) { - PlayCryInternal(species, pan, volume, priority, 0); + PlayCryInternal(species, pan, volume, priority, CRY_MODE_NORMAL); } -void PlayCry3(u16 species, s8 pan, u8 mode) +// Assuming it's not CRY_MODE_DOUBLES, this is equivalent to PlayCry_Normal except it allows other modes. +void PlayCry_ByMode(u16 species, s8 pan, u8 mode) { - if (mode == 1) + if (mode == CRY_MODE_DOUBLES) { - PlayCryInternal(species, pan, CRY_VOLUME, 10, 1); + PlayCryInternal(species, pan, CRY_VOLUME, CRY_PRIORITY_NORMAL, mode); } else { m4aMPlayVolumeControl(&gMPlayInfo_BGM, TRACKS_ALL, 85); - PlayCryInternal(species, pan, CRY_VOLUME, 10, mode); + PlayCryInternal(species, pan, CRY_VOLUME, CRY_PRIORITY_NORMAL, mode); gPokemonCryBGMDuckingCounter = 2; RestoreBGMVolumeAfterPokemonCry(); } } -void PlayCry4(u16 species, s8 pan, u8 mode) +// Used when releasing multiple Pokémon at once in battle. +void PlayCry_ReleaseDouble(u16 species, s8 pan, u8 mode) { - if (mode == 1) + if (mode == CRY_MODE_DOUBLES) { - PlayCryInternal(species, pan, CRY_VOLUME, 10, 1); + PlayCryInternal(species, pan, CRY_VOLUME, CRY_PRIORITY_NORMAL, mode); } else { if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI)) m4aMPlayVolumeControl(&gMPlayInfo_BGM, TRACKS_ALL, 85); - PlayCryInternal(species, pan, CRY_VOLUME, 10, mode); + PlayCryInternal(species, pan, CRY_VOLUME, CRY_PRIORITY_NORMAL, mode); } } -void PlayCry6(u16 species, s8 pan, u8 mode) // not present in R/S +// Duck the BGM but don't restore it. Not present in R/S +void PlayCry_DuckNoRestore(u16 species, s8 pan, u8 mode) { - if (mode == 1) + if (mode == CRY_MODE_DOUBLES) { - PlayCryInternal(species, pan, CRY_VOLUME, 10, 1); + PlayCryInternal(species, pan, CRY_VOLUME, CRY_PRIORITY_NORMAL, mode); } else { m4aMPlayVolumeControl(&gMPlayInfo_BGM, TRACKS_ALL, 85); - PlayCryInternal(species, pan, CRY_VOLUME, 10, mode); + PlayCryInternal(species, pan, CRY_VOLUME, CRY_PRIORITY_NORMAL, mode); gPokemonCryBGMDuckingCounter = 2; } } -void PlayCry5(u16 species, u8 mode) +void PlayCry_Script(u16 species, u8 mode) { m4aMPlayVolumeControl(&gMPlayInfo_BGM, TRACKS_ALL, 85); - PlayCryInternal(species, 0, CRY_VOLUME, 10, mode); + PlayCryInternal(species, 0, CRY_VOLUME, CRY_PRIORITY_NORMAL, mode); gPokemonCryBGMDuckingCounter = 2; RestoreBGMVolumeAfterPokemonCry(); } void PlayCryInternal(u16 species, s8 pan, s8 volume, u8 priority, u8 mode) { - bool32 v0; + bool32 reverse; u32 release; u32 length; u32 pitch; @@ -375,76 +376,80 @@ void PlayCryInternal(u16 species, s8 pan, s8 volume, u8 priority, u8 mode) u8 table; species--; + + // Set default values + // May be overridden depending on mode. length = 140; - v0 = FALSE; + reverse = FALSE; release = 0; pitch = 15360; chorus = 0; switch (mode) { - case 0: + case CRY_MODE_NORMAL: break; - case 1: + case CRY_MODE_DOUBLES: length = 20; release = 225; break; - case 2: + case CRY_MODE_ENCOUNTER: release = 225; pitch = 15600; chorus = 20; volume = 90; break; - case 3: + case CRY_MODE_HIGH_PITCH: length = 50; release = 200; pitch = 15800; chorus = 20; volume = 90; break; - case 4: + case CRY_MODE_ECHO_START: length = 25; - v0 = TRUE; + reverse = TRUE; release = 100; pitch = 15600; chorus = 192; volume = 90; break; - case 5: + case CRY_MODE_FAINT: release = 200; pitch = 14440; break; - case 6: + case CRY_MODE_ECHO_END: release = 220; pitch = 15555; chorus = 192; volume = 70; break; - case 7: + case CRY_MODE_ROAR_1: length = 10; release = 100; pitch = 14848; break; - case 8: + case CRY_MODE_ROAR_2: length = 60; release = 225; pitch = 15616; break; - case 9: + case CRY_MODE_GROWL_1: length = 15; - v0 = TRUE; + reverse = TRUE; release = 125; pitch = 15200; break; - case 10: + case CRY_MODE_GROWL_2: length = 100; release = 225; pitch = 15200; break; - case 12: + case CRY_MODE_WEAK_DOUBLES: length = 20; release = 225; - case 11: + // fallthrough + case CRY_MODE_WEAK: pitch = 15000; break; } @@ -463,28 +468,29 @@ void PlayCryInternal(u16 species, s8 pan, s8 volume, u8 priority, u8 mode) // If you wish to expand pokemon, you need to // append new cases to the switch. species = SpeciesToCryId(species); - index = species & 0x7F; + index = species % 128; table = species / 128; + #define GET_CRY(speciesIndex, tableId, reversed) \ + ((reversed) ? &gCryTable_Reverse[(128 * (tableId)) + (speciesIndex)] : &gCryTable[(128 * (tableId)) + (speciesIndex)]) + switch (table) { case 0: - gMPlay_PokemonCry = SetPokemonCryTone( - v0 ? &gCryTable2[(128 * 0) + index] : &gCryTable[(128 * 0) + index]); + gMPlay_PokemonCry = SetPokemonCryTone(GET_CRY(index, 0, reverse)); break; case 1: - gMPlay_PokemonCry = SetPokemonCryTone( - v0 ? &gCryTable2[(128 * 1) + index] : &gCryTable[(128 * 1) + index]); + gMPlay_PokemonCry = SetPokemonCryTone(GET_CRY(index, 1, reverse)); break; case 2: - gMPlay_PokemonCry = SetPokemonCryTone( - v0 ? &gCryTable2[(128 * 2) + index] : &gCryTable[(128 * 2) + index]); + gMPlay_PokemonCry = SetPokemonCryTone(GET_CRY(index, 2, reverse)); break; case 3: - gMPlay_PokemonCry = SetPokemonCryTone( - v0 ? &gCryTable2[(128 * 3) + index] : &gCryTable[(128 * 3) + index]); + gMPlay_PokemonCry = SetPokemonCryTone(GET_CRY(index, 3, reverse)); break; } + + #undef GET_CRY } bool8 IsCryFinished(void) |