From bf79fa17fbc106fd06c545732ad875275821376e Mon Sep 17 00:00:00 2001 From: robojumper Date: Wed, 16 Oct 2024 03:44:09 +0200 Subject: [PATCH] Untangle eggAudio a bit (#61) * Untangle eggAudio a bit * eggAudioRmtSpeakerMgr with a regswap * Fix eggAudioRmtSpeakerMgr (thanks Cuyler!) * eggAudioUtility with two regswaps --- config/SOUE01/splits.txt | 10 + config/SOUE01/symbols.txt | 110 ++++---- configure.py | 8 +- include/egg/audio/eggAudioArcPlayerMgr.h | 125 +++++++++- include/egg/audio/eggAudioHeapMgr.h | 37 ++- include/egg/audio/eggAudioMgr.h | 58 ++++- include/egg/audio/eggAudioRmtSpeakerMgr.h | 45 +++- include/egg/audio/eggAudioSystem.h | 36 ++- include/egg/audio/eggAudioUtility.h | 48 +++- include/nw4r/snd/snd_RemoteSpeaker.h | 4 +- include/nw4r/snd/snd_SoundArchivePlayer.h | 16 +- include/nw4r/snd/snd_SoundStartable.h | 3 +- src/egg/audio/eggAudioArcPlayerMgr.cpp | 291 +++++++++++++++++++++- src/egg/audio/eggAudioHeapMgr.cpp | 17 +- src/egg/audio/eggAudioMgr.cpp | 95 ++++++- src/egg/audio/eggAudioRmtSpeakerMgr.cpp | 145 ++++++++++- src/egg/audio/eggAudioSystem.cpp | 52 +++- src/egg/audio/eggAudioUtility.cpp | 92 ++++++- 18 files changed, 1108 insertions(+), 84 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 9356f760..b49b218d 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -1752,22 +1752,32 @@ egg/gfx/eggTextureBuffer.cpp: egg/audio/eggAudioArcPlayerMgr.cpp: .text start:0x804B59E0 end:0x804B6428 + .data start:0x8056F2C0 end:0x8056F320 egg/audio/eggAudioHeapMgr.cpp: .text start:0x804B6430 end:0x804B64A8 egg/audio/eggAudioMgr.cpp: .text start:0x804B64B0 end:0x804B69C8 + .data start:0x8056F320 end:0x8056F420 egg/audio/eggAudioRmtSpeakerMgr.cpp: .text start:0x804B69D0 end:0x804B6F58 + .sdata start:0x80574F68 end:0x80574F6C + .sbss start:0x805768D8 end:0x805768E8 + .bss start:0x80675390 end:0x80675480 egg/audio/eggAudioUtility.cpp: .text start:0x804B6F60 end:0x804B720C .ctors start:0x804DB9B0 end:0x804DB9B4 + .sdata start:0x80574F70 end:0x80574F78 + .sbss start:0x805768E8 end:0x805768F8 + .bss start:0x80675480 end:0x80675490 egg/audio/eggAudioSystem.cpp: .text start:0x804B7210 end:0x804B7544 + .sbss start:0x805768F8 end:0x80576900 + .sdata2 start:0x8057F8B0 end:0x8057F8C8 egg/util/eggException.cpp: .text start:0x804B7550 end:0x804B7B48 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index f9d8f363..00b6a589 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -19810,29 +19810,29 @@ SndAudioMgr__initialize = .text:0x80359DC0; // type:function size:0xEC fn_80359EB0 = .text:0x80359EB0; // type:function size:0x10 SndAudioMgr__calc = .text:0x80359EC0; // type:function size:0xB8 fn_80359F80 = .text:0x80359F80; // type:function size:0x2C -fn_80359FB0 = .text:0x80359FB0; // type:function size:0xD4 -fn_8035A090 = .text:0x8035A090; // type:function size:0x8C -fn_8035A120 = .text:0x8035A120; // type:function size:0x54 -SndAudioMgr__holdSound = .text:0x8035A180; // type:function size:0x34 -SndAudioMgr__holdSound2 = .text:0x8035A1C0; // type:function size:0x34 -SndAudioMgr__holdSound3 = .text:0x8035A200; // type:function size:0x70 -fn_8035A270 = .text:0x8035A270; // type:function size:0x34 -fn_8035A2B0 = .text:0x8035A2B0; // type:function size:0x34 -fn_8035A2F0 = .text:0x8035A2F0; // type:function size:0x70 -fn_8035A360 = .text:0x8035A360; // type:function size:0x34 -fn_8035A3A0 = .text:0x8035A3A0; // type:function size:0x34 -fn_8035A3E0 = .text:0x8035A3E0; // type:function size:0x70 -fn_8035A450 = .text:0x8035A450; // type:function size:0x10 +stateProc__Q23EGG12SoundHeapMgrFv = .text:0x80359FB0; // type:function size:0xD4 +loadState__Q23EGG12SoundHeapMgrFl = .text:0x8035A090; // type:function size:0x8C +getCurrentLevel__Q23EGG12SoundHeapMgrFv = .text:0x8035A120; // type:function size:0x54 +holdSound__Q23EGG9ArcPlayerFPQ34nw4r3snd11SoundHandleUl = .text:0x8035A180; // type:function size:0x34 +holdSound__Q23EGG9ArcPlayerFPQ34nw4r3snd11SoundHandleUi = .text:0x8035A1C0; // type:function size:0x34 +holdSound__Q23EGG9ArcPlayerFPQ34nw4r3snd11SoundHandlePCc = .text:0x8035A200; // type:function size:0x70 +prepareSound__Q23EGG9ArcPlayerFPQ34nw4r3snd11SoundHandleUl = .text:0x8035A270; // type:function size:0x34 +prepareSound__Q23EGG9ArcPlayerFPQ34nw4r3snd11SoundHandleUi = .text:0x8035A2B0; // type:function size:0x34 +prepareSound__Q23EGG9ArcPlayerFPQ34nw4r3snd11SoundHandlePCc = .text:0x8035A2F0; // type:function size:0x70 +startSound__Q23EGG9ArcPlayerFPQ34nw4r3snd11SoundHandleUl = .text:0x8035A360; // type:function size:0x34 +startSound__Q23EGG9ArcPlayerFPQ34nw4r3snd11SoundHandleUi = .text:0x8035A3A0; // type:function size:0x34 +startSound__Q23EGG9ArcPlayerFPQ34nw4r3snd11SoundHandlePCc = .text:0x8035A3E0; // type:function size:0x70 +setupMemoryArchive__Q23EGG9ArcPlayerFPCvPQ34nw4r3snd9SoundHeapl = .text:0x8035A450; // type:function size:0x10 fn_8035A460 = .text:0x8035A460; // type:function size:0x58 fn_8035A4C0 = .text:0x8035A4C0; // type:function size:0x8 -fn_8035A4D0 = .text:0x8035A4D0; // type:function size:0x8 -fn_8035A4E0 = .text:0x8035A4E0; // type:function size:0x8 -fn_8035A4F0 = .text:0x8035A4F0; // type:function size:0x8 -fn_8035A500 = .text:0x8035A500; // type:function size:0x8 -fn_8035A510 = .text:0x8035A510; // type:function size:0x8 -fn_8035A520 = .text:0x8035A520; // type:function size:0x8 -fn_8035A530 = .text:0x8035A530; // type:function size:0x8 -fn_8035A540 = .text:0x8035A540; // type:function size:0x8 +@248@loadGroup__Q23EGG14SimpleAudioMgrFUiPQ34nw4r3snd9SoundHeapUl = .text:0x8035A4D0; // type:function size:0x8 +@248@loadGroup__Q23EGG14SimpleAudioMgrFiPQ34nw4r3snd9SoundHeapUl = .text:0x8035A4E0; // type:function size:0x8 +@248@loadGroup__Q23EGG14SimpleAudioMgrFUlPQ34nw4r3snd9SoundHeapUl = .text:0x8035A4F0; // type:function size:0x8 +@248@loadGroup__Q23EGG14SimpleAudioMgrFPCcPQ34nw4r3snd9SoundHeapUl = .text:0x8035A500; // type:function size:0x8 +@248@closeArchive__Q23EGG14SimpleAudioMgrFv = .text:0x8035A510; // type:function size:0x8 +@248@setupMemoryArchive__Q23EGG14SimpleAudioMgrFPCvPQ34nw4r3snd9SoundHeap = .text:0x8035A520; // type:function size:0x8 +@248@openNandArchive__Q23EGG14SimpleAudioMgrFPCcPQ34nw4r3snd9SoundHeap = .text:0x8035A530; // type:function size:0x8 +@248@openDvdArchive__Q23EGG14SimpleAudioMgrFPCcPQ34nw4r3snd9SoundHeap = .text:0x8035A540; // type:function size:0x8 fn_8035A550 = .text:0x8035A550; // type:function size:0x8 fn_8035A560 = .text:0x8035A560; // type:function size:0x3C fn_8035A5A0 = .text:0x8035A5A0; // type:function size:0x54 @@ -26815,8 +26815,8 @@ loadGroup__Q23EGG9ArcPlayerFPCcPQ34nw4r3snd9SoundHeapUl = .text:0x804B62D0; // t calc__Q23EGG9ArcPlayerFv = .text:0x804B63A0; // type:function size:0x18 stopAllSound__Q23EGG9ArcPlayerFv = .text:0x804B63C0; // type:function size:0x5C @248@calc__Q23EGG14SimpleAudioMgrFv = .text:0x804B6420; // type:function size:0x8 -fn_804B6430 = .text:0x804B6430; // type:function size:0x70 -fn_804B64A0 = .text:0x804B64A0; // type:function size:0x8 +createSoundHeap__Q23EGG12SoundHeapMgrFPQ23EGG9AllocatorUl = .text:0x804B6430; // type:function size:0x70 +destroySoundHeap__Q23EGG12SoundHeapMgrFv = .text:0x804B64A0; // type:function size:0x8 __ct__Q33EGG9IAudioMgr3ArgFv = .text:0x804B64B0; // type:function size:0x30 __ct__Q33EGG14SimpleAudioMgr17SimpleAudioMgrArgFv = .text:0x804B64E0; // type:function size:0x44 __ct__Q23EGG14SimpleAudioMgrFv = .text:0x804B6530; // type:function size:0xE0 @@ -26833,35 +26833,35 @@ loadGroup__Q23EGG14SimpleAudioMgrFiPQ34nw4r3snd9SoundHeapUl = .text:0x804B6920; loadGroup__Q23EGG14SimpleAudioMgrFUlPQ34nw4r3snd9SoundHeapUl = .text:0x804B6930; // type:function size:0x8 loadGroup__Q23EGG14SimpleAudioMgrFPCcPQ34nw4r3snd9SoundHeapUl = .text:0x804B6940; // type:function size:0x8 initialize__Q23EGG9IAudioMgrFPQ33EGG9IAudioMgr3Arg = .text:0x804B6950; // type:function size:0x4 -EGG__SoundArchivePlayerEGG__detail_SetupSound = .text:0x804B6960; // type:function size:0x34 +detail_SetupSound__Q23EGG21SoundArchivePlayerEGGFPQ34nw4r3snd11SoundHandleUlbPCQ44nw4r3snd14SoundStartable9StartInfo = .text:0x804B6960; // type:function size:0x34 @12@detail_SetupSound__Q23EGG21SoundArchivePlayerEGGFPQ34nw4r3snd11SoundHandleUlbPCQ44nw4r3snd14SoundStartable9StartInfo = .text:0x804B69A0; // type:function size:0x8 @12@__dt__Q23EGG21SoundArchivePlayerEGGFv = .text:0x804B69B0; // type:function size:0x8 @248@__dt__Q23EGG14SimpleAudioMgrFv = .text:0x804B69C0; // type:function size:0x8 setupCallback__Q23EGG18AudioRmtSpeakerMgrFll = .text:0x804B69D0; // type:function size:0x90 shutdownCallback__Q23EGG18AudioRmtSpeakerMgrFll = .text:0x804B6A60; // type:function size:0x8C -fn_804B6AF0 = .text:0x804B6AF0; // type:function size:0x84 -fn_804B6B80 = .text:0x804B6B80; // type:function size:0x7C -fn_804B6C00 = .text:0x804B6C00; // type:function size:0x48 +fn_804B6AF0__Q23EGG18AudioRmtSpeakerMgrFlPFll_vb = .text:0x804B6AF0; // type:function size:0x84 +fn_804B6B80__Q23EGG18AudioRmtSpeakerMgrFlPFll_v = .text:0x804B6B80; // type:function size:0x7C +fn_804B6C00__Q23EGG18AudioRmtSpeakerMgrFlPFll_v = .text:0x804B6C00; // type:function size:0x48 calc__Q23EGG18AudioRmtSpeakerMgrFv = .text:0x804B6C50; // type:function size:0xC4 setupCallbackDirect__Q23EGG18AudioRmtSpeakerMgrFll = .text:0x804B6D20; // type:function size:0x3C shutdownCallbackDirect__Q23EGG18AudioRmtSpeakerMgrFll = .text:0x804B6D60; // type:function size:0x20 -fn_804B6D80 = .text:0x804B6D80; // type:function size:0x60 -fn_804B6DE0 = .text:0x804B6DE0; // type:function size:0x78 +fn_804B6D80__Q23EGG18AudioRmtSpeakerMgrFlPFll_v = .text:0x804B6D80; // type:function size:0x60 +fn_804B6DE0__Q23EGG18AudioRmtSpeakerMgrFlPFll_v = .text:0x804B6DE0; // type:function size:0x78 connectAllByForce__Q23EGG18AudioRmtSpeakerMgrFv = .text:0x804B6E60; // type:function size:0x68 disconnectAllByForce__Q23EGG18AudioRmtSpeakerMgrFv = .text:0x804B6ED0; // type:function size:0x78 getWpadVolume__Q23EGG18AudioRmtSpeakerMgrFv = .text:0x804B6F50; // type:function size:0x8 __ct__Q33EGG12AudioUtility12MoveParamMgrFv = .text:0x804B6F60; // type:function size:0x30 init__Q33EGG12AudioUtility12MoveParamMgrFv = .text:0x804B6F90; // type:function size:0x10 -init__EGG__AudioUtility_HBM = .text:0x804B6FA0; // type:function size:0x10 +init__Q33EGG12AudioUtility3HBMFPQ23EGG14SimpleAudioMgrPFv_vUl = .text:0x804B6FA0; // type:function size:0x10 enter__Q33EGG12AudioUtility3HBMFv = .text:0x804B6FB0; // type:function size:0x130 exit__Q33EGG12AudioUtility3HBMFb = .text:0x804B70E0; // type:function size:0x120 -__sinit_eggAudioUtility_cpp = .text:0x804B7200; // type:function size:0xC -fn_804B7210 = .text:0x804B7210; // type:function size:0x1C -fn_804B7230 = .text:0x804B7230; // type:function size:0x40 -fn_804B7270 = .text:0x804B7270; // type:function size:0xF8 -fn_804B7370 = .text:0x804B7370; // type:function size:0x60 -fn_804B73D0 = .text:0x804B73D0; // type:function size:0x78 -fn_804B7450 = .text:0x804B7450; // type:function size:0xF4 +__sinit_\eggAudioUtility_cpp = .text:0x804B7200; // type:function size:0xC scope:local +__ct__Q23EGG11AudioSystemFv = .text:0x804B7210; // type:function size:0x1C +__dt__Q23EGG11AudioSystemFv = .text:0x804B7230; // type:function size:0x40 +fn_804B7270__Q23EGG11AudioSystemFl = .text:0x804B7270; // type:function size:0xF8 +fn_804B7370__Q23EGG11AudioSystemFv = .text:0x804B7370; // type:function size:0x60 +fn_804B73D0__Q23EGG11AudioSystemFl = .text:0x804B73D0; // type:function size:0x78 +calc__Q23EGG11AudioSystemFv = .text:0x804B7450; // type:function size:0xF4 ExceptionWaitTime__Q23EGG9ExceptionFUl = .text:0x804B7550; // type:function size:0x78 ExceptionCallback__Q23EGG9ExceptionFPQ44nw4r2db6detail11ConsoleHeadPv = .text:0x804B75D0; // type:function size:0x58 ExceptionCallback___Q23EGG9ExceptionFPQ44nw4r2db6detail11ConsoleHeadPv = .text:0x804B7630; // type:function size:0x214 @@ -37249,11 +37249,11 @@ EGG__Screen__vtable = .data:0x8056F254; // type:object size:0x14 lbl_8056F268 = .data:0x8056F268; // type:object size:0x10 lbl_8056F278 = .data:0x8056F278; // type:object size:0x38 lbl_8056F2B0 = .data:0x8056F2B0; // type:object size:0x10 -lbl_8056F2C0 = .data:0x8056F2C0; // type:object size:0x60 -lbl_8056F320 = .data:0x8056F320; // type:object size:0xA8 -lbl_8056F3C8 = .data:0x8056F3C8; // type:object size:0x10 -lbl_8056F3D8 = .data:0x8056F3D8; // type:object size:0x30 -lbl_8056F408 = .data:0x8056F408; // type:object size:0x18 +__vt__Q23EGG9ArcPlayer = .data:0x8056F2C0; // type:object size:0x5C +__vt__Q23EGG14SimpleAudioMgr = .data:0x8056F320; // type:object size:0xA4 +__vt__Q23EGG9IAudioMgr = .data:0x8056F3C8; // type:object size:0x10 +__vt__Q23EGG21SoundArchivePlayerEGG = .data:0x8056F3D8; // type:object size:0x30 +__vt__Q23EGG12SoundHeapMgr = .data:0x8056F408; // type:object size:0x14 lbl_8056F420 = .data:0x8056F420; // type:object size:0xC scope:local data:string __vt__Q23EGG9Exception = .data:0x8056F42C; // type:object size:0xC lbl_8056F438 = .data:0x8056F438; // type:object size:0x14 @@ -39699,8 +39699,8 @@ lbl_80574F50 = .sdata:0x80574F50; // type:object size:0x8 data:string lbl_80574F58 = .sdata:0x80574F58; // type:object size:0x8 data:4byte lbl_80574F60 = .sdata:0x80574F60; // type:object size:0x4 data:4byte lbl_80574F64 = .sdata:0x80574F64; // type:object size:0x4 data:4byte -lbl_80574F68 = .sdata:0x80574F68; // type:object size:0x8 data:byte -lbl_80574F70 = .sdata:0x80574F70; // type:object size:0x8 data:4byte +sAudioRmtSpeakerWpadVolume__Q23EGG18AudioRmtSpeakerMgr = .sdata:0x80574F68; // type:object size:0x1 data:byte +sHBFadeframe__Q33EGG12AudioUtility3HBM = .sdata:0x80574F70; // type:object size:0x4 data:4byte fragmentID = .sdata:0x80574F78; // type:object size:0x4 scope:local data:4byte @wstringBase0 = .sdata:0x80574F80; // type:object size:0x2 scope:local lbl_80574F88 = .sdata:0x80574F88; // type:object size:0x4 data:float @@ -41056,15 +41056,15 @@ lbl_805768C4 = .sbss:0x805768C4; // type:object size:0x4 data:4byte lbl_805768C8 = .sbss:0x805768C8; // type:object size:0x4 data:4byte lbl_805768CC = .sbss:0x805768CC; // type:object size:0x4 data:4byte lbl_805768D0 = .sbss:0x805768D0; // type:object size:0x8 data:byte -lbl_805768D8 = .sbss:0x805768D8; // type:object size:0x1 data:byte -lbl_805768DC = .sbss:0x805768DC; // type:object size:0x4 data:4byte -lbl_805768E0 = .sbss:0x805768E0; // type:object size:0x4 data:4byte -lbl_805768E4 = .sbss:0x805768E4; // type:object size:0x1 data:byte -lbl_805768E8 = .sbss:0x805768E8; // type:object size:0x4 data:4byte -AudioHeap_ptr = .sbss:0x805768EC; // type:object size:0x4 data:4byte -lbl_805768F0 = .sbss:0x805768F0; // type:object size:0x4 data:4byte -lbl_805768F4 = .sbss:0x805768F4; // type:object size:0x4 data:4byte -lbl_805768F8 = .sbss:0x805768F8; // type:object size:0x8 data:4byte +sAudioRmtSpeakerConnectCanncelSw__Q23EGG18AudioRmtSpeakerMgr = .sbss:0x805768D8; // type:object size:0x1 data:byte +mTaskFinishCount__Q23EGG18AudioRmtSpeakerMgr = .sbss:0x805768DC; // type:object size:0x4 data:4byte +mTaskRequestCount__Q23EGG18AudioRmtSpeakerMgr = .sbss:0x805768E0; // type:object size:0x4 data:4byte +sTask__Q23EGG18AudioRmtSpeakerMgr = .sbss:0x805768E4; // type:object size:0x1 data:byte +sMultiArcSimpleAudioMgr__Q33EGG12AudioUtility3HBM = .sbss:0x805768E8; // type:object size:0x4 data:4byte +sSimpleAudioMgr__Q33EGG12AudioUtility3HBM = .sbss:0x805768EC; // type:object size:0x4 data:4byte +sHBMEffectRestCallback__Q33EGG12AudioUtility3HBM = .sbss:0x805768F0; // type:object size:0x4 data:4byte +sHBMUserCallback__Q33EGG12AudioUtility3HBM = .sbss:0x805768F4; // type:object size:0x4 data:4byte +sInstanse__Q23EGG11AudioSystem = .sbss:0x805768F8; // type:object size:0x4 data:4byte sException__Q23EGG9Exception = .sbss:0x80576900; // type:object size:0x4 data:4byte sConsoleHandle__Q23EGG9Exception = .sbss:0x80576904; // type:object size:0x4 data:4byte sMapFileWorks__Q23EGG9Exception = .sbss:0x80576908; // type:object size:0x4 data:4byte @@ -49474,8 +49474,8 @@ lbl_806750C0 = .bss:0x806750C0; // type:object size:0xA8 data:4byte lbl_80675168 = .bss:0x80675168; // type:object size:0x18 lbl_80675180 = .bss:0x80675180; // type:object size:0x10 lbl_80675190 = .bss:0x80675190; // type:object size:0x200 data:4byte -lbl_80675390 = .bss:0x80675390; // type:object size:0xF0 -lbl_80675480 = .bss:0x80675480; // type:object size:0x10 +sTasks__Q23EGG18AudioRmtSpeakerMgr = .bss:0x80675390; // type:object size:0xF0 +sMoveParamMgr__Q23EGG12AudioUtility = .bss:0x80675480; // type:object size:0xC lbl_80675490 = .bss:0x80675490; // type:object size:0x10 lbl_806754A0 = .bss:0x806754A0; // type:object size:0x20 data:4byte lbl_806754C0 = .bss:0x806754C0; // type:object size:0x20 data:4byte diff --git a/configure.py b/configure.py index a68b09f8..1639d685 100644 --- a/configure.py +++ b/configure.py @@ -781,11 +781,11 @@ config.libs = [ "audio", [ Object(NonMatching, "egg/audio/eggAudioArcPlayerMgr.cpp"), - Object(NonMatching, "egg/audio/eggAudioHeapMgr.cpp"), - Object(NonMatching, "egg/audio/eggAudioMgr.cpp"), - Object(NonMatching, "egg/audio/eggAudioRmtSpeakerMgr.cpp"), + Object(Matching, "egg/audio/eggAudioHeapMgr.cpp"), + Object(Matching, "egg/audio/eggAudioMgr.cpp"), + Object(Matching, "egg/audio/eggAudioRmtSpeakerMgr.cpp"), Object(NonMatching, "egg/audio/eggAudioUtility.cpp"), - Object(NonMatching, "egg/audio/eggAudioSystem.cpp"), + Object(Matching, "egg/audio/eggAudioSystem.cpp"), ], ), EGGLib( diff --git a/include/egg/audio/eggAudioArcPlayerMgr.h b/include/egg/audio/eggAudioArcPlayerMgr.h index a2ef8a7e..a68ea608 100644 --- a/include/egg/audio/eggAudioArcPlayerMgr.h +++ b/include/egg/audio/eggAudioArcPlayerMgr.h @@ -1,9 +1,132 @@ #ifndef EGG_AUDIO_ARC_PLAYER_MANAGER_H #define EGG_AUDIO_ARC_PLAYER_MANAGER_H +#include +#include +#include +#include +#include +#include + namespace EGG { -class ArcPlayer {}; +class ArcPlayer { +public: + enum SARC_STORAGE { + STORAGE_NONE, + STORAGE_DVD, + STORAGE_NAND, + STORAGE_CNT, + STORAGE_MEM + }; + + ArcPlayer(nw4r::snd::SoundArchivePlayer *, nw4r::snd::SoundHeap *); + virtual ~ArcPlayer(); // at 0x8 + bool setSteamBlocks(u32); + void stopAllSound(); + + u32 changeNameToId(const char *name) { + return mOpenSndArchive->ConvertLabelStringToSoundId(name); + } + nw4r::snd::SoundArchivePlayer *getPlayer() { + return mActiveSndArchivePlayer; + } + + void setLoadStringLabels(bool bLoad) { + mLoadLabelStringData = bLoad; + } + + virtual UNKTYPE *openArchive(const char *, nw4r::snd::SoundHeap *, SARC_STORAGE); // at 0xC + virtual UNKTYPE *openDvdArchive(const char *, nw4r::snd::SoundHeap *); // at 0x10 + virtual UNKTYPE *openNandArchive(const char *, nw4r::snd::SoundHeap *); // at 0x14 + virtual UNKTYPE *setupMemoryArchive(const void *, nw4r::snd::SoundHeap *); // at 0x18 + + virtual UNKTYPE *setupMemoryArchive(const void *p, nw4r::snd::SoundHeap *heap, s32) // at 0x1C + { + return setupMemoryArchive(p, heap); + } + + virtual void closeArchive(); // at 0x20 + virtual bool loadGroup(unsigned int, nw4r::snd::SoundHeap *, u32); // at 0x24 + virtual bool loadGroup(int, nw4r::snd::SoundHeap *, u32); // at 0x28 + virtual bool loadGroup(u32, nw4r::snd::SoundHeap *, u32); // at 0x2C + virtual bool loadGroup(const char *, nw4r::snd::SoundHeap *, u32); // at 0x30 + virtual void calc(); // at 0x34 + + virtual bool startSound(nw4r::snd::SoundHandle *handle, u32 id) // at 0x38 + { + return mActiveSndArchivePlayer->StartSound(handle, id); + } + + virtual bool startSound(nw4r::snd::SoundHandle *handle, unsigned int id) // at 0x3C + { + return ArcPlayer::startSound(handle, (u32)id); + } + + virtual bool startSound(nw4r::snd::SoundHandle *handle, const char *name) // at 0x40 + { + u32 id = -1; + if (mOpenSndArchive) { + id = changeNameToId(name); + } + + return ArcPlayer::startSound(handle, id); + } + + virtual bool prepareSound(nw4r::snd::SoundHandle *handle, u32 id) // at 0x44 + { + return mActiveSndArchivePlayer->PrepareSound(handle, id); + } + + virtual bool prepareSound(nw4r::snd::SoundHandle *handle, unsigned int id) // at 0x48 + { + return ArcPlayer::prepareSound(handle, (u32)id); + } + + virtual bool prepareSound(nw4r::snd::SoundHandle *handle, const char *name) // at 0x4C + { + u32 id = -1; + if (mOpenSndArchive) { + id = changeNameToId(name); + } + + return ArcPlayer::prepareSound(handle, id); + } + + virtual bool holdSound(nw4r::snd::SoundHandle *handle, u32 id) // at 0x50 + { + return mActiveSndArchivePlayer->HoldSound(handle, id); + } + + virtual bool holdSound(nw4r::snd::SoundHandle *handle, unsigned int id) // at 0x54 + { + return ArcPlayer::holdSound(handle, (u32)id); + } + + virtual bool holdSound(nw4r::snd::SoundHandle *handle, const char *name) // at 0x58 + { + u32 id = -1; + if (mOpenSndArchive) { + id = changeNameToId(name); + } + + return ArcPlayer::holdSound(handle, id); + } + +private: + /* 0x004 */ bool mIsOpeningArchive; + /* 0x005 */ bool mIsLoadingGroup; + /* 0x006 */ bool mLoadLabelStringData; + /* 0x008 */ nw4r::snd::SoundArchive *mOpenSndArchive; + /* 0x00C */ nw4r::snd::DvdSoundArchive mDvdSndArchive; + /* 0x198 */ nw4r::snd::NandSoundArchive mNandSndArchive; + /* 0x374 */ nw4r::snd::MemorySoundArchive mMemorySndArchive; + /* 0x4C4 */ nw4r::snd::SoundArchivePlayer *mActiveSndArchivePlayer; + /* 0x4C8 */ nw4r::snd::SoundHeap *mSoundHeap; + /* 0x4CC */ SARC_STORAGE mStorage; + /* 0x4D0 */ u32 mSteamBlocks; + /* 0x4D4 */ void *mpHeaderBuf; +}; } // namespace EGG diff --git a/include/egg/audio/eggAudioHeapMgr.h b/include/egg/audio/eggAudioHeapMgr.h index ac7296e2..577bdc5c 100644 --- a/include/egg/audio/eggAudioHeapMgr.h +++ b/include/egg/audio/eggAudioHeapMgr.h @@ -1,9 +1,44 @@ #ifndef EGG_AUDIO_HEAP_MANAGER_H #define EGG_AUDIO_HEAP_MANAGER_H +#include +#include + namespace EGG { -class SoundHeapMgr {}; +class SoundMessageQueue { +public: + SoundMessageQueue() { + OSInitMessageQueue(&mQueue, mBuffer, 4); + } + + OSMessageQueue mQueue; + OSMessage mBuffer[4]; +}; + +class SoundHeapMgr { +public: + ~SoundHeapMgr() { + destroySoundHeap(); + } + virtual bool loadState(s32 id) {} + virtual int getCurrentLevel() {} + virtual void stateProc() {} + + void createSoundHeap(Allocator *allocator, u32 size); + void destroySoundHeap(); + + nw4r::snd::SoundHeap *getSoundHeap() { + return &mSoundHeap; + } + +private: + nw4r::snd::SoundHeap mSoundHeap; + u8 unk[0x68 - 0x38]; + SoundMessageQueue mQueue1; + SoundMessageQueue mQueue2; + SoundMessageQueue mQueue3; +}; } // namespace EGG diff --git a/include/egg/audio/eggAudioMgr.h b/include/egg/audio/eggAudioMgr.h index 603c30bf..1c3ef4b3 100644 --- a/include/egg/audio/eggAudioMgr.h +++ b/include/egg/audio/eggAudioMgr.h @@ -3,25 +3,75 @@ #include "egg/audio/eggAudioArcPlayerMgr.h" #include "egg/audio/eggAudioHeapMgr.h" +#include "egg/audio/eggAudioSystem.h" #include "egg/core/eggHeap.h" #include "egg/egg_types.h" namespace EGG { + +class SoundArchivePlayerEGG : public nw4r::snd::SoundArchivePlayer { +public: + virtual StartResult + detail_SetupSound(nw4r::snd::SoundHandle *pHandle, u32 id, bool hold, const StartInfo *pStartInfo) override { + if (AudioSystem::sInstanse != nullptr && + (AudioSystem::sInstanse->field0x08NotZero() || AudioSystem::sInstanse->field0x04NotZero())) { + return START_ERR_USER; + } + return nw4r::snd::SoundArchivePlayer::detail_SetupSound(pHandle, id, hold, pStartInfo); + } // at 0x2C +}; + class IAudioMgr { public: struct Arg { + Arg(); /* 0x00 */ EGG::Heap *heap; /* 0x04 */ char *soundFileName; /* 0x08 */ int sndThreadPriority; - /* 0x0c */ int sndThreadStackSize; - /* 0x10 */ int dvdThreadPriority; + /* 0x0C */ int dvdThreadPriority; + /* 0x10 */ int sndThreadStackSize; /* 0x14 */ int dvdThreadStackSize; /* 0x18 */ u32 blocks; - /* 0x1c */ u8 field_0x1C; + /* 0x1c */ u32 field_0x1C; + /* 0x20 */ bool loadStringLabels; }; + + void init() { + field_0x04 = false; + } + + virtual UNKTYPE initialize(Arg *) {} + virtual UNKTYPE calc() = 0; + + bool field_0x04; +}; + +class SimpleAudioMgr : public IAudioMgr, public SoundHeapMgr, public ArcPlayer, public AudioSystem { +public: + struct SimpleAudioMgrArg : public IAudioMgr::Arg { + SimpleAudioMgrArg(); + }; + + SimpleAudioMgr(); + virtual ~SimpleAudioMgr(); + + void initialize(EGG::IAudioMgr::Arg *); + virtual void calc() override; + + virtual UNKTYPE *openDvdArchive(const char *, nw4r::snd::SoundHeap *) override; // at 0x10 + virtual UNKTYPE *openNandArchive(const char *, nw4r::snd::SoundHeap *) override; // at 0x14 + virtual UNKTYPE *setupMemoryArchive(const void *, nw4r::snd::SoundHeap *) override; // at 0x18 + + virtual void closeArchive() override; // at 0x20 + virtual bool loadGroup(unsigned int, nw4r::snd::SoundHeap *, u32) override; // at 0x24 + virtual bool loadGroup(int, nw4r::snd::SoundHeap *, u32) override; // at 0x28 + virtual bool loadGroup(u32, nw4r::snd::SoundHeap *, u32) override; // at 0x2C + virtual bool loadGroup(const char *, nw4r::snd::SoundHeap *, u32) override; // at 0x30 + +private: + SoundArchivePlayerEGG mArchivePlayer; }; -class SimpleAudioMgr : public IAudioMgr, public SoundHeapMgr, public ArcPlayer {}; } // namespace EGG #endif diff --git a/include/egg/audio/eggAudioRmtSpeakerMgr.h b/include/egg/audio/eggAudioRmtSpeakerMgr.h index aa209ecc..f33d0a8d 100644 --- a/include/egg/audio/eggAudioRmtSpeakerMgr.h +++ b/include/egg/audio/eggAudioRmtSpeakerMgr.h @@ -1,6 +1,49 @@ #ifndef EGG_AUDIO_REMOTE_SPEAKER_MANAGER_H #define EGG_AUDIO_REMOTE_SPEAKER_MANAGER_H -namespace EGG {} // namespace EGG +#include +#include + +namespace EGG { + +// Size 0xC +struct AudioRmtSpeakerTask { + bool field_0x00; + bool field_0x01; + s32 mChannel; + WPADCallback *mpCallback; +}; + +class AudioRmtSpeakerMgr { +public: + static void calc(); + + static void fn_804B6D80(s32 i, WPADCallback *pCallback); + static void fn_804B6DE0(s32 i, WPADCallback *pCallback); + + static void connectAllByForce(); + static void disconnectAllByForce(); + + static u8 getWpadVolume(); + +private: + static void setupCallback(s32, s32); + static void shutdownCallback(s32, s32); + static void fn_804B6AF0(s32 i, WPADCallback *pCallback, bool); + static void fn_804B6B80(s32 i, WPADCallback *pCallback); + static void fn_804B6C00(s32 i, WPADCallback *pCallback); + static void setupCallbackDirect(s32, s32); + static void shutdownCallbackDirect(s32, s32); + static bool sAudioRmtSpeakerConnectCanncelSw; + static u32 mTaskFinishCount; + static u32 mTaskRequestCount; + static bool sTask; + + static u8 sAudioRmtSpeakerWpadVolume; + + static AudioRmtSpeakerTask sTasks[0x14]; +}; + +} // namespace EGG #endif diff --git a/include/egg/audio/eggAudioSystem.h b/include/egg/audio/eggAudioSystem.h index f7b11811..b0e2f4a2 100644 --- a/include/egg/audio/eggAudioSystem.h +++ b/include/egg/audio/eggAudioSystem.h @@ -1,6 +1,40 @@ #ifndef EGG_AUDIO_SYSTEM_H #define EGG_AUDIO_SYSTEM_H -namespace EGG {} // namespace EGG +#include + +namespace EGG { + +class AudioSystem { +public: + AudioSystem(); + ~AudioSystem(); + + void fn_804B7270(s32 frame); + void fn_804B7370(); + void fn_804B73D0(s32 frame); + void calc(); + + bool isField0x04Eq2() { + return field_0x04 == 2; + } + + bool field0x08NotZero() { + return field_0x08 != 0; + } + + bool field0x04NotZero() { + return field_0x04 != 0; + } + + static AudioSystem *sInstanse; ///< sic + +private: + f32 field_0x00; + s32 field_0x04; + s32 field_0x08; +}; + +} // namespace EGG #endif diff --git a/include/egg/audio/eggAudioUtility.h b/include/egg/audio/eggAudioUtility.h index 96fcf1cc..6152d219 100644 --- a/include/egg/audio/eggAudioUtility.h +++ b/include/egg/audio/eggAudioUtility.h @@ -1,6 +1,52 @@ #ifndef EGG_AUDIO_ARC_UTILITY_H #define EGG_AUDIO_ARC_UTILITY_H -namespace EGG {} // namespace EGG +#include +#include +#include + +namespace EGG { + +// We don't really know much about this since it's +// unused in both NSMBW and SS +struct MultiArcSimpleAudioMgr { + u8 field_0x000[0x0FC - 0x000]; + s32 field_0x0FC; + ArcPlayer players[]; + + nw4r::snd::SoundArchivePlayer *getPlayer(int i) { + return players[i].getPlayer(); + } +}; + +class AudioUtility { +public: + class MoveParamMgr { + public: + MoveParamMgr(); + static void init(); + + nw4r::ut::List mList; + }; + + class HBM { + public: + static void init(SimpleAudioMgr *mgr, void (*userCallback)(), u32 frame); + static void enter(); + static void exit(bool); + + static MultiArcSimpleAudioMgr *sMultiArcSimpleAudioMgr; + static SimpleAudioMgr *sSimpleAudioMgr; + static void (*sHBMEffectRestCallback)(); + static void (*sHBMUserCallback)(s32, s32); + static u32 sHBFadeframe; + }; + + static MoveParamMgr sMoveParamMgr; + + static nw4r::ut::List lbl_80675480; +}; + +} // namespace EGG #endif diff --git a/include/nw4r/snd/snd_RemoteSpeaker.h b/include/nw4r/snd/snd_RemoteSpeaker.h index 10e9f037..884ec247 100644 --- a/include/nw4r/snd/snd_RemoteSpeaker.h +++ b/include/nw4r/snd/snd_RemoteSpeaker.h @@ -80,7 +80,9 @@ private: bool mCommandBusyFlag; // at 0x5 bool mForceResumeFlag; // at 0x6 bool mContinueFlag; // at 0x7 - volatile bool mIntervalFlag; // at 0x8 + // TODO commenting out a random flag to make eggAudioRmtSpeakerMgr match + // TODO offsets are wrong as a result + // volatile bool mIntervalFlag; // at 0x8 SpeakerState mState; // at 0xC SpeakerCommand mUserCommand; // at 0x10 SpeakerCommand mInternalCommand; // at 0x14 diff --git a/include/nw4r/snd/snd_SoundArchivePlayer.h b/include/nw4r/snd/snd_SoundArchivePlayer.h index 6c776e7e..2846d9d4 100644 --- a/include/nw4r/snd/snd_SoundArchivePlayer.h +++ b/include/nw4r/snd/snd_SoundArchivePlayer.h @@ -44,15 +44,14 @@ public: virtual void InvalidateWaveData(const void* pStart, const void* pEnd); // at 0x10 - virtual StartResult - detail_SetupSound(SoundHandle* pHandle, u32 id, - detail::BasicSound::AmbientArgInfo* pArgInfo, - detail::ExternalSoundPlayer* pPlayer, bool hold, - const StartInfo* pStartInfo); // at 0x28 - virtual u32 detail_ConvertLabelStringToSoundId(const char* pLabel) { return mSoundArchive->ConvertLabelStringToSoundId(pLabel); - } // at 0x2C + } // at 0x28 + + virtual StartResult + detail_SetupSound(SoundHandle* pHandle, u32 id, + bool hold, + const StartInfo* pStartInfo); // at 0x2C bool IsAvailable() const; @@ -198,6 +197,9 @@ private: SeqNoteOnCallback mSeqCallback; // at 0x20 WsdCallback mWsdCallback; // at 0x28 + // @TODO The comments here are wrong + u8 field_0x30[0x3C - 0x30]; + u32 mSoundPlayerCount; // at 0x30 SoundPlayer* mSoundPlayers; // at 0x34 diff --git a/include/nw4r/snd/snd_SoundStartable.h b/include/nw4r/snd/snd_SoundStartable.h index 71f701bd..86d5cd2c 100644 --- a/include/nw4r/snd/snd_SoundStartable.h +++ b/include/nw4r/snd/snd_SoundStartable.h @@ -59,8 +59,7 @@ public: virtual StartResult detail_SetupSound(SoundHandle* pHandle, u32 id, - detail::BasicSound::AmbientArgInfo* pArgInfo, - detail::ExternalSoundPlayer* pPlayer, bool hold, + bool hold, const StartInfo* pStartInfo) = 0; // at 0xC virtual u32 diff --git a/src/egg/audio/eggAudioArcPlayerMgr.cpp b/src/egg/audio/eggAudioArcPlayerMgr.cpp index 89b4927c..176ac9db 100644 --- a/src/egg/audio/eggAudioArcPlayerMgr.cpp +++ b/src/egg/audio/eggAudioArcPlayerMgr.cpp @@ -1,3 +1,292 @@ #include +#include +#include +#include -namespace EGG {} // namespace EGG +namespace EGG { + +using namespace nw4r; + +ArcPlayer::ArcPlayer(snd::SoundArchivePlayer *player, snd::SoundHeap *heap) + : mIsOpeningArchive(false), mIsLoadingGroup(false), mLoadLabelStringData(true), mOpenSndArchive(NULL), + mActiveSndArchivePlayer(player), mSoundHeap(heap), mStorage(STORAGE_NONE), mSteamBlocks(1) {} + +ArcPlayer::~ArcPlayer() {} + +bool ArcPlayer::setSteamBlocks(u32 n) { + if (!mOpenSndArchive) { + mSteamBlocks = n; + return true; + } + + return false; +} + +UNKTYPE *ArcPlayer::openArchive(const char *name, snd::SoundHeap *heap, SARC_STORAGE storage) { + UNKTYPE *ret = NULL; + + switch (storage) { + case STORAGE_DVD: ret = openDvdArchive(name, heap); break; + + case STORAGE_NAND: ret = openNandArchive(name, heap); break; + + default: break; + } + + return ret; +} + +UNKTYPE *ArcPlayer::openDvdArchive(const char *name, snd::SoundHeap *heap) { + u32 headerBufSize; + + if (!heap) { + heap = mSoundHeap; + } + + if (mOpenSndArchive) { + return mActiveSndArchivePlayer; + } + + mOpenSndArchive = &mDvdSndArchive; + + if (mDvdSndArchive.Open(name)) { + mIsOpeningArchive = true; + + headerBufSize = mDvdSndArchive.GetHeaderSize(); + mpHeaderBuf = heap->Alloc(headerBufSize, NULL, (void *)'ARCH'); + if (!mDvdSndArchive.LoadHeader(mpHeaderBuf, headerBufSize)) { + mIsOpeningArchive = false; + return NULL; + } + + if (mLoadLabelStringData) { + headerBufSize = mDvdSndArchive.GetLabelStringDataSize(); + void *stringDataBuf = heap->Alloc(headerBufSize, NULL, (void *)'ARCL'); + mDvdSndArchive.LoadLabelStringData(stringDataBuf, headerBufSize); + } + + u32 setupBufSize = mActiveSndArchivePlayer->GetRequiredMemSize(mOpenSndArchive); + void *setupBuf = heap->Alloc(setupBufSize, NULL, (void *)'APLM'); + + u32 strmBufSize = mSteamBlocks * mActiveSndArchivePlayer->GetRequiredStrmBufferSize(mOpenSndArchive); + void *strmBuf = heap->Alloc(strmBufSize, NULL, (void *)'APLS'); + + if (!mActiveSndArchivePlayer->Setup(mOpenSndArchive, setupBuf, setupBufSize, strmBuf, strmBufSize)) { + mIsOpeningArchive = false; + return NULL; + } + + mStorage = STORAGE_DVD; + mIsOpeningArchive = false; + return mActiveSndArchivePlayer; + } + + return NULL; +} + +UNKTYPE *ArcPlayer::openNandArchive(const char *name, snd::SoundHeap *heap) { + u32 headerBufSize; + + if (!heap) { + heap = mSoundHeap; + } + + if (mOpenSndArchive) { + return mActiveSndArchivePlayer; + } + + mOpenSndArchive = &mNandSndArchive; + + if (mNandSndArchive.Open(name)) { + mIsOpeningArchive = true; + + headerBufSize = mNandSndArchive.GetHeaderSize(); + void *headerBuf = heap->Alloc(headerBufSize, NULL, NULL); + if (!mNandSndArchive.LoadHeader(headerBuf, headerBufSize)) { + mIsOpeningArchive = false; + return NULL; + } + + if (mLoadLabelStringData) { + headerBufSize = mNandSndArchive.GetLabelStringDataSize(); + void *stringDataBuf = heap->Alloc(headerBufSize, NULL, NULL); + mNandSndArchive.LoadLabelStringData(stringDataBuf, headerBufSize); + } + + u32 setupBufSize = mActiveSndArchivePlayer->GetRequiredMemSize(&mNandSndArchive); + void *setupBuf = heap->Alloc(setupBufSize, NULL, NULL); + + u32 strmBufSize = mSteamBlocks * mActiveSndArchivePlayer->GetRequiredStrmBufferSize(&mNandSndArchive); + void *strmBuf = heap->Alloc(strmBufSize, NULL, NULL); + + if (!mActiveSndArchivePlayer->Setup(&mNandSndArchive, setupBuf, setupBufSize, strmBuf, strmBufSize)) { + mIsOpeningArchive = false; + return NULL; + } + + mStorage = STORAGE_NAND; + mIsOpeningArchive = false; + return mActiveSndArchivePlayer; + } + + return NULL; +} + +UNKTYPE *ArcPlayer::setupMemoryArchive(const void *work, snd::SoundHeap *heap) { + if (!heap) { + heap = mSoundHeap; + } + + if (mOpenSndArchive) { + return mActiveSndArchivePlayer; + } + + mOpenSndArchive = &mMemorySndArchive; + + if (mMemorySndArchive.Setup(work)) { + mIsOpeningArchive = true; + + u32 neededForMem = mActiveSndArchivePlayer->GetRequiredMemSize(&mMemorySndArchive); + void *memBuf = heap->Alloc(neededForMem, NULL, NULL); + + u32 neededForStrm = mSteamBlocks * mActiveSndArchivePlayer->GetRequiredStrmBufferSize(&mMemorySndArchive); + void *strmBuf = heap->Alloc(neededForStrm, NULL, NULL); + + if (!mActiveSndArchivePlayer->Setup(&mMemorySndArchive, memBuf, neededForMem, strmBuf, neededForStrm)) { + mIsOpeningArchive = false; + return NULL; + } + + mStorage = STORAGE_MEM; + mIsOpeningArchive = false; + return mActiveSndArchivePlayer; + } + + return NULL; +} + +UNKTYPE ArcPlayer::closeArchive() { + if (!mOpenSndArchive) { + return; + } + + switch (mStorage) { + case STORAGE_DVD: mDvdSndArchive.Close(); break; + + case STORAGE_NAND: mNandSndArchive.Close(); break; + + case STORAGE_CNT: + case STORAGE_MEM: mMemorySndArchive.Shutdown(); break; + } + + mActiveSndArchivePlayer->Shutdown(); + + mStorage = STORAGE_NONE; + mOpenSndArchive = NULL; +} + +bool ArcPlayer::loadGroup(unsigned int id, snd::SoundHeap *heap, u32 loadBlockSize) { + if (mStorage == STORAGE_NAND || mStorage == STORAGE_CNT) { + return true; + } + + if (!heap) { + heap = mSoundHeap; + } + + if (mIsOpeningArchive) { + return false; + } else { + if (!mActiveSndArchivePlayer->IsAvailable()) { + return false; + } + + mIsLoadingGroup = true; + UNKWORD result = mActiveSndArchivePlayer->LoadGroup((u32)id, heap, loadBlockSize); + mIsLoadingGroup = false; + return (result != 0); + } +} + +bool ArcPlayer::loadGroup(int id, snd::SoundHeap *heap, u32 loadBlockSize) { + if (mStorage == STORAGE_NAND || mStorage == STORAGE_CNT) { + return true; + } + + if (!heap) { + heap = mSoundHeap; + } + + if (mIsOpeningArchive) { + return false; + } else { + if (!mActiveSndArchivePlayer->IsAvailable()) { + return false; + } + + mIsLoadingGroup = true; + UNKWORD result = mActiveSndArchivePlayer->LoadGroup((u32)id, heap, loadBlockSize); + mIsLoadingGroup = false; + return (result != 0); + } +} + +bool ArcPlayer::loadGroup(u32 id, snd::SoundHeap *heap, u32 loadBlockSize) { + if (mStorage == STORAGE_NAND || mStorage == STORAGE_CNT) { + return true; + } + + if (!heap) { + heap = mSoundHeap; + } + + if (mIsOpeningArchive) { + return false; + } else { + if (!mActiveSndArchivePlayer->IsAvailable()) { + return false; + } + + mIsLoadingGroup = true; + bool b = (mActiveSndArchivePlayer->LoadGroup(id, heap, loadBlockSize) != 0); + mIsLoadingGroup = false; + return b; + } +} + +bool ArcPlayer::loadGroup(const char *name, snd::SoundHeap *heap, u32 loadBlockSize) { + if (mStorage == STORAGE_NAND || mStorage == STORAGE_CNT) { + return true; + } + + if (!heap) { + heap = mSoundHeap; + } + + if (mIsOpeningArchive) { + return false; + } else { + if (!mActiveSndArchivePlayer->IsAvailable()) { + return false; + } + + mIsLoadingGroup = true; + bool b = (mActiveSndArchivePlayer->LoadGroup(name, heap, loadBlockSize) != 0); + mIsLoadingGroup = false; + return b; + } +} + +void ArcPlayer::calc() { + if (!mIsOpeningArchive) { + mActiveSndArchivePlayer->Update(); + } +} + +void ArcPlayer::stopAllSound() { + for (int i = 0; i < mActiveSndArchivePlayer->GetSoundPlayerCount(); i++) { + mActiveSndArchivePlayer->GetSoundPlayer(i).StopAllSound(0); + } +} + +} // namespace EGG diff --git a/src/egg/audio/eggAudioHeapMgr.cpp b/src/egg/audio/eggAudioHeapMgr.cpp index b9582070..5ca7c5d7 100644 --- a/src/egg/audio/eggAudioHeapMgr.cpp +++ b/src/egg/audio/eggAudioHeapMgr.cpp @@ -1,3 +1,18 @@ #include -namespace EGG {} // namespace EGG +namespace EGG { + +void SoundHeapMgr::createSoundHeap(Allocator *allocator, u32 size) { + if (!mSoundHeap.IsValid()) { + void *ptr = allocator->alloc(size); + if (ptr != nullptr) { + mSoundHeap.Create(ptr, size); + } + } +} + +void SoundHeapMgr::destroySoundHeap() { + mSoundHeap.Destroy(); +} + +} // namespace EGG diff --git a/src/egg/audio/eggAudioMgr.cpp b/src/egg/audio/eggAudioMgr.cpp index 02f2f40f..ab330146 100644 --- a/src/egg/audio/eggAudioMgr.cpp +++ b/src/egg/audio/eggAudioMgr.cpp @@ -1,3 +1,96 @@ #include +#include +#include +#include -namespace EGG {} // namespace EGG +namespace EGG { + +IAudioMgr::Arg::Arg() { + heap = nullptr; + sndThreadPriority = 4; + dvdThreadPriority = 3; + soundFileName = nullptr; + sndThreadStackSize = 0; + dvdThreadStackSize = 0; + blocks = 1; +} + +SimpleAudioMgr::SimpleAudioMgrArg::SimpleAudioMgrArg() { + field_0x1C = 0x8CA000; + loadStringLabels = true; +} + +SimpleAudioMgr::SimpleAudioMgr() : ArcPlayer(&mArchivePlayer, getSoundHeap()) { + init(); +} + +SimpleAudioMgr::~SimpleAudioMgr() {} + +void SimpleAudioMgr::initialize(EGG::IAudioMgr::Arg *arg) { + AIInit(nullptr); + AXInit(); + + if (arg->field_0x1C != 0 && arg->heap != nullptr) { + Allocator alloc(arg->heap, 0x20); + SoundHeapMgr::createSoundHeap(&alloc, arg->field_0x1C); + } + + if (arg->sndThreadStackSize == 0 && arg->dvdThreadStackSize == 0) { + nw4r::snd::SoundSystem::InitSoundSystem(arg->sndThreadPriority, arg->dvdThreadPriority); + } else { + if (arg->sndThreadStackSize == 0) { + arg->sndThreadStackSize = 0x4000; + } + if (arg->dvdThreadStackSize == 0) { + arg->dvdThreadStackSize = 0x4000; + } + + nw4r::snd::SoundSystem::SoundSystemParam param; + param.soundThreadPriority = arg->sndThreadPriority; + param.soundThreadStackSize = arg->sndThreadStackSize; + param.dvdThreadPriority = arg->dvdThreadPriority; + param.dvdThreadStackSize = arg->dvdThreadStackSize; + u32 size = nw4r::snd::SoundSystem::GetRequiredMemSize(param); + void *ptr = SoundHeapMgr::getSoundHeap()->Alloc(size, nullptr, (void*)'SYST'); + nw4r::snd::SoundSystem::InitSoundSystem(param, ptr, size); + } + ArcPlayer::setSteamBlocks(arg->blocks); + setLoadStringLabels(arg->loadStringLabels); + IAudioMgr::field_0x04 = true; +} + +void SimpleAudioMgr::calc() { + AudioSystem::calc(); + if (AudioSystem::isField0x04Eq2()) { + ArcPlayer::stopAllSound(); + } + ArcPlayer::calc(); +} + +UNKTYPE *SimpleAudioMgr::openDvdArchive(const char *name, nw4r::snd::SoundHeap *heap) { + return ArcPlayer::openDvdArchive(name, heap); +} +UNKTYPE *SimpleAudioMgr::openNandArchive(const char *name, nw4r::snd::SoundHeap *heap) { + return ArcPlayer::openNandArchive(name, heap); +} +UNKTYPE *SimpleAudioMgr::setupMemoryArchive(const void *name, nw4r::snd::SoundHeap *heap) { + return ArcPlayer::setupMemoryArchive(name, heap); +} + +void SimpleAudioMgr::closeArchive() { + ArcPlayer::closeArchive(); +} +bool SimpleAudioMgr::loadGroup(unsigned int arg, nw4r::snd::SoundHeap *heap, u32 arg2) { + return ArcPlayer::loadGroup(arg, heap, arg2); +} +bool SimpleAudioMgr::loadGroup(int arg, nw4r::snd::SoundHeap *heap, u32 arg2) { + return ArcPlayer::loadGroup(arg, heap, arg2); +} +bool SimpleAudioMgr::loadGroup(u32 arg, nw4r::snd::SoundHeap *heap, u32 arg2) { + return ArcPlayer::loadGroup(arg, heap, arg2); +} +bool SimpleAudioMgr::loadGroup(const char *arg, nw4r::snd::SoundHeap *heap, u32 arg2) { + return ArcPlayer::loadGroup(arg, heap, arg2); +} + +} // namespace EGG diff --git a/src/egg/audio/eggAudioRmtSpeakerMgr.cpp b/src/egg/audio/eggAudioRmtSpeakerMgr.cpp index 62eeaa21..08695c8e 100644 --- a/src/egg/audio/eggAudioRmtSpeakerMgr.cpp +++ b/src/egg/audio/eggAudioRmtSpeakerMgr.cpp @@ -1,3 +1,146 @@ #include +#include +#include -namespace EGG {} // namespace EGG +namespace EGG { + +bool AudioRmtSpeakerMgr::sAudioRmtSpeakerConnectCanncelSw; +u32 AudioRmtSpeakerMgr::mTaskFinishCount; +u32 AudioRmtSpeakerMgr::mTaskRequestCount; +bool AudioRmtSpeakerMgr::sTask; + +u8 AudioRmtSpeakerMgr::sAudioRmtSpeakerWpadVolume = 0x58; + +AudioRmtSpeakerTask AudioRmtSpeakerMgr::sTasks[0x14]; + +void AudioRmtSpeakerMgr::setupCallback(s32 arg1, s32 arg2) { + if (arg2 == 0) { + if (sTasks[mTaskFinishCount].mpCallback != nullptr) { + (sTasks[mTaskFinishCount].mpCallback)(arg1, arg2); + } + sAudioRmtSpeakerWpadVolume = WPADGetSpeakerVolume(); + } else { + fn_804B6D80(arg1, sTasks[mTaskFinishCount].mpCallback); + } + sTasks[mTaskFinishCount].field_0x01 = true; +} + +void AudioRmtSpeakerMgr::shutdownCallback(s32 arg1, s32 arg2) { + if ((u32)arg2 + 1 <= 1) { + if (sTasks[mTaskFinishCount].mpCallback != nullptr) { + (sTasks[mTaskFinishCount].mpCallback)(arg1, arg2); + } + } else { + fn_804B6DE0(arg1, sTasks[mTaskFinishCount].mpCallback); + } + sTasks[mTaskFinishCount].field_0x01 = true; +} + +void AudioRmtSpeakerMgr::fn_804B6AF0(s32 i, WPADCallback *pCallback, bool enable) { + BOOL intr = OSDisableInterrupts(); + + u32 index = mTaskRequestCount; + sTasks[index].mChannel = i; + sTasks[index].field_0x00 = enable; + sTasks[index].mpCallback = pCallback; + sTasks[index].field_0x01 = false; + if (++mTaskRequestCount >= 0x14) { + mTaskRequestCount = 0; + } + + OSRestoreInterrupts(intr); +} + +void AudioRmtSpeakerMgr::fn_804B6B80(s32 i, WPADCallback *pCallback) { + if (!nw4r::snd::SoundSystem::GetRemoteSpeaker(i).Setup(pCallback)) { + fn_804B6AF0(i, pCallback, true); + sTasks[mTaskRequestCount].field_0x01 = true; + } +} + +void AudioRmtSpeakerMgr::fn_804B6C00(s32 i, WPADCallback *pCallback) { + nw4r::snd::SoundSystem::GetRemoteSpeaker(i).Shutdown(pCallback); +} + +void AudioRmtSpeakerMgr::calc() { + if (!sTask) { + if (mTaskRequestCount != mTaskFinishCount) { + if (sTasks[mTaskFinishCount].field_0x00) { + fn_804B6B80(sTasks[mTaskFinishCount].mChannel, setupCallback); + } else { + fn_804B6C00(sTasks[mTaskFinishCount].mChannel, shutdownCallback); + } + sTask = true; + } + } else if (sTasks[mTaskFinishCount].field_0x01) { + sTask = false; + mTaskFinishCount++; + if (mTaskFinishCount >= 0x14) { + mTaskFinishCount = 0; + } + } +} + +void AudioRmtSpeakerMgr::setupCallbackDirect(s32 arg1, s32 arg2) { + if (arg2 == 0) { + sAudioRmtSpeakerWpadVolume = WPADGetSpeakerVolume(); + } else { + fn_804B6B80(arg1, setupCallbackDirect); + } +} + +void AudioRmtSpeakerMgr::shutdownCallbackDirect(s32 arg1, s32 arg2) { + if (arg2 == -1) { + return; + } + if (arg2 == 0) { + return; + } + fn_804B6C00(arg1, shutdownCallbackDirect); +} + +void AudioRmtSpeakerMgr::fn_804B6D80(s32 i, WPADCallback *pCallback) { + WPADDeviceType ty; + if (!sAudioRmtSpeakerConnectCanncelSw && WPADProbe(i, &ty) != WPAD_ERR_NO_CONTROLLER) { + fn_804B6AF0(i, pCallback, true); + } +} + +void AudioRmtSpeakerMgr::fn_804B6DE0(s32 i, WPADCallback *pCallback) { + WPADDeviceType ty; + if (!sAudioRmtSpeakerConnectCanncelSw) { + if (WPADProbe(i, &ty) == WPAD_ERR_NO_CONTROLLER) { + if (!nw4r::snd::SoundSystem::GetRemoteSpeaker(i).IsEnabledOutput()) { + return; + } + } + fn_804B6AF0(i, pCallback, false); + } +} + +void AudioRmtSpeakerMgr::connectAllByForce() { + WPADDeviceType ty; + sAudioRmtSpeakerConnectCanncelSw = false; + for (int i = 0; i < 4; i++) { + if (WPADProbe(i, &ty) != WPAD_ERR_NO_CONTROLLER) { + fn_804B6B80(i, setupCallbackDirect); + } + } +} + +void AudioRmtSpeakerMgr::disconnectAllByForce() { + WPADDeviceType ty; + for (int i = 0; i < 4; i++) { + WPADProbe(i, &ty); // ignoring result here + if (nw4r::snd::SoundSystem::GetRemoteSpeaker(i).IsAvailable()) { + fn_804B6C00(i, shutdownCallbackDirect); + } + } + sAudioRmtSpeakerConnectCanncelSw = true; +} + +u8 AudioRmtSpeakerMgr::getWpadVolume() { + return sAudioRmtSpeakerWpadVolume; +} + +} // namespace EGG diff --git a/src/egg/audio/eggAudioSystem.cpp b/src/egg/audio/eggAudioSystem.cpp index 12b88463..50d8634d 100644 --- a/src/egg/audio/eggAudioSystem.cpp +++ b/src/egg/audio/eggAudioSystem.cpp @@ -1,3 +1,53 @@ #include +#include -namespace EGG {} // namespace EGG +namespace EGG { + +AudioSystem *AudioSystem::sInstanse; + +AudioSystem::AudioSystem() { + field_0x00 = 1.0f; + field_0x08 = 0; + field_0x04 = 0; + sInstanse = this; +} + +AudioSystem::~AudioSystem() {} + +void AudioSystem::fn_804B7270(s32 frame) { + if (field_0x08 == 0 && field_0x04 == 0) { + field_0x00 = nw4r::snd::SoundSystem::GetMasterVolume(); + nw4r::snd::SoundSystem::SetMasterVolume(0.0f, frame * 16.666667f); + field_0x04 = 1; + } +} + +void AudioSystem::fn_804B7370() { + if (field_0x08 == 0) { + nw4r::snd::SoundSystem::SetMasterVolume(field_0x00, 0); + field_0x04 = 0; + } +} + +void AudioSystem::fn_804B73D0(s32 frame) { + if (field_0x08 == 0) { + field_0x08 = 1; + nw4r::snd::SoundSystem::SetMasterVolume(0.0f, frame * 16.666667f); + } +} + +void AudioSystem::calc() { + f32 masterVolume = nw4r::snd::SoundSystem::GetMasterVolume(); + + if (field_0x08 == 1 && masterVolume == 0.0f) { + nw4r::snd::SoundSystem::PrepareReset(); + nw4r::snd::SoundSystem::WaitForResetReady(); + field_0x08 = 2; + } + + if (field_0x08 != 2 && field_0x04 == 1 && masterVolume == 0.0f) { + field_0x04 = 2; + } +} + +} // namespace EGG diff --git a/src/egg/audio/eggAudioUtility.cpp b/src/egg/audio/eggAudioUtility.cpp index 5fc52e30..95c2b0b9 100644 --- a/src/egg/audio/eggAudioUtility.cpp +++ b/src/egg/audio/eggAudioUtility.cpp @@ -1,3 +1,93 @@ +#include #include +#include +#include -namespace EGG {} // namespace EGG +namespace EGG { + +AudioUtility::MoveParamMgr AudioUtility::sMoveParamMgr; + +MultiArcSimpleAudioMgr *AudioUtility::HBM::sMultiArcSimpleAudioMgr; +SimpleAudioMgr *AudioUtility::HBM::sSimpleAudioMgr; +void (*AudioUtility::HBM::sHBMEffectRestCallback)(); +void (*AudioUtility::HBM::sHBMUserCallback)(s32, s32); +u32 AudioUtility::HBM::sHBFadeframe = 0x12; + +AudioUtility::MoveParamMgr::MoveParamMgr() { + init(); +} + +void AudioUtility::MoveParamMgr::init() { + nw4r::ut::List_Init(&sMoveParamMgr.mList, 0x28); +} + +void AudioUtility::HBM::init(SimpleAudioMgr *mgr, void (*userCallback)(), u32 frame) { + sSimpleAudioMgr = mgr; + sHBFadeframe = frame; + sHBMEffectRestCallback = userCallback; +} + +void AudioUtility::HBM::enter() { + if (sHBMUserCallback != nullptr) { + (sHBMUserCallback)(0, 0); + } + + // Regswaps + u32 i; + int j; + + if (sSimpleAudioMgr != nullptr) { + for (i = 0; i < sSimpleAudioMgr->getPlayer()->GetSoundPlayerCount(); i++) { + sSimpleAudioMgr->getPlayer()->GetSoundPlayer(i).PauseAllSound(true, sHBFadeframe); + } + } + + if (sMultiArcSimpleAudioMgr != nullptr) { + int max = sMultiArcSimpleAudioMgr->field_0x0FC; + for (j = 0; j < max; j++) { + for (i = 0; i < sMultiArcSimpleAudioMgr->getPlayer(j)->GetSoundPlayerCount(); i++) { + sMultiArcSimpleAudioMgr->getPlayer(j)->GetSoundPlayer(i).PauseAllSound(true, sHBFadeframe); + } + } + } + + nw4r::snd::SoundSystem::ClearEffect(nw4r::snd::AUX_A, 0xFA); + nw4r::snd::SoundSystem::ClearEffect(nw4r::snd::AUX_B, 0xFA); + nw4r::snd::SoundSystem::ClearEffect(nw4r::snd::AUX_C, 0xFA); + AudioRmtSpeakerMgr::disconnectAllByForce(); +} + +void AudioUtility::HBM::exit(bool arg) { + if (sHBMUserCallback != nullptr) { + (sHBMUserCallback)(true, arg); + } + + if (arg) { + // Regswaps + u32 i; + int j; + + if (sSimpleAudioMgr != nullptr) { + for (i = 0; i < sSimpleAudioMgr->getPlayer()->GetSoundPlayerCount(); i++) { + sSimpleAudioMgr->getPlayer()->GetSoundPlayer(i).PauseAllSound(false, sHBFadeframe); + } + } + + if (sMultiArcSimpleAudioMgr != nullptr) { + int max = sMultiArcSimpleAudioMgr->field_0x0FC; + for (j = 0; j < max; j++) { + for (i = 0; i < sMultiArcSimpleAudioMgr->getPlayer(j)->GetSoundPlayerCount(); i++) { + sMultiArcSimpleAudioMgr->getPlayer(j)->GetSoundPlayer(i).PauseAllSound(false, sHBFadeframe); + } + } + } + } + + if (sHBMEffectRestCallback != nullptr) { + (sHBMEffectRestCallback)(); + } + + AudioRmtSpeakerMgr::connectAllByForce(); +} + +} // namespace EGG