NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
snd_Voice.h
1#ifndef NW4R_SND_VOICE_H
2#define NW4R_SND_VOICE_H
3
4/*******************************************************************************
5 * headers
6 */
7
8#include <types.h>
9
10#include "nw4r/snd/snd_adpcm.h" // AdpcmLoopParam
11#include "nw4r/snd/snd_AxVoice.h"
12#include "nw4r/snd/snd_global.h"
13#include "nw4r/snd/snd_DisposeCallbackManager.h" // DisposeCallback
14
15#include "nw4r/ut/ut_LinkList.h"
16
17/*******************************************************************************
18 * types
19 */
20
21// forward declarations
22namespace nw4r { namespace snd { namespace detail { struct WaveInfo; }}}
23
24/*******************************************************************************
25 * classes and functions
26 */
27
28namespace nw4r { namespace snd { namespace detail
29{
30 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2b832
31 // NOTE: different from ketteiban: no remote fields
32 class Voice : public DisposeCallback
33 {
34 // enums
35 public:
36 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2b6c2
37 enum VoiceCallbackStatus
38 {
39 CALLBACK_STATUS_FINISH_WAVE,
40 CALLBACK_STATUS_CANCEL,
41 CALLBACK_STATUS_DROP_VOICE,
42 CALLBACK_STATUS_DROP_DSP,
43 };
44
45 enum VoiceSyncFlag {
46 SYNC_AX_SRC_INITIAL = (1 << 0),
47 SYNC_AX_VOICE = (1 << 1),
48 SYNC_AX_SRC = (1 << 2),
49 SYNC_AX_VE = (1 << 3),
50 SYNC_AX_MIX = (1 << 4),
51 SYNC_AX_LPF = (1 << 5),
52 SYNC_AX_REMOTE = (1 << 7),
53 SYNC_AX_BIQUAD = (1 << 8),
54 };
55
56 // typedefs
57 public:
58 typedef ut::LinkList<Voice, 0xfc> LinkList;
59
60 typedef void Callback(Voice *dropVoice, VoiceCallbackStatus status,
61 void *callbackData);
62
63 // methods
64 public:
65 // cdtors
66 Voice();
67 virtual ~Voice();
68
69 // virtual function ordering
70 // vtable DisposeCallback
71 virtual void InvalidateData(void const *, void const *) {}
72 virtual void InvalidateWaveData(void const *start, void const *end);
73
74 // methods
75 void Setup(WaveInfo const &waveParam, ulong startOffset);
76
77 int GetPriority() const { return mPriority; }
78
79 void SetVoiceOutParam(int voiceOutIndex,
80 VoiceOutParam const &voiceOutParam);
81 void SetVoiceOutParamPitchDisableFlag(bool flag)
82 {
83 mVoiceOutParamPitchDisableFlag = flag;
84 }
85 void SetRemoteFilter(int filter);
86 void SetBiquadFilter(int type, f32 value);
87 void SetPriority(int priority);
88 void SetPan(f32 pan);
89 void SetSurroundPan(f32 surroundPan);
90 void SetLpfFreq(f32 lpfFreq);
91 void SetOutputLine(int flag);
92 void SetMainOutVolume(f32 volume);
93 void SetMainSend(f32 send);
94 void SetFxSend(AuxBus bus, f32 send);
95 void SetRemoteOutVolume(int remote, f32 volume);
96 void SetPitch(f32 pitch);
97 void SetVolume(f32 volume);
98 void SetVeVolume(f32 targetVolume, f32 initVolume);
99 void SetPanMode(PanMode panMode);
100 void SetPanCurve(PanCurve panCurve);
101
102 bool IsActive() const { return mAxVoice[0][0] != nullptr; }
103 bool IsPlayFinished() const
104 {
105 return IsActive() && mAxVoice[0][0]->IsPlayFinished();
106 }
107 bool IsRun() const
108 {
109 return IsActive() && mAxVoice[0][0]->IsRun();
110 }
111 SampleFormat GetFormat() const;
112 ulong GetCurrentPlayingSample() const;
113 int GetPhysicalVoiceCount() const
114 {
115 return mChannelCount * mVoiceOutCount;
116 }
117
118 void SetVoiceType(AxVoice::VoiceType type);
119 void SetLoopFlag(bool loopFlag);
120 void SetLoopStart(int channelIndex, void const *baseAddress,
121 ulong samples);
122 void SetLoopEnd(int channelIndex, void const *baseAddress, ulong samples);
123 void SetAdpcmLoop(int channelIndex, AdpcmLoopParam const *param);
124
125 bool Acquire(int channelCount, int voiceOutCount, int priority,
126 Callback *callback, void *callbackData);
127 void Free();
128
129 void InitParam(int channelCount, int voiceOutCount, Callback *callback,
130 void *callbackData);
131
132 void Start();
133 void Pause(bool flag);
134 void Stop();
135 void StopAtPoint(int channelIndex, void const *baseAddress,
136 ulong samples);
137
138 private:
139 void RunAllAxVoice();
140 void StopAllAxVoice();
141 void SyncAxVoice();
142 void StopFinished();
143
144 void Calc();
145 void CalcAxSrc(bool initialUpdate);
146 void CalcAxVe();
147 bool CalcAxMix();
148 void CalcAxLpf();
149 void CalcAxBiquadFilter();
150 void CalcAxRemoteFilter();
151
152 void CalcMixParam(int channelIndex, int voiceOutIndex,
155
156 void Update();
157 void UpdateVoicesPriority();
158
159 void ResetDelta();
160
161 void TransformDpl2Pan(f32 *outPan, f32 *outSurroundPan, f32 inPan,
162 f32 inSurroundPan);
163
164 static void AxVoiceCallbackFunc(AxVoice *dropVoice,
165 AxVoice::AxVoiceCallbackStatus status,
166 void *callbackData);
167
168 // static members
169 public:
170 static f32 const SURROUND_ATTENUATED_DB;
171 static ulong const VOICE_PRIORITY_RELEASE;
172 static ulong const VOICE_PRIORITY_ALLOC;
173 static ulong const VOICE_PRIORITY_USE;
174 static int const VOICE_PRIORITY_FREE;
175 static ulong const VOICE_PRIORITY_NODROP;
176 static ulong const VOICE_PRIORITY_MAX = 31; // just going to put it here
177 static int const PRIORITY_RELEASE;
178 static int const PRIORITY_NODROP;
179 static int const PRIORITY_MIN = 0;
180 static int const PRIORITY_MAX = 255;
181 static int const REMOTE_FILTER_MAX = 127;
182 static int const REMOTE_FILTER_MIN = 0;
183 static f32 const SEND_MAX;
184 static f32 const SEND_MIN;
185 static f32 const BIQUAD_VALUE_MAX;
186 static f32 const BIQUAD_VALUE_MIN;
187 static f32 const CUTOFF_FREQ_MAX;
188 static f32 const CUTOFF_FREQ_MIN;
189 static f32 const SPAN_CENTER;
190 static f32 const SPAN_REAR;
191 static f32 const SPAN_FRONT;
192 static f32 const PAN_CENTER;
193 static f32 const PAN_RIGHT;
194 static f32 const PAN_LEFT;
195 static f32 const VOLUME_MAX;
196 static f32 const VOLUME_MIN;
197 static int const CHANNEL_MAX = 2;
198 static int const UPDATE_BIQUAD = 1 << 8;
199 static int const UPDATE_REMOTE_FILTER = 1 << 7;
200 // 1 << 6 skipped
201 static int const UPDATE_LPF = 1 << 5;
202 static int const UPDATE_MIX = 1 << 4;
203 static int const UPDATE_VE = 1 << 3;
204 static int const UPDATE_SRC = 1 << 2;
205 static int const UPDATE_PAUSE = 1 << 1;
206 static int const UPDATE_START = 1 << 0;
207
208 // members
209 private:
210 /* base DisposeCallback */ // size 0x0c, offset 0x00
211 AxVoice *mAxVoice[CHANNEL_MAX][4]; // size 0x20, offset 0x0c
212 VoiceOutParam mVoiceOutParam[4]; // size 0x60, offset 0x2c
213 int mChannelCount; // size 0x04, offset 0x8c
214 int mVoiceOutCount; // size 0x04, offset 0x90
215 Callback *mCallback; // size 0x04, offset 0x94
216 void *mCallbackData; // size 0x04, offset 0x98
217 bool mActiveFlag; // size 0x01, offset 0x9c
218 bool mStartFlag; // size 0x01, offset 0x9d
219 bool mStartedFlag; // size 0x01, offset 0x9e
220 bool mPauseFlag; // size 0x01, offset 0x9f
221 bool mPausingFlag; // size 0x01, offset 0xa0
222 bool mVoiceOutParamPitchDisableFlag; // size 0x01, offset 0xa1
223 u16 mSyncFlag; // size 0x02, offset 0xa2
224 u8 mRemoteFilter; // size 0x01, offset 0xa4
225 u8 mBiquadType; // size 0x01, offset 0xa5
226 /* 2 bytes padding */
227 int mPriority; // size 0x04, offset 0xa8
228 f32 mPan; // size 0x04, offset 0xac
229 f32 mSurroundPan; // size 0x04, offset 0xb0
230 f32 mLpfFreq; // size 0x04, offset 0xb4
231 f32 mBiquadValue; // size 0x04, offset 0xb8
232 int mOutputLineFlag; // size 0x04, offset 0xbc
233 f32 mMainOutVolume; // size 0x04, offset 0xc0
234 f32 mMainSend; // size 0x04, offset 0xc4
235 f32 mFxSend[AUX_BUS_NUM]; // size 0x0c, offset 0xc8
236 f32 mRemoteOutVolume[4]; // size 0x10, offset 0xd4 TODO following sizes wrong
237 f32 mPitch; // size 0x04, offset 0xd4
238 f32 mVolume; // size 0x04, offset 0xd8
239 f32 mVeInitVolume; // size 0x04, offset 0xdc
240 f32 mVeTargetVolume; // size 0x04, offset 0xe0
241 PanMode mPanMode; // size 0x04, offset 0xe4
242 PanCurve mPanCurve; // size 0x04, offset 0xe8
243 public:
244 ut::LinkListNode mLinkNode; // size 0x08, offset 0xec
245
246 // friends
247 private:
248 friend class VoiceManager;
249 }; // size 0xf4
250}}} // namespace nw4r::snd::detail
251
252#endif // NW4R_SND_VOICE_H