Fix: AUD_OpenALDevice::getPosition returns negative values

Reported by Antony Riakiotakis. The problem was the seeking code.
This commit is contained in:
Jörg Müller 2015-03-26 14:45:21 +13:00
parent 92f305a490
commit 770b109deb

@ -276,9 +276,9 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::seek(float position)
alGetSourcei(m_source, AL_SOURCE_STATE, &info);
if(info != AL_PLAYING)
{
if(info == AL_PAUSED)
// we need to stop playing sounds as well to clear the buffers
// this might cause clicks, but fixes a bug regarding position determination
if(info == AL_PAUSED || info == AL_PLAYING)
alSourceStop(m_source);
alSourcei(m_source, AL_BUFFER, 0);
@ -319,7 +319,6 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::seek(float position)
alSourceRewind(m_source);
}
}
if(m_status == AUD_STATUS_STOPPED)
m_status = AUD_STATUS_PAUSED;
@ -343,9 +342,14 @@ float AUD_OpenALDevice::AUD_OpenALHandle::getPosition()
if(!m_isBuffered)
{
int queued;
// this usually always returns CYCLE_BUFFERS
alGetSourcei(m_source, AL_BUFFERS_QUEUED, &queued);
AUD_Specs specs = m_reader->getSpecs();
position += (m_reader->getPosition() - m_device->m_buffersize *
CYCLE_BUFFERS) / (float)specs.rate;
queued) / (float)specs.rate;
}
return position;