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. 2
      Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.cpp
  2. 9
      Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp

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

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

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

@ -457,19 +457,22 @@ unsigned plWin32StreamingSound::GetByteOffset()
{
if (fDataStream && fDSoundBuffer)
{
UInt32 totalSize = fDataStream->GetDataSize();
UInt32 bytesRemaining = fDataStream->NumBytesLeft();
unsigned bytesQueued = fDSoundBuffer->BuffersQueued() * STREAM_BUFFER_SIZE;
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;
}
float plWin32StreamingSound::GetActualTimeSec()
{
if (fDataStream && fDSoundBuffer)
return fDSoundBuffer->BytePosToMSecs(fDataStream->NumBytesLeft()) / 1000.0f;
return fDSoundBuffer->BytePosToMSecs(this->GetByteOffset()) / 1000.0f;
return 0.0f;
}

Loading…
Cancel
Save