NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
snd_WsdFile.h
1#ifndef NW4R_SND_WSD_FILE_H
2#define NW4R_SND_WSD_FILE_H
3
4/*******************************************************************************
5 * headers
6 */
7
8#include <types.h>
9
10#include "nw4r/snd/snd_Util.h"
11
12#include "nw4r/ut/ut_binaryFileFormat.h"
13
14/*******************************************************************************
15 * types
16 */
17
18// forward declarations
19namespace nw4r { namespace snd { namespace detail { struct WaveInfo; }}}
20namespace nw4r { namespace snd { namespace detail { struct WaveSoundInfo; }}}
21namespace nw4r { namespace snd { namespace detail { struct WaveSoundNoteInfo; }}}
22
23namespace nw4r { namespace snd { namespace detail
24{
25 struct WsdFile
26 {
27 /* Header */
28
29 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2e4ce7
30 struct Header
31 {
32 ut::BinaryFileHeader fileHeader; // size 0x10, offset 0x00
33 ulong dataBlockOffset; // size 0x04, offset 0x10
34 ulong dataBlockSize; // size 0x04, offset 0x14
35 ulong waveBlockOffset; // size 0x04, offset 0x18
36 ulong waveBlockSize; // size 0x04, offset 0x1c
37 }; // size 0x20
38
39 /* DataBlock */
40
41 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x30abf7
42 struct WsdInfo
43 {
44 f32 pitch; // size 0x04, offset 0x00
45 u8 pan; // size 0x01, offset 0x04
46 u8 surroundPan; // size 0x01, offset 0x05
47 u8 fxSendA; // size 0x01, offset 0x06
48 u8 fxSendB; // size 0x01, offset 0x07
49 u8 fxSendC; // size 0x01, offset 0x08
50 u8 mainSend; // size 0x01, offset 0x09
51 u8 padding[2];
52 // TODO: template parameters
53 Util::DataRef<void> graphEnvTablevRef; // size 0x08, offset 0x0c
54 Util::DataRef<void> randomizerTableRef; // size 0x08, offset 0x14
55 ulong reserved;
56 }; // size 0x20
57
58 struct TrackInfo;
59
60 typedef Util::Table<Util::DataRef<TrackInfo> > TrackInfoTable;
61
62 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x30af52
63 struct NoteInfo
64 {
65 s32 waveIndex; // size 0x04, offset 0x00
66 u8 attack; // size 0x01, offset 0x04
67 u8 decay; // size 0x01, offset 0x05
68 u8 sustain; // size 0x01, offset 0x06
69 u8 release; // size 0x01, offset 0x07
70 u8 hold; // size 0x01, offset 0x08
71 u8 padding[3];
72 u8 originalKey; // size 0x01, offset 0x0c
73 u8 volume; // size 0x01, offset 0x0d
74 u8 pan; // size 0x01, offset 0x0e
75 u8 surroundPan; // size 0x01, offset 0x0f
76 f32 pitch; // size 0x04, offset 0x10
77 // TODO: template parameters
78 Util::DataRef<void> lfoTableRef; // size 0x08, offset 0x14
79 Util::DataRef<void> graphEnvTablevRef; // size 0x08, offset 0x1c
80 Util::DataRef<void> randomizerTableRef; // size 0x08, offset 0x24
81 ulong reserved;
82 }; // size 0x30
83
84 typedef Util::Table<Util::DataRef<NoteInfo> > NoteInfoTable;
85
86 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x30ab32
87 struct Wsd
88 {
89 Util::DataRef<WsdInfo> refWsdInfo; // size 0x08, offset 0x00
90 Util::DataRef<TrackInfoTable> refTrackTable; // size 0x08, offset 0x08
91 Util::DataRef<NoteInfoTable> refNoteTable; // size 0x08, offset 0x10
92 }; // size 0x18
93
94 static ulong const SIGNATURE_DATA_BLOCK =
95 NW4R_FOUR_BYTE('D', 'A', 'T', 'A');
96
97 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2e4ec8
98 struct DataBlock
99 {
100 ut::BinaryBlockHeader blockHeader; // size 0x08, offset 0x00
101 ulong wsdCount; // size 0x04, offset 0x08
102 Util::DataRef<Wsd> refWsd[]; // flexible, offset 0x0c (unit size 0x08)
103 }; // size 0x0c
104
105 /* WaveBlock */
106
107 static ulong const SIGNATURE_WAVE_BLOCK =
108 NW4R_FOUR_BYTE('W', 'A', 'V', 'E');
109
110 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2e4f87
112 {
113 ut::BinaryBlockHeader blockHeader; // size 0x04, offset 0x00
114 ulong waveCount; // size 0x04, offset 0x08
115 ulong offsetTable[]; // flexible, offset 0x0c (unit size 0x04)
116 }; // size 0x0c
117
118 /* WaveBlockOld */
119
120 // FILE_VERSION <= NW4R_FILE_VERSION(1, 0)
121 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x30b523
123 {
124 ut::BinaryBlockHeader blockHeader; // size 0x08, offset 0x00
125 ulong offsetTable[]; // flexible, offset 0x08 (unit size 0x04)
126 }; // size 0x08
127
128 /* WsdFile */
129
130 static ulong const SIGNATURE_FILE =
131 NW4R_FOUR_BYTE('R', 'W', 'S', 'D');
132 static int const FILE_VERSION = NW4R_FILE_VERSION(1, 3);
133 }; // "namespace" WsdFile
134}}} // namespace nw4r::snd::detail
135
136/*******************************************************************************
137 * classes and functions
138 */
139
140namespace nw4r { namespace snd { namespace detail
141{
142 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2e502c
143 class WsdFileReader
144 {
145 // methods
146 public:
147 // cdtors
148 WsdFileReader(void const *wsdData);
149
150 // methods
151 bool ReadWaveInfo(int waveIndex, WaveInfo *waveData,
152 void const *waveDataAddress) const;
153 bool ReadWaveSoundInfo(WaveSoundInfo *info, int index) const;
154 bool ReadWaveSoundNoteInfo(WaveSoundNoteInfo *noteInfo, int index,
155 int noteIndex) const;
156
157 private:
158 bool IsValidFileHeader(void const *wsdData);
159
160 // static members
161 private:
162 static int const SUPPORTED_FILE_VERSION = NW4R_FILE_VERSION(1, 3);
163
164 // members
165 private:
166 WsdFile::Header const *mHeader; // size 0x04, offset 0x00
167 WsdFile::DataBlock const *mDataBlock; // size 0x04, offset 0x04
168 WsdFile::WaveBlock const *mWaveBlock; // size 0x04, offset 0x08
169 }; // size 0x0c
170}}} // namespace nw4r::snd::detail
171
172#endif // NW4R_SND_WSD_FILE_H