From b18a2f00d796f9a8c68fa2d259278aebdafedb7b Mon Sep 17 00:00:00 2001 From: robojumper Date: Tue, 8 Jul 2025 00:10:45 +0200 Subject: [PATCH] d_snd_bgm_seq_data_mgr, d_snd_bgm_seq_config OK --- config/SOUE01/splits.txt | 15 +++-- config/SOUE01/symbols.txt | 38 ++++++------ configure.py | 4 +- include/d/snd/d_snd_bgm_seq_config.h | 30 ++++++++++ ...le_data_mgr.h => d_snd_bgm_seq_data_mgr.h} | 20 ++++--- include/d/snd/d_snd_bgm_sound.h | 7 --- include/d/snd/d_snd_bgm_sound_harp_mgr.h | 4 ++ include/d/snd/d_snd_state_mgr.h | 11 ++-- include/d/snd/d_snd_types.h | 1 + src/d/snd/d_snd_bgm_battle_data_mgr.cpp | 18 ------ src/d/snd/d_snd_bgm_mml_parsers.cpp | 4 +- src/d/snd/d_snd_bgm_seq_config.cpp | 52 ++++++++++++++++ src/d/snd/d_snd_bgm_seq_data_mgr.cpp | 60 +++++++++++++++++++ src/d/snd/d_snd_bgm_sound.cpp | 18 +++++- src/d/snd/d_snd_state_mgr.cpp | 4 +- 15 files changed, 217 insertions(+), 69 deletions(-) create mode 100644 include/d/snd/d_snd_bgm_seq_config.h rename include/d/snd/{d_snd_bgm_battle_data_mgr.h => d_snd_bgm_seq_data_mgr.h} (51%) delete mode 100644 src/d/snd/d_snd_bgm_battle_data_mgr.cpp create mode 100644 src/d/snd/d_snd_bgm_seq_config.cpp create mode 100644 src/d/snd/d_snd_bgm_seq_data_mgr.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 6f420e74..795689c7 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -2700,7 +2700,7 @@ d/snd/d_snd_bgm_sound.cpp: .text start:0x80379D20 end:0x8037B4D8 align:16 .data start:0x80549088 end:0x80549100 .sbss start:0x80575D88 end:0x80575D90 - .sdata2 start:0x8057DA58 end:0x8057DA80 + .sdata2 start:0x8057DA58 end:0x8057DA60 d/snd/d_snd_bgm_sound_battle.cpp: .text start:0x8037B4E0 end:0x8037B908 align:16 @@ -2709,13 +2709,20 @@ d/snd/d_snd_bgm_sound_battle.cpp: d/snd/d_snd_bgm_sound_harp_mgr.cpp: .text start:0x8037B910 end:0x8037BA68 align:16 -d/snd/d_snd_bgm_battle_data_mgr.cpp: - .text start:0x8037BA70 end:0x8037BEA8 align:16 - .rodata start:0x804F3858 end:0x804F38C8 +d/snd/d_snd_bgm_seq_data_mgr.cpp: + .text start:0x8037BA70 end:0x8037BD24 align:16 .data start:0x80549148 end:0x80549158 .sdata start:0x805742F0 end:0x805742F8 .sbss start:0x80575D90 end:0x80575D98 +d/snd/d_snd_bgm_reverb.cpp: + .text start:0x8037BD30 end:0x8037BD84 align:16 + .sdata2 start:0x8057DA60 end:0x8057DA80 + +d/snd/d_snd_bgm_seq_config.cpp: + .text start:0x8037BD90 end:0x8037BEA8 align:16 + .rodata start:0x804F3858 end:0x804F38C8 + d/snd/d_snd_bgm_harp_data.cpp: .text start:0x8037BEB0 end:0x8037C518 align:16 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index e4b86c94..c14fdeab 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -20725,7 +20725,7 @@ fn_8037A0C0 = .text:0x8037A0C0; // type:function size:0xC fn_8037A0D0 = .text:0x8037A0D0; // type:function size:0x20 startBgmSound__14dSndBgmSound_cFUllUl = .text:0x8037A0F0; // type:function size:0x2D4 fadeIn__14dSndBgmSound_cFUll = .text:0x8037A3D0; // type:function size:0x1D0 -fn_8037A5A0 = .text:0x8037A5A0; // type:function size:0x68 +loadSeqConfig__14dSndBgmSound_cFUl = .text:0x8037A5A0; // type:function size:0x68 prepareSound__14dSndBgmSound_cFUlUl = .text:0x8037A610; // type:function size:0x250 prepareSound__14dSndBgmSound_cFPCcUl = .text:0x8037A860; // type:function size:0x58 onPreparing__14dSndBgmSound_cFUlUl = .text:0x8037A8C0; // type:function size:0x7C @@ -20767,20 +20767,20 @@ setLoaded__21dSndBgmSoundHarpMgr_cFv = .text:0x8037B980; // type:function size:0 reset__21dSndBgmSoundHarpMgr_cFv = .text:0x8037B990; // type:function size:0x48 setPlaySamplePosition__21dSndBgmSoundHarpMgr_cFl = .text:0x8037B9E0; // type:function size:0x74 getCurrentVarSet__21dSndBgmSoundHarpMgr_cFv = .text:0x8037BA60; // type:function size:0x8 -__dt__40SndMgrDisposer<22dSndBgmBattleDataMgr_c>Fv = .text:0x8037BA70; // type:function size:0x78 -create__40SndMgrDisposer<22dSndBgmBattleDataMgr_c>Fv = .text:0x8037BAF0; // type:function size:0x48 -remove__40SndMgrDisposer<22dSndBgmBattleDataMgr_c>Fv = .text:0x8037BB40; // type:function size:0x10 -__ct__22dSndBgmBattleDataMgr_cFv = .text:0x8037BB50; // type:function size:0x6C -getDataPrefix__22dSndBgmBattleDataMgr_cFv = .text:0x8037BBC0; // type:function size:0x8 -getDataPrefixLength__22dSndBgmBattleDataMgr_cFv = .text:0x8037BBD0; // type:function size:0x24 -fn_8037BC00 = .text:0x8037BC00; // type:function size:0x4 -fn_8037BC10 = .text:0x8037BC10; // type:function size:0xC0 -getHarpMgrForSoundId__22dSndBgmBattleDataMgr_cFUl = .text:0x8037BCD0; // type:function size:0x54 +__dt__37SndMgrDisposer<19dSndBgmSeqDataMgr_c>Fv = .text:0x8037BA70; // type:function size:0x78 scope:weak +create__37SndMgrDisposer<19dSndBgmSeqDataMgr_c>Fv = .text:0x8037BAF0; // type:function size:0x48 scope:weak +remove__37SndMgrDisposer<19dSndBgmSeqDataMgr_c>Fv = .text:0x8037BB40; // type:function size:0x10 scope:weak +__ct__19dSndBgmSeqDataMgr_cFv = .text:0x8037BB50; // type:function size:0x6C +getDataPrefix__19dSndBgmSeqDataMgr_cFv = .text:0x8037BBC0; // type:function size:0x8 +getDataPrefixLength__19dSndBgmSeqDataMgr_cFv = .text:0x8037BBD0; // type:function size:0x24 +initialize__19dSndBgmSeqDataMgr_cFv = .text:0x8037BC00; // type:function size:0x4 +setupState0__19dSndBgmSeqDataMgr_cFv = .text:0x8037BC10; // type:function size:0xC0 +getHarpMgrForSoundId__19dSndBgmSeqDataMgr_cFUl = .text:0x8037BCD0; // type:function size:0x54 fn_8037BD30 = .text:0x8037BD30; // type:function size:0x4C fn_8037BD80 = .text:0x8037BD80; // type:function size:0x4 -fn_8037BD90 = .text:0x8037BD90; // type:function size:0x4C -fn_8037BDE0 = .text:0x8037BDE0; // type:function size:0x5C -fn_8037BE40 = .text:0x8037BE40; // type:function size:0x68 +getConfig__19dSndBgmBattleConfigFUl = .text:0x8037BD90; // type:function size:0x4C +hasConfig__19dSndBgmBattleConfigFUl = .text:0x8037BDE0; // type:function size:0x5C +getConfig__16dSndBgmSeqConfigFUll = .text:0x8037BE40; // type:function size:0x68 __ct__27dSndBgmDataHarpVarSetBase_cFl = .text:0x8037BEB0; // type:function size:0x7C __ct__20dSndBgmDataHarpVar_cFv = .text:0x8037BF30; // type:function size:0x10 scope:weak __dt__27dSndBgmDataHarpVarSetBase_cFv = .text:0x8037BF40; // type:function size:0x64 @@ -29029,8 +29029,8 @@ lbl_804F365C = .rodata:0x804F365C; // type:object size:0x1C lbl_804F3678 = .rodata:0x804F3678; // type:object size:0x16C lbl_804F37E8 = .rodata:0x804F37E8; // type:object size:0x30 data:2byte lbl_804F3818 = .rodata:0x804F3818; // type:object size:0x40 -lbl_804F3858 = .rodata:0x804F3858; // type:object size:0x30 data:4byte -lbl_804F3888 = .rodata:0x804F3888; // type:object size:0x40 +sBattleConfigs = .rodata:0x804F3858; // type:object size:0x30 scope:local data:4byte +sBgmConfigs = .rodata:0x804F3888; // type:object size:0x40 scope:local lbl_804F38C8 = .rodata:0x804F38C8; // type:object size:0x18 lbl_804F38E0 = .rodata:0x804F38E0; // type:object size:0x10 sFlowSoundDefs = .rodata:0x804F38F0; // type:object size:0x80 scope:local @@ -38041,7 +38041,7 @@ lbl_80549078 = .data:0x80549078; // type:object size:0x10 lbl_80549088 = .data:0x80549088; // type:object size:0x34 __vt__14dSndBgmSound_c = .data:0x805490BC; // type:object size:0x44 lbl_80549100 = .data:0x80549100; // type:object size:0x48 -__vt__40SndMgrDisposer<22dSndBgmBattleDataMgr_c> = .data:0x80549148; // type:object size:0x10 +__vt__37SndMgrDisposer<19dSndBgmSeqDataMgr_c> = .data:0x80549148; // type:object size:0xC scope:weak __vt__18dSndBgmMmlParser_c = .data:0x80549158; // type:object size:0x10 lbl_80549168 = .data:0x80549168; // type:object size:0x10 lbl_80549178 = .data:0x80549178; // type:object size:0x10 @@ -41096,7 +41096,7 @@ lbl_805742D0 = .sdata:0x805742D0; // type:object size:0x8 lbl_805742D8 = .sdata:0x805742D8; // type:object size:0x8 lbl_805742E0 = .sdata:0x805742E0; // type:object size:0x8 lbl_805742E8 = .sdata:0x805742E8; // type:object size:0x8 -lbl_805742F0 = .sdata:0x805742F0; // type:object size:0x8 +@7580 = .sdata:0x805742F0; // type:object size:0x6 scope:local data:string lbl_805742F8 = .sdata:0x805742F8; // type:object size:0x8 lbl_80574300 = .sdata:0x80574300; // type:object size:0x8 data:string lbl_80574308 = .sdata:0x80574308; // type:object size:0x8 @@ -42297,8 +42297,8 @@ sDisposer__24dSndAreaSoundEffectMgr_c = .sbss:0x80575D7C; // type:object size:0x sInstance__12dSndBgmMgr_c = .sbss:0x80575D80; // type:object size:0x4 data:4byte sDisposer__12dSndBgmMgr_c = .sbss:0x80575D84; // type:object size:0x4 data:4byte spGlobalHarpMgr__14dSndBgmSound_c = .sbss:0x80575D88; // type:object size:0x8 data:4byte -sInstance__22dSndBgmBattleDataMgr_c = .sbss:0x80575D90; // type:object size:0x4 data:4byte -sDisposer__22dSndBgmBattleDataMgr_c = .sbss:0x80575D94; // type:object size:0x4 data:4byte +sInstance__19dSndBgmSeqDataMgr_c = .sbss:0x80575D90; // type:object size:0x4 data:4byte +sDisposer__19dSndBgmSeqDataMgr_c = .sbss:0x80575D94; // type:object size:0x4 data:4byte sInstance__20dSndSmallEffectMgr_c = .sbss:0x80575D98; // type:object size:0x4 data:4byte sDisposer__20dSndSmallEffectMgr_c = .sbss:0x80575D9C; // type:object size:0x4 data:4byte lbl_80575DA0 = .sbss:0x80575DA0; // type:object size:0x4 data:4byte diff --git a/configure.py b/configure.py index 707d5872..7be44e87 100644 --- a/configure.py +++ b/configure.py @@ -759,7 +759,9 @@ config.libs = [ Object(NonMatching, "d/snd/d_snd_bgm_sound.cpp"), Object(NonMatching, "d/snd/d_snd_bgm_sound_battle.cpp"), Object(Matching, "d/snd/d_snd_bgm_sound_harp_mgr.cpp"), - Object(NonMatching, "d/snd/d_snd_bgm_battle_data_mgr.cpp"), + Object(Matching, "d/snd/d_snd_bgm_seq_data_mgr.cpp"), + Object(NonMatching, "d/snd/d_snd_bgm_reverb.cpp"), + Object(Matching, "d/snd/d_snd_bgm_seq_config.cpp"), Object(Matching, "d/snd/d_snd_bgm_harp_data.cpp"), Object(Matching, "d/snd/d_snd_bgm_mml_parser_base.cpp"), Object(NonMatching, "d/snd/d_snd_bgm_mml_parsers.cpp"), diff --git a/include/d/snd/d_snd_bgm_seq_config.h b/include/d/snd/d_snd_bgm_seq_config.h new file mode 100644 index 00000000..b66e9275 --- /dev/null +++ b/include/d/snd/d_snd_bgm_seq_config.h @@ -0,0 +1,30 @@ +#ifndef D_SND_BGM_SEQ_CONFIG_H +#define D_SND_BGM_SEQ_CONFIG_H + +#include "common.h" + +struct dSndBgmSeqConfig { + /* 0x00 */ u32 soundId; + /* 0x04 */ s32 field_0x04; + /* 0x08 */ s32 field_0x08; + /* 0x0C */ u16 field_0x0C; + /* 0x0E */ u16 field_0x0E; + + + static const dSndBgmSeqConfig *getConfig(u32 soundId, s32 unkParam); +}; + +struct dSndBgmBattleConfig_MuteUnmuteMasks { + /* 0x00 */ u16 unmuteMask; + /* 0x02 */ u16 muteMask; +}; + +struct dSndBgmBattleConfig { + /* 0x00 */ u32 soundId; + /* 0x04 */ dSndBgmBattleConfig_MuteUnmuteMasks mTrackMasks[3]; + + static bool hasConfig(u32 soundId); + static const dSndBgmBattleConfig *getConfig(u32 soundId); +}; + +#endif diff --git a/include/d/snd/d_snd_bgm_battle_data_mgr.h b/include/d/snd/d_snd_bgm_seq_data_mgr.h similarity index 51% rename from include/d/snd/d_snd_bgm_battle_data_mgr.h rename to include/d/snd/d_snd_bgm_seq_data_mgr.h index 50d5dc0e..de8ad699 100644 --- a/include/d/snd/d_snd_bgm_battle_data_mgr.h +++ b/include/d/snd/d_snd_bgm_seq_data_mgr.h @@ -1,28 +1,32 @@ -#ifndef D_SND_BGM_BATTLE_DATA_MGR_H -#define D_SND_BGM_BATTLE_DATA_MGR_H +#ifndef D_SND_BGM_SEQ_DATA_MGR_H +#define D_SND_BGM_SEQ_DATA_MGR_H #include "common.h" -#include "d/snd/d_snd_util.h" #include "d/snd/d_snd_types.h" +#include "d/snd/d_snd_util.h" -SND_DISPOSER_FORWARD_DECL(dSndBgmBattleDataMgr_c); +SND_DISPOSER_FORWARD_DECL(dSndBgmSeqDataMgr_c); // Previous Ghidra name: SomeUnusedSoundMgr -class dSndBgmBattleDataMgr_c { +class dSndBgmSeqDataMgr_c { public: - SND_DISPOSER_MEMBERS(dSndBgmBattleDataMgr_c); + SND_DISPOSER_MEMBERS(dSndBgmSeqDataMgr_c); public: - dSndBgmBattleDataMgr_c(); + dSndBgmSeqDataMgr_c(); static const char *getDataPrefix(); static u32 getDataPrefixLength(); dSndBgmSoundHarpMgr_c *getHarpMgrForSoundId(u32 soundId); + void initialize(); + void setupState0(); private: + static const s32 NUM_SOUNDS = 2; + /* 0x10 */ dSndBgmSoundHarpMgr_c *mpMgrs; - /* 0x14 */ u8 field_0x14; + /* 0x14 */ bool mInitialized; }; #endif diff --git a/include/d/snd/d_snd_bgm_sound.h b/include/d/snd/d_snd_bgm_sound.h index c85f4279..0f01dcb7 100644 --- a/include/d/snd/d_snd_bgm_sound.h +++ b/include/d/snd/d_snd_bgm_sound.h @@ -7,13 +7,6 @@ #include "nw4r/snd/snd_SoundStartable.h" #include "nw4r/ut/ut_list.h" -struct dSndBgmSeqConfig { - /* 0x00 */ u32 soundId; - /* 0x04 */ u8 _0x04[0x0C - 0x04]; - /* 0x0C */ u16 field_0x0C; - /* 0x0E */ u16 field_0x0E; -}; - class dSndBgmSound_c : public dSndSound_c { enum BgmSoundFlags_e { BGM_FLAG_BATTLE = 0x1, diff --git a/include/d/snd/d_snd_bgm_sound_harp_mgr.h b/include/d/snd/d_snd_bgm_sound_harp_mgr.h index ca5aa14e..16bcdc40 100644 --- a/include/d/snd/d_snd_bgm_sound_harp_mgr.h +++ b/include/d/snd/d_snd_bgm_sound_harp_mgr.h @@ -41,6 +41,10 @@ public: mPrevIdx = -1; } + u32 getSoundId() const { + return mSoundId; + } + private: /* 0x00 */ dSndBgmHarpData_c mHarpData; /* 0x0C */ dSndBgmDataHarpVarSetBase_c *mpCurrVarSet; diff --git a/include/d/snd/d_snd_state_mgr.h b/include/d/snd/d_snd_state_mgr.h index 9f7cedf1..13c3b1df 100644 --- a/include/d/snd/d_snd_state_mgr.h +++ b/include/d/snd/d_snd_state_mgr.h @@ -31,7 +31,8 @@ public: }; enum EventFlags_e { - EVENT_0x2 = 0x2, + EVENT_IN_EVENT = 0x1, + EVENT_DEMO = 0x2, EVENT_MUTE_BGM_PARTIAL = 0x8, EVENT_MUTE_BGM_FULL = 0x10, EVENT_MUTE_STAGE_EFFECTS_PARTIAL = 0x20, @@ -92,15 +93,15 @@ public: } bool checkEventFlag(u32 mask) const { - return field_0x094 & mask; + return mEventFlags & mask; } void onEventFlag(u32 mask) { - field_0x094 |= mask; + mEventFlags |= mask; } void offEventFlag(u32 mask) { - field_0x094 &= ~mask; + mEventFlags &= ~mask; } void setFlowEvent(u32 eventId); @@ -197,7 +198,7 @@ private: /* 0x088 */ UNKWORD field_0x088; /* 0x08C */ s32 mSoundEventId; /* 0x090 */ UNKWORD field_0x090; - /* 0x094 */ u32 field_0x094; + /* 0x094 */ u32 mEventFlags; /* 0x098 */ SizedString<64> field_0x098; /* 0x0D8 */ SizedString<64> field_0x0D8; /* 0x118 */ const char *field_0x118; diff --git a/include/d/snd/d_snd_types.h b/include/d/snd/d_snd_types.h index 6c6a9d9a..2533df67 100644 --- a/include/d/snd/d_snd_types.h +++ b/include/d/snd/d_snd_types.h @@ -23,5 +23,6 @@ class dSndBgmSound_c; class dSndBgmBattleSound_c; class dSndBgmSoundHarpMgr_c; +class dSndBgmSeqConfig; #endif diff --git a/src/d/snd/d_snd_bgm_battle_data_mgr.cpp b/src/d/snd/d_snd_bgm_battle_data_mgr.cpp deleted file mode 100644 index a7f01e93..00000000 --- a/src/d/snd/d_snd_bgm_battle_data_mgr.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "d/snd/d_snd_bgm_battle_data_mgr.h" -#include "d/snd/d_snd_bgm_sound_harp_mgr.h" - -#include "d/snd/d_snd_util.h" - -SND_DISPOSER_DEFINE(dSndBgmBattleDataMgr_c) - -dSndBgmBattleDataMgr_c::dSndBgmBattleDataMgr_c() : field_0x14(0) { - mpMgrs = new dSndBgmSoundHarpMgr_c[2]; -} - -const char *dSndBgmBattleDataMgr_c::getDataPrefix() { - return "DATA_"; -} - -u32 dSndBgmBattleDataMgr_c::getDataPrefixLength() { - return std::strlen(getDataPrefix()); -} diff --git a/src/d/snd/d_snd_bgm_mml_parsers.cpp b/src/d/snd/d_snd_bgm_mml_parsers.cpp index e43782cc..e8797706 100644 --- a/src/d/snd/d_snd_bgm_mml_parsers.cpp +++ b/src/d/snd/d_snd_bgm_mml_parsers.cpp @@ -3,7 +3,7 @@ #include "common.h" #include "d/snd/d_snd_mgr.h" #include "d/snd/d_snd_bgm_sound_harp_mgr.h" -#include "d/snd/d_snd_bgm_battle_data_mgr.h" +#include "d/snd/d_snd_bgm_seq_data_mgr.h" #include "d/snd/d_snd_player_mgr.h" #include "nw4r/snd/snd_SoundArchive.h" #include "sized_string.h" @@ -21,7 +21,7 @@ bool dSndBgmMmlParserHarp_c::parseData(const char *soundLabel, u32 baseSoundId, bool ok = false; field_0x294->reset(); SizedString<64> dataLabel; - dataLabel.sprintf("%s%s", dSndBgmBattleDataMgr_c::getDataPrefix(), soundLabel); + dataLabel.sprintf("%s%s", dSndBgmSeqDataMgr_c::getDataPrefix(), soundLabel); u32 dataId = dSndPlayerMgr_c::GetInstance()->convertLabelStringToSoundId(dataLabel); if (dataId != -1 && dSndMgr_c::GetInstance()->getArchive()->GetSoundType(dataId) == nw4r::snd::SoundArchive::SOUND_TYPE_SEQ) { ok = loadAndParse(dataId, trackMask, true); diff --git a/src/d/snd/d_snd_bgm_seq_config.cpp b/src/d/snd/d_snd_bgm_seq_config.cpp new file mode 100644 index 00000000..423c4295 --- /dev/null +++ b/src/d/snd/d_snd_bgm_seq_config.cpp @@ -0,0 +1,52 @@ +#include "d/snd/d_snd_bgm_seq_config.h" + +#include "common.h" +#include "d/snd/d_snd_wzsound.h" + +static const dSndBgmBattleConfig sBattleConfigs[] = { + { BGM_BATTLE2, {{(1 << 7) | (1 << 4) | (1 << 3), 0}, {(1 << 9) | (1 << 6), 0}, {0, 0}}}, + {BGM_BATTLE_ROOM_MAIN, {{(1 << 7) | (1 << 4), 0}, {(1 << 9), 0}, {0, 0}}}, + { BGM_MIDDLE_BOSS, {{(1 << 1), 0}, {(1 << 2), 0}, {0, 0}}} +}; + +const dSndBgmBattleConfig *dSndBgmBattleConfig::getConfig(u32 soundId) { + for (int i = 0; i < ARRAY_LENGTH(sBattleConfigs); i++) { + if (soundId == sBattleConfigs[i].soundId) { + return &sBattleConfigs[i]; + } + } + return nullptr; +} + +bool dSndBgmBattleConfig::hasConfig(u32 soundId) { + if (soundId == -1) { + return false; + } + + for (int i = 0; i < ARRAY_LENGTH(sBattleConfigs); i++) { + if (soundId == sBattleConfigs[i].soundId) { + return true; + } + } + return false; +} + +static const dSndBgmSeqConfig sBgmConfigs[] = { + { BGM_BATTLE2, 0, 0x180, 1, 4}, + { BGM_BATTLE2, 1, 0x180, 5, 0x2F}, + {BGM_BATTLE_ROOM_MAIN, 1, 0x180, 5, 0x2C}, + { BGM_MUTE, 1, 0x120, 0, 0x1F}, +}; + +const dSndBgmSeqConfig *dSndBgmSeqConfig::getConfig(u32 soundId, s32 unkParam) { + if (soundId == -1) { + return nullptr; + } + + for (const dSndBgmSeqConfig *def = sBgmConfigs; def < sBgmConfigs + ARRAY_LENGTH(sBgmConfigs); def++) { + if (soundId == def->soundId && def->field_0x04 == unkParam) { + return def; + } + } + return nullptr; +} diff --git a/src/d/snd/d_snd_bgm_seq_data_mgr.cpp b/src/d/snd/d_snd_bgm_seq_data_mgr.cpp new file mode 100644 index 00000000..5c60f592 --- /dev/null +++ b/src/d/snd/d_snd_bgm_seq_data_mgr.cpp @@ -0,0 +1,60 @@ +#include "d/snd/d_snd_bgm_seq_data_mgr.h" +#include "common.h" +#include "d/snd/d_snd_bgm_mgr.h" +#include "d/snd/d_snd_bgm_mml_parsers.h" +#include "d/snd/d_snd_bgm_sound_harp_mgr.h" + +#include "d/snd/d_snd_mgr.h" +#include "d/snd/d_snd_player_mgr.h" +#include "d/snd/d_snd_util.h" +#include "d/snd/d_snd_wzsound.h" + +SND_DISPOSER_DEFINE(dSndBgmSeqDataMgr_c) + +dSndBgmSeqDataMgr_c::dSndBgmSeqDataMgr_c() : mInitialized(false) { + mpMgrs = new dSndBgmSoundHarpMgr_c[NUM_SOUNDS]; +} + +const char *dSndBgmSeqDataMgr_c::getDataPrefix() { + return "DATA_"; +} + +u32 dSndBgmSeqDataMgr_c::getDataPrefixLength() { + return std::strlen(getDataPrefix()); +} + +void dSndBgmSeqDataMgr_c::initialize() { + // no-op +} + +void dSndBgmSeqDataMgr_c::setupState0() { + if (mInitialized) { + return; + } + + // DATA_BGM_BATTLE2, DATA_BGM_BATTLE2_OUTRO + for (int i = 0; i < NUM_SOUNDS; i++) { + u32 dataId = DATA_BGM_BATTLE2 + i; + const char *baseLabel = dSndMgr_c::getSoundLabelString(dataId) + getDataPrefixLength(); + u32 baseSoundId = dSndPlayerMgr_c::GetInstance()->convertLabelStringToSoundId(baseLabel); + dSndBgmMmlParserHarp_c parser(&mpMgrs[i]); + (void)dSndBgmMgr_c::isSoundPlayedByBgmBattlePlayer(dataId); + parser.parseData(baseSoundId, (1 << 15) | (1 << 0)); + } + + mInitialized = true; +} + +dSndBgmSoundHarpMgr_c *dSndBgmSeqDataMgr_c::getHarpMgrForSoundId(u32 soundId) { + if (soundId == -1) { + return nullptr; + } + + for (dSndBgmSoundHarpMgr_c *it = &mpMgrs[0]; it < &mpMgrs[NUM_SOUNDS]; it++) { + if (it->getSoundId() == soundId) { + return it; + } + } + + return nullptr; +} diff --git a/src/d/snd/d_snd_bgm_sound.cpp b/src/d/snd/d_snd_bgm_sound.cpp index 35a28b38..e6e8a78e 100644 --- a/src/d/snd/d_snd_bgm_sound.cpp +++ b/src/d/snd/d_snd_bgm_sound.cpp @@ -1,9 +1,10 @@ #include "d/snd/d_snd_bgm_sound.h" #include "common.h" -#include "d/snd/d_snd_bgm_battle_data_mgr.h" #include "d/snd/d_snd_bgm_mgr.h" #include "d/snd/d_snd_bgm_mml_parsers.h" +#include "d/snd/d_snd_bgm_seq_config.h" +#include "d/snd/d_snd_bgm_seq_data_mgr.h" #include "d/snd/d_snd_mgr.h" #include "d/snd/d_snd_player_mgr.h" #include "d/snd/d_snd_sound.h" @@ -17,6 +18,7 @@ #include "nw4r/snd/snd_WaveSoundHandle.h" #include "toBeSorted/music_mgrs.h" + dSndBgmSoundHarpMgr_c *dSndBgmSound_c::spGlobalHarpMgr; dSndBgmSound_c::dSndBgmSound_c() @@ -153,7 +155,8 @@ nw4r::snd::SoundStartable::StartResult dSndBgmSound_c::startBgmSound(u32 soundId mSeqTempo = mpHarpMgr->getTempo(); } - if (mSeqTempo > 0 && dSndMgr_c::GetInstance()->getArchive()->GetSoundType(soundId) == nw4r::snd::SoundArchive::SOUND_TYPE_SEQ) { + if (mSeqTempo > 0 && dSndMgr_c::GetInstance()->getArchive()->GetSoundType(soundId) == + nw4r::snd::SoundArchive::SOUND_TYPE_SEQ) { mSeqPlaySamplePosition = (mSeqTempo * startOffset * 0xC0); mSeqPlaySamplePosition /= 120000; info.startOffsetType = nw4r::snd::SoundStartable::StartInfo::START_OFFSET_TYPE_TICK; @@ -232,6 +235,15 @@ void dSndBgmSound_c::fadeIn(u32 id, s32 fadeFrames) { } } +void dSndBgmSound_c::loadSeqConfig(u32 soundId) { + if (dSndMgr_c::GetInstance()->getArchive()->GetSoundType(soundId) == nw4r::snd::SoundArchive::SOUND_TYPE_SEQ) { + mpSeqConfig = dSndBgmSeqConfig::getConfig(soundId, 1); + if (mpSeqConfig != nullptr) { + field_0x118 = mpSeqConfig->field_0x08; + } + } +} + // Largely a copy of dSndSound_c::prepareSound, with changes to support different startable nw4r::snd::SoundStartable::StartResult dSndBgmSound_c::prepareSound(u32 soundId, u32 startOffset) { if (soundId == -1) { @@ -454,7 +466,7 @@ void dSndBgmSound_c::getHarpData(u32 soundId) { return; } - dSndBgmSoundHarpMgr_c *mgr = dSndBgmBattleDataMgr_c::GetInstance()->getHarpMgrForSoundId(soundId); + dSndBgmSoundHarpMgr_c *mgr = dSndBgmSeqDataMgr_c::GetInstance()->getHarpMgrForSoundId(soundId); if (mgr != nullptr) { mpHarpMgr = mgr; } else { diff --git a/src/d/snd/d_snd_state_mgr.cpp b/src/d/snd/d_snd_state_mgr.cpp index c62499b8..86100d36 100644 --- a/src/d/snd/d_snd_state_mgr.cpp +++ b/src/d/snd/d_snd_state_mgr.cpp @@ -41,7 +41,7 @@ dSndStateMgr_c::dSndStateMgr_c() field_0x088(0), mSoundEventId(SND_EVENT_0x89), field_0x090(0), - field_0x094(0), + mEventFlags(0), field_0x118(nullptr), field_0x11C(0), field_0x120(0), @@ -210,7 +210,7 @@ void dSndStateMgr_c::initializeEventCallbacks(const char *name) { sEventExecuteCallback = nullptr; resetOverrides(); - if (checkEventFlag(EVENT_0x2)) { + if (checkEventFlag(EVENT_DEMO)) { handleDemoEvent(name); return; }