diff options
author | Jörg Müller <nexyon@gmail.com> | 2015-03-26 04:45:21 +0300 |
---|---|---|
committer | Jörg Müller <nexyon@gmail.com> | 2015-03-26 04:45:21 +0300 |
commit | 770b109deb6fbaea571901e56f5b9b6742483f69 (patch) | |
tree | 76e189b0187af60665e41635d7bde5cca8f511f9 /intern/audaspace | |
parent | 92f305a490802812091da4640df552d77f168844 (diff) |
Fix: AUD_OpenALDevice::getPosition returns negative values
Reported by Antony Riakiotakis. The problem was the seeking code.
Diffstat (limited to 'intern/audaspace')
-rw-r--r-- | intern/audaspace/OpenAL/AUD_OpenALDevice.cpp | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp index d055c131183..c0c77b6f917 100644 --- a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp +++ b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp @@ -276,49 +276,48 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::seek(float position) alGetSourcei(m_source, AL_SOURCE_STATE, &info); - if(info != AL_PLAYING) - { - if(info == AL_PAUSED) - alSourceStop(m_source); + // 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; - alSourcei(m_source, AL_BUFFER, 0); - m_current = 0; + ALenum err; + if((err = alGetError()) == AL_NO_ERROR) + { + 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)); - 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; |