diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 87f2b7ac..6f420e74 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -2686,6 +2686,8 @@ d/snd/d_snd_bgm_mgr.cpp: d/snd/d_snd_bgm_sound_callbacks.cpp: .text start:0x803739D0 end:0x80378ECC align:16 + .rodata start:0x804F37E8 end:0x804F3858 + .data start:0x80548F98 end:0x80549088 .sdata start:0x80574268 end:0x805742B8 .sdata2 start:0x8057D970 end:0x8057DA50 @@ -2695,16 +2697,24 @@ d/snd/d_snd_bgm_sound_battle_callbacks.cpp: .sdata2 start:0x8057DA50 end:0x8057DA58 d/snd/d_snd_bgm_sound.cpp: - .text start:0x80379D20 end:0x8037B908 align:16 + .text start:0x80379D20 end:0x8037B4D8 align:16 + .data start:0x80549088 end:0x80549100 .sbss start:0x80575D88 end:0x80575D90 + .sdata2 start:0x8057DA58 end:0x8057DA80 + +d/snd/d_snd_bgm_sound_battle.cpp: + .text start:0x8037B4E0 end:0x8037B908 align:16 + .data start:0x80549100 end:0x80549148 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 .data start:0x80549148 end:0x80549158 .sdata start:0x805742F0 end:0x805742F8 + .sbss start:0x80575D90 end:0x80575D98 d/snd/d_snd_bgm_harp_data.cpp: .text start:0x8037BEB0 end:0x8037C518 align:16 @@ -2715,6 +2725,7 @@ d/snd/d_snd_bgm_mml_parser_base.cpp: d/snd/d_snd_bgm_mml_parsers.cpp: .text start:0x8037D020 end:0x8037D800 align:16 + .data start:0x80549168 end:0x805491B8 .sdata start:0x805742F8 end:0x80574300 d/snd/d_snd_small_effect_mgr.cpp: @@ -2726,6 +2737,7 @@ d/snd/d_snd_small_effect_mgr.cpp: d/snd/d_snd_harp_mgr.cpp: .text start:0x8037F8C0 end:0x80382150 align:16 + .rodata start:0x804F38C8 end:0x804F38E0 .data start:0x805491D0 end:0x805491E0 .sdata start:0x80574308 end:0x80574310 .sbss start:0x80575DA0 end:0x80575DA8 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 81bfc1a4..e4b86c94 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -19905,15 +19905,15 @@ setVolume__11dSndSound_cFfl = .text:0x8035D050; // type:function size:0x1C setPitchRelated__11dSndSound_cFfl = .text:0x8035D070; // type:function size:0x1C setLinearPitch__11dSndSound_cFfl = .text:0x8035D090; // type:function size:0x1C resetTrackVolumes__11dSndSound_cFv = .text:0x8035D0B0; // type:function size:0xE8 -setTrackVolume__11dSndSound_cFUlfl = .text:0x8035D1A0; // type:function size:0x114 -setStrmTrackVolume__11dSndSound_cFUlfl = .text:0x8035D2C0; // type:function size:0xC0 +setTrackVolume__11dSndSound_cFUsfl = .text:0x8035D1A0; // type:function size:0x114 +setStrmTrackVolume__11dSndSound_cFUsfl = .text:0x8035D2C0; // type:function size:0xC0 setSingleSeqTrackVolume__11dSndSound_cFUsfl = .text:0x8035D380; // type:function size:0xA0 setSingleStrmTrackVolume__11dSndSound_cFUsfl = .text:0x8035D420; // type:function size:0xA0 -setEachSeqTrackVolume__11dSndSound_cFUlf = .text:0x8035D4C0; // type:function size:0xB8 -setEachStrmTrackVolume__11dSndSound_cFUlf = .text:0x8035D580; // type:function size:0xB8 +setEachSeqTrackVolume__11dSndSound_cFUsf = .text:0x8035D4C0; // type:function size:0xB8 +setEachStrmTrackVolume__11dSndSound_cFUsf = .text:0x8035D580; // type:function size:0xB8 getCurrentStrmTrackVolume__11dSndSound_cCFUl = .text:0x8035D640; // type:function size:0x24 setSeqTempoRatio__11dSndSound_cFfl = .text:0x8035D670; // type:function size:0x60 -setSeqTrackMute__11dSndSound_cFUlQ34nw4r3snd7SeqMute = .text:0x8035D6D0; // type:function size:0x78 +setSeqTrackMute__11dSndSound_cFUsQ34nw4r3snd7SeqMute = .text:0x8035D6D0; // type:function size:0x78 prepareSound__11dSndSound_cFUlUl = .text:0x8035D750; // type:function size:0x1E8 prepareSound__11dSndSound_cFPCcUl = .text:0x8035D940; // type:function size:0x58 onPreparing__11dSndSound_cFUlUl = .text:0x8035D9A0; // type:function size:0x68 @@ -19983,7 +19983,7 @@ shutdown__15dSndPlayerMgr_cFv = .text:0x8035EF90; // type:function size:0x38 calc__15dSndPlayerMgr_cFv = .text:0x8035EFD0; // type:function size:0x40 fn_8035F010 = .text:0x8035F010; // type:function size:0x20 isBgmPlayerId__15dSndPlayerMgr_cFUl = .text:0x8035F030; // type:function size:0x1C -fn_8035F050 = .text:0x8035F050; // type:function size:0x50 +isSoundPlayedByBgmBattlePlayer__15dSndPlayerMgr_cFUl = .text:0x8035F050; // type:function size:0x50 __dt__40SndMgrDisposer<22dSndControlPlayerMgr_c>Fv = .text:0x8035F0A0; // type:function size:0x78 create__40SndMgrDisposer<22dSndControlPlayerMgr_c>Fv = .text:0x8035F120; // type:function size:0x48 remove__40SndMgrDisposer<22dSndControlPlayerMgr_c>Fv = .text:0x8035F170; // type:function size:0x10 @@ -20404,8 +20404,8 @@ apply__26dSndControlPlayerLpfFreq_cFv = .text:0x8036C5F0; // type:function size: getAppliedValue__26dSndControlPlayerLpfFreq_cFv = .text:0x8036C600; // type:function size:0xC apply__25dSndControlPlayerFxSend_cFv = .text:0x8036C610; // type:function size:0x40 getAppliedValue__25dSndControlPlayerFxSend_cFv = .text:0x8036C650; // type:function size:0x58 -fn_8036C6B0 = .text:0x8036C6B0; // type:function size:0x64 -isInvalidSoundId = .text:0x8036C720; // type:function size:0x10 +isSoundPlayedByBgmBattlePlayer__12dSndBgmMgr_cFUl = .text:0x8036C6B0; // type:function size:0x64 +isBgmBattle2__12dSndBgmMgr_cFUl = .text:0x8036C720; // type:function size:0x10 __dt__30SndMgrDisposer<12dSndBgmMgr_c>Fv = .text:0x8036C730; // type:function size:0x78 create__30SndMgrDisposer<12dSndBgmMgr_c>Fv = .text:0x8036C7B0; // type:function size:0x48 remove__30SndMgrDisposer<12dSndBgmMgr_c>Fv = .text:0x8036C800; // type:function size:0x10 @@ -20479,7 +20479,7 @@ beginBgmBattleRoom__12dSndBgmMgr_cFv = .text:0x80370780; // type:function size:0 endBgmBattleRoom__12dSndBgmMgr_cFv = .text:0x803707E0; // type:function size:0x60 isPlayingAnyBattleMusic__12dSndBgmMgr_cFv = .text:0x80370840; // type:function size:0x78 fn_803708C0 = .text:0x803708C0; // type:function size:0x34 -fn_80370900 = .text:0x80370900; // type:function size:0xA0 +weirdCheckAlwaysFalse__12dSndBgmMgr_cFv = .text:0x80370900; // type:function size:0xA0 fn_803709A0 = .text:0x803709A0; // type:function size:0xA8 fn_80370A50 = .text:0x80370A50; // type:function size:0x74 fn_80370AD0 = .text:0x80370AD0; // type:function size:0x64 @@ -20527,13 +20527,13 @@ getBgmSoundByIndex__12dSndBgmMgr_cFUl = .text:0x803722D0; // type:function size: getBgmSoundHandleForId__12dSndBgmMgr_cCFUl = .text:0x803722F0; // type:function size:0x70 fn_80372360 = .text:0x80372360; // type:function size:0xC4 getSoundHandleForBgm__12dSndBgmMgr_cFUlUl = .text:0x80372430; // type:function size:0xD0 -fn_80372500 = .text:0x80372500; // type:function size:0xD8 +getActiveBgmSound__12dSndBgmMgr_cFv = .text:0x80372500; // type:function size:0xD8 fn_803725E0 = .text:0x803725E0; // type:function size:0xB4 fn_803726A0 = .text:0x803726A0; // type:function size:0xE4 findIdleBgmSoundHandle__12dSndBgmMgr_cFv = .text:0x80372790; // type:function size:0x10C fn_803728A0 = .text:0x803728A0; // type:function size:0x74 fn_80372920 = .text:0x80372920; // type:function size:0x3C -fn_80372960 = .text:0x80372960; // type:function size:0x8 +getBgmBattleSound__12dSndBgmMgr_cFv = .text:0x80372960; // type:function size:0x8 addToBgmSoundList__12dSndBgmMgr_cFQ212dSndBgmMgr_c14BgmSoundList_eP14dSndBgmSound_c = .text:0x80372970; // type:function size:0x6C appendToBgmSoundList__12dSndBgmMgr_cFQ212dSndBgmMgr_c14BgmSoundList_eP14dSndBgmSound_c = .text:0x803729E0; // type:function size:0x6C removeFromBgmSoundList__12dSndBgmMgr_cFQ212dSndBgmMgr_c14BgmSoundList_eP14dSndBgmSound_c = .text:0x80372A50; // type:function size:0x70 @@ -20714,34 +20714,34 @@ fn_80379980 = .text:0x80379980; // type:function size:0x158 fn_80379AE0 = .text:0x80379AE0; // type:function size:0x40 fn_80379B20 = .text:0x80379B20; // type:function size:0x200 __ct__14dSndBgmSound_cFv = .text:0x80379D20; // type:function size:0xF8 -fn_80379E20 = .text:0x80379E20; // type:function size:0x58 -fn_80379E80 = .text:0x80379E80; // type:function size:0xC -fn_80379E90 = .text:0x80379E90; // type:function size:0xC8 -fn_80379F60 = .text:0x80379F60; // type:function size:0xC8 -fn_8037A030 = .text:0x8037A030; // type:function size:0x4 -fn_8037A040 = .text:0x8037A040; // type:function size:0x5C -fn_8037A0A0 = .text:0x8037A0A0; // type:function size:0x20 +__dt__21dSndBgmSoundHarpMgr_cFv = .text:0x80379E20; // type:function size:0x58 +init__14dSndBgmSound_cFRQ34nw4r3snd14SoundStartablel = .text:0x80379E80; // type:function size:0xC +cancel__14dSndBgmSound_cFv = .text:0x80379E90; // type:function size:0xC8 +calc__14dSndBgmSound_cFv = .text:0x80379F60; // type:function size:0xC8 +postCalc__14dSndBgmSound_cFv = .text:0x8037A030; // type:function size:0x4 +calcPlaySamplePosition__14dSndBgmSound_cFv = .text:0x8037A040; // type:function size:0x5C +isBgmBattle__14dSndBgmSound_cCFv = .text:0x8037A0A0; // type:function size:0x20 fn_8037A0C0 = .text:0x8037A0C0; // type:function size:0xC fn_8037A0D0 = .text:0x8037A0D0; // type:function size:0x20 -fn_8037A0F0 = .text:0x8037A0F0; // type:function size:0x2D4 -fn_8037A3D0 = .text:0x8037A3D0; // type:function size:0x1D0 +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 -fn_8037A610 = .text:0x8037A610; // type:function size:0x250 -fn_8037A860 = .text:0x8037A860; // type:function size:0x58 -fn_8037A8C0 = .text:0x8037A8C0; // type:function size:0x7C -fn_8037A940 = .text:0x8037A940; // type:function size:0x104 -fn_8037AA50 = .text:0x8037AA50; // type:function size:0xE8 -fn_8037AB40 = .text:0x8037AB40; // type:function size:0x4C -fn_8037AB90 = .text:0x8037AB90; // type:function size:0x148 -fn_8037ACE0 = .text:0x8037ACE0; // type:function size:0xC0 -fn_8037ADA0 = .text:0x8037ADA0; // type:function size:0xC0 -fn_8037AE60 = .text:0x8037AE60; // type:function size:0x70 -fn_8037AED0 = .text:0x8037AED0; // type:function size:0x144 -fn_8037B020 = .text:0x8037B020; // type:function size:0x64 -fn_8037B090 = .text:0x8037B090; // type:function size:0x28 -fn_8037B0C0 = .text:0x8037B0C0; // type:function size:0x38 -fn_8037B100 = .text:0x8037B100; // type:function size:0x64 -fn_8037B170 = .text:0x8037B170; // type:function size:0x1C8 +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 +stop__14dSndBgmSound_cFl = .text:0x8037A940; // type:function size:0x104 +pause__14dSndBgmSound_cFbl = .text:0x8037AA50; // type:function size:0xE8 +pause__14dSndBgmSound_cFl = .text:0x8037AB40; // type:function size:0x4C +getPlaySamplePosition__14dSndBgmSound_cFv = .text:0x8037AB90; // type:function size:0x148 +getStrmPlaySamplePosition__14dSndBgmSound_cFv = .text:0x8037ACE0; // type:function size:0xC0 +getWavePlaySamplePosition__14dSndBgmSound_cFv = .text:0x8037ADA0; // type:function size:0xC0 +getSeqSoundPlaySamplePosition__14dSndBgmSound_cFv = .text:0x8037AE60; // type:function size:0x70 +calcSeqPlaySamplePosition__14dSndBgmSound_cFv = .text:0x8037AED0; // type:function size:0x144 +applyVars__14dSndBgmSound_cFv = .text:0x8037B020; // type:function size:0x64 +onBecomeActive__14dSndBgmSound_cFv = .text:0x8037B090; // type:function size:0x28 +getCurrentHarpVarSet__14dSndBgmSound_cFv = .text:0x8037B0C0; // type:function size:0x38 +getHarpData__14dSndBgmSound_cFUl = .text:0x8037B100; // type:function size:0x64 +loadNewHarpData__14dSndBgmSound_cFUl = .text:0x8037B170; // type:function size:0x1C8 fn_8037B340 = .text:0x8037B340; // type:function size:0x4C fn_8037B390 = .text:0x8037B390; // type:function size:0x4C fn_8037B3E0 = .text:0x8037B3E0; // type:function size:0x4C @@ -20767,15 +20767,15 @@ 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 -SomeSoundMgr__dtor = .text:0x8037BA70; // type:function size:0x78 -initSomeUnusedSoundMgr = .text:0x8037BAF0; // type:function size:0x48 -SomeSoundMgr__deref = .text:0x8037BB40; // type:function size:0x10 -SomeSoundMgr__ctor = .text:0x8037BB50; // type:function size:0x6C -getDATA_ = .text:0x8037BBC0; // type:function size:0x8 -fn_8037BBD0 = .text:0x8037BBD0; // type:function size:0x24 +__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 -fn_8037BCD0 = .text:0x8037BCD0; // type:function size:0x54 +getHarpMgrForSoundId__22dSndBgmBattleDataMgr_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 @@ -20810,11 +20810,11 @@ ReadVar__18dSndBgmMmlParser_cCFPPCUc = .text:0x8037CEF0; // type:function size:0 ReadArg__18dSndBgmMmlParser_cCFPPCUcQ218dSndBgmMmlParser_c10SeqArgType = .text:0x8037CF20; // type:function size:0xD8 CommandProc__18dSndBgmMmlParser_cCFUliUlll = .text:0x8037D000; // type:function size:0x4 NoteOnCommandProc__18dSndBgmMmlParser_cCFUliiil = .text:0x8037D010; // type:function size:0x4 -fn_8037D020 = .text:0x8037D020; // type:function size:0x64 -fn_8037D090 = .text:0x8037D090; // type:function size:0xE8 -fn_8037D180 = .text:0x8037D180; // type:function size:0x84 -fn_8037D210 = .text:0x8037D210; // type:function size:0x38 -fn_8037D250 = .text:0x8037D250; // type:function size:0x20 +__ct__22dSndBgmMmlParserHarp_cFP21dSndBgmSoundHarpMgr_c = .text:0x8037D020; // type:function size:0x64 +parseData__22dSndBgmMmlParserHarp_cFPCcUlUl = .text:0x8037D090; // type:function size:0xE8 +parseData__22dSndBgmMmlParserHarp_cFUlUl = .text:0x8037D180; // type:function size:0x84 +CommandProc__22dSndBgmMmlParserHarp_cCFUliUlll = .text:0x8037D210; // type:function size:0x38 +NoteOnCommandProc__22dSndBgmMmlParserHarp_cCFUliiil = .text:0x8037D250; // type:function size:0x20 fn_8037D270 = .text:0x8037D270; // type:function size:0x58 fn_8037D2D0 = .text:0x8037D2D0; // type:function size:0x68 fn_8037D340 = .text:0x8037D340; // type:function size:0x4 @@ -38039,15 +38039,15 @@ lbl_80549058 = .data:0x80549058; // type:object size:0x10 data:string lbl_80549068 = .data:0x80549068; // type:object size:0x10 lbl_80549078 = .data:0x80549078; // type:object size:0x10 lbl_80549088 = .data:0x80549088; // type:object size:0x34 -lbl_805490BC = .data:0x805490BC; // type:object size:0x44 +__vt__14dSndBgmSound_c = .data:0x805490BC; // type:object size:0x44 lbl_80549100 = .data:0x80549100; // type:object size:0x48 -lbl_80549148 = .data:0x80549148; // type:object size:0x10 +__vt__40SndMgrDisposer<22dSndBgmBattleDataMgr_c> = .data:0x80549148; // type:object size:0x10 __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 lbl_80549188 = .data:0x80549188; // type:object size:0x10 lbl_80549198 = .data:0x80549198; // type:object size:0x10 -lbl_805491A8 = .data:0x805491A8; // type:object size:0x10 +__vt__22dSndBgmMmlParserHarp_c = .data:0x805491A8; // type:object size:0x10 __vt__12SoundStopper = .data:0x805491B8; // type:object size:0xC __vt__38SndMgrDisposer<20dSndSmallEffectMgr_c> = .data:0x805491C4; // type:object size:0xC lbl_805491D0 = .data:0x805491D0; // type:object size:0x10 @@ -42296,9 +42296,9 @@ sInstance__24dSndAreaSoundEffectMgr_c = .sbss:0x80575D78; // type:object size:0x sDisposer__24dSndAreaSoundEffectMgr_c = .sbss:0x80575D7C; // type:object size:0x4 data:4byte sInstance__12dSndBgmMgr_c = .sbss:0x80575D80; // type:object size:0x4 data:4byte sDisposer__12dSndBgmMgr_c = .sbss:0x80575D84; // type:object size:0x4 data:4byte -lbl_80575D88 = .sbss:0x80575D88; // type:object size:0x8 data:4byte -SOME_UNUSED_SOUND_MGR = .sbss:0x80575D90; // type:object size:0x4 data:4byte -SOME_UNUSED_SOUND_MGR_source = .sbss:0x80575D94; // 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__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 22004320..707d5872 100644 --- a/configure.py +++ b/configure.py @@ -757,6 +757,7 @@ config.libs = [ Object(NonMatching, "d/snd/d_snd_bgm_sound_callbacks.cpp"), Object(NonMatching, "d/snd/d_snd_bgm_sound_battle_callbacks.cpp"), 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_harp_data.cpp"), diff --git a/include/d/snd/d_snd_bgm_battle_data_mgr.h b/include/d/snd/d_snd_bgm_battle_data_mgr.h new file mode 100644 index 00000000..50d5dc0e --- /dev/null +++ b/include/d/snd/d_snd_bgm_battle_data_mgr.h @@ -0,0 +1,28 @@ +#ifndef D_SND_BGM_BATTLE_DATA_MGR_H +#define D_SND_BGM_BATTLE_DATA_MGR_H + +#include "common.h" +#include "d/snd/d_snd_util.h" +#include "d/snd/d_snd_types.h" + +SND_DISPOSER_FORWARD_DECL(dSndBgmBattleDataMgr_c); + +// Previous Ghidra name: SomeUnusedSoundMgr +class dSndBgmBattleDataMgr_c { +public: + SND_DISPOSER_MEMBERS(dSndBgmBattleDataMgr_c); + +public: + dSndBgmBattleDataMgr_c(); + + static const char *getDataPrefix(); + static u32 getDataPrefixLength(); + + dSndBgmSoundHarpMgr_c *getHarpMgrForSoundId(u32 soundId); + +private: + /* 0x10 */ dSndBgmSoundHarpMgr_c *mpMgrs; + /* 0x14 */ u8 field_0x14; +}; + +#endif diff --git a/include/d/snd/d_snd_bgm_mgr.h b/include/d/snd/d_snd_bgm_mgr.h index ea5436fc..9dc08c9f 100644 --- a/include/d/snd/d_snd_bgm_mgr.h +++ b/include/d/snd/d_snd_bgm_mgr.h @@ -17,10 +17,13 @@ public: SND_DISPOSER_MEMBERS(dSndBgmMgr_c); public: + static bool isSoundPlayedByBgmBattlePlayer(u32 soundId); + static bool isBgmBattle2(u32 soundId); + enum BgmSoundList_e { BGM_LIST_PREPARING = 0, BGM_LIST_PLAYING = 1, - BGM_LIST_STOPPED = 2, + BGM_LIST_STOPPING = 2, BGM_LIST_MAX = 3, }; @@ -72,7 +75,19 @@ public: bool isPlayingAnyBattleMusic(); + void removeFromAllBgmSoundLists(dSndBgmSound_c *sound); + void addToBgmSoundList(BgmSoundList_e list, dSndBgmSound_c *sound); + void appendToBgmSoundList(BgmSoundList_e list, dSndBgmSound_c *sound); + + // Unless there's a Ghidra decompiler bug this function + // always returns false + bool weirdCheckAlwaysFalse(); + + dSndBgmSound_c *getActiveBgmSound(); + private: + dSndBgmBattleSound_c *getBgmBattleSound(); + bool stopBgmSound(dSndBgmSound_c *sound, s32 fadeFrames); void checkForPrepareStoppedBgmSound(u32 stoppedSoundId); dSndBgmSound_c *findNewBgmSoundHandle(); @@ -91,10 +106,7 @@ private: void calcLists(); void calcStopOldBgmSounds(); - void addToBgmSoundList(BgmSoundList_e list, dSndBgmSound_c *sound); - void appendToBgmSoundList(BgmSoundList_e list, dSndBgmSound_c *sound); void removeFromBgmSoundList(BgmSoundList_e list, dSndBgmSound_c *sound); - void removeFromAllBgmSoundLists(dSndBgmSound_c *sound); bool isInBgmSoundList(BgmSoundList_e list, dSndBgmSound_c *sound); dSndBgmSound_c *getFirstInBgmSoundList(BgmSoundList_e list); dSndBgmSound_c *getNextInBgmSoundList(BgmSoundList_e list, dSndBgmSound_c *sound); @@ -119,7 +131,7 @@ private: /* 0x250 */ s32 mScheduledSoundDelay; /* 0x254 */ dSndBgmSound_c *mBgmSounds[7]; /* 0x270 */ dSndBgmSound_c *field_0x270; - /* 0x274 */ UNKWORD field_0x274; + /* 0x274 */ dSndBgmSound_c *mpPrevActiveBgmSound; /* 0x278 */ nw4r::ut::List mBgmSoundLists[BGM_LIST_MAX]; // node offset 0xF0 -> dSndBgmSound_c /* 0x29C */ UNKWORD field_0x29C; /* 0x2A0 */ dSndActor_c mSoundActor; diff --git a/include/d/snd/d_snd_bgm_mml_parser_base.h b/include/d/snd/d_snd_bgm_mml_parser_base.h index b69946c1..9debde20 100644 --- a/include/d/snd/d_snd_bgm_mml_parser_base.h +++ b/include/d/snd/d_snd_bgm_mml_parser_base.h @@ -33,7 +33,7 @@ struct dBgmMmlTrack { * Partial copy of nw4r::snd::detail::MmlParser */ class dSndBgmMmlParser_c { -private: +protected: // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2d70c // Swapped - or maybe just returns a boolean enum ParseResult { diff --git a/include/d/snd/d_snd_bgm_mml_parsers.h b/include/d/snd/d_snd_bgm_mml_parsers.h new file mode 100644 index 00000000..52873832 --- /dev/null +++ b/include/d/snd/d_snd_bgm_mml_parsers.h @@ -0,0 +1,22 @@ +#ifndef D_SND_BGM_MML_PARSERS__H +#define D_SND_BGM_MML_PARSERS__H + +#include "d/snd/d_snd_bgm_mml_parser_base.h" +#include "d/snd/d_snd_types.h" + +class dSndBgmMmlParserHarp_c : dSndBgmMmlParser_c { +public: + dSndBgmMmlParserHarp_c(dSndBgmSoundHarpMgr_c *mgr); + + virtual void CommandProc(u32 trackNo, int wait, u32 command, s32 commandArg1, s32 commandArg2) const override; + virtual void NoteOnCommandProc(u32 trackNo, int wait, int key, int velocity, s32 length) const override; + + bool parseData(const char *soundLabel, u32 baseSoundId, u32 trackMask); + bool parseData(u32 baseSoundId, u32 trackMask); + +private: + /* 0x294 */ dSndBgmSoundHarpMgr_c *field_0x294; + /* 0x298 */ dSndBgmSoundHarpMgr_c *field_0x298; +}; + +#endif diff --git a/include/d/snd/d_snd_bgm_sound battle.h b/include/d/snd/d_snd_bgm_sound battle.h new file mode 100644 index 00000000..ad67643c --- /dev/null +++ b/include/d/snd/d_snd_bgm_sound battle.h @@ -0,0 +1,11 @@ +#ifndef D_SND_BGM_SOUND_BATTLE_H +#define D_SND_BGM_SOUND_BATTLE_H + +#include "d/snd/d_snd_bgm_sound.h" + +class dSndBgmBattleSound_c : public dSndBgmSound_c { +public: + dSndBgmBattleSound_c(); +}; + +#endif diff --git a/include/d/snd/d_snd_bgm_sound.h b/include/d/snd/d_snd_bgm_sound.h index f7fcb511..c85f4279 100644 --- a/include/d/snd/d_snd_bgm_sound.h +++ b/include/d/snd/d_snd_bgm_sound.h @@ -1,27 +1,106 @@ #ifndef D_SND_BGM_SOUND_H #define D_SND_BGM_SOUND_H +#include "common.h" +#include "d/snd/d_snd_bgm_sound_harp_mgr.h" #include "d/snd/d_snd_sound.h" #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, + BGM_FLAG_0x8 = 0x8, + BGM_FLAG_0x10 = 0x10, + BGM_FLAG_PAUSED = 0x20, + BGM_FLAG_0x40 = 0x40, + }; + public: + typedef void (*StopCallback)(bool); + typedef void (*CalcCallback)(dSndBgmSound_c *sound); + dSndBgmSound_c(); + virtual void cancel() override; // vt 0x08 + virtual void calc() override; // vt 0x0C + virtual void fadeIn(u32 id, s32 fadeFrames) override; // vt 0x10 + virtual nw4r::snd::SoundStartable::StartResult prepareSound(u32 soundId, u32 startOffset) override; // vt 0x14 + virtual nw4r::snd::SoundStartable::StartResult prepareSound(const char *label, u32 startOffset) override; // vt 0x18 + virtual void onPreparing(u32 soundId, u32 startOffset) override; // vt 0x1C + virtual void stop(s32 fadeFrames) override; // vt 0x20 + virtual void pause(bool pauseFlag, s32 fadeFrames) override; // vt 0x24 + virtual void init(nw4r::snd::SoundStartable &startable, s32 idx); // vt 0x28 + virtual void vt_0x2C(); // vt 0x2C + virtual void pause(s32 fadeFrames); // vt 0x30 + virtual void loadSeqConfig(u32 soundId); // vt 0x34 + virtual void postCalc() {} // vt 0x38 + virtual void calcSeqPlaySamplePosition(); // vt 0x3C + virtual void loadCallbacks(u32 soundId); // vt 0x40 + + nw4r::snd::SoundStartable::StartResult startBgmSound(u32 soundId, s32 fadeFrames, u32 startOffset); bool isPreparedSoundId(u32 soundId) const { return IsPrepared() && !mIsRunning && GetId() == soundId; } -private: - /* 0x0F0 */ nw4r::ut::Node mBgmMgrNode; -}; + bool isPrepared() const { + return IsPrepared() && !mIsRunning; + } -class dSndBgmBattleSound_c : public dSndBgmSound_c { -public: - dSndBgmBattleSound_c(); + void applyVars(); + void onBecomeActive(); + bool isBgmBattle() const; + + const dSndBgmDataHarpVarSetBase_c *getCurrentHarpVarSet(); + + u32 getStrmPlaySamplePosition(); + u32 getWavePlaySamplePosition(); + +private: + void getHarpData(u32 soundId); + bool loadNewHarpData(u32 soundId); + + void calcPlaySamplePosition(); + u32 getPlaySamplePosition(); + u32 getSeqSoundPlaySamplePosition(); + static dSndBgmSoundHarpMgr_c *spGlobalHarpMgr; + + /* 0x0F0 */ nw4r::ut::Node mBgmMgrNode; + /* 0x0F8 */ nw4r::snd::SoundStartable *mpStartable; + /* 0x0FC */ dSoundSource_c *mpSoundSource; + /* 0x100 */ s32 mIndex; + /* 0x104 */ UNKWORD field_0x104; + /* 0x108 */ s32 mSeqTempo; + /* 0x10C */ u32 mBgmFlags; + /* 0x110 */ bool mDidRewindPlaySamplePosition; + /* 0x114 */ s32 field_0x114; + /* 0x118 */ s32 field_0x118; + /* 0x11C */ u32 mPlaySamplePosition; + /* 0x120 */ dSndBgmSoundHarpMgr_c mHarpMgr; + /* 0x140 */ dSndBgmSoundHarpMgr_c *mpHarpMgr; + /* 0x144 */ const dSndBgmSeqConfig *mpSeqConfig; + /* 0x148 */ s32 mSeqPlaySamplePosition; + /* 0x14C */ UNKWORD field_0x14C[2]; + /* 0x154 */ f32 field_0x154[2]; + /* 0x15C */ StopCallback mpStopCallback; + /* 0x160 */ CalcCallback mpCalcCallback; + /* 0x164 */ void *cb3; + /* 0x168 */ void *cb4; + /* 0x16C */ void *cb5; + /* 0x170 */ void *cb6; + /* 0x174 */ void *cb7; + /* 0x178 */ void *cb8; + /* 0x17C */ void *cb9; + /* 0x180 */ void *cb10; }; #endif 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 498a3c67..ca5aa14e 100644 --- a/include/d/snd/d_snd_bgm_sound_harp_mgr.h +++ b/include/d/snd/d_snd_bgm_sound_harp_mgr.h @@ -4,7 +4,7 @@ #include "common.h" #include "d/snd/d_snd_bgm_harp_data.h" -class dSndBgmSoundHarpMgr_c : public dSndBgmHarpData_c { +class dSndBgmSoundHarpMgr_c { public: dSndBgmSoundHarpMgr_c(); ~dSndBgmSoundHarpMgr_c() {} @@ -21,10 +21,31 @@ public: return mIsLoaded; } + void setField_0x08(s32 value) { + mHarpData.setField_0x08(value); + } + + void setTempo(s32 tempo) { + mTempo = tempo; + } + + s32 getTempo() const { + return mTempo; + } + + void addVar(int wait, int key, int velocity) { + mHarpData.addVar(wait, key, velocity); + } + + void resetPrevIdx() { + mPrevIdx = -1; + } + private: + /* 0x00 */ dSndBgmHarpData_c mHarpData; /* 0x0C */ dSndBgmDataHarpVarSetBase_c *mpCurrVarSet; /* 0x10 */ u32 mSoundId; - /* 0x14 */ UNKWORD field_0x14; + /* 0x14 */ s32 mTempo; /* 0x18 */ s32 mPrevIdx; /* 0x1C */ u8 field_0x1C; /* 0x1D */ bool mIsLoaded; diff --git a/include/d/snd/d_snd_mgr.h b/include/d/snd/d_snd_mgr.h index d1e92710..a8f73022 100644 --- a/include/d/snd/d_snd_mgr.h +++ b/include/d/snd/d_snd_mgr.h @@ -32,6 +32,17 @@ public: return label; } + static u32 getPlayerId(u32 soundId) { + nw4r::snd::SoundArchive::SoundInfo info; + u32 playerId; + if (!sInstance->getArchive()->ReadSoundInfo(soundId, &info)) { + playerId = -1; + } else { + playerId = info.playerId; + } + return playerId; + } + private: static dSndMgr_c *sInstance; diff --git a/include/d/snd/d_snd_player_mgr.h b/include/d/snd/d_snd_player_mgr.h index 1dfa2a44..8302edd6 100644 --- a/include/d/snd/d_snd_player_mgr.h +++ b/include/d/snd/d_snd_player_mgr.h @@ -79,6 +79,7 @@ public: const char *getSoundArchivePath(); u32 convertLabelStringToSoundId(const char *label) const; static bool isBgmPlayerId(u32 id); + static bool isSoundPlayedByBgmBattlePlayer(u32 soundId); u32 getSomeUserParam(u32 soundId) const; nw4r::snd::SoundArchivePlayer &getSoundArchivePlayerForType(s32 sourceType); diff --git a/include/d/snd/d_snd_sound.h b/include/d/snd/d_snd_sound.h index 5ef8cc5f..ae9dcb5c 100644 --- a/include/d/snd/d_snd_sound.h +++ b/include/d/snd/d_snd_sound.h @@ -153,20 +153,20 @@ public: void setVolume(f32 volume, s32 frames); void setPitchRelated(f32 pitch, s32 frames); void setLinearPitch(f32 pitch, s32 frames); - void setTrackVolume(u32 trackFlags, f32 volume, s32 frames); - void setStrmTrackVolume(u32 trackFlags, f32 volume, s32 frames); + void setTrackVolume(u16 trackFlags, f32 volume, s32 frames); + void setStrmTrackVolume(u16 trackFlags, f32 volume, s32 frames); void setSingleSeqTrackVolume(u16 index, f32 volume, s32 frames); void setSingleStrmTrackVolume(u16 index, f32 volume, s32 frames); // why f32 frames? - void setEachSeqTrackVolume(u32 trackFlags, f32 frames); - void setEachStrmTrackVolume(u32 trackFlags, f32 frames); + void setEachSeqTrackVolume(u16 trackFlags, f32 frames); + void setEachStrmTrackVolume(u16 trackFlags, f32 frames); void setSeqTempoRatio(f32 ratio, s32 frames); - void setSeqTrackMute(u32 trackFlags, nw4r::snd::SeqMute mute); + void setSeqTrackMute(u16 trackFlags, nw4r::snd::SeqMute mute); void forceStop(); - s16 readSeqTrackVariable(int varNo); + s32 readSeqTrackVariable(int varNo); void writeSeqTrackVariable(int varNo, s16 value); void linkCtrl(dSndControlSound_c *); @@ -184,7 +184,7 @@ public: return mIsPreparing && !mIsRunning && GetId() == soundId; } - bool isFadingOutSoundId(u32 soundId) const { + bool isFadingOut() const { return mIsFadingOut && IsAttachedSound(); } diff --git a/include/d/snd/d_snd_source.h b/include/d/snd/d_snd_source.h index b2a1ee49..161322ab 100644 --- a/include/d/snd/d_snd_source.h +++ b/include/d/snd/d_snd_source.h @@ -15,7 +15,6 @@ /** Size: probably 0x15C */ class dSoundSource_c : public dSoundSourceIf_c, public dSnd3DActor_c { public: - dSoundSource_c(s32 sourceType, dAcBase_c *, const char *name, dSndSourceGroup_c *pOwnerGroup); virtual ~dSoundSource_c(); @@ -34,7 +33,6 @@ public: nw4r::snd::SoundHandle *holdSound(u32 soundId, nw4r::snd::SoundHandle *handle); u32 specializeBgHitSoundId(u32 baseSoundId, u32 polyAttr0, u32 polyAttr1); - // This is where it gets a bit wild and this class starts mixing in overrides between // new virtual functions, which causes the vtable to list these functions in exactly this // order. @@ -206,6 +204,15 @@ public: dSndSeSound2_c *getHandleType2ForSoundId(u32 soundId); + // Would have loved to roll this in with a PrepareSound function + // but that doesn't work + void markPrepared() { + field_0x11C |= 0x80000000; + } + + nw4r::snd::SoundStartable::StartResult + startSound(u32 soundId, nw4r::snd::SoundHandle *handle, nw4r::snd::SoundHandle **pOutHandle); + protected: StartResult setupSoundCommon(nw4r::snd::SoundHandle *pHandle, u32 soundId, const StartInfo *pStartInfo, void *arg); void setVolumeFade(f32 volume, u32 fadeFrames); @@ -226,10 +233,6 @@ private: dSndDistantSoundActor_c *startBaseSoundAtPosition(u32 baseSoundId, const nw4r::math::VEC3 *position, f32 volume); nw4r::snd::SoundHandle *startBaseSound(u32 baseSoundId, f32 volume); - - nw4r::snd::SoundStartable::StartResult - startSound(u32 soundId, nw4r::snd::SoundHandle *handle, nw4r::snd::SoundHandle **pOutHandle); - nw4r::snd::SoundHandle *continueHoldingSound( dSndSeSound2_c *seHandle, u32 soundId, dSndDistantSoundActor_c *distant, const nw4r::math::VEC3 *position ); diff --git a/include/d/snd/d_snd_state_mgr.h b/include/d/snd/d_snd_state_mgr.h index 9479620e..9f7cedf1 100644 --- a/include/d/snd/d_snd_state_mgr.h +++ b/include/d/snd/d_snd_state_mgr.h @@ -31,6 +31,7 @@ public: }; enum EventFlags_e { + EVENT_0x2 = 0x2, EVENT_MUTE_BGM_PARTIAL = 0x8, EVENT_MUTE_BGM_FULL = 0x10, EVENT_MUTE_STAGE_EFFECTS_PARTIAL = 0x20, @@ -39,6 +40,7 @@ public: EVENT_MUTE_ENEMY_FULL = 0x100, EVENT_MUTE_OBJ_PARTIAL = 0x200, EVENT_MUTE_OBJ_FULL = 0x400, + EVENT_0x400000 = 0x400000, }; dSndStateMgr_c(); @@ -89,10 +91,18 @@ public: field_0x010 &= ~mask; } - bool checkFlag0x94(u32 mask) const { + bool checkEventFlag(u32 mask) const { return field_0x094 & mask; } + void onEventFlag(u32 mask) { + field_0x094 |= mask; + } + + void offEventFlag(u32 mask) { + field_0x094 &= ~mask; + } + void setFlowEvent(u32 eventId); const char *getCurrentStageMusicDemoName() const; diff --git a/include/d/snd/d_snd_types.h b/include/d/snd/d_snd_types.h index 8def0e2a..6c6a9d9a 100644 --- a/include/d/snd/d_snd_types.h +++ b/include/d/snd/d_snd_types.h @@ -22,4 +22,6 @@ class dSndSeSound2_c; class dSndBgmSound_c; class dSndBgmBattleSound_c; +class dSndBgmSoundHarpMgr_c; + #endif diff --git a/include/nw4r/snd/snd_StrmSound.h b/include/nw4r/snd/snd_StrmSound.h index 240659ea..88bb3205 100644 --- a/include/nw4r/snd/snd_StrmSound.h +++ b/include/nw4r/snd/snd_StrmSound.h @@ -88,6 +88,8 @@ namespace nw4r { namespace snd { namespace detail return DEBUG_SOUND_TYPE_STRMSOUND; } + u32 GetPlaySamplePosition() const { return mStrmPlayer.GetPlaySamplePosition(); } + // static members public: static int const FILE_STREAM_BUFFER_SIZE = 128; diff --git a/include/nw4r/snd/snd_StrmSoundHandle.h b/include/nw4r/snd/snd_StrmSoundHandle.h index e377ed9a..712fb90e 100644 --- a/include/nw4r/snd/snd_StrmSoundHandle.h +++ b/include/nw4r/snd/snd_StrmSoundHandle.h @@ -41,6 +41,12 @@ namespace nw4r { namespace snd mSound->SetTrackVolume(trackFlags, volume, fadeFrames); } + u32 GetPlaySamplePosition() const { + if (!IsAttachedSound()) + return -1; + return mSound->GetPlaySamplePosition(); + } + // members private: /* base NonCopyable */ // size 0x00, offset 0x00 diff --git a/include/nw4r/snd/snd_WaveSound.h b/include/nw4r/snd/snd_WaveSound.h index 87989c8e..568ef104 100644 --- a/include/nw4r/snd/snd_WaveSound.h +++ b/include/nw4r/snd/snd_WaveSound.h @@ -74,6 +74,8 @@ namespace nw4r { namespace snd { namespace detail return DEBUG_SOUND_TYPE_WAVESOUND; } + u32 GetPlaySamplePosition() const { return mWsdPlayer.GetPlaySamplePosition(); } + // static members public: static ut::detail::RuntimeTypeInfo const typeInfo; diff --git a/include/nw4r/snd/snd_WaveSoundHandle.h b/include/nw4r/snd/snd_WaveSoundHandle.h index af7de2b1..67a56540 100644 --- a/include/nw4r/snd/snd_WaveSoundHandle.h +++ b/include/nw4r/snd/snd_WaveSoundHandle.h @@ -7,6 +7,8 @@ #include "common.h" // nullptr +#include "nw4r/snd/snd_WaveSound.h" // snd::WaveSound + #include "nw4r/ut/ut_NonCopyable.h" // ut::NonCopyable /******************************************************************************* @@ -30,10 +32,17 @@ namespace nw4r { namespace snd public: // cdtors WaveSoundHandle(SoundHandle *handle); + ~WaveSoundHandle() { DetachSound(); } // methods bool IsAttachedSound() const { return mSound != nullptr; } + u32 GetPlaySamplePosition() const { + if (!IsAttachedSound()) + return -1; + return mSound->GetPlaySamplePosition(); + } + void DetachSound(); // members diff --git a/src/d/snd/d_snd_bgm_battle_data_mgr.cpp b/src/d/snd/d_snd_bgm_battle_data_mgr.cpp new file mode 100644 index 00000000..a7f01e93 --- /dev/null +++ b/src/d/snd/d_snd_bgm_battle_data_mgr.cpp @@ -0,0 +1,18 @@ +#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_mgr.cpp b/src/d/snd/d_snd_bgm_mgr.cpp index 597be71f..325a71bb 100644 --- a/src/d/snd/d_snd_bgm_mgr.cpp +++ b/src/d/snd/d_snd_bgm_mgr.cpp @@ -2,6 +2,7 @@ #include "common.h" #include "d/snd/d_snd_bgm_sound.h" +#include "d/snd/d_snd_bgm_sound battle.h" #include "d/snd/d_snd_mgr.h" #include "d/snd/d_snd_player_mgr.h" #include "d/snd/d_snd_sound.h" @@ -10,6 +11,18 @@ #include "nw4r/snd/snd_SoundArchive.h" #include "nw4r/ut/ut_list.h" +bool dSndBgmMgr_c::isSoundPlayedByBgmBattlePlayer(u32 soundId) { + if (soundId == -1) { + return false; + } + + return dSndMgr_c::getPlayerId(soundId) == dSndPlayerMgr_c::PLAYER_BGM_BATTLE; +} + +bool dSndBgmMgr_c::isBgmBattle2(u32 soundId) { + return soundId == BGM_BATTLE2; +} + SND_DISPOSER_DEFINE(dSndBgmMgr_c); dSndBgmMgr_c::dSndBgmMgr_c() @@ -18,7 +31,7 @@ dSndBgmMgr_c::dSndBgmMgr_c() field_0x248(0), mScheduledSoundId(-1), mScheduledSoundDelay(0), - field_0x274(0), + mpPrevActiveBgmSound(nullptr), field_0x29C(0), mSoundActor(dSndMgr_c::GetInstance()->getPlayer()), field_0x2F4(1.0f), @@ -64,16 +77,27 @@ dSndBgmMgr_c::dSndBgmMgr_c() } void dSndBgmMgr_c::calcLists() { - // TODO ... + // TODO Regswap + dSndBgmSound_c *snd; + snd = getActiveBgmSound(); + if (snd != nullptr) { + if (snd != mpPrevActiveBgmSound) { + snd->onBecomeActive(); + } + snd->applyVars(); + } + mpPrevActiveBgmSound = snd; + + dSndBgmSound_c *next, *it; for (it = getFirstInBgmSoundList(BGM_LIST_PLAYING); it != nullptr; it = next) { next = getNextInBgmSoundList(BGM_LIST_PLAYING, it); it->calc(); } - for (it = getFirstInBgmSoundList(BGM_LIST_STOPPED); it != nullptr; it = next) { - next = getNextInBgmSoundList(BGM_LIST_STOPPED, it); + for (it = getFirstInBgmSoundList(BGM_LIST_STOPPING); it != nullptr; it = next) { + next = getNextInBgmSoundList(BGM_LIST_STOPPING, it); it->calc(); } @@ -152,17 +176,27 @@ bool dSndBgmMgr_c::endBgmBattleRoom() { return playFanSound(BGM_BATTLE_ROOM_OUTRO); } +bool dSndBgmMgr_c::weirdCheckAlwaysFalse() { + u32 soundId = getBgmBattleSound()->GetId(); + bool ok = false; + // @bug should be != -1 + if (soundId != 0) { + if (getBgmBattleSound()->isPlaying()) { + ok = true; + } + } + // @bug passes a boolean to a function expecting a sound ID. + // function only returns true if sound ID is 0x1585, so this + // always returns false + return isBgmBattle2(ok); +} + void dSndBgmMgr_c::playDelayedSound(u32 soundId, s32 delay) { if (soundId == -1) { return; } - nw4r::snd::SoundArchive::SoundInfo info; - u32 playerId; - if (!dSndMgr_c::GetInstance()->getArchive()->ReadSoundInfo(soundId, &info)) { - playerId = -1; - } else { - playerId = info.playerId; - } + + u32 playerId = dSndMgr_c::getPlayerId(soundId); switch (playerId) { case dSndPlayerMgr_c::PLAYER_BGM: @@ -197,12 +231,7 @@ void dSndBgmMgr_c::cancelDelayedBgm() { } nw4r::snd::SoundArchive::SoundInfo info; - u32 playerId; - if (!dSndMgr_c::GetInstance()->getArchive()->ReadSoundInfo(mScheduledSoundId, &info)) { - playerId = -1; - } else { - playerId = info.playerId; - } + u32 playerId = dSndMgr_c::getPlayerId(mScheduledSoundId); if (dSndPlayerMgr_c::isBgmPlayerId(playerId)) { cancelDelayedSound(); @@ -216,13 +245,7 @@ bool dSndBgmMgr_c::startDelayedSound() { bool ok = false; - nw4r::snd::SoundArchive::SoundInfo info; - u32 playerId; - if (!dSndMgr_c::GetInstance()->getArchive()->ReadSoundInfo(mScheduledSoundId, &info)) { - playerId = -1; - } else { - playerId = info.playerId; - } + u32 playerId = dSndMgr_c::getPlayerId(mScheduledSoundId); switch (playerId) { case dSndPlayerMgr_c::PLAYER_BGM: case dSndPlayerMgr_c::PLAYER_BGM_BATTLE: ok = playBgm(mScheduledSoundId, 0, false); break; @@ -275,7 +298,7 @@ bool dSndBgmMgr_c::isPlayingBgmSoundId(u32 soundId) const { bool dSndBgmMgr_c::isFadingOutBgmSoundId(u32 soundId) const { for (int i = 0; i < 7; i++) { - if (mBgmSounds[i]->GetId() == soundId && mBgmSounds[i]->isFadingOutSoundId(soundId)) { + if (mBgmSounds[i]->GetId() == soundId && mBgmSounds[i]->isFadingOut()) { return true; } } diff --git a/src/d/snd/d_snd_bgm_mml_parsers.cpp b/src/d/snd/d_snd_bgm_mml_parsers.cpp new file mode 100644 index 00000000..e43782cc --- /dev/null +++ b/src/d/snd/d_snd_bgm_mml_parsers.cpp @@ -0,0 +1,74 @@ +#include "d/snd/d_snd_bgm_mml_parsers.h" + +#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_player_mgr.h" +#include "nw4r/snd/snd_SoundArchive.h" +#include "sized_string.h" + +dSndBgmMmlParserHarp_c::dSndBgmMmlParserHarp_c(dSndBgmSoundHarpMgr_c *mgr) + : dSndBgmMmlParser_c(&dSndMgr_c::GetInstance()->getPlayer(), dSndMgr_c::GetInstance()->getArchive()) { + field_0x294 = mgr; + field_0x298 = mgr; +} + +bool dSndBgmMmlParserHarp_c::parseData(const char *soundLabel, u32 baseSoundId, u32 trackMask) { + if (soundLabel == nullptr) { + return false; + } + bool ok = false; + field_0x294->reset(); + SizedString<64> dataLabel; + dataLabel.sprintf("%s%s", dSndBgmBattleDataMgr_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); + if (ok) { + field_0x294->setSoundId(baseSoundId); + } + } + field_0x294->setLoaded(); + return ok; +} + +bool dSndBgmMmlParserHarp_c::parseData(u32 baseSoundId, u32 trackMask) { + if (baseSoundId == -1) { + return false; + } + return parseData(dSndMgr_c::getSoundLabelString(baseSoundId), baseSoundId, trackMask); +} + +void dSndBgmMmlParserHarp_c::CommandProc(u32 trackNo, int wait, u32 command, s32 commandArg1, s32 commandArg2) const { + if (command > 0xFF) { + return; + } + + // TODO type + switch ((s32)trackNo) { + case 15: + if (command == MML_JUMP) { + field_0x298->setField_0x08(wait); + } + break; + default: + if (command == MML_SET_TEMPO) { + field_0x294->setTempo(commandArg1); + } + break; + + } +} + +void dSndBgmMmlParserHarp_c::NoteOnCommandProc(u32 trackNo, int wait, int key, int velocity, s32 length) const { + // TODO type + switch ((s32)trackNo) { + case 15: + field_0x298->addVar(wait, key, velocity); + break; + default: + break; + + } +} diff --git a/src/d/snd/d_snd_bgm_sound.cpp b/src/d/snd/d_snd_bgm_sound.cpp new file mode 100644 index 00000000..35a28b38 --- /dev/null +++ b/src/d/snd/d_snd_bgm_sound.cpp @@ -0,0 +1,512 @@ +#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_mgr.h" +#include "d/snd/d_snd_player_mgr.h" +#include "d/snd/d_snd_sound.h" +#include "d/snd/d_snd_source.h" +#include "d/snd/d_snd_state_mgr.h" +#include "d/snd/d_snd_wzsound.h" +#include "nw4r/snd/snd_SeqSoundHandle.h" +#include "nw4r/snd/snd_SoundArchive.h" +#include "nw4r/snd/snd_SoundStartable.h" +#include "nw4r/snd/snd_StrmSoundHandle.h" +#include "nw4r/snd/snd_WaveSoundHandle.h" +#include "toBeSorted/music_mgrs.h" + +dSndBgmSoundHarpMgr_c *dSndBgmSound_c::spGlobalHarpMgr; + +dSndBgmSound_c::dSndBgmSound_c() + : mpStartable(nullptr), + mpSoundSource(nullptr), + mIndex(7), + field_0x104(0), + mSeqTempo(-1), + mBgmFlags(0), + mDidRewindPlaySamplePosition(false), + field_0x114(-1), + field_0x118(0x180), + mPlaySamplePosition(0), + mpHarpMgr(&mHarpMgr), + mpSeqConfig(nullptr), + mSeqPlaySamplePosition(-1), + // not initialized!!! + // mpStopCallback(nullptr), + mpCalcCallback(nullptr), + cb3(nullptr), + cb4(nullptr), + cb5(nullptr), + cb6(nullptr), + cb7(nullptr), + cb8(nullptr), + cb9(nullptr), + cb10(nullptr) { + for (int i = 0; i < 2; i++) { + field_0x14C[i] = 0; + field_0x154[i] = 0.0f; + } + + if (spGlobalHarpMgr == nullptr) { + spGlobalHarpMgr = new dSndBgmSoundHarpMgr_c(); + } +} + +void dSndBgmSound_c::init(nw4r::snd::SoundStartable &startable, s32 idx) { + mpStartable = &startable; + mIndex = idx; +} + +void dSndBgmSound_c::cancel() { + if (hasState()) { + dSndSound_c::cancel(); + mBgmFlags = 0; + field_0x104 = 0; + mDidRewindPlaySamplePosition = false; + mpHarpMgr = &mHarpMgr; + mpSeqConfig = nullptr; + mPlaySamplePosition = 0; + mSeqPlaySamplePosition = -1; + field_0x114 = -1; + mSeqTempo = -1; + field_0x118 = 0x180; + mHarpMgr.reset(); + for (int i = 0; i < 2; i++) { + field_0x14C[i] = 0; + field_0x154[i] = 0.0f; + } + dSndBgmMgr_c::GetInstance()->removeFromAllBgmSoundLists(this); + } +} + +void dSndBgmSound_c::calc() { + dSndSound_c::calc(); + mDidRewindPlaySamplePosition = false; + if (mIsRunning) { + if (!IsAttachedSound()) { + if (mpStopCallback != nullptr) { + (mpStopCallback)(false); + mpStopCallback = nullptr; + } + cancel(); + } else { + field_0x104++; + postCalc(); + calcPlaySamplePosition(); + if (mpCalcCallback != nullptr) { + (mpCalcCallback)(this); + } + } + } +} + +void dSndBgmSound_c::calcPlaySamplePosition() { + if (!isSeqSound()) { + u32 oldPos = mPlaySamplePosition; + mPlaySamplePosition = getPlaySamplePosition(); + if (mPlaySamplePosition < oldPos) { + mDidRewindPlaySamplePosition = true; + } + } +} + +bool dSndBgmSound_c::isBgmBattle() const { + // TODO index constants + if (mIndex == 4) { + return true; + } + return (mBgmFlags & BGM_FLAG_BATTLE) != 0; +} + +nw4r::snd::SoundStartable::StartResult dSndBgmSound_c::startBgmSound(u32 soundId, s32 fadeFrames, u32 startOffset) { + if (isPlaying()) { + stop(0); + } + + nw4r::snd::SoundStartable::StartResult res; + if (isPrepared() || isPreparing()) { + if (soundId != GetId()) { + return nw4r::snd::SoundStartable::START_ERR_USER; + } + if (startOffset != 0 && mPrevStartOffset != startOffset) { + return nw4r::snd::SoundStartable::START_ERR_USER; + } + + (void)IsPrepared(); // return value ignored + StartPrepared(); + res = nw4r::snd::SoundStartable::START_SUCCESS; + } else { + if (startOffset == 0) { + if (mpSoundSource != nullptr) { + res = mpSoundSource->startSound(soundId, this, nullptr); + } else { + res = mpStartable->StartSoundReturnStatus(this, soundId, nullptr); + } + } else { + nw4r::snd::SoundStartable::StartInfo info; + info.enableFlag |= nw4r::snd::SoundStartable::StartInfo::ENABLE_START_OFFSET; + + getHarpData(soundId); + if (mpHarpMgr != nullptr) { + mSeqTempo = mpHarpMgr->getTempo(); + } + + 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; + info.startOffset = mSeqPlaySamplePosition; + } else { + info.startOffsetType = nw4r::snd::SoundStartable::StartInfo::START_OFFSET_TYPE_MILLISEC; + info.startOffset = startOffset; + } + + if (mpSoundSource != nullptr) { + // TODO - is it a @bug that no pStartInfo is passed here? + res = mpSoundSource->startSound(soundId, this, nullptr); + } else { + res = mpStartable->StartSoundReturnStatus(this, soundId, &info); + } + } + } + + if (res == nw4r::snd::SoundStartable::START_SUCCESS) { + fadeIn(soundId, fadeFrames); + } else { + cancel(); + } + + return res; +} + +void dSndBgmSound_c::fadeIn(u32 id, s32 fadeFrames) { + dSndSound_c::fadeIn(id, fadeFrames); + u32 param = dSndMgr_c::GetInstance()->getArchive()->GetSoundUserParam(id); + if (dSndMgr_c::GetInstance()->getArchive()->GetSoundType(id) == nw4r::snd::SoundArchive::SOUND_TYPE_STRM) { + // Mute all seq tracks but the first + setStrmTrackVolume(~(1 << 0), 0.0f, 0); + // Unmute second and third based on flags + if ((param & 0x10000) != 0) { + setStrmTrackVolume((1 << 1), 1.0f, 0); + } + if ((param & 0x20000) != 0) { + setStrmTrackVolume((1 << 2), 1.0f, 0); + } + } + + loadCallbacks(id); + loadSeqConfig(id); + getHarpData(id); + if (mpHarpMgr != nullptr) { + mSeqTempo = mpHarpMgr->getTempo(); + } + + if ((param & 0x40000000) != 0) { + mBgmFlags |= BGM_FLAG_0x10 | BGM_FLAG_0x8; + dSndStateMgr_c::GetInstance()->onEventFlag(dSndStateMgr_c::EVENT_0x400000); + } + + if ((param & 0x10000000) != 0) { + mBgmFlags |= BGM_FLAG_0x10; + dSndStateMgr_c::GetInstance()->onEventFlag(dSndStateMgr_c::EVENT_0x400000); + } + + if ((param & 0x800000) != 0) { + mBgmFlags |= BGM_FLAG_0x40; + } + + if (dSndPlayerMgr_c::isSoundPlayedByBgmBattlePlayer(id)) { + mBgmFlags |= BGM_FLAG_BATTLE; + } + + if (id == BGM_MUTE) { + dSndBgmMgr_c::GetInstance()->appendToBgmSoundList(dSndBgmMgr_c::BGM_LIST_PLAYING, this); + } else { + dSndBgmMgr_c::GetInstance()->addToBgmSoundList(dSndBgmMgr_c::BGM_LIST_PLAYING, this); + } + + if (dSndBgmMgr_c::GetInstance()->getActiveBgmSound() == this) { + mpHarpMgr->setPlaySamplePosition(0); + } +} + +// 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) { + return nw4r::snd::SoundStartable::START_ERR_USER; + } + + if (isPlaying()) { + return nw4r::snd::SoundStartable::START_ERR_USER; + } + + if (isPreparingSoundId(soundId)) { + if (mPrevStartOffset == startOffset) { + return nw4r::snd::SoundStartable::START_ERR_USER; + } + forceStop(); + } else { + if (isPreparing()) { + forceStop(); + } else { + fn_80372920(FANFARE_SOUND_MGR); + } + } + + nw4r::snd::SoundStartable::StartResult res; + if (startOffset == 0) { + if (mpSoundSource != nullptr) { + mpSoundSource->markPrepared(); + res = mpSoundSource->PrepareSoundReturnStatus(this, soundId, nullptr); + } else { + res = mpStartable->PrepareSoundReturnStatus(this, soundId, nullptr); + } + } else { + nw4r::snd::SoundStartable::StartInfo info; + info.enableFlag |= nw4r::snd::SoundStartable::StartInfo::ENABLE_START_OFFSET; + info.startOffsetType = nw4r::snd::SoundStartable::StartInfo::START_OFFSET_TYPE_MILLISEC; + info.startOffset = startOffset; + if (mpSoundSource != nullptr) { + mpSoundSource->markPrepared(); + // TODO - is it a @bug that no pStartInfo is passed here? + res = mpSoundSource->PrepareSoundReturnStatus(this, soundId, nullptr); + } else { + res = mpStartable->PrepareSoundReturnStatus(this, soundId, &info); + } + } + + if (res == nw4r::snd::SoundStartable::START_SUCCESS) { + onPreparing(soundId, startOffset); + } else { + cancel(); + } + + return res; +} + +nw4r::snd::SoundStartable::StartResult dSndBgmSound_c::prepareSound(const char *label, u32 startOffset) { + return prepareSound(dSndPlayerMgr_c::GetInstance()->convertLabelStringToSoundId(label), startOffset); +} + +void dSndBgmSound_c::onPreparing(u32 soundId, u32 startOffset) { + if (soundId == -1) { + return; + } + + dSndSound_c::onPreparing(soundId, startOffset); + getHarpData(soundId); + if (dSndPlayerMgr_c::isSoundPlayedByBgmBattlePlayer(soundId)) { + mBgmFlags |= BGM_FLAG_BATTLE; + } + dSndBgmMgr_c::GetInstance()->addToBgmSoundList(dSndBgmMgr_c::BGM_LIST_PREPARING, this); +} + +void dSndBgmSound_c::stop(s32 fadeFrames) { + if (isRunning()) { + if (mpStopCallback != nullptr) { + (mpStopCallback)(true); + mpStopCallback = nullptr; + } + Stop(fadeFrames); + if (fadeFrames != 0) { + mIsFadingOut = true; + dSndBgmMgr_c::GetInstance()->addToBgmSoundList(dSndBgmMgr_c::BGM_LIST_STOPPING, this); + } else { + cancel(); + } + } else if (!isPreparing()) { + cancel(); + } +} + +void dSndBgmSound_c::pause(bool pauseFlag, s32 fadeFrames) { + if (isFadingOut()) { + return; + } + + if (isPlaying()) { + if (pauseFlag == false) { + if (mIndex != 4 && dSndBgmMgr_c::GetInstance()->weirdCheckAlwaysFalse()) { + setVolume(0.0f, 10); + } + mBgmFlags &= ~BGM_FLAG_PAUSED; + } + dSndSound_c::pause(pauseFlag, fadeFrames); + } +} + +void dSndBgmSound_c::pause(s32 fadeFrames) { + pause(true, fadeFrames); + mBgmFlags |= BGM_FLAG_PAUSED; +} + +u32 dSndBgmSound_c::getPlaySamplePosition() { + if (isRunning()) { + u32 soundId = GetId(); + if (dSndMgr_c::GetInstance()->getArchive()->GetSoundType(soundId) == nw4r::snd::SoundArchive::SOUND_TYPE_SEQ) { + return getSeqSoundPlaySamplePosition(); + } + + if (dSndMgr_c::GetInstance()->getArchive()->GetSoundType(soundId) == nw4r::snd::SoundArchive::SOUND_TYPE_STRM) { + nw4r::snd::StrmSoundHandle handle(this); + return handle.GetPlaySamplePosition(); + } + + if (dSndMgr_c::GetInstance()->getArchive()->GetSoundType(soundId) == nw4r::snd::SoundArchive::SOUND_TYPE_WAVE) { + nw4r::snd::WaveSoundHandle handle(this); + return handle.GetPlaySamplePosition(); + } + } + + return -1; +} + +u32 dSndBgmSound_c::getStrmPlaySamplePosition() { + if (isRunning()) { + u32 soundId = GetId(); + if (dSndMgr_c::GetInstance()->getArchive()->GetSoundType(soundId) == nw4r::snd::SoundArchive::SOUND_TYPE_STRM) { + nw4r::snd::StrmSoundHandle handle(this); + return handle.GetPlaySamplePosition(); + } + } + + return -1; +} + +u32 dSndBgmSound_c::getWavePlaySamplePosition() { + if (isRunning()) { + u32 soundId = GetId(); + if (dSndMgr_c::GetInstance()->getArchive()->GetSoundType(soundId) == nw4r::snd::SoundArchive::SOUND_TYPE_WAVE) { + nw4r::snd::WaveSoundHandle handle(this); + return handle.GetPlaySamplePosition(); + } + } + + return -1; +} + +u32 dSndBgmSound_c::getSeqSoundPlaySamplePosition() { + if (isRunning()) { + calcSeqPlaySamplePosition(); + return mSeqPlaySamplePosition; + } else { + return -1; + } +} + +void dSndBgmSound_c::calcSeqPlaySamplePosition() { + if (!isSeqSound()) { + return; + } + + nw4r::snd::SeqSoundHandle handle(this); + s32 tick = handle.GetTick(); + field_0x114 = readSeqTrackVariable(3); + if (field_0x114 >= 0) { + mSeqPlaySamplePosition = tick % field_0x118; + if (mSeqPlaySamplePosition == 0) { + field_0x114++; + if (mpSeqConfig != nullptr && field_0x114 > mpSeqConfig->field_0x0E) { + field_0x114 = mpSeqConfig->field_0x0C; + } + } + mSeqPlaySamplePosition += field_0x118 * field_0x114; + } else if (mpSeqConfig != nullptr) { + if (tick < (mpSeqConfig->field_0x0E + 1) * field_0x118) { + mSeqPlaySamplePosition = tick; + return; + } + s32 offset = mpSeqConfig->field_0x0C * field_0x118; + + tick -= offset; + tick = tick % (field_0x118 * (mpSeqConfig->field_0x0E - mpSeqConfig->field_0x0C)); + mSeqPlaySamplePosition = tick + offset; + } else { + mSeqPlaySamplePosition = tick; + } +} + +void dSndBgmSound_c::applyVars() { + if (isRunning()) { + mpHarpMgr->setPlaySamplePosition(getPlaySamplePosition()); + } +} + +void dSndBgmSound_c::onBecomeActive() { + if (mpHarpMgr != nullptr) { + mpHarpMgr->resetPrevIdx(); + } + mHarpMgr.resetPrevIdx(); + spGlobalHarpMgr->resetPrevIdx(); +} + +const dSndBgmDataHarpVarSetBase_c *dSndBgmSound_c::getCurrentHarpVarSet() { + if (isRunning()) { + return mpHarpMgr->getCurrentVarSet(); + } + return nullptr; +} + +void dSndBgmSound_c::getHarpData(u32 soundId) { + if (soundId == -1) { + return; + } + + dSndBgmSoundHarpMgr_c *mgr = dSndBgmBattleDataMgr_c::GetInstance()->getHarpMgrForSoundId(soundId); + if (mgr != nullptr) { + mpHarpMgr = mgr; + } else { + loadNewHarpData(soundId); + } +} + +bool dSndBgmSound_c::loadNewHarpData(u32 soundId) { + if (soundId == -1) { + return false; + } + + if (!IsAttachedSound()) { + return false; + } + + bool ok = false; + if (!mHarpMgr.isLoaded()) { + dSndBgmMmlParserHarp_c parser(&mHarpMgr); + // result unused + (void)dSndBgmMgr_c::isSoundPlayedByBgmBattlePlayer(soundId); + if ((ok = parser.parseData(soundId, (1 << 15) | (1 << 0)))) { + mHarpMgr.setLoaded(); + } + } + + if (soundId == BGM_D301_INSIDE) { + spGlobalHarpMgr->reset(); + if (!spGlobalHarpMgr->isLoaded()) { + dSndBgmMmlParserHarp_c parser(spGlobalHarpMgr); + if ((ok = parser.parseData("BGM_D301_INSIDE_B", soundId, (1 << 15) | (1 << 0)))) { + spGlobalHarpMgr->setLoaded(); + } + } + } else if (soundId == BGM_D003_3) { + spGlobalHarpMgr->reset(); + if (!spGlobalHarpMgr->isLoaded()) { + dSndBgmMmlParserHarp_c parser(spGlobalHarpMgr); + if ((ok = parser.parseData("BGM_D003_3_B", soundId, (1 << 15) | (1 << 0)))) { + spGlobalHarpMgr->setLoaded(); + } + } + } else { + if (soundId == BGM_D101) { + spGlobalHarpMgr->reset(); + if (!spGlobalHarpMgr->isLoaded()) { + dSndBgmMmlParserHarp_c parser(spGlobalHarpMgr); + if ((ok = parser.parseData("BGM_D101_hell", soundId, (1 << 15) | (1 << 0)))) { + spGlobalHarpMgr->setLoaded(); + } + } + } + } + return ok; +} diff --git a/src/d/snd/d_snd_bgm_sound_harp_mgr.cpp b/src/d/snd/d_snd_bgm_sound_harp_mgr.cpp index 24bc879d..e54a999c 100644 --- a/src/d/snd/d_snd_bgm_sound_harp_mgr.cpp +++ b/src/d/snd/d_snd_bgm_sound_harp_mgr.cpp @@ -3,7 +3,7 @@ #include "common.h" dSndBgmSoundHarpMgr_c::dSndBgmSoundHarpMgr_c() - : mpCurrVarSet(nullptr), mSoundId(-1), field_0x14(-1), mPrevIdx(-1), mIsLoaded(false) { + : mpCurrVarSet(nullptr), mSoundId(-1), mTempo(-1), mPrevIdx(-1), mIsLoaded(false) { reset(); } @@ -17,9 +17,9 @@ void dSndBgmSoundHarpMgr_c::setLoaded() { void dSndBgmSoundHarpMgr_c::reset() { mSoundId = -1; - field_0x14 = -1; + mTempo = -1; mPrevIdx = -1; - resetVars(); + mHarpData.resetVars(); mpCurrVarSet = 0; mIsLoaded = false; } @@ -28,10 +28,10 @@ void dSndBgmSoundHarpMgr_c::setPlaySamplePosition(s32 position) { if (position < 0) { return; } - s32 idx = getIdxForPosition(position); + s32 idx = mHarpData.getIdxForPosition(position); if (idx != mPrevIdx && idx >= 0) { - writeSeqVars(idx); - mpCurrVarSet = getUsableVarSet(idx); + mHarpData.writeSeqVars(idx); + mpCurrVarSet = mHarpData.getUsableVarSet(idx); mPrevIdx = idx; } } diff --git a/src/d/snd/d_snd_sound.cpp b/src/d/snd/d_snd_sound.cpp index 11d1dc63..7e51e683 100644 --- a/src/d/snd/d_snd_sound.cpp +++ b/src/d/snd/d_snd_sound.cpp @@ -160,7 +160,7 @@ void dSndSound_c::unlinkCtrl(dSndControlSound_c *ctrl) { nw4r::ut::List_Remove(&mList, ctrl); } -s16 dSndSound_c::readSeqTrackVariable(int varNo) { +s32 dSndSound_c::readSeqTrackVariable(int varNo) { if (!isSeqSound()) { return -1; } @@ -224,7 +224,7 @@ void dSndSound_c::resetTrackVolumes() { } } -void dSndSound_c::setTrackVolume(u32 trackFlags, f32 volume, s32 frames) { +void dSndSound_c::setTrackVolume(u16 trackFlags, f32 volume, s32 frames) { if (trackFlags != 0 && IsAttachedSound()) { switch (dSndMgr_c::GetInstance()->getArchive()->GetSoundType(GetId())) { case nw4r::snd::SoundArchive::SOUND_TYPE_SEQ: { @@ -247,7 +247,7 @@ void dSndSound_c::setTrackVolume(u32 trackFlags, f32 volume, s32 frames) { } } -void dSndSound_c::setStrmTrackVolume(u32 trackFlags, f32 volume, s32 frames) { +void dSndSound_c::setStrmTrackVolume(u16 trackFlags, f32 volume, s32 frames) { if (trackFlags != 0 && IsAttachedSound()) { switch (dSndMgr_c::GetInstance()->getArchive()->GetSoundType(GetId())) { case nw4r::snd::SoundArchive::SOUND_TYPE_STRM: { @@ -284,7 +284,7 @@ void dSndSound_c::setSingleStrmTrackVolume(u16 index, f32 volume, s32 frames) { } } -void dSndSound_c::setEachSeqTrackVolume(u32 trackFlags, f32 frames) { +void dSndSound_c::setEachSeqTrackVolume(u16 trackFlags, f32 frames) { for (int i = 0; i < 16; i++) { if ((trackFlags & (u16)(1 << i)) != 0) { setSingleSeqTrackVolume(i, 1.0f, (u32)frames); @@ -294,7 +294,7 @@ void dSndSound_c::setEachSeqTrackVolume(u32 trackFlags, f32 frames) { } } -void dSndSound_c::setEachStrmTrackVolume(u32 trackFlags, f32 frames) { +void dSndSound_c::setEachStrmTrackVolume(u16 trackFlags, f32 frames) { for (int i = 0; i < 3; i++) { if ((trackFlags & (u16)(1 << i)) != 0) { setSingleStrmTrackVolume(i, 1.0f, (u32)frames); @@ -317,7 +317,7 @@ void dSndSound_c::setSeqTempoRatio(f32 ratio, s32 frames) { } } -void dSndSound_c::setSeqTrackMute(u32 trackFlags, nw4r::snd::SeqMute mute) { +void dSndSound_c::setSeqTrackMute(u16 trackFlags, nw4r::snd::SeqMute mute) { if (isSeqSound()) { nw4r::snd::SeqSoundHandle handle(this); handle.SetTrackMute(trackFlags, mute); diff --git a/src/d/snd/d_snd_source_mgr.cpp b/src/d/snd/d_snd_source_mgr.cpp index 65a42c43..6b214a7b 100644 --- a/src/d/snd/d_snd_source_mgr.cpp +++ b/src/d/snd/d_snd_source_mgr.cpp @@ -393,15 +393,15 @@ dSndSourceMgr_c::dSndSourceMgr_c() } void dSndSourceMgr_c::calcEnemyObjVolume() { - if (dSndStateMgr_c::GetInstance()->checkFlag0x94(dSndStateMgr_c::EVENT_MUTE_ENEMY_FULL)) { + if (dSndStateMgr_c::GetInstance()->checkEventFlag(dSndStateMgr_c::EVENT_MUTE_ENEMY_FULL)) { dSndControlPlayerMgr_c::GetInstance()->setEnemyMuteVolume(0.0f); - } else if (dSndStateMgr_c::GetInstance()->checkFlag0x94(dSndStateMgr_c::EVENT_MUTE_ENEMY_PARTIAL)) { + } else if (dSndStateMgr_c::GetInstance()->checkEventFlag(dSndStateMgr_c::EVENT_MUTE_ENEMY_PARTIAL)) { dSndControlPlayerMgr_c::GetInstance()->setEnemyMuteVolume(0.3f); } - if (dSndStateMgr_c::GetInstance()->checkFlag0x94(dSndStateMgr_c::EVENT_MUTE_OBJ_FULL)) { + if (dSndStateMgr_c::GetInstance()->checkEventFlag(dSndStateMgr_c::EVENT_MUTE_OBJ_FULL)) { dSndControlPlayerMgr_c::GetInstance()->setObjectMuteVolume(0.0f); - } else if (dSndStateMgr_c::GetInstance()->checkFlag0x94(dSndStateMgr_c::EVENT_MUTE_OBJ_PARTIAL)) { + } else if (dSndStateMgr_c::GetInstance()->checkEventFlag(dSndStateMgr_c::EVENT_MUTE_OBJ_PARTIAL)) { dSndControlPlayerMgr_c::GetInstance()->setObjectMuteVolume(0.3f); } } diff --git a/src/d/snd/d_snd_state_mgr.cpp b/src/d/snd/d_snd_state_mgr.cpp index 4d1f1711..c62499b8 100644 --- a/src/d/snd/d_snd_state_mgr.cpp +++ b/src/d/snd/d_snd_state_mgr.cpp @@ -210,7 +210,7 @@ void dSndStateMgr_c::initializeEventCallbacks(const char *name) { sEventExecuteCallback = nullptr; resetOverrides(); - if (checkFlag0x94(0x2)) { + if (checkEventFlag(EVENT_0x2)) { handleDemoEvent(name); return; }