1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
//
// Generated By: dol2asm
// Translation Unit: JASDSPChannel
//
#include "JSystem/JAudio2/JASDSPChannel.h"
#include "JSystem/JAudio2/JASHeapCtrl.h"
#include "JSystem/JKernel/JKRSolidHeap.h"
/* 804512E0-804512E8 0007E0 0004+04 5/5 0/0 0/0 .sbss sDspChannels__13JASDSPChannel */
JASDSPChannel* JASDSPChannel::sDspChannels;
/* 8029D2F4-8029D320 297C34 002C+00 1/1 0/0 0/0 .text __ct__13JASDSPChannelFv */
JASDSPChannel::JASDSPChannel() :
mStatus(STATUS_INACTIVE),
mPriority(-1),
mFlags(0),
field_0xc(0),
mCallback(NULL),
mCallbackData(NULL),
mChannel(NULL)
{
/* empty function */
}
/* 8029D320-8029D330 297C60 0010+00 0/0 3/3 0/0 .text free__13JASDSPChannelFv */
void JASDSPChannel::free() {
mCallback = NULL;
mCallbackData = NULL;
}
/* 8029D330-8029D340 297C70 0010+00 0/0 2/2 0/0 .text start__13JASDSPChannelFv */
void JASDSPChannel::start() {
mFlags |= 1;
}
/* 8029D340-8029D3C8 297C80 0088+00 3/3 2/2 0/0 .text drop__13JASDSPChannelFv */
void JASDSPChannel::drop() {
if (mCallback != NULL) {
mCallback(CB_DROP, NULL, mCallbackData);
}
mCallback = NULL;
mCallbackData = NULL;
mPriority = -1;
mFlags &= ~1;
if (mStatus == STATUS_ACTIVE) {
mFlags |= 2;
mStatus = STATUS_DROP;
}
}
/* 8029D3C8-8029D44C 297D08 0084+00 0/0 1/1 0/0 .text initAll__13JASDSPChannelFv */
void JASDSPChannel::initAll() {
sDspChannels = new (JASDram, 0x20) JASDSPChannel[0x40];
for (int i = 0; i < 0x40; i++) {
sDspChannels[i].mChannel = JASDsp::getDSPHandle(i);
}
}
/* 8029D44C-8029D4BC 297D8C 0070+00 0/0 1/1 0/0 .text
* alloc__13JASDSPChannelFUcPFUlPQ26JASDsp8TChannelPv_lPv */
JASDSPChannel* JASDSPChannel::alloc(u8 i_priority, Callback i_callback, void* i_callbackData) {
JASDSPChannel* channel = getLowestChannel(i_priority);
if (channel == NULL) {
return NULL;
}
channel->drop();
channel->mPriority = i_priority;
channel->field_0xc = 0;
channel->mCallback = i_callback;
channel->mCallbackData = i_callbackData;
return channel;
}
/* 8029D4BC-8029D534 297DFC 0078+00 0/0 1/1 0/0 .text
* allocForce__13JASDSPChannelFUcPFUlPQ26JASDsp8TChannelPv_lPv */
JASDSPChannel* JASDSPChannel::allocForce(u8 i_priority, Callback i_callback, void* i_callbackData) {
JASDSPChannel* channel = getLowestChannel(i_priority);
if (channel == NULL) {
return NULL;
}
channel->mStatus = STATUS_INACTIVE;
channel->drop();
channel->mPriority = i_priority;
channel->field_0xc = 0;
channel->mCallback = i_callback;
channel->mCallbackData = i_callbackData;
return channel;
}
/* 8029D534-8029D540 297E74 000C+00 0/0 1/1 0/0 .text setPriority__13JASDSPChannelFUc */
void JASDSPChannel::setPriority(u8 i_priority) {
mPriority = i_priority;
}
/* 8029D540-8029D5D0 297E80 0090+00 2/2 0/0 0/0 .text getLowestChannel__13JASDSPChannelFi
*/
JASDSPChannel* JASDSPChannel::getLowestChannel(int i_priority) {
s16 best_priority = 0xff;
int best_index = -1;
int best_unknown = 0;
for (int i = 0; i < 0x40; i++) {
JASDSPChannel* channel = &sDspChannels[i];
s16 priority = channel->mPriority;
if (priority < 0) {
return channel;
}
if (priority <= i_priority && priority <= best_priority) {
if (priority != best_priority || channel->field_0xc > best_unknown) {
best_unknown = channel->field_0xc;
best_index = i;
best_priority = priority;
}
}
}
if (best_index < 0) {
return NULL;
}
return &sDspChannels[best_index];
}
/* 8029D5D0-8029D65C 297F10 008C+00 1/1 0/0 0/0 .text getLowestActiveChannel__13JASDSPChannelFv */
JASDSPChannel* JASDSPChannel::getLowestActiveChannel() {
s16 best_priority = 0xff;
int best_index = -1;
int best_unknown = 0;
for (int i = 0; i < 0x40; i++) {
JASDSPChannel* channel = &sDspChannels[i];
if (channel->mStatus == STATUS_ACTIVE) {
s16 priority = channel->mPriority;
if (priority < 0x7f && priority <= best_priority) {
if (priority != best_priority || channel->field_0xc > best_unknown) {
best_unknown = channel->field_0xc;
best_index = i;
best_priority = priority;
}
}
}
}
if (best_index < 0) {
return NULL;
}
return &sDspChannels[best_index];
}
/* 8029D65C-8029D89C 297F9C 0240+00 1/1 0/0 0/0 .text updateProc__13JASDSPChannelFv */
void JASDSPChannel::updateProc() {
int ret;
if (mChannel->isFinish()) {
mFlags &= ~2;
if (mStatus == STATUS_ACTIVE) {
if (mCallback != NULL) {
ret = mCallback(CB_STOP, NULL, mCallbackData);
} else {
ret = -1;
}
if (ret < 0) {
mPriority = -1;
}
}
mStatus = STATUS_INACTIVE;
mChannel->replyFinishRequest();
mChannel->flush();
} else if (mFlags & 2) {
mFlags &= ~2;
mChannel->forceStop();
mChannel->flush();
} else if (mStatus != STATUS_DROP) {
if ((mFlags & 1) && mStatus == STATUS_INACTIVE) {
mFlags &= ~1;
mStatus = STATUS_ACTIVE;
mChannel->init();
if (mCallback != NULL) {
ret = mCallback(CB_START, mChannel, mCallbackData);
} else {
ret = 0;
}
if (ret < 0) {
mStatus = STATUS_INACTIVE;
if (mCallback != NULL) {
ret = mCallback(CB_STOP, NULL, mCallbackData);
} else {
ret = -1;
}
if (ret < 0) {
mPriority = -1;
}
mChannel->flush();
} else {
mChannel->playStart();
mChannel->flush();
}
} else if (mStatus != STATUS_INACTIVE) {
bool flush = false;
if (mCallback != NULL) {
ret = mCallback(CB_PLAY, mChannel, mCallbackData);
flush = true;
} else {
ret = 0;
}
if (ret < 0) {
mStatus = STATUS_INACTIVE;
if (mCallback != NULL) {
ret = mCallback(CB_STOP, NULL, mCallbackData);
} else {
ret = -1;
}
if (ret < 0) {
mPriority = -1;
}
mChannel->playStop();
mChannel->flush();
} else {
field_0xc++;
if (flush) {
mChannel->flush();
}
}
}
}
}
/* 8029D89C-8029D910 2981DC 0074+00 0/0 1/1 0/0 .text updateAll__13JASDSPChannelFv */
void JASDSPChannel::updateAll() {
for (u32 i = 0; i < 0x40; i++) {
if ((i & 0xf) == 0 && i != 0) {
JASDsp::releaseHalt((i - 1) >> 4);
}
sDspChannels[i].updateProc();
}
JASDsp::releaseHalt(3);
}
/* 8029D910-8029D948 298250 0038+00 0/0 1/1 0/0 .text killActiveChannel__13JASDSPChannelFv */
int JASDSPChannel::killActiveChannel() {
JASDSPChannel* channel = getLowestActiveChannel();
if (channel == NULL) {
return 0;
} else {
channel->drop();
return 1;
}
}
/* 8029D948-8029D958 298288 0010+00 0/0 1/1 0/0 .text getHandle__13JASDSPChannelFUl */
JASDSPChannel* JASDSPChannel::getHandle(u32 i_index) {
return &sDspChannels[i_index];
}
|