[Bf-blender-cvs] [770b109] master: Fix: AUD_OpenALDevice::getPosition returns negative values

Jörg Müller noreply at git.blender.org
Thu Mar 26 02:49:14 CET 2015


Commit: 770b109deb6fbaea571901e56f5b9b6742483f69
Author: Jörg Müller
Date:   Thu Mar 26 14:45:21 2015 +1300
Branches: master
https://developer.blender.org/rB770b109deb6fbaea571901e56f5b9b6742483f69

Fix: AUD_OpenALDevice::getPosition returns negative values

Reported by Antony Riakiotakis. The problem was the seeking code.

===================================================================

M	intern/audaspace/OpenAL/AUD_OpenALDevice.cpp

===================================================================

diff --git a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
index d055c13..c0c77b6 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;




More information about the Bf-blender-cvs mailing list