From 73ec7f9001515077ff97d4ca930e90d8b202f679 Mon Sep 17 00:00:00 2001 From: = Date: Sun, 7 Apr 2024 15:19:21 -0400 Subject: [PATCH] Lock RAM audio to size of buffer. External saves --- soh-uwp/Package.appxmanifest | 2 +- soh/soh/SaveManager.cpp | 14 +++++++------- soh/src/code/audio_synthesis.c | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/soh-uwp/Package.appxmanifest b/soh-uwp/Package.appxmanifest index 3dbfb047..a4001529 100644 --- a/soh-uwp/Package.appxmanifest +++ b/soh-uwp/Package.appxmanifest @@ -15,7 +15,7 @@ + Version="1.1.2.0" /> diff --git a/soh/soh/SaveManager.cpp b/soh/soh/SaveManager.cpp index d8003988..dfc61d67 100644 --- a/soh/soh/SaveManager.cpp +++ b/soh/soh/SaveManager.cpp @@ -44,12 +44,12 @@ void SaveManager::ReadSaveFile(std::filesystem::path savePath, uintptr_t addr, v } std::filesystem::path SaveManager::GetFileName(int fileNum) { - const std::filesystem::path sSavePath(LUS::Context::GetPathRelativeToAppDirectory("Save")); + const std::filesystem::path sSavePath(LUS::Context::GetPathRelativeToAuxiliary("Save")); return sSavePath / ("file" + std::to_string(fileNum + 1) + ".sav"); } std::filesystem::path SaveManager::GetFileTempName(int fileNum) { - const std::filesystem::path sSavePath(LUS::Context::GetPathRelativeToAppDirectory("Save")); + const std::filesystem::path sSavePath(LUS::Context::GetPathRelativeToAuxiliary("Save")); return sSavePath / ("file" + std::to_string(fileNum + 1) + ".temp"); } @@ -371,10 +371,10 @@ void SaveManager::SaveRandomizer(SaveContext* saveContext, int sectionID, bool f void SaveManager::Init() { // Wait on saves that snuck through the Wait in OnExitGame ThreadPoolWait(); - const std::filesystem::path sSavePath(LUS::Context::GetPathRelativeToAppDirectory("Save")); + const std::filesystem::path sSavePath(LUS::Context::GetPathRelativeToAuxiliary("Save")); const std::filesystem::path sGlobalPath = sSavePath / std::string("global.sav"); - auto sOldSavePath = LUS::Context::GetPathRelativeToAppDirectory("oot_save.sav"); - auto sOldBackupSavePath = LUS::Context::GetPathRelativeToAppDirectory("oot_save.bak"); + auto sOldSavePath = LUS::Context::GetPathRelativeToAuxiliary("oot_save.sav"); + auto sOldBackupSavePath = LUS::Context::GetPathRelativeToAuxiliary("oot_save.bak"); // If the save directory does not exist, create it if (!std::filesystem::exists(sSavePath)) { @@ -1017,7 +1017,7 @@ void SaveManager::SaveGlobal() { globalBlock["zTargetSetting"] = gSaveContext.zTargetSetting; globalBlock["language"] = gSaveContext.language; - const std::filesystem::path sSavePath(LUS::Context::GetPathRelativeToAppDirectory("Save")); + const std::filesystem::path sSavePath(LUS::Context::GetPathRelativeToAuxiliary("Save")); const std::filesystem::path sGlobalPath = sSavePath / std::string("global.sav"); std::ofstream output(sGlobalPath); @@ -1076,7 +1076,7 @@ void SaveManager::LoadFile(int fileNum) { GameInteractor::Instance->ExecuteHooks(fileNum); } catch (const std::exception& e) { input.close(); - std::filesystem::path newFile(LUS::Context::GetPathRelativeToAppDirectory("Save") + ("/file" + std::to_string(fileNum + 1) + "-" + std::to_string(GetUnixTimestamp()) + ".bak")); + std::filesystem::path newFile(LUS::Context::GetPathRelativeToAuxiliary("Save") + ("/file" + std::to_string(fileNum + 1) + "-" + std::to_string(GetUnixTimestamp()) + ".bak")); #if defined(__SWITCH__) || defined(__WIIU__) copy_file(fileName.c_str(), newFile.c_str()); #else diff --git a/soh/src/code/audio_synthesis.c b/soh/src/code/audio_synthesis.c index 2911730c..57674813 100644 --- a/soh/src/code/audio_synthesis.c +++ b/soh/src/code/audio_synthesis.c @@ -714,7 +714,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS s16* filter; s32 bookOffset; s32 finished; - s32 aligned; + s32 aligned, ramAlign; s16 addr; u16 unused; @@ -803,6 +803,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS noteFinished = false; restart = false; phi_s4 = 0; + endOfSample = false; nFirstFrameSamplesToIgnore = synthState->samplePosInt & 0xF; nSamplesUntilLoopEnd = loopEndPos - synthState->samplePosInt; @@ -897,7 +898,18 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS aLoadBuffer(cmd++, sampleData - sampleDataStartPad, addr, aligned); // RAM samples do not need rounded alignment value for src bytes otherwise access violations ahoy! } else { - aLoadBufferNoRound(cmd++, sampleData - sampleDataStartPad, addr, (nFramesToDecode * frameSize + 16)); + /* + * Probably a cleaner way of handling this but 16 padding needs to scale down towards end of + * buffer. Example: + * + * Final frame with one sample remaining: + * S + * DDDDDDDDDPPPPPPPPPPPPPPPP + * + * This should return a padding of 17, not 25 + */ + ramAlign = min((nFramesToDecode * frameSize) + 16, (audioFontSample->size + 16) - (sampleDataOffset + sampleDataStart)); + aLoadBufferNoRound(cmd++, sampleData - sampleDataStartPad, addr, ramAlign); } } else {