Files
tp/src/JSystem/JAudio2/JASBNKParser.cpp
T

322 lines
12 KiB
C++
Raw Normal View History

2021-04-01 02:07:58 +02:00
//
2021-03-28 22:49:05 +02:00
// Generated By: dol2asm
// Translation Unit: JASBNKParser
2021-04-01 02:07:58 +02:00
//
2021-03-28 22:49:05 +02:00
2021-04-01 02:07:58 +02:00
#include "JSystem/JAudio2/JASBNKParser.h"
2024-10-23 19:25:13 -04:00
#include "JSystem/JAudio2/JASBasicBank.h"
#include "JSystem/JAudio2/JASCalc.h"
#include "JSystem/JAudio2/JASDrumSet.h"
#include "JSystem/JAudio2/JASHeapCtrl.h"
2025-06-16 01:38:08 +03:00
#include "JSystem/JAudio2/JASChannel.h"
2024-10-23 19:25:13 -04:00
#include "JSystem/JKernel/JKRSolidHeap.h"
#include "JSystem/JSupport/JSupport.h"
2021-03-28 22:49:05 +02:00
2021-04-06 18:00:35 +02:00
/* 80299538-80299558 293E78 0020+00 0/0 1/1 0/0 .text createBank__12JASBNKParserFPCvP7JKRHeap */
2024-10-23 19:25:13 -04:00
JASBank* JASBNKParser::createBank(void const* stream, JKRHeap* heap) {
return createBasicBank(stream, heap);
2021-03-28 22:49:05 +02:00
}
2021-04-06 18:00:35 +02:00
/* 80451288-8045128C 000788 0004+00 1/1 0/0 0/0 .sbss sUsedHeapSize__12JASBNKParser */
2024-10-23 19:25:13 -04:00
u32 JASBNKParser::sUsedHeapSize;
2021-03-28 22:49:05 +02:00
2021-04-06 18:00:35 +02:00
/* 80299558-80299600 293E98 00A8+00 1/1 0/0 0/0 .text createBasicBank__12JASBNKParserFPCvP7JKRHeap
2021-04-01 02:07:58 +02:00
*/
2024-10-23 19:25:13 -04:00
JASBasicBank* JASBNKParser::createBasicBank(void const* stream, JKRHeap* heap) {
if (heap == NULL) {
heap = JASDram;
}
u32 free_size = heap->getFreeSize();
2025-06-16 01:38:08 +03:00
TFileHeader* filep = (TFileHeader*)stream;
JUT_ASSERT(59, filep->id == 'IBNK');
2024-10-23 19:25:13 -04:00
JASBasicBank* bank = NULL;
2025-06-16 01:38:08 +03:00
switch (filep->mVersion) {
2024-10-23 19:25:13 -04:00
case 0:
bank = Ver0::createBasicBank(stream, heap);
break;
case 1:
bank = Ver1::createBasicBank(stream, heap);
break;
}
sUsedHeapSize += free_size - heap->getFreeSize();
return bank;
2021-03-28 22:49:05 +02:00
}
2021-04-06 18:00:35 +02:00
/* 80299600-8029963C 293F40 003C+00 1/1 0/0 0/0 .text findChunk__Q212JASBNKParser4Ver1FPCvUl */
2024-10-23 19:25:13 -04:00
JASBNKParser::Ver1::TChunk* JASBNKParser::Ver1::findChunk(void const* stream, u32 id) {
TFileHeader* header = (TFileHeader*)stream;
void* end = (void*)((int)stream + header->mSize);
TChunk* chunk = (TChunk*)((int)stream + 0x20);
while (chunk < end) {
if (chunk->mID == id) {
return chunk;
}
chunk = (TChunk*)(((int)chunk + 0xb + chunk->mSize) & ~3);
}
return NULL;
2021-03-28 22:49:05 +02:00
}
2021-04-06 18:00:35 +02:00
/* 8029963C-80299A3C 293F7C 0400+00 1/1 0/0 0/0 .text
2021-04-01 02:07:58 +02:00
* createBasicBank__Q212JASBNKParser4Ver1FPCvP7JKRHeap */
2024-10-23 19:25:13 -04:00
JASBasicBank* JASBNKParser::Ver1::createBasicBank(void const* stream, JKRHeap* heap) {
if (heap == NULL) {
heap = JASDram;
}
2021-03-28 22:49:05 +02:00
2024-10-23 19:25:13 -04:00
JASBasicBank* bank = new (heap, 0) JASBasicBank();
if (bank == NULL) {
return NULL;
}
TEnvtChunk* envt_chunk = (TEnvtChunk*)findChunk(stream, 'ENVT');
TOscChunk* osc_chunk = (TOscChunk*)findChunk(stream, 'OSCT');
TListChunk* list_chunk = (TListChunk*)findChunk(stream, 'LIST');
2025-04-09 16:45:30 -04:00
u8* envt = new (heap, 2) u8[envt_chunk->mSize];
2024-10-23 19:25:13 -04:00
JASCalc::bcopy(envt_chunk->mData, envt, envt_chunk->mSize);
2025-04-09 16:45:30 -04:00
u32* ptr = &osc_chunk->mCount;
u32 count = *ptr++;
2024-10-23 19:25:13 -04:00
JASOscillator::Data* osc_data = new (heap, 0) JASOscillator::Data[count];
2025-04-09 16:45:30 -04:00
for (int i = 0; i < count; i++, ptr += sizeof(TOsc) >> 2) {
TOsc* osc = (TOsc*)ptr;
2024-10-23 19:25:13 -04:00
JASOscillator::Data* data = &osc_data[i];
data->mTarget = osc->mTarget;
data->_04 = osc->_08;
data->mScale = osc->mScale;
data->_14 = osc->_18;
2025-04-09 16:45:30 -04:00
data->mTable = (JASOscillator::Point*)(envt + osc->mTableOffset);
data->_0C = (JASOscillator::Point*)(envt + osc->_10);
2024-10-23 19:25:13 -04:00
}
bank->newInstTable(list_chunk->mCount, heap);
for (int i = 0; i < list_chunk->mCount; i++) {
if (list_chunk->mOffsets[i] != 0) {
2025-04-09 16:45:30 -04:00
u32* data = (u32*)((int)stream + list_chunk->mOffsets[i]);
switch (*data++) {
2024-10-23 19:25:13 -04:00
case 'Inst': {
JASBasicInst* inst = new (heap, 0) JASBasicInst();
2025-04-09 16:45:30 -04:00
u32 count = *data++;
2024-10-23 19:25:13 -04:00
for (int j = 0; j < count; j++) {
2025-04-09 16:45:30 -04:00
u32 index = *data++;
2024-10-23 19:25:13 -04:00
inst->setOsc(j, &osc_data[index]);
}
2025-04-09 16:45:30 -04:00
count = *data++;
2024-10-23 19:25:13 -04:00
for (int j = 0; j < count; j++) {
data++;
}
2025-04-09 16:45:30 -04:00
count = *data++;
2024-10-23 19:25:13 -04:00
inst->setKeyRegionCount(count, heap);
for (int j = 0; j < count; j++) {
JASBasicInst::TKeymap* keymap = inst->getKeyRegion(j);
keymap->setHighKey(*data >> 0x18);
u32 fVar4 = data[1];
keymap->field_0x4 = JSULoHalf(data[3]);
keymap->field_0x8 = *(f32*)&data[4];
keymap->field_0xc = *(f32*)&data[5];
data += 2;
for (int k = 0; k < fVar4; k++) {
data += 4;
}
}
inst->setVolume(*(f32*)&data[0]);
inst->setPitch(*(f32*)&data[1]);
bank->setInst(i, inst);
break;
}
case 'Perc': {
JASDrumSet* drum = new (heap, 0) JASDrumSet();
2025-04-09 16:45:30 -04:00
u32 count = *data++;
2024-10-23 19:25:13 -04:00
drum->newPercArray(count, heap);
for (int j = 0; j < count; j++) {
2025-04-09 16:45:30 -04:00
u32 offset = *data++;
2024-10-23 19:25:13 -04:00
if (offset != 0) {
JASDrumSet::TPerc* perc = new (heap, 0) JASDrumSet::TPerc();
u32* ptr = (u32*)((int)stream + offset);
TPercData* perc_data = (TPercData*)(ptr + 1);
perc->setVolume(perc_data->mVolume);
perc->setPitch(perc_data->mPitch);
perc->setPan((f32)perc_data->mPan / 127.0f);
perc->setRelease(perc_data->mRelease);
ptr = (u32*)&perc_data->field_0xc;
2025-04-09 16:45:30 -04:00
u32 count2 = *ptr++;
2024-10-23 19:25:13 -04:00
for (int k = 0; k < count2; k++) {
ptr++;
}
u32 pVar6 = ptr[0];
perc->field_0xe = JSULoHalf(ptr[2]);
perc->field_0x10 = *(f32*)&ptr[3];
perc->field_0x14 = *(f32*)&ptr[4];
for (int k = 0; k < pVar6; k++) {}
drum->setPerc(j, perc);
}
}
bank->setInst(i, drum);
break;
}
}
}
}
return bank;
}
2021-03-28 22:49:05 +02:00
2021-04-06 18:00:35 +02:00
/* 80299A3C-80299E68 29437C 042C+00 1/1 0/0 0/0 .text
2021-04-01 02:07:58 +02:00
* createBasicBank__Q212JASBNKParser4Ver0FPCvP7JKRHeap */
2024-10-23 19:25:13 -04:00
JASBasicBank* JASBNKParser::Ver0::createBasicBank(void const* stream, JKRHeap* heap) {
2025-04-09 16:45:30 -04:00
if (heap == NULL) {
heap = JASDram;
}
2025-06-16 01:38:08 +03:00
THeader const* header = (THeader*)stream;
2025-04-09 16:45:30 -04:00
JASBasicBank* bank = new (heap, 0) JASBasicBank();
if (bank == NULL) {
return NULL;
}
bank->newInstTable(0x80, heap);
for (int i = 0; i < 0x80; i++) {
2025-06-16 01:38:08 +03:00
TInst* tinst = header->mOffsets.mInstOffset[i].ptr(header);
2025-04-09 16:45:30 -04:00
if (tinst != NULL) {
2025-06-16 01:38:08 +03:00
JASBasicInst* instp = new (heap, 0) JASBasicInst();
JUT_ASSERT(368, instp != 0);
instp->setVolume(tinst->mVolume);
instp->setPitch(tinst->mPitch);
2025-04-09 16:45:30 -04:00
int osc_idx = 0;
for (int j = 0; j < 2; j++) {
2025-06-16 01:38:08 +03:00
TOsc* tosc = tinst->mOscOffset[j].ptr(header);
2025-04-09 16:45:30 -04:00
if (tosc != NULL) {
2025-06-16 01:38:08 +03:00
JASOscillator::Data* osc = findOscPtr(bank, header, tosc);
if (osc != NULL) {
instp->setOsc(osc_idx, osc);
2025-04-09 16:45:30 -04:00
} else {
2025-06-16 01:38:08 +03:00
osc = new (heap, 0) JASOscillator::Data();
JUT_ASSERT(386, osc != 0);
osc->mTarget = tosc->mTarget;
osc->_04 = tosc->field_0x4;
2025-04-09 16:45:30 -04:00
2025-06-16 01:38:08 +03:00
JASOscillator::Point* points = tosc->mPointOffset.ptr(header);
2025-04-09 16:45:30 -04:00
if (points != NULL) {
2025-06-16 01:38:08 +03:00
const JASOscillator::Point* endPtr = getOscTableEndPtr(points);
int size = endPtr - points;
2025-04-09 16:45:30 -04:00
JASOscillator::Point* table = new (heap, 0) JASOscillator::Point[size];
2025-06-16 01:38:08 +03:00
JUT_ASSERT(396, table != 0);
2025-04-09 16:45:30 -04:00
JASCalc::bcopy(points, table, size * sizeof(JASOscillator::Point));
2025-06-16 01:38:08 +03:00
osc->mTable = table;
2025-04-09 16:45:30 -04:00
} else {
2025-06-16 01:38:08 +03:00
osc->mTable = NULL;
2025-04-09 16:45:30 -04:00
}
2025-06-16 01:38:08 +03:00
points = tosc->field_0xc.ptr(header);
2025-04-09 16:45:30 -04:00
if (points != NULL) {
2025-06-16 01:38:08 +03:00
const JASOscillator::Point* endPtr = getOscTableEndPtr(points);
int size = endPtr - points;
2025-04-09 16:45:30 -04:00
JASOscillator::Point* table = new (heap, 0) JASOscillator::Point[size];
2025-06-16 01:38:08 +03:00
JUT_ASSERT(409, table != 0);
2025-04-09 16:45:30 -04:00
JASCalc::bcopy(points, table, size * sizeof(JASOscillator::Point));
2025-06-16 01:38:08 +03:00
osc->_0C = table;
2025-04-09 16:45:30 -04:00
} else {
2025-06-16 01:38:08 +03:00
osc->_0C = NULL;
2025-04-09 16:45:30 -04:00
}
2025-06-16 01:38:08 +03:00
osc->mScale = tosc->mScale;
osc->_14 = tosc->field_0x14;
instp->setOsc(osc_idx, osc);
2025-04-09 16:45:30 -04:00
}
osc_idx++;
}
}
2025-06-16 01:38:08 +03:00
instp->setKeyRegionCount(tinst->mKeyRegionCount, heap);
2025-04-09 16:45:30 -04:00
for (int j = 0; j < tinst->mKeyRegionCount; j++) {
2025-06-16 01:38:08 +03:00
JASBasicInst::TKeymap* keymap = instp->getKeyRegion(j);
TKeymap* tkeymap = tinst->mKeymapOffset[j].ptr(header);
2025-04-09 16:45:30 -04:00
keymap->setHighKey(tkeymap->mHighKey);
2025-06-16 01:38:08 +03:00
TVmap* tvmap = tkeymap->mVmapOffset.ptr(header);
2025-04-09 16:45:30 -04:00
keymap->field_0x4 = JSULoHalf(tvmap->field_0x4);
keymap->field_0x8 = tvmap->field_0x8;
keymap->field_0xc = tvmap->field_0xc;
}
2025-06-16 01:38:08 +03:00
bank->setInst(i, instp);
2025-04-09 16:45:30 -04:00
}
}
for (int i = 0; i < 12; i++) {
2025-06-16 01:38:08 +03:00
TPerc* tperc = header->mOffsets.mPercOffset[i].ptr(header);
2025-04-09 16:45:30 -04:00
if (tperc != NULL) {
2025-06-16 01:38:08 +03:00
JASDrumSet* setp = new (heap, 0) JASDrumSet();
JUT_ASSERT(509, setp != 0);
setp->newPercArray(0x80, heap);
2025-04-09 16:45:30 -04:00
for (int j = 0; j < 0x80; j++) {
2025-06-16 01:38:08 +03:00
TPmap* tpmap = tperc->mPmapOffset[j].ptr(header);
2025-04-09 16:45:30 -04:00
if (tpmap != NULL) {
2025-06-16 01:38:08 +03:00
JASDrumSet::TPerc* percp = new (heap, 0) JASDrumSet::TPerc();
JUT_ASSERT(519, percp);
percp->setVolume(tpmap->mVolume);
percp->setPitch(tpmap->mPitch);
2025-04-09 16:45:30 -04:00
if (tperc->mMagic == 'PER2') {
2025-06-16 01:38:08 +03:00
percp->setPan(tperc->mPan[j] / 127.0f);
percp->setRelease(tperc->mRelease[j]);
2025-04-09 16:45:30 -04:00
}
2025-06-16 01:38:08 +03:00
TVmap* vmap = tpmap->mVmapOffset.ptr(header);
percp->field_0xe = JSULoHalf(vmap->field_0x4);
percp->field_0x10 = vmap->field_0x8;
percp->field_0x14 = vmap->field_0xc;
setp->setPerc(j, percp);
2025-04-09 16:45:30 -04:00
}
}
2025-06-16 01:38:08 +03:00
bank->setInst(i + 0xe4, setp);
2025-04-09 16:45:30 -04:00
}
}
return bank;
2021-03-28 22:49:05 +02:00
}
2021-04-06 18:00:35 +02:00
/* 80299E68-80299F8C 2947A8 0124+00 1/1 0/0 0/0 .text
2021-04-01 02:07:58 +02:00
* findOscPtr__Q212JASBNKParser4Ver0FP12JASBasicBankPCQ312JASBNKParser4Ver07THeaderPCQ312JASBNKParser4Ver04TOsc
*/
2025-04-09 16:45:30 -04:00
JASOscillator::Data* JASBNKParser::Ver0::findOscPtr(JASBasicBank* bank, THeader const* header,
TOsc const* osc) {
TOffsetData const* data = &header->mOffsets;
for (int i = 0; i < 0x80; i++) {
TInst* tinst = data->mInstOffset[i].ptr(header);
if (tinst != NULL) {
for (int j = 0; j < 2; j++) {
TOsc* tosc = tinst->mOscOffset[j].ptr(header);
if (tosc == osc) {
JASInst* inst = bank->getInst(i);
if (inst != NULL) {
JASInstParam param;
inst->getParam(0x3c, 0x7f, &param);
if (j < param.field_0x1d) {
return param.field_0x14[j];
}
}
}
}
}
}
return NULL;
2021-03-28 22:49:05 +02:00
}
2021-04-06 18:00:35 +02:00
/* 80299F8C-80299FA0 2948CC 0014+00 1/1 0/0 0/0 .text
2021-04-01 02:07:58 +02:00
* getOscTableEndPtr__Q212JASBNKParser4Ver0FPCQ213JASOscillator5Point */
2025-04-09 16:45:30 -04:00
JASOscillator::Point const* JASBNKParser::Ver0::getOscTableEndPtr(JASOscillator::Point const* points) {
s16 tmp;
do {
tmp = points->_0;
points++;
} while (tmp <= 10);
return points;
2021-03-28 22:49:05 +02:00
}