[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30991] branches/soc-2010-nexyon: Audaspace:

Joerg Mueller nexyon at gmail.com
Mon Aug 2 20:22:34 CEST 2010


Revision: 30991
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30991
Author:   nexyon
Date:     2010-08-02 20:22:34 +0200 (Mon, 02 Aug 2010)

Log Message:
-----------
Audaspace:
* Added a stopCallback function that is called when the end of a sound is reached.
* Fixed the scrubbing not working.
* Minor SoundActuator cleanup.

Modified Paths:
--------------
    branches/soc-2010-nexyon/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
    branches/soc-2010-nexyon/intern/audaspace/OpenAL/AUD_OpenALDevice.h
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.cpp
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.h
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_IDevice.h
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_NULLDevice.cpp
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_NULLDevice.h
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SoftwareDevice.cpp
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SoftwareDevice.h
    branches/soc-2010-nexyon/source/blender/blenkernel/intern/sound.c
    branches/soc-2010-nexyon/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2010-nexyon/source/gameengine/Ketsji/KX_SoundActuator.h

Added Paths:
-----------
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SilenceFactory.cpp
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SilenceFactory.h
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SilenceReader.cpp
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SilenceReader.h

Modified: branches/soc-2010-nexyon/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2010-08-02 17:50:43 UTC (rev 30990)
+++ branches/soc-2010-nexyon/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2010-08-02 18:22:34 UTC (rev 30991)
@@ -68,6 +68,12 @@
 
 	/// The loop count of the source.
 	int loopcount;
+
+	/// The stop callback.
+	stopCallback stop;
+
+	/// Stop callback data.
+	void* stop_data;
 };
 
 struct AUD_OpenALBufferedFactory
@@ -131,13 +137,9 @@
 
 		{
 			// for all sounds
-			AUD_HandleIterator it = m_playingSounds->begin();
-			while(it != m_playingSounds->end())
+			for(AUD_HandleIterator it = m_playingSounds->begin(); it != m_playingSounds->end(); it++)
 			{
 				sound = *it;
-				// increment the iterator to make sure it's valid,
-				// in case the sound gets deleted after stopping
-				++it;
 
 				// is it a streamed sound?
 				if(!sound->isBuffered)
@@ -227,12 +229,21 @@
 					// if it really stopped
 					if(sound->data_end)
 					{
+						if(sound->stop)
+							sound->stop(sound->stop_data);
+
+						// increment the iterator to the next value,
+						// because the sound gets deleted in the list here.
+						++it;
 						// pause or
 						if(sound->keep)
 							pause(sound);
 						// stop
 						else
 							stop(sound);
+						// decrement again, so that we get the next sound in the
+						// next loop run
+						--it;
 					}
 					// continue playing
 					else
@@ -1012,6 +1023,20 @@
 	return result;
 }
 
+bool AUD_OpenALDevice::setStopCallback(AUD_Handle* handle, stopCallback callback, void* data)
+{
+	lock();
+	bool result = isValid(handle);
+	if(result)
+	{
+		AUD_OpenALHandle* h = (AUD_OpenALHandle*)handle;
+		h->stop = callback;
+		h->stop_data = data;
+	}
+	unlock();
+	return result;
+}
+
 /* AUD_XXX Temorary disabled
 
 bool AUD_OpenALDevice::bufferFactory(void *value)

Modified: branches/soc-2010-nexyon/intern/audaspace/OpenAL/AUD_OpenALDevice.h
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/OpenAL/AUD_OpenALDevice.h	2010-08-02 17:50:43 UTC (rev 30990)
+++ branches/soc-2010-nexyon/intern/audaspace/OpenAL/AUD_OpenALDevice.h	2010-08-02 18:22:34 UTC (rev 30991)
@@ -160,6 +160,7 @@
 	virtual bool setPitch(AUD_Handle* handle, float pitch);
 	virtual int getLoopCount(AUD_Handle* handle);
 	virtual bool setLoopCount(AUD_Handle* handle, int count);
+	virtual bool setStopCallback(AUD_Handle* handle, stopCallback callback = NULL, void* data = NULL);
 
 	virtual AUD_Vector3 getListenerLocation() const;
 	virtual void setListenerLocation(const AUD_Vector3& location);

Modified: branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.cpp
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.cpp	2010-08-02 17:50:43 UTC (rev 30990)
+++ branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.cpp	2010-08-02 18:22:34 UTC (rev 30991)
@@ -60,6 +60,7 @@
 #include "AUD_ReadDevice.h"
 #include "AUD_IReader.h"
 #include "AUD_SequencerFactory.h"
+#include "AUD_SilenceFactory.h"
 
 #ifdef WITH_SDL
 #include "AUD_SDLDevice.h"
@@ -845,6 +846,32 @@
 	return result;
 }
 
+static void pauseSound(AUD_Channel* handle)
+{
+	assert(AUD_device);
+
+	AUD_device->pause(handle);
+}
+
+AUD_Channel* AUD_pauseAfter(AUD_Channel* handle, float seconds)
+{
+	assert(AUD_device);
+
+	AUD_SilenceFactory silence;
+	AUD_LimiterFactory limiter(&silence, 0, seconds);
+
+	try
+	{
+		AUD_Channel* channel = AUD_device->play(&limiter);
+		AUD_device->setStopCallback(channel, (stopCallback)pauseSound, handle);
+		return channel;
+	}
+	catch(AUD_Exception&)
+	{
+		return NULL;
+	}
+}
+
 AUD_Sound* AUD_createSequencer(void* data, AUD_volumeFunction volume)
 {
 /* AUD_XXX should be this: but AUD_createSequencer is called before the device

Modified: branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.h
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.h	2010-08-02 17:50:43 UTC (rev 30990)
+++ branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.h	2010-08-02 18:22:34 UTC (rev 30991)
@@ -463,6 +463,14 @@
 								  float sthreshold, int samplerate,
 								  int* length);
 
+/**
+ * Pauses a playing sound after a specific amount of time.
+ * \param handle The handle to the sound.
+ * \param time The time in seconds.
+ * \return The silence handle.
+ */
+extern AUD_Channel* AUD_pauseAfter(AUD_Channel* handle, float seconds);
+
 extern AUD_Sound* AUD_createSequencer(void* data, AUD_volumeFunction volume);
 
 extern void AUD_destroySequencer(AUD_Sound* sequencer);

Modified: branches/soc-2010-nexyon/intern/audaspace/intern/AUD_IDevice.h
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/intern/AUD_IDevice.h	2010-08-02 17:50:43 UTC (rev 30990)
+++ branches/soc-2010-nexyon/intern/audaspace/intern/AUD_IDevice.h	2010-08-02 18:22:34 UTC (rev 30991)
@@ -34,6 +34,8 @@
 {
 };
 
+typedef void (*stopCallback)(void*);
+
 /**
  * This class represents an output device for sound sources.
  * Output devices may be several backends such as plattform independand like
@@ -225,6 +227,18 @@
 	 *        - false if the handle is invalid.
 	 */
 	virtual bool setLoopCount(AUD_Handle* handle, int count)=0;
+
+	/**
+	 * Sets the callback function that's called when the end of a playing sound
+	 * is reached.
+	 * \param handle The sound handle.
+	 * \param callback The callback function.
+	 * \param data The data that should be passed to the callback function.
+	 * \return
+	 *        - true if the handle is valid.
+	 *        - false if the handle is invalid.
+	 */
+	virtual bool setStopCallback(AUD_Handle* handle, stopCallback callback = 0, void* data = 0)=0;
 };
 
 #endif //AUD_IDevice

Modified: branches/soc-2010-nexyon/intern/audaspace/intern/AUD_NULLDevice.cpp
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/intern/AUD_NULLDevice.cpp	2010-08-02 17:50:43 UTC (rev 30990)
+++ branches/soc-2010-nexyon/intern/audaspace/intern/AUD_NULLDevice.cpp	2010-08-02 18:22:34 UTC (rev 30991)
@@ -133,3 +133,8 @@
 {
 	return false;
 }
+
+bool AUD_NULLDevice::setStopCallback(AUD_Handle* handle, stopCallback callback, void* data)
+{
+	return false;
+}

Modified: branches/soc-2010-nexyon/intern/audaspace/intern/AUD_NULLDevice.h
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/intern/AUD_NULLDevice.h	2010-08-02 17:50:43 UTC (rev 30990)
+++ branches/soc-2010-nexyon/intern/audaspace/intern/AUD_NULLDevice.h	2010-08-02 18:22:34 UTC (rev 30991)
@@ -59,6 +59,7 @@
 	virtual bool setPitch(AUD_Handle* handle, float pitch);
 	virtual int getLoopCount(AUD_Handle* handle);
 	virtual bool setLoopCount(AUD_Handle* handle, int count);
+	virtual bool setStopCallback(AUD_Handle* handle, stopCallback callback = 0, void* data = 0);
 };
 
 #endif //AUD_NULLDEVICE

Copied: branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SilenceFactory.cpp (from rev 30970, branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SinusFactory.cpp)
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SilenceFactory.cpp	                        (rev 0)
+++ branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SilenceFactory.cpp	2010-08-02 18:22:34 UTC (rev 30991)
@@ -0,0 +1,37 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN LGPL LICENSE BLOCK *****
+ *
+ * Copyright 2009 Jörg Hermann Müller
+ *
+ * This file is part of AudaSpace.
+ *
+ * AudaSpace is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * AudaSpace is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with AudaSpace.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * ***** END LGPL LICENSE BLOCK *****
+ */
+
+#include "AUD_SilenceFactory.h"
+#include "AUD_SilenceReader.h"
+#include "AUD_Space.h"
+
+AUD_SilenceFactory::AUD_SilenceFactory()
+{
+}
+
+AUD_IReader* AUD_SilenceFactory::createReader() const
+{
+	return new AUD_SilenceReader();
+}

Copied: branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SilenceFactory.h (from rev 30970, branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SinusFactory.h)
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SilenceFactory.h	                        (rev 0)
+++ branches/soc-2010-nexyon/intern/audaspace/intern/AUD_SilenceFactory.h	2010-08-02 18:22:34 UTC (rev 30991)
@@ -0,0 +1,50 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN LGPL LICENSE BLOCK *****
+ *
+ * Copyright 2009 Jörg Hermann Müller
+ *
+ * This file is part of AudaSpace.
+ *
+ * AudaSpace is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * AudaSpace is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with AudaSpace.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * ***** END LGPL LICENSE BLOCK *****
+ */
+
+#ifndef AUD_SILENCEFACTORY
+#define AUD_SILENCEFACTORY
+
+#include "AUD_IFactory.h"
+
+/**
+ * This factory creates a reader that plays a sine tone.
+ */
+class AUD_SilenceFactory : public AUD_IFactory
+{
+private:
+	// hide copy constructor and operator=
+	AUD_SilenceFactory(const AUD_SilenceFactory&);
+	AUD_SilenceFactory& operator=(const AUD_SilenceFactory&);
+
+public:
+	/**
+	 * Creates a new silence factory.
+	 */
+	AUD_SilenceFactory();
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list