From 40bcaba9d8eaae0b098aab3e2232d963706ac4be Mon Sep 17 00:00:00 2001 From: ZarothYe Date: Fri, 11 Mar 2022 10:55:44 -0600 Subject: [PATCH] Don't feed remaining subtitles when audio skips to past the end of last subtitle --- Sources/Plasma/PubUtilLib/plAudio/plWin32Sound.cpp | 12 +++++++----- .../PubUtilLib/plAudioCore/plSrtFileReader.cpp | 9 +++++++++ .../Plasma/PubUtilLib/plAudioCore/plSrtFileReader.h | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plAudio/plWin32Sound.cpp b/Sources/Plasma/PubUtilLib/plAudio/plWin32Sound.cpp index 945363a2..6cebf3c0 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plWin32Sound.cpp +++ b/Sources/Plasma/PubUtilLib/plAudio/plWin32Sound.cpp @@ -115,11 +115,13 @@ void plWin32Sound::Update() plSrtFileReader* srtReader = buf->GetSrtReader(); if (srtReader != nullptr) { uint32_t currentTimeMs = (uint32_t)(GetActualTimeSec() * 1000.0f); - while (plSrtEntry* nextEntry = srtReader->GetNextEntryStartingBeforeTime(currentTimeMs)) { - if (plgAudioSys::AreSubtitlesEnabled()) { - // add a plSubtitleMsg to go... to whoever is listening (probably the KI) - plSubtitleMsg* msg = new plSubtitleMsg(nextEntry->GetSubtitleText(), nextEntry->GetSpeakerName()); - msg->Send(); + if (currentTimeMs <= srtReader->GetLastEntryEndTime()) { + while (plSrtEntry* nextEntry = srtReader->GetNextEntryStartingBeforeTime(currentTimeMs)) { + if (plgAudioSys::AreSubtitlesEnabled()) { + // add a plSubtitleMsg to go... to whoever is listening (probably the KI) + plSubtitleMsg* msg = new plSubtitleMsg(nextEntry->GetSubtitleText(), nextEntry->GetSpeakerName()); + msg->Send(); + } } } } diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.cpp index 2cc63f32..13fcd13a 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.cpp @@ -184,4 +184,13 @@ plSrtEntry* plSrtFileReader::GetNextEntryEndingBeforeTime(uint32_t timeMs) } return nullptr; +} + +uint32_t plSrtFileReader::GetLastEntryEndTime() +{ + if (!fEntries.empty()) { + return fEntries.back().GetEndTimeMs(); + } + + return 0; } \ No newline at end of file diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.h b/Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.h index 94604f87..1d9750fd 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.h +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.h @@ -95,6 +95,7 @@ public: void AdvanceToTime(uint32_t timeMs); plSrtEntry* GetNextEntryStartingBeforeTime(uint32_t timeMs); plSrtEntry* GetNextEntryEndingBeforeTime(uint32_t timeMs); + uint32_t GetLastEntryEndTime(); protected: