diff --git a/OTRExporter/OTRExporter/AudioExporter.cpp b/OTRExporter/OTRExporter/AudioExporter.cpp index a4d847771..b15b276fd 100644 --- a/OTRExporter/OTRExporter/AudioExporter.cpp +++ b/OTRExporter/OTRExporter/AudioExporter.cpp @@ -161,7 +161,8 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit WriteSoundFontEntry(audio, audio->soundFontTable[i].soundEffects[k], audio->samples, &fntWriter); } - std::string fName = OTRExporter_DisplayList::GetPathToRes(res, StringHelper::Sprintf("fonts/font_%02X", i)); + //std::string fName = OTRExporter_DisplayList::GetPathToRes(res, StringHelper::Sprintf("fonts/font_%02X", i)); + std::string fName = OTRExporter_DisplayList::GetPathToRes(res, StringHelper::Sprintf("fonts/%s", audio->soundFontNames[i].c_str())); AddFile(fName, fntStream->ToVector()); } diff --git a/ZAPDTR/ZAPD/ZAudio.cpp b/ZAPDTR/ZAPD/ZAudio.cpp index 976133513..a502a0545 100644 --- a/ZAPDTR/ZAPD/ZAudio.cpp +++ b/ZAPDTR/ZAPD/ZAudio.cpp @@ -68,6 +68,13 @@ void ZAudio::ParseXML(tinyxml2::XMLElement* reader) } } + if (std::string(child->Value()) == "Soundfont") + { + auto name = child->Attribute("Name"); + auto index = child->IntAttribute("Index", 0); + soundFontNames[index] = name; + } + child = child->NextSiblingElement(); } } @@ -154,14 +161,10 @@ SampleEntry* ZAudio::ParseSampleEntry(std::vector audioBank, int bp = 0; } - if (/* sample->loop.count != 0xFFFFFFFF && */ sample->loop.count != 0) + if (sample->loop.count != 0) { - //for (int i = 0; i < sample->loop.count; i++) for (int i = 0; i < 16; i++) { - //if ((loopOffset + 16 + (i * 2)) >= audioBank.size()) - //break; - int16_t state = BitConverter::ToInt16BE(audioBank, loopOffset + 16 + (i * 2)); sample->loop.states.push_back(state); } diff --git a/ZAPDTR/ZAPD/ZAudio.h b/ZAPDTR/ZAPD/ZAudio.h index 511ba5ed6..286c75c11 100644 --- a/ZAPDTR/ZAPD/ZAudio.h +++ b/ZAPDTR/ZAPD/ZAudio.h @@ -95,6 +95,7 @@ public: std::map samples; std::vector> fontIndices; std::vector seqNames; + std::map soundFontNames; // First Key = Bank ID, Sec Key = LoopDataOffset, Third Key = Sample Data Offset std::map>> sampleOffsets; diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp index 8d7933c0d..452b511d8 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp @@ -2085,7 +2085,7 @@ static inline void* seg_addr(uintptr_t w1) uint32_t segNum = (w1 >> 24); uint32_t offset = w1 & 0x00FFFFFE; - offset = 0; // Cursed Malon bug + //offset = 0; // Cursed Malon bug if (segmentPointers[segNum] != 0) return (void*)(segmentPointers[segNum] + offset); diff --git a/soh/assets/xml/GC_NMQ_D/audio/Audio.xml b/soh/assets/xml/GC_NMQ_D/audio/Audio.xml index 2d35b24c2..e021bb0ac 100644 --- a/soh/assets/xml/GC_NMQ_D/audio/Audio.xml +++ b/soh/assets/xml/GC_NMQ_D/audio/Audio.xml @@ -1171,7 +1171,7 @@ - + @@ -1514,6 +1514,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/soh/include/z64audio.h b/soh/include/z64audio.h index b804eb193..2eb497571 100644 --- a/soh/include/z64audio.h +++ b/soh/include/z64audio.h @@ -21,6 +21,7 @@ #define CALC_RESAMPLE_FREQ(sampleRate) ((float)sampleRate / (s32)gAudioContext.audioBufferParameters.frequency) extern bool gUseLegacySD; +extern char* fontMap[256]; typedef enum { /* 0 */ ADSR_STATE_DISABLED, @@ -233,6 +234,7 @@ typedef struct { /* 0x08 */ Instrument** instruments; /* 0x0C */ Drum** drums; /* 0x10 */ SoundFontSound* soundEffects; + s32 fntIndex; } SoundFont; // size = 0x14 typedef struct { diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index a9332573a..125207a5b 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -567,18 +567,6 @@ extern "C" Vtx* ResourceMgr_LoadVtxByName(const char* path) return (Vtx*)res->vertices.data(); } -extern "C" SequenceData ResourceMgr_LoadSeqByID(int seqID) { - if (seqID == 0xFF) { - SequenceData sDat; - sDat.numFonts = 0; - - return sDat; - } - - std::string fmtStr = "audio/sequences/seq_%02X"; - return ResourceMgr_LoadSeqByName(StringHelper::Sprintf(fmtStr.c_str(), seqID).c_str()); -} - extern "C" SequenceData ResourceMgr_LoadSeqByName(const char* path) { auto file = OTRGlobals::Instance->context->GetResourceManager()->LoadFile(path).get(); @@ -604,8 +592,6 @@ std::map cachedCustomSFs; extern "C" SoundFontSample* ResourceMgr_LoadAudioSample(const char* path) { - //auto str = StringHelper::Sprintf("audio/samples/sample_%08X", romOffset); - if (std::string(path) == "") return nullptr; @@ -694,10 +680,9 @@ extern "C" SoundFontSample* ResourceMgr_LoadAudioSample(const char* path) } } -extern "C" SoundFont* ResourceMgr_LoadAudioSoundFont(int fontIndex) { +extern "C" SoundFont* ResourceMgr_LoadAudioSoundFont(const char* path) { auto soundFont = - std::static_pointer_cast(OTRGlobals::Instance->context->GetResourceManager()->LoadResource( - StringHelper::Sprintf("audio/fonts/font_%02X", fontIndex))); + std::static_pointer_cast(OTRGlobals::Instance->context->GetResourceManager()->LoadResource(path)); if (soundFont == nullptr) return NULL; @@ -710,6 +695,7 @@ extern "C" SoundFont* ResourceMgr_LoadAudioSoundFont(int fontIndex) { { SoundFont* soundFontC = (SoundFont*)malloc(sizeof(SoundFont)); + soundFontC->fntIndex = soundFont->id; soundFontC->numDrums = soundFont->drums.size(); soundFontC->numInstruments = soundFont->instruments.size(); soundFontC->numSfx = soundFont->soundEffects.size(); diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index f5b3e25d3..851a3cfaf 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -47,8 +47,7 @@ Gfx* ResourceMgr_LoadGfxByName(const char* path); Gfx* ResourceMgr_PatchGfxByName(const char* path, int size); Vtx* ResourceMgr_LoadVtxByCRC(uint64_t crc); Vtx* ResourceMgr_LoadVtxByName(const char* path); -SoundFont* ResourceMgr_LoadAudioSoundFont(int fontIndex); -SequenceData ResourceMgr_LoadSeqByID(int seqID); +SoundFont* ResourceMgr_LoadAudioSoundFont(const char* path); SequenceData ResourceMgr_LoadSeqByName(const char* path); SoundFontSample* ResourceMgr_LoadAudioSample(const char* path); CollisionHeader* ResourceMgr_LoadColByName(const char* path); 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]; }