NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
snd_StrmPlayer.h
1#ifndef NW4R_SND_STRM_PLAYER_H
2#define NW4R_SND_STRM_PLAYER_H
3
4/*******************************************************************************
5 * headers
6 */
7
8#include <types.h>
9
10#include "nw4r/snd/snd_BasicPlayer.h"
11#include "nw4r/snd/snd_global.h"
12#include "nw4r/snd/snd_InstancePool.h"
13#include "nw4r/snd/snd_Task.h"
14#include "nw4r/snd/snd_SoundThread.h"
15#include "nw4r/snd/snd_StrmChannel.h"
16#include "nw4r/snd/snd_StrmFile.h"
17#include "nw4r/snd/snd_Voice.h"
18
19#include "nw4r/ut/ut_LinkList.h"
20
21#include <revolution/OS/OSMutex.h>
22
23/*******************************************************************************
24 * types
25 */
26
27// forward declarations
28namespace nw4r { namespace ut { class FileStream; }}
29
30/*******************************************************************************
31 * classes and functions
32 */
33
34namespace nw4r { namespace snd {
35
37{
38 /* 0x00 */ bool loopFlag;
39 /* 0x04 */ int sampleRate;
40 /* 0x08 */ ulong loopStart;
41 /* 0x0C */ ulong loopEnd;
42};
43
44namespace detail
45{
46 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2fcda
47 class StrmPlayer : public BasicPlayer, public SoundThread::PlayerCallback
48 {
49 // enums
50 public:
51 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f3ca
52 enum StartOffsetType
53 {
54 START_OFFSET_TYPE_SAMPLE,
55 START_OFFSET_TYPE_MILLISEC,
56 };
57
58 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2fc67
59 enum SetupResult
60 {
61 SETUP_SUCCESS,
62
63 SETUP_ERR_CANNOT_ALLOCATE_BUFFER,
64
65 SETUP_ERR_UNKNOWN
66 };
67
68 // nested types
69 public:
70 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2fb36
71 struct StrmTrack
72 {
73 bool mActiveFlag; // size 0x01, offset 0x00
74 Voice *mVoice; // size 0x04, offset 0x04
75 StrmFileReader::StrmTrackInfo mTrackInfo; // size 0x28, offset 0x08
76 f32 mVolume; // size 0x04, offset 0x30
77 f32 mPan; // size 0x04, offset 0x34
78 }; // size 0x38
79
80 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f430
81 class StrmHeaderLoadTask : public Task
82 {
83 // methods
84 public:
85 // cdtors
86 StrmHeaderLoadTask();
87
88 // virtual function ordering
89 // vtable Task
90 virtual void Execute();
91 virtual void Cancel();
92 virtual void OnCancel();
93
94 // members
95 public:
96 /* base Task */ // size 0x10, offset 0x00
97 StrmPlayer *player; // size 0x04, offset 0x10
98 ut::FileStream *fileStream; // size 0x04, offset 0x14
99 StartOffsetType startOffsetType; // size 0x04, offset 0x18
100 s32 startOffset; // size 0x04, offset 0x1c
101 }; // size 0x20
102
103 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f537
104 class StrmDataLoadTask : public Task
105 {
106 // typedefs
107 public:
109
110 // methods
111 public:
112 // cdtors
113 StrmDataLoadTask();
114
115 // virtual function ordering
116 // vtable Task
117 virtual void Execute();
118 virtual void Cancel();
119 virtual void OnCancel();
120
121 // members
122 public:
123 /* base Task */ // size 0x10, offset 0x00
124 StrmPlayer *mStrmPlayer; // size 0x04, offset 0x10
125 ut::FileStream *fileStream; // size 0x04, offset 0x14
126 ulong mSize; // size 0x04, offset 0x18
127 s32 mOffset; // size 0x04, offset 0x1c
128 ulong mBlockSize; // size 0x04, offset 0x20
129 s32 mBufferBlockIndex; // size 0x04, offset 0x24
130 bool mNeedUpdateAdpcmLoop; // size 0x01, offset 0x28
131 /* 3 bytes padding */
132 ut::LinkListNode link; // size 0x08, offset 0x2c
133 }; // size 0x34
134
135 // methods
136 public:
137 StrmPlayer();
138 virtual ~StrmPlayer();
139
140 // virtual function ordering
141 // vtable BasicPlayer
142 virtual bool Start();
143 virtual void Stop();
144 virtual void Pause(bool flag);
145 virtual bool IsActive() const { return mActiveFlag; }
146 virtual bool IsStarted() const { return mStartedFlag; }
147 virtual bool IsPause() const { return mPauseFlag; }
148
149 // vtable SoundThread::PlayerCallback
150 virtual void OnUpdateFrameSoundThread() { Update(); }
151 virtual void OnUpdateVoiceSoundThread() { UpdateBuffer(); }
152 virtual void OnShutdownSoundThread() { Stop(); }
153
154 // methods
155 SetupResult Setup(StrmBufferPool *bufferPool, int allocChannelCount,
156 u16 allocTrackFlag, int voiceOutCount);
157 void Update();
158 void Shutdown();
159
160 bool IsPrepared() const { return mPreparedFlag; }
161 StrmChannel *GetTrackChannel(StrmTrack const &track, int channelIndex);
162 StrmTrack *GetPlayerTrack(int trackNo);
163
164 void SetTaskErrorFlag() { mTaskErrorFlag = true; }
165 void SetTaskCancelFlag() { mTaskCancelFlag = true; }
166
167 bool IsAdpcm() const
168 {
169 return mStrmInfo.sampleFormat == SAMPLE_FORMAT_DSP_ADPCM;
170 }
171 bool CheckDiskDriveError() const;
172
173 void SetAdpcmLoopContext(int channelNum, u16 *predScale);
174 void SetTrackVolume(ulong trackBitFlag, f32 volume);
175 ulong GetPlaySamplePosition() const;
176
177 bool ReadStrmDataInfo(StrmDataInfo*) const;
178 void InitParam();
179 bool SetupPlayer();
180 bool Prepare(ut::FileStream *fileStream,
181 StartOffsetType startOffsetType, int startOffset);
182
183 bool LoadHeader(ut::FileStream *fileStream,
184 StartOffsetType startOffsetType, int startOffset);
185 bool LoadStreamData(ut::FileStream *fileStream, int offset, ulong size,
186 ulong blockSize, int bufferBlockIndex,
187 bool needUpdateAdpcmLoop);
188
189 bool AllocStrmBuffers();
190 void FreeStrmBuffers();
191
192 bool AllocVoices(int voiceOutCount);
193 void FreeVoices();
194
195 int CalcLoadingBufferBlockCount() const;
196 bool CalcStartOffset(s32 *startBlockIndex, ulong *startBlockOffset,
197 s32 *loopCount);
198
199 void SetLoopEndToZeroBuffer(int endBufferBlockIndex);
200
201 void UpdateBuffer();
202 void UpdatePauseStatus();
203 void UpdateLoadingBlockIndex();
204 void UpdatePlayingBlockIndex();
205 void UpdateLoopAddress(ulong loopStartSamples, ulong loopEndSamples);
206 void UpdateDataLoopAddress(s32 endBlockBufferIndex);
207 void UpdateVoiceParams(StrmTrack *track);
208
209 static ulong GetSampleByByte(ulong byte, SampleFormat format);
210
211 private:
212 static void VoiceCallbackFunc(Voice *voice,
213 Voice::VoiceCallbackStatus status,
214 void *arg);
215
216 // static members
217 public:
218 static int const LOAD_BUFFER_SIZE = 0x4000;
219 static int const LOAD_BUFFER_CHANNEL_NUM;
220 static int const BUFFER_BLOCK_COUNT_MAX = 32;
221 static int const STRM_CHANNEL_NUM_PER_TRACK;
222 static int const STRM_CHANNEL_NUM = 16;
223 static int const DATA_BLOCK_SIZE_MAX = 0x2000;
224 static int const STRM_TRACK_NUM = 8;
225
226 private:
227 static bool sStaticInitFlag;
228 static OSMutex sLoadBufferMutex;
229 static byte_t sLoadBuffer[LOAD_BUFFER_SIZE];
230
231 // members
232 private:
233 /* base BasicPlayer */ // size 0x0a4, offset 0x000
234 /* base SoundThread::PlayerCallback */ // size 0x00c, offset 0x0a4
235 StrmFileReader::StrmInfo mStrmInfo; // size 0x040, offset 0x0b0
236 bool volatile mSetupFlag; // size 0x001, offset 0x0f0
237 bool mActiveFlag; // size 0x001, offset 0x0f1
238 bool mStartedFlag; // size 0x001, offset 0x0f2
239 bool mPreparedFlag; // size 0x001, offset 0x0f3
240 bool mTaskErrorFlag; // size 0x001, offset 0x0f4
241 bool mTaskCancelFlag; // size 0x001, offset 0x0f5
242 bool mLoadingDelayFlag; // size 0x001, offset 0x0f6
243 bool mPauseFlag; // size 0x001, offset 0x0f7
244 bool mPauseStatus; // size 0x001, offset 0x0f8
245 bool mLoadWaitFlag; // size 0x001, offset 0x0f9
246 bool mNoRealtimeLoadFlag; // size 0x001, offset 0x0fa
247 bool mSkipUpdateAdpcmLoop; // size 0x001, offset 0x0fb
248 bool mValidAdpcmLoop; // size 0x001, offset 0x0fc
249 bool mPlayFinishFlag; // size 0x001, offset 0x0fd
250 bool mLoadFinishFlag; // size 0x001, offset 0x0fe
251 bool mAllocStrmBufferFlag; // size 0x001, offset 0x0ff
252 s32 mLoopCounter; // size 0x004, offset 0x100
253 int mPrepareCounter; // size 0x004, offset 0x104
254 int mChangeNumBlocks; // size 0x004, offset 0x108
255 int mDataBlockSize; // size 0x004, offset 0x10c
256 int mBufferBlockCount; // size 0x004, offset 0x110
257 int mBufferBlockCountBase; // size 0x004, offset 0x114
258 int mLoadingBufferBlockCount; // size 0x004, offset 0x118
259 int mLoadingBufferBlockIndex; // size 0x004, offset 0x11c
260 int mLoadingDataBlockIndex; // size 0x004, offset 0x120
261 int mPlayingBufferBlockCount; // size 0x004, offset 0x124
262 int mPlayingBufferBlockIndex; // size 0x004, offset 0x128
263 int mPlayingDataBlockIndex; // size 0x004, offset 0x12c
264 int mLoopStartBlockIndex; // size 0x004, offset 0x130
265 int mLastBlockIndex; // size 0x004, offset 0x134
266 int mLoadWaitCount; // size 0x004, offset 0x138
267 StartOffsetType mStartOffsetType; // size 0x004, offset 0x13c
268 int mStartOffset; // size 0x004, offset 0x140
269 StrmHeaderLoadTask mStrmHeaderLoadTask; // size 0x020, offset 0x144
270 StrmDataLoadTask::LinkList mStrmDataLoadTaskList; // size 0x00c, offset 0x164
271 InstancePool<StrmDataLoadTask> mStrmDataLoadTaskPool; // size 0x004, offset 0x170
272 StrmDataLoadTask mStrmDataLoadTaskArea[BUFFER_BLOCK_COUNT_MAX]; // size 0x680, offset 0x174
273 StrmBufferPool *mBufferPool; // size 0x004, offset 0x7f4
274 ut::FileStream *mFileStream; // size 0x004, offset 0x7f8
275 s32 mTrackCount; // size 0x004, offset 0x7fc
276 s32 mChannelCount; // size 0x004, offset 0x800
277 s32 mVoiceOutCount; // size 0x004, offset 0x804
278 StrmChannel mChannels[STRM_CHANNEL_NUM]; // size 0x340, offset 0x808
279 StrmTrack mTracks[STRM_TRACK_NUM]; // size 0x1c0, offset 0xb48
280 }; // size 0xd08
281}}} // namespace nw4r::snd::detail
282
283#endif // NW4R_SND_STRM_PLAYER_H
Debugging library which includes various utilities used by the rest of nw4r.
Definition ut_list.cpp:4