From 8a5e118ab77de12a6e1fbc25dc79836191debeef Mon Sep 17 00:00:00 2001 From: Demur Rumed Date: Mon, 21 Apr 2025 14:14:38 +0000 Subject: [PATCH] optimize SfxExtractor bookkeeping --- .../accessible-actors/SfxExtractor.cpp | 17 +++++------------ .../accessible-actors/SfxExtractor.h | 3 +-- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/soh/soh/Enhancements/accessible-actors/SfxExtractor.cpp b/soh/soh/Enhancements/accessible-actors/SfxExtractor.cpp index 546bbb7bc..408165c28 100644 --- a/soh/soh/Enhancements/accessible-actors/SfxExtractor.cpp +++ b/soh/soh/Enhancements/accessible-actors/SfxExtractor.cpp @@ -107,14 +107,8 @@ void SfxExtractor::setup() { 0); // Over-allocated just a tad because otherwise we'll overrun if the last frame is short. tempBuffer = tempStorage.data(); - // Build are master sfx extraction todo list. - for (int i = 0; i < sfxCount; i++) - sfxToRip.push(sfxTable[i]); - + sfxToRip = 0; currentStep = STEP_MAIN; - for (int i = 1; i < 10; i++) { - progressMilestones[i - 1] = sfxToRip.size() - ((int)ceil(sfxToRip.size() * (i / 10.0f))); - } archive = std::make_shared("accessibility.o2r"); archive->Open(); } catch (...) { currentStep = STEP_ERROR; } @@ -135,13 +129,12 @@ void SfxExtractor::ripNextSfx() { return; } - if (sfxToRip.empty()) { + if (sfxToRip == sfxCount) { currentStep = STEP_FINISHED; // Caught 'em all! return; } - currentSfx = sfxToRip.front(); - sfxToRip.pop(); + currentSfx = sfxTable[sfxToRip++]; startOfInput = 0; endOfInput = 0; Audio_PlaySoundGeneral(currentSfx, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, @@ -177,9 +170,9 @@ void SfxExtractor::finished() { Audio_PlayFanfare(NA_BGM_ITEM_GET); } void SfxExtractor::maybeGiveProgressReport() { - size_t ripsRemaining = sfxToRip.size() + 1; + size_t ripsRemaining = sfxCount - sfxToRip; for (int i = 0; i < 9; i++) { - if (ripsRemaining == progressMilestones[i]) { + if (ripsRemaining == sfxCount - ((int)ceil(sfxCount * ((i+1) / 10.0f)))) { int percentDone = (i + 1) * 10; std::stringstream ss; ss << percentDone << " percent complete."; diff --git a/soh/soh/Enhancements/accessible-actors/SfxExtractor.h b/soh/soh/Enhancements/accessible-actors/SfxExtractor.h index 0f4deefcd..e6dc2b97a 100644 --- a/soh/soh/Enhancements/accessible-actors/SfxExtractor.h +++ b/soh/soh/Enhancements/accessible-actors/SfxExtractor.h @@ -4,13 +4,12 @@ class SfxExtractor { std::shared_ptr archive; int currentStep; int captureThreadState; - std::queue sfxToRip; + int sfxToRip; size_t startOfInput; size_t endOfInput; s16 currentSfx; std::vector tempStorage; // Stores raw audio data for the sfx currently being ripped. int16_t* tempBuffer; // Raw pointer to the above vector. - int progressMilestones[9]; // Implements progress reports after every 10 percent. // Check if a buffer contains meaningful audio output. bool isAllZero(int16_t* buffer, size_t count); // Find the beginning of a captured signal.