From 941c19f2c33a0d1af75a10a64fe0905387d1e440 Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Wed, 1 Jun 2022 13:06:32 -0400 Subject: Audio decompiled and WIP custom sample support --- soh/src/code/audio_heap.c | 8 +- soh/src/code/audio_load.c | 365 +++++++++++++++++++++++++++++++---------- soh/src/code/audio_playback.c | 57 +++++-- soh/src/code/audio_seqplayer.c | 12 +- soh/src/code/audio_synthesis.c | 14 +- soh/src/code/code_800E4FE0.c | 4 - 6 files changed, 345 insertions(+), 115 deletions(-) (limited to 'soh/src/code') diff --git a/soh/src/code/audio_heap.c b/soh/src/code/audio_heap.c index 765fd8b09..84e91d439 100644 --- a/soh/src/code/audio_heap.c +++ b/soh/src/code/audio_heap.c @@ -10,6 +10,8 @@ void AudioHeap_DiscardSampleCaches(void); void AudioHeap_DiscardSampleBank(s32 sampleBankId); void AudioHeap_DiscardSampleBanks(void); +extern bool gUseLegacySD; + f32 func_800DDE20(f32 arg0) { return 256.0f * gAudioContext.audioBufferParameters.unkUpdatesPerFrameScaled / arg0; } @@ -1201,7 +1203,11 @@ void AudioHeap_DiscardSampleCacheEntry(SampleCacheEntry* entry) { } } -void AudioHeap_UnapplySampleCache(SampleCacheEntry* entry, SoundFontSample* sample) { +void AudioHeap_UnapplySampleCache(SampleCacheEntry* entry, SoundFontSample* sample) +{ + if (!gUseLegacySD) + return; + if (sample != NULL) { if (sample->sampleAddr == entry->allocatedAddr) { sample->sampleAddr = entry->sampleAddr; diff --git a/soh/src/code/audio_load.c b/soh/src/code/audio_load.c index 7af9037a6..ecb6eab2d 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,7 +38,7 @@ 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); u32 AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 noLoad); void* AudioLoad_SyncLoad(u32 tableType, u32 tableId, s32* didAllocate); @@ -74,6 +75,11 @@ void* sUnusedHandler = NULL; s32 gAudioContextInitalized = false; +uintptr_t fontStart; +uint32_t fontOffsets[8192]; + +bool gUseLegacySD = false; + void AudioLoad_DecreaseSampleDmaTtls(void) { u32 i; @@ -278,8 +284,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) { @@ -352,6 +361,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; } } @@ -400,7 +412,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); @@ -544,7 +557,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; } @@ -556,18 +569,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; @@ -633,12 +655,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; @@ -681,13 +713,39 @@ void* 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); @@ -720,7 +778,14 @@ void* 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; @@ -743,9 +808,16 @@ void* AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { return ret; } -u32 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; } @@ -796,29 +868,63 @@ 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) (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; + } } } } @@ -826,39 +932,56 @@ 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]); + } } } } } - + if (numInstruments > 0x7E) { 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; } } @@ -866,9 +989,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(u32 devAddr, u8* addr, size_t size, s32 medium) { @@ -1270,17 +1395,21 @@ void AudioLoad_Init(void* heap, u32 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 @@ -1454,28 +1583,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) { @@ -1687,7 +1828,7 @@ void AudioLoad_AsyncDmaUnkMedium(u32 devAddr, void* ramAddr, size_t size, s16 ar #define RELOC(v, base) (reloc = (void*)((u32)(v) + (u32)(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) { @@ -1699,32 +1840,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; + } } } } @@ -1977,9 +2144,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); @@ -2024,6 +2199,7 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, RelocInfo* relocInfo } sample = gAudioContext.usedSamples[i]; + if (sample->medium == MEDIUM_RAM) { continue; } @@ -2100,10 +2276,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); diff --git a/soh/src/code/audio_playback.c b/soh/src/code/audio_playback.c index c116b4ddb..5d43118b8 100644 --- a/soh/src/code/audio_playback.c +++ b/soh/src/code/audio_playback.c @@ -1,6 +1,8 @@ #include "global.h" #include "Cvar.h" +extern bool gUseLegacySD; + void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) { f32 volRight, volLeft; s32 smallPanIndex; @@ -307,7 +309,7 @@ SoundFontSound* Audio_InstrumentGetSound(Instrument* instrument, s32 semitone) { Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) { Instrument* inst; - + if (fontId == 0xFF) { return NULL; } @@ -317,16 +319,31 @@ Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) { return NULL; } - if (instId >= gAudioContext.soundFonts[fontId].numInstruments) { - gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000; - return NULL; + int instCnt = 0; + + if (gUseLegacySD) { + instCnt = gAudioContext.soundFonts[fontId].numInstruments; + inst = gAudioContext.soundFonts[fontId].instruments[instId]; + + if (instId >= gAudioContext.soundFonts[fontId].numInstruments) + if (instId >= instCnt) { + gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000; + return NULL; + } + } else { + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId); + + if (instId >= sf->numInstruments) + return NULL; + + inst = sf->instruments[instId]; } - inst = gAudioContext.soundFonts[fontId].instruments[instId]; if (inst == NULL) { gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000; return inst; } + return inst; } @@ -343,12 +360,17 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) { return NULL; } - if (drumId >= gAudioContext.soundFonts[fontId].numDrums) { - gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000; - return NULL; - } + if (gUseLegacySD) { + if (drumId >= gAudioContext.soundFonts[fontId].numDrums) { + gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000; + return NULL; + } - drum = gAudioContext.soundFonts[fontId].drums[drumId]; + drum = gAudioContext.soundFonts[fontId].drums[drumId]; + } else { + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId); + drum = sf->drums[drumId]; + } if (drum == NULL) { gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x5000000; @@ -369,12 +391,17 @@ SoundFontSound* Audio_GetSfx(s32 fontId, s32 sfxId) { return NULL; } - if (sfxId >= gAudioContext.soundFonts[fontId].numSfx) { - gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000; - return NULL; - } + if (gUseLegacySD) { + if (sfxId >= gAudioContext.soundFonts[fontId].numSfx) { + gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000; + return NULL; + } - sfx = &gAudioContext.soundFonts[fontId].soundEffects[sfxId]; + sfx = &gAudioContext.soundFonts[fontId].soundEffects[sfxId]; + } else { + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId); + sfx = &sf->soundEffects[sfxId]; + } if (sfx == NULL) { gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000; diff --git a/soh/src/code/audio_seqplayer.c b/soh/src/code/audio_seqplayer.c index 3dd7b811e..52d14a9a1 100644 --- a/soh/src/code/audio_seqplayer.c +++ b/soh/src/code/audio_seqplayer.c @@ -938,8 +938,16 @@ u8 AudioSeq_GetInstrument(SequenceChannel* channel, u8 instId, Instrument** inst *instOut = NULL; return 0; } - adsr->envelope = inst->envelope; - adsr->releaseRate = inst->releaseRate; + + if (inst->envelope != NULL) + { + adsr->envelope = inst->envelope; + adsr->releaseRate = (inst->releaseRate); + } + else { + adsr->envelope = gDefaultEnvelope; + } + *instOut = inst; instId += 2; return instId; diff --git a/soh/src/code/audio_synthesis.c b/soh/src/code/audio_synthesis.c index 037bd2ec3..b567dd0ef 100644 --- a/soh/src/code/audio_synthesis.c +++ b/soh/src/code/audio_synthesis.c @@ -749,8 +749,10 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS cmd = AudioSynth_LoadWaveSamples(cmd, noteSubEu, synthState, nSamplesToLoad); noteSamplesDmemAddrBeforeResampling = DMEM_UNCOMPRESSED_NOTE + (synthState->samplePosInt * 2); synthState->samplePosInt += nSamplesToLoad; - } else { + } else + { audioFontSample = noteSubEu->sound.soundFontSound->sample; + loopInfo = audioFontSample->loop; loopEndPos = loopInfo->end; sampleAddr = audioFontSample->sampleAddr; @@ -822,6 +824,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS noteFinished = true; } } + switch (audioFontSample->codec) { case CODEC_ADPCM: @@ -848,6 +851,9 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS goto skip; case CODEC_S16: AudioSynth_ClearBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE, (samplesLenAdjusted * 2) + 0x20); + AudioSynth_LoadBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE, ALIGN16(nSamplesToLoad * 2), + audioFontSample->sampleAddr + (synthState->samplePosInt * 2)); + flags = A_CONTINUE; skipBytes = 0; nSamplesProcessed = samplesLenAdjusted; @@ -860,7 +866,8 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS if (nFramesToDecode != 0) { frameIndex = (synthState->samplePosInt + skipInitialSamples - nFirstFrameSamplesToIgnore) / 16; sampleDataOffset = frameIndex * frameSize; - if (audioFontSample->medium == MEDIUM_RAM) { + if (audioFontSample->medium == MEDIUM_RAM) + { sampleData = (u8*)(sampleDataStart + sampleDataOffset + sampleAddr); } else if (audioFontSample->medium == MEDIUM_UNK) { return cmd; @@ -1024,7 +1031,8 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS unk7 = noteSubEu->unk_07; unkE = noteSubEu->unk_0E; buf = &synthState->synthesisBuffers->panSamplesBuffer[0x18]; - if (unk7 != 0 && noteSubEu->unk_0E != 0) { + if (unk7 != 0 && noteSubEu->unk_0E != 0) + { AudioSynth_DMemMove(cmd++, DMEM_TEMP, DMEM_SCRATCH2, aiBufLen * 2); thing = DMEM_SCRATCH2 - unk7; if (synthState->unk_1A != 0) { diff --git a/soh/src/code/code_800E4FE0.c b/soh/src/code/code_800E4FE0.c index c46ae7a07..d88e731f4 100644 --- a/soh/src/code/code_800E4FE0.c +++ b/soh/src/code/code_800E4FE0.c @@ -213,11 +213,7 @@ AudioTask* func_800E5000(void) { task = &gAudioContext.currTask->task.t; task->type = M_AUDTASK; task->flags = 0; - //task->ucode_boot = D_801120C0; task->ucode_boot_size = 0x1000; - //task->ucode_data_size = ((rspAspMainDataEnd - rspAspMainDataStart) * sizeof(u64)) - 1; - //task->ucode = D_801120C0; - //task->ucode_data = rspAspMainDataStart; task->ucode_size = 0x1000; task->dram_stack = NULL; task->dram_stack_size = 0; -- cgit v1.2.3 From c49cee352111acc5f2a831ba2f7a46a627785eff Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Fri, 10 Jun 2022 13:37:50 -0400 Subject: Audio support nearly complete. --- soh/src/code/audio_data.c | 6 -- soh/src/code/audio_init_params.c | 35 ++++----- soh/src/code/audio_load.c | 151 ++++++++++++++++++++++++--------------- soh/src/code/audio_playback.c | 13 +++- soh/src/code/audio_seqplayer.c | 32 ++++++--- soh/src/code/audio_synthesis.c | 7 +- soh/src/code/code_800F9280.c | 6 +- 7 files changed, 155 insertions(+), 95 deletions(-) (limited to 'soh/src/code') diff --git a/soh/src/code/audio_data.c b/soh/src/code/audio_data.c index 540eedca8..5fe49139b 100644 --- a/soh/src/code/audio_data.c +++ b/soh/src/code/audio_data.c @@ -544,16 +544,10 @@ u8 gDefaultShortNoteGateTimeTable[] = { }; AdsrEnvelope gDefaultEnvelope[] = { - // OTRTODO: Byteswapped manually for quick audio support. { 0x0100, 0x007D }, { 0xE803, 0x007D }, { 0xFFFF, 0x0000 }, { 0x0000, 0x0000 }, - /* { 1, 32000 }, - { 1000, 32000 }, - { -1, 0 }, - { 0, 0 }, - */ }; NoteSubEu gZeroNoteSub = { 0 }; diff --git a/soh/src/code/audio_init_params.c b/soh/src/code/audio_init_params.c index 0cebdf596..8d990b623 100644 --- a/soh/src/code/audio_init_params.c +++ b/soh/src/code/audio_init_params.c @@ -66,23 +66,24 @@ ReverbSettings D_80133420[][3] = { }, }; +// OTRTODO AudioSpec gAudioSpecs[18] = { - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x4000, 0x2880, 0, 0, 0 }, - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[1], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[2], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 23, 4, 0, 0, 2, D_80133420[4], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 23, 4, 0, 0, 2, D_80133420[5], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[6], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[7], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 23, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[9], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 23, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 28, 3, 0, 0, 2, D_80133420[10], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x2800, 0x2880, 0, 0, 0 }, - { 32000, 1, 28, 3, 0, 0, 1, D_80133420[11], 0x300, 0x200, 0x7FFF, 0, 0x4800, 0, 0x4000, 0, 0, 0, 0 }, - { 32000, 1, 28, 3, 0, 0, 1, D_80133420[11], 0x300, 0x200, 0x7FFF, 0, 0, 0, 0x4000, 0x4800, 0, 0, 0 }, - { 32000, 1, 22, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 22, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 16, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44000, 1, 24, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x4000, 0x2880, 0, 0, 0 }, + { 44000, 1, 24, 4, 0, 0, 2, D_80133420[1], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44000, 1, 24, 4, 0, 0, 2, D_80133420[2], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44000, 1, 23, 4, 0, 0, 2, D_80133420[4], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44000, 1, 23, 4, 0, 0, 2, D_80133420[5], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44000, 1, 24, 4, 0, 0, 2, D_80133420[6], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44000, 1, 24, 4, 0, 0, 2, D_80133420[7], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44000, 1, 23, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44000, 1, 24, 4, 0, 0, 2, D_80133420[9], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44000, 1, 23, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44000, 1, 28, 3, 0, 0, 2, D_80133420[10], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x2800, 0x2880, 0, 0, 0 }, + { 44000, 1, 28, 3, 0, 0, 1, D_80133420[11], 0x300, 0x200, 0x7FFF, 0, 0x4800, 0, 0x4000, 0, 0, 0, 0 }, + { 44000, 1, 28, 3, 0, 0, 1, D_80133420[11], 0x300, 0x200, 0x7FFF, 0, 0, 0, 0x4000, 0x4800, 0, 0, 0 }, + { 44000, 1, 22, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44000, 1, 22, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44000, 1, 16, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, { 22050, 1, 24, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[2], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3600, 0x2600, 0, 0, 0 }, + { 44000, 1, 24, 4, 0, 0, 2, D_80133420[2], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3600, 0x2600, 0, 0, 0 }, }; diff --git a/soh/src/code/audio_load.c b/soh/src/code/audio_load.c index ecb6eab2d..0732d2fa3 100644 --- a/soh/src/code/audio_load.c +++ b/soh/src/code/audio_load.c @@ -45,7 +45,7 @@ void* AudioLoad_SyncLoad(u32 tableType, u32 tableId, s32* didAllocate); u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 tableId); void* AudioLoad_SearchCaches(s32 tableType, s32 id); AudioTable* AudioLoad_GetLoadTable(s32 tableType); -void AudioLoad_SyncDma(u32 devAddr, u8* addr, size_t size, s32 medium); +void AudioLoad_SyncDma(uintptr_t devAddr, u8* addr, size_t size, s32 medium); void AudioLoad_SyncDmaUnkMedium(u32 devAddr, u8* addr, size_t size, s32 unkMediumParam); s32 AudioLoad_Dma(OSIoMesg* mesg, u32 priority, s32 direction, u32 devAddr, void* ramAddr, size_t size, OSMesgQueue* reqQueue, s32 medium, const char* dmaFuncType); @@ -75,6 +75,8 @@ void* sUnusedHandler = NULL; s32 gAudioContextInitalized = false; +char* sequenceMap[256]; + uintptr_t fontStart; uint32_t fontOffsets[8192]; @@ -372,7 +374,7 @@ void AudioLoad_InitTable(AudioTable* table, uintptr_t romAddr, u16 unkMediumPara SoundFontData* AudioLoad_SyncLoadSeqFonts(s32 seqId, u32* outDefaultFontId) { char pad[0x8]; s32 index; - SoundFontData* font; + SoundFontData* font = NULL; s32 numFonts; s32 fontId; s32 i; @@ -387,6 +389,7 @@ SoundFontData* AudioLoad_SyncLoadSeqFonts(s32 seqId, u32* outDefaultFontId) { while (numFonts > 0) { fontId = gAudioContext.sequenceFontTable[index++]; + font = AudioLoad_SyncLoadFont(fontId); numFonts--; } @@ -479,13 +482,26 @@ void AudioLoad_AsyncLoadFont(s32 fontId, s32 arg1, s32 retData, OSMesgQueue* ret u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) { s32 index; - index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; + if (!gUseLegacySD) + { + if (seqId == 255) + return NULL; - *outNumFonts = gAudioContext.sequenceFontTable[index++]; - if (*outNumFonts == 0) { - return NULL; + SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); + + if (sDat.numFonts == 0) + return NULL; + + return sDat.fonts; + } else { + index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; + + *outNumFonts = gAudioContext.sequenceFontTable[index++]; + if (*outNumFonts == 0) { + return NULL; + } + return &gAudioContext.sequenceFontTable[index]; } - return &gAudioContext.sequenceFontTable[index]; } void AudioLoad_DiscardSeqFonts(s32 seqId) { @@ -564,16 +580,29 @@ s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) { AudioSeq_SequencePlayerDisable(seqPlayer); fontId = 0xFF; - index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; - numFonts = gAudioContext.sequenceFontTable[index++]; - while (numFonts > 0) { - fontId = gAudioContext.sequenceFontTable[index++]; - - //if (gUseLegacySD) - AudioLoad_SyncLoadFont(fontId); - - numFonts--; + if (gUseLegacySD) { + index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; + numFonts = gAudioContext.sequenceFontTable[index++]; + + while (numFonts > 0) { + fontId = gAudioContext.sequenceFontTable[index++]; + + AudioLoad_SyncLoadFont(fontId); // NOTE: If this is commented out, then enemies will play child link sounds... + + numFonts--; + } + } + else + { + SequenceData seqData2 = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); + + for (int i = 0; i < seqData2.numFonts; i++) + { + fontId = seqData2.fonts[i]; + AudioLoad_SyncLoadFont(fontId); // NOTE: If this is commented out, then enemies will play child link sounds... + numFonts--; + } } seqData = AudioLoad_SyncLoadSeq(seqId); @@ -655,7 +684,6 @@ 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; @@ -720,13 +748,12 @@ void* AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { if (!gUseLegacySD && tableType == SEQUENCE_TABLE) { - seqData = ResourceMgr_LoadSeqByID(id); - size = ResourceMgr_GetSeqSizeByID(id); - size -= 2; - medium = seqData[0]; - cachePolicy = seqData[1]; + SequenceData sData = ResourceMgr_LoadSeqByName(sequenceMap[id]); + seqData = sData.seqData; + size = sData.seqDataSize; + medium = sData.medium; + cachePolicy = sData.cachePolicy; romAddr = 0; - seqData += 2; } else if (!gUseLegacySD && tableType == FONT_TABLE) { @@ -996,7 +1023,7 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo } } -void AudioLoad_SyncDma(u32 devAddr, u8* addr, size_t size, s32 medium) { +void AudioLoad_SyncDma(uintptr_t devAddr, u8* addr, size_t size, s32 medium) { OSMesgQueue* msgQueue = &gAudioContext.syncDmaQueue; OSIoMesg* ioMesg = &gAudioContext.syncDmaIoMesg; size = ALIGN16(size); @@ -1179,7 +1206,6 @@ s32 AudioLoad_AssertValidAddr(uintptr_t ramAddr, uintptr_t startAddr, size_t siz #define BASE_ROM_OFFSET(x) (void*)((u32)(x) + (u32)(romAddr)) void AudioLoad_InitSwapFontSampleHeaders(SoundFontSample* sample, uintptr_t romAddr) { - // OTRTODO: This will be removed when we actually extract the data. size_t maxSoundFontSize = 0x3AA0; // soundFont 0 is the largest size at 0x3AA0 AdpcmLoop* loop; AdpcmBook* book; @@ -1400,7 +1426,12 @@ void AudioLoad_Init(void* heap, u32 heapSize) { AudioLoad_InitTable(gAudioContext.sequenceTable, seqStart, 0); AudioLoad_InitTable(gAudioContext.soundFontTable, bankStart, 0); AudioLoad_InitTable(gAudioContext.sampleBankTable, tableStart, 0); - numFonts = gAudioContext.soundFontTable->numEntries; + + if (gUseLegacySD) + numFonts = gAudioContext.soundFontTable->numEntries; + else + numFonts = 0x26; // OTRTODO: Count the number of soundfonts that are inside the OTR(s) + gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); if (gUseLegacySD) { @@ -1409,6 +1440,23 @@ void AudioLoad_Init(void* heap, u32 heapSize) { } AudioLoad_InitSwapFont(); + } else { + int seqListSize = 0; + char** seqList = ResourceMgr_ListFiles("audio/sequences*", &seqListSize); + + for (int i = 0; i < seqListSize; i++) + { + SequenceData sDat = ResourceMgr_LoadSeqByName(seqList[i]); + + char* str = malloc(strlen(seqList[i]) + 1); + strcpy(str, seqList[i]); + + sequenceMap[sDat.seqNumber] = str; + } + + free(seqList); + + int bp = 0; } if (temp_v0_3 = AudioHeap_Alloc(&gAudioContext.audioInitPool, D_8014A6C4.permanentPoolSize), temp_v0_3 == NULL) { @@ -1429,7 +1477,6 @@ void AudioLoad_InitSlowLoads(void) { s32 AudioLoad_SlowLoadSample(s32 fontId, s32 instId, s8* isDone) { SoundFontSample* sample; AudioSlowLoad* slowLoad; - sample = AudioLoad_GetFontSample(fontId, instId); if (sample == NULL) { *isDone = 0; @@ -1601,11 +1648,13 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* isDone) { slowLoad->sample.sampleAddr = NULL; slowLoad->isDone = isDone; - if (!gUseLegacySD) { - char* seqData = ResourceMgr_LoadSeqByID(seqId); - size = ResourceMgr_GetSeqSizeByID(seqId) - 2; - slowLoad->curDevAddr = seqData + 2; - slowLoad->medium = seqData[0]; + if (!gUseLegacySD) + { + SequenceData sData = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); + char* seqData = sData.seqData; + size = sData.seqDataSize; + slowLoad->curDevAddr = seqData; + slowLoad->medium = sData.medium; } else { size = seqTable->entries[seqId].size; size = ALIGN16(size); @@ -1829,41 +1878,23 @@ void AudioLoad_AsyncDmaUnkMedium(u32 devAddr, void* ramAddr, size_t size, s16 ar #define RELOC(v, base) (reloc = (void*)((u32)(v) + (u32)(base))) 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) { - // OTRTODO: This can be removed once we have properly byteswapped files on the disk. - assert("mem for sound font bank is too low."); + if (gUseLegacySD) + { + // NOTE: This is hack to detect whether or not the sample has been relocated. + if ((uintptr_t)mem <= maxSoundBankSize) { + assert("mem for sound font bank is too low."); + } } SoundFontSample* sample; void* reloc; - // OTRTODO: Seems precarious to assume the RAM is never <= 0x3EB2A0, but it largely works. + // NOTE: Seems precarious to assume the RAM is never <= 0x3EB2A0, but it largely works. 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); @@ -2116,8 +2147,10 @@ s32 AudioLoad_GetSamplesForFont(s32 fontId, SoundFontSample** sampleSet) { void AudioLoad_AddUsedSample(SoundFontSound* sound) { SoundFontSample* sample = sound->sample; - if ((sample->size != 0) && (sample->unk_bit26) && (sample->medium != MEDIUM_RAM)) { - gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; + if (sample != NULL) { + if ((sample->size != 0) && (sample->unk_bit26) && (sample->medium != MEDIUM_RAM)) { + gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; + } } } diff --git a/soh/src/code/audio_playback.c b/soh/src/code/audio_playback.c index 5d43118b8..9992eee3d 100644 --- a/soh/src/code/audio_playback.c +++ b/soh/src/code/audio_playback.c @@ -286,7 +286,18 @@ void Audio_ProcessNotes(void) { } subAttrs.frequency *= playbackState->vibratoFreqScale * playbackState->portamentoFreqScale; - subAttrs.frequency *= gAudioContext.audioBufferParameters.resampleRate; + + f32 resampRate = gAudioContext.audioBufferParameters.resampleRate; + + if (!gUseLegacySD && !noteSubEu2->bitField1.isSyntheticWave && noteSubEu2->sound.soundFontSound != NULL && + noteSubEu2->sound.soundFontSound->sample != NULL && + noteSubEu2->sound.soundFontSound->sample->sampleRateMagicValue == 'RIFF') { + resampRate = CALC_RESAMPLE_FREQ(noteSubEu2->sound.soundFontSound->sample->sampleRate); + } + + subAttrs.frequency *= resampRate; + + subAttrs.velocity *= scale; Audio_InitNoteSub(note, noteSubEu2, &subAttrs); noteSubEu->bitField1.bookOffset = bookOffset; diff --git a/soh/src/code/audio_seqplayer.c b/soh/src/code/audio_seqplayer.c index 52d14a9a1..beac78269 100644 --- a/soh/src/code/audio_seqplayer.c +++ b/soh/src/code/audio_seqplayer.c @@ -3,6 +3,9 @@ #include "ultra64.h" #include "global.h" +extern bool gUseLegacySD; +extern char* sequenceMap[256]; + #define PORTAMENTO_IS_SPECIAL(x) ((x).mode & 0x80) #define PORTAMENTO_MODE(x) ((x).mode & ~0x80) #define PORTAMENTO_MODE_1 1 @@ -1060,9 +1063,15 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { command = (u8)parameters[0]; if (seqPlayer->defaultFont != 0xFF) { - offset = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId]; - lowBits = gAudioContext.sequenceFontTable[offset]; - command = gAudioContext.sequenceFontTable[offset + lowBits - result]; + if (gUseLegacySD) { + offset = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId]; + lowBits = gAudioContext.sequenceFontTable[offset]; + command = gAudioContext.sequenceFontTable[offset + lowBits - result]; + } + else { + SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqPlayer->seqId]); + command = sDat.fonts[sDat.numFonts - result - 1]; + } } if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, command)) { @@ -1170,10 +1179,17 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { result = (u8)parameters[0]; command = (u8)parameters[0]; - if (seqPlayer->defaultFont != 0xFF) { - offset = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId]; - lowBits = gAudioContext.sequenceFontTable[offset]; - command = gAudioContext.sequenceFontTable[offset + lowBits - result]; + if (seqPlayer->defaultFont != 0xFF) + { + if (gUseLegacySD) { + offset = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId]; + lowBits = gAudioContext.sequenceFontTable[offset]; + command = gAudioContext.sequenceFontTable[offset + lowBits - result]; + } + else { + SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqPlayer->seqId]); + command = sDat.fonts[sDat.numFonts - result - 1]; + } } if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, command)) { @@ -1330,14 +1346,12 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { break; case 0xB2: offset = (u16)parameters[0]; - // OTRTODO: Byteswap added for quick audio channel->unk_22 = BOMSWAP16(*(u16*)(seqPlayer->seqData + (uintptr_t)(offset + scriptState->value * 2))); break; case 0xB4: channel->dynTable = (void*)&seqPlayer->seqData[channel->unk_22]; break; case 0xB5: - // OTRTODO: Byteswap added for quick audio channel->unk_22 = BOMSWAP16(((u16*)(channel->dynTable))[scriptState->value]); break; case 0xB6: diff --git a/soh/src/code/audio_synthesis.c b/soh/src/code/audio_synthesis.c index b567dd0ef..0f402b111 100644 --- a/soh/src/code/audio_synthesis.c +++ b/soh/src/code/audio_synthesis.c @@ -440,11 +440,11 @@ void func_800DBE64(void) { void func_800DBE6C(void) { } -void AudioSynth_LoadFilter(Acmd* cmd, s32 flags, s32 countOrBuf, s32 addr) { +void AudioSynth_LoadFilter(Acmd* cmd, s32 flags, s32 countOrBuf, uintptr_t addr) { aFilter(cmd, flags, countOrBuf, addr); } -void AudioSynth_LoadFilterCount(Acmd* cmd, s32 count, s32 addr) { +void AudioSynth_LoadFilterCount(Acmd* cmd, s32 count, uintptr_t addr) { aFilter(cmd, 2, count, addr); } @@ -561,6 +561,9 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat NoteSubEu* noteSubEu2; s32 unk14; + if (aiBufLen == 0) + return; + t = gAudioContext.numNotes * updateIndex; count = 0; if (gAudioContext.numSynthesisReverbs == 0) { diff --git a/soh/src/code/code_800F9280.c b/soh/src/code/code_800F9280.c index e23ede0e9..6ca2ad75d 100644 --- a/soh/src/code/code_800F9280.c +++ b/soh/src/code/code_800F9280.c @@ -363,7 +363,11 @@ void Audio_ProcessSeqCmd(u32 cmd) { } } -void Audio_QueueSeqCmd(u32 cmd) { +extern f32 D_80130F24; +extern f32 D_80130F28; + +void Audio_QueueSeqCmd(u32 cmd) +{ sAudioSeqCmds[sSeqCmdWrPos++] = cmd; } -- cgit v1.2.3 From 2b40e66fa490a15934a943eb0a262a300c5bbfce Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Fri, 10 Jun 2022 15:40:19 -0400 Subject: Fixed resample and corrupt audio bug. Minor documentation updates. --- soh/src/code/audio_load.c | 4 ++++ soh/src/code/z_kankyo.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'soh/src/code') diff --git a/soh/src/code/audio_load.c b/soh/src/code/audio_load.c index 0732d2fa3..3056a442b 100644 --- a/soh/src/code/audio_load.c +++ b/soh/src/code/audio_load.c @@ -1421,6 +1421,10 @@ void AudioLoad_Init(void* heap, u32 heapSize) { uintptr_t bankStart = ResourceMgr_LoadFileRaw(_AudiobankSegmentRomStart); uintptr_t tableStart = ResourceMgr_LoadFileRaw(_AudiotableSegmentRomStart); + // If we have the old audioseq files present (and this is a 32-bit build), use the legacy audio system + if (seqStart != NULL && bankStart != NULL && tableStart != NULL) + gUseLegacySD = true; + fontStart = bankStart; AudioLoad_InitTable(gAudioContext.sequenceTable, seqStart, 0); diff --git a/soh/src/code/z_kankyo.c b/soh/src/code/z_kankyo.c index 9f7518374..6f1fc0c8f 100644 --- a/soh/src/code/z_kankyo.c +++ b/soh/src/code/z_kankyo.c @@ -2093,9 +2093,14 @@ void func_80075B44(GlobalContext* globalCtx) { case 7: Audio_SetNatureAmbienceChannelIO(NATURE_CHANNEL_CRITTER_1 << 4 | NATURE_CHANNEL_CRITTER_3, CHANNEL_IO_PORT_1, 0); - if (globalCtx->envCtx.unk_EE[0] == 0 && globalCtx->envCtx.unk_F2[0] == 0) { - Audio_SetNatureAmbienceChannelIO(NATURE_CHANNEL_CRITTER_4 << 4 | NATURE_CHANNEL_CRITTER_5, - CHANNEL_IO_PORT_1, 1); + if (globalCtx->envCtx.unk_EE[0] == 0 && globalCtx->envCtx.unk_F2[0] == 0) + { + // OTRTODO: This is where corrupt audio happens. Commenting this out seems to not introduce any side effects? + // Further investigation is needed... + + if (gUseLegacySD) + Audio_SetNatureAmbienceChannelIO(NATURE_CHANNEL_CRITTER_4 << 4 | NATURE_CHANNEL_CRITTER_5, + CHANNEL_IO_PORT_1, 1); } globalCtx->envCtx.unk_E0++; break; -- cgit v1.2.3 From 6c94c8690eaf1676e81fd0bd21cd6cd9574a24a2 Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Mon, 13 Jun 2022 18:09:22 -0400 Subject: Updated sample rate to 44100hz --- soh/src/code/audio_init_params.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'soh/src/code') diff --git a/soh/src/code/audio_init_params.c b/soh/src/code/audio_init_params.c index 8d990b623..cb479020d 100644 --- a/soh/src/code/audio_init_params.c +++ b/soh/src/code/audio_init_params.c @@ -68,22 +68,22 @@ ReverbSettings D_80133420[][3] = { // OTRTODO AudioSpec gAudioSpecs[18] = { - { 44000, 1, 24, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x4000, 0x2880, 0, 0, 0 }, - { 44000, 1, 24, 4, 0, 0, 2, D_80133420[1], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 44000, 1, 24, 4, 0, 0, 2, D_80133420[2], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 44000, 1, 23, 4, 0, 0, 2, D_80133420[4], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 44000, 1, 23, 4, 0, 0, 2, D_80133420[5], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 44000, 1, 24, 4, 0, 0, 2, D_80133420[6], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 44000, 1, 24, 4, 0, 0, 2, D_80133420[7], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 44000, 1, 23, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 44000, 1, 24, 4, 0, 0, 2, D_80133420[9], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 44000, 1, 23, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 44000, 1, 28, 3, 0, 0, 2, D_80133420[10], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x2800, 0x2880, 0, 0, 0 }, - { 44000, 1, 28, 3, 0, 0, 1, D_80133420[11], 0x300, 0x200, 0x7FFF, 0, 0x4800, 0, 0x4000, 0, 0, 0, 0 }, - { 44000, 1, 28, 3, 0, 0, 1, D_80133420[11], 0x300, 0x200, 0x7FFF, 0, 0, 0, 0x4000, 0x4800, 0, 0, 0 }, - { 44000, 1, 22, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 44000, 1, 22, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 44000, 1, 16, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44100, 1, 24, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x4000, 0x2880, 0, 0, 0 }, + { 44100, 1, 24, 4, 0, 0, 2, D_80133420[1], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44100, 1, 24, 4, 0, 0, 2, D_80133420[2], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44100, 1, 23, 4, 0, 0, 2, D_80133420[4], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44100, 1, 23, 4, 0, 0, 2, D_80133420[5], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44100, 1, 24, 4, 0, 0, 2, D_80133420[6], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44100, 1, 24, 4, 0, 0, 2, D_80133420[7], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44100, 1, 23, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44100, 1, 24, 4, 0, 0, 2, D_80133420[9], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44100, 1, 23, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44100, 1, 28, 3, 0, 0, 2, D_80133420[10], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x2800, 0x2880, 0, 0, 0 }, + { 44100, 1, 28, 3, 0, 0, 1, D_80133420[11], 0x300, 0x200, 0x7FFF, 0, 0x4800, 0, 0x4000, 0, 0, 0, 0 }, + { 44100, 1, 28, 3, 0, 0, 1, D_80133420[11], 0x300, 0x200, 0x7FFF, 0, 0, 0, 0x4000, 0x4800, 0, 0, 0 }, + { 44100, 1, 22, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44100, 1, 22, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 44100, 1, 16, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, { 22050, 1, 24, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 44000, 1, 24, 4, 0, 0, 2, D_80133420[2], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3600, 0x2600, 0, 0, 0 }, + { 44100, 1, 24, 4, 0, 0, 2, D_80133420[2], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3600, 0x2600, 0, 0, 0 }, }; -- cgit v1.2.3 From 0a629ea6e953d9b2d63d14c28525e7047de88984 Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Mon, 13 Jun 2022 21:54:25 -0400 Subject: Fixed last remaining audio bugs --- soh/src/code/audio_init_params.c | 1 - soh/src/code/audio_synthesis.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'soh/src/code') diff --git a/soh/src/code/audio_init_params.c b/soh/src/code/audio_init_params.c index cb479020d..ebe5e8130 100644 --- a/soh/src/code/audio_init_params.c +++ b/soh/src/code/audio_init_params.c @@ -66,7 +66,6 @@ ReverbSettings D_80133420[][3] = { }, }; -// OTRTODO AudioSpec gAudioSpecs[18] = { { 44100, 1, 24, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x4000, 0x2880, 0, 0, 0 }, { 44100, 1, 24, 4, 0, 0, 2, D_80133420[1], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, diff --git a/soh/src/code/audio_synthesis.c b/soh/src/code/audio_synthesis.c index 0f402b111..2c5d03102 100644 --- a/soh/src/code/audio_synthesis.c +++ b/soh/src/code/audio_synthesis.c @@ -561,8 +561,8 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat NoteSubEu* noteSubEu2; s32 unk14; - if (aiBufLen == 0) - return; + //if (aiBufLen == 0) + //return; t = gAudioContext.numNotes * updateIndex; count = 0; -- cgit v1.2.3 From c930bd0138a987223a854c4f4d54e6c9b4a48778 Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Tue, 14 Jun 2022 00:59:31 -0400 Subject: Added names for the soundfonts. --- soh/src/code/audio_init_params.c | 3 ++- soh/src/code/audio_load.c | 35 ++++++++++++++++++++++++++--------- soh/src/code/audio_playback.c | 6 +++--- 3 files changed, 31 insertions(+), 13 deletions(-) (limited to 'soh/src/code') diff --git a/soh/src/code/audio_init_params.c b/soh/src/code/audio_init_params.c index ebe5e8130..95af11421 100644 --- a/soh/src/code/audio_init_params.c +++ b/soh/src/code/audio_init_params.c @@ -10,7 +10,8 @@ const s16 D_8014A6C0[] = { 0x0030, // gTatumsPerBeat }; -const AudioContextInitSizes D_8014A6C4 = { 0x37F00, 0xE0E0, 0xBCE0 }; +//const AudioContextInitSizes D_8014A6C4 = { 0x37F00, 0xE0E0, 0xBCE0 }; +const AudioContextInitSizes D_8014A6C4 = { 0x37F000, 0xE0E00, 0xBCE00 }; // OTRTODO: This might be overkill... ReverbSettings D_80133420[][3] = { { diff --git a/soh/src/code/audio_load.c b/soh/src/code/audio_load.c index 3056a442b..29226bcbe 100644 --- a/soh/src/code/audio_load.c +++ b/soh/src/code/audio_load.c @@ -76,6 +76,7 @@ void* sUnusedHandler = NULL; s32 gAudioContextInitalized = false; char* sequenceMap[256]; +char* fontMap[256]; uintptr_t fontStart; uint32_t fontOffsets[8192]; @@ -690,7 +691,8 @@ SoundFontData* AudioLoad_SyncLoadFont(u32 fontId) { } if (!gUseLegacySD) { - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId); + SoundFont* sf = ResourceMgr_LoadAudioSoundFont + (fontMap[fontId]); sampleBankId1 = sf->sampleBankId1; sampleBankId2 = sf->sampleBankId2; @@ -757,7 +759,7 @@ void* AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { } else if (!gUseLegacySD && tableType == FONT_TABLE) { - fnt = ResourceMgr_LoadAudioSoundFont(id); + fnt = ResourceMgr_LoadAudioSoundFont(fontMap[id]); size = sizeof(SoundFont); medium = 2; cachePolicy = 0; @@ -895,7 +897,7 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo Drum* drum; SoundFontSound* sfx; s32 i; - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId); + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); s32 numDrums = 0; s32 numInstruments = 0; @@ -1433,10 +1435,6 @@ void AudioLoad_Init(void* heap, u32 heapSize) { if (gUseLegacySD) numFonts = gAudioContext.soundFontTable->numEntries; - else - numFonts = 0x26; // OTRTODO: Count the number of soundfonts that are inside the OTR(s) - - gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); if (gUseLegacySD) { for (i = 0; i < numFonts; i++) { @@ -1460,9 +1458,28 @@ void AudioLoad_Init(void* heap, u32 heapSize) { free(seqList); + int fntListSize = 0; + char** fntList = ResourceMgr_ListFiles("audio/fonts*", &fntListSize); + + for (int i = 0; i < fntListSize; i++) + { + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fntList[i]); + + char* str = malloc(strlen(fntList[i]) + 1); + strcpy(str, fntList[i]); + + fontMap[sf->fntIndex] = str; + } + + numFonts = fntListSize; + + free(fntList); + int bp = 0; } + gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); + if (temp_v0_3 = AudioHeap_Alloc(&gAudioContext.audioInitPool, D_8014A6C4.permanentPoolSize), temp_v0_3 == NULL) { // cast away const from D_8014A6C4 *((u32*)&D_8014A6C4.permanentPoolSize) = 0; @@ -2182,7 +2199,7 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, RelocInfo* relocInfo gAudioContext.numUsedSamples = 0; if (!gUseLegacySD) { - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId); + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); numDrums = sf->numDrums; numInstruments = sf->numInstruments; @@ -2319,7 +2336,7 @@ void AudioLoad_LoadPermanentSamples(void) { //fontId = gAudioContext.permanentCache[i].id; if (!gUseLegacySD) { - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId); + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); relocInfo.sampleBankId1 = sf->sampleBankId1; relocInfo.sampleBankId2 = sf->sampleBankId2; } else { diff --git a/soh/src/code/audio_playback.c b/soh/src/code/audio_playback.c index 9992eee3d..df64e2c7b 100644 --- a/soh/src/code/audio_playback.c +++ b/soh/src/code/audio_playback.c @@ -342,7 +342,7 @@ Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) { return NULL; } } else { - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId); + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); if (instId >= sf->numInstruments) return NULL; @@ -379,7 +379,7 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) { drum = gAudioContext.soundFonts[fontId].drums[drumId]; } else { - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId); + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); drum = sf->drums[drumId]; } @@ -410,7 +410,7 @@ SoundFontSound* Audio_GetSfx(s32 fontId, s32 sfxId) { sfx = &gAudioContext.soundFonts[fontId].soundEffects[sfxId]; } else { - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId); + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); sfx = &sf->soundEffects[sfxId]; } -- cgit v1.2.3 From 960a29e5138d6258a6a214d024da5eff600ce7e4 Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Tue, 14 Jun 2022 18:56:17 -0400 Subject: Fixed StormLib Forward Slash BackSlash issues --- soh/src/code/audio_load.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'soh/src/code') diff --git a/soh/src/code/audio_load.c b/soh/src/code/audio_load.c index 29226bcbe..5a579e2a0 100644 --- a/soh/src/code/audio_load.c +++ b/soh/src/code/audio_load.c @@ -897,8 +897,8 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo Drum* drum; SoundFontSound* sfx; s32 i; - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); - + SoundFont* sf = NULL; + s32 numDrums = 0; s32 numInstruments = 0; s32 numSfx = 0; @@ -908,6 +908,7 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo numInstruments = gAudioContext.soundFonts[fontId].numInstruments; numSfx = gAudioContext.soundFonts[fontId].numSfx; } else { + sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); numDrums = sf->numDrums; numInstruments = sf->numInstruments; numSfx = sf->numSfx; @@ -1436,7 +1437,10 @@ void AudioLoad_Init(void* heap, u32 heapSize) { if (gUseLegacySD) numFonts = gAudioContext.soundFontTable->numEntries; - if (gUseLegacySD) { + if (gUseLegacySD) + { + gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); + for (i = 0; i < numFonts; i++) { AudioLoad_InitSoundFontMeta(i); } @@ -1474,11 +1478,10 @@ void AudioLoad_Init(void* heap, u32 heapSize) { numFonts = fntListSize; free(fntList); + gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); - int bp = 0; } - gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); if (temp_v0_3 = AudioHeap_Alloc(&gAudioContext.audioInitPool, D_8014A6C4.permanentPoolSize), temp_v0_3 == NULL) { // cast away const from D_8014A6C4 -- cgit v1.2.3 From ac8acaeba48987bb8f432e435a5a42f2872cb4a7 Mon Sep 17 00:00:00 2001 From: vaguerant Date: Fri, 17 Jun 2022 11:08:32 +1000 Subject: Cheat: shield with two-handed weapons (#487) --- soh/src/code/z_player_lib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'soh/src/code') diff --git a/soh/src/code/z_player_lib.c b/soh/src/code/z_player_lib.c index cf7fbd51c..77c569951 100644 --- a/soh/src/code/z_player_lib.c +++ b/soh/src/code/z_player_lib.c @@ -360,7 +360,8 @@ s32 Player_ActionToModelGroup(Player* this, s32 actionParam) { void Player_SetModelsForHoldingShield(Player* this) { if ((this->stateFlags1 & 0x400000) && ((this->itemActionParam < 0) || (this->itemActionParam == this->heldItemActionParam))) { - if (!Player_HoldsTwoHandedWeapon(this) && !Player_IsChildWithHylianShield(this)) { + if ((CVar_GetS32("gShieldTwoHanded", 0) && (this->heldItemActionParam != PLAYER_AP_STICK) || + !Player_HoldsTwoHandedWeapon(this)) && !Player_IsChildWithHylianShield(this)) { this->rightHandType = 10; this->rightHandDLists = &sPlayerDListGroups[10][(void)0, gSaveContext.linkAge]; if (this->sheathType == 18) { -- cgit v1.2.3