summaryrefslogtreecommitdiff
path: root/soh/src/code/audio_load.c
diff options
context:
space:
mode:
authorKevin Alexis Contreras <36680385+KiritoDv@users.noreply.github.com>2022-06-01 15:11:11 -0500
committerKevin Alexis Contreras <36680385+KiritoDv@users.noreply.github.com>2022-06-01 15:11:11 -0500
commit0320107fc03bfb17192191ae12f4380d76d850cf (patch)
treed5cec2396720cda5f5350518636d278f01d02429 /soh/src/code/audio_load.c
parent0067a69795c160332eab0f2ef5188a062d03b81f (diff)
parent6f5ce7d7157d60c22ca7cd43ff576fc54dc50dbc (diff)
Merge branch 'zapd_audio_support' into zelda64
Diffstat (limited to 'soh/src/code/audio_load.c')
-rw-r--r--soh/src/code/audio_load.c367
1 files changed, 275 insertions, 92 deletions
diff --git a/soh/src/code/audio_load.c b/soh/src/code/audio_load.c
index fee03e9ae..c9a8c6c46 100644
--- a/soh/src/code/audio_load.c
+++ b/soh/src/code/audio_load.c
@@ -4,6 +4,7 @@
#include "ultra64.h"
#include "global.h"
+#include "soh/OTRGlobals.h"
#define MK_ASYNC_MSG(retData, tableType, id, status) (((retData) << 24) | ((tableType) << 16) | ((id) << 8) | (status))
#define ASYNC_TBLTYPE(v) ((u8)(v >> 16))
@@ -37,11 +38,11 @@ void AudioLoad_ProcessAsyncLoads(s32 resetStatus);
void AudioLoad_ProcessAsyncLoadUnkMedium(AudioAsyncLoad* asyncLoad, s32 resetStatus);
void AudioLoad_ProcessAsyncLoad(AudioAsyncLoad* asyncLoad, s32 resetStatus);
void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo, s32 temporary);
-void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo);
+void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo, int fontId);
void AudioLoad_DiscardFont(s32 fontId);
uintptr_t AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 noLoad);
uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 tableId, s32* didAllocate);
-uintptr_t AudioLoad_GetRealTableIndex(s32 tableType, u32 tableId);
+u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 tableId);
void* AudioLoad_SearchCaches(s32 tableType, s32 id);
AudioTable* AudioLoad_GetLoadTable(s32 tableType);
void AudioLoad_SyncDma(uintptr_t devAddr, u8* addr, size_t size, s32 medium);
@@ -75,6 +76,11 @@ void* sUnusedHandler = NULL;
s32 gAudioContextInitalized = false;
+uintptr_t fontStart;
+uint32_t fontOffsets[8192];
+
+bool gUseLegacySD = false;
+
void AudioLoad_DecreaseSampleDmaTtls(void) {
u32 i;
@@ -279,8 +285,11 @@ void AudioLoad_InitSampleDmaBuffers(s32 arg0) {
}
s32 AudioLoad_IsFontLoadComplete(s32 fontId) {
+ return true;
+
if (fontId == 0xFF) {
return true;
+
} else if (gAudioContext.fontLoadStatus[fontId] >= 2) {
return true;
} else if (gAudioContext.fontLoadStatus[AudioLoad_GetRealTableIndex(FONT_TABLE, fontId)] >= 2) {
@@ -353,6 +362,9 @@ void AudioLoad_InitTable(AudioTable* table, uintptr_t romAddr, u16 unkMediumPara
for (i = 0; i < table->numEntries; i++) {
if ((table->entries[i].size != 0) && (table->entries[i].medium == MEDIUM_CART)) {
+ if (romAddr == fontStart)
+ fontOffsets[i] = table->entries[i].romAddr;
+
table->entries[i].romAddr += romAddr;
}
}
@@ -401,7 +413,8 @@ void AudioLoad_SyncLoadSeqParts(s32 seqId, s32 arg1) {
s32 AudioLoad_SyncLoadSample(SoundFontSample* sample, s32 fontId) {
void* sampleAddr;
- if (sample->unk_bit25 == 1) {
+ if (sample->unk_bit25 == 1)
+ {
if (sample->medium != MEDIUM_RAM) {
sampleAddr = AudioHeap_AllocSampleCache(sample->size, fontId, (void*)sample->sampleAddr, sample->medium,
CACHE_PERSISTENT);
@@ -549,7 +562,7 @@ s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) {
s32 numFonts;
s32 fontId;
- if (seqId >= gAudioContext.numSequences) {
+ if (gUseLegacySD && seqId >= gAudioContext.numSequences) {
return 0;
}
@@ -561,18 +574,27 @@ s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) {
while (numFonts > 0) {
fontId = gAudioContext.sequenceFontTable[index++];
- AudioLoad_SyncLoadFont(fontId);
+
+ //if (gUseLegacySD)
+ AudioLoad_SyncLoadFont(fontId);
+
numFonts--;
}
seqData = AudioLoad_SyncLoadSeq(seqId);
+
if (seqData == NULL) {
return 0;
}
AudioSeq_ResetSequencePlayer(seqPlayer);
seqPlayer->seqId = seqId;
- seqPlayer->defaultFont = AudioLoad_GetRealTableIndex(FONT_TABLE, fontId);
+
+ if (gUseLegacySD)
+ seqPlayer->defaultFont = AudioLoad_GetRealTableIndex(FONT_TABLE, fontId);
+ else
+ seqPlayer->defaultFont = fontId;
+
seqPlayer->seqData = seqData;
seqPlayer->enabled = 1;
seqPlayer->scriptState.pc = seqData;
@@ -638,12 +660,22 @@ SoundFontData* AudioLoad_SyncLoadFont(u32 fontId) {
s32 didAllocate;
RelocInfo relocInfo;
s32 realFontId = AudioLoad_GetRealTableIndex(FONT_TABLE, fontId);
+ //s32 realFontId = fontId;
if (gAudioContext.fontLoadStatus[realFontId] == 1) {
return NULL;
}
- sampleBankId1 = gAudioContext.soundFonts[realFontId].sampleBankId1;
- sampleBankId2 = gAudioContext.soundFonts[realFontId].sampleBankId2;
+
+ if (!gUseLegacySD) {
+ SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId);
+
+ sampleBankId1 = sf->sampleBankId1;
+ sampleBankId2 = sf->sampleBankId2;
+ } else {
+
+ sampleBankId1 = gAudioContext.soundFonts[realFontId].sampleBankId1;
+ sampleBankId2 = gAudioContext.soundFonts[realFontId].sampleBankId2;
+ }
relocInfo.sampleBankId1 = sampleBankId1;
relocInfo.sampleBankId2 = sampleBankId2;
@@ -686,13 +718,39 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
if (ret != NULL) {
*didAllocate = false;
status = 2;
- } else {
- table = AudioLoad_GetLoadTable(tableType);
- size = table->entries[realId].size;
- size = ALIGN16(size);
- medium = table->entries[id].medium;
- cachePolicy = table->entries[id].cachePolicy;
- romAddr = table->entries[realId].romAddr;
+ } else
+ {
+ char* seqData = 0;
+ SoundFont* fnt;
+
+ if (!gUseLegacySD && tableType == SEQUENCE_TABLE)
+ {
+ seqData = ResourceMgr_LoadSeqByID(id);
+ size = ResourceMgr_GetSeqSizeByID(id);
+ size -= 2;
+ medium = seqData[0];
+ cachePolicy = seqData[1];
+ romAddr = 0;
+ seqData += 2;
+ }
+ else if (!gUseLegacySD && tableType == FONT_TABLE)
+ {
+ fnt = ResourceMgr_LoadAudioSoundFont(id);
+ size = sizeof(SoundFont);
+ medium = 2;
+ cachePolicy = 0;
+ romAddr = 0;
+ }
+ else
+ {
+ table = AudioLoad_GetLoadTable(tableType);
+ size = table->entries[realId].size;
+ size = ALIGN16(size);
+ medium = table->entries[id].medium;
+ cachePolicy = table->entries[id].cachePolicy;
+ romAddr = table->entries[realId].romAddr;
+ }
+
switch (cachePolicy) {
case 0:
ret = AudioHeap_AllocPermanent(tableType, realId, size);
@@ -725,7 +783,14 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
if (medium == MEDIUM_UNK) {
AudioLoad_SyncDmaUnkMedium(romAddr, ret, size, (s16)table->unkMediumParam);
} else {
- AudioLoad_SyncDma(romAddr, ret, size, medium);
+ if (!gUseLegacySD && tableType == SEQUENCE_TABLE && seqData != NULL) {
+ AudioLoad_SyncDma(seqData, ret, size, medium);
+ } else if (!gUseLegacySD && tableType == FONT_TABLE) {
+ AudioLoad_SyncDma(fnt, ret, size, medium);
+ }
+ else {
+ AudioLoad_SyncDma(romAddr, ret, size, medium);
+ }
}
status = cachePolicy == 0 ? 5 : 2;
@@ -748,9 +813,15 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
return ret;
}
-uintptr_t AudioLoad_GetRealTableIndex(s32 tableType, u32 id) {
+u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 id) {
+ if ((tableType == SEQUENCE_TABLE || tableType == FONT_TABLE) && !gUseLegacySD) {
+ return id;
+ }
+
AudioTable* table = AudioLoad_GetLoadTable(tableType);
+ // If the size is 0, then this entry actually redirects to another entry.
+ // The rom address is actually an index into the same table where the "real" data is.
if (table->entries[id].size == 0) {
id = table->entries[id].romAddr;
}
@@ -801,29 +872,62 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo
Drum* drum;
SoundFontSound* sfx;
s32 i;
- s32 numDrums = gAudioContext.soundFonts[fontId].numDrums;
- s32 numInstruments = gAudioContext.soundFonts[fontId].numInstruments;
- s32 numSfx = gAudioContext.soundFonts[fontId].numSfx;
+ SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId);
+
+ s32 numDrums = 0;
+ s32 numInstruments = 0;
+ s32 numSfx = 0;
+
+ if (gUseLegacySD) {
+ numDrums = gAudioContext.soundFonts[fontId].numDrums;
+ numInstruments = gAudioContext.soundFonts[fontId].numInstruments;
+ numSfx = gAudioContext.soundFonts[fontId].numSfx;
+ } else {
+ numDrums = sf->numDrums;
+ numInstruments = sf->numInstruments;
+ numSfx = sf->numSfx;
+ }
+
void** ptrs = (void**)mem;
-#define BASE_OFFSET(x) (uintptr_t)((uintptr_t)(x) + (uintptr_t)(mem))
+#define BASE_OFFSET(x) (void*)((u32)(x) + (u32)(mem))
reloc2 = ptrs[0];
if (1) {}
- if ((reloc2 != 0) && (numDrums != 0)) {
+ if ((reloc2 != 0 || !gUseLegacySD) && (numDrums != 0))
+ {
ptrs[0] = BASE_OFFSET(reloc2);
- for (i = 0; i < numDrums; i++) {
- reloc = ((Drum**)ptrs[0])[i];
-
- if (reloc != 0) {
- reloc = BASE_OFFSET(reloc);
-
- ((Drum**)ptrs[0])[i] = drum = reloc;
- if (!drum->loaded) {
- AudioLoad_RelocateSample(&drum->sound, mem, relocInfo);
- reloc = drum->envelope;
- drum->envelope = BASE_OFFSET(reloc);
- drum->loaded = 1;
+ for (i = 0; i < numDrums; i++)
+ {
+ if (gUseLegacySD)
+ reloc = ((Drum**)ptrs[0])[i];
+
+ if (reloc != 0 || !gUseLegacySD)
+ {
+ if (gUseLegacySD)
+ {
+ reloc = BASE_OFFSET(reloc);
+ ((Drum**)ptrs[0])[i] = drum = reloc;
+ }
+
+ if (!gUseLegacySD)
+ drum = sf->drums[i];
+
+ if (!drum->loaded)
+ {
+ if (!gUseLegacySD)
+ {
+ AudioLoad_RelocateSample(&sf->drums[i]->sound, mem, relocInfo, fontOffsets[fontId]);
+ //reloc = drum->envelope;
+ drum->loaded = 1;
+ }
+ else
+ {
+ AudioLoad_RelocateSample(&drum->sound, mem, relocInfo, fontOffsets[fontId]);
+ reloc = drum->envelope;
+ drum->envelope = BASE_OFFSET(reloc);
+ drum->loaded = 1;
+ }
}
}
}
@@ -831,14 +935,19 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo
reloc2 = ptrs[1];
if (1) {}
- if ((reloc2 != 0) && (numSfx != 0)) {
+ if ((reloc2 != 0 || !gUseLegacySD) && (numSfx != 0)) {
ptrs[1] = BASE_OFFSET(reloc2);
for (i = 0; i < numSfx; i++) {
reloc = (SoundFontSound*)ptrs[1] + i;
- if (reloc != 0) {
- sfx = reloc;
- if (sfx->sample != NULL) {
- AudioLoad_RelocateSample(sfx, mem, relocInfo);
+ if (reloc != 0 || !gUseLegacySD)
+ {
+ if (!gUseLegacySD) {
+ AudioLoad_RelocateSample(&sf->soundEffects[i].sample, mem, relocInfo, fontOffsets[fontId]);
+ } else {
+ sfx = reloc;
+ if (sfx->sample != NULL) {
+ AudioLoad_RelocateSample(sfx, mem, relocInfo, fontOffsets[fontId]);
+ }
}
}
}
@@ -848,22 +957,34 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo
numInstruments = 0x7E;
}
- for (i = 2; i <= 2 + numInstruments - 1; i++) {
- if (ptrs[i] != NULL) {
+ int startI = gUseLegacySD ? 2 : 0;
+ int startEC = gUseLegacySD ? 2 + numInstruments - 1 : numInstruments - 1;
+ //for (i = 2; i <= 2 + numInstruments - 1; i++) {
+ for (i = startI; i <= startEC; i++) {
+ if (!gUseLegacySD || ptrs[i] != NULL)
+ {
ptrs[i] = BASE_OFFSET(ptrs[i]);
- inst = ptrs[i];
- if (!inst->loaded) {
- if (inst->normalRangeLo != 0) {
- AudioLoad_RelocateSample(&inst->lowNotesSound, mem, relocInfo);
+ if (gUseLegacySD)
+ inst = ptrs[i];
+ else
+ inst = sf->instruments[i];
+
+ if (inst != NULL && !inst->loaded) {
+ if (inst->normalRangeLo != 0)
+ {
+ AudioLoad_RelocateSample(&inst->lowNotesSound, mem, relocInfo, fontOffsets[fontId]);
}
- AudioLoad_RelocateSample(&inst->normalNotesSound, mem, relocInfo);
+ AudioLoad_RelocateSample(&inst->normalNotesSound, mem, relocInfo, fontOffsets[fontId]);
if (inst->normalRangeHi != 0x7F) {
- AudioLoad_RelocateSample(&inst->highNotesSound, mem, relocInfo);
+ AudioLoad_RelocateSample(&inst->highNotesSound, mem, relocInfo, fontOffsets[fontId]);
}
reloc = inst->envelope;
- inst->envelope = BASE_OFFSET(reloc);
+
+ if (gUseLegacySD)
+ inst->envelope = BASE_OFFSET(reloc);
+
inst->loaded = 1;
}
}
@@ -871,9 +992,11 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo
#undef BASE_OFFSET
- gAudioContext.soundFonts[fontId].drums = ptrs[0];
- gAudioContext.soundFonts[fontId].soundEffects = ptrs[1];
- gAudioContext.soundFonts[fontId].instruments = (Instrument**)(ptrs + 2);
+ if (gUseLegacySD) {
+ gAudioContext.soundFonts[fontId].drums = ptrs[0];
+ gAudioContext.soundFonts[fontId].soundEffects = ptrs[1];
+ gAudioContext.soundFonts[fontId].instruments = (Instrument**)(ptrs + 2);
+ }
}
void AudioLoad_SyncDma(uintptr_t devAddr, u8* addr, size_t size, s32 medium) {
@@ -1275,21 +1398,25 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
uintptr_t bankStart = ResourceMgr_LoadFileRaw(_AudiobankSegmentRomStart);
uintptr_t tableStart = ResourceMgr_LoadFileRaw(_AudiotableSegmentRomStart);
+ fontStart = bankStart;
+
AudioLoad_InitTable(gAudioContext.sequenceTable, seqStart, 0);
AudioLoad_InitTable(gAudioContext.soundFontTable, bankStart, 0);
AudioLoad_InitTable(gAudioContext.sampleBankTable, tableStart, 0);
numFonts = gAudioContext.soundFontTable->numEntries;
gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont));
- for (i = 0; i < numFonts; i++) {
- AudioLoad_InitSoundFontMeta(i);
- }
+ if (gUseLegacySD) {
+ for (i = 0; i < numFonts; i++) {
+ AudioLoad_InitSoundFontMeta(i);
+ }
- AudioLoad_InitSwapFont();
+ AudioLoad_InitSwapFont();
+ }
if (temp_v0_3 = AudioHeap_Alloc(&gAudioContext.audioInitPool, D_8014A6C4.permanentPoolSize), temp_v0_3 == NULL) {
// cast away const from D_8014A6C4
- *((size_t*)&D_8014A6C4.permanentPoolSize) = 0;
+ // *((u32*)&D_8014A6C4.permanentPoolSize) = 0;
}
AudioHeap_AllocPoolInit(&gAudioContext.permanentPool, temp_v0_3, D_8014A6C4.permanentPoolSize);
@@ -1459,28 +1586,40 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* isDone) {
AudioTable* seqTable;
size_t size;
- if (seqId >= gAudioContext.numSequences) {
+ if (gUseLegacySD && seqId >= gAudioContext.numSequences) {
*isDone = 0;
return -1;
}
seqId = AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId);
+
seqTable = AudioLoad_GetLoadTable(SEQUENCE_TABLE);
+
slowLoad = &gAudioContext.slowLoads[gAudioContext.slowLoadPos];
if (slowLoad->status == LOAD_STATUS_DONE) {
slowLoad->status = LOAD_STATUS_WAITING;
}
+
slowLoad->sample.sampleAddr = NULL;
slowLoad->isDone = isDone;
- size = seqTable->entries[seqId].size;
- size = ALIGN16(size);
+
+ if (!gUseLegacySD) {
+ char* seqData = ResourceMgr_LoadSeqByID(seqId);
+ size = ResourceMgr_GetSeqSizeByID(seqId) - 2;
+ slowLoad->curDevAddr = seqData + 2;
+ slowLoad->medium = seqData[0];
+ } else {
+ size = seqTable->entries[seqId].size;
+ size = ALIGN16(size);
+ slowLoad->curDevAddr = seqTable->entries[seqId].romAddr;
+ slowLoad->medium = seqTable->entries[seqId].medium;
+ }
+
slowLoad->curRamAddr = ramAddr;
slowLoad->status = LOAD_STATUS_START;
slowLoad->bytesRemaining = size;
slowLoad->ramAddr = ramAddr;
- slowLoad->curDevAddr = seqTable->entries[seqId].romAddr;
- slowLoad->medium = seqTable->entries[seqId].medium;
slowLoad->seqOrFontId = seqId;
if (slowLoad->medium == MEDIUM_UNK) {
@@ -1693,7 +1832,7 @@ void AudioLoad_AsyncDmaUnkMedium(uintptr_t devAddr, uintptr_t ramAddr, size_t si
#define RELOC(v, base) (reloc = (uintptr_t)((uintptr_t)(v) + (uintptr_t)(base)))
-void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo) {
+void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo, int fontId) {
// OTRTODO: This is hack to detect whether or not the sample has been relocated.
size_t maxSoundBankSize = 0x3EB2A0; // sample bank 0 is largest size at 0x3EB2A0
if ((uintptr_t)mem <= maxSoundBankSize) {
@@ -1705,32 +1844,58 @@ void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocIn
void* reloc;
// OTRTODO: Seems precarious to assume the RAM is never <= 0x3EB2A0, but it largely works.
- if ((uintptr_t)sound->sample < maxSoundBankSize) {
- sample = sound->sample = RELOC(sound->sample, mem);
- if (sample->size != 0 && sample->unk_bit25 != 1) {
- sample->loop = RELOC(sample->loop, mem);
- sample->book = RELOC(sample->book, mem);
-
- // Resolve the sample medium 2-bit bitfield into a real value based on relocInfo.
- switch (sample->medium) {
- case 0:
- sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr1);
- sample->medium = relocInfo->medium1;
- break;
- case 1:
- sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr2);
- sample->medium = relocInfo->medium2;
- break;
- case 2:
- case 3:
- // Invalid? This leaves sample->medium as MEDIUM_CART and MEDIUM_DISK_DRIVE
- // respectively, and the sampleAddr unrelocated.
- break;
+ if ((uintptr_t)sound->sample < maxSoundBankSize || !gUseLegacySD)
+ {
+ if (!gUseLegacySD) {
+ SoundFontSample* sample2 = sound;
+
+ if (sample2->unk_bit25 != 1)
+ {
+ //if (sample2->size == 0x5CC8)
+ //{
+ // switch (sample2->medium) {
+ // case 0:
+ // sample2->medium = relocInfo->medium1;
+ // break;
+ // case 1:
+ // sample2->medium = relocInfo->medium2;
+ // break;
+ // }
+
+ // sample2->unk_bit25 = 1;
+ // if (sample2->unk_bit26 && (sample2->medium != MEDIUM_RAM)) {
+ // // gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample2;
+ // }
+ //}
}
+ } else {
+ sample = sound->sample = RELOC(sound->sample, mem);
+
+ if (sample->size != 0 && sample->unk_bit25 != 1) {
+ sample->loop = RELOC(sample->loop, mem);
+ sample->book = RELOC(sample->book, mem);
+
+ // Resolve the sample medium 2-bit bitfield into a real value based on relocInfo.
+ switch (sample->medium) {
+ case 0:
+ sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr1);
+ sample->medium = relocInfo->medium1;
+ break;
+ case 1:
+ sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr2);
+ sample->medium = relocInfo->medium2;
+ break;
+ case 2:
+ case 3:
+ // Invalid? This leaves sample->medium as MEDIUM_CART and MEDIUM_DISK_DRIVE
+ // respectively, and the sampleAddr unrelocated.
+ break;
+ }
- sample->unk_bit25 = 1;
- if (sample->unk_bit26 && (sample->medium != MEDIUM_RAM)) {
- gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample;
+ sample->unk_bit25 = 1;
+ if (sample->unk_bit26 && (sample->medium != MEDIUM_RAM)) {
+ gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample;
+ }
}
}
}
@@ -1983,9 +2148,17 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, RelocInfo* relocInfo
gAudioContext.numUsedSamples = 0;
- numDrums = gAudioContext.soundFonts[fontId].numDrums;
- numInstruments = gAudioContext.soundFonts[fontId].numInstruments;
- numSfx = gAudioContext.soundFonts[fontId].numSfx;
+ if (!gUseLegacySD) {
+ SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId);
+
+ numDrums = sf->numDrums;
+ numInstruments = sf->numInstruments;
+ numSfx = sf->numSfx;
+ } else {
+ numDrums = gAudioContext.soundFonts[fontId].numDrums;
+ numInstruments = gAudioContext.soundFonts[fontId].numInstruments;
+ numSfx = gAudioContext.soundFonts[fontId].numSfx;
+ }
for (i = 0; i < numInstruments; i++) {
instrument = Audio_GetInstrumentInner(fontId, i);
@@ -2030,6 +2203,7 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, RelocInfo* relocInfo
}
sample = gAudioContext.usedSamples[i];
+
if (sample->medium == MEDIUM_RAM) {
continue;
}
@@ -2106,10 +2280,19 @@ void AudioLoad_LoadPermanentSamples(void) {
for (i = 0; i < gAudioContext.permanentPool.count; i++) {
RelocInfo relocInfo;
- if (gAudioContext.permanentCache[i].tableType == FONT_TABLE) {
+ if (gAudioContext.permanentCache[i].tableType == FONT_TABLE)
+ {
fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioContext.permanentCache[i].id);
- relocInfo.sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1;
- relocInfo.sampleBankId2 = gAudioContext.soundFonts[fontId].sampleBankId2;
+ //fontId = gAudioContext.permanentCache[i].id;
+
+ if (!gUseLegacySD) {
+ SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId);
+ relocInfo.sampleBankId1 = sf->sampleBankId1;
+ relocInfo.sampleBankId2 = sf->sampleBankId2;
+ } else {
+ relocInfo.sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1;
+ relocInfo.sampleBankId2 = gAudioContext.soundFonts[fontId].sampleBankId2;
+ }
if (relocInfo.sampleBankId1 != 0xFF) {
relocInfo.sampleBankId1 = AudioLoad_GetRealTableIndex(SAMPLE_TABLE, relocInfo.sampleBankId1);