NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
snd_AxManager.h
1#ifndef NW4R_SND_AX_MANAGER_H
2#define NW4R_SND_AX_MANAGER_H
3
4/*******************************************************************************
5 * headers
6 */
7
8#include <types.h>
9
10#include "nw4r/snd/snd_AxVoice.h"
11#include "nw4r/snd/snd_global.h"
12
13#include "nw4r/snd/snd_FxBase.h"
14#include "nw4r/snd/snd_MoveValue.h"
15
16#include "nw4r/ut/ut_LinkList.h"
17
18#include <revolution/AI/ai.h> // AIDMACallback
19#include <revolution/AX/AX.h>
20#include <revolution/AX/AXCL.h> // AX_MAX_VOLUME
21#include <revolution/AX/AXAux.h> // AXAuxCallback
22#include <revolution/AX/AXOut.h> // AXFrameCallback
23
24#include "nw4r/NW4RAssert.hpp"
25
26/*******************************************************************************
27 * types
28 */
29
30// forward declarations
31namespace nw4r { namespace snd { namespace detail { class BiquadFilterLpf; }}}
32namespace nw4r { namespace snd { namespace detail { class BiquadFilterHpf; }}}
33namespace nw4r { namespace snd { namespace detail { class BiquadFilterBpf512; }}}
34namespace nw4r { namespace snd { namespace detail { class BiquadFilterBpf1024; }}}
35namespace nw4r { namespace snd { namespace detail { class BiquadFilterBpf2048; }}}
36namespace nw4r { namespace snd { class BiquadFilterCallback; }}
37
38/*******************************************************************************
39 * classes and functions
40 */
41
42namespace nw4r { namespace snd { namespace detail
43{
44 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2a5afe
45 class AxManager
46 {
47 // nested types
48 public:
49 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2a6808
51 {
52 // typedefs
53 public:
55
56 // members
57 public:
58 ut::LinkListNode node; // size 0x08, offset 0x00
59 AXFrameCallback *callback; // size 0x04, offset 0x08
60 }; // size 0x0c
61
62 // methods
63 public:
64 // instance accessors
65 static AxManager &GetInstance();
66
67 // methods
68 void Init();
69 void Update();
70 void Shutdown();
71
72 OutputMode GetOutputMode();
73 void const *GetZeroBufferAddress();
74 bool CheckInit() { return mInitialized; }
75 f32 GetOutputVolume() const;
76 FxBase::LinkList &GetEffectList(AuxBus bus)
77 {
78 NW4RAssertHeaderClampedLValue_Line(173, bus, AUX_A, AUX_BUS_NUM);
79
80 return mFxList[bus];
81 }
82 BiquadFilterCallback const *GetBiquadFilterCallback(int index)
83 {
84 return sBiquadFilterCallbackTable[static_cast<u8>(index)];
85 }
86
87 void SetOutputMode(OutputMode mode);
88 void SetMainOutVolume(f32 volume, int frames);
89 void SetBiquadFilterCallback(int type,
90 BiquadFilterCallback const *callback);
91
92 void RegisterCallback(CallbackListNode *node,
93 AXFrameCallback *callback);
94 void UnregisterCallback(CallbackListNode *node);
95
96 bool AppendEffect(AuxBus bus, FxBase *pFx);
97 void ClearEffect(AuxBus bus, int frame);
98 void ShutdownEffect(AuxBus bus);
99
100 f32 GetMasterVolume() const {
101 return mMasterVolume.GetValue();
102 }
103 void SetMasterVolume(f32 volume, int frame);
104 void PrepareReset();
105
106 bool IsResetReady() const {
107 return mResetReadyCounter == 0;
108 }
109
110 AxVoice::SrcType GetSrcType() const {
111 return mSrcType;
112 }
113
114 private:
115 // cdtors
116 AxManager();
117
118 // callbacks
119 static void AxCallbackFunc();
120 static void AuxCallbackFunc(void* pChans, void* pContext);
121 static void AiDmaCallbackFunc();
122
123 // static members
124 private:
125 static u8 const AUX_CALLBACK_WAIT_FRAME = 6;
126 static u16 const AUX_RETURN_VOLUME_MAX = AX_MAX_VOLUME;
127 static int const FX_SAMPLE_RATE = 32000;
128 static SampleFormat const FX_SAMPLE_FORMAT = SAMPLE_FORMAT_PCM_S32;
129 static int const FX_BUFFER_SIZE = 0x180;
130 static int const ZERO_BUFFER_SIZE = 256;
131 static int const SAMPLES_PAR_AUDIO_FRAME;
132 static int const AUDIO_FRAME_INTERVAL;
133
134 static byte_t sZeroBuffer[ZERO_BUFFER_SIZE];
135 static BiquadFilterCallback const *sBiquadFilterCallbackTable[128];
136 static BiquadFilterLpf sBiquadFilterLpf;
137 static BiquadFilterHpf sBiquadFilterHpf;
138 static BiquadFilterBpf512 sBiquadFilterBpf512;
139 static BiquadFilterBpf1024 sBiquadFilterBpf1024;
140 static BiquadFilterBpf2048 sBiquadFilterBpf2048;
141
142 // members
143 private:
144 OutputMode mOutputMode; // size 0x04, offset 0x00
145 void *mZeroBufferAddress; // size 0x04, offset 0x04
146 CallbackListNode::LinkList mCallbackList; // size 0x0c, offset 0x08
147 AXFrameCallback *mNextAxRegisterCallback; // size 0x04, offset 0x14
148 bool mInitialized; // size 0x01, offset 0x18
149 bool mUpdateVoicePrioFlag; // size 0x01, offset 0x19
150 /* 2 bytes padding */
151 MoveValue<f32, int> mMasterVolume; // size 0x10, offset 0x1c
152 MoveValue<f32, int> mMainOutVolume; // size 0x10, offset 0x2c
153 MoveValue<f32, int> mVolumeForReset; // size 0x10, offset 0x3c
154 AIDMACallback mOldAidCallback; // size 0x04, offset 0x4c
155 volatile s32 mResetReadyCounter; // size 0x04, offset 0x50
156 MoveValue<f32, int> mAuxFadeVolume[AUX_BUS_NUM]; // size 0x30, offset 0x54
157 MoveValue<f32, int> mAuxUserVolume[AUX_BUS_NUM]; // size 0x30, offset 0x84
158 FxBase::LinkList mFxList[AUX_BUS_NUM]; // size 0x24, offset 0xb4
159 AXAuxCallback mAuxCallback[AUX_BUS_NUM]; // size 0x0c, offset 0xd8
160 void *mAuxCallbackContext[AUX_BUS_NUM]; // size 0x0c, offset 0xe4
161 u8 mAuxCallbackWaitCounter[AUX_BUS_NUM]; // size 0x03, offset 0xf0
162 /* 1 byte padding */
163 ulong mEffectProcessTick[AUX_BUS_NUM]; // size 0x0c, offset 0xf4
164 AxVoice::SrcType mSrcType;
165 }; // size 0x104
166}}} // namespace nw4r::snd::detail
167
168#endif // NW4R_SND_AX_MANAGER_H