diff options
| author | robojumper <robojumper@gmail.com> | 2024-10-16 03:44:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-15 21:44:09 -0400 |
| commit | bf79fa17fbc106fd06c545732ad875275821376e (patch) | |
| tree | 17249f9386cb4e6d174090772ac7fe2cb702a5d9 /include | |
| parent | 40b04ad7247e1d60ac99f62698e7c04388bfcdfc (diff) | |
Untangle eggAudio a bit (#61)
* Untangle eggAudio a bit
* eggAudioRmtSpeakerMgr with a regswap
* Fix eggAudioRmtSpeakerMgr (thanks Cuyler!)
* eggAudioUtility with two regswaps
Diffstat (limited to 'include')
| -rw-r--r-- | include/egg/audio/eggAudioArcPlayerMgr.h | 125 | ||||
| -rw-r--r-- | include/egg/audio/eggAudioHeapMgr.h | 37 | ||||
| -rw-r--r-- | include/egg/audio/eggAudioMgr.h | 58 | ||||
| -rw-r--r-- | include/egg/audio/eggAudioRmtSpeakerMgr.h | 45 | ||||
| -rw-r--r-- | include/egg/audio/eggAudioSystem.h | 36 | ||||
| -rw-r--r-- | include/egg/audio/eggAudioUtility.h | 48 | ||||
| -rw-r--r-- | include/nw4r/snd/snd_RemoteSpeaker.h | 4 | ||||
| -rw-r--r-- | include/nw4r/snd/snd_SoundArchivePlayer.h | 16 | ||||
| -rw-r--r-- | include/nw4r/snd/snd_SoundStartable.h | 3 |
9 files changed, 353 insertions, 19 deletions
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 <common.h> +#include <nw4r/snd/snd_DvdSoundArchive.h> +#include <nw4r/snd/snd_MemorySoundArchive.h> +#include <nw4r/snd/snd_NandSoundArchive.h> +#include <nw4r/snd/snd_SoundArchivePlayer.h> +#include <nw4r/snd/snd_SoundHeap.h> + 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 <egg/core/eggAllocator.h> +#include <nw4r/snd/snd_SoundHeap.h> + 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 <common.h> +#include <rvl/WPAD.h> + +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 <common.h> + +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 <common.h> +#include <egg/audio/eggAudioMgr.h> +#include <nw4r/ut/ut_list.h> + +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 |
