Skip to content

Commit

Permalink
Merge pull request #1065 from ZarothYe/fix-streaming-sound-timings
Browse files Browse the repository at this point in the history
Make `plWin32StreamingSound::GetActualTimeSec()` return correct values
  • Loading branch information
Hoikas authored Feb 8, 2022
2 parents 8e67706 + 5513597 commit 3b20ede
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,9 @@ bool plDSoundBuffer::IsEAXAccelerated() const

//// bytePosToMSecs //////////////////////////////////////////////////////////

uint32_t plDSoundBuffer::bytePosToMSecs( uint32_t bytePos ) const
uint32_t plDSoundBuffer::bytePosToMSecs(uint32_t bytePos) const
{
return (uint32_t)(bytePos * 1000 / (float)fBufferDesc->fAvgBytesPerSec);
return (uint32_t)(bytePos / ((float)fBufferDesc->fAvgBytesPerSec / 1000.0f));
}

//// GetBufferBytePos ////////////////////////////////////////////////////////
Expand Down
17 changes: 10 additions & 7 deletions Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,21 +440,24 @@ void plWin32StreamingSound::IActuallyStop()

unsigned plWin32StreamingSound::GetByteOffset()
{
if(fDataStream && fDSoundBuffer)
{
if (fDataStream && fDSoundBuffer)
{
uint32_t totalSize = fDataStream->GetDataSize();
uint32_t 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() - std::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;
}

Expand Down

0 comments on commit 3b20ede

Please sign in to comment.