NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
snd_SoundArchiveFile.h
1#ifndef NW4R_SND_SOUND_ARCHIVE_FILE_H
2#define NW4R_SND_SOUND_ARCHIVE_FILE_H
3
4/*******************************************************************************
5 * headers
6 */
7
8#include <types.h>
9
10#include "nw4r/snd/snd_SoundArchive.h"
11#include "nw4r/snd/snd_Util.h"
12
13#include "nw4r/ut/ut_binaryFileFormat.h"
14#include "nw4r/ut/ut_algorithm.h"
15
16/*******************************************************************************
17 * types
18 */
19
20namespace nw4r { namespace snd { namespace detail
21{
23 {
24 /* Header */
25
26 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x240a6
27 struct Header
28 {
29 ut::BinaryFileHeader fileHeader; // size 0x10, offset 0x00
30 ulong symbolDataOffset; // size 0x04, offset 0x10
31 ulong symbolDataSize; // size 0x04, offset 0x14
32 ulong infoOffset; // size 0x04, offset 0x18
33 ulong infoSize; // size 0x04, offset 0x1c
34 ulong fileImageOffset; // size 0x04, offset 0x20
35 ulong fileImageSize; // size 0x04, offset 0x24
36 }; // size 0x28
37
38 static const int HEADER_AREA_SIZE = ROUND_UP(sizeof(Header), 32) + 40;
39
40 /* SymbolBlock */
41
42 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x24881
44 {
45 u16 flags; // size 0x02, offset 0x00
46 u16 bit; // size 0x02, offset 0x02
47 ulong leftIdx; // size 0x04, offset 0x04
48 ulong rightIdx; // size 0x04, offset 0x08
49 ulong strIdx; // size 0x04, offset 0x0c
50 ulong id; // size 0x04, offset 0x10
51 }; // size 0x14
52
53 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x24a2e
55 {
56 ulong rootIdx; // size 0x04, offset 0x00
57 Util::Table<StringTreeNode> nodeTable; // size 0x18, offset 0x04
58 }; // size 0x1c
59
60 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x24830
62 {
63 Util::Table<ulong> offsetTable; // size 0x08, offset 0x00
64 }; // size 0x08
65
67 {
68 ulong tableOffset; // size 0x04, offset 0x00
69 ulong soundTreeOffset; // size 0x04, offset 0x04
70 ulong playerTreeOffset; // size 0x04, offset 0x08
71 ulong groupTreeOffset; // size 0x04, offset 0x0c
72 ulong bankTreeOffset; // size 0x04, offset 0x10
73 }; // size 0x14
74
76 {
77 StringTable stringTable; // size 0x08
78 StringChunk stringChunk; // size 0x14
79 }; // size 0x14
80
81 static ulong const SIGNATURE_SYMB_BLOCK =
82 NW4R_FOUR_BYTE('S', 'Y', 'M', 'B');
83
85 {
86 ut::BinaryBlockHeader blockHeader; // size 0x08, offset 0x00
87 StringBlock stringBlock; // size 0x14, offset 0x08
88 }; // size 0x20
89
90 /* InfoBlock */
91
92 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2da8f9
93 enum SoundType
94 {
95 SOUND_TYPE_INVALID,
96
97 SOUND_TYPE_SEQ,
98 SOUND_TYPE_STRM,
99 SOUND_TYPE_WAVE,
100 };
101
103 ulong flags;
104 u8 decayCurve;
105 u8 decayRatio;
106 u8 field_0x06;
107 };
108
109 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x25183
111 {
112 ulong dataOffset; // size 0x04, offset 0x00
113 ulong bankId; // size 0x04, offset 0x04
114 ulong allocTrack; // size 0x04, offset 0x08
115 u8 channelPriority; // size 0x01, offset 0x0c
116 u8 releasePriorityFix; // size 0x01, offset 0x0d
117 u8 padding[2];
118 ulong reserved;
119 }; // size 0x14
120
121 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x25089
123 {
124 ulong startPosition; // size 0x04, offset 0x00
125 u16 allocChannelCount; // size 0x02, offset 0x04
126 u16 allocTrackFlag; // size 0x02, offset 0x06
127 ulong reserved;
128 }; // size 0x0c
129
130 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x24f62
132 {
133 s32 subNo; // size 0x04, offset 0x00
134 ulong allocTrack; // size 0x04, offset 0x04
135 u8 channelPriority; // size 0x01, offset 0x08
136 u8 releasePriorityFix; // size 0x01, offset 0x09
137 u8 padding[2];
138 ulong reserved;
139 }; // size 0x10
140
142 SoundInfoRef;
143
144 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2546c
146 {
147 ulong stringId; // size 0x04, offset 0x00
148 ulong fileId; // size 0x04, offset 0x04
149 ulong playerId; // size 0x04, offset 0x08
150 Util::DataRef<Sound3DParam> param3dRef; // size 0x08, offset 0x0c
151 u8 volume; // size 0x01, offset 0x14
152 u8 playerPriority; // size 0x01, offset 0x15
153 u8 soundType; // size 0x01, offset 0x16
154 u8 remoteFilter; // size 0x01, offset 0x17
155 SoundInfoRef soundInfoRef; // size 0x08, offset 0x18
156 ulong userParam[2]; // size 0x08, offset 0x20
157 u8 panMode; // size 0x01, offset 0x28
158 u8 panCurve; // size 0x01, offset 0x29
159 u8 actorPlayerId; // size 0x01, offset 0x2a
160 u8 reserved;
161 }; // size 0x2c
162
164 SoundCommonInfoTable;
165
166 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2db9b5
168 {
169 u16 seqSoundCount; // size 0x02, offset 0x00
170 u16 seqTrackCount; // size 0x02, offset 0x02
171 u16 strmSoundCount; // size 0x02, offset 0x04
172 u16 strmTrackCount; // size 0x02, offset 0x06
173 u16 strmChannelCount; // size 0x02, offset 0x08
174 u16 waveSoundCount; // size 0x02, offset 0x0a
175 u16 waveTrackCount; // size 0x02, offset 0x0c
176 u16 padding;
177 ulong reserved;
178 }; // size 0x14
179
180 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x24eab
181 struct BankInfo
182 {
183 ulong stringId; // size 0x04, offset 0x00
184 ulong fileId; // size 0x04, offset 0x04
185 ulong reserved;
186 }; // size 0x0c
187
188 typedef Util::Table<Util::DataRef<BankInfo> > BankInfoTable;
189
190 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x24d8f
192 {
193 ulong stringId; // size 0x04, offset 0x00
194 u8 playableSoundCount; // size 0x01, offset 0x04
195 u8 padding;
196 u16 padding2;
197 ulong heapSize; // size 0x04, offset 0x08
198 ulong reserved;
199 }; // size 0x10
200
201 typedef Util::Table<Util::DataRef<PlayerInfo> > PlayerInfoTable;
202
203 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2db6e3
205 {
206 ulong fileId; // size 0x04, offset 0x00
207 ulong offset; // size 0x04, offset 0x04
208 ulong size; // size 0x04, offset 0x08
209 ulong waveDataOffset; // size 0x04, offset 0x0c
210 ulong waveDataSize; // size 0x04, offset 0x10
211 ulong reserved;
212 }; // size 0x18
213
214 typedef Util::Table<Util::DataRef<GroupItemInfo> > GroupItemInfoTable;
215
216 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x24c1b
218 {
219 ulong stringId; // size 0x04, offset 0x00
220 s32 entryNum; // size 0x04, offset 0x04
221 Util::DataRef<char> extFilePathRef; // size 0x08, offset 0x08
222 ulong offset; // size 0x04, offset 0x10
223 ulong size; // size 0x04, offset 0x14
224 ulong waveDataOffset; // size 0x04, offset 0x18
225 ulong waveDataSize; // size 0x04, offset 0x1c
226 Util::DataRef<GroupItemInfoTable> itemTableRef; // size 0x08, offset 0x20
227 }; // size 0x28
228
229 typedef Util::Table<Util::DataRef<GroupInfo> > GroupInfoTable;
230
232
233 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2dc40b
234 struct FileInfo
235 {
236 ulong fileSize; // size 0x04, offset 0x00
237 ulong waveDataFileSize; // size 0x04, offset 0x04
238 s32 entryNum; // size 0x04, offset 0x08
239 Util::DataRef<char> extFilePathRef; // size 0x08, offset 0x0c
240 Util::DataRef<FilePosTable> filePosTableRef; // size 0x08, offset 0x14
241 }; // size 0x1c
242
243 typedef Util::Table<Util::DataRef<FileInfo> > FileInfoTable;
244
245 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x24665
246 struct Info
247 {
248 Util::DataRef<SoundCommonInfoTable> soundTableRef; // size 0x08, offset 0x00
249 Util::DataRef<BankInfoTable> bankTableRef; // size 0x08, offset 0x08
250 Util::DataRef<PlayerInfoTable> playerTableRef; // size 0x08, offset 0x10
251 Util::DataRef<FileInfoTable> fileTableRef; // size 0x08, offset 0x18
252 Util::DataRef<GroupInfoTable> groupTableRef; // size 0x08, offset 0x20
253 Util::DataRef<SoundArchivePlayerInfo> soundArchivePlayerInfoRef; // size 0x08, offset 0x28
254 }; // size 0x30
255
256 static ulong const SIGNATURE_INFO_BLOCK =
257 NW4R_FOUR_BYTE('I', 'N', 'F', 'O');
258
259 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2da76d
261 {
262 ut::BinaryBlockHeader blockHeader; // size 0x08, offset 0x00
263 Info info; // size 0x30, offset 0x08
264 }; // size 0x38
265
266 /* SoundArchiveFile */
267
268 static ulong const SIGNATURE_FILE =
269 NW4R_FOUR_BYTE('R', 'S', 'A', 'R');
270 static int const FILE_VERSION = NW4R_FILE_VERSION(1, 4);
271 }; // "namespace" SoundArchiveFile
272}}} // namespace nw4r::snd::detail
273
274/*******************************************************************************
275 * classes and functions
276 */
277
278namespace nw4r { namespace snd { namespace detail
279{
280 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x261f8
281 class SoundArchiveFileReader
282 {
283 // methods
284 public:
285 // cdtors
286 SoundArchiveFileReader();
287 ~SoundArchiveFileReader() {} // not default?
288
289 // methods
290 void Init(void const *soundArchiveData);
291
292 u16 GetVersion() const { return mHeader.fileHeader.version; }
293 ulong GetLabelStringChunkOffset() const
294 {
295 return mHeader.symbolDataOffset;
296 }
297 ulong GetLabelStringChunkSize() const { return mHeader.symbolDataSize; }
298 ulong GetInfoChunkOffset() const { return mHeader.infoOffset; }
299 ulong GetInfoChunkSize() const { return mHeader.infoSize; }
300
301 char const *GetString(ulong id) const;
302 SoundArchive::SoundType GetSoundType(ulong soundId) const;
303 ulong GetSoundStringId(ulong id) const;
304 ulong GetBankCount() const;
305 ulong GetPlayerCount() const;
306 ulong GetGroupCount() const;
307 ulong GetFileCount() const;
308 void const *GetPtrConst(void const *base, ulong offset) const
309 {
310 if (offset == 0)
311 return nullptr;
312
313 return ut::AddOffsetToPtr(base, offset);
314 }
315
316 void SetStringChunk(void const *stringChunk, ulong stringChunkSize);
317 void SetInfoChunk(void const *infoChunk, ulong infoChunkSize);
318
319 bool ReadSeqSoundInfo(ulong soundId,
320 SoundArchive::SeqSoundInfo *info) const;
321 bool ReadStrmSoundInfo(ulong soundId,
322 SoundArchive::StrmSoundInfo *info) const;
323 bool ReadWaveSoundInfo(ulong soundId,
324 SoundArchive::WaveSoundInfo *info) const;
325 bool ReadSoundArchivePlayerInfo(
327 bool ReadSoundInfo(ulong soundId, SoundArchive::SoundInfo *info) const;
328
329 bool ReadBankInfo(ulong bankId, SoundArchive::BankInfo *info) const;
330
331 bool ReadPlayerInfo(ulong playerId, SoundArchive::PlayerInfo *info) const;
332 bool ReadSound3DParam(ulong soundId, nw4r::snd::SoundArchive::Sound3DParam* info) const;
333
334 bool ReadGroupItemInfo(ulong groupId, ulong index,
335 SoundArchive::GroupItemInfo *info) const;
336 bool ReadGroupInfo(ulong groupId, SoundArchive::GroupInfo *info) const;
337
338 bool ReadFileInfo(ulong fileId, SoundArchive::FileInfo *info) const;
339 bool ReadFilePos(ulong fileId, ulong index,
340 SoundArchive::FilePos *filePos) const;
341
342 ulong ConvertLabelStringToId(SoundArchiveFile::StringTree const *tree,
343 char const *str) const;
344 const char* GetSoundLabelString(ulong id) const;
345 ulong GetSoundUserParam(ulong id) const;
346
347 ulong ConvertLabelStringToSoundId(const char* pLabel) const {
348 return ConvertLabelStringToId(mStringTreeSound, pLabel);
349 }
350 ulong ConvertLabelStringToPlayerId(const char* pLabel) const {
351 return ConvertLabelStringToId(mStringTreePlayer, pLabel);
352 }
353 ulong ConvertLabelStringToGroupId(const char* pLabel) const {
354 return ConvertLabelStringToId(mStringTreeGroup, pLabel);
355 }
356 ulong ConvertLabelStringToBankId(const char* pLabel) const {
357 return ConvertLabelStringToId(mStringTreeBank, pLabel);
358 }
359
360 private:
361 static bool IsValidFileHeader(void const *soundArchiveData);
362
363 SoundArchiveFile::SeqSoundInfo const *impl_GetSeqSoundInfo(
364 ulong soundId) const;
365 SoundArchiveFile::StrmSoundInfo const *impl_GetStrmSoundInfo(
366 ulong soundId) const;
367 SoundArchiveFile::WaveSoundInfo const *impl_GetWaveSoundInfo(
368 ulong soundId) const;
369 SoundArchiveFile::SoundCommonInfo const *impl_GetSoundInfo(
370 ulong soundId) const;
371
372 bool impl_GetSoundInfoOffset(
373 ulong soundId, SoundArchiveFile::SoundInfoRef *soundInfoRef) const;
374
375 SoundArchiveFile::BankInfo const *impl_GetBankInfo(ulong bankId) const;
376
377 SoundArchiveFile::PlayerInfo const *impl_GetPlayerInfo(
378 ulong playerId) const;
379
380 SoundArchiveFile::GroupInfo const *impl_GetGroupInfo(ulong groupId) const;
381
382 // static members
383 public:
384 static u16 const SUPPORTED_FILE_VERSION = NW4R_FILE_VERSION(1, 4);
385
386 // members
387 private:
388 SoundArchiveFile::Header mHeader; // size 0x28, offset 0x00
389 SoundArchiveFile::Info const *mInfo; // size 0x04, offset 0x28
390 void const *mStringBase; // size 0x04, offset 0x2c
391 SoundArchiveFile::StringTable const *mStringTable; // size 0x04, offset 0x30
392 SoundArchiveFile::StringTree const *mStringTreeSound; // size 0x04, offset 0x34
393 SoundArchiveFile::StringTree const *mStringTreePlayer; // size 0x04, offset 0x38
394 SoundArchiveFile::StringTree const *mStringTreeGroup; // size 0x04, offset 0x3c
395 SoundArchiveFile::StringTree const *mStringTreeBank; // size 0x04, offset 0x40
396 }; // size 0x44
397}}} // namespace nw4r::snd::detail
398
399#endif // NW4R_SND_SOUND_ARCHIVE_FILE_H