Fix: AUD_OpenALDevice::getPosition returns negative values

Reported by Antony Riakiotakis. The problem was the seeking code.
This commit is contained in:
Joerg Mueller 2015-03-26 14:45:21 +13:00
parent 92f305a490
commit 770b109deb
Notes: blender-bot 2023-02-14 09:19:08 +01:00
Referenced by issue #44149, Compositing : Node Groups do not work correctly
1 changed files with 37 additions and 33 deletions

View File

@ -276,49 +276,48 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::seek(float position)
alGetSourcei(m_source, AL_SOURCE_STATE, &info);
if(info != AL_PLAYING)
// 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);
m_current = 0;
ALenum err;
if((err = alGetError()) == AL_NO_ERROR)
{
if(info == AL_PAUSED)
alSourceStop(m_source);
int length;
AUD_DeviceSpecs specs = m_device->m_specs;
specs.specs = m_reader->getSpecs();
m_device->m_buffer.assureSize(m_device->m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
alSourcei(m_source, AL_BUFFER, 0);
m_current = 0;
ALenum err;
if((err = alGetError()) == AL_NO_ERROR)
for(int i = 0; i < CYCLE_BUFFERS; i++)
{
int length;
AUD_DeviceSpecs specs = m_device->m_specs;
specs.specs = m_reader->getSpecs();
m_device->m_buffer.assureSize(m_device->m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
length = m_device->m_buffersize;
m_reader->read(length, m_eos, m_device->m_buffer.getBuffer());
for(int i = 0; i < CYCLE_BUFFERS; i++)
if(length == 0)
{
length = m_device->m_buffersize;
m_reader->read(length, m_eos, m_device->m_buffer.getBuffer());
if(length == 0)
{
// AUD_XXX: TODO: don't fill all buffers and enqueue them later
length = 1;
memset(m_device->m_buffer.getBuffer(), 0, length * AUD_DEVICE_SAMPLE_SIZE(specs));
}
alBufferData(m_buffers[i], m_format, m_device->m_buffer.getBuffer(),
length * AUD_DEVICE_SAMPLE_SIZE(specs), specs.rate);
if(alGetError() != AL_NO_ERROR)
break;
// AUD_XXX: TODO: don't fill all buffers and enqueue them later
length = 1;
memset(m_device->m_buffer.getBuffer(), 0, length * AUD_DEVICE_SAMPLE_SIZE(specs));
}
if(m_loopcount != 0)
m_eos = false;
alBufferData(m_buffers[i], m_format, m_device->m_buffer.getBuffer(),
length * AUD_DEVICE_SAMPLE_SIZE(specs), specs.rate);
alSourceQueueBuffers(m_source, CYCLE_BUFFERS, m_buffers);
if(alGetError() != AL_NO_ERROR)
break;
}
alSourceRewind(m_source);
if(m_loopcount != 0)
m_eos = false;
alSourceQueueBuffers(m_source, CYCLE_BUFFERS, m_buffers);
}
alSourceRewind(m_source);
}
if(m_status == AUD_STATUS_STOPPED)
@ -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;