mirror of
https://github.com/zeldaret/tww.git
synced 2026-06-28 18:30:54 -04:00
325 lines
9.2 KiB
C++
325 lines
9.2 KiB
C++
//
|
|
// Generated by dtk
|
|
// Translation Unit: JASDSPChannel.cpp
|
|
//
|
|
|
|
#include "JSystem/JAudio/JASDSPChannel.h"
|
|
#include "JSystem/JAudio/JASAudioThread.h"
|
|
#include "JSystem/JAudio/JASChAllocQueue.h"
|
|
#include "JSystem/JAudio/JASDSPInterface.h"
|
|
#include "JSystem/JAudio/JASRate.h"
|
|
#include "JSystem/JAudio/JASSystemHeap.h"
|
|
#include "JSystem/JAudio/dspproc.h"
|
|
#include "JSystem/JKernel/JKRSolidHeap.h"
|
|
#include "JSystem/JUtility/JUTAssert.h"
|
|
|
|
/* 8028963C-80289694 .text init__Q28JASystem11TDSPChannelFUc */
|
|
void JASystem::TDSPChannel::init(u8 param_1) {
|
|
mNumber = param_1;
|
|
field_0x1 = 1;
|
|
field_0x8 = 0;
|
|
field_0x6 = 0;
|
|
mCallback = NULL;
|
|
field_0x3 = 0;
|
|
field_0x4 = 0;
|
|
field_0xc = DSPInterface::getDSPHandle(param_1);
|
|
}
|
|
|
|
/* 80289694-80289720 .text allocate__Q28JASystem11TDSPChannelFUl */
|
|
int JASystem::TDSPChannel::allocate(u32 param_1) {
|
|
/* Nonmatching */
|
|
if (field_0x1 != 1) {
|
|
return false;
|
|
}
|
|
if (field_0x8 == 0) {
|
|
OSReport("sign %x があるのにCH.%d はFREE\n", field_0x8, mNumber);
|
|
}
|
|
field_0x1 = 0;
|
|
field_0x8 = param_1;
|
|
field_0x3 = 1;
|
|
field_0xc->allocInit();
|
|
return true;
|
|
}
|
|
|
|
/* 80289720-8028973C .text free__Q28JASystem11TDSPChannelFv */
|
|
void JASystem::TDSPChannel::free() {
|
|
field_0x1 = 1;
|
|
field_0x3 = 0;
|
|
mCallback = NULL;
|
|
field_0x8 = 0;
|
|
}
|
|
|
|
JASystem::TDSPChannel* JASystem::TDSPChannel::DSPCH;
|
|
int JASystem::TDSPChannel::smnUse;
|
|
|
|
/* 8028973C-802897E0 .text forceStop__Q28JASystem11TDSPChannelFv */
|
|
bool JASystem::TDSPChannel::forceStop() {
|
|
if (field_0x1 == 2) {
|
|
return false;
|
|
}
|
|
if (field_0x1 == 1) {
|
|
OSReport("----- JASDSPChannel::forceStop Warning! : CH_FREE\n");
|
|
return false;
|
|
}
|
|
if (field_0xc->field_0x0 == 0) {
|
|
return false;
|
|
}
|
|
smnUse--;
|
|
field_0xc->field_0x10a = 1;
|
|
field_0xc->flushChannel();
|
|
field_0x1 = 2;
|
|
return true;
|
|
}
|
|
|
|
/* 802897E0-802897F4 .text forceDelete__Q28JASystem11TDSPChannelFv */
|
|
void JASystem::TDSPChannel::forceDelete() {
|
|
field_0x8 = 0;
|
|
field_0x3 = 0;
|
|
mCallback = NULL;
|
|
}
|
|
|
|
/* 802897F4-80289844 .text play__Q28JASystem11TDSPChannelFv */
|
|
void JASystem::TDSPChannel::play() {
|
|
if (!mCallback) {
|
|
field_0xc->field_0x68 = 0;
|
|
}
|
|
field_0xc->playStart();
|
|
field_0xc->flushChannel();
|
|
}
|
|
|
|
/* 80289844-80289874 .text stop__Q28JASystem11TDSPChannelFv */
|
|
void JASystem::TDSPChannel::stop() {
|
|
field_0xc->field_0x0 = 0;
|
|
field_0xc->flushChannel();
|
|
}
|
|
|
|
/* 80289874-80289994 .text initAll__Q28JASystem11TDSPChannelFv */
|
|
void JASystem::TDSPChannel::initAll() {
|
|
static int first = 1;
|
|
if (first == 0) {
|
|
OSReport("---- DSPChannel::initAll : already initialized\n");
|
|
return;
|
|
}
|
|
DSPCH = new (JASDram, 0x20) TDSPChannel[64];
|
|
JUT_ASSERT(204, DSPCH);
|
|
OSReport("----- JASDSPChannel size : %d\n", 0x14);
|
|
for (u8 i = 0; i < 64; i++) {
|
|
DSPCH[i].init(i);
|
|
}
|
|
first = 0;
|
|
}
|
|
|
|
int JASystem::TDSPChannel::smnFree = 64;
|
|
|
|
/* 80289994-80289A54 .text alloc__Q28JASystem11TDSPChannelFUlUl */
|
|
JASystem::TDSPChannel* JASystem::TDSPChannel::alloc(u32 param_1, u32 param_2) {
|
|
/* Nonmatching */
|
|
if (param_1) {
|
|
OSReport("----- JASDSPChannel::alloc : 多チャネルモードはサポートされていません\n");
|
|
return NULL;
|
|
}
|
|
int i = 0;
|
|
do {
|
|
if (DSPCH[i].field_0x1 == 1 && DSPCH[i].allocate(param_2)) {
|
|
smnFree--;
|
|
smnUse++;
|
|
return &DSPCH[i];
|
|
}
|
|
i++;
|
|
} while(i < 64);
|
|
return NULL;
|
|
}
|
|
|
|
/* 80289A54-80289AF4 .text free__Q28JASystem11TDSPChannelFPQ28JASystem11TDSPChannelUl */
|
|
int JASystem::TDSPChannel::free(JASystem::TDSPChannel* param_1, u32 param_2) {
|
|
if (!param_1) {
|
|
OSReport("----- JASDSPChannel::free : NULL のチャネルを解放しようとしました\n");
|
|
return -1;
|
|
}
|
|
if (param_1->field_0x8 != param_2) {
|
|
OSReport("----- JASDSPChannel::free : BAD USERが開放を試みた\n");
|
|
return -2;
|
|
}
|
|
if (param_1->field_0x1 == 0) {
|
|
smnUse--;
|
|
}
|
|
if (param_1->field_0x1 != 1) {
|
|
smnFree++;
|
|
}
|
|
param_1->free();
|
|
return 0;
|
|
}
|
|
|
|
/* 80289AF4-80289C0C .text getLower__Q28JASystem11TDSPChannelFv */
|
|
JASystem::TDSPChannel* JASystem::TDSPChannel::getLower() {
|
|
u8 r31 = 0xff;
|
|
u8 r30 = 0;
|
|
u32 r29 = 0;
|
|
for (u8 i = 0; i < 64; i++) {
|
|
u8 r27;
|
|
TDSPChannel* dspch = DSPCH + i;
|
|
if (dspch->field_0x1 == 2) {
|
|
continue;
|
|
}
|
|
if (dspch->field_0x1 == 1) {
|
|
r30 = i;
|
|
break;
|
|
}
|
|
if (dspch->mCallback) {
|
|
r27 = dspch->field_0x3;
|
|
if (r27 <= r31) {
|
|
JUT_ASSERT(305, i == dspch->getNumber());
|
|
if (r27 != r31 || dspch->field_0xc->field_0x10c >= r29) {
|
|
r29 = dspch->field_0xc->field_0x10c;
|
|
r30 = i;
|
|
r31 = r27;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return DSPCH + r30;
|
|
}
|
|
|
|
/* 80289C0C-80289D10 .text getLowerActive__Q28JASystem11TDSPChannelFv */
|
|
JASystem::TDSPChannel* JASystem::TDSPChannel::getLowerActive() {
|
|
/* Nonmatching */
|
|
u8 r29 = 0xff;
|
|
u8 r28 = 0;
|
|
u32 r27 = 0;
|
|
for (u8 i = 0; i < 64; i++) {
|
|
TDSPChannel* dspch = DSPCH + i;
|
|
if (dspch->field_0x1 == 2 || dspch->field_0x1 == 1) {
|
|
continue;
|
|
}
|
|
u8 r30 = dspch->field_0x3;
|
|
if (r30 <= r29) {
|
|
JUT_ASSERT(345, i == dspch->getNumber());
|
|
if (r30 != r29 || dspch->field_0xc->field_0x10c >= r27) {
|
|
r27 = dspch->field_0xc->field_0x10c;
|
|
r28 = i;
|
|
r29 = r30;
|
|
}
|
|
}
|
|
}
|
|
return DSPCH + r28;
|
|
}
|
|
|
|
/* 80289D10-80289DC8 .text breakLower__Q28JASystem11TDSPChannelFUc */
|
|
BOOL JASystem::TDSPChannel::breakLower(u8 param_1) {
|
|
TDSPChannel* dspch = getLower();
|
|
if (dspch->field_0x3 > param_1) {
|
|
return false;
|
|
}
|
|
if (dspch->field_0x1 != 1) {
|
|
if (dspch->mCallback) {
|
|
dspch->onUpdate(3);
|
|
} else {
|
|
OSReport("----- BreakLowerDSPchannel : Error:Callback is NULL\n");
|
|
}
|
|
dspch->forceStop();
|
|
} else {
|
|
OSReport("----- BreakLowerDSPchannel : DSP Ch is FREE %d \n", dspch->mNumber);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/* 80289DC8-80289E68 .text breakLowerActive__Q28JASystem11TDSPChannelFUc */
|
|
bool JASystem::TDSPChannel::breakLowerActive(u8 param_1) {
|
|
TDSPChannel* dspch = getLowerActive();
|
|
if (dspch->field_0x3 > param_1) {
|
|
return false;
|
|
}
|
|
if (dspch->field_0x1 != 1) {
|
|
if (dspch->mCallback) {
|
|
dspch->onUpdate(3);
|
|
}
|
|
dspch->forceStop();
|
|
} else {
|
|
OSReport("----- BreakLowerActiveDSPchannel : DSP Ch is FREE %d\n", dspch->mNumber);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
OSTick JASystem::history[10];
|
|
OSTick JASystem::old_time;
|
|
f32 JASystem::DSP_LIMIT_RATIO = 1.1f;
|
|
|
|
/* 80289E68-8028A04C .text updateAll__Q28JASystem11TDSPChannelFv */
|
|
void JASystem::TDSPChannel::updateAll() {
|
|
/* Nonmatching */
|
|
if (Kernel::gSubFrames <= 10) {
|
|
OSTick time = OSGetTick();
|
|
OSTick var3 = time - old_time;
|
|
old_time = time;
|
|
u32 var2 = Kernel::gSubFrames - TAudioThread::snIntCount;
|
|
history[var2] = var3;
|
|
if (var2) {
|
|
if (f32(history[0]) / var3 < DSP_LIMIT_RATIO) {
|
|
breakLowerActive(126);
|
|
}
|
|
}
|
|
}
|
|
TDSPQueue::checkQueue();
|
|
for (u32 i = 0; i < 64; i++) {
|
|
if ((i & 0x0f) == 0 && i != 0) {
|
|
DSPReleaseHalt2(i - 1 >> 4);
|
|
}
|
|
TDSPChannel* dspChannel = DSPCH + i;
|
|
DSPInterface::DSPBuffer* dspBuffer = dspChannel->field_0xc;
|
|
if (dspChannel->field_0x1 == 1) {
|
|
continue;
|
|
}
|
|
if (dspBuffer->field_0x2 != 0) {
|
|
if (dspChannel->mCallback) {
|
|
dspChannel->onUpdate(2);
|
|
}
|
|
dspBuffer->field_0x2 = 0;
|
|
dspBuffer->field_0x0 = 0;
|
|
dspBuffer->flushChannel();
|
|
if (dspChannel->field_0x1 == 1) {
|
|
continue;
|
|
}
|
|
}
|
|
if (dspBuffer->field_0x10a == 0) {
|
|
dspBuffer->field_0x10c++;
|
|
if (dspBuffer->field_0x10c == dspChannel->field_0x4 && dspChannel->mCallback) {
|
|
dspChannel->mCallback(dspChannel, 4);
|
|
}
|
|
}
|
|
if (dspChannel->mCallback) {
|
|
if (dspChannel->field_0x6) {
|
|
dspChannel->field_0x6--;
|
|
}
|
|
if (dspChannel->field_0x6 == 0) {
|
|
dspChannel->onUpdate(0);
|
|
if (dspChannel->field_0x6 == 0) {
|
|
dspBuffer->field_0x2 = 0;
|
|
dspBuffer->field_0x0 = 0;
|
|
dspBuffer->flushChannel();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
DSPReleaseHalt2(3);
|
|
}
|
|
|
|
/* 8028A04C-8028A08C .text onUpdate__Q28JASystem11TDSPChannelFUl */
|
|
void JASystem::TDSPChannel::onUpdate(u32 param_1) {
|
|
if (mCallback) {
|
|
field_0x6 = mCallback(this, param_1);
|
|
}
|
|
}
|
|
|
|
/* 8028A08C-8028A0C0 .text getNumBreak__Q28JASystem11TDSPChannelFv */
|
|
int JASystem::TDSPChannel::getNumBreak() {
|
|
int count = 0;
|
|
for (int i = 0; i < 64; i++) {
|
|
if (DSPCH[i].field_0x1 == 2) {
|
|
count++;
|
|
}
|
|
}
|
|
return count;
|
|
}
|