Trying to reimplement the original functions

This commit is contained in:
KiritoDv 2024-11-02 08:49:29 -06:00
parent 9ec3886ea8
commit 5f1a34d9c9
5 changed files with 151 additions and 138 deletions

View File

@ -37,7 +37,7 @@ void AudioLoad_ProcessAsyncLoads(s32 resetStatus);
void AudioLoad_ProcessAsyncLoad(AudioAsyncLoad* asyncLoad, s32 resetStatus); void AudioLoad_ProcessAsyncLoad(AudioAsyncLoad* asyncLoad, s32 resetStatus);
void AudioLoad_AsyncDma(AudioAsyncLoad* asyncLoad, u32 size); void AudioLoad_AsyncDma(AudioAsyncLoad* asyncLoad, u32 size);
void AudioLoad_AsyncDmaUnkMedium(uintptr_t devAddr, u8* ramAddr, u32 size, s32 unkMediumParam); void AudioLoad_AsyncDmaUnkMedium(uintptr_t devAddr, u8* ramAddr, u32 size, s32 unkMediumParam);
void AudioLoad_RelocateSample(TunedSample* sample, TunedSample32Bit* tSample, uintptr_t fontDataAddr, SampleBankRelocInfo* relocInfo); void AudioLoad_RelocateSample(TunedSample* tSample, u32 fontDataAddr, SampleBankRelocInfo* relocInfo);
s32 AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, uintptr_t fontDataAddr, SampleBankRelocInfo* relocData, s32 isAsync); s32 AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, uintptr_t fontDataAddr, SampleBankRelocInfo* relocData, s32 isAsync);
s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus); s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus);
@ -394,11 +394,12 @@ void AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) {
func_800144E4(&gSeqPlayers[playerIdx]); func_800144E4(&gSeqPlayers[playerIdx]);
index = BSWAP16(*((u16*) gSeqFontTable + seqId)); index = BSWAP16(*((u16*) gSeqFontTable + seqId));
numFonts = gSeqFontTable[index++];
fontId = 0xFF; fontId = 0xFF;
for (numFonts = gSeqFontTable[index++]; numFonts > 0; numFonts--) { for (numFonts; numFonts > 0; numFonts--) {
fontId = gSeqFontTable[index++]; fontId = gSeqFontTable[index++];
// AudioLoad_SyncLoadFont(fontId); AudioLoad_SyncLoadFont(fontId);
} }
seqData = AudioLoad_SyncLoadSeq(seqId); seqData = AudioLoad_SyncLoadSeq(seqId);
@ -407,18 +408,19 @@ void AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) {
gSeqPlayers[playerIdx].seqId = seqId; gSeqPlayers[playerIdx].seqId = seqId;
gSeqPlayers[playerIdx].defaultFont = fontId; gSeqPlayers[playerIdx].defaultFont = fontId;
gSeqPlayers[playerIdx].enabled = 1; gSeqPlayers[playerIdx].enabled = true;
gSeqPlayers[playerIdx].seqData = seqData; gSeqPlayers[playerIdx].seqData = seqData;
gSeqPlayers[playerIdx].scriptState.pc = seqData; gSeqPlayers[playerIdx].scriptState.pc = seqData;
gSeqPlayers[playerIdx].scriptState.depth = 0; gSeqPlayers[playerIdx].scriptState.depth = 0;
gSeqPlayers[playerIdx].delay = 0; gSeqPlayers[playerIdx].delay = 0;
gSeqPlayers[playerIdx].finished = 0; gSeqPlayers[playerIdx].finished = false;
} }
void* AudioLoad_SyncLoadSeq(s32 seqId) { void* AudioLoad_SyncLoadSeq(s32 seqId) {
AudioTable* table = AudioLoad_GetLoadTable(SEQUENCE_TABLE); AudioTable* table = AudioLoad_GetLoadTable(SEQUENCE_TABLE);
gSeqLoadStatus[seqId] = 2; s32 seqIdx = AudioLoad_GetLoadTableIndex(SEQUENCE_TABLE, seqId);
return Audio_LoadBlob(gAudioTable, table->entries[seqId].romAddr);
return Audio_LoadBlob(gAudioTable, table->entries[seqIdx].romAddr);
} }
void* AudioLoad_SyncLoadSampleBank(u32 sampleBankId, s32* outMedium) { void* AudioLoad_SyncLoadSampleBank(u32 sampleBankId, s32* outMedium) {
@ -487,7 +489,7 @@ void* AudioLoad_SyncLoadFont(s32 fontId) {
} }
if (didAllocate == 1) { if (didAllocate == 1) {
AudioLoad_RelocateFontAndPreloadSamples(fontId, fontData, &relocInfo, AUDIOLOAD_SYNC); AudioLoad_RelocateFontAndPreloadSamples(fontId, fontData, &relocInfo, AUDIOLOAD_SYNC);
} }
return fontData; return fontData;
@ -513,46 +515,57 @@ void* AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
size = ALIGN16(size); size = ALIGN16(size);
medium = table->entries[id].medium; medium = table->entries[id].medium;
cachePolicy = table->entries[id].cachePolicy; cachePolicy = table->entries[id].cachePolicy;
romAddr = table->entries[id].romAddr;
switch (cachePolicy) { switch (tableType) {
case CACHEPOLICY_0: case SEQUENCE_TABLE:
ramAddr = AudioHeap_AllocPermanent(tableType, id, size); romAddr = Audio_LoadBlob(gAudioTable, table->entries[id].romAddr);
if (ramAddr == NULL) {
return ramAddr;
}
break; break;
case FONT_TABLE:
case CACHEPOLICY_1: romAddr = Audio_LoadFont(table->entries[id]);
ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_PERSISTENT, id);
if (ramAddr == NULL) {
return ramAddr;
}
break; break;
case SAMPLE_TABLE:
case CACHEPOLICY_2: loadStatus = 0;
ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_TEMPORARY, id);
if (ramAddr == NULL) {
return ramAddr;
}
break;
case CACHEPOLICY_3:
case CACHEPOLICY_4:
ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_EITHER, id);
if (ramAddr == NULL) {
return ramAddr;
}
break; break;
} }
// switch (cachePolicy) {
// case CACHEPOLICY_0:
// ramAddr = AudioHeap_AllocPermanent(tableType, id, size);
// if (ramAddr == NULL) {
// return ramAddr;
// }
// break;
//
// case CACHEPOLICY_1:
// ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_PERSISTENT, id);
// if (ramAddr == NULL) {
// return ramAddr;
// }
// break;
//
// case CACHEPOLICY_2:
// ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_TEMPORARY, id);
// if (ramAddr == NULL) {
// return ramAddr;
// }
// break;
//
// case CACHEPOLICY_3:
// case CACHEPOLICY_4:
// ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_EITHER, id);
// if (ramAddr == NULL) {
// return ramAddr;
// }
// break;
// }
*didAllocate = true; *didAllocate = true;
if (medium == MEDIUM_UNK) { // if (medium == MEDIUM_UNK) {
AudioLoad_SyncDmaUnkMedium(romAddr, ramAddr, size, table->base.unkMediumParam); // AudioLoad_SyncDmaUnkMedium(romAddr, ramAddr, size, table->base.unkMediumParam);
} else { // } else {
AudioLoad_SyncDma(romAddr, ramAddr, size, medium); // AudioLoad_SyncDma(romAddr, ramAddr, size, medium);
} // }
loadStatus = (cachePolicy == CACHEPOLICY_0) ? 5 : 2; loadStatus = (cachePolicy == CACHEPOLICY_0) ? 5 : 2;
} }
@ -575,7 +588,7 @@ void* AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
} }
break; break;
} }
return ramAddr; return romAddr;
} }
s32 AudioLoad_GetLoadTableIndex(s32 tableType, u32 entryId) { s32 AudioLoad_GetLoadTableIndex(s32 tableType, u32 entryId) {
@ -623,50 +636,45 @@ AudioTable* AudioLoad_GetLoadTable(s32 tableType) {
} }
void AudioLoad_RelocateFont(s32 fontId, uintptr_t fontBaseAddr, SampleBankRelocInfo* relocData) { void AudioLoad_RelocateFont(s32 fontId, uintptr_t fontBaseAddr, SampleBankRelocInfo* relocData) {
uint32_t* fontDataPtrs = fontBaseAddr; // uint32_t* fontDataPtrs = fontBaseAddr;
uint32_t** drumDataPtrs = fontBaseAddr; // uint32_t** drumDataPtrs = fontBaseAddr;
s32 numDrums; // s32 numDrums;
u32 offset; // u32 offset;
s32 i; // s32 i;
s32 numInstruments; // s32 numInstruments;
//
// numDrums = gSoundFontList[fontId].numDrums;
// numInstruments = gSoundFontList[fontId].numInstruments;
//
// Drum** relocatedDrums = memalloc(numDrums * sizeof(Drum*));
// Instrument** relocatedInstruments = memalloc((numInstruments + 1) * sizeof(Instrument*));
//
// if ((fontDataPtrs[0] != 0) && (numDrums != 0)) {
// for (i = 0; i < numDrums; i++) {
// offset = *(*drumDataPtrs + i);
// if (offset != 0) {
// relocatedDrums[i] = Audio_LoadDrum(BSWAP32(offset), 0, relocData->sampleBankId1);
// }
// }
// }
//
// for (i = 1; i <= numInstruments; i++) {
// if (fontDataPtrs[i] != 0) {
// // TODO: fix this
// relocatedInstruments[i] = Audio_LoadInstrument(BSWAP32(fontDataPtrs[i]), relocData->sampleBankId1);
// }
// }
AudioTable* table = AudioLoad_GetLoadTable(FONT_TABLE);
SoundFont* font = Audio_LoadFont(table->entries[fontId]);
numDrums = gSoundFontList[fontId].numDrums; gSoundFontList[fontId].drums = font->drums;
numInstruments = gSoundFontList[fontId].numInstruments; gSoundFontList[fontId].instruments = font->instruments;
Drum** relocatedDrums = memalloc(numDrums * sizeof(Drum*));
Instrument** relocatedInstruments = memalloc((numInstruments + 1) * sizeof(Instrument*));
if ((fontDataPtrs[0] != 0) && (numDrums != 0)) {
for (i = 0; i < numDrums; i++) {
offset = *(*drumDataPtrs + i);
if (offset != 0) {
relocatedDrums[i] = Audio_LoadDrum(BSWAP32(offset) + fontBaseAddr, 0, 0);
}
}
}
for (i = 1; i <= numInstruments; i++) {
if (fontDataPtrs[i] != 0) {
Instrument* instrument = Audio_LoadInstrument(BSWAP32(fontDataPtrs[i]) + fontBaseAddr, 0);
Instrument32Bit* base = fontBaseAddr + BSWAP32(fontDataPtrs[i]);
if (instrument->normalRangeLo != 0) {
AudioLoad_RelocateSample(&instrument->lowPitchTunedSample, &base->lowPitchTunedSample, fontBaseAddr, relocData);
}
AudioLoad_RelocateSample(&instrument->normalPitchTunedSample, &base->normalPitchTunedSample, fontBaseAddr, relocData);
if (instrument->normalRangeHi != 0x7F) {
AudioLoad_RelocateSample(&instrument->highPitchTunedSample, &base->highPitchTunedSample, fontBaseAddr, relocData);
}
relocatedInstruments[i] = instrument;
}
}
gSoundFontList[fontId].drums = relocatedDrums;
gSoundFontList[fontId].instruments = relocatedInstruments;
} }
void AudioLoad_SyncDma(uintptr_t devAddr, u8* ramAddr, u32 size, s32 medium) { void AudioLoad_SyncDma(uintptr_t devAddr, u8* ramAddr, u32 size, s32 medium) {
memcpy(ramAddr, devAddr, size);
return;
size = ALIGN16(size); size = ALIGN16(size);
osInvalDCache(ramAddr, size); osInvalDCache(ramAddr, size);
@ -937,8 +945,10 @@ void AudioLoad_Init(void) {
gSoundFontList = AudioHeap_Alloc(&gInitPool, numFonts * sizeof(SoundFont)); gSoundFontList = AudioHeap_Alloc(&gInitPool, numFonts * sizeof(SoundFont));
for (i = 0; i < numFonts; i++) { for (i = 0; i < numFonts; i++) {
gSoundFontList[i] = Audio_LoadFont(gSoundFontTable->entries[i]); gSoundFontList[i].sampleBankId1 = (gSoundFontTable->entries[i].shortData1 >> 8) & 0xFF;
gFontLoadStatus[i] = 2; gSoundFontList[i].sampleBankId2 = gSoundFontTable->entries[i].shortData1 & 0xFF;
gSoundFontList[i].numInstruments = (gSoundFontTable->entries[i].shortData2 >> 8) & 0xFF;
gSoundFontList[i].numDrums = gSoundFontTable->entries[i].shortData2 & 0xFF;
} }
ramAddr = AudioHeap_Alloc(&gInitPool, gPermanentPoolSize); ramAddr = AudioHeap_Alloc(&gInitPool, gPermanentPoolSize);
@ -1262,7 +1272,7 @@ void AudioLoad_AsyncDmaUnkMedium(uintptr_t devAddr, u8* ramAddr, u32 size, s32 u
static const char devstr50[] = "Error: Already wavetable is touched %x.\n"; static const char devstr50[] = "Error: Already wavetable is touched %x.\n";
static const char devstr51[] = "Touch Warning: Length zero %x\n"; static const char devstr51[] = "Touch Warning: Length zero %x\n";
void AudioLoad_RelocateSample(TunedSample* tunedSample, TunedSample32Bit* tSample, uintptr_t fontDataAddr, SampleBankRelocInfo* relocInfo) { void AudioLoad_RelocateSample(TunedSample* tSample, u32 fontDataAddr, SampleBankRelocInfo* relocInfo) {
Sample32Bit* baseSample = fontDataAddr + BSWAP32(tSample->sample); Sample32Bit* baseSample = fontDataAddr + BSWAP32(tSample->sample);
// "Touch Warning: Length zero %x\n"; // "Touch Warning: Length zero %x\n";
@ -1314,6 +1324,7 @@ s32 AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, uintptr_t fontDataAddr,
s32 pad; s32 pad;
u32 nChunks; u32 nChunks;
s32 inProgress; s32 inProgress;
isAsync = 0;
inProgress = false; inProgress = false;
if (gPreloadSampleStackTop != 0) { if (gPreloadSampleStackTop != 0) {
@ -1339,41 +1350,40 @@ s32 AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, uintptr_t fontDataAddr,
sampleRamAddr = NULL; sampleRamAddr = NULL;
#endif #endif
//! @bug Those are assignments, not equality checks. //! @bug Those are assignments, not equality checks.
switch (isAsync) { // switch (isAsync) {
case AUDIOLOAD_SYNC: // case AUDIOLOAD_SYNC:
if (sample->medium = relocData->medium1) { // if (sample->medium = relocData->medium1) {
sampleRamAddr = AudioHeap_AllocPersistentSampleCache(sample->size, relocData->sampleBankId1, // sampleRamAddr = AudioHeap_AllocPersistentSampleCache(sample->size, relocData->sampleBankId1,
sample->sampleAddr, sample->medium); // sample->sampleAddr, sample->medium);
} else if (sample->medium = relocData->medium2) { // } else if (sample->medium = relocData->medium2) {
sampleRamAddr = AudioHeap_AllocPersistentSampleCache(sample->size, relocData->sampleBankId2, // sampleRamAddr = AudioHeap_AllocPersistentSampleCache(sample->size, relocData->sampleBankId2,
sample->sampleAddr, sample->medium); // sample->sampleAddr, sample->medium);
} // }
break; // break;
//
// case AUDIOLOAD_ASYNC:
// if (sample->medium = relocData->medium1) {
// sampleRamAddr = AudioHeap_AllocTemporarySampleCache(sample->size, relocData->sampleBankId1,
// sample->sampleAddr, sample->medium);
// } else if (sample->medium = relocData->medium2) {
// sampleRamAddr = AudioHeap_AllocTemporarySampleCache(sample->size, relocData->sampleBankId2,
// sample->sampleAddr, sample->medium);
// }
// break;
// }
case AUDIOLOAD_ASYNC: // if (sampleRamAddr == NULL) {
if (sample->medium = relocData->medium1) { // continue;
sampleRamAddr = AudioHeap_AllocTemporarySampleCache(sample->size, relocData->sampleBankId1, // }
sample->sampleAddr, sample->medium);
} else if (sample->medium = relocData->medium2) {
sampleRamAddr = AudioHeap_AllocTemporarySampleCache(sample->size, relocData->sampleBankId2,
sample->sampleAddr, sample->medium);
}
break;
}
if (sampleRamAddr == NULL) {
continue;
}
switch (isAsync) { switch (isAsync) {
case AUDIOLOAD_SYNC: case AUDIOLOAD_SYNC:
if (sample->medium == MEDIUM_UNK) { if (sample->medium == MEDIUM_UNK) {
AudioLoad_SyncDmaUnkMedium(sample->sampleAddr, sampleRamAddr, sample->size, // AudioLoad_SyncDmaUnkMedium(sample->sampleAddr, sampleRamAddr, sample->size, gSampleBankTable->base.unkMediumParam);
gSampleBankTable->base.unkMediumParam);
sample->sampleAddr = sampleRamAddr; sample->sampleAddr = sampleRamAddr;
sample->medium = MEDIUM_RAM; sample->medium = MEDIUM_RAM;
} else { } else {
AudioLoad_SyncDma(sample->sampleAddr, sampleRamAddr, sample->size, sample->medium); // AudioLoad_SyncDma(sample->sampleAddr, sampleRamAddr, sample->size, sample->medium);
sample->sampleAddr = sampleRamAddr; sample->sampleAddr = sampleRamAddr;
sample->medium = MEDIUM_RAM; sample->medium = MEDIUM_RAM;
} }

View File

@ -55,7 +55,7 @@ void AudioThread_CreateNextAudioBuffer(s16 *samples, u32 num_samples) {
gCurAudioFrameDmaCount = 0; gCurAudioFrameDmaCount = 0;
AudioLoad_DecreaseSampleDmaTtls(); AudioLoad_DecreaseSampleDmaTtls();
// AudioLoad_ProcessLoads(gAudioResetStep); AudioLoad_ProcessLoads(gAudioResetStep);
if (MQ_GET_MESG(gAudioSpecQueue, &specId)) { if (MQ_GET_MESG(gAudioSpecQueue, &specId)) {
if (gAudioResetStep == 0) { if (gAudioResetStep == 0) {
@ -362,16 +362,19 @@ void AudioThread_ProcessCmds(u32 msg) {
u8 writePos; u8 writePos;
if (!gThreadCmdQueueFinished) { if (!gThreadCmdQueueFinished) {
gCurCmdReadPos = (msg >> 8) & 0xFF; gCurCmdReadPos = msg >> 8;
} }
writePos = msg & 0xFF;
while (true) { while (true) {
writePos = msg & 0xFF;
if (gCurCmdReadPos == writePos) { if (gCurCmdReadPos == writePos) {
gThreadCmdQueueFinished = 0; gThreadCmdQueueFinished = 0;
break; break;
} }
cmd = &gThreadCmdBuffer[gCurCmdReadPos & 0xFF];
gCurCmdReadPos++; cmd = &gThreadCmdBuffer[gCurCmdReadPos++ & 0xFF];
if (cmd->op == AUDIOCMD_OP_GLOBAL_STOP_AUDIOCMDS) { if (cmd->op == AUDIOCMD_OP_GLOBAL_STOP_AUDIOCMDS) {
gThreadCmdQueueFinished = true; gThreadCmdQueueFinished = true;
break; break;

View File

@ -42,7 +42,7 @@ void AudioThread_CreateNextAudioBuffer(int16_t *samples, uint32_t num_samples);
GameEngine* GameEngine::Instance; GameEngine* GameEngine::Instance;
static GamePool MemoryPool = { static GamePool MemoryPool = {
.chunk = 1024 * 20, .chunk = 1024 * 512,
.cursor = 0, .cursor = 0,
.length = 0, .length = 0,
.memory = nullptr .memory = nullptr
@ -437,7 +437,7 @@ extern "C" int32_t OTRConvertHUDXToScreenX(int32_t v) {
extern "C" void* GameEngine_Malloc(size_t size) { extern "C" void* GameEngine_Malloc(size_t size) {
// This is really wrong // This is really wrong
// return malloc(size); return malloc(size);
// TODO: Kenix please take a look at this, i think it works but you are better at this // TODO: Kenix please take a look at this, i think it works but you are better at this
const auto chunk = MemoryPool.chunk; const auto chunk = MemoryPool.chunk;
@ -449,7 +449,7 @@ extern "C" void* GameEngine_Malloc(size_t size) {
if(MemoryPool.cursor + size < MemoryPool.length) { if(MemoryPool.cursor + size < MemoryPool.length) {
const auto res = static_cast<uint8_t*>(MemoryPool.memory) + MemoryPool.cursor; const auto res = static_cast<uint8_t*>(MemoryPool.memory) + MemoryPool.cursor;
MemoryPool.cursor += size; MemoryPool.cursor += size;
SPDLOG_INFO("Allocating {} into memory pool", size); //SPDLOG_INFO("Allocating {} into memory pool", size);
return res; return res;
} }

View File

@ -43,37 +43,36 @@ EnvelopePoint* Audio_LoadEnvelope(uint32_t addr) {
return envelopes; return envelopes;
} }
extern "C" SoundFont Audio_LoadFont(AudioTableEntry entry) { extern "C" SoundFont* Audio_LoadFont(AudioTableEntry entry) {
auto reader = Audio_MakeReader(gAudioBank, entry.romAddr); auto reader = Audio_MakeReader(gAudioBank, entry.romAddr);
SoundFont font = { SoundFont* font = memalloc(SoundFont);
.numInstruments = (uint32_t)((entry.shortData2 >> 8) & 0xFF),
.numDrums = (uint32_t)(entry.shortData2 & 0xFF), font->numInstruments = (entry.shortData2 >> 8) & 0xFFu;
.sampleBankId1 = (uint32_t)((entry.shortData1 >> 8) & 0xFF), font->numDrums = entry.shortData2 & 0xFFu;
.sampleBankId2 = (uint32_t)(entry.shortData1 & 0xFF), font->sampleBankId1 = (entry.shortData1 >> 8) & 0xFFu;
}; font->sampleBankId2 = entry.shortData1 & 0xFFu;
font->instruments = memallocn(Instrument*, font->numInstruments);
font.instruments = memallocn(Instrument*, font.numInstruments); font->drums = memallocn(Drum*, font->numDrums);
font.drums = memallocn(Drum*, font.numDrums);
uint32_t drumBaseAddr = entry.romAddr + reader.ReadUInt32(); uint32_t drumBaseAddr = entry.romAddr + reader.ReadUInt32();
uint32_t instBaseAddr = 4; uint32_t instBaseAddr = 4;
if(font.drums != nullptr && drumBaseAddr != 0){ if(font->drums != nullptr && drumBaseAddr != 0){
reader.Seek(drumBaseAddr, Ship::SeekOffsetType::Start); reader.Seek(drumBaseAddr, Ship::SeekOffsetType::Start);
for(size_t i = 0; i < font.numDrums; i++){ for(size_t i = 0; i < font->numDrums; i++){
font.drums[i] = Audio_LoadDrum(entry.romAddr + reader.ReadUInt32(), entry.romAddr, font.sampleBankId1); font->drums[i] = Audio_LoadDrum(entry.romAddr + reader.ReadUInt32(), entry.romAddr, font->sampleBankId1);
} }
} }
if(font.instruments != nullptr){ if(font->instruments != nullptr){
reader.Seek(instBaseAddr, Ship::SeekOffsetType::Start); reader.Seek(instBaseAddr, Ship::SeekOffsetType::Start);
for(size_t i = 1; i < font.numInstruments; i++){ for(size_t i = 1; i < font->numInstruments; i++){
font.instruments[i] = Audio_LoadInstrument(reader.ReadUInt32(), font.sampleBankId1); font->instruments[i] = Audio_LoadInstrument(reader.ReadUInt32(), font->sampleBankId1);
} }
} }
gSampleFontLoadStatus[font.sampleBankId1] = 2; gSampleFontLoadStatus[font->sampleBankId1] = 2;
return font; return font;
} }
@ -105,7 +104,7 @@ extern "C" AdpcmBook* Audio_LoadBook(uint32_t addr) {
size_t length = 8 * book->order * book->numPredictors; size_t length = 8 * book->order * book->numPredictors;
book->book = memallocn(int16_t, length); book->book = memallocn(int16_t, length);
if(length > 16){ if(length > 0x40){
return nullptr; return nullptr;
} }
@ -128,6 +127,7 @@ Sample* Audio_LoadSample(uint32_t sampleAddr, uint32_t baseAddr = 0, uint32_t sa
sample->isRelocated = 1; sample->isRelocated = 1;
sample->sampleAddr = (uint8_t*) Audio_LoadBlob(gAudioTable, gSeqTableInit.entries[sampleBankID].romAddr) + addr; sample->sampleAddr = (uint8_t*) Audio_LoadBlob(gAudioTable, gSeqTableInit.entries[sampleBankID].romAddr) + addr;
gUsedSamples[gNumUsedSamples++] = sample;
return sample; return sample;
} }

View File

@ -13,7 +13,7 @@ AdpcmLoop* Audio_LoadLoop(uint32_t addr);
Instrument* Audio_LoadInstrument(uint32_t addr, uint32_t sampleBankID); Instrument* Audio_LoadInstrument(uint32_t addr, uint32_t sampleBankID);
Drum* Audio_LoadDrum(uint32_t addr, uint32_t baseAddr, uint32_t sampleBankID); Drum* Audio_LoadDrum(uint32_t addr, uint32_t baseAddr, uint32_t sampleBankID);
Sample* Audio_LoadSample(uint32_t addr, uint32_t sampleBankID); Sample* Audio_LoadSample(uint32_t addr, uint32_t sampleBankID);
SoundFont Audio_LoadFont(AudioTableEntry entry); SoundFont* Audio_LoadFont(AudioTableEntry entry);
#ifdef __cplusplus #ifdef __cplusplus
} }