2021-07-27 23:44:58 +00:00
|
|
|
#include "ultra64.h"
|
|
|
|
#include "global.h"
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
#define MK_ASYNC_MSG(retData, tableType, id, loadStatus) \
|
|
|
|
(((retData) << 24) | ((tableType) << 16) | ((id) << 8) | (loadStatus))
|
2021-11-07 16:58:50 +00:00
|
|
|
#define ASYNC_TBLTYPE(v) ((u8)(v >> 16))
|
|
|
|
#define ASYNC_ID(v) ((u8)(v >> 8))
|
2022-06-03 19:59:02 +00:00
|
|
|
#define ASYNC_LOAD_STATUS(v) ((u8)(v >> 0))
|
2021-11-07 16:58:50 +00:00
|
|
|
|
|
|
|
typedef enum {
|
2022-06-03 19:59:02 +00:00
|
|
|
/* 0 */ SLOW_LOAD_STATE_WAITING,
|
|
|
|
/* 1 */ SLOW_LOAD_STATE_START,
|
|
|
|
/* 2 */ SLOW_LOAD_STATE_LOADING,
|
|
|
|
/* 3 */ SLOW_LOAD_STATE_DONE
|
|
|
|
} SlowLoadState;
|
2021-11-07 16:58:50 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* 0x00 */ s32 sampleBankId1;
|
|
|
|
/* 0x04 */ s32 sampleBankId2;
|
|
|
|
/* 0x08 */ s32 baseAddr1;
|
|
|
|
/* 0x0C */ s32 baseAddr2;
|
|
|
|
/* 0x10 */ u32 medium1;
|
|
|
|
/* 0x14 */ u32 medium2;
|
2022-06-12 23:33:56 +00:00
|
|
|
} SampleBankRelocInfo; // size = 0x18
|
2021-11-07 16:58:50 +00:00
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
// opaque type for soundfont data loaded into ram (should maybe get rid of this?)
|
2021-11-07 16:58:50 +00:00
|
|
|
typedef void SoundFontData;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
|
|
|
/* forward declarations */
|
2022-06-20 20:31:53 +00:00
|
|
|
s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2);
|
2021-11-07 16:58:50 +00:00
|
|
|
SoundFontData* AudioLoad_SyncLoadFont(u32 fontId);
|
2022-06-19 14:31:08 +00:00
|
|
|
Sample* AudioLoad_GetFontSample(s32 fontId, s32 instId);
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_ProcessAsyncLoads(s32 resetStatus);
|
|
|
|
void AudioLoad_ProcessAsyncLoadUnkMedium(AudioAsyncLoad* asyncLoad, s32 resetStatus);
|
|
|
|
void AudioLoad_ProcessAsyncLoad(AudioAsyncLoad* asyncLoad, s32 resetStatus);
|
2022-06-12 23:33:56 +00:00
|
|
|
void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData, SampleBankRelocInfo* sampleBankReloc,
|
2022-06-20 20:31:53 +00:00
|
|
|
s32 isAsync);
|
2022-06-19 14:31:08 +00:00
|
|
|
void AudioLoad_RelocateSample(TunedSample* tunedSample, SoundFontData* fontData, SampleBankRelocInfo* sampleBankReloc);
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_DiscardFont(s32 fontId);
|
|
|
|
u32 AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 noLoad);
|
2022-06-20 20:31:53 +00:00
|
|
|
void* AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate);
|
|
|
|
u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 id);
|
2021-11-07 16:58:50 +00:00
|
|
|
void* AudioLoad_SearchCaches(s32 tableType, s32 id);
|
|
|
|
AudioTable* AudioLoad_GetLoadTable(s32 tableType);
|
2022-06-20 20:31:53 +00:00
|
|
|
void AudioLoad_SyncDma(u32 devAddr, u8* ramAddr, u32 size, s32 medium);
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_SyncDmaUnkMedium(u32 devAddr, u8* addr, u32 size, s32 unkMediumParam);
|
|
|
|
s32 AudioLoad_Dma(OSIoMesg* mesg, u32 priority, s32 direction, u32 devAddr, void* ramAddr, u32 size,
|
|
|
|
OSMesgQueue* reqQueue, s32 medium, const char* dmaFuncType);
|
|
|
|
void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData, OSMesgQueue* retQueue);
|
|
|
|
AudioAsyncLoad* AudioLoad_StartAsyncLoadUnkMedium(s32 unkMediumParam, u32 devAddr, void* ramAddr, s32 size, s32 medium,
|
|
|
|
s32 nChunks, OSMesgQueue* retQueue, s32 retMsg);
|
|
|
|
AudioAsyncLoad* AudioLoad_StartAsyncLoad(u32 devAddr, void* ramAddr, u32 size, s32 medium, s32 nChunks,
|
|
|
|
OSMesgQueue* retQueue, s32 retMsg);
|
|
|
|
void AudioLoad_AsyncDma(AudioAsyncLoad* asyncLoad, u32 size);
|
|
|
|
void AudioLoad_AsyncDmaUnkMedium(u32 devAddr, void* ramAddr, u32 size, s16 arg3);
|
|
|
|
u8* AudioLoad_SyncLoadSeq(s32 seqId);
|
|
|
|
s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus);
|
|
|
|
void AudioLoad_DmaSlowCopy(AudioSlowLoad* slowLoad, s32 size);
|
|
|
|
void AudioLoad_ProcessSlowLoads(s32 resetStatus);
|
|
|
|
void AudioLoad_DmaSlowCopyUnkMedium(s32 devAddr, u8* ramAddr, s32 size, s32 arg3);
|
|
|
|
|
|
|
|
OSMesgQueue sScriptLoadQueue;
|
2022-04-09 00:20:23 +00:00
|
|
|
OSMesg sScriptLoadMsgBuf[16];
|
2021-11-07 16:58:50 +00:00
|
|
|
s8* sScriptLoadDonePointers[0x10];
|
|
|
|
s32 sAudioLoadPad1[2]; // file padding
|
|
|
|
|
2021-09-07 18:14:09 +00:00
|
|
|
s32 D_8016B780;
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 sAudioLoadPad2[4]; // double file padding?
|
|
|
|
|
|
|
|
DmaHandler sDmaHandler = osEPiStartDma;
|
|
|
|
void* sUnusedHandler = NULL;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 gAudioContextInitalized = false;
|
|
|
|
|
|
|
|
void AudioLoad_DecreaseSampleDmaTtls(void) {
|
2021-09-07 18:14:09 +00:00
|
|
|
u32 i;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-09-07 18:14:09 +00:00
|
|
|
for (i = 0; i < gAudioContext.sampleDmaListSize1; i++) {
|
2021-11-07 16:58:50 +00:00
|
|
|
SampleDma* dma = &gAudioContext.sampleDmas[i];
|
2021-09-07 18:14:09 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (dma->ttl != 0) {
|
|
|
|
dma->ttl--;
|
|
|
|
if (dma->ttl == 0) {
|
|
|
|
dma->reuseIndex = gAudioContext.sampleDmaReuseQueue1WrPos;
|
2021-09-07 18:14:09 +00:00
|
|
|
gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1WrPos] = i;
|
|
|
|
gAudioContext.sampleDmaReuseQueue1WrPos++;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = gAudioContext.sampleDmaListSize1; i < gAudioContext.sampleDmaCount; i++) {
|
|
|
|
SampleDma* dma = &gAudioContext.sampleDmas[i];
|
2021-09-07 18:14:09 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (dma->ttl != 0) {
|
|
|
|
dma->ttl--;
|
|
|
|
if (dma->ttl == 0) {
|
|
|
|
dma->reuseIndex = gAudioContext.sampleDmaReuseQueue2WrPos;
|
2021-09-07 18:14:09 +00:00
|
|
|
gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2WrPos] = i;
|
|
|
|
gAudioContext.sampleDmaReuseQueue2WrPos++;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.unused2628 = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void* AudioLoad_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, s32 medium) {
|
|
|
|
s32 pad1;
|
|
|
|
SampleDma* dma;
|
2021-09-07 18:14:09 +00:00
|
|
|
s32 hasDma = false;
|
|
|
|
u32 dmaDevAddr;
|
2021-11-07 16:58:50 +00:00
|
|
|
u32 pad2;
|
2021-09-07 18:14:09 +00:00
|
|
|
u32 dmaIndex;
|
|
|
|
u32 transfer;
|
|
|
|
s32 bufferPos;
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
if (arg2 != 0 || *dmaIndexRef >= gAudioContext.sampleDmaListSize1) {
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = gAudioContext.sampleDmaListSize1; i < gAudioContext.sampleDmaCount; i++) {
|
|
|
|
dma = &gAudioContext.sampleDmas[i];
|
2021-09-07 18:14:09 +00:00
|
|
|
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
|
2021-11-07 16:58:50 +00:00
|
|
|
.sampleDmas[gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2RdPos]]
|
2021-09-07 18:14:09 +00:00
|
|
|
.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++;
|
2021-11-07 16:58:50 +00:00
|
|
|
dma = gAudioContext.sampleDmas + dmaIndex;
|
2021-09-07 18:14:09 +00:00
|
|
|
hasDma = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
search_short_lived:
|
2021-11-07 16:58:50 +00:00
|
|
|
dma = gAudioContext.sampleDmas + *dmaIndexRef;
|
2021-09-07 18:14:09 +00:00
|
|
|
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
|
2021-11-07 16:58:50 +00:00
|
|
|
.sampleDmas[gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1RdPos]]
|
2021-09-07 18:14:09 +00:00
|
|
|
.reuseIndex = dma->reuseIndex;
|
|
|
|
}
|
|
|
|
gAudioContext.sampleDmaReuseQueue1RdPos++;
|
|
|
|
}
|
|
|
|
dma->ttl = 2;
|
|
|
|
return dma->ramAddr + (devAddr - dma->devAddr);
|
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
dma = gAudioContext.sampleDmas + i++;
|
2021-09-07 18:14:09 +00:00
|
|
|
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++];
|
2021-11-07 16:58:50 +00:00
|
|
|
dma = gAudioContext.sampleDmas + dmaIndex;
|
2021-09-07 18:14:09 +00:00
|
|
|
hasDma = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
transfer = dma->size;
|
|
|
|
dmaDevAddr = devAddr & ~0xF;
|
|
|
|
dma->ttl = 3;
|
|
|
|
dma->devAddr = dmaDevAddr;
|
|
|
|
dma->sizeUnused = transfer;
|
2022-04-09 00:20:23 +00:00
|
|
|
AudioLoad_Dma(&gAudioContext.currAudioFrameDmaIoMsgBuf[gAudioContext.curAudioFrameDmaCount++], OS_MESG_PRI_NORMAL,
|
2021-11-07 16:58:50 +00:00
|
|
|
OS_READ, dmaDevAddr, dma->ramAddr, transfer, &gAudioContext.currAudioFrameDmaQueue, medium,
|
|
|
|
"SUPERDMA");
|
2021-09-07 18:14:09 +00:00
|
|
|
*dmaIndexRef = dmaIndex;
|
|
|
|
return (devAddr - dmaDevAddr) + dma->ramAddr;
|
|
|
|
}
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
void AudioLoad_InitSampleDmaBuffers(s32 numNotes) {
|
2021-11-07 16:58:50 +00:00
|
|
|
SampleDma* dma;
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 i;
|
|
|
|
s32 t2;
|
2021-08-12 19:37:37 +00:00
|
|
|
s32 j;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.sampleDmaBufSize = gAudioContext.sampleDmaBufSize1;
|
|
|
|
gAudioContext.sampleDmas =
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioHeap_Alloc(&gAudioContext.miscPool,
|
2021-11-07 16:58:50 +00:00
|
|
|
4 * gAudioContext.numNotes * sizeof(SampleDma) * gAudioContext.audioBufferParameters.specUnk4);
|
|
|
|
t2 = 3 * gAudioContext.numNotes * gAudioContext.audioBufferParameters.specUnk4;
|
2021-07-27 23:44:58 +00:00
|
|
|
for (i = 0; i < t2; i++) {
|
2021-11-07 16:58:50 +00:00
|
|
|
dma = &gAudioContext.sampleDmas[gAudioContext.sampleDmaCount];
|
2022-06-03 19:59:02 +00:00
|
|
|
dma->ramAddr = AudioHeap_AllocAttemptExternal(&gAudioContext.miscPool, gAudioContext.sampleDmaBufSize);
|
2021-11-07 16:58:50 +00:00
|
|
|
if (dma->ramAddr == NULL) {
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioHeap_WritebackDCache(dma->ramAddr, gAudioContext.sampleDmaBufSize);
|
|
|
|
dma->size = gAudioContext.sampleDmaBufSize;
|
|
|
|
dma->devAddr = 0;
|
|
|
|
dma->sizeUnused = 0;
|
|
|
|
dma->unused = 0;
|
|
|
|
dma->ttl = 0;
|
|
|
|
gAudioContext.sampleDmaCount++;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = 0; (u32)i < gAudioContext.sampleDmaCount; i++) {
|
2021-09-07 18:14:09 +00:00
|
|
|
gAudioContext.sampleDmaReuseQueue1[i] = i;
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.sampleDmas[i].reuseIndex = i;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = gAudioContext.sampleDmaCount; i < 0x100; i++) {
|
2021-09-07 18:14:09 +00:00
|
|
|
gAudioContext.sampleDmaReuseQueue1[i] = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-09-07 18:14:09 +00:00
|
|
|
gAudioContext.sampleDmaReuseQueue1RdPos = 0;
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.sampleDmaReuseQueue1WrPos = gAudioContext.sampleDmaCount;
|
|
|
|
gAudioContext.sampleDmaListSize1 = gAudioContext.sampleDmaCount;
|
|
|
|
gAudioContext.sampleDmaBufSize = gAudioContext.sampleDmaBufSize2;
|
|
|
|
|
|
|
|
for (j = 0; j < gAudioContext.numNotes; j++) {
|
|
|
|
dma = &gAudioContext.sampleDmas[gAudioContext.sampleDmaCount];
|
2022-06-03 19:59:02 +00:00
|
|
|
dma->ramAddr = AudioHeap_AllocAttemptExternal(&gAudioContext.miscPool, gAudioContext.sampleDmaBufSize);
|
2021-11-07 16:58:50 +00:00
|
|
|
if (dma->ramAddr == NULL) {
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioHeap_WritebackDCache(dma->ramAddr, gAudioContext.sampleDmaBufSize);
|
|
|
|
dma->size = gAudioContext.sampleDmaBufSize;
|
|
|
|
dma->devAddr = 0U;
|
|
|
|
dma->sizeUnused = 0;
|
|
|
|
dma->unused = 0;
|
|
|
|
dma->ttl = 0;
|
|
|
|
gAudioContext.sampleDmaCount++;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = gAudioContext.sampleDmaListSize1; (u32)i < gAudioContext.sampleDmaCount; i++) {
|
2021-09-07 18:14:09 +00:00
|
|
|
gAudioContext.sampleDmaReuseQueue2[i - gAudioContext.sampleDmaListSize1] = i;
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.sampleDmas[i].reuseIndex = i - gAudioContext.sampleDmaListSize1;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = gAudioContext.sampleDmaCount; i < 0x100; i++) {
|
2021-09-07 18:14:09 +00:00
|
|
|
gAudioContext.sampleDmaReuseQueue2[i] = gAudioContext.sampleDmaListSize1;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-09-07 18:14:09 +00:00
|
|
|
gAudioContext.sampleDmaReuseQueue2RdPos = 0;
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.sampleDmaReuseQueue2WrPos = gAudioContext.sampleDmaCount - gAudioContext.sampleDmaListSize1;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 AudioLoad_IsFontLoadComplete(s32 fontId) {
|
|
|
|
if (fontId == 0xFF) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return true;
|
2022-06-03 19:59:02 +00:00
|
|
|
} else if (gAudioContext.fontLoadStatus[fontId] >= LOAD_STATUS_COMPLETE) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return true;
|
2022-06-03 19:59:02 +00:00
|
|
|
} else if (gAudioContext.fontLoadStatus[AudioLoad_GetRealTableIndex(FONT_TABLE, fontId)] >= LOAD_STATUS_COMPLETE) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 AudioLoad_IsSeqLoadComplete(s32 seqId) {
|
2021-07-27 23:44:58 +00:00
|
|
|
if (seqId == 0xFF) {
|
2021-08-12 19:37:37 +00:00
|
|
|
return true;
|
2022-06-03 19:59:02 +00:00
|
|
|
} else if (gAudioContext.seqLoadStatus[seqId] >= LOAD_STATUS_COMPLETE) {
|
2021-08-12 19:37:37 +00:00
|
|
|
return true;
|
2022-06-03 19:59:02 +00:00
|
|
|
} else if (gAudioContext.seqLoadStatus[AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId)] >=
|
|
|
|
LOAD_STATUS_COMPLETE) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 AudioLoad_IsSampleLoadComplete(s32 sampleBankId) {
|
|
|
|
if (sampleBankId == 0xFF) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return true;
|
2022-06-03 19:59:02 +00:00
|
|
|
} else if (gAudioContext.sampleFontLoadStatus[sampleBankId] >= LOAD_STATUS_COMPLETE) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return true;
|
2022-06-03 19:59:02 +00:00
|
|
|
} else if (gAudioContext.sampleFontLoadStatus[AudioLoad_GetRealTableIndex(SAMPLE_TABLE, sampleBankId)] >=
|
|
|
|
LOAD_STATUS_COMPLETE) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
void AudioLoad_SetFontLoadStatus(s32 fontId, s32 loadStatus) {
|
|
|
|
if ((fontId != 0xFF) && (gAudioContext.fontLoadStatus[fontId] != LOAD_STATUS_PERMANENTLY_LOADED)) {
|
|
|
|
gAudioContext.fontLoadStatus[fontId] = loadStatus;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
void AudioLoad_SetSeqLoadStatus(s32 seqId, s32 loadStatus) {
|
|
|
|
if ((seqId != 0xFF) && (gAudioContext.seqLoadStatus[seqId] != LOAD_STATUS_PERMANENTLY_LOADED)) {
|
|
|
|
gAudioContext.seqLoadStatus[seqId] = loadStatus;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
void AudioLoad_SetSampleFontLoadStatusAndApplyCaches(s32 sampleBankId, s32 loadStatus) {
|
2021-11-07 16:58:50 +00:00
|
|
|
if (sampleBankId != 0xFF) {
|
2022-06-03 19:59:02 +00:00
|
|
|
if (gAudioContext.sampleFontLoadStatus[sampleBankId] != LOAD_STATUS_PERMANENTLY_LOADED) {
|
|
|
|
gAudioContext.sampleFontLoadStatus[sampleBankId] = loadStatus;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
if ((gAudioContext.sampleFontLoadStatus[sampleBankId] == LOAD_STATUS_PERMANENTLY_LOADED) ||
|
|
|
|
(gAudioContext.sampleFontLoadStatus[sampleBankId] == LOAD_STATUS_COMPLETE)) {
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioHeap_ApplySampleBankCache(sampleBankId);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
void AudioLoad_SetSampleFontLoadStatus(s32 sampleBankId, s32 loadStatus) {
|
|
|
|
if ((sampleBankId != 0xFF) &&
|
|
|
|
(gAudioContext.sampleFontLoadStatus[sampleBankId] != LOAD_STATUS_PERMANENTLY_LOADED)) {
|
|
|
|
gAudioContext.sampleFontLoadStatus[sampleBankId] = loadStatus;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_InitTable(AudioTable* table, u32 romAddr, u16 unkMediumParam) {
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 i;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
table->unkMediumParam = unkMediumParam;
|
|
|
|
table->romAddr = romAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = 0; i < table->numEntries; i++) {
|
|
|
|
if ((table->entries[i].size != 0) && (table->entries[i].medium == MEDIUM_CART)) {
|
2021-07-27 23:44:58 +00:00
|
|
|
table->entries[i].romAddr += romAddr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
SoundFontData* AudioLoad_SyncLoadSeqFonts(s32 seqId, u32* outDefaultFontId) {
|
2022-06-03 19:59:02 +00:00
|
|
|
s32 pad[2];
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 index;
|
2022-06-03 19:59:02 +00:00
|
|
|
SoundFontData* fontData;
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 numFonts;
|
|
|
|
s32 fontId;
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 i;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (seqId >= gAudioContext.numSequences) {
|
|
|
|
return NULL;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
fontId = 0xFF;
|
|
|
|
index = ((u16*)gAudioContext.sequenceFontTable)[seqId];
|
|
|
|
numFonts = gAudioContext.sequenceFontTable[index++];
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
while (numFonts > 0) {
|
|
|
|
fontId = gAudioContext.sequenceFontTable[index++];
|
2022-06-03 19:59:02 +00:00
|
|
|
fontData = AudioLoad_SyncLoadFont(fontId);
|
2021-11-07 16:58:50 +00:00
|
|
|
numFonts--;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
*outDefaultFontId = fontId;
|
2022-06-03 19:59:02 +00:00
|
|
|
return fontData;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_SyncLoadSeqParts(s32 seqId, s32 arg1) {
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 pad;
|
2021-11-07 16:58:50 +00:00
|
|
|
u32 defaultFontId;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (seqId < gAudioContext.numSequences) {
|
2021-07-27 23:44:58 +00:00
|
|
|
if (arg1 & 2) {
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioLoad_SyncLoadSeqFonts(seqId, &defaultFontId);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
if (arg1 & 1) {
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioLoad_SyncLoadSeq(seqId);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 14:31:08 +00:00
|
|
|
s32 AudioLoad_SyncLoadSample(Sample* sample, s32 fontId) {
|
2021-07-27 23:44:58 +00:00
|
|
|
void* sampleAddr;
|
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
if (sample->isRelocated == true) {
|
2021-11-07 16:58:50 +00:00
|
|
|
if (sample->medium != MEDIUM_RAM) {
|
|
|
|
sampleAddr = AudioHeap_AllocSampleCache(sample->size, fontId, (void*)sample->sampleAddr, sample->medium,
|
|
|
|
CACHE_PERSISTENT);
|
2021-07-27 23:44:58 +00:00
|
|
|
if (sampleAddr == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (sample->medium == MEDIUM_UNK) {
|
2022-06-16 00:15:44 +00:00
|
|
|
AudioLoad_SyncDmaUnkMedium((u32)sample->sampleAddr, sampleAddr, sample->size,
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.sampleBankTable->unkMediumParam);
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2022-06-16 00:15:44 +00:00
|
|
|
AudioLoad_SyncDma((u32)sample->sampleAddr, sampleAddr, sample->size, sample->medium);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
sample->medium = MEDIUM_RAM;
|
2021-07-27 23:44:58 +00:00
|
|
|
sample->sampleAddr = sampleAddr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 AudioLoad_SyncLoadInstrument(s32 fontId, s32 instId, s32 drumId) {
|
|
|
|
if (instId < 0x7F) {
|
|
|
|
Instrument* instrument = Audio_GetInstrumentInner(fontId, instId);
|
2021-07-27 23:44:58 +00:00
|
|
|
|
|
|
|
if (instrument == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (instrument->normalRangeLo != 0) {
|
2022-06-19 14:31:08 +00:00
|
|
|
AudioLoad_SyncLoadSample(instrument->lowPitchTunedSample.sample, fontId);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2022-06-19 14:31:08 +00:00
|
|
|
AudioLoad_SyncLoadSample(instrument->normalPitchTunedSample.sample, fontId);
|
2021-07-27 23:44:58 +00:00
|
|
|
if (instrument->normalRangeHi != 0x7F) {
|
2022-06-19 14:31:08 +00:00
|
|
|
return AudioLoad_SyncLoadSample(instrument->highPitchTunedSample.sample, fontId);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
} else if (instId == 0x7F) {
|
|
|
|
Drum* drum = Audio_GetDrum(fontId, drumId);
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-08-19 22:10:51 +00:00
|
|
|
if (drum == NULL) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2022-06-19 14:31:08 +00:00
|
|
|
AudioLoad_SyncLoadSample(drum->tunedSample.sample, fontId);
|
2021-07-27 23:44:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_AsyncLoad(s32 tableType, s32 id, s32 nChunks, s32 retData, OSMesgQueue* retQueue) {
|
|
|
|
if (AudioLoad_AsyncLoadInner(tableType, id, nChunks, retData, retQueue) == NULL) {
|
2022-04-09 00:20:23 +00:00
|
|
|
osSendMesg(retQueue, (OSMesg)0xFFFFFFFF, OS_MESG_NOBLOCK);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_AsyncLoadSeq(s32 seqId, s32 arg1, s32 retData, OSMesgQueue* retQueue) {
|
|
|
|
AudioLoad_AsyncLoad(SEQUENCE_TABLE, seqId, 0, retData, retQueue);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_AsyncLoadSampleBank(s32 sampleBankId, s32 arg1, s32 retData, OSMesgQueue* retQueue) {
|
|
|
|
AudioLoad_AsyncLoad(SAMPLE_TABLE, sampleBankId, 0, retData, retQueue);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_AsyncLoadFont(s32 fontId, s32 arg1, s32 retData, OSMesgQueue* retQueue) {
|
|
|
|
AudioLoad_AsyncLoad(FONT_TABLE, fontId, 0, retData, retQueue);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) {
|
2022-06-03 19:59:02 +00:00
|
|
|
s32 index = ((u16*)gAudioContext.sequenceFontTable)[seqId];
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
*outNumFonts = gAudioContext.sequenceFontTable[index++];
|
|
|
|
if (*outNumFonts == 0) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
return &gAudioContext.sequenceFontTable[index];
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_DiscardSeqFonts(s32 seqId) {
|
|
|
|
s32 fontId;
|
2022-06-03 19:59:02 +00:00
|
|
|
s32 index = ((u16*)gAudioContext.sequenceFontTable)[seqId];
|
|
|
|
s32 numFonts = gAudioContext.sequenceFontTable[index++];
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
while (numFonts > 0) {
|
|
|
|
numFonts--;
|
|
|
|
fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioContext.sequenceFontTable[index++]);
|
|
|
|
if (AudioHeap_SearchPermanentCache(FONT_TABLE, fontId) == NULL) {
|
|
|
|
AudioLoad_DiscardFont(fontId);
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SetFontLoadStatus(fontId, LOAD_STATUS_NOT_LOADED);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_DiscardFont(s32 fontId) {
|
2021-09-07 18:14:09 +00:00
|
|
|
u32 i;
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioCache* pool = &gAudioContext.fontCache;
|
|
|
|
AudioPersistentCache* persistent;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (fontId == pool->temporary.entries[0].id) {
|
2021-07-27 23:44:58 +00:00
|
|
|
pool->temporary.entries[0].id = -1;
|
2021-11-07 16:58:50 +00:00
|
|
|
} else if (fontId == pool->temporary.entries[1].id) {
|
2021-07-27 23:44:58 +00:00
|
|
|
pool->temporary.entries[1].id = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
persistent = &pool->persistent;
|
|
|
|
for (i = 0; i < persistent->numEntries; i++) {
|
2021-11-07 16:58:50 +00:00
|
|
|
if (fontId == persistent->entries[i].id) {
|
2021-07-27 23:44:58 +00:00
|
|
|
persistent->entries[i].id = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioHeap_DiscardFont(fontId);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 AudioLoad_SyncInitSeqPlayer(s32 playerIdx, s32 seqId, s32 arg2) {
|
2021-07-27 23:44:58 +00:00
|
|
|
if (gAudioContext.resetTimer != 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
|
|
|
|
gAudioContext.seqPlayers[playerIdx].skipTicks = 0;
|
|
|
|
AudioLoad_SyncInitSeqPlayerInternal(playerIdx, seqId, arg2);
|
|
|
|
// Intentionally missing return. Returning the result of the above function
|
|
|
|
// call matches but is UB because it too is missing a return, and using the
|
|
|
|
// result of a non-void function that has failed to return a value is UB.
|
|
|
|
// The callers of this function do not use the return value, so it's fine.
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 AudioLoad_SyncInitSeqPlayerSkipTicks(s32 playerIdx, s32 seqId, s32 skipTicks) {
|
2021-07-27 23:44:58 +00:00
|
|
|
if (gAudioContext.resetTimer != 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.seqPlayers[playerIdx].skipTicks = skipTicks;
|
|
|
|
AudioLoad_SyncInitSeqPlayerInternal(playerIdx, seqId, 0);
|
|
|
|
// Missing return, see above.
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) {
|
|
|
|
SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx];
|
2021-07-27 23:44:58 +00:00
|
|
|
u8* seqData;
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 index;
|
|
|
|
s32 numFonts;
|
|
|
|
s32 fontId;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (seqId >= gAudioContext.numSequences) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioSeq_SequencePlayerDisable(seqPlayer);
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
fontId = 0xFF;
|
|
|
|
index = ((u16*)gAudioContext.sequenceFontTable)[seqId];
|
|
|
|
numFonts = gAudioContext.sequenceFontTable[index++];
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
while (numFonts > 0) {
|
|
|
|
fontId = gAudioContext.sequenceFontTable[index++];
|
|
|
|
AudioLoad_SyncLoadFont(fontId);
|
|
|
|
numFonts--;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
seqData = AudioLoad_SyncLoadSeq(seqId);
|
2021-07-27 23:44:58 +00:00
|
|
|
if (seqData == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioSeq_ResetSequencePlayer(seqPlayer);
|
2021-07-27 23:44:58 +00:00
|
|
|
seqPlayer->seqId = seqId;
|
2021-11-07 16:58:50 +00:00
|
|
|
seqPlayer->defaultFont = AudioLoad_GetRealTableIndex(FONT_TABLE, fontId);
|
2021-07-27 23:44:58 +00:00
|
|
|
seqPlayer->seqData = seqData;
|
2022-06-03 19:59:02 +00:00
|
|
|
seqPlayer->enabled = true;
|
2021-07-27 23:44:58 +00:00
|
|
|
seqPlayer->scriptState.pc = seqData;
|
|
|
|
seqPlayer->scriptState.depth = 0;
|
|
|
|
seqPlayer->delay = 0;
|
2022-06-03 19:59:02 +00:00
|
|
|
seqPlayer->finished = false;
|
2021-11-07 16:58:50 +00:00
|
|
|
seqPlayer->playerIdx = playerIdx;
|
|
|
|
AudioSeq_SkipForwardSequence(seqPlayer);
|
|
|
|
//! @bug missing return (but the return value is not used so it's not UB)
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
u8* AudioLoad_SyncLoadSeq(s32 seqId) {
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 pad;
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 didAllocate;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
if (gAudioContext.seqLoadStatus[AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId)] == LOAD_STATUS_IN_PROGRESS) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
return AudioLoad_SyncLoad(SEQUENCE_TABLE, seqId, &didAllocate);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
u32 AudioLoad_GetSampleBank(u32 sampleBankId, u32* outMedium) {
|
|
|
|
return AudioLoad_TrySyncLoadSampleBank(sampleBankId, outMedium, true);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
u32 AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 noLoad) {
|
2022-06-03 19:59:02 +00:00
|
|
|
void* ramAddr;
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioTable* sampleBankTable;
|
|
|
|
u32 realTableId = AudioLoad_GetRealTableIndex(SAMPLE_TABLE, sampleBankId);
|
|
|
|
s8 cachePolicy;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
sampleBankTable = AudioLoad_GetLoadTable(SAMPLE_TABLE);
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioLoad_SearchCaches(SAMPLE_TABLE, realTableId);
|
|
|
|
if (ramAddr != NULL) {
|
|
|
|
if (gAudioContext.sampleFontLoadStatus[realTableId] != LOAD_STATUS_IN_PROGRESS) {
|
|
|
|
AudioLoad_SetSampleFontLoadStatus(realTableId, LOAD_STATUS_COMPLETE);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
*outMedium = MEDIUM_RAM;
|
2022-06-16 00:15:44 +00:00
|
|
|
return (u32)ramAddr;
|
2021-11-07 16:58:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cachePolicy = sampleBankTable->entries[sampleBankId].cachePolicy;
|
|
|
|
if (cachePolicy == 4 || noLoad == true) {
|
|
|
|
*outMedium = sampleBankTable->entries[sampleBankId].medium;
|
|
|
|
return sampleBankTable->entries[realTableId].romAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioLoad_SyncLoad(SAMPLE_TABLE, sampleBankId, &noLoad);
|
|
|
|
if (ramAddr != NULL) {
|
2021-11-07 16:58:50 +00:00
|
|
|
*outMedium = MEDIUM_RAM;
|
2022-06-16 00:15:44 +00:00
|
|
|
return (u32)ramAddr;
|
2021-11-07 16:58:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*outMedium = sampleBankTable->entries[sampleBankId].medium;
|
|
|
|
return sampleBankTable->entries[realTableId].romAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
SoundFontData* AudioLoad_SyncLoadFont(u32 fontId) {
|
2022-06-03 19:59:02 +00:00
|
|
|
SoundFontData* fontData;
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 sampleBankId1;
|
|
|
|
s32 sampleBankId2;
|
|
|
|
s32 didAllocate;
|
2022-06-12 23:33:56 +00:00
|
|
|
SampleBankRelocInfo sampleBankReloc;
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 realFontId = AudioLoad_GetRealTableIndex(FONT_TABLE, fontId);
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
if (gAudioContext.fontLoadStatus[realFontId] == LOAD_STATUS_IN_PROGRESS) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2022-06-19 14:31:08 +00:00
|
|
|
sampleBankId1 = gAudioContext.soundFontList[realFontId].sampleBankId1;
|
|
|
|
sampleBankId2 = gAudioContext.soundFontList[realFontId].sampleBankId2;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
sampleBankReloc.sampleBankId1 = sampleBankId1;
|
|
|
|
sampleBankReloc.sampleBankId2 = sampleBankId2;
|
2021-11-07 16:58:50 +00:00
|
|
|
if (sampleBankId1 != 0xFF) {
|
2022-06-12 23:33:56 +00:00
|
|
|
sampleBankReloc.baseAddr1 = AudioLoad_TrySyncLoadSampleBank(sampleBankId1, &sampleBankReloc.medium1, false);
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2022-06-12 23:33:56 +00:00
|
|
|
sampleBankReloc.baseAddr1 = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (sampleBankId2 != 0xFF) {
|
2022-06-12 23:33:56 +00:00
|
|
|
sampleBankReloc.baseAddr2 = AudioLoad_TrySyncLoadSampleBank(sampleBankId2, &sampleBankReloc.medium2, false);
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2022-06-12 23:33:56 +00:00
|
|
|
sampleBankReloc.baseAddr2 = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
fontData = AudioLoad_SyncLoad(FONT_TABLE, fontId, &didAllocate);
|
|
|
|
if (fontData == NULL) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
if (didAllocate == true) {
|
2022-06-12 23:33:56 +00:00
|
|
|
AudioLoad_RelocateFontAndPreloadSamples(realFontId, fontData, &sampleBankReloc, false);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
return fontData;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void* AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
|
2021-07-27 23:44:58 +00:00
|
|
|
u32 size;
|
|
|
|
AudioTable* table;
|
|
|
|
s32 pad;
|
2021-11-07 16:58:50 +00:00
|
|
|
u32 medium;
|
2022-06-03 19:59:02 +00:00
|
|
|
s32 loadStatus;
|
2021-07-27 23:44:58 +00:00
|
|
|
u32 romAddr;
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 cachePolicy;
|
2022-06-03 19:59:02 +00:00
|
|
|
void* ramAddr;
|
2021-11-07 16:58:50 +00:00
|
|
|
u32 realId;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
realId = AudioLoad_GetRealTableIndex(tableType, id);
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioLoad_SearchCaches(tableType, realId);
|
|
|
|
if (ramAddr != NULL) {
|
2021-07-27 23:44:58 +00:00
|
|
|
*didAllocate = false;
|
2022-06-03 19:59:02 +00:00
|
|
|
loadStatus = LOAD_STATUS_COMPLETE;
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2021-11-07 16:58:50 +00:00
|
|
|
table = AudioLoad_GetLoadTable(tableType);
|
|
|
|
size = table->entries[realId].size;
|
2021-07-27 23:44:58 +00:00
|
|
|
size = ALIGN16(size);
|
2021-11-07 16:58:50 +00:00
|
|
|
medium = table->entries[id].medium;
|
|
|
|
cachePolicy = table->entries[id].cachePolicy;
|
|
|
|
romAddr = table->entries[realId].romAddr;
|
|
|
|
switch (cachePolicy) {
|
2021-07-27 23:44:58 +00:00
|
|
|
case 0:
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioHeap_AllocPermanent(tableType, realId, size);
|
|
|
|
if (ramAddr == NULL) {
|
|
|
|
return ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
case 1:
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_PERSISTENT, realId);
|
|
|
|
if (ramAddr == NULL) {
|
|
|
|
return ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
case 2:
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_TEMPORARY, realId);
|
|
|
|
if (ramAddr == NULL) {
|
|
|
|
return ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
case 3:
|
|
|
|
case 4:
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_EITHER, realId);
|
|
|
|
if (ramAddr == NULL) {
|
|
|
|
return ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*didAllocate = true;
|
2021-11-07 16:58:50 +00:00
|
|
|
if (medium == MEDIUM_UNK) {
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SyncDmaUnkMedium(romAddr, ramAddr, size, (s16)table->unkMediumParam);
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SyncDma(romAddr, ramAddr, size, medium);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
loadStatus = (cachePolicy == 0) ? LOAD_STATUS_PERMANENTLY_LOADED : LOAD_STATUS_COMPLETE;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (tableType) {
|
|
|
|
case SEQUENCE_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SetSeqLoadStatus(realId, loadStatus);
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case FONT_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SetFontLoadStatus(realId, loadStatus);
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case SAMPLE_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SetSampleFontLoadStatusAndApplyCaches(realId, loadStatus);
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
return ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 id) {
|
|
|
|
AudioTable* table = AudioLoad_GetLoadTable(tableType);
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (table->entries[id].size == 0) {
|
|
|
|
id = table->entries[id].romAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
return id;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void* AudioLoad_SearchCaches(s32 tableType, s32 id) {
|
2022-06-03 19:59:02 +00:00
|
|
|
void* ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioHeap_SearchPermanentCache(tableType, id);
|
|
|
|
if (ramAddr != NULL) {
|
|
|
|
return ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioHeap_SearchCaches(tableType, CACHE_EITHER, id);
|
|
|
|
if (ramAddr != NULL) {
|
|
|
|
return ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioTable* AudioLoad_GetLoadTable(s32 tableType) {
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioTable* table;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
|
|
|
switch (tableType) {
|
|
|
|
case SEQUENCE_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
table = gAudioContext.sequenceTable;
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case FONT_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
table = gAudioContext.soundFontTable;
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
default:
|
2022-06-03 19:59:02 +00:00
|
|
|
table = NULL;
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case SAMPLE_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
table = gAudioContext.sampleBankTable;
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-06-03 19:59:02 +00:00
|
|
|
return table;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
/**
|
|
|
|
* Read and extract information from soundFont binary loaded into ram.
|
|
|
|
* Also relocate offsets into pointers within this loaded soundFont
|
|
|
|
*
|
|
|
|
* @param fontId index of font being processed
|
|
|
|
* @param fontData ram address of raw soundfont binary loaded into cache
|
|
|
|
* @param sampleBankReloc information on the sampleBank containing raw audio samples
|
|
|
|
*/
|
|
|
|
void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, SampleBankRelocInfo* sampleBankReloc) {
|
2022-06-19 14:31:08 +00:00
|
|
|
u32 soundOffset; // Relative offset from the beginning of fontData directly to the tunedSample/envelope
|
2022-06-12 23:33:56 +00:00
|
|
|
u32 soundListOffset; // Relative offset from the beginning of fontData to the list of soundOffsets/sfxs
|
2021-09-07 18:14:09 +00:00
|
|
|
Instrument* inst;
|
2021-07-27 23:44:58 +00:00
|
|
|
Drum* drum;
|
2022-06-19 14:31:08 +00:00
|
|
|
SoundEffect* soundEffect;
|
2021-08-30 00:51:57 +00:00
|
|
|
s32 i;
|
2022-06-19 14:31:08 +00:00
|
|
|
s32 numDrums = gAudioContext.soundFontList[fontId].numDrums;
|
|
|
|
s32 numInstruments = gAudioContext.soundFontList[fontId].numInstruments;
|
|
|
|
s32 numSfx = gAudioContext.soundFontList[fontId].numSfx;
|
2022-06-16 00:15:44 +00:00
|
|
|
u32* fontData = (u32*)fontDataStartAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
// Relocate an offset (relative to the start of the font data) to a pointer (a ram address)
|
2022-06-16 00:15:44 +00:00
|
|
|
#define RELOC_TO_RAM(offset) ((u32)(offset) + (u32)(fontDataStartAddr))
|
2021-11-07 16:58:50 +00:00
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
// Drums relocation
|
|
|
|
|
|
|
|
// The first u32 in fontData is an offset to a list of offsets to the drums
|
|
|
|
soundListOffset = fontData[0];
|
2021-09-07 18:14:09 +00:00
|
|
|
if (1) {}
|
2022-06-12 23:33:56 +00:00
|
|
|
|
|
|
|
// If the soundFont has drums
|
|
|
|
if ((soundListOffset != 0) && (numDrums != 0)) {
|
|
|
|
|
|
|
|
fontData[0] = RELOC_TO_RAM(soundListOffset);
|
|
|
|
|
|
|
|
// Loop through the drum offsets
|
2021-09-07 18:14:09 +00:00
|
|
|
for (i = 0; i < numDrums; i++) {
|
2022-06-12 23:33:56 +00:00
|
|
|
// Get the i'th drum offset
|
2022-06-16 00:15:44 +00:00
|
|
|
soundOffset = (u32)((Drum**)fontData[0])[i];
|
2022-06-12 23:33:56 +00:00
|
|
|
|
|
|
|
// Some drum data entries are empty, represented by an offset of 0 in the list of drum offsets
|
|
|
|
if (soundOffset != 0) {
|
|
|
|
soundOffset = RELOC_TO_RAM(soundOffset);
|
2022-06-16 00:15:44 +00:00
|
|
|
((Drum**)fontData[0])[i] = drum = (Drum*)soundOffset;
|
2022-06-12 23:33:56 +00:00
|
|
|
|
|
|
|
// The drum may be in the list multiple times and already relocated
|
|
|
|
if (!drum->isRelocated) {
|
2022-06-19 14:31:08 +00:00
|
|
|
AudioLoad_RelocateSample(&drum->tunedSample, fontDataStartAddr, sampleBankReloc);
|
2022-06-12 23:33:56 +00:00
|
|
|
|
2022-06-16 00:15:44 +00:00
|
|
|
soundOffset = (u32)drum->envelope;
|
2022-06-19 14:31:08 +00:00
|
|
|
drum->envelope = (EnvelopePoint*)RELOC_TO_RAM(soundOffset);
|
2022-06-12 23:33:56 +00:00
|
|
|
|
|
|
|
drum->isRelocated = true;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
// Sound effects relocation
|
|
|
|
|
|
|
|
// The second u32 in fontData is an offset to the first sound effect entry
|
|
|
|
soundListOffset = fontData[1];
|
2021-09-07 18:14:09 +00:00
|
|
|
if (1) {}
|
2022-06-12 23:33:56 +00:00
|
|
|
|
|
|
|
// If the soundFont has sound effects
|
|
|
|
if ((soundListOffset != 0) && (numSfx != 0)) {
|
|
|
|
|
|
|
|
fontData[1] = RELOC_TO_RAM(soundListOffset);
|
|
|
|
|
|
|
|
// Loop through the sound effects
|
2021-09-07 18:14:09 +00:00
|
|
|
for (i = 0; i < numSfx; i++) {
|
2022-06-12 23:33:56 +00:00
|
|
|
// Get a pointer to the i'th sound effect
|
2022-06-19 14:31:08 +00:00
|
|
|
soundOffset = (u32)(((SoundEffect*)fontData[1]) + i);
|
|
|
|
soundEffect = (SoundEffect*)soundOffset;
|
2022-06-12 23:33:56 +00:00
|
|
|
|
|
|
|
// Check for NULL (note: the pointer is guaranteed to be in fontData and can never be NULL)
|
2022-06-19 14:31:08 +00:00
|
|
|
if ((soundEffect != NULL) && ((u32)soundEffect->tunedSample.sample != 0)) {
|
|
|
|
AudioLoad_RelocateSample(&soundEffect->tunedSample, fontDataStartAddr, sampleBankReloc);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
// Instruments relocation
|
|
|
|
|
|
|
|
// Instrument Id 126 and above is reserved.
|
|
|
|
// There can only be 126 instruments, indexed from 0 to 125
|
|
|
|
if (numInstruments > 126) {
|
|
|
|
numInstruments = 126;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
// Starting from the 3rd u32 in fontData is the list of offsets to the instruments
|
|
|
|
// Loop through the instruments
|
2021-09-07 18:14:09 +00:00
|
|
|
for (i = 2; i <= 2 + numInstruments - 1; i++) {
|
2022-06-12 23:33:56 +00:00
|
|
|
// Some instrument data entries are empty, represented by an offset of 0 in the list of instrument offsets
|
2022-06-16 00:15:44 +00:00
|
|
|
if (fontData[i] != 0) {
|
2022-06-12 23:33:56 +00:00
|
|
|
fontData[i] = RELOC_TO_RAM(fontData[i]);
|
2022-06-16 00:15:44 +00:00
|
|
|
inst = (Instrument*)fontData[i];
|
2022-06-12 23:33:56 +00:00
|
|
|
|
|
|
|
// The instrument may be in the list multiple times and already relocated
|
|
|
|
if (!inst->isRelocated) {
|
|
|
|
// Some instruments have a different sample for low pitches
|
2021-09-07 18:14:09 +00:00
|
|
|
if (inst->normalRangeLo != 0) {
|
2022-06-19 14:31:08 +00:00
|
|
|
AudioLoad_RelocateSample(&inst->lowPitchTunedSample, fontDataStartAddr, sampleBankReloc);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
2022-06-12 23:33:56 +00:00
|
|
|
|
|
|
|
// Every instrument has a sample for the default range
|
2022-06-19 14:31:08 +00:00
|
|
|
AudioLoad_RelocateSample(&inst->normalPitchTunedSample, fontDataStartAddr, sampleBankReloc);
|
2022-06-12 23:33:56 +00:00
|
|
|
|
|
|
|
// Some instruments have a different sample for high pitches
|
2021-09-07 18:14:09 +00:00
|
|
|
if (inst->normalRangeHi != 0x7F) {
|
2022-06-19 14:31:08 +00:00
|
|
|
AudioLoad_RelocateSample(&inst->highPitchTunedSample, fontDataStartAddr, sampleBankReloc);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2021-09-07 18:14:09 +00:00
|
|
|
|
2022-06-16 00:15:44 +00:00
|
|
|
soundOffset = (u32)inst->envelope;
|
2022-06-19 14:31:08 +00:00
|
|
|
inst->envelope = (EnvelopePoint*)RELOC_TO_RAM(soundOffset);
|
2022-06-12 23:33:56 +00:00
|
|
|
|
|
|
|
inst->isRelocated = true;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
#undef FONT_DATA_RELOC
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2022-06-19 14:31:08 +00:00
|
|
|
// Store the relocated pointers
|
|
|
|
gAudioContext.soundFontList[fontId].drums = (Drum**)fontData[0];
|
|
|
|
gAudioContext.soundFontList[fontId].soundEffects = (SoundEffect*)fontData[1];
|
|
|
|
gAudioContext.soundFontList[fontId].instruments = (Instrument**)(fontData + 2);
|
2021-11-07 16:58:50 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
void AudioLoad_SyncDma(u32 devAddr, u8* ramAddr, u32 size, s32 medium) {
|
2021-11-07 16:58:50 +00:00
|
|
|
OSMesgQueue* msgQueue = &gAudioContext.syncDmaQueue;
|
|
|
|
OSIoMesg* ioMesg = &gAudioContext.syncDmaIoMesg;
|
2021-07-27 23:44:58 +00:00
|
|
|
size = ALIGN16(size);
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
Audio_InvalDCache(ramAddr, size);
|
2021-07-27 23:44:58 +00:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
if (size < 0x400) {
|
|
|
|
break;
|
|
|
|
}
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_Dma(ioMesg, OS_MESG_PRI_HIGH, OS_READ, devAddr, ramAddr, 0x400, msgQueue, medium, "FastCopy");
|
2021-07-27 23:44:58 +00:00
|
|
|
osRecvMesg(msgQueue, NULL, OS_MESG_BLOCK);
|
|
|
|
size -= 0x400;
|
|
|
|
devAddr += 0x400;
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr += 0x400;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (size != 0) {
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_Dma(ioMesg, OS_MESG_PRI_HIGH, OS_READ, devAddr, ramAddr, size, msgQueue, medium, "FastCopy");
|
2021-07-27 23:44:58 +00:00
|
|
|
osRecvMesg(msgQueue, NULL, OS_MESG_BLOCK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_SyncDmaUnkMedium(u32 devAddr, u8* addr, u32 size, s32 unkMediumParam) {
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 AudioLoad_Dma(OSIoMesg* mesg, u32 priority, s32 direction, u32 devAddr, void* ramAddr, u32 size,
|
|
|
|
OSMesgQueue* reqQueue, s32 medium, const char* dmaFuncType) {
|
2021-07-27 23:44:58 +00:00
|
|
|
OSPiHandle* handle;
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
if (gAudioContext.resetTimer > 16) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
switch (medium) {
|
|
|
|
case MEDIUM_CART:
|
2021-07-27 23:44:58 +00:00
|
|
|
handle = gAudioContext.cartHandle;
|
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case MEDIUM_DISK_DRIVE:
|
|
|
|
// driveHandle is uninitialized and corresponds to stubbed-out disk drive support.
|
|
|
|
// SM64 Shindou called osDriveRomInit here.
|
|
|
|
handle = gAudioContext.driveHandle;
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((size % 0x10) != 0) {
|
|
|
|
size = ALIGN16(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
mesg->hdr.pri = priority;
|
|
|
|
mesg->hdr.retQueue = reqQueue;
|
|
|
|
mesg->dramAddr = ramAddr;
|
|
|
|
mesg->devAddr = devAddr;
|
|
|
|
mesg->size = size;
|
|
|
|
handle->transferInfo.cmdType = 2;
|
|
|
|
sDmaHandler(handle, mesg, direction);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_Unused1(void) {
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_SyncLoadSimple(u32 tableType, u32 fontId) {
|
|
|
|
s32 didAllocate;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioLoad_SyncLoad(tableType, fontId, &didAllocate);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData, OSMesgQueue* retQueue) {
|
2021-08-30 00:51:57 +00:00
|
|
|
u32 size;
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioTable* table;
|
|
|
|
void* ramAddr;
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 medium;
|
|
|
|
s8 cachePolicy;
|
2021-08-30 00:51:57 +00:00
|
|
|
u32 devAddr;
|
2022-06-03 19:59:02 +00:00
|
|
|
s32 loadStatus;
|
|
|
|
s32 pad;
|
|
|
|
u32 realId = AudioLoad_GetRealTableIndex(tableType, id);
|
2021-07-27 23:44:58 +00:00
|
|
|
|
|
|
|
switch (tableType) {
|
|
|
|
case SEQUENCE_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
if (gAudioContext.seqLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case FONT_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
if (gAudioContext.fontLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case SAMPLE_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
if (gAudioContext.sampleFontLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioLoad_SearchCaches(tableType, realId);
|
|
|
|
if (ramAddr != NULL) {
|
|
|
|
loadStatus = LOAD_STATUS_COMPLETE;
|
|
|
|
osSendMesg(retQueue, (OSMesg)MK_ASYNC_MSG(retData, 0, 0, LOAD_STATUS_NOT_LOADED), OS_MESG_NOBLOCK);
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2022-06-03 19:59:02 +00:00
|
|
|
table = AudioLoad_GetLoadTable(tableType);
|
|
|
|
size = table->entries[realId].size;
|
2021-08-30 00:51:57 +00:00
|
|
|
size = ALIGN16(size);
|
2022-06-03 19:59:02 +00:00
|
|
|
medium = table->entries[id].medium;
|
|
|
|
cachePolicy = table->entries[id].cachePolicy;
|
|
|
|
devAddr = table->entries[realId].romAddr;
|
|
|
|
loadStatus = LOAD_STATUS_COMPLETE;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
switch (cachePolicy) {
|
2021-07-27 23:44:58 +00:00
|
|
|
case 0:
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioHeap_AllocPermanent(tableType, realId, size);
|
|
|
|
if (ramAddr == NULL) {
|
|
|
|
return ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2022-06-03 19:59:02 +00:00
|
|
|
loadStatus = LOAD_STATUS_PERMANENTLY_LOADED;
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
case 1:
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_PERSISTENT, realId);
|
|
|
|
if (ramAddr == NULL) {
|
|
|
|
return ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
case 2:
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_TEMPORARY, realId);
|
|
|
|
if (ramAddr == NULL) {
|
|
|
|
return ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
case 3:
|
|
|
|
case 4:
|
2022-06-03 19:59:02 +00:00
|
|
|
ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_EITHER, realId);
|
|
|
|
if (ramAddr == NULL) {
|
|
|
|
return ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (medium == MEDIUM_UNK) {
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_StartAsyncLoadUnkMedium((s16)table->unkMediumParam, devAddr, ramAddr, size, medium, nChunks,
|
|
|
|
retQueue, MK_ASYNC_MSG(retData, tableType, id, loadStatus));
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_StartAsyncLoad(devAddr, ramAddr, size, medium, nChunks, retQueue,
|
|
|
|
MK_ASYNC_MSG(retData, tableType, realId, loadStatus));
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2022-06-03 19:59:02 +00:00
|
|
|
loadStatus = LOAD_STATUS_IN_PROGRESS;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (tableType) {
|
2021-11-07 16:58:50 +00:00
|
|
|
case SEQUENCE_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SetSeqLoadStatus(realId, loadStatus);
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case FONT_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SetFontLoadStatus(realId, loadStatus);
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case SAMPLE_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SetSampleFontLoadStatusAndApplyCaches(realId, loadStatus);
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
return ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_ProcessLoads(s32 resetStatus) {
|
|
|
|
AudioLoad_ProcessSlowLoads(resetStatus);
|
|
|
|
AudioLoad_ProcessSamplePreloads(resetStatus);
|
|
|
|
AudioLoad_ProcessAsyncLoads(resetStatus);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_SetDmaHandler(DmaHandler callback) {
|
2021-07-27 23:44:58 +00:00
|
|
|
sDmaHandler = callback;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_SetUnusedHandler(void* callback) {
|
|
|
|
sUnusedHandler = callback;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 14:31:08 +00:00
|
|
|
void AudioLoad_InitSoundFont(s32 fontId) {
|
|
|
|
SoundFont* font = &gAudioContext.soundFontList[fontId];
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioTableEntry* entry = &gAudioContext.soundFontTable->entries[fontId];
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
font->sampleBankId1 = (entry->shortData1 >> 8) & 0xFF;
|
|
|
|
font->sampleBankId2 = (entry->shortData1) & 0xFF;
|
|
|
|
font->numInstruments = (entry->shortData2 >> 8) & 0xFF;
|
|
|
|
font->numDrums = entry->shortData2 & 0xFF;
|
|
|
|
font->numSfx = entry->shortData3;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_Init(void* heap, u32 heapSize) {
|
2022-06-03 19:59:02 +00:00
|
|
|
s32 pad[18];
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 numFonts;
|
2022-06-03 19:59:02 +00:00
|
|
|
void* ramAddr;
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 i;
|
|
|
|
|
|
|
|
D_801755D0 = NULL;
|
|
|
|
gAudioContext.resetTimer = 0;
|
|
|
|
|
|
|
|
{
|
|
|
|
s32 i;
|
2022-06-03 19:59:02 +00:00
|
|
|
u8* audioContextPtr = (u8*)&gAudioContext;
|
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
for (i = sizeof(gAudioContext); i >= 0; i--) {
|
2022-06-03 19:59:02 +00:00
|
|
|
*audioContextPtr++ = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (osTvType) {
|
|
|
|
case OS_TV_PAL:
|
|
|
|
gAudioContext.unk_2960 = 20.03042f;
|
|
|
|
gAudioContext.refreshRate = 50;
|
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
case OS_TV_MPAL:
|
|
|
|
gAudioContext.unk_2960 = 16.546f;
|
|
|
|
gAudioContext.refreshRate = 60;
|
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
case OS_TV_NTSC:
|
|
|
|
default:
|
|
|
|
gAudioContext.unk_2960 = 16.713f;
|
|
|
|
gAudioContext.refreshRate = 60;
|
2022-06-03 19:59:02 +00:00
|
|
|
break;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Audio_InitMesgQueues();
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
gAudioContext.aiBufLengths[i] = 0xA0;
|
|
|
|
}
|
|
|
|
|
2022-05-09 16:59:23 +00:00
|
|
|
gAudioContext.totalTaskCount = 0;
|
2022-06-03 19:59:02 +00:00
|
|
|
gAudioContext.rspTaskIndex = 0;
|
|
|
|
gAudioContext.curAiBufIndex = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
gAudioContext.soundMode = 0;
|
2022-06-03 19:59:02 +00:00
|
|
|
gAudioContext.curTask = NULL;
|
2021-07-27 23:44:58 +00:00
|
|
|
gAudioContext.rspTask[0].task.t.data_size = 0;
|
|
|
|
gAudioContext.rspTask[1].task.t.data_size = 0;
|
2021-11-07 16:58:50 +00:00
|
|
|
osCreateMesgQueue(&gAudioContext.syncDmaQueue, &gAudioContext.syncDmaMesg, 1);
|
2022-04-09 00:20:23 +00:00
|
|
|
osCreateMesgQueue(&gAudioContext.currAudioFrameDmaQueue, gAudioContext.currAudioFrameDmaMsgBuf,
|
|
|
|
ARRAY_COUNT(gAudioContext.currAudioFrameDmaMsgBuf));
|
|
|
|
osCreateMesgQueue(&gAudioContext.externalLoadQueue, gAudioContext.externalLoadMsgBuf,
|
|
|
|
ARRAY_COUNT(gAudioContext.externalLoadMsgBuf));
|
|
|
|
osCreateMesgQueue(&gAudioContext.preloadSampleQueue, gAudioContext.preloadSampleMsgBuf,
|
2022-06-03 19:59:02 +00:00
|
|
|
ARRAY_COUNT(gAudioContext.preloadSampleMsgBuf));
|
2021-09-07 18:14:09 +00:00
|
|
|
gAudioContext.curAudioFrameDmaCount = 0;
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.sampleDmaCount = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
gAudioContext.cartHandle = osCartRomInit();
|
|
|
|
|
|
|
|
if (heap == NULL) {
|
|
|
|
gAudioContext.audioHeap = gAudioHeap;
|
2022-06-12 23:47:53 +00:00
|
|
|
gAudioContext.audioHeapSize = gAudioHeapInitSizes.heapSize;
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
|
|
|
void** hp = &heap;
|
|
|
|
gAudioContext.audioHeap = *hp;
|
|
|
|
gAudioContext.audioHeapSize = heapSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < (s32)gAudioContext.audioHeapSize / 8; i++) {
|
|
|
|
((u64*)gAudioContext.audioHeap)[i] = 0;
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
// Main Pool Split (split entirety of audio heap into initPool and sessionPool)
|
2022-06-12 23:47:53 +00:00
|
|
|
AudioHeap_InitMainPools(gAudioHeapInitSizes.initPoolSize);
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
// Initialize the audio interface buffers
|
2021-07-27 23:44:58 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2022-06-12 23:47:53 +00:00
|
|
|
gAudioContext.aiBuffers[i] = AudioHeap_AllocZeroed(&gAudioContext.initPool, AIBUF_LEN * sizeof(s16));
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
// Set audio tables pointers
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.sequenceTable = (AudioTable*)gSequenceTable;
|
|
|
|
gAudioContext.soundFontTable = (AudioTable*)gSoundFontTable;
|
|
|
|
gAudioContext.sampleBankTable = (AudioTable*)gSampleBankTable;
|
|
|
|
gAudioContext.sequenceFontTable = gSequenceFontTable;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.numSequences = gAudioContext.sequenceTable->numEntries;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-08-30 00:08:41 +00:00
|
|
|
gAudioContext.audioResetSpecIdToLoad = 0;
|
2022-06-03 19:59:02 +00:00
|
|
|
gAudioContext.resetStatus = 1; // Set reset to immediately initialize the audio heap
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioHeap_ResetStep();
|
2022-06-03 19:59:02 +00:00
|
|
|
|
|
|
|
// Initialize audio tables
|
2022-06-16 00:15:44 +00:00
|
|
|
AudioLoad_InitTable(gAudioContext.sequenceTable, (u32)_AudioseqSegmentRomStart, 0);
|
|
|
|
AudioLoad_InitTable(gAudioContext.soundFontTable, (u32)_AudiobankSegmentRomStart, 0);
|
|
|
|
AudioLoad_InitTable(gAudioContext.sampleBankTable, (u32)_AudiotableSegmentRomStart, 0);
|
2021-11-07 16:58:50 +00:00
|
|
|
numFonts = gAudioContext.soundFontTable->numEntries;
|
2022-06-19 14:31:08 +00:00
|
|
|
gAudioContext.soundFontList = AudioHeap_Alloc(&gAudioContext.initPool, numFonts * sizeof(SoundFont));
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = 0; i < numFonts; i++) {
|
2022-06-19 14:31:08 +00:00
|
|
|
AudioLoad_InitSoundFont(i);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-12 23:47:53 +00:00
|
|
|
ramAddr = AudioHeap_Alloc(&gAudioContext.initPool, gAudioHeapInitSizes.permanentPoolSize);
|
2022-06-03 19:59:02 +00:00
|
|
|
if (ramAddr == NULL) {
|
2022-06-12 23:47:53 +00:00
|
|
|
// cast away const from gAudioHeapInitSizes
|
|
|
|
*((u32*)&gAudioHeapInitSizes.permanentPoolSize) = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-12 23:47:53 +00:00
|
|
|
AudioHeap_AllocPoolInit(&gAudioContext.permanentPool, ramAddr, gAudioHeapInitSizes.permanentPoolSize);
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContextInitalized = true;
|
2022-05-09 16:59:23 +00:00
|
|
|
osSendMesg(gAudioContext.taskStartQueueP, (OSMesg)gAudioContext.totalTaskCount, OS_MESG_NOBLOCK);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_InitSlowLoads(void) {
|
2022-06-03 19:59:02 +00:00
|
|
|
gAudioContext.slowLoads[0].state = SLOW_LOAD_STATE_WAITING;
|
|
|
|
gAudioContext.slowLoads[1].state = SLOW_LOAD_STATE_WAITING;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
s32 AudioLoad_SlowLoadSample(s32 fontId, s32 instId, s8* status) {
|
2022-06-19 14:31:08 +00:00
|
|
|
Sample* sample;
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioSlowLoad* slowLoad;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
sample = AudioLoad_GetFontSample(fontId, instId);
|
2021-07-27 23:44:58 +00:00
|
|
|
if (sample == NULL) {
|
2022-06-03 19:59:02 +00:00
|
|
|
*status = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (sample->medium == MEDIUM_RAM) {
|
2022-06-03 19:59:02 +00:00
|
|
|
*status = 2;
|
2021-07-27 23:44:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
slowLoad = &gAudioContext.slowLoads[gAudioContext.slowLoadPos];
|
2022-06-03 19:59:02 +00:00
|
|
|
if (slowLoad->state == SLOW_LOAD_STATE_DONE) {
|
|
|
|
slowLoad->state = SLOW_LOAD_STATE_WAITING;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
slowLoad->sample = *sample;
|
2022-06-03 19:59:02 +00:00
|
|
|
slowLoad->status = status;
|
2021-11-07 16:58:50 +00:00
|
|
|
slowLoad->curRamAddr =
|
|
|
|
AudioHeap_AllocSampleCache(sample->size, fontId, sample->sampleAddr, sample->medium, CACHE_TEMPORARY);
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (slowLoad->curRamAddr == NULL) {
|
|
|
|
if (sample->medium == MEDIUM_UNK || sample->codec == CODEC_S16_INMEMORY) {
|
2022-06-03 19:59:02 +00:00
|
|
|
*status = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
return -1;
|
|
|
|
} else {
|
2022-06-03 19:59:02 +00:00
|
|
|
*status = 3;
|
2021-07-27 23:44:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
slowLoad->state = SLOW_LOAD_STATE_START;
|
2021-11-07 16:58:50 +00:00
|
|
|
slowLoad->bytesRemaining = ALIGN16(sample->size);
|
|
|
|
slowLoad->ramAddr = slowLoad->curRamAddr;
|
2022-06-16 00:15:44 +00:00
|
|
|
slowLoad->curDevAddr = (u32)sample->sampleAddr;
|
2021-11-07 16:58:50 +00:00
|
|
|
slowLoad->medium = sample->medium;
|
|
|
|
slowLoad->seqOrFontId = fontId;
|
|
|
|
slowLoad->instId = instId;
|
|
|
|
if (slowLoad->medium == MEDIUM_UNK) {
|
|
|
|
slowLoad->unkMediumParam = gAudioContext.sampleBankTable->unkMediumParam;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.slowLoadPos ^= 1;
|
2021-07-27 23:44:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-19 14:31:08 +00:00
|
|
|
Sample* AudioLoad_GetFontSample(s32 fontId, s32 instId) {
|
|
|
|
Sample* sample;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (instId < 0x80) {
|
|
|
|
Instrument* instrument = Audio_GetInstrumentInner(fontId, instId);
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
if (instrument == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2022-06-19 14:31:08 +00:00
|
|
|
sample = instrument->normalPitchTunedSample.sample;
|
2021-11-07 16:58:50 +00:00
|
|
|
} else if (instId < 0x100) {
|
|
|
|
Drum* drum = Audio_GetDrum(fontId, instId - 0x80);
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
if (drum == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2022-06-19 14:31:08 +00:00
|
|
|
sample = drum->tunedSample.sample;
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2022-06-19 14:31:08 +00:00
|
|
|
SoundEffect* soundEffect = Audio_GetSoundEffect(fontId, instId - 0x100);
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2022-06-19 14:31:08 +00:00
|
|
|
if (soundEffect == NULL) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2022-06-19 14:31:08 +00:00
|
|
|
sample = soundEffect->tunedSample.sample;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2022-06-03 19:59:02 +00:00
|
|
|
return sample;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_Unused2(void) {
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_FinishSlowLoad(AudioSlowLoad* slowLoad) {
|
2022-06-19 14:31:08 +00:00
|
|
|
Sample* sample;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (slowLoad->sample.sampleAddr == NULL) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
sample = AudioLoad_GetFontSample(slowLoad->seqOrFontId, slowLoad->instId);
|
2021-07-27 23:44:58 +00:00
|
|
|
if (sample == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
slowLoad->sample = *sample;
|
|
|
|
sample->sampleAddr = slowLoad->ramAddr;
|
|
|
|
sample->medium = MEDIUM_RAM;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_ProcessSlowLoads(s32 resetStatus) {
|
|
|
|
AudioSlowLoad* slowLoad;
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 i;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(gAudioContext.slowLoads); i++) {
|
|
|
|
slowLoad = &gAudioContext.slowLoads[i];
|
2022-06-03 19:59:02 +00:00
|
|
|
switch (gAudioContext.slowLoads[i].state) {
|
|
|
|
case SLOW_LOAD_STATE_LOADING:
|
2021-11-07 16:58:50 +00:00
|
|
|
if (slowLoad->medium != MEDIUM_UNK) {
|
2022-04-09 00:20:23 +00:00
|
|
|
osRecvMesg(&slowLoad->msgQueue, NULL, OS_MESG_BLOCK);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (resetStatus != 0) {
|
2022-06-03 19:59:02 +00:00
|
|
|
slowLoad->state = SLOW_LOAD_STATE_DONE;
|
2021-07-27 23:44:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-06-03 16:51:23 +00:00
|
|
|
FALLTHROUGH;
|
2022-06-03 19:59:02 +00:00
|
|
|
case SLOW_LOAD_STATE_START:
|
|
|
|
slowLoad->state = SLOW_LOAD_STATE_LOADING;
|
2021-11-07 16:58:50 +00:00
|
|
|
if (slowLoad->bytesRemaining == 0) {
|
|
|
|
AudioLoad_FinishSlowLoad(slowLoad);
|
2022-06-03 19:59:02 +00:00
|
|
|
slowLoad->state = SLOW_LOAD_STATE_DONE;
|
|
|
|
*slowLoad->status = 1;
|
2021-11-07 16:58:50 +00:00
|
|
|
} else if (slowLoad->bytesRemaining < 0x400) {
|
|
|
|
if (slowLoad->medium == MEDIUM_UNK) {
|
|
|
|
u32 size = slowLoad->bytesRemaining;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioLoad_DmaSlowCopyUnkMedium(slowLoad->curDevAddr, slowLoad->curRamAddr, size,
|
|
|
|
slowLoad->unkMediumParam);
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioLoad_DmaSlowCopy(slowLoad, slowLoad->bytesRemaining);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
slowLoad->bytesRemaining = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2021-11-07 16:58:50 +00:00
|
|
|
if (slowLoad->medium == MEDIUM_UNK) {
|
|
|
|
AudioLoad_DmaSlowCopyUnkMedium(slowLoad->curDevAddr, slowLoad->curRamAddr, 0x400,
|
|
|
|
slowLoad->unkMediumParam);
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioLoad_DmaSlowCopy(slowLoad, 0x400);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
slowLoad->bytesRemaining -= 0x400;
|
|
|
|
slowLoad->curRamAddr += 0x400;
|
|
|
|
slowLoad->curDevAddr += 0x400;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_DmaSlowCopy(AudioSlowLoad* slowLoad, s32 size) {
|
2021-12-01 00:08:57 +00:00
|
|
|
Audio_InvalDCache(slowLoad->curRamAddr, size);
|
2022-04-09 00:20:23 +00:00
|
|
|
osCreateMesgQueue(&slowLoad->msgQueue, &slowLoad->msg, 1);
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_Dma(&slowLoad->ioMesg, OS_MESG_PRI_NORMAL, OS_READ, slowLoad->curDevAddr, slowLoad->curRamAddr, size,
|
2022-04-09 00:20:23 +00:00
|
|
|
&slowLoad->msgQueue, slowLoad->medium, "SLOWCOPY");
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_DmaSlowCopyUnkMedium(s32 devAddr, u8* ramAddr, s32 size, s32 arg3) {
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* status) {
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioSlowLoad* slowLoad;
|
|
|
|
AudioTable* seqTable;
|
2021-07-27 23:44:58 +00:00
|
|
|
u32 size;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (seqId >= gAudioContext.numSequences) {
|
2022-06-03 19:59:02 +00:00
|
|
|
*status = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
seqId = AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId);
|
|
|
|
seqTable = AudioLoad_GetLoadTable(SEQUENCE_TABLE);
|
|
|
|
slowLoad = &gAudioContext.slowLoads[gAudioContext.slowLoadPos];
|
2022-06-03 19:59:02 +00:00
|
|
|
if (slowLoad->state == SLOW_LOAD_STATE_DONE) {
|
|
|
|
slowLoad->state = SLOW_LOAD_STATE_WAITING;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
slowLoad->sample.sampleAddr = NULL;
|
2022-06-03 19:59:02 +00:00
|
|
|
slowLoad->status = status;
|
2021-11-07 16:58:50 +00:00
|
|
|
size = seqTable->entries[seqId].size;
|
2021-07-27 23:44:58 +00:00
|
|
|
size = ALIGN16(size);
|
2021-11-07 16:58:50 +00:00
|
|
|
slowLoad->curRamAddr = ramAddr;
|
2022-06-03 19:59:02 +00:00
|
|
|
slowLoad->state = SLOW_LOAD_STATE_START;
|
2021-11-07 16:58:50 +00:00
|
|
|
slowLoad->bytesRemaining = size;
|
|
|
|
slowLoad->ramAddr = ramAddr;
|
|
|
|
slowLoad->curDevAddr = seqTable->entries[seqId].romAddr;
|
|
|
|
slowLoad->medium = seqTable->entries[seqId].medium;
|
|
|
|
slowLoad->seqOrFontId = seqId;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (slowLoad->medium == MEDIUM_UNK) {
|
|
|
|
slowLoad->unkMediumParam = seqTable->unkMediumParam;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.slowLoadPos ^= 1;
|
2021-07-27 23:44:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_InitAsyncLoads(void) {
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 i;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(gAudioContext.asyncLoads); i++) {
|
|
|
|
gAudioContext.asyncLoads[i].status = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioAsyncLoad* AudioLoad_StartAsyncLoadUnkMedium(s32 unkMediumParam, u32 devAddr, void* ramAddr, s32 size, s32 medium,
|
|
|
|
s32 nChunks, OSMesgQueue* retQueue, s32 retMsg) {
|
|
|
|
AudioAsyncLoad* asyncLoad;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
asyncLoad = AudioLoad_StartAsyncLoad(devAddr, ramAddr, size, medium, nChunks, retQueue, retMsg);
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (asyncLoad == NULL) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
osSendMesg(&gAudioContext.asyncLoadUnkMediumQueue, (OSMesg)asyncLoad, OS_MESG_NOBLOCK);
|
2021-11-07 16:58:50 +00:00
|
|
|
asyncLoad->unkMediumParam = unkMediumParam;
|
|
|
|
return asyncLoad;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioAsyncLoad* AudioLoad_StartAsyncLoad(u32 devAddr, void* ramAddr, u32 size, s32 medium, s32 nChunks,
|
|
|
|
OSMesgQueue* retQueue, s32 retMsg) {
|
|
|
|
AudioAsyncLoad* asyncLoad;
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 i;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(gAudioContext.asyncLoads); i++) {
|
|
|
|
if (gAudioContext.asyncLoads[i].status == 0) {
|
|
|
|
asyncLoad = &gAudioContext.asyncLoads[i];
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
// no more available async loads
|
|
|
|
if (i == ARRAY_COUNT(gAudioContext.asyncLoads)) {
|
2021-07-27 23:44:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
asyncLoad->status = 1;
|
2021-11-07 16:58:50 +00:00
|
|
|
asyncLoad->curDevAddr = devAddr;
|
|
|
|
asyncLoad->ramAddr = ramAddr;
|
|
|
|
asyncLoad->curRamAddr = ramAddr;
|
|
|
|
asyncLoad->bytesRemaining = size;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
|
|
|
if (nChunks == 0) {
|
2021-11-07 16:58:50 +00:00
|
|
|
asyncLoad->chunkSize = 0x1000;
|
2021-07-27 23:44:58 +00:00
|
|
|
} else if (nChunks == 1) {
|
2021-11-07 16:58:50 +00:00
|
|
|
asyncLoad->chunkSize = size;
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2022-01-12 20:48:04 +00:00
|
|
|
asyncLoad->chunkSize = ALIGN256((s32)size / nChunks);
|
2021-11-07 16:58:50 +00:00
|
|
|
if (asyncLoad->chunkSize < 0x100) {
|
|
|
|
asyncLoad->chunkSize = 0x100;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
asyncLoad->retQueue = retQueue;
|
|
|
|
asyncLoad->delay = 3;
|
|
|
|
asyncLoad->medium = medium;
|
|
|
|
asyncLoad->retMsg = retMsg;
|
|
|
|
osCreateMesgQueue(&asyncLoad->msgQueue, &asyncLoad->msg, 1);
|
|
|
|
return asyncLoad;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_ProcessAsyncLoads(s32 resetStatus) {
|
|
|
|
AudioAsyncLoad* asyncLoad;
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 i;
|
|
|
|
|
|
|
|
if (gAudioContext.resetTimer == 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (gAudioContext.curUnkMediumLoad == NULL) {
|
2021-07-27 23:44:58 +00:00
|
|
|
if (resetStatus != 0) {
|
2021-11-07 16:58:50 +00:00
|
|
|
// Clear and ignore queue if resetting.
|
2021-07-27 23:44:58 +00:00
|
|
|
do {
|
2021-11-07 16:58:50 +00:00
|
|
|
} while (osRecvMesg(&gAudioContext.asyncLoadUnkMediumQueue, (OSMesg*)&asyncLoad, OS_MESG_NOBLOCK) != -1);
|
|
|
|
} else if (osRecvMesg(&gAudioContext.asyncLoadUnkMediumQueue, (OSMesg*)&asyncLoad, OS_MESG_NOBLOCK) == -1) {
|
|
|
|
gAudioContext.curUnkMediumLoad = NULL;
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.curUnkMediumLoad = asyncLoad;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (gAudioContext.curUnkMediumLoad != NULL) {
|
|
|
|
AudioLoad_ProcessAsyncLoadUnkMedium(gAudioContext.curUnkMediumLoad, resetStatus);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(gAudioContext.asyncLoads); i++) {
|
|
|
|
if (gAudioContext.asyncLoads[i].status == 1) {
|
|
|
|
asyncLoad = &gAudioContext.asyncLoads[i];
|
|
|
|
if (asyncLoad->medium != MEDIUM_UNK) {
|
|
|
|
AudioLoad_ProcessAsyncLoad(asyncLoad, resetStatus);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_ProcessAsyncLoadUnkMedium(AudioAsyncLoad* asyncLoad, s32 resetStatus) {
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_FinishAsyncLoad(AudioAsyncLoad* asyncLoad) {
|
|
|
|
u32 retMsg = asyncLoad->retMsg;
|
|
|
|
u32 fontId;
|
2021-07-27 23:44:58 +00:00
|
|
|
u32 pad;
|
|
|
|
OSMesg doneMsg;
|
2021-11-07 16:58:50 +00:00
|
|
|
u32 sampleBankId1;
|
|
|
|
u32 sampleBankId2;
|
2022-06-12 23:33:56 +00:00
|
|
|
SampleBankRelocInfo sampleBankReloc;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
|
|
|
if (1) {}
|
|
|
|
switch (ASYNC_TBLTYPE(retMsg)) {
|
|
|
|
case SEQUENCE_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SetSeqLoadStatus(ASYNC_ID(retMsg), ASYNC_LOAD_STATUS(retMsg));
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case SAMPLE_TABLE:
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SetSampleFontLoadStatusAndApplyCaches(ASYNC_ID(retMsg), ASYNC_LOAD_STATUS(retMsg));
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case FONT_TABLE:
|
|
|
|
fontId = ASYNC_ID(retMsg);
|
2022-06-19 14:31:08 +00:00
|
|
|
sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1;
|
|
|
|
sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2;
|
2022-06-12 23:33:56 +00:00
|
|
|
sampleBankReloc.sampleBankId1 = sampleBankId1;
|
|
|
|
sampleBankReloc.sampleBankId2 = sampleBankId2;
|
|
|
|
sampleBankReloc.baseAddr1 =
|
|
|
|
sampleBankId1 != 0xFF ? AudioLoad_GetSampleBank(sampleBankId1, &sampleBankReloc.medium1) : 0;
|
|
|
|
sampleBankReloc.baseAddr2 =
|
|
|
|
sampleBankId2 != 0xFF ? AudioLoad_GetSampleBank(sampleBankId2, &sampleBankReloc.medium2) : 0;
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SetFontLoadStatus(fontId, ASYNC_LOAD_STATUS(retMsg));
|
2022-06-12 23:33:56 +00:00
|
|
|
AudioLoad_RelocateFontAndPreloadSamples(fontId, asyncLoad->ramAddr, &sampleBankReloc, true);
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-06-16 00:15:44 +00:00
|
|
|
doneMsg = (OSMesg)asyncLoad->retMsg;
|
2021-07-27 23:44:58 +00:00
|
|
|
if (1) {}
|
2022-06-03 19:59:02 +00:00
|
|
|
asyncLoad->status = 0;
|
2021-11-07 16:58:50 +00:00
|
|
|
osSendMesg(asyncLoad->retQueue, doneMsg, OS_MESG_NOBLOCK);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_ProcessAsyncLoad(AudioAsyncLoad* asyncLoad, s32 resetStatus) {
|
|
|
|
AudioTable* sampleBankTable = gAudioContext.sampleBankTable;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (asyncLoad->delay >= 2) {
|
|
|
|
asyncLoad->delay--;
|
2021-07-27 23:44:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (asyncLoad->delay == 1) {
|
|
|
|
asyncLoad->delay = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
} else if (resetStatus != 0) {
|
2021-11-07 16:58:50 +00:00
|
|
|
// Await the previous DMA response synchronously, then return.
|
|
|
|
osRecvMesg(&asyncLoad->msgQueue, NULL, OS_MESG_BLOCK);
|
2022-06-03 19:59:02 +00:00
|
|
|
asyncLoad->status = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
return;
|
2021-11-07 16:58:50 +00:00
|
|
|
} else if (osRecvMesg(&asyncLoad->msgQueue, NULL, OS_MESG_NOBLOCK) == -1) {
|
|
|
|
// If the previous DMA step isn't done, return.
|
2021-07-27 23:44:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (asyncLoad->bytesRemaining == 0) {
|
|
|
|
AudioLoad_FinishAsyncLoad(asyncLoad);
|
2021-07-27 23:44:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (asyncLoad->bytesRemaining < asyncLoad->chunkSize) {
|
|
|
|
if (asyncLoad->medium == MEDIUM_UNK) {
|
|
|
|
AudioLoad_AsyncDmaUnkMedium(asyncLoad->curDevAddr, asyncLoad->curRamAddr, asyncLoad->bytesRemaining,
|
|
|
|
sampleBankTable->unkMediumParam);
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioLoad_AsyncDma(asyncLoad, asyncLoad->bytesRemaining);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
asyncLoad->bytesRemaining = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (asyncLoad->medium == MEDIUM_UNK) {
|
|
|
|
AudioLoad_AsyncDmaUnkMedium(asyncLoad->curDevAddr, asyncLoad->curRamAddr, asyncLoad->chunkSize,
|
|
|
|
sampleBankTable->unkMediumParam);
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioLoad_AsyncDma(asyncLoad, asyncLoad->chunkSize);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
asyncLoad->bytesRemaining -= asyncLoad->chunkSize;
|
|
|
|
asyncLoad->curDevAddr += asyncLoad->chunkSize;
|
|
|
|
asyncLoad->curRamAddr += asyncLoad->chunkSize;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_AsyncDma(AudioAsyncLoad* asyncLoad, u32 size) {
|
2021-07-27 23:44:58 +00:00
|
|
|
size = ALIGN16(size);
|
2021-12-01 00:08:57 +00:00
|
|
|
Audio_InvalDCache(asyncLoad->curRamAddr, size);
|
2021-11-07 16:58:50 +00:00
|
|
|
osCreateMesgQueue(&asyncLoad->msgQueue, &asyncLoad->msg, 1);
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_Dma(&asyncLoad->ioMesg, OS_MESG_PRI_NORMAL, OS_READ, asyncLoad->curDevAddr, asyncLoad->curRamAddr, size,
|
|
|
|
&asyncLoad->msgQueue, asyncLoad->medium, "BGCOPY");
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_AsyncDmaUnkMedium(u32 devAddr, void* ramAddr, u32 size, s16 arg3) {
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
/**
|
2022-06-19 14:31:08 +00:00
|
|
|
* Read and extract information from TunedSample and its Sample
|
2022-06-12 23:33:56 +00:00
|
|
|
* contained in the soundFont binary loaded into ram
|
2022-06-19 14:31:08 +00:00
|
|
|
* TunedSample contains metadata on a sample used by a particular instrument/drum/sfx
|
|
|
|
* Also relocate offsets into pointers within this loaded TunedSample
|
2022-06-12 23:33:56 +00:00
|
|
|
*
|
|
|
|
* @param fontId index of font being processed
|
|
|
|
* @param fontData ram address of raw soundfont binary loaded into cache
|
|
|
|
* @param sampleBankReloc information on the sampleBank containing raw audio samples
|
|
|
|
*/
|
2022-06-19 14:31:08 +00:00
|
|
|
void AudioLoad_RelocateSample(TunedSample* tunedSample, SoundFontData* fontData, SampleBankRelocInfo* sampleBankReloc) {
|
|
|
|
Sample* sample;
|
2021-07-27 23:44:58 +00:00
|
|
|
void* reloc;
|
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
// Relocate an offset (relative to data loaded in ram at `base`) to a pointer (a ram address)
|
|
|
|
#define AUDIO_RELOC(offset, base) (reloc = (void*)((u32)(offset) + (u32)(base)))
|
|
|
|
|
|
|
|
// If this has not already been relocated
|
2022-06-19 14:31:08 +00:00
|
|
|
if ((u32)tunedSample->sample <= AUDIO_RELOCATED_ADDRESS_START) {
|
2022-06-12 23:33:56 +00:00
|
|
|
|
2022-06-19 14:31:08 +00:00
|
|
|
sample = tunedSample->sample = AUDIO_RELOC(tunedSample->sample, fontData);
|
2022-06-12 23:33:56 +00:00
|
|
|
|
|
|
|
// If the sample exists and has not already been relocated
|
|
|
|
// Note: this is important, as the same sample can be used by different drums, sound effects, instruments
|
|
|
|
if ((sample->size != 0) && (sample->isRelocated != true)) {
|
|
|
|
sample->loop = AUDIO_RELOC(sample->loop, fontData);
|
|
|
|
sample->book = AUDIO_RELOC(sample->book, fontData);
|
2021-11-07 16:58:50 +00:00
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
// Resolve the sample medium 2-bit bitfield into a real value based on sampleBankReloc.
|
|
|
|
// Then relocate the offset sample within the sampleBank (not the fontData) into absolute address.
|
|
|
|
// sampleAddr can be either rom or ram depending on sampleBank cache policy
|
|
|
|
// in practice, this is always in rom
|
2021-08-31 22:53:35 +00:00
|
|
|
switch (sample->medium) {
|
2021-07-27 23:44:58 +00:00
|
|
|
case 0:
|
2022-06-12 23:33:56 +00:00
|
|
|
sample->sampleAddr = AUDIO_RELOC(sample->sampleAddr, sampleBankReloc->baseAddr1);
|
|
|
|
sample->medium = sampleBankReloc->medium1;
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-12 23:33:56 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
case 1:
|
2022-06-12 23:33:56 +00:00
|
|
|
sample->sampleAddr = AUDIO_RELOC(sample->sampleAddr, sampleBankReloc->baseAddr2);
|
|
|
|
sample->medium = sampleBankReloc->medium2;
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
2022-06-12 23:33:56 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
case 2:
|
|
|
|
case 3:
|
2021-11-07 16:58:50 +00:00
|
|
|
// Invalid? This leaves sample->medium as MEDIUM_CART and MEDIUM_DISK_DRIVE
|
|
|
|
// respectively, and the sampleAddr unrelocated.
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
sample->isRelocated = true;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (sample->unk_bit26 && (sample->medium != MEDIUM_RAM)) {
|
|
|
|
gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
#undef AUDIO_RELOC
|
|
|
|
}
|
2021-09-07 18:14:09 +00:00
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
/**
|
|
|
|
* @param fontId index of font being processed
|
|
|
|
* @param fontData ram address of raw soundfont binary loaded into cache
|
|
|
|
* @param sampleBankReloc information on the sampleBank containing raw audio samples
|
|
|
|
* @param isAsync bool for whether this is an asynchronous load or not
|
|
|
|
*/
|
|
|
|
void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData, SampleBankRelocInfo* sampleBankReloc,
|
|
|
|
s32 isAsync) {
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioPreloadReq* preload;
|
|
|
|
AudioPreloadReq* topPreload;
|
2022-06-19 14:31:08 +00:00
|
|
|
Sample* sample;
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 size;
|
2021-09-07 18:14:09 +00:00
|
|
|
s32 nChunks;
|
2022-06-03 19:59:02 +00:00
|
|
|
u8* sampleRamAddr;
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 preloadInProgress;
|
2021-09-07 18:14:09 +00:00
|
|
|
s32 i;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
preloadInProgress = false;
|
|
|
|
if (gAudioContext.preloadSampleStackTop != 0) {
|
|
|
|
preloadInProgress = true;
|
2021-09-07 18:14:09 +00:00
|
|
|
} else {
|
|
|
|
D_8016B780 = 0;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.numUsedSamples = 0;
|
2022-06-12 23:33:56 +00:00
|
|
|
AudioLoad_RelocateFont(fontId, fontData, sampleBankReloc);
|
2021-11-07 16:58:50 +00:00
|
|
|
|
|
|
|
size = 0;
|
|
|
|
for (i = 0; i < gAudioContext.numUsedSamples; i++) {
|
|
|
|
size += ALIGN16(gAudioContext.usedSamples[i]->size);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
if (size && size) {}
|
2021-09-07 18:14:09 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = 0; i < gAudioContext.numUsedSamples; i++) {
|
|
|
|
if (gAudioContext.preloadSampleStackTop == 120) {
|
2021-09-07 18:14:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
sample = gAudioContext.usedSamples[i];
|
2022-06-03 19:59:02 +00:00
|
|
|
sampleRamAddr = NULL;
|
2022-06-12 23:33:56 +00:00
|
|
|
switch (isAsync) {
|
2021-11-07 16:58:50 +00:00
|
|
|
case false:
|
2022-06-12 23:33:56 +00:00
|
|
|
if (sample->medium == sampleBankReloc->medium1) {
|
|
|
|
sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId1,
|
2022-06-03 19:59:02 +00:00
|
|
|
sample->sampleAddr, sample->medium, CACHE_PERSISTENT);
|
2022-06-12 23:33:56 +00:00
|
|
|
} else if (sample->medium == sampleBankReloc->medium2) {
|
|
|
|
sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId2,
|
2022-06-03 19:59:02 +00:00
|
|
|
sample->sampleAddr, sample->medium, CACHE_PERSISTENT);
|
2021-11-07 16:58:50 +00:00
|
|
|
} else if (sample->medium == MEDIUM_DISK_DRIVE) {
|
2022-06-03 19:59:02 +00:00
|
|
|
sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, 0xFE, sample->sampleAddr, sample->medium,
|
|
|
|
CACHE_PERSISTENT);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case true:
|
2022-06-12 23:33:56 +00:00
|
|
|
if (sample->medium == sampleBankReloc->medium1) {
|
|
|
|
sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId1,
|
2022-06-03 19:59:02 +00:00
|
|
|
sample->sampleAddr, sample->medium, CACHE_TEMPORARY);
|
2022-06-12 23:33:56 +00:00
|
|
|
} else if (sample->medium == sampleBankReloc->medium2) {
|
|
|
|
sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId2,
|
2022-06-03 19:59:02 +00:00
|
|
|
sample->sampleAddr, sample->medium, CACHE_TEMPORARY);
|
2021-11-07 16:58:50 +00:00
|
|
|
} else if (sample->medium == MEDIUM_DISK_DRIVE) {
|
2022-06-03 19:59:02 +00:00
|
|
|
sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, 0xFE, sample->sampleAddr, sample->medium,
|
|
|
|
CACHE_TEMPORARY);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-06-03 19:59:02 +00:00
|
|
|
if (sampleRamAddr == NULL) {
|
2021-09-07 18:14:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
switch (isAsync) {
|
2021-11-07 16:58:50 +00:00
|
|
|
case false:
|
|
|
|
if (sample->medium == MEDIUM_UNK) {
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SyncDmaUnkMedium((u32)sample->sampleAddr, sampleRamAddr, sample->size,
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.sampleBankTable->unkMediumParam);
|
2022-06-03 19:59:02 +00:00
|
|
|
sample->sampleAddr = sampleRamAddr;
|
2021-11-07 16:58:50 +00:00
|
|
|
sample->medium = MEDIUM_RAM;
|
2021-09-07 18:14:09 +00:00
|
|
|
} else {
|
2022-06-03 19:59:02 +00:00
|
|
|
AudioLoad_SyncDma((u32)sample->sampleAddr, sampleRamAddr, sample->size, sample->medium);
|
|
|
|
sample->sampleAddr = sampleRamAddr;
|
2021-11-07 16:58:50 +00:00
|
|
|
sample->medium = MEDIUM_RAM;
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
if (sample->medium == MEDIUM_DISK_DRIVE) {}
|
2021-09-07 18:14:09 +00:00
|
|
|
break;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case true:
|
|
|
|
preload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop];
|
|
|
|
preload->sample = sample;
|
2022-06-03 19:59:02 +00:00
|
|
|
preload->ramAddr = sampleRamAddr;
|
2021-11-07 16:58:50 +00:00
|
|
|
preload->encodedInfo = (gAudioContext.preloadSampleStackTop << 24) | 0xFFFFFF;
|
|
|
|
preload->isFree = false;
|
|
|
|
preload->endAndMediumKey = (u32)sample->sampleAddr + sample->size + sample->medium;
|
|
|
|
gAudioContext.preloadSampleStackTop++;
|
2021-09-07 18:14:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.numUsedSamples = 0;
|
2021-09-07 18:14:09 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (gAudioContext.preloadSampleStackTop != 0 && !preloadInProgress) {
|
|
|
|
topPreload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop - 1];
|
|
|
|
sample = topPreload->sample;
|
2021-09-07 18:14:09 +00:00
|
|
|
nChunks = (sample->size >> 12) + 1;
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioLoad_StartAsyncLoad((u32)sample->sampleAddr, topPreload->ramAddr, sample->size, sample->medium, nChunks,
|
|
|
|
&gAudioContext.preloadSampleQueue, topPreload->encodedInfo);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) {
|
2022-06-19 14:31:08 +00:00
|
|
|
Sample* sample;
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioPreloadReq* preload;
|
|
|
|
u32 preloadIndex;
|
2021-08-30 00:51:57 +00:00
|
|
|
u32 key;
|
2021-11-07 16:58:50 +00:00
|
|
|
u32 nChunks;
|
2021-08-30 00:51:57 +00:00
|
|
|
s32 pad;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (gAudioContext.preloadSampleStackTop > 0) {
|
2021-07-27 23:44:58 +00:00
|
|
|
if (resetStatus != 0) {
|
2021-11-07 16:58:50 +00:00
|
|
|
// Clear result queue and preload stack and return.
|
|
|
|
osRecvMesg(&gAudioContext.preloadSampleQueue, (OSMesg*)&preloadIndex, OS_MESG_NOBLOCK);
|
|
|
|
gAudioContext.preloadSampleStackTop = 0;
|
2022-06-03 19:59:02 +00:00
|
|
|
return false;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
if (osRecvMesg(&gAudioContext.preloadSampleQueue, (OSMesg*)&preloadIndex, OS_MESG_NOBLOCK) == -1) {
|
|
|
|
// Previous preload is not done yet.
|
2022-06-03 19:59:02 +00:00
|
|
|
return false;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
preloadIndex >>= 24;
|
|
|
|
preload = &gAudioContext.preloadSampleStack[preloadIndex];
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (preload->isFree == false) {
|
|
|
|
sample = preload->sample;
|
2021-08-31 22:53:35 +00:00
|
|
|
key = (u32)sample->sampleAddr + sample->size + sample->medium;
|
2021-11-07 16:58:50 +00:00
|
|
|
if (key == preload->endAndMediumKey) {
|
|
|
|
// Change storage for sample to the preloaded version.
|
|
|
|
sample->sampleAddr = preload->ramAddr;
|
|
|
|
sample->medium = MEDIUM_RAM;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
preload->isFree = true;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
// Pop requests with isFree = true off the stack, as far as possible,
|
|
|
|
// and dispatch the next DMA.
|
2021-08-30 00:51:57 +00:00
|
|
|
for (;;) {
|
2021-11-07 16:58:50 +00:00
|
|
|
if (gAudioContext.preloadSampleStackTop <= 0) {
|
2021-08-30 00:51:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
preload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop - 1];
|
|
|
|
if (preload->isFree == true) {
|
|
|
|
gAudioContext.preloadSampleStackTop--;
|
2021-07-27 23:44:58 +00:00
|
|
|
continue;
|
2021-08-30 00:51:57 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
sample = preload->sample;
|
|
|
|
nChunks = (sample->size >> 12) + 1;
|
2021-08-31 22:53:35 +00:00
|
|
|
key = (u32)sample->sampleAddr + sample->size + sample->medium;
|
2021-11-07 16:58:50 +00:00
|
|
|
if (key != preload->endAndMediumKey) {
|
|
|
|
preload->isFree = true;
|
|
|
|
gAudioContext.preloadSampleStackTop--;
|
2021-07-27 23:44:58 +00:00
|
|
|
} else {
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioLoad_StartAsyncLoad((u32)sample->sampleAddr, preload->ramAddr, sample->size, sample->medium,
|
|
|
|
nChunks, &gAudioContext.preloadSampleQueue, preload->encodedInfo);
|
2021-08-30 00:51:57 +00:00
|
|
|
break;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-03 19:59:02 +00:00
|
|
|
return true;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 14:31:08 +00:00
|
|
|
s32 AudioLoad_AddToSampleSet(Sample* sample, s32 numSamples, Sample** sampleSet) {
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 i;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = 0; i < numSamples; i++) {
|
|
|
|
if (sample->sampleAddr == sampleSet[i]->sampleAddr) {
|
2021-07-27 23:44:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (i == numSamples) {
|
|
|
|
sampleSet[numSamples] = sample;
|
|
|
|
numSamples++;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
return numSamples;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 14:31:08 +00:00
|
|
|
s32 AudioLoad_GetSamplesForFont(s32 fontId, Sample** sampleSet) {
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 i;
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 numSamples = 0;
|
2022-06-19 14:31:08 +00:00
|
|
|
s32 numDrums = gAudioContext.soundFontList[fontId].numDrums;
|
|
|
|
s32 numInstruments = gAudioContext.soundFontList[fontId].numInstruments;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = 0; i < numDrums; i++) {
|
|
|
|
Drum* drum = Audio_GetDrum(fontId, i);
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
if (1) {}
|
|
|
|
if (drum != NULL) {
|
2022-06-19 14:31:08 +00:00
|
|
|
numSamples = AudioLoad_AddToSampleSet(drum->tunedSample.sample, numSamples, sampleSet);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = 0; i < numInstruments; i++) {
|
|
|
|
Instrument* instrument = Audio_GetInstrumentInner(fontId, i);
|
2022-06-03 19:59:02 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
if (instrument != NULL) {
|
|
|
|
if (instrument->normalRangeLo != 0) {
|
2022-06-19 14:31:08 +00:00
|
|
|
numSamples = AudioLoad_AddToSampleSet(instrument->lowPitchTunedSample.sample, numSamples, sampleSet);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
if (instrument->normalRangeHi != 0x7F) {
|
2022-06-19 14:31:08 +00:00
|
|
|
numSamples = AudioLoad_AddToSampleSet(instrument->highPitchTunedSample.sample, numSamples, sampleSet);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2022-06-19 14:31:08 +00:00
|
|
|
numSamples = AudioLoad_AddToSampleSet(instrument->normalPitchTunedSample.sample, numSamples, sampleSet);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
// Should really also process sfx, but this method is never called.
|
2021-11-07 16:58:50 +00:00
|
|
|
return numSamples;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 14:31:08 +00:00
|
|
|
void AudioLoad_AddUsedSample(TunedSample* tunedSample) {
|
|
|
|
Sample* sample = tunedSample->sample;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
if ((sample->size != 0) && sample->unk_bit26 && (sample->medium != MEDIUM_RAM)) {
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, SampleBankRelocInfo* sampleBankReloc) {
|
2021-09-07 18:14:09 +00:00
|
|
|
s32 numDrums;
|
|
|
|
s32 numInstruments;
|
|
|
|
s32 numSfx;
|
|
|
|
Drum* drum;
|
|
|
|
Instrument* instrument;
|
2022-06-19 14:31:08 +00:00
|
|
|
SoundEffect* soundEffect;
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioPreloadReq* preload;
|
|
|
|
AudioPreloadReq* topPreload;
|
2021-09-07 18:14:09 +00:00
|
|
|
u8* addr;
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 size;
|
2021-09-07 18:14:09 +00:00
|
|
|
s32 i;
|
2022-06-19 14:31:08 +00:00
|
|
|
Sample* sample;
|
2021-11-07 16:58:50 +00:00
|
|
|
s32 preloadInProgress;
|
2021-09-07 18:14:09 +00:00
|
|
|
s32 nChunks;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
preloadInProgress = false;
|
|
|
|
if (gAudioContext.preloadSampleStackTop != 0) {
|
|
|
|
preloadInProgress = true;
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.numUsedSamples = 0;
|
|
|
|
|
2022-06-19 14:31:08 +00:00
|
|
|
numDrums = gAudioContext.soundFontList[fontId].numDrums;
|
|
|
|
numInstruments = gAudioContext.soundFontList[fontId].numInstruments;
|
|
|
|
numSfx = gAudioContext.soundFontList[fontId].numSfx;
|
2021-09-07 18:14:09 +00:00
|
|
|
|
|
|
|
for (i = 0; i < numInstruments; i++) {
|
2021-11-07 16:58:50 +00:00
|
|
|
instrument = Audio_GetInstrumentInner(fontId, i);
|
2021-09-07 18:14:09 +00:00
|
|
|
if (instrument != NULL) {
|
|
|
|
if (instrument->normalRangeLo != 0) {
|
2022-06-19 14:31:08 +00:00
|
|
|
AudioLoad_AddUsedSample(&instrument->lowPitchTunedSample);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
|
|
|
if (instrument->normalRangeHi != 0x7F) {
|
2022-06-19 14:31:08 +00:00
|
|
|
AudioLoad_AddUsedSample(&instrument->highPitchTunedSample);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
2022-06-19 14:31:08 +00:00
|
|
|
AudioLoad_AddUsedSample(&instrument->normalPitchTunedSample);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < numDrums; i++) {
|
2021-11-07 16:58:50 +00:00
|
|
|
drum = Audio_GetDrum(fontId, i);
|
2021-09-07 18:14:09 +00:00
|
|
|
if (drum != NULL) {
|
2022-06-19 14:31:08 +00:00
|
|
|
AudioLoad_AddUsedSample(&drum->tunedSample);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < numSfx; i++) {
|
2022-06-19 14:31:08 +00:00
|
|
|
soundEffect = Audio_GetSoundEffect(fontId, i);
|
|
|
|
if (soundEffect != NULL) {
|
|
|
|
AudioLoad_AddUsedSample(&soundEffect->tunedSample);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (gAudioContext.numUsedSamples == 0) {
|
2021-09-07 18:14:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
size = 0;
|
|
|
|
for (i = 0; i < gAudioContext.numUsedSamples; i++) {
|
|
|
|
size += ALIGN16(gAudioContext.usedSamples[i]->size);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
if (size) {}
|
2021-09-07 18:14:09 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
for (i = 0; i < gAudioContext.numUsedSamples; i++) {
|
|
|
|
if (gAudioContext.preloadSampleStackTop == 120) {
|
2021-09-07 18:14:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
sample = gAudioContext.usedSamples[i];
|
|
|
|
if (sample->medium == MEDIUM_RAM) {
|
2021-09-07 18:14:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
switch (async) {
|
|
|
|
case false:
|
2022-06-12 23:33:56 +00:00
|
|
|
if (sample->medium == sampleBankReloc->medium1) {
|
|
|
|
addr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId1, sample->sampleAddr,
|
2021-11-07 16:58:50 +00:00
|
|
|
sample->medium, CACHE_PERSISTENT);
|
2022-06-12 23:33:56 +00:00
|
|
|
} else if (sample->medium == sampleBankReloc->medium2) {
|
|
|
|
addr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId2, sample->sampleAddr,
|
2021-11-07 16:58:50 +00:00
|
|
|
sample->medium, CACHE_PERSISTENT);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case true:
|
2022-06-12 23:33:56 +00:00
|
|
|
if (sample->medium == sampleBankReloc->medium1) {
|
|
|
|
addr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId1, sample->sampleAddr,
|
2021-11-07 16:58:50 +00:00
|
|
|
sample->medium, CACHE_TEMPORARY);
|
2022-06-12 23:33:56 +00:00
|
|
|
} else if (sample->medium == sampleBankReloc->medium2) {
|
|
|
|
addr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId2, sample->sampleAddr,
|
2021-11-07 16:58:50 +00:00
|
|
|
sample->medium, CACHE_TEMPORARY);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (addr == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
switch (async) {
|
|
|
|
case false:
|
|
|
|
if (sample->medium == MEDIUM_UNK) {
|
|
|
|
AudioLoad_SyncDmaUnkMedium((u32)sample->sampleAddr, addr, sample->size,
|
|
|
|
gAudioContext.sampleBankTable->unkMediumParam);
|
2021-09-07 18:14:09 +00:00
|
|
|
sample->sampleAddr = addr;
|
2021-11-07 16:58:50 +00:00
|
|
|
sample->medium = MEDIUM_RAM;
|
2021-09-07 18:14:09 +00:00
|
|
|
} else {
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioLoad_SyncDma((u32)sample->sampleAddr, addr, sample->size, sample->medium);
|
2021-09-07 18:14:09 +00:00
|
|
|
sample->sampleAddr = addr;
|
2021-11-07 16:58:50 +00:00
|
|
|
sample->medium = MEDIUM_RAM;
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
case true:
|
|
|
|
preload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop];
|
|
|
|
preload->sample = sample;
|
|
|
|
preload->ramAddr = addr;
|
|
|
|
preload->encodedInfo = (gAudioContext.preloadSampleStackTop << 24) | 0xFFFFFF;
|
|
|
|
preload->isFree = false;
|
|
|
|
preload->endAndMediumKey = (u32)sample->sampleAddr + sample->size + sample->medium;
|
|
|
|
gAudioContext.preloadSampleStackTop++;
|
2021-09-07 18:14:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-11-07 16:58:50 +00:00
|
|
|
gAudioContext.numUsedSamples = 0;
|
2021-09-07 18:14:09 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (gAudioContext.preloadSampleStackTop != 0 && !preloadInProgress) {
|
|
|
|
topPreload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop - 1];
|
|
|
|
sample = topPreload->sample;
|
2021-09-07 18:14:09 +00:00
|
|
|
nChunks = (sample->size >> 12) + 1;
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioLoad_StartAsyncLoad((u32)sample->sampleAddr, topPreload->ramAddr, sample->size, sample->medium, nChunks,
|
|
|
|
&gAudioContext.preloadSampleQueue, topPreload->encodedInfo);
|
2021-09-07 18:14:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_LoadPermanentSamples(void) {
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 pad;
|
2021-11-07 16:58:50 +00:00
|
|
|
u32 fontId;
|
|
|
|
AudioTable* sampleBankTable;
|
2021-07-27 23:44:58 +00:00
|
|
|
s32 pad2;
|
|
|
|
s32 i;
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
sampleBankTable = AudioLoad_GetLoadTable(SAMPLE_TABLE);
|
2022-06-03 19:59:02 +00:00
|
|
|
for (i = 0; i < gAudioContext.permanentPool.numEntries; i++) {
|
2022-06-12 23:33:56 +00:00
|
|
|
SampleBankRelocInfo sampleBankReloc;
|
2021-11-07 16:58:50 +00:00
|
|
|
|
|
|
|
if (gAudioContext.permanentCache[i].tableType == FONT_TABLE) {
|
|
|
|
fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioContext.permanentCache[i].id);
|
2022-06-19 14:31:08 +00:00
|
|
|
sampleBankReloc.sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1;
|
|
|
|
sampleBankReloc.sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2;
|
2021-11-07 16:58:50 +00:00
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
if (sampleBankReloc.sampleBankId1 != 0xFF) {
|
|
|
|
sampleBankReloc.sampleBankId1 =
|
|
|
|
AudioLoad_GetRealTableIndex(SAMPLE_TABLE, sampleBankReloc.sampleBankId1);
|
|
|
|
sampleBankReloc.medium1 = sampleBankTable->entries[sampleBankReloc.sampleBankId1].medium;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-12 23:33:56 +00:00
|
|
|
if (sampleBankReloc.sampleBankId2 != 0xFF) {
|
|
|
|
sampleBankReloc.sampleBankId2 =
|
|
|
|
AudioLoad_GetRealTableIndex(SAMPLE_TABLE, sampleBankReloc.sampleBankId2);
|
|
|
|
sampleBankReloc.medium2 = sampleBankTable->entries[sampleBankReloc.sampleBankId2].medium;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
2022-06-12 23:33:56 +00:00
|
|
|
AudioLoad_PreloadSamplesForFont(fontId, false, &sampleBankReloc);
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_Unused3(void) {
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_Unused4(void) {
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_Unused5(void) {
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:59:02 +00:00
|
|
|
void AudioLoad_ScriptLoad(s32 tableType, s32 id, s8* status) {
|
2021-11-07 16:58:50 +00:00
|
|
|
static u32 sLoadIndex = 0;
|
2022-06-03 19:59:02 +00:00
|
|
|
|
|
|
|
sScriptLoadDonePointers[sLoadIndex] = status;
|
2021-11-07 16:58:50 +00:00
|
|
|
AudioLoad_AsyncLoad(tableType, id, 0, sLoadIndex, &sScriptLoadQueue);
|
|
|
|
sLoadIndex++;
|
|
|
|
if (sLoadIndex == 0x10) {
|
|
|
|
sLoadIndex = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_ProcessScriptLoads(void) {
|
|
|
|
u32 temp;
|
2021-07-27 23:44:58 +00:00
|
|
|
u32 sp20;
|
2022-06-03 19:59:02 +00:00
|
|
|
s8* status;
|
2021-07-27 23:44:58 +00:00
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
if (osRecvMesg(&sScriptLoadQueue, (OSMesg*)&sp20, OS_MESG_NOBLOCK) != -1) {
|
|
|
|
temp = sp20 >> 24;
|
2022-06-03 19:59:02 +00:00
|
|
|
status = sScriptLoadDonePointers[temp];
|
|
|
|
if (status != NULL) {
|
|
|
|
*status = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:58:50 +00:00
|
|
|
void AudioLoad_InitScriptLoads(void) {
|
2022-04-09 00:20:23 +00:00
|
|
|
osCreateMesgQueue(&sScriptLoadQueue, sScriptLoadMsgBuf, ARRAY_COUNT(sScriptLoadMsgBuf));
|
2021-07-27 23:44:58 +00:00
|
|
|
}
|