SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
SpkSound.cpp
1#include "Game/Speaker/SpkSound.hpp"
2#include "JSystem/JAudio2/JASHeapCtrl.hpp"
3
4void SpkSoundHandle::releaseSound() {
5 if (!mSound) {
6 return;
7 }
8
9 mSound->mSoundHandle = nullptr;
10 mSound = nullptr;
11}
12
13SpkSoundVolume::SpkSoundVolume() {
14 _0 = 1.0f;
15 _4 = 0.0f;
16 _8 = 1.0f;
17 _C = 0.0f;
18 _10 = 1.0f;
19 _14 = 1.0f;
20 _18 = 0.0f;
21 _1C = 1.0f;
22}
23
24void SpkSoundVolume::setRelease(s32 release) {
25 if (release > 0) {
26 _4 = 1.0f / release;
27 }
28 else {
29 _4 = 1.0f;
30 }
31
32 _0 = 1.0f;
33}
34
35void SpkSoundVolume::setFadeOut(s32 fadeOut) {
36 BOOL status = OSDisableInterrupts();
37
38 if (fadeOut > 0) {
39 _C = 1.0f / fadeOut;
40 }
41 else {
42 _C = 1.0f;
43 }
44
45 _8 = 1.0f;
46 OSRestoreInterrupts(status);
47}
48
49SpkSound::SpkSound() : JSUPtrLink(this), mSoundHandle(nullptr), _14(-1), _18(0), _1C(0), _20(0), _24(100), _28(0), _2C(0), _30(-1), _34(-1), _38(0), _3C(-1) {
50
51}
52
53#ifdef NON_MATCHING
54SpkSound::~SpkSound() {
55 releaseHandle();
56
57 if (this) {
58 JASPoolAllocObject<SpkSound>::memPool_.free(this, 0x60);
59 }
60}
61#endif
62
63// SpkSound::update
64
65void SpkSound::stop(s32 a1) {
66 _38 = 3;
67 s32 fade = (6 * a1) / 40;
68
69 if (fade) {
70 mVolume.setFadeOut(fade);
71 }
72 else {
73 mVolume.setRelease(_28);
74 }
75}
76
77void SpkSound::attachHandle(SpkSoundHandle *pHandle) {
78 if (mSoundHandle) {
79 releaseHandle();
80 }
81
82 mSoundHandle = pHandle;
83 pHandle->mSound = this;
84}
85
86void SpkSound::releaseHandle() {
87 if (!mSoundHandle) {
88 return;
89 }
90
91 mSoundHandle->mSound = nullptr;
92 mSoundHandle = nullptr;
93}
94
95bool SpkSound::start(s32 a1, s32 a2) {
96 _20 = a1;
97 bool res = setWaveData(a2);
98
99 if (!res) {
100 return false;
101 }
102
103 _38 = 1;
104 return true;
105}
106
107void SpkSound::unlock() {
108 if (_38 != 1) {
109 return;
110 }
111
112 _38 = 2;
113}
114
115SpkSoundHolder::SpkSoundHolder() : JASGlobalInstance(this) {
116 _44 = 0xA;
117 _40 = 1.0f;
118
119 for (int i = 0; i < 4; i++) {
120 _30[i] = 1.0f;
121 }
122}
123
124bool SpkSoundHolder::update(s32 a1) {
125 BOOL status = OSDisableInterrupts();
126 bool ret = updateEachSound(a1);
127 OSRestoreInterrupts(status);
128 return ret;
129}