NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
snd_SoundArchivePlayer.h
1#ifndef NW4R_SND_SOUND_ARCHIVE_PLAYER_H
2#define NW4R_SND_SOUND_ARCHIVE_PLAYER_H
3
4/*******************************************************************************
5 * headers
6 */
7
8#include <types.h>
9
10// WARNING: DO NOT REORDER these #include directives, data pooling depends on it
11
12// clang-format off
13#include "nw4r/snd/snd_BasicSound.h"
14#include "nw4r/snd/snd_DisposeCallbackManager.h" // detail::DisposeCallback
15#include "nw4r/snd/snd_MmlParser.h"
16#include "nw4r/snd/snd_NoteOnCallback.h" // This needs to be
17#include "nw4r/snd/snd_MmlSeqTrackAllocator.h" // before this
18#include "nw4r/snd/snd_SeqPlayer.h"
19#include "nw4r/snd/snd_SeqSound.h"
20#include "nw4r/snd/snd_SoundArchive.h"
21#include "nw4r/snd/snd_SoundInstanceManager.h"
22#include "nw4r/snd/snd_SoundMemoryAllocatable.h"
23#include "nw4r/snd/snd_WsdPlayer.h" // and this needs to be
24#include "nw4r/snd/snd_SoundStartable.h" // before this
25#include "nw4r/snd/snd_StrmChannel.h" // detail::StrmBufferPool
26#include "nw4r/snd/snd_StrmSound.h"
27#include "nw4r/snd/snd_Util.h" // Util::Table
28#include "nw4r/snd/snd_WaveFile.h"
29#include "nw4r/snd/snd_WaveSound.h"
30// clang-format on
31
32#include <nw4r/NW4RAssert.hpp>
33
34/*******************************************************************************
35 * types
36 */
37
38// forward declarations
39namespace nw4r { namespace snd { namespace detail { class PlayerHeap; }}}
40namespace nw4r { namespace snd { namespace detail { class SeqTrackAllocator; }}}
41namespace nw4r { namespace snd { class SoundActor; }}
42namespace nw4r { namespace snd { class SoundHandle; }}
43namespace nw4r { namespace snd { class SoundPlayer; }}
44
45/*******************************************************************************
46 * classes and functions
47 */
48
49namespace nw4r { namespace snd
50{
51 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x28a19
53 {
54 // methods
55 public:
56 // virtual function ordering
57 // vtable SoundArchivePlayer_FileManager
58 virtual void const *GetFileAddress(ulong) = 0;
59 virtual void const *GetFileWaveDataAddress(ulong) = 0;
60
61 // members
62 private:
63 /* vtable */ // size 0x04, offset 0x00
64 }; // size 0x04
65
66 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x31598
67 class SoundArchivePlayer : public detail::DisposeCallback,
68 public SoundStartable
69 {
70 // nested types
71 private:
72 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2e0ad7
74 {
75 void const *address; // size 0x04, offset 0x00
76 void const *waveDataAddress; // size 0x04, offset 0x04
77 }; // size 0x08
78
79 typedef detail::Util::Table<GroupAddress> GroupAddressTable;
80
81 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2e0bdd
83 {
84 void const *address; // size 0x04, offset 0x00
85 void const *waveDataAddress; // size 0x04, offset 0x04
86 }; // size 0x08
87
88 typedef detail::Util::Table<FileAddress> FileAddressTable;
89
90 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2e4f9
91 class SeqNoteOnCallback : public detail::NoteOnCallback
92 {
93 // methods
94 public:
95 // cdtors
96 SeqNoteOnCallback(SoundArchivePlayer const &player) :
97 mSoundArchivePlayer(player)
98 {
99 }
100
101 virtual ~SeqNoteOnCallback() {}
102
103 // virtual function ordering
104 // vtable NoteOnCallback
105 virtual detail::Channel *NoteOn(
106 detail::SeqPlayer *seqPlayer, int bankNo,
107 detail::NoteOnInfo const &noteOnInfo);
108
109 // members
110 private:
111 /* base NoteOnCallback */ // size 0x04, offset 0x00
112 SoundArchivePlayer const &mSoundArchivePlayer; // size 0x04, offset 0x04
113 }; // size 0x08
114
115 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2e8e1
116 class WsdCallback : public detail::WsdPlayer::WsdCallback
117 {
118 // methods
119 public:
120 // cdtors
121 WsdCallback(SoundArchivePlayer const &player) :
122 mSoundArchivePlayer(player)
123 {
124 }
125 virtual ~WsdCallback() {}
126
127 // virtual function ordering
128 // vtable detail::WsdPlayer::WsdCallback
129 virtual bool GetWaveSoundData(detail::WaveSoundInfo *info,
131 detail::WaveInfo *waveData,
132 void const *waveSoundData, int index,
133 int noteIndex,
134 ulong userData) const;
135
136 // members
137 private:
138 /* base detail::WsdPlayer::WsdCallback */ // size 0x04, offset 0x00
139 SoundArchivePlayer const &mSoundArchivePlayer; // size 0x04, offset 0x04
140 }; // size 0x08
141
142 // methods
143 public:
144 // cdtors
145 SoundArchivePlayer();
146 virtual ~SoundArchivePlayer();
147
148 // virtual function ordering
149 // vtable detail::DisposeCallback
150 virtual void InvalidateData(void const *start, void const *end);
151 virtual void InvalidateWaveData(void const *start, void const *end);
152
153 // vtable SoundStartable
154 // WARNING: DO NOT REORDER these declarations
155 virtual ulong detail_ConvertLabelStringToSoundId(char const *label)
156 {
157 // specifically not the header variant
158 NW4RAssertPointerNonnull_Line(194, mSoundArchive);
159
160 return mSoundArchive->ConvertLabelStringToSoundId(label);
161 }
162 virtual StartResult detail_SetupSound(SoundHandle *handle, ulong soundId,
163 bool holdFlag,
164 StartInfo const *startInfo);
165
166 // methods
167 bool Setup(SoundArchive const *arc, void *buffer, ulong size,
168 void *strmBuffer, ulong strmBufferSize);
169 void Shutdown();
170
171 bool LoadGroup(ulong id, SoundMemoryAllocatable *pAllocatable, ulong blockSize);
172 bool LoadGroup(const char *pLabel, SoundMemoryAllocatable *pAllocatable, ulong blockSize);
173
174 bool LoadGroup(int id, SoundMemoryAllocatable *pAllocatable, ulong blockSize) {
175 return LoadGroup(static_cast<ulong>(id), pAllocatable, blockSize);
176 }
177 bool LoadGroup(unsigned int id, SoundMemoryAllocatable *pAllocatable, ulong blockSize) {
178 return LoadGroup(static_cast<ulong>(id), pAllocatable, blockSize);
179 }
180
181 bool IsLoadedGroup(ulong groupId) const;
182
183 SoundArchive const &GetSoundArchive() const;
184 ulong GetSoundPlayerCount() const { return mSoundPlayerCount; }
185 SoundPlayer &GetSoundPlayer(ulong playerId);
186
187 bool IsAvailable() const;
188 ulong GetRequiredMemSize(SoundArchive const *arc);
189 ulong GetRequiredStrmBufferSize(SoundArchive const *arc);
190 void const *GetGroupAddress(ulong groupId) const;
191 void SetGroupAddress(ulong id, const void* pAddr);
192 void const *GetGroupWaveDataAddress(ulong groupId) const;
193 void SetGroupWaveDataAddress(ulong id, const void* pAddr);
194 void const *GetFileAddress(ulong fileId) const;
195 void const *GetFileWaveDataAddress(ulong fileId) const;
196 void const *detail_GetFileAddress(ulong fileId) const;
197 void const *detail_GetFileWaveDataAddress(ulong fileId) const;
198
199 bool SetupMram(SoundArchive const *arc, void *buffer, ulong size);
200 bool SetupStrmBuffer(SoundArchive const *arc, void *buffer, ulong size);
201 bool SetupSoundPlayer(SoundArchive const *arc, void **buffer,
202 void *endp);
203
204 bool SetupSeqSound(SoundArchive const *arc, int numSounds,
205 void **buffer, void *endp);
206 bool SetupWaveSound(SoundArchive const *arc, int numSounds,
207 void **buffer, void *endp);
208 bool SetupStrmSound(SoundArchive const *arc, int numSounds,
209 void **buffer, void *endp);
210 bool SetupSeqTrack(SoundArchive const *arc, int numTracks,
211 void **buffer, void *endp);
212
213 bool CreateGroupAddressTable(SoundArchive const *arc, void **buffer,
214 void *endp);
215 bool CreateFileAddressTable(SoundArchive const *arc, void **buffer,
216 void *endp);
217
218 detail::PlayerHeap *CreatePlayerHeap(void **buffer, void *endp,
219 ulong heapSize);
220
221 void Update();
222 void UpdateCommonSoundParam(detail::BasicSound *sound,
223 SoundArchive::SoundInfo const *commonInfo);
224
225 SoundStartable::StartResult detail_SetupSoundImpl(
226 SoundHandle *handle, ulong soundId,
227 detail::BasicSound::AmbientInfo *ambientArgInfo, SoundActor *actor,
228 bool holdFlag, SoundStartable::StartInfo const *startInfo);
229
230 private:
231 template <typename Sound>
232 Sound *AllocSound(
233 detail::SoundInstanceManager<Sound> *manager, ulong soundId,
234 int priority, int ambientPriority,
235 detail::BasicSound::AmbientInfo *ambientArgInfo);
236
237 SoundStartable::StartResult PrepareSeqImpl(
238 detail::SeqSound *sound, SoundArchive::SoundInfo const *commonInfo,
239 SoundArchive::SeqSoundInfo const *info,
240 SoundStartable::StartInfo::StartOffsetType startOffsetType,
241 int startOffset, void const *externalSeqDataAddress,
242 char const *externalSeqStartLabel);
243 SoundStartable::StartResult PrepareStrmImpl(
244 detail::StrmSound *sound, SoundArchive::SoundInfo const *commonInfo,
245 SoundArchive::StrmSoundInfo const *info,
246 SoundStartable::StartInfo::StartOffsetType startOffsetType,
247 int startOffset);
248 SoundStartable::StartResult PrepareWaveSoundImpl(
249 detail::WaveSound *sound, SoundArchive::SoundInfo const *commonInfo,
250 SoundArchive::WaveSoundInfo const *info,
251 SoundStartable::StartInfo::StartOffsetType startOffsetType,
252 int startOffset);
253
254 // static members
255 public:
256 static int const DEFAULT_STREAM_BLOCK_COUNT;
257
258 // members
259 private:
260 /* base detail::DisposeCallback */ // size 0x0c, offset 0x00
261 /* base SoundStartable */ // size 0x04, offset 0x0c
262 SoundArchive const *mSoundArchive; // size 0x04, offset 0x10
263 GroupAddressTable *mGroupTable; // size 0x04, offset 0x14
264 FileAddressTable *mFileTable; // size 0x04, offset 0x18
265 SoundArchivePlayer_FileManager *mFileManager; // size 0x04, offset 0x1c
266 SeqNoteOnCallback mSeqCallback; // size 0x08, offset 0x20
267 WsdCallback mWsdCallback; // size 0x08, offset 0x28
268 detail::SeqTrackAllocator *mSeqTrackAllocator; // size 0x04, offset 0x30
269 detail::SeqPlayer::SeqUserprocCallback *mSeqUserprocCallback; // size 0x04, offset 0x34
270 void *mSeqUserprocCallbackArg; // size 0x04, offset 0x38
271 ulong mSoundPlayerCount; // size 0x04, offset 0x3c
272 SoundPlayer *mSoundPlayers; // size 0x04, offset 0x40
273 detail::SoundInstanceManager<detail::SeqSound> mSeqSoundInstanceManager; // size 0x28, offset 0x44
274 detail::SoundInstanceManager<detail::StrmSound> mStrmSoundInstanceManager; // size 0x28, offset 0x6c
275 detail::SoundInstanceManager<detail::WaveSound> mWaveSoundInstanceManager; // size 0x28, offset 0x94
276 detail::MmlSeqTrackAllocator mMmlSeqTrackAllocator; // size 0x0c, offset 0xbc
277 detail::StrmBufferPool mStrmBufferPool; // size 0x18, offset 0xc8
278 detail::MmlParser mMmlParser; // size 0x04, offset 0xe0
279 void *mSetupBufferAddress; // size 0x04, offset 0xe4
280 ulong mSetupBufferSize; // size 0x04, offset 0xe8
281 }; // size 0xec
282}} // namespace nw4r::snd
283
284#endif // NW4R_SND_SOUND_ARCHIVE_PLAYER_H