summaryrefslogtreecommitdiff
path: root/src/code/audio_load.c
diff options
context:
space:
mode:
authorzelda2774 <69368340+zelda2774@users.noreply.github.com>2021-09-07 20:14:09 +0200
committerGitHub <noreply@github.com>2021-09-07 14:14:09 -0400
commit9c7d3688acf8f611dbc0d0b09c0a230b27e65c75 (patch)
treef44b617b31188e5b8ccb836d2c68a59b21ee14d8 /src/code/audio_load.c
parentd63ed0c17aeae4c0ccdec311212f151ab4200d5c (diff)
audio_load OK (#948)
* Match func_800DDB64 * Match func_800DC910 * remove stack comments * Move nop padding to ucode_disas * Partially label audio_synthesis To some extent copied from sm64. * cleanup * Reverb and ReverbBits have nothing to do with reverbs * review * naming * Revert "reduce diff" This reverts commit cd4ac24d8809f3f8e5b0f91788bffd72b47d15af. * Match func_800E283C * Audio_DmaSampleData * Warning fixes * func_800E4198 * func_800E4918 * Fix compiler warnings in z_camera/db_camera * cleanup * terminology * tiny bit of doc * undo permuter_settings change * Revert "Fix compiler warnings in z_camera/db_camera" This reverts commit dfdfac47f2bb972056eb70b4f1ffb4df907166a0. * review Co-authored-by: zelda2774 <zelda2774@invalid>
Diffstat (limited to 'src/code/audio_load.c')
-rw-r--r--src/code/audio_load.c632
1 files changed, 470 insertions, 162 deletions
diff --git a/src/code/audio_load.c b/src/code/audio_load.c
index 3fa8a0788..1146c3a1c 100644
--- a/src/code/audio_load.c
+++ b/src/code/audio_load.c
@@ -3,25 +3,26 @@
typedef enum { LOAD_STATUS_WAITING, LOAD_STATUS_START, LOAD_STATUS_LOADING, LOAD_STATUS_DONE } SyncLoadStatus;
-#define RELOC(v, base) (reloc = (void*)((u32)v + (u32)base))
+// opaque type for unpatched audio bank data (should maybe get rid of this?)
+typedef void AudioBankData;
/* forward declarations */
s32 func_800E217C(s32 playerIndex, s32, s32);
-unk_ldr* func_800E2454(u32 bankId);
+AudioBankData* func_800E2454(u32 bankId);
AudioBankSample* Audio_GetBankSample(s32 bankId, s32 sfxId);
void Audio_ProcessAsyncLoads(s32 arg0);
void Audio_HandleAsyncMsg(AsyncLoadReq* arg0, s32 arg1);
void Audio_UpdateAsyncReq(AsyncLoadReq* arg0, s32 arg1);
-void func_800E4198(s32, unk_ldr*, RelocInfo*, s32);
+void func_800E4198(s32, AudioBankData*, RelocInfo*, s32);
void Audio_SampleReloc(AudioBankSound* sound, u32, RelocInfo*);
void func_800E202C(s32 arg0);
u32 func_800E2338(u32 arg0, u32* arg1, s32 arg2);
-u8* func_800E2558(u32 tableType, u32 tableIdx, s32* didAllocate);
+void* func_800E2558(u32 tableType, u32 tableIdx, s32* didAllocate);
u32 Audio_GetTableIndex(s32 tableType, u32 tableIdx);
void* func_800E27A4(s32 tableType, s32 id);
void* Audio_GetLoadTable(s32 tableType);
void Audio_DMAFastCopy(u32 devAddr, u8* addr, u32 size, s32 handleType);
-void func_800E2BCC(u32 devAddr, u8* addr, u32 size, s32 handleType);
+void Audio_NoopCopy(u32 devAddr, u8* addr, u32 size, s32 handleType);
s32 Audio_DMA(OSIoMesg* mesg, u32 priority, s32 direction, u32 devAddr, void* ramAddr, u32 size, OSMesgQueue* reqQueue,
s32 handleType, const char* dmaFuncType);
void* Audio_AsyncLoadInner(s32 tableType, s32 arg1, s32 arg2, s32 arg3, OSMesgQueue* retQueue);
@@ -38,33 +39,36 @@ void Audio_ProcessSyncLoads(s32 resetStatus);
void func_800E38F8(s32 arg0, s32 arg1, s32 arg2, s32 arg3);
OSMesgQueue D_8016B6E0;
-u8 D_8016B6F8[0x40];
-u8* D_8016B738[0x12];
-u32 D_8016B780[8];
+OSMesg D_8016B6F8[0x10];
+s8* D_8016B738[0x12];
+s32 D_8016B780;
+s32 sAudioLoadPad[4];
void func_800E11F0(void) {
- s32 i;
+ u32 i;
- for (i = 0; i < gAudioContext.unk_2624; i++) {
+ for (i = 0; i < gAudioContext.sampleDmaListSize1; i++) {
SampleDmaReq* req = &gAudioContext.sampleDmaReqs[i];
- if (req->unk_0E != 0) {
- req->unk_0E--;
- if ((req->unk_0E) == 0) {
- req->unk_0D = gAudioContext.unk_282E;
- gAudioContext.unk_262C[gAudioContext.unk_282E] = i;
- gAudioContext.unk_282E++;
+
+ if (req->ttl != 0) {
+ req->ttl--;
+ if (req->ttl == 0) {
+ req->reuseIndex = gAudioContext.sampleDmaReuseQueue1WrPos;
+ gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1WrPos] = i;
+ gAudioContext.sampleDmaReuseQueue1WrPos++;
}
}
}
- for (i = gAudioContext.unk_2624; i < gAudioContext.sampleDmaReqCnt; i++) {
+ for (i = gAudioContext.sampleDmaListSize1; i < gAudioContext.sampleDmaReqCnt; i++) {
SampleDmaReq* req = &gAudioContext.sampleDmaReqs[i];
- if (req->unk_0E != 0) {
- req->unk_0E--;
- if (req->unk_0E == 0) {
- req->unk_0D = gAudioContext.unk_282F;
- gAudioContext.unk_272C[gAudioContext.unk_282F] = i;
- gAudioContext.unk_282F++;
+
+ if (req->ttl != 0) {
+ req->ttl--;
+ if (req->ttl == 0) {
+ req->reuseIndex = gAudioContext.sampleDmaReuseQueue2WrPos;
+ gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2WrPos] = i;
+ gAudioContext.sampleDmaReuseQueue2WrPos++;
}
}
}
@@ -72,7 +76,102 @@ void func_800E11F0(void) {
gAudioContext.unk_2628 = 0;
}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/Audio_DmaSampleData.s")
+void* Audio_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, s32 medium) {
+ s32 sp60;
+ SampleDmaReq* dma;
+ s32 hasDma = false;
+ u32 dmaDevAddr;
+ u32 pad;
+ u32 dmaIndex;
+ u32 transfer;
+ s32 bufferPos;
+ u32 i;
+
+ if (arg2 != 0 || *dmaIndexRef >= gAudioContext.sampleDmaListSize1) {
+ for (i = gAudioContext.sampleDmaListSize1; i < gAudioContext.sampleDmaReqCnt; i++) {
+ dma = &gAudioContext.sampleDmaReqs[i];
+ bufferPos = devAddr - dma->devAddr;
+ if (0 <= bufferPos && (u32)bufferPos <= dma->size - size) {
+ // We already have a DMA request for this memory range.
+ if (dma->ttl == 0 &&
+ gAudioContext.sampleDmaReuseQueue2RdPos != gAudioContext.sampleDmaReuseQueue2WrPos) {
+ // Move the DMA out of the reuse queue, by swapping it with the
+ // read pos, and then incrementing the read pos.
+ if (dma->reuseIndex != gAudioContext.sampleDmaReuseQueue2RdPos) {
+ gAudioContext.sampleDmaReuseQueue2[dma->reuseIndex] =
+ gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2RdPos];
+ gAudioContext
+ .sampleDmaReqs[gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2RdPos]]
+ .reuseIndex = dma->reuseIndex;
+ }
+ gAudioContext.sampleDmaReuseQueue2RdPos++;
+ }
+ dma->ttl = 32;
+ *dmaIndexRef = (u8)i;
+ return &dma->ramAddr[devAddr - dma->devAddr];
+ }
+ }
+
+ if (arg2 == 0) {
+ goto search_short_lived;
+ }
+
+ if (gAudioContext.sampleDmaReuseQueue2RdPos != gAudioContext.sampleDmaReuseQueue2WrPos && arg2 != 0) {
+ // Allocate a DMA from reuse queue 2, unless full.
+ dmaIndex = gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2RdPos];
+ gAudioContext.sampleDmaReuseQueue2RdPos++;
+ dma = gAudioContext.sampleDmaReqs + dmaIndex;
+ hasDma = true;
+ }
+ } else {
+ search_short_lived:
+ dma = gAudioContext.sampleDmaReqs + *dmaIndexRef;
+ i = 0;
+ again:
+ bufferPos = devAddr - dma->devAddr;
+ if (0 <= bufferPos && (u32)bufferPos <= dma->size - size) {
+ // We already have DMA for this memory range.
+ if (dma->ttl == 0) {
+ // Move the DMA out of the reuse queue, by swapping it with the
+ // read pos, and then incrementing the read pos.
+ if (dma->reuseIndex != gAudioContext.sampleDmaReuseQueue1RdPos) {
+ gAudioContext.sampleDmaReuseQueue1[dma->reuseIndex] =
+ gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1RdPos];
+ gAudioContext
+ .sampleDmaReqs[gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1RdPos]]
+ .reuseIndex = dma->reuseIndex;
+ }
+ gAudioContext.sampleDmaReuseQueue1RdPos++;
+ }
+ dma->ttl = 2;
+ return dma->ramAddr + (devAddr - dma->devAddr);
+ }
+ dma = gAudioContext.sampleDmaReqs + i++;
+ if (i <= gAudioContext.sampleDmaListSize1) {
+ goto again;
+ }
+ }
+
+ if (!hasDma) {
+ if (gAudioContext.sampleDmaReuseQueue1RdPos == gAudioContext.sampleDmaReuseQueue1WrPos) {
+ return NULL;
+ }
+ // Allocate a DMA from reuse queue 1.
+ dmaIndex = gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1RdPos++];
+ dma = gAudioContext.sampleDmaReqs + dmaIndex;
+ hasDma = true;
+ }
+
+ transfer = dma->size;
+ dmaDevAddr = devAddr & ~0xF;
+ dma->ttl = 3;
+ dma->devAddr = dmaDevAddr;
+ dma->sizeUnused = transfer;
+ Audio_DMA(&gAudioContext.currAudioFrameDmaIoMesgBufs[gAudioContext.curAudioFrameDmaCount++], OS_MESG_PRI_NORMAL,
+ OS_READ, dmaDevAddr, dma->ramAddr, transfer, &gAudioContext.currAudioFrameDmaQueue, medium, "SUPERDMA");
+ *dmaIndexRef = dmaIndex;
+ return (devAddr - dmaDevAddr) + dma->ramAddr;
+}
void func_800E1618(s32 arg0) {
SampleDmaReq* temp_s0;
@@ -94,25 +193,25 @@ void func_800E1618(s32 arg0) {
func_800DE238(temp_s0->ramAddr, gAudioContext.unk_288C);
temp_s0->size = gAudioContext.unk_288C;
temp_s0->devAddr = 0;
- temp_s0->unk_08 = 0;
- temp_s0->unk_0C = 0;
- temp_s0->unk_0E = 0;
+ temp_s0->sizeUnused = 0;
+ temp_s0->unused = 0;
+ temp_s0->ttl = 0;
gAudioContext.sampleDmaReqCnt++;
}
}
- for (i = 0; i < gAudioContext.sampleDmaReqCnt; i++) {
- gAudioContext.unk_262C[i] = i;
- gAudioContext.sampleDmaReqs[i].unk_0D = i;
+ for (i = 0; (u32)i < gAudioContext.sampleDmaReqCnt; i++) {
+ gAudioContext.sampleDmaReuseQueue1[i] = i;
+ gAudioContext.sampleDmaReqs[i].reuseIndex = i;
}
for (i = gAudioContext.sampleDmaReqCnt; i < 0x100; i++) {
- gAudioContext.unk_262C[i] = 0;
+ gAudioContext.sampleDmaReuseQueue1[i] = 0;
}
- gAudioContext.unk_282C = 0;
- gAudioContext.unk_282E = gAudioContext.sampleDmaReqCnt;
- gAudioContext.unk_2624 = gAudioContext.sampleDmaReqCnt;
+ gAudioContext.sampleDmaReuseQueue1RdPos = 0;
+ gAudioContext.sampleDmaReuseQueue1WrPos = gAudioContext.sampleDmaReqCnt;
+ gAudioContext.sampleDmaListSize1 = gAudioContext.sampleDmaReqCnt;
gAudioContext.unk_288C = gAudioContext.unk_2878;
for (j = 0; j < gAudioContext.maxSimultaneousNotes; j++) {
@@ -124,24 +223,24 @@ void func_800E1618(s32 arg0) {
func_800DE238(temp_s0->ramAddr, gAudioContext.unk_288C);
temp_s0->size = gAudioContext.unk_288C;
temp_s0->devAddr = 0U;
- temp_s0->unk_08 = 0;
- temp_s0->unk_0C = 0;
- temp_s0->unk_0E = 0;
+ temp_s0->sizeUnused = 0;
+ temp_s0->unused = 0;
+ temp_s0->ttl = 0;
gAudioContext.sampleDmaReqCnt++;
}
}
- for (i = gAudioContext.unk_2624; i < gAudioContext.sampleDmaReqCnt; i++) {
- gAudioContext.unk_272C[i - gAudioContext.unk_2624] = i;
- gAudioContext.sampleDmaReqs[i].unk_0D = i - gAudioContext.unk_2624;
+ for (i = gAudioContext.sampleDmaListSize1; (u32)i < gAudioContext.sampleDmaReqCnt; i++) {
+ gAudioContext.sampleDmaReuseQueue2[i - gAudioContext.sampleDmaListSize1] = i;
+ gAudioContext.sampleDmaReqs[i].reuseIndex = i - gAudioContext.sampleDmaListSize1;
}
for (i = gAudioContext.sampleDmaReqCnt; i < 0x100; i++) {
- gAudioContext.unk_272C[i] = gAudioContext.unk_2624;
+ gAudioContext.sampleDmaReuseQueue2[i] = gAudioContext.sampleDmaListSize1;
}
- gAudioContext.unk_282D = 0;
- gAudioContext.unk_282F = gAudioContext.sampleDmaReqCnt - gAudioContext.unk_2624;
+ gAudioContext.sampleDmaReuseQueue2RdPos = 0;
+ gAudioContext.sampleDmaReuseQueue2WrPos = gAudioContext.sampleDmaReqCnt - gAudioContext.sampleDmaListSize1;
}
s32 Audio_IsBankLoadComplete(s32 bankId) {
@@ -223,10 +322,10 @@ void Audio_InitAudioTable(AudioTable* table, u32 romAddr, u16 arg2) {
}
}
-unk_ldr* func_800E1B68(s32 arg0, u32* arg1) {
+AudioBankData* func_800E1B68(s32 arg0, u32* arg1) {
char pad[0x8];
s32 phi_s0;
- unk_ldr* sp28;
+ AudioBankData* sp28;
s32 phi_s1;
s32 phi_s2;
s32 i;
@@ -275,7 +374,7 @@ s32 func_800E1C78(AudioBankSample* sample, s32 arg1) {
}
if (sample->medium == 1) {
- func_800E2BCC(sample->sampleAddr, sampleAddr, sample->size, gAudioContext.audioTable->header.unk_02);
+ Audio_NoopCopy(sample->sampleAddr, sampleAddr, sample->size, gAudioContext.audioTable->header.unk_02);
} else {
Audio_DMAFastCopy(sample->sampleAddr, sampleAddr, sample->size, sample->medium);
}
@@ -361,7 +460,7 @@ void func_800E1F7C(s32 arg0) {
}
void func_800E202C(s32 arg0) {
- s32 i;
+ u32 i;
SoundMultiPool* pool = &gAudioContext.bankLoadedPool;
PersistentPool* persistent;
@@ -482,8 +581,8 @@ u32 func_800E2338(u32 arg0, u32* arg1, s32 arg2) {
}
}
-unk_ldr* func_800E2454(u32 bankId) {
- u8* temp_ret;
+AudioBankData* func_800E2454(u32 bankId) {
+ AudioBankData* temp_ret;
s32 unk02;
s32 unk03;
s32 sp38;
@@ -496,22 +595,22 @@ unk_ldr* func_800E2454(u32 bankId) {
unk02 = gAudioContext.ctlEntries[idx].unk_02;
unk03 = gAudioContext.ctlEntries[idx].unk_03;
- relocInfo.unk_00 = unk02;
- relocInfo.unk_04 = unk03;
- if (relocInfo.unk_00 != 0xFF) {
- relocInfo.unk_08 = func_800E2338(relocInfo.unk_00, &relocInfo.unk_10, 0);
+ relocInfo.index1 = unk02;
+ relocInfo.index2 = unk03;
+ if (relocInfo.index1 != 0xFF) {
+ relocInfo.baseAddr1 = func_800E2338(relocInfo.index1, &relocInfo.medium1, 0);
} else {
- relocInfo.unk_08 = 0;
+ relocInfo.baseAddr1 = 0;
}
if (unk03 != 0xFF) {
- relocInfo.unk_0C = func_800E2338(unk03, &relocInfo.unk_14, 0);
+ relocInfo.baseAddr2 = func_800E2338(unk03, &relocInfo.medium2, 0);
} else {
- relocInfo.unk_0C = 0;
+ relocInfo.baseAddr2 = 0;
}
temp_ret = func_800E2558(BANK_TABLE, bankId, &sp38);
- if (temp_ret == 0) {
+ if (temp_ret == NULL) {
return NULL;
}
if (sp38 == 1) {
@@ -521,7 +620,7 @@ unk_ldr* func_800E2454(u32 bankId) {
return temp_ret;
}
-u8* func_800E2558(u32 tableType, u32 tableIdx, s32* didAllocate) {
+void* func_800E2558(u32 tableType, u32 tableIdx, s32* didAllocate) {
u32 size;
AudioTable* table;
s32 pad;
@@ -529,7 +628,7 @@ u8* func_800E2558(u32 tableType, u32 tableIdx, s32* didAllocate) {
s32 status;
u32 romAddr;
s32 sp24;
- u8* ret;
+ void* ret;
u32 id;
id = Audio_GetTableIndex(tableType, tableIdx);
@@ -574,7 +673,7 @@ u8* func_800E2558(u32 tableType, u32 tableIdx, s32* didAllocate) {
*didAllocate = true;
if (sp40 == 1) {
- func_800E2BCC(romAddr, ret, size, (s16)table->header.unk_02);
+ Audio_NoopCopy(romAddr, ret, size, (s16)table->header.unk_02);
} else {
Audio_DMAFastCopy(romAddr, ret, size, sp40);
}
@@ -647,95 +746,82 @@ void* Audio_GetLoadTable(s32 tableType) {
#define BASE_OFFSET(x, off) (void*)((u32)(x) + (u32)(off))
-#ifdef NON_MATCHING
-void func_800E283C(s32 arg0, unk_ldr* arg1, RelocInfo* arg2) {
- s32 temp_v1_3;
- void* reloc;
+void func_800E283C(s32 bankId, AudioBankData* mem, RelocInfo* relocInfo) {
+ u32 reloc;
+ u32 reloc2;
+ Instrument* inst;
Drum* drum;
AudioBankSound* sfx;
- Instrument* inst;
- Instrument** end;
- Instrument** instIt;
- Drum** drums;
- s32 temp_a3;
- s32 sp50;
- s32 temp_s5;
s32 i;
+ s32 numDrums = gAudioContext.ctlEntries[bankId].numDrums;
+ s32 numInstruments = gAudioContext.ctlEntries[bankId].numInstruments;
+ s32 numSfx = gAudioContext.ctlEntries[bankId].numSfx;
+ void** ptrs = (void**)mem;
- temp_a3 = gAudioContext.ctlEntries[arg0].numDrums;
- sp50 = gAudioContext.ctlEntries[arg0].numInstruments;
- temp_s5 = gAudioContext.ctlEntries[arg0].numSfx;
-
- drums = arg1->drums;
- if ((drums != NULL) && (temp_a3 != 0)) {
- if (1) {
- arg1->drums = RELOC(drums, arg1);
- }
- for (i = 0; i < temp_a3; i++) {
- reloc = arg1->drums[i];
- if (reloc != NULL) {
- arg1->drums[i] = drum = RELOC(reloc, arg1);
+ reloc2 = ptrs[0];
+ if (1) {}
+ if ((reloc2 != 0) && (numDrums != 0)) {
+ ptrs[0] = BASE_OFFSET(reloc2, mem);
+ for (i = 0; i < numDrums; i++) {
+ reloc = ((Drum**)ptrs[0])[i];
+ if (reloc != 0) {
+ reloc = BASE_OFFSET(reloc, mem);
+ ((Drum**)ptrs[0])[i] = drum = reloc;
if (!drum->loaded) {
- Audio_SampleReloc(&drum->sound, arg1, arg2);
+ Audio_SampleReloc(&drum->sound, mem, relocInfo);
reloc = drum->envelope;
- drum->envelope = BASE_OFFSET(reloc, arg1);
+ drum->envelope = BASE_OFFSET(reloc, mem);
drum->loaded = 1;
}
}
}
}
- if ((arg1->sfx != NULL) && (temp_s5 != 0)) {
- if (1) {
- arg1->sfx = RELOC(arg1->sfx, arg1);
- }
- for (i = 0; i < temp_s5; i++) {
- sfx = &arg1->sfx[i];
- if ((sfx != NULL) && (sfx->sample != NULL)) {
- Audio_SampleReloc(sfx, arg1, arg2);
+ reloc2 = ptrs[1];
+ if (1) {}
+ if ((reloc2 != 0) && (numSfx != 0)) {
+ ptrs[1] = BASE_OFFSET(reloc2, mem);
+ for (i = 0; i < numSfx; i++) {
+ reloc = (AudioBankSound*)ptrs[1] + i;
+ if (reloc != 0) {
+ sfx = reloc;
+ if (sfx->sample != NULL) {
+ Audio_SampleReloc(sfx, mem, relocInfo);
+ }
}
}
}
- if (sp50 >= 0x7F) {
- sp50 = 0x7E;
+ if (numInstruments > 0x7E) {
+ numInstruments = 0x7E;
}
- temp_v1_3 = sp50 + 1;
- if (temp_v1_3 > 1) {
- instIt = arg1->instruments;
- end = instIt + temp_v1_3 - 2;
- do {
- if (*instIt != NULL) {
- inst = *instIt;
- *instIt = RELOC(inst, arg1);
- if (0) {}
- inst = *instIt;
- if (!inst->loaded) {
- if (inst->normalRangeLo != 0) {
- Audio_SampleReloc(&inst->lowNotesSound, arg1, arg2);
- }
- Audio_SampleReloc(&inst->normalNotesSound, arg1, arg2);
- if (inst->normalRangeHi != 0x7F) {
- Audio_SampleReloc(&inst->highNotesSound, arg1, arg2);
- }
-
- inst->loaded = 1;
- inst->envelope = RELOC(inst->envelope, arg1);
+ for (i = 2; i <= 2 + numInstruments - 1; i++) {
+ if (ptrs[i] != NULL) {
+ ptrs[i] = BASE_OFFSET(ptrs[i], mem);
+ inst = ptrs[i];
+ if (!inst->loaded) {
+ if (inst->normalRangeLo != 0) {
+ Audio_SampleReloc(&inst->lowNotesSound, mem, relocInfo);
+ }
+ Audio_SampleReloc(&inst->normalNotesSound, mem, relocInfo);
+ if (inst->normalRangeHi != 0x7F) {
+ Audio_SampleReloc(&inst->highNotesSound, mem, relocInfo);
}
+
+ reloc = inst->envelope;
+ inst->envelope = BASE_OFFSET(reloc, mem);
+ inst->loaded = 1;
}
- instIt++;
- } while (instIt <= end);
+ }
}
- gAudioContext.ctlEntries[arg0].drums = arg1->drums;
- gAudioContext.ctlEntries[arg0].soundEffects = arg1->sfx;
- gAudioContext.ctlEntries[arg0].instruments = arg1->instruments;
+ gAudioContext.ctlEntries[bankId].drums = ptrs[0];
+ gAudioContext.ctlEntries[bankId].soundEffects = ptrs[1];
+ gAudioContext.ctlEntries[bankId].instruments = (Instrument**)(ptrs + 2);
}
-#else
-void func_800E283C(s32 arg0, unk_ldr* arg1, RelocInfo* arg2);
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/func_800E283C.s")
-#endif
+
+#undef BASE_OFFSET
void Audio_DMAFastCopy(u32 devAddr, u8* addr, u32 size, s32 handleType) {
OSMesgQueue* msgQueue = &gAudioContext.unk_25E8;
@@ -761,7 +847,7 @@ void Audio_DMAFastCopy(u32 devAddr, u8* addr, u32 size, s32 handleType) {
}
}
-void func_800E2BCC(u32 devAddr, u8* addr, u32 size, s32 handleType) {
+void Audio_NoopCopy(u32 devAddr, u8* addr, u32 size, s32 handleType) {
}
s32 (*sDmaHandler)(OSPiHandle* handle, OSIoMesg* mb, s32 direction) = osEPiStartDma;
@@ -949,7 +1035,7 @@ void Audio_ContextInit(void* heap, u32 heapSize) {
{
s32 i;
- u8* ctxP = &gAudioContext;
+ u8* ctxP = (u8*)&gAudioContext;
for (i = sizeof(gAudioContext); i >= 0; i--) {
*ctxP++ = 0;
}
@@ -984,10 +1070,10 @@ void Audio_ContextInit(void* heap, u32 heapSize) {
gAudioContext.rspTask[0].task.t.data_size = 0;
gAudioContext.rspTask[1].task.t.data_size = 0;
osCreateMesgQueue(&gAudioContext.unk_25E8, &gAudioContext.unk_2600, 1);
- osCreateMesgQueue(&gAudioContext.unk_1ED0, gAudioContext.unk_1EE8, 0x40);
+ osCreateMesgQueue(&gAudioContext.currAudioFrameDmaQueue, gAudioContext.currAudioFrameDmaMesgBufs, 0x40);
osCreateMesgQueue(&gAudioContext.unk_1E20, gAudioContext.unk_1E38, 0x10);
osCreateMesgQueue(&gAudioContext.unk_1E78, gAudioContext.unk_1E90, 0x10);
- gAudioContext.sampleIoReqIdx = 0;
+ gAudioContext.curAudioFrameDmaCount = 0;
gAudioContext.sampleDmaReqCnt = 0;
gAudioContext.cartHandle = osCartRomInit();
@@ -1045,7 +1131,7 @@ void Audio_SyncLoadsInit(void) {
gAudioContext.syncLoads[1].status = 0;
}
-s32 Audio_SyncLoadSample(s32 arg0, s32 arg1, u8* isDone) {
+s32 Audio_SyncLoadSample(s32 arg0, s32 arg1, s8* isDone) {
AudioBankSample* sample;
AudioSyncLoad* syncLoad;
@@ -1193,7 +1279,7 @@ void func_800E3874(AudioSyncLoad* arg0, s32 size) {
void func_800E38F8(s32 arg0, s32 arg1, s32 arg2, s32 arg3) {
}
-s32 Audio_SyncLoadSeq(s32 seqIdx, u8* ramAddr, u8* isDone) {
+s32 Audio_SyncLoadSeq(s32 seqIdx, u8* ramAddr, s8* isDone) {
AudioSyncLoad* syncLoad;
SequenceTable* seqTable;
u32 size;
@@ -1291,7 +1377,7 @@ AsyncLoadReq* Audio_InitAsyncReq(u32 devAddr, void* ramAddr, u32 size, s32 arg3,
loadReq->unk_01 = 3;
loadReq->unk_02 = arg3;
loadReq->retMsg = retMsg;
- osCreateMesgQueue(&loadReq->msgQueue, loadReq->msg, ARRAY_COUNT(loadReq->msg));
+ osCreateMesgQueue(&loadReq->msgQueue, &loadReq->msg, 1);
return loadReq;
}
@@ -1306,8 +1392,8 @@ void Audio_ProcessAsyncLoads(s32 resetStatus) {
if (gAudioContext.curAsyncReq == NULL) {
if (resetStatus != 0) {
do {
- } while (osRecvMesg(&gAudioContext.asyncLoadQueue, &loadReq, OS_MESG_NOBLOCK) != -1);
- } else if (osRecvMesg(&gAudioContext.asyncLoadQueue, &loadReq, OS_MESG_NOBLOCK) == -1) {
+ } while (osRecvMesg(&gAudioContext.asyncLoadQueue, (OSMesg*)&loadReq, OS_MESG_NOBLOCK) != -1);
+ } else if (osRecvMesg(&gAudioContext.asyncLoadQueue, (OSMesg*)&loadReq, OS_MESG_NOBLOCK) == -1) {
gAudioContext.curAsyncReq = NULL;
} else {
gAudioContext.curAsyncReq = loadReq;
@@ -1352,10 +1438,10 @@ void Audio_AsyncReqDone(AsyncLoadReq* loadReq) {
b2 = ASYNC_B2(retMsg);
t1 = gAudioContext.ctlEntries[b2].unk_02;
t2 = gAudioContext.ctlEntries[b2].unk_03;
- sp30.unk_00 = t1;
- sp30.unk_04 = t2;
- sp30.unk_08 = t1 != 0xFF ? func_800E2318(t1, &sp30.unk_10) : 0;
- sp30.unk_0C = t2 != 0xFF ? func_800E2318(t2, &sp30.unk_14) : 0;
+ sp30.index1 = t1;
+ sp30.index2 = t2;
+ sp30.baseAddr1 = t1 != 0xFF ? func_800E2318(t1, &sp30.medium1) : 0;
+ sp30.baseAddr2 = t2 != 0xFF ? func_800E2318(t2, &sp30.medium2) : 0;
Audio_SetBankLoadStatus(b2, ASYNC_B3(retMsg));
func_800E4198(b2, loadReq->unk_04, &sp30, 1);
break;
@@ -1421,6 +1507,8 @@ void func_800E3FB4(AsyncLoadReq* req, u32 size) {
void func_800E4044(u32 devAddr, void* ramAddr, u32 size, s16 arg3) {
}
+#define RELOC(v, base) (reloc = (void*)((u32)(v) + (u32)(base)))
+
void Audio_SampleReloc(AudioBankSound* sound, u32 arg1, RelocInfo* arg2) {
AudioBankSample* sample;
void* reloc;
@@ -1432,12 +1520,12 @@ void Audio_SampleReloc(AudioBankSound* sound, u32 arg1, RelocInfo* arg2) {
sample->book = RELOC(sample->book, arg1);
switch (sample->medium) {
case 0:
- sample->sampleAddr = RELOC(sample->sampleAddr, arg2->unk_08);
- sample->medium = arg2->unk_10;
+ sample->sampleAddr = RELOC(sample->sampleAddr, arg2->baseAddr1);
+ sample->medium = arg2->medium1;
break;
case 1:
- sample->sampleAddr = RELOC(sample->sampleAddr, arg2->unk_0C);
- sample->medium = arg2->unk_14;
+ sample->sampleAddr = RELOC(sample->sampleAddr, arg2->baseAddr2);
+ sample->medium = arg2->medium2;
break;
case 2:
case 3:
@@ -1446,13 +1534,107 @@ void Audio_SampleReloc(AudioBankSound* sound, u32 arg1, RelocInfo* arg2) {
sample->unk_bits25 = 1;
if (sample->unk_bits26 && (sample->medium != 0)) {
- gAudioContext.unk_B68[gAudioContext.unk_1768++] = sample;
+ gAudioContext.unk_0B68[gAudioContext.unk_1768++] = sample;
}
}
}
}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/func_800E4198.s")
+#undef RELOC
+
+void func_800E4198(s32 bankId, AudioBankData* mem, RelocInfo* relocInfo, s32 arg3) {
+ AudioStruct0D68* item;
+ AudioStruct0D68* item2;
+ AudioBankSample* sample;
+ s32 count;
+ s32 nChunks;
+ u8* addr;
+ s32 sp4C;
+ s32 i;
+
+ sp4C = false;
+ if (gAudioContext.unk_176C != 0) {
+ sp4C = true;
+ } else {
+ D_8016B780 = 0;
+ }
+ gAudioContext.unk_1768 = 0;
+ func_800E283C(bankId, mem, relocInfo);
+
+ count = 0;
+ for (i = 0; i < gAudioContext.unk_1768; i++) {
+ count += ALIGN16(gAudioContext.unk_0B68[i]->size);
+ }
+ if (count && count) {}
+
+ for (i = 0; i < gAudioContext.unk_1768; i++) {
+ if (gAudioContext.unk_176C == 120) {
+ break;
+ }
+
+ sample = gAudioContext.unk_0B68[i];
+ addr = NULL;
+ switch (arg3) {
+ case 0:
+ if (sample->medium == relocInfo->medium1) {
+ addr = func_800E05C4(sample->size, relocInfo->index1, sample->sampleAddr, sample->medium, 1);
+ } else if (sample->medium == relocInfo->medium2) {
+ addr = func_800E05C4(sample->size, relocInfo->index2, sample->sampleAddr, sample->medium, 1);
+ } else if (sample->medium == 3) {
+ addr = func_800E05C4(sample->size, 0xFE, sample->sampleAddr, sample->medium, 1);
+ }
+ break;
+
+ case 1:
+ if (sample->medium == relocInfo->medium1) {
+ addr = func_800E05C4(sample->size, relocInfo->index1, sample->sampleAddr, sample->medium, 0);
+ } else if (sample->medium == relocInfo->medium2) {
+ addr = func_800E05C4(sample->size, relocInfo->index2, sample->sampleAddr, sample->medium, 0);
+ } else if (sample->medium == 3) {
+ addr = func_800E05C4(sample->size, 0xFE, sample->sampleAddr, sample->medium, 0);
+ }
+ break;
+ }
+ if (addr == NULL) {
+ continue;
+ }
+
+ switch (arg3) {
+ case 0:
+ if (sample->medium == 1) {
+ Audio_NoopCopy((u32)sample->sampleAddr, addr, sample->size,
+ gAudioContext.audioTable->header.unk_02);
+ sample->sampleAddr = addr;
+ sample->medium = 0;
+ } else {
+ Audio_DMAFastCopy((u32)sample->sampleAddr, addr, sample->size, sample->medium);
+ sample->sampleAddr = addr;
+ sample->medium = 0;
+ }
+ if (sample->medium == 3) {}
+ break;
+
+ case 1:
+ item = &gAudioContext.unk_0D68[gAudioContext.unk_176C];
+ item->sample = sample;
+ item->ramAddr = addr;
+ item->encodedInfo = (gAudioContext.unk_176C << 24) | 0xFFFFFF;
+ item->isFree = false;
+ item->endAndMediumKey = (u32)sample->sampleAddr + sample->size + sample->medium;
+ gAudioContext.unk_176C++;
+ break;
+ }
+ }
+
+ gAudioContext.unk_1768 = 0;
+ if (gAudioContext.unk_176C != 0 && !sp4C) {
+ item2 = &gAudioContext.unk_0D68[gAudioContext.unk_176C - 1];
+ sample = item2->sample;
+ nChunks = (sample->size >> 12) + 1;
+ Audio_InitAsyncReq((u32)sample->sampleAddr, item2->ramAddr, sample->size, sample->medium, nChunks,
+ &gAudioContext.unk_1E78, item2->encodedInfo);
+ }
+}
s32 func_800E4590(s32 resetStatus) {
AudioBankSample* sample;
@@ -1564,13 +1746,139 @@ void func_800E48C0(AudioBankSound* sound) {
AudioBankSample* sample = sound->sample;
if ((sample->size != 0) && (sample->unk_bits26) && (sample->medium)) {
- gAudioContext.unk_B68[gAudioContext.unk_1768++] = sample;
+ gAudioContext.unk_0B68[gAudioContext.unk_1768++] = sample;
}
}
-// large
-void func_800E4918(s32, s32, RelocInfo*);
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/func_800E4918.s")
+void func_800E4918(s32 bankId, s32 arg1, RelocInfo* relocInfo) {
+ s32 numDrums;
+ s32 numInstruments;
+ s32 numSfx;
+ Drum* drum;
+ Instrument* instrument;
+ AudioBankSound* sound;
+ AudioStruct0D68* item;
+ AudioStruct0D68* item2;
+ u8* addr;
+ s32 count;
+ s32 i;
+ AudioBankSample* sample;
+ s32 sp44;
+ s32 nChunks;
+
+ sp44 = false;
+ if (gAudioContext.unk_176C != 0) {
+ sp44 = true;
+ }
+ gAudioContext.unk_1768 = 0;
+
+ numDrums = gAudioContext.ctlEntries[bankId].numDrums;
+ numInstruments = gAudioContext.ctlEntries[bankId].numInstruments;
+ numSfx = gAudioContext.ctlEntries[bankId].numSfx;
+
+ for (i = 0; i < numInstruments; i++) {
+ instrument = Audio_GetInstrumentInner(bankId, i);
+ if (instrument != NULL) {
+ if (instrument->normalRangeLo != 0) {
+ func_800E48C0(&instrument->lowNotesSound);
+ }
+ if (instrument->normalRangeHi != 0x7F) {
+ func_800E48C0(&instrument->highNotesSound);
+ }
+ func_800E48C0(&instrument->normalNotesSound);
+ }
+ }
+
+ for (i = 0; i < numDrums; i++) {
+ drum = Audio_GetDrum(bankId, i);
+ if (drum != NULL) {
+ func_800E48C0(&drum->sound);
+ }
+ }
+
+ for (i = 0; i < numSfx; i++) {
+ sound = Audio_GetSfx(bankId, i);
+ if (sound != NULL) {
+ func_800E48C0(sound);
+ }
+ }
+
+ if (gAudioContext.unk_1768 == 0) {
+ return;
+ }
+
+ count = 0;
+ for (i = 0; i < gAudioContext.unk_1768; i++) {
+ count += ALIGN16(gAudioContext.unk_0B68[i]->size);
+ }
+ if (count) {}
+
+ for (i = 0; i < gAudioContext.unk_1768; i++) {
+ if (gAudioContext.unk_176C == 120) {
+ break;
+ }
+
+ sample = gAudioContext.unk_0B68[i];
+ if (sample->medium == 0) {
+ continue;
+ }
+
+ switch (arg1) {
+ case 0:
+ if (sample->medium == relocInfo->medium1) {
+ addr = func_800E05C4(sample->size, relocInfo->index1, sample->sampleAddr, sample->medium, 1);
+ } else if (sample->medium == relocInfo->medium2) {
+ addr = func_800E05C4(sample->size, relocInfo->index2, sample->sampleAddr, sample->medium, 1);
+ }
+ break;
+
+ case 1:
+ if (sample->medium == relocInfo->medium1) {
+ addr = func_800E05C4(sample->size, relocInfo->index1, sample->sampleAddr, sample->medium, 0);
+ } else if (sample->medium == relocInfo->medium2) {
+ addr = func_800E05C4(sample->size, relocInfo->index2, sample->sampleAddr, sample->medium, 0);
+ }
+ break;
+ }
+ if (addr == NULL) {
+ continue;
+ }
+
+ switch (arg1) {
+ case 0:
+ if (sample->medium == 1) {
+ Audio_NoopCopy((u32)sample->sampleAddr, addr, sample->size,
+ gAudioContext.audioTable->header.unk_02);
+ sample->sampleAddr = addr;
+ sample->medium = 0;
+ } else {
+ Audio_DMAFastCopy((u32)sample->sampleAddr, addr, sample->size, sample->medium);
+ sample->sampleAddr = addr;
+ sample->medium = 0;
+ }
+ break;
+
+ case 1:
+ item = &gAudioContext.unk_0D68[gAudioContext.unk_176C];
+ item->sample = sample;
+ item->ramAddr = addr;
+ item->encodedInfo = (gAudioContext.unk_176C << 24) | 0xFFFFFF;
+ item->isFree = false;
+ item->endAndMediumKey = (u32)sample->sampleAddr + sample->size + sample->medium;
+ gAudioContext.unk_176C++;
+ break;
+ }
+ }
+
+ gAudioContext.unk_1768 = 0;
+ if (gAudioContext.unk_176C != 0 && !sp44) {
+ item2 = &gAudioContext.unk_0D68[gAudioContext.unk_176C - 1];
+ sample = item2->sample;
+ nChunks = (sample->size >> 12) + 1;
+ Audio_InitAsyncReq((u32)sample->sampleAddr, item2->ramAddr, sample->size, sample->medium, nChunks,
+ &gAudioContext.unk_1E78, item2->encodedInfo);
+ }
+}
void func_800E4D94(void) {
s32 pad;
@@ -1584,17 +1892,17 @@ void func_800E4D94(void) {
RelocInfo sp4C;
if (gAudioContext.unk_2D60[i].poolIndex == 1) {
temp_s2 = Audio_GetTableIndex(BANK_TABLE, gAudioContext.unk_2D60[i].id);
- sp4C.unk_00 = gAudioContext.ctlEntries[temp_s2].unk_02;
- sp4C.unk_04 = gAudioContext.ctlEntries[temp_s2].unk_03;
+ sp4C.index1 = gAudioContext.ctlEntries[temp_s2].unk_02;
+ sp4C.index2 = gAudioContext.ctlEntries[temp_s2].unk_03;
- if (sp4C.unk_00 != 0xFF) {
- sp4C.unk_00 = Audio_GetTableIndex(AUDIO_TABLE, sp4C.unk_00);
- sp4C.unk_10 = audioTable->entries[sp4C.unk_00].unk_08;
+ if (sp4C.index1 != 0xFF) {
+ sp4C.index1 = Audio_GetTableIndex(AUDIO_TABLE, sp4C.index1);
+ sp4C.medium1 = audioTable->entries[sp4C.index1].unk_08;
}
- if (sp4C.unk_04 != 0xFF) {
- sp4C.unk_04 = Audio_GetTableIndex(AUDIO_TABLE, sp4C.unk_04);
- sp4C.unk_14 = audioTable->entries[sp4C.unk_04].unk_08;
+ if (sp4C.index2 != 0xFF) {
+ sp4C.index2 = Audio_GetTableIndex(AUDIO_TABLE, sp4C.index2);
+ sp4C.medium2 = audioTable->entries[sp4C.index2].unk_08;
}
func_800E4918(temp_s2, 0, &sp4C);
}
@@ -1610,7 +1918,7 @@ void func_800E4EDC(void) {
void func_800E4EE4(void) {
}
-void func_800E4EEC(s32 tableType, s32 arg1, u8* arg2) {
+void func_800E4EEC(s32 tableType, s32 arg1, s8* arg2) {
static u32 D_801304DC = 0;
D_8016B738[D_801304DC] = arg2;
Audio_AsyncLoad(tableType, arg1, 0, D_801304DC, &D_8016B6E0);
@@ -1623,10 +1931,10 @@ void func_800E4EEC(s32 tableType, s32 arg1, u8* arg2) {
void func_800E4F58(void) {
u32 pad;
u32 sp20;
- u8* temp_v0;
+ s8* temp_v0;
- if (osRecvMesg(&D_8016B6E0, &sp20, OS_MESG_NOBLOCK) != -1) {
- pad = sp20 >> 0x18;
+ if (osRecvMesg(&D_8016B6E0, (OSMesg*)&sp20, OS_MESG_NOBLOCK) != -1) {
+ pad = sp20 >> 24;
temp_v0 = D_8016B738[pad];
if (temp_v0 != NULL) {
*temp_v0 = 0;
@@ -1635,5 +1943,5 @@ void func_800E4F58(void) {
}
void func_800E4FB0(void) {
- osCreateMesgQueue(&D_8016B6E0, &D_8016B6F8, 0x10);
+ osCreateMesgQueue(&D_8016B6E0, D_8016B6F8, 0x10);
}