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

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

@ -710,9 +710,9 @@ hsBool plDSoundBuffer::IsEAXAccelerated( void ) const
//// 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 ////////////////////////////////////////////////////////

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

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

Loading…
Cancel
Save