NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_audio.hpp
Go to the documentation of this file.
1#pragma once
3#include <game/snd/snd_2d_calc.hpp>
4#include <game/snd/snd_audio_mgr.hpp>
5#include <game/snd/snd_scene_manager.hpp>
6#include <game/mLib/m_vec.hpp>
7#include <lib/egg/core/eggHeap.h>
8#include <nw4r/snd.h>
9#include <nw4r/math.h>
10
11/// @file
12
13/// @ingroup bases
14
15class NMSndObjectBase : public nw4r::snd::SoundActor {
16public:
17 enum OBJ_TYPE {
18 OBJ_TYPE_0 = 0
19 };
20
21 NMSndObjectBase(OBJ_TYPE, nw4r::snd::SoundArchivePlayer &);
22 virtual ~NMSndObjectBase();
23 virtual u8 vf1C(ulong, int);
24
25 bool sendRemote(nw4r::snd::SoundHandle *p, unsigned long p1, unsigned long p2);
26
27 u32 getTotal() const { return mTotalCount; }
28
29 u32 mTotalCount;
30 u32 m_58;
31 Snd2DCalc *mpSnd2dCalc;
32 OBJ_TYPE mObjType;
33};
34
35template<int T>
36class NMSndObject : public NMSndObjectBase {
37public:
38 class SoundHandlePrm : public nw4r::snd::SoundHandle {
39 public:
40 SoundHandlePrm() : m_04(1.0f) {}
41
42 float m_04;
43 };
44
45 NMSndObject() :
46 NMSndObjectBase(NMSndObjectBase::OBJ_TYPE_0, SndAudioMgr::sInstance->mArcPlayer),
47 m_64(1.0f), m_68(0), m_6c(1.0f), m_70(0.0f)
48 {
49 SetPlayableSoundCount(0, T);
50 mTotalCount = T + 2;
51 m_58 = 1;
52 }
53
54 void processParams() {
55 for (int idx = 0; idx < mTotalCount; idx++) {
56 if (!mParams[idx].IsAttachedSound()) {
57 continue;
58 }
59 u32 flag = SndAudioMgr::sInstance->get3DCtrlFlag(mParams[idx].GetId());
60 if (~flag & 1) {
61 mParams[idx].SetVolume(m_64, 0);
62 } else if (
63 SndSceneMgr::sInstance->m_14 == 3 ||
64 (SndSceneMgr::sInstance->m_14 == 2 && SndSceneMgr::sInstance->m_10 == 3)
65 ) {
66 mParams[idx].SetVolume(m_64, 0);
67 }
68 if (~flag & 8) {
69 nw4r::snd::SoundArchive::SoundInfo info;
70 SndAudioMgr::sInstance->mpSndArc->ReadSoundInfo(mParams[idx].GetId(), &info);
71 if (m_68 < 0) {
72 mParams[idx].SetPlayerPriority(info.playerPriority + m_68);
73 } else {
74 mParams[idx].SetPlayerPriority(info.playerPriority);
75 }
76 }
77 if (~flag & 2) {
78 mParams[idx].SetPan(m_70);
79 }
80 }
81 }
82
83 void calc() {
84 for (int i = 0; i < T; i++) {
85 if (GetPlayingSoundCount(i) > 0) {
86 mpSnd2dCalc->fn_8019ee20(m_64, mPos, 0);
87 processParams();
88 break;
89 }
90 }
91 }
92
93 virtual void calc(const nw4r::math::VEC2 &pos) {
94 mPos = pos;
95 calc();
96 }
97
98 SoundHandlePrm *findHandle(int id) {
99 for (int i = 0; i < mTotalCount; i++) {
100 if (mParams[i].IsAttachedSound()) {
101 if (mParams[i].GetId() == id) {
102 return &mParams[i];
103 }
104 }
105 }
106 return nullptr;
107 }
108
109 SoundHandlePrm *getFreeHandle() {
110 for (int i = 0; i < mTotalCount; i++) {
111 if (!mParams[i].IsAttachedSound()) {
112 mParams[i].m_04 = 1.0f;
113 return &mParams[i];
114 }
115 }
116 return nullptr;
117 }
118
119 virtual SoundHandlePrm *startSound(unsigned long p1, unsigned long p2) {
120 SoundHandlePrm *p = getFreeHandle();
121 if (p != nullptr) {
122 detail_StartSound(p, p1, 0);
123 if (!p->IsAttachedSound()) {
124 return nullptr;
125 }
126 sendRemote(p, p1, p2);
127 return p;
128 }
129 return nullptr;
130 }
131 virtual SoundHandlePrm *holdSound(unsigned long p1, unsigned long p2) {
132 SoundHandlePrm *p = findHandle(p1);
133 if (p == nullptr) {
134 p = getFreeHandle();
135 }
136 if (p != nullptr) {
137 detail_HoldSound(p, p1, 0);
138 if (!p->IsAttachedSound()) {
139 return nullptr;
140 }
141 sendRemote(p, p1, p2);
142 return p;
143 }
144 return nullptr;
145 }
146
147 virtual SoundHandlePrm *prepareSound(unsigned long p1, unsigned long p2) {
148 SoundHandlePrm *p = getFreeHandle();
149 if (p != nullptr) {
150 detail_PrepareSound(p, p1, 0);
151 if (!p->IsAttachedSound()) {
152 return nullptr;
153 }
154 sendRemote(p, p1, p2);
155 return p;
156 }
157 return nullptr;
158 }
159
160 virtual SoundHandlePrm *startSound(unsigned long p1, short p2, unsigned long p3) {
161 SoundHandlePrm *p = getFreeHandle();
162 if (p != nullptr) {
163 detail_StartSound(p, p1, 0);
164 if (!p->IsAttachedSound()) {
165 return nullptr;
166 }
167 sendRemote(p, p1, p3);
168 if (SndAudioMgr::sInstance->mpSndArc->GetSoundType(p1) == 1) {
169 nw4r::snd::SeqSoundHandle handle(p);
170 handle.WriteVariable(0, p2);
171 }
172 return p;
173 }
174 return nullptr;
175 }
176 virtual SoundHandlePrm *holdSound(unsigned long p1, short p2, unsigned long p3) {
177 SoundHandlePrm *p = findHandle(p1);
178 if (p == nullptr) {
179 p = getFreeHandle();
180 }
181 if (p != nullptr) {
182 detail_HoldSound(p, p1, 0);
183 if (!p->IsAttachedSound()) {
184 return nullptr;
185 }
186 sendRemote(p, p1, p3);
187 if (SndAudioMgr::sInstance->mpSndArc->GetSoundType(p1) == 1) {
188 nw4r::snd::SeqSoundHandle handle(p);
189 handle.WriteVariable(0, p2);
190 }
191 return p;
192 }
193 return nullptr;
194 }
195
196 virtual SoundHandlePrm *startSound(unsigned long p1, const nw4r::math::VEC2 &p2, unsigned long p3) {
197 SoundHandlePrm *p = getFreeHandle();
198 if (p != nullptr) {
199 detail_StartSound(p, p1, 0);
200 if (!p->IsAttachedSound()) {
201 return nullptr;
202 }
203 SndAudioMgr::sInstance->setSoundPosition(p, p2);
204 sendRemote(p, p1, p3);
205 return p;
206 }
207 return nullptr;
208 }
209 virtual SoundHandlePrm *holdSound(unsigned long p1, const nw4r::math::VEC2 &p2, unsigned long p3) {
210 SoundHandlePrm *p = findHandle(p1);
211 if (p == nullptr) {
212 p = getFreeHandle();
213 }
214 if (p != nullptr) {
215 detail_HoldSound(p, p1, 0);
216 if (!p->IsAttachedSound()) {
217 return nullptr;
218 }
219 SndAudioMgr::sInstance->setSoundPosition(p, p2);
220 sendRemote(p, p1, p3);
221 return p;
222 }
223 return nullptr;
224 }
225
226 float m_64;
227 int m_68;
228 float m_6c;
229 float m_70;
230 SoundHandlePrm mParams[T + 2];
231 nw4r::math::VEC2 mPos;
232};
233
234template<int T>
235class NMSndObjectCmn : public NMSndObjectBase {
236public:
237 class SoundHandlePrm;
238
239 NMSndObjectCmn() {}
240 virtual ~NMSndObjectCmn() {}
241
242 virtual void calc(const nw4r::math::VEC2 &pos);
243 virtual nw4r::snd::SoundHandle *startSound(unsigned long p1, const nw4r::math::VEC2 &p2, unsigned long p3);
244 virtual nw4r::snd::SoundHandle *startSound(unsigned long p1, const nw4r::math::VEC2 &p2, short p3, unsigned long p4);
245 virtual nw4r::snd::SoundHandle *holdSound(unsigned long p1, const nw4r::math::VEC2 &p2, unsigned long p3);
246 virtual nw4r::snd::SoundHandle *holdSound(unsigned long p1, int p2, const nw4r::math::VEC2 &p3, unsigned long p4);
247 virtual nw4r::snd::SoundHandle *holdSound(unsigned long p1, int p2, const nw4r::math::VEC2 &p3, short p4, unsigned long p5);
248};
249
250class SndObjctPly : public NMSndObject<4> {
251public:
252 void calculate(const nw4r::math::VEC2 &pos) {
253 NMSndObject<4>::calc(pos);
254 }
255
256 SoundHandlePrm *startSound(ulong p1, ulong p2) override;
257 SoundHandlePrm *holdSound(ulong p1, ulong p2) override;
258 SoundHandlePrm *startSound(ulong p1, short p2, ulong p3) override;
259 SoundHandlePrm *holdSound(ulong p1, short p2, ulong p3) override;
260 SoundHandlePrm *startSound(ulong p1, const nw4r::math::VEC2 &p2, ulong p3) override;
261 SoundHandlePrm *holdSound(ulong p1, const nw4r::math::VEC2 &p2, ulong p3) override;
262
263 void stopPlyJumpSound();
264 void startFootSound(ulong, float, ulong);
265 void fn_8019AAB0(ulong, int);
266 void fn_8019ABB0(ulong, int);
267};
268
269class SndObjctEmy : public NMSndObject<4> {
270public:
271 SoundHandlePrm *startSound(ulong p1, ulong p2) override;
272 SoundHandlePrm *holdSound(ulong p1, ulong p2) override;
273 SoundHandlePrm *startSound(ulong p1, short p2, ulong p3) override;
274 SoundHandlePrm *holdSound(ulong p1, short p3, ulong p4) override;
275 SoundHandlePrm *startSound(ulong p1, const nw4r::math::VEC2 &p2, ulong p3) override;
276 SoundHandlePrm *holdSound(ulong p1, const nw4r::math::VEC2 &p3, ulong p4) override;
277};
278
279class SndObjctCmnEmy : public NMSndObjectCmn<12> {
280public:
281 virtual nw4r::snd::SoundHandle *startSound(ulong p1, const nw4r::math::VEC2 &p2, ulong p3);
282 virtual nw4r::snd::SoundHandle *startSound(ulong p1, const nw4r::math::VEC2 &p2, short p3, ulong p4);
283 virtual nw4r::snd::SoundHandle *holdSound(ulong p1, int p2, const nw4r::math::VEC2 &p3, ulong p4);
284 virtual nw4r::snd::SoundHandle *holdSound(ulong p1, int p2, const nw4r::math::VEC2 &p3, short p4, ulong p5);
285 virtual nw4r::snd::SoundHandle *stopSound(ulong p1);
286};
287
288class SndObjctCmnMap : public NMSndObjectCmn<12> {
289public:
290 virtual nw4r::snd::SoundHandle *startSound(ulong p1, const nw4r::math::VEC2 &p2, ulong p3);
291 virtual nw4r::snd::SoundHandle *startSound(ulong p1, const nw4r::math::VEC2 &p2, short p3, ulong p4);
292 virtual nw4r::snd::SoundHandle *holdSound(ulong p1, int p2, const nw4r::math::VEC2 &p3, ulong p4);
293 virtual nw4r::snd::SoundHandle *holdSound(ulong p1, int p2, const nw4r::math::VEC2 &p3, short p4, ulong p5);
294 virtual nw4r::snd::SoundHandle *stopSound(ulong p1);
295};
296
297namespace dAudio {
298 void init(EGG::Heap *heap);
299 void execute();
300 void requestStartScene(ProfileName sceneProf); ///< Sets up game audio for the given scene.
301 void createSndObjctCmn();
302 void deleteSndObjctCmn();
303 void setNextScene(ProfileName prof, unsigned long bgmIndex);
304 void pauseOffGameWithReset(); ///< @unofficial
305 void boot();
306 void loadSceneSnd();
307 bool isLoadedSceneSnd();
308 void FUN_8006a6a0(bool); ///< @unofficial
309 void setMainBgmNo(int);
310 void setBgmMode(int);
311 void updateBgmInfo();
312 bool isBgmAccentSign(u8);
313 void pauseOffMove(int);
314 void pauseMove(int);
315
316 int getRemotePlayer(int);
317 mVec2_c cvtSndObjctPos(const mVec2_c &);
318 mVec2_c cvtSndObjctPos(const mVec3_c &);
319
320 class SndObjctPlyBase_c : public SndObjctPly {
321 public:
322 SndObjctPlyBase_c() {
323 m_00 = 5;
324 m_04 = 6;
325 m_08 = 0;
326 }
327
328 u32 m_00;
329 u32 m_04;
330 u8 m_08;
331 };
332
333 class SndObjctPly_c : public SndObjctPlyBase_c {
334 public:
335 virtual SoundHandlePrm *startSound(ulong p1, ulong p2) {
336 return SndObjctPly::startSound(p1, p2);
337 }
338 virtual SoundHandlePrm *startSound(ulong p1, short p2, ulong p3) {
339 return SndObjctPly::startSound(p1, p2, p3);
340 }
341 virtual SoundHandlePrm *holdSound(ulong p1, ulong p2) {
342 return SndObjctPly::holdSound(p1, p2);
343 }
344 virtual SoundHandlePrm *holdSound(ulong p1, short p2, ulong p3) {
345 return SndObjctPly::holdSound(p1, p2, p3);
346 }
347 };
348
350 public:
351 nw4r::snd::SoundHandle *startSound(unsigned long soundID, const nw4r::math::VEC2 &pos, int remPlayer) {
352 return SndObjctCmnEmy::startSound(soundID, pos, remPlayer);
353 }
354 nw4r::snd::SoundHandle *startSound(unsigned long soundID, const mVec3_c &pos, int remPlayer) {
355 return SndObjctCmnEmy::startSound(soundID, dAudio::cvtSndObjctPos(pos), remPlayer);
356 }
357 };
358
359 class SndObjctEmy_c : public SndObjctEmy {
360 public:
361 virtual SoundHandlePrm *startSound(ulong p1, ulong p2) {
362 return SndObjctEmy::startSound(p1, p2);
363 }
364 virtual SoundHandlePrm *startSound(ulong p1, short p2, ulong p3) {
365 return SndObjctEmy::startSound(p1, p2, p3);
366 }
367 virtual SoundHandlePrm *holdSound(ulong p1, ulong p2) {
368 return SndObjctEmy::holdSound(p1, p2);
369 }
370 virtual SoundHandlePrm *holdSound(ulong p1, short p2, ulong p3) {
371 return SndObjctEmy::holdSound(p1, p2, p3);
372 }
373 };
374
376 public:
377 void startSound(unsigned long soundID, const nw4r::math::VEC2 &pos, int remPlayer) {
378 SndObjctCmnMap::startSound(soundID, pos, remPlayer);
379 }
380 void startSound(unsigned long soundID, const mVec3_c &pos, int remPlayer) {
381 SndObjctCmnMap::startSound(soundID, dAudio::cvtSndObjctPos(pos), remPlayer);
382 }
383 void holdSound(unsigned long soundID, int id, const nw4r::math::VEC2 &pos, int remPlayer) {
384 SndObjctCmnMap::holdSound(soundID, id, pos, remPlayer);
385 }
386 void holdSound(unsigned long soundID, int id, const mVec3_c &pos, int remPlayer) {
387 SndObjctCmnMap::holdSound(soundID, id, dAudio::cvtSndObjctPos(pos), remPlayer);
388 }
389 };
390
391 extern SndObjctCmnEmy_c *g_pSndObjEmy;
392 extern SndObjctCmnMap_c *g_pSndObjMap;
393
394 /// @unofficial
395 class SoundEffectID_t {
396 public:
397 SoundEffectID_t(u32 soundID) : mID(soundID) {}
398
399 operator u32() const {
400 return mID;
401 }
402
403 private:
404 template<class T, class TVec>
405 void playObjSound(T *obj, const TVec &pos, int playerNo) const {
406 obj->startSound(mID, dAudio::cvtSndObjctPos(pos), playerNo);
407 }
408
409 template<class T, class TVec>
410 void holdObjSound(T *obj, int id, const TVec &pos, int playerNo) const {
411 obj->holdSound(mID, id, dAudio::cvtSndObjctPos(pos), playerNo);
412 }
413
414 public:
415 template<class TVec>
416 void playEmySound(const TVec &pos, int playerNo) const {
417 playObjSound(dAudio::g_pSndObjEmy, pos, playerNo);
418 }
419
420 template<class TVec>
421 void playMapSound(const TVec &pos, int playerNo) const {
422 playObjSound(dAudio::g_pSndObjMap, pos, playerNo);
423 }
424
425 template<class TVec>
426 void holdMapSound(int id, const TVec &pos, int playerNo) const {
427 holdObjSound(dAudio::g_pSndObjMap, id, pos, playerNo);
428 }
429
430 private:
431 u32 mID;
432 };
433};
A two-dimensional floating point vector.
Definition m_vec.hpp:26
A three-dimensional floating point vector.
Definition m_vec.hpp:122
void requestStartScene(ProfileName sceneProf)
Sets up game audio for the given scene.
void FUN_8006a6a0(bool)
void pauseOffGameWithReset()
u16 ProfileName
The name of a profile. Value is a fProf::PROFILE_NAME_e.
Definition f_profile.hpp:32