Browse Source

Don't feed remaining subtitles when audio skips to past the end of last subtitle

(cherry picked from commit 40bcaba9d8)
working-2022q1
ZarothYe 3 years ago committed by rarified
parent
commit
f0d2bd3eaa
  1. 12
      Sources/Plasma/PubUtilLib/plAudio/plWin32Sound.cpp
  2. 9
      Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.cpp
  3. 1
      Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.h

12
Sources/Plasma/PubUtilLib/plAudio/plWin32Sound.cpp

@ -115,11 +115,13 @@ void plWin32Sound::Update()
plSrtFileReader* srtReader = buf->GetSrtReader(); plSrtFileReader* srtReader = buf->GetSrtReader();
if (srtReader != nullptr) { if (srtReader != nullptr) {
uint32_t currentTimeMs = (uint32_t)(GetActualTimeSec() * 1000.0f); uint32_t currentTimeMs = (uint32_t)(GetActualTimeSec() * 1000.0f);
while (plSrtEntry* nextEntry = srtReader->GetNextEntryStartingBeforeTime(currentTimeMs)) { if (currentTimeMs <= srtReader->GetLastEntryEndTime()) {
if (plgAudioSys::AreSubtitlesEnabled()) { while (plSrtEntry* nextEntry = srtReader->GetNextEntryStartingBeforeTime(currentTimeMs)) {
// add a plSubtitleMsg to go... to whoever is listening (probably the KI) if (plgAudioSys::AreSubtitlesEnabled()) {
plSubtitleMsg* msg = new plSubtitleMsg(nextEntry->GetSubtitleText(), nextEntry->GetSpeakerName()); // add a plSubtitleMsg to go... to whoever is listening (probably the KI)
msg->Send(); plSubtitleMsg* msg = new plSubtitleMsg(nextEntry->GetSubtitleText(), nextEntry->GetSpeakerName());
msg->Send();
}
} }
} }
} }

9
Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.cpp

@ -184,4 +184,13 @@ plSrtEntry* plSrtFileReader::GetNextEntryEndingBeforeTime(uint32_t timeMs)
} }
return nullptr; return nullptr;
}
uint32_t plSrtFileReader::GetLastEntryEndTime()
{
if (!fEntries.empty()) {
return fEntries.back().GetEndTimeMs();
}
return 0;
} }

1
Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.h

@ -95,6 +95,7 @@ public:
void AdvanceToTime(uint32_t timeMs); void AdvanceToTime(uint32_t timeMs);
plSrtEntry* GetNextEntryStartingBeforeTime(uint32_t timeMs); plSrtEntry* GetNextEntryStartingBeforeTime(uint32_t timeMs);
plSrtEntry* GetNextEntryEndingBeforeTime(uint32_t timeMs); plSrtEntry* GetNextEntryEndingBeforeTime(uint32_t timeMs);
uint32_t GetLastEntryEndTime();
protected: protected:

Loading…
Cancel
Save