Browse Source

Fix usage and overflow bug causing plWin32StreamingSound::GetActualTimeSec() to return absurd values. Needed fix for subtitle timings.

working_subtitles
ZarothYe 3 years ago committed by rarified
parent
commit
d0d8dd246e
  1. 4
      Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.cpp
  2. 13
      Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp

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

@ -710,9 +710,9 @@ hsBool plDSoundBuffer::IsEAXAccelerated( void ) const
//// BytePosToMSecs ////////////////////////////////////////////////////////// //// BytePosToMSecs //////////////////////////////////////////////////////////
UInt32 plDSoundBuffer::BytePosToMSecs( UInt32 bytePos ) const UInt32 plDSoundBuffer::BytePosToMSecs(UInt32 bytePos) const
{ {
return (UInt32)(bytePos * 1000 / (hsScalar)fBufferDesc->fAvgBytesPerSec); return (UInt32)(bytePos / ((hsScalar)fBufferDesc->fAvgBytesPerSec) / 1000.0f);
} }
//// GetBufferBytePos //////////////////////////////////////////////////////// //// GetBufferBytePos ////////////////////////////////////////////////////////

13
Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp

@ -455,21 +455,24 @@ void plWin32StreamingSound::IActuallyStop()
unsigned plWin32StreamingSound::GetByteOffset() unsigned plWin32StreamingSound::GetByteOffset()
{ {
if(fDataStream && fDSoundBuffer) if (fDataStream && fDSoundBuffer)
{ {
UInt32 totalSize = fDataStream->GetDataSize();
UInt32 bytesRemaining = fDataStream->NumBytesLeft();
unsigned bytesQueued = fDSoundBuffer->BuffersQueued() * STREAM_BUFFER_SIZE; unsigned bytesQueued = fDSoundBuffer->BuffersQueued() * STREAM_BUFFER_SIZE;
unsigned offset = fDSoundBuffer->GetByteOffset(); unsigned offset = fDSoundBuffer->GetByteOffset();
long byteoffset = ((fDataStream->GetDataSize() - fDataStream->NumBytesLeft()) - bytesQueued) + offset; long byteoffset = ((totalSize - bytesRemaining) - bytesQueued) + offset;
return byteoffset < 0 ? fDataStream->GetDataSize() - abs(byteoffset) : byteoffset; return byteoffset < 0 ? totalSize - std::abs(byteoffset) : byteoffset;
} }
return 0; return 0;
} }
float plWin32StreamingSound::GetActualTimeSec() float plWin32StreamingSound::GetActualTimeSec()
{ {
if(fDataStream && fDSoundBuffer) if (fDataStream && fDSoundBuffer)
return fDSoundBuffer->BytePosToMSecs(fDataStream->NumBytesLeft()) / 1000.0f; return fDSoundBuffer->BytePosToMSecs(this->GetByteOffset()) / 1000.0f;
return 0.0f; return 0.0f;
} }

Loading…
Cancel
Save