NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
snd_RemoteSpeaker.h
1#ifndef NW4R_SND_REMOTE_SPEAKER_H
2#define NW4R_SND_REMOTE_SPEAKER_H
3
4#include <revolution/OS.h> // IWYU pragma: export
5#include <revolution/WENC.h> // IWYU pragma: export
6#include <revolution/WPAD.h> // IWYU pragma: export
7
8namespace nw4r {
9namespace snd {
10
11class RemoteSpeaker {
12public:
13 enum SpeakerState {
14 STATE_INVALID,
15 STATE_EXEC_SPEAKER_ON,
16 STATE_SPEAKER_ON,
17 STATE_EXEC_SPEAKER_PLAY,
18 STATE_SPEAKER_PLAY,
19 STATE_EXEC_SPEAKER_OFF,
20 STATE_SPEAKER_OFF
21 };
22
23 enum SpeakerCommand {
24 COMMAND_NONE,
25 COMMAND_SPEAKER_ON,
26 COMMAND_SPEAKER_PLAY,
27 COMMAND_SPEAKER_OFF
28 };
29
30 static const int SAMPLES_PER_AUDIO_PACKET = 40;
31
32public:
33 RemoteSpeaker();
34
35 void InitParam();
36 bool Setup(WPADCallback pCallback);
37 void Shutdown(WPADCallback pCallback);
38
39 bool EnableOutput(bool enable);
40 bool IsEnabledOutput() const;
41
42 void Update();
43 void UpdateStreamData(const s16 *pRmtSamples);
44
45 bool IsAvailable() const {
46 return mState == STATE_SPEAKER_PLAY;
47 }
48
49 void SetChannelIndex(int index) {
50 mChannelIndex = index;
51 }
52
53private:
54 static const int SAMPLES_PER_ENCODED_PACKET = (SAMPLES_PER_AUDIO_PACKET + 1) / 2;
55
56 static const int CONTINUOUS_PLAY_INTERVAL_MINUTES = 8;
57
58private:
59 void ClearParam();
60 void ExecCommand(SpeakerCommand command);
61
62 bool IsAllSampleZero(const s16 *pRmtSamples);
63 void NotifyCallback(s32 chan, s32 result);
64
65 static void SpeakerOnCallback(s32 chan, s32 result);
66 static void SpeakerPlayCallback(s32 chan, s32 result);
67 static void SpeakerOffCallback(s32 chan, s32 result);
68
69 static void ContinueAlarmHandler(OSAlarm *pAlarm, OSContext *pCtx);
70 static void IntervalAlarmHandler(OSAlarm *pAlarm, OSContext *pCtx);
71
72private:
73 bool mInitFlag; // at 0x0
74 bool mPlayFlag; // at 0x1
75 bool mEnableFlag; // at 0x2
76 bool mFirstEncodeFlag; // at 0x3
77 bool mValidCallbackFlag; // at 0x4
78 bool mCommandBusyFlag; // at 0x5
79 // TODO commenting out a random flag to make eggAudioRmtSpeakerMgr match
80 // TODO offsets are wrong as a result
81 // bool mForceResumeFlag; // at 0x6
82 bool mContinueFlag; // at 0x7
83 volatile bool mIntervalFlag; // at 0x8
84 SpeakerState mState; // at 0xC
85 SpeakerCommand mUserCommand; // at 0x10
86 SpeakerCommand mInternalCommand; // at 0x14
87 WENCInfo mEncodeInfo; // at 0x18
88 int mChannelIndex; // at 0x38
89 WPADCallback *mWpadCallback; // at 0x3C
90 OSAlarm mContinueAlarm; // at 0x40
91 OSAlarm mIntervalAlarm; // at 0x70
92 s64 mContinueBeginTime; // at 0xA0
93};
94
95} // namespace snd
96} // namespace nw4r
97
98#endif