Untangle eggAudio a bit (#61)

* Untangle eggAudio a bit

* eggAudioRmtSpeakerMgr with a regswap

* Fix eggAudioRmtSpeakerMgr (thanks Cuyler!)

* eggAudioUtility with two regswaps
This commit is contained in:
robojumper
2024-10-16 03:44:09 +02:00
committed by GitHub
parent 40b04ad724
commit bf79fa17fb
18 changed files with 1108 additions and 84 deletions
+124 -1
View File
@@ -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
+36 -1
View File
@@ -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
+54 -4
View File
@@ -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
+44 -1
View File
@@ -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
+35 -1
View File
@@ -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
+47 -1
View File
@@ -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
+3 -1
View File
@@ -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
+9 -7
View File
@@ -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
+1 -2
View File
@@ -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