Browse Source

Fix parentheses mistake for retrieving streaming audio timings and apply code fix suggestions from Adam

tickets/38/38/1
ZarothYe 2 years ago
parent
commit
126d7511e0
  1. 2
      Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.cpp
  2. 3
      Sources/Plasma/PubUtilLib/plAudio/plWin32Sound.cpp
  3. 4
      Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.cpp
  4. 4
      Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.h

2
Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.cpp

@ -712,7 +712,7 @@ hsBool plDSoundBuffer::IsEAXAccelerated( void ) const
UInt32 plDSoundBuffer::BytePosToMSecs(UInt32 bytePos) const UInt32 plDSoundBuffer::BytePosToMSecs(UInt32 bytePos) const
{ {
return (UInt32)(bytePos / ((hsScalar)fBufferDesc->fAvgBytesPerSec) / 1000.0f); return (UInt32)(bytePos / ((float)fBufferDesc->fAvgBytesPerSec / 1000.0f));
} }
//// GetBufferBytePos //////////////////////////////////////////////////////// //// GetBufferBytePos ////////////////////////////////////////////////////////

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

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

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

@ -64,7 +64,7 @@ bool plSrtFileReader::ReadFile()
// if file exists and was opened successfully // if file exists and was opened successfully
if (srtFileStream.Open(path, L"r")) { if (srtFileStream.Open(path, L"r")) {
plStatusLog::AddLineS("audio.log", "Successfully opened subtitle file {}", path); plStatusLog::AddLineS("audio.log", "Successfully opened subtitle file %S", path);
uint32_t subtitleNumber = 0; uint32_t subtitleNumber = 0;
uint32_t subtitleStartTimeMs = 0; uint32_t subtitleStartTimeMs = 0;
@ -81,7 +81,7 @@ bool plSrtFileReader::ReadFile()
if (std::regex_match(line, matches, timingsRegex)) { if (std::regex_match(line, matches, timingsRegex)) {
if (matches.size() < 9) { if (matches.size() < 9) {
// add error message and ensure this subtitle line won't be added to the entries // add error message and ensure this subtitle line won't be added to the entries
plStatusLog::AddLineS("audio.log", plStatusLog::kRed, " Subtitle timings '{}' are formatted incorrectly.", line); plStatusLog::AddLineS("audio.log", plStatusLog::kRed, " Subtitle timings '%s' are formatted incorrectly.", line);
subtitleNumber = 0; subtitleNumber = 0;
} }
else { else {

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

@ -50,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _plSrtFileReader_h #define _plSrtFileReader_h
#include "hsTypes.h" #include "hsTypes.h"
#include "../pnUtils/pnUtils.h"
#include <cstdint> #include <cstdint>
#include <vector> #include <vector>
@ -85,7 +86,8 @@ class plSrtFileReader
public: public:
plSrtFileReader(const char* audioFileName) plSrtFileReader(const char* audioFileName)
: fAudioFileName(std::move(audioFileName)), fEntries(), fCurrentEntryIndex() { } : fAudioFileName(StrDup(audioFileName)), fCurrentEntryIndex(0) { }
virtual ~plSrtFileReader() { delete[] fAudioFileName; }
bool ReadFile(); bool ReadFile();
void StartOver() { fCurrentEntryIndex = 0; } void StartOver() { fCurrentEntryIndex = 0; }

Loading…
Cancel
Save