[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21987] branches/soundsystem: Sound Branch

Jörg Müller nexyon at gmail.com
Tue Jul 28 20:42:26 CEST 2009


Revision: 21987
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21987
Author:   nexyon
Date:     2009-07-28 20:42:26 +0200 (Tue, 28 Jul 2009)

Log Message:
-----------
Sound Branch

Sequencer audio update, still not perfect, but improving.

Modified Paths:
--------------
    branches/soundsystem/CMakeLists.txt
    branches/soundsystem/intern/audaspace/AUD_C-API.h
    branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
    branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.h
    branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp
    branches/soundsystem/intern/audaspace/intern/AUD_IDevice.h
    branches/soundsystem/intern/audaspace/intern/AUD_NULLDevice.cpp
    branches/soundsystem/intern/audaspace/intern/AUD_NULLDevice.h
    branches/soundsystem/intern/audaspace/intern/AUD_SoftwareDevice.cpp
    branches/soundsystem/intern/audaspace/intern/AUD_SoftwareDevice.h
    branches/soundsystem/source/blender/blenkernel/BKE_sequence.h
    branches/soundsystem/source/blender/blenkernel/BKE_sound.h
    branches/soundsystem/source/blender/blenkernel/intern/library.c
    branches/soundsystem/source/blender/blenkernel/intern/packedFile.c
    branches/soundsystem/source/blender/blenkernel/intern/scene.c
    branches/soundsystem/source/blender/blenkernel/intern/sequence.c
    branches/soundsystem/source/blender/blenkernel/intern/sound.c
    branches/soundsystem/source/blender/blenloader/intern/readfile.c
    branches/soundsystem/source/blender/editors/animation/anim_ops.c
    branches/soundsystem/source/blender/editors/screen/screen_ops.c
    branches/soundsystem/source/blender/editors/space_sequencer/sequencer_add.c
    branches/soundsystem/source/blender/editors/space_sequencer/sequencer_edit.c
    branches/soundsystem/source/blender/makesdna/DNA_scene_types.h
    branches/soundsystem/source/blender/makesdna/DNA_sequence_types.h
    branches/soundsystem/source/blender/makesdna/DNA_sound_types.h
    branches/soundsystem/source/blender/windowmanager/intern/wm_init_exit.c

Modified: branches/soundsystem/CMakeLists.txt
===================================================================
--- branches/soundsystem/CMakeLists.txt	2009-07-28 18:25:02 UTC (rev 21986)
+++ branches/soundsystem/CMakeLists.txt	2009-07-28 18:42:26 UTC (rev 21987)
@@ -63,11 +63,10 @@
 OPTION(WITH_DDS			"Enable DDS Support"                                   	ON)
 OPTION(WITH_FFMPEG		"Enable FFMPeg Support(http://ffmpeg.mplayerhq.hu/)"	ON)
 OPTION(WITH_PYTHON		"Enable Embedded Python API"				ON)
-OPTION(WITH_SDL			"Enable SDL for sound and joystick support"				ON)
+OPTION(WITH_SDL			"Enable SDL for sound and joystick support"		ON)
 OPTION(WITH_OPENJPEG		"Enable OpenJpeg Support (http://www.openjpeg.org/)"	OFF)
 OPTION(WITH_OPENAL		"Enable OpenAL Support (http://www.openal.org)"		ON)
 OPTION(WITH_OPENMP		"Enable OpenMP (has to be supported by the compiler)"	OFF)
-OPTION(WITH_SDL		"Enable SDL Support(http://www.libsdl.org/)"	ON)
 OPTION(WITH_WEBPLUGIN		"Enable Web Plugin (Unix only)"				OFF)
 
 IF(NOT WITH_GAMEENGINE AND WITH_PLAYER)

Modified: branches/soundsystem/intern/audaspace/AUD_C-API.h
===================================================================
--- branches/soundsystem/intern/audaspace/AUD_C-API.h	2009-07-28 18:25:02 UTC (rev 21986)
+++ branches/soundsystem/intern/audaspace/AUD_C-API.h	2009-07-28 18:42:26 UTC (rev 21987)
@@ -72,6 +72,16 @@
 extern void AUD_exit();
 
 /**
+ * Locks the playback device.
+ */
+extern void AUD_lock();
+
+/**
+ * Unlocks the device.
+ */
+extern void AUD_unlock();
+
+/**
  * Returns information about a sound.
  * \param sound The sound to get the info about.
  * \return The AUD_SoundInfo structure with filled in data.
@@ -192,6 +202,13 @@
 extern int AUD_seek(AUD_Handle* handle, float seekTo);
 
 /**
+ * Retrieves the playback position of a handle.
+ * \return The current playback position in seconds or 0.0 if the handle is
+ *         invalid.
+ */
+extern float AUD_getPosition(AUD_Handle* handle);
+
+/**
  * Returns the status of a playing, paused or stopped sound.
  * \param handle The handle to the sound.
  * \return The status of the sound behind the handle.

Modified: branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
===================================================================
--- branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2009-07-28 18:25:02 UTC (rev 21986)
+++ branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2009-07-28 18:42:26 UTC (rev 21987)
@@ -204,7 +204,7 @@
 			// check if the sound has been stopped
 			alGetSourcei(sound->source, AL_SOURCE_STATE, &info);
 
-			if(info == AL_STOPPED)
+			if(info != AL_PLAYING)
 			{
 				// if it really stopped
 				if(sound->data_end)
@@ -538,11 +538,6 @@
 					alSourcei(sound->source, AL_BUFFER, (*i)->buffer);
 					if(alGetError() != AL_NO_ERROR)
 						AUD_THROW(AUD_ERROR_OPENAL);
-
-					alSourcePlay(sound->source);
-
-					if(alGetError() != AL_NO_ERROR)
-						AUD_THROW(AUD_ERROR_OPENAL);
 				}
 				catch(AUD_Exception e)
 				{
@@ -645,11 +640,6 @@
 				alSourceQueueBuffers(sound->source, 3, sound->buffers);
 				if(alGetError() != AL_NO_ERROR)
 					AUD_THROW(AUD_ERROR_OPENAL);
-
-				alSourcePlay(sound->source);
-
-				if(alGetError() != AL_NO_ERROR)
-					AUD_THROW(AUD_ERROR_OPENAL);
 			}
 			catch(AUD_Exception e)
 			{
@@ -715,20 +705,6 @@
 		if(*i == handle)
 		{
 			m_playingSounds->push_back(*i);
-
-			alGetSourcei((*i)->source, AL_SOURCE_STATE, &info);
-
-			switch(info)
-			{
-			case AL_PLAYING:
-				break;
-			case AL_STOPPED:
-//				alSourceRewind((*i)->source);
-			default:
-//				alSourcePlay((*i)->source);
-				break;
-			}
-
 			start();
 			m_pausedSounds->erase(i);
 			unlock();
@@ -835,6 +811,41 @@
 			alhandle->reader->seek((int)(position *
 										 alhandle->reader->getSpecs().rate));
 			alhandle->data_end = false;
+
+			ALint info;
+
+			alGetSourcei(alhandle->source, AL_SOURCE_STATE, &info);
+
+			if(info != AL_PLAYING)
+			{
+				if(info != AL_STOPPED)
+					alSourceStop(alhandle->source);
+
+				alSourceUnqueueBuffers(alhandle->source, 3, alhandle->buffers);
+				if(alGetError() == AL_NO_ERROR)
+				{
+					sample_t* buf;
+					int length;
+					AUD_Specs specs = alhandle->reader->getSpecs();
+
+					for(int i=0; i<3; i++)
+					{
+						length = m_buffersize;
+						alhandle->reader->read(length, buf);
+						alBufferData(alhandle->buffers[i], alhandle->format,
+									 buf, length * AUD_SAMPLE_SIZE(specs),
+									 specs.rate);
+
+						if(alGetError() != AL_NO_ERROR)
+							break;
+					}
+
+					alSourceQueueBuffers(alhandle->source, 3,
+										 alhandle->buffers);
+				}
+
+				alSourceRewind(alhandle->source);
+			}
 		}
 		unlock();
 		return true;
@@ -844,6 +855,26 @@
 	return false;
 }
 
+float AUD_OpenALDevice::getPosition(AUD_Handle* handle)
+{
+	lock();
+
+	float position = 0.0;
+
+	if(isValid(handle))
+	{
+		AUD_OpenALHandle* h = (AUD_OpenALHandle*)handle;
+		if(h->isBuffered)
+			alGetSourcef(h->source, AL_SEC_OFFSET, &position);
+		else
+			position = h->reader->getPosition() /
+					   (float)h->reader->getSpecs().rate;
+	}
+
+	unlock();
+	return position;
+}
+
 AUD_Status AUD_OpenALDevice::getStatus(AUD_Handle* handle)
 {
 	lock();

Modified: branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.h
===================================================================
--- branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.h	2009-07-28 18:25:02 UTC (rev 21986)
+++ branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.h	2009-07-28 18:42:26 UTC (rev 21987)
@@ -149,6 +149,7 @@
 	virtual bool setKeep(AUD_Handle* handle, bool keep);
 	virtual bool sendMessage(AUD_Handle* handle, AUD_Message &message);
 	virtual bool seek(AUD_Handle* handle, float position);
+	virtual float getPosition(AUD_Handle* handle);
 	virtual AUD_Status getStatus(AUD_Handle* handle);
 	virtual void lock();
 	virtual void unlock();

Modified: branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp
===================================================================
--- branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp	2009-07-28 18:25:02 UTC (rev 21986)
+++ branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp	2009-07-28 18:42:26 UTC (rev 21987)
@@ -133,6 +133,18 @@
 	AUD_3ddevice = NULL;
 }
 
+void AUD_lock()
+{
+	assert(AUD_device);
+	AUD_device->lock();
+}
+
+void AUD_unlock()
+{
+	assert(AUD_device);
+	AUD_device->unlock();
+}
+
 AUD_SoundInfo AUD_getInfo(AUD_Sound* sound)
 {
 	assert(sound);
@@ -300,8 +312,9 @@
 
 int AUD_stop(AUD_Handle* handle)
 {
-	assert(AUD_device);
-	return AUD_device->stop(handle);
+	if(AUD_device)
+		return AUD_device->stop(handle);
+	return false;
 }
 
 int AUD_setKeep(AUD_Handle* handle, int keep)
@@ -316,6 +329,12 @@
 	return AUD_device->seek(handle, seekTo);
 }
 
+float AUD_getPosition(AUD_Handle* handle)
+{
+	assert(AUD_device);
+	return AUD_device->getPosition(handle);
+}
+
 AUD_Status AUD_getStatus(AUD_Handle* handle)
 {
 	assert(AUD_device);

Modified: branches/soundsystem/intern/audaspace/intern/AUD_IDevice.h
===================================================================
--- branches/soundsystem/intern/audaspace/intern/AUD_IDevice.h	2009-07-28 18:25:02 UTC (rev 21986)
+++ branches/soundsystem/intern/audaspace/intern/AUD_IDevice.h	2009-07-28 18:42:26 UTC (rev 21987)
@@ -127,6 +127,14 @@
 	virtual bool seek(AUD_Handle* handle, float position)=0;
 
 	/**
+	 * Retrieves the current playback position of a sound.
+	 * \param handle The handle returned by the play function.
+	 * \return The playback position in seconds, or 0.0 if the handle is
+	 *         invalid.
+	 */
+	virtual float getPosition(AUD_Handle* handle)=0;
+
+	/**
 	 * Returns the status of a played back sound.
 	 * \param handle The handle returned by the play function.
 	 * \return

Modified: branches/soundsystem/intern/audaspace/intern/AUD_NULLDevice.cpp
===================================================================
--- branches/soundsystem/intern/audaspace/intern/AUD_NULLDevice.cpp	2009-07-28 18:25:02 UTC (rev 21986)
+++ branches/soundsystem/intern/audaspace/intern/AUD_NULLDevice.cpp	2009-07-28 18:42:26 UTC (rev 21987)
@@ -74,6 +74,11 @@
 	return false;
 }
 
+float AUD_NULLDevice::getPosition(AUD_Handle* handle)
+{
+	return 0.0f;
+}
+
 AUD_Status AUD_NULLDevice::getStatus(AUD_Handle* handle)
 {
 	return AUD_STATUS_INVALID;

Modified: branches/soundsystem/intern/audaspace/intern/AUD_NULLDevice.h
===================================================================
--- branches/soundsystem/intern/audaspace/intern/AUD_NULLDevice.h	2009-07-28 18:25:02 UTC (rev 21986)
+++ branches/soundsystem/intern/audaspace/intern/AUD_NULLDevice.h	2009-07-28 18:42:26 UTC (rev 21987)
@@ -53,6 +53,7 @@
 	virtual bool setKeep(AUD_Handle* handle, bool keep);
 	virtual bool sendMessage(AUD_Handle* handle, AUD_Message &message);
 	virtual bool seek(AUD_Handle* handle, float position);
+	virtual float getPosition(AUD_Handle* handle);
 	virtual AUD_Status getStatus(AUD_Handle* handle);
 	virtual void lock();
 	virtual void unlock();

Modified: branches/soundsystem/intern/audaspace/intern/AUD_SoftwareDevice.cpp
===================================================================
--- branches/soundsystem/intern/audaspace/intern/AUD_SoftwareDevice.cpp	2009-07-28 18:25:02 UTC (rev 21986)
+++ branches/soundsystem/intern/audaspace/intern/AUD_SoftwareDevice.cpp	2009-07-28 18:42:26 UTC (rev 21987)
@@ -324,6 +324,22 @@
 	return false;
 }
 
+float AUD_SoftwareDevice::getPosition(AUD_Handle* handle)
+{
+	lock();
+
+	float position = 0.0f;
+
+	if(isValid(handle))
+	{
+		AUD_SoftwareHandle* h = (AUD_SoftwareHandle*)handle;
+		position = h->reader->getPosition() / (float)m_specs.rate;
+	}
+
+	unlock();
+	return position;
+}
+
 AUD_Status AUD_SoftwareDevice::getStatus(AUD_Handle* handle)
 {
 	lock();

Modified: branches/soundsystem/intern/audaspace/intern/AUD_SoftwareDevice.h
===================================================================
--- branches/soundsystem/intern/audaspace/intern/AUD_SoftwareDevice.h	2009-07-28 18:25:02 UTC (rev 21986)
+++ branches/soundsystem/intern/audaspace/intern/AUD_SoftwareDevice.h	2009-07-28 18:42:26 UTC (rev 21987)
@@ -125,6 +125,7 @@
 	virtual bool setKeep(AUD_Handle* handle, bool keep);
 	virtual bool sendMessage(AUD_Handle* handle, AUD_Message &message);
 	virtual bool seek(AUD_Handle* handle, float position);
+	virtual float getPosition(AUD_Handle* handle);
 	virtual AUD_Status getStatus(AUD_Handle* handle);
 	virtual void lock();

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list