tp/libs/JSystem/JAudio2/JASDSPChannel.cpp

249 lines
7.6 KiB
C++

//
// 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];
}