NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
snd_StrmFile.h
1#ifndef NW4R_SND_STRM_FILE_H
2#define NW4R_SND_STRM_FILE_H
3
4/*******************************************************************************
5 * headers
6 */
7
8#include <types.h>
9
10#include "nw4r/snd/snd_adpcm.h"
11#include "nw4r/snd/snd_global.h" // SampleFormat
12#include "nw4r/snd/snd_Util.h" // Util::DataRef
13
14#include "nw4r/ut/ut_binaryFileFormat.h"
15
16/*******************************************************************************
17 * types
18 */
19
20// forward declarations
21namespace nw4r { namespace ut { class FileStream; }}
22
23namespace nw4r { namespace snd { namespace detail
24{
25 struct StrmFile
26 {
27 /* Header */
28
29 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f271d
30 struct Header
31 {
32 ut::BinaryFileHeader fileHeader; // size 0x10, offset 0x00
33 ulong headBlockOffset; // size 0x04, offset 0x10
34 ulong headBlockSize; // size 0x04, offset 0x14
35 ulong adpcBlockOffset; // size 0x04, offset 0x18
36 ulong adpcBlockSize; // size 0x04, offset 0x1c
37 ulong dataBlockOffset; // size 0x04, offset 0x20
38 ulong dataBlockSize; // size 0x04, offset 0x24
39 }; // size 0x28
40
41 /* HeadBlock */
42
43 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f2d81
45 {
46 u8 format; // size 0x01, offset 0x00
47 u8 loopFlag; // size 0x01, offset 0x01
48 u8 numChannels; // size 0x01, offset 0x02
49 u8 sampleRate24; // size 0x01, offset 0x03
50 u16 sampleRate; // size 0x02, offset 0x04
51 u16 blockHeaderOffset; // size 0x02, offset 0x06
52 ulong loopStart; // size 0x04, offset 0x08
53 ulong loopEnd; // size 0x04, offset 0x0c
54 ulong dataOffset; // size 0x04, offset 0x10
55 ulong numBlocks; // size 0x04, offset 0x14
56 ulong blockSize; // size 0x04, offset 0x18
57 ulong blockSamples; // size 0x04, offset 0x1c
58 ulong lastBlockSize; // size 0x04, offset 0x20
59 ulong lastBlockSamples; // size 0x04, offset 0x24
60 ulong lastBlockPaddedSize; // size 0x04, offset 0x28
61 ulong adpcmDataInterval; // size 0x04, offset 0x2c
62 ulong adpcmDataSize; // size 0x04, offset 0x30
63 }; // size 0x34
64
65 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f3a1e
66 struct TrackInfo
67 {
68 u8 channelCount; // size 0x01, offset 0x00
69 u8 channelIndexTable[]; // flexible, offset 0x01 (unit size 0x01)
70 }; // size 0x01
71
72 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f3196
74 {
75 u8 volume; // size 0x01, offset 0x00
76 u8 pan; // size 0x01, offset 0x01
77 u8 padding[2];
78 ulong reserved;
79 u8 channelCount; // size 0x01, offset 0x08
80 u8 channelIndexTable[]; // flexible, offset 0x09 (unit size 0x01)
81 /* 3 bytes padding */
82 }; // size 0x0c
83
84 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f34ef
86 {
87 u8 trackCount; // size 0x01, offset 0x00
88 u8 trackDataType; // size 0x01, offset 0x01
89 u8 padding[2];
90 Util::DataRef<TrackInfo, TrackInfoEx> refTrackHeader[]; // flexible, offset 0x04 (unit size 0x08)
91 }; // size 0x04
92
93 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f336f
95 {
96 AdpcmParam adpcmParam; // size 0x28, offset 0x00
97 AdpcmLoopParam adpcmLoopParam; // size 0x06, offset 0x28
98 }; // size 0x2e
99
100 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f3cbb
102 {
103 Util::DataRef<AdpcmParamSet> refAdpcmInfo; // size 0x08, offset 0x00
104 }; // size 0x08
105
106 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f3780
108 {
109 u8 channelCount; // size 0x01, offset 0x00
110 u8 padding[3];
111 Util::DataRef<ChannelInfo> refChannelHeader[]; // flexible, offset 0x04 (unit size 0x08)
112 }; // size 0x04
113
114 static ulong const SIGNATURE_HEAD_BLOCK =
115 NW4R_FOUR_BYTE('H', 'E', 'A', 'D');
116
117 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f2ab0
119 {
120 ut::BinaryBlockHeader blockHeader; // size 0x08, offset 0x00
121 Util::DataRef<StrmDataInfo> refDataHeader; // size 0x08, offset 0x08
122 Util::DataRef<TrackTable> refTrackTable; // size 0x08, offset 0x10
123 Util::DataRef<ChannelTable> refChannelTable; // size 0x08, offset 0x18
124 }; // size 0x20
125
126 /* StrmFile */
127
128 static ulong const SIGNATURE_FILE =
129 NW4R_FOUR_BYTE('R', 'S', 'T', 'M');
130 static int const FILE_VERSION = NW4R_FILE_VERSION(1, 0);
131 }; // "namespace" StrmFile
132}}} // namespace nw4r::snd::detail
133
134/*******************************************************************************
135 * classes and functions
136 */
137
138namespace nw4r { namespace snd { namespace detail
139{
140 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f2b8e
141 class StrmFileReader
142 {
143 // nested types
144 public:
145 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f0e7
146 struct StrmInfo
147 {
148 SampleFormat sampleFormat; // size 0x04, offset 0x00
149 bool loopFlag; // size 0x01, offset 0x04
150 /* 3 bytes padding */
151 int numChannels; // size 0x04, offset 0x08
152 int sampleRate; // size 0x04, offset 0x0c
153 u16 blockHeaderOffset; // size 0x02, offset 0x10
154 /* 2 bytes padding */
155 ulong loopStart; // size 0x04, offset 0x14
156 ulong loopEnd; // size 0x04, offset 0x18
157 ulong dataOffset; // size 0x04, offset 0x1c
158 ulong numBlocks; // size 0x04, offset 0x20
159 ulong blockSize; // size 0x04, offset 0x24
160 ulong blockSamples; // size 0x04, offset 0x28
161 ulong lastBlockSize; // size 0x04, offset 0x2c
162 ulong lastBlockSamples; // size 0x04, offset 0x30
163 ulong lastBlockPaddedSize; // size 0x04, offset 0x34
164 ulong adpcmDataInterval; // size 0x04, offset 0x38
165 ulong adpcmDataSize; // size 0x04, offset 0x3c
166 }; // size 0x40
167
168 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2fa44
170 {
171 u8 volume; // size 0x01, offset 0x00
172 u8 pan; // size 0x01, offset 0x01
173 /* 2 bytes padding */
174 int channelCount; // size 0x04, offset 0x04
175 u8 channelIndexTable[32]; // size 0x20, offset 0x08
176 }; // size 0x28
177
178 // methods
179 public:
180 // cdtors
181 StrmFileReader();
182
183 // methods
184 void Setup(void const *strmData);
185
186 bool IsAvailable() const { return mHeader != nullptr; }
187 ulong GetAdpcBlockOffset() const
188 {
189 if (IsAvailable())
190 return mHeader->adpcBlockOffset;
191
192 return 0;
193 }
194
195 int GetTrackCount() const;
196 int GetChannelCount() const;
197
198 bool ReadStrmInfo(StrmInfo *strmInfo) const;
199 bool ReadStrmTrackInfo(StrmTrackInfo *trackInfo, int trackIndex) const;
200 bool ReadAdpcmInfo(AdpcmParam *adpcmParam,
201 AdpcmLoopParam *adpcmLoopParam,
202 int channelIndex) const;
203
204 private:
205 static bool IsValidFileHeader(void const *strmData);
206
207 static SampleFormat GetSampleFormatFromStrmFileFormat(u8 format);
208
209 // static members
210 public:
211 static int const SUPPORTED_FILE_VERSION = NW4R_FILE_VERSION(1, 0);
212
213 // members
214 private:
215 StrmFile::Header const *mHeader; // size 0x04, offset 0x00
216 StrmFile::HeadBlock const *mHeadBlock; // size 0x04, offset 0x04
217
218 // friends
219 private:
220 friend class StrmFileLoader;
221 }; // size 0x08
222
223 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f3fc4
224 class StrmFileLoader
225 {
226 // methods
227 public:
228 // cdtors
229 StrmFileLoader(ut::FileStream &stream) : mStream(stream) {}
230
231 // methods
232 bool LoadFileHeader(void *buffer, ulong size);
233
234 int GetTrackCount() const;
235 int GetChannelCount() const;
236
237 bool ReadStrmInfo(StrmFileReader::StrmInfo *strmInfo) const;
238 bool ReadStrmTrackInfo(StrmFileReader::StrmTrackInfo *trackInfo,
239 int trackIndex) const;
240 bool ReadAdpcmInfo(AdpcmParam *adpcmParam,
241 AdpcmLoopParam *adpcmLoopParam,
242 int channelIndex) const;
243 bool ReadAdpcBlockData(u16 *yn1, u16 *yn2, int blockIndex,
244 int channelCount);
245
246 // members
247 private:
248 ut::FileStream &mStream; // size 0x04, offset 0x00
249 StrmFileReader mReader; // size 0x08, offset 0x04
250 }; // size 0x0c
251}}} // namespace nw4r::snd::detail
252
253#endif // NW4R_SND_STRM_FILE_H
Debugging library which includes various utilities used by the rest of nw4r.
Definition ut_list.cpp:4