[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21863] branches/soundsystem: Initial ( ugly) sequencer sound support.

Jörg Müller nexyon at gmail.com
Fri Jul 24 20:28:09 CEST 2009


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

Log Message:
-----------
Initial (ugly) sequencer sound support.

Modified Paths:
--------------
    branches/soundsystem/intern/audaspace/AUD_C-API.h
    branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
    branches/soundsystem/intern/audaspace/intern/AUD_BufferReader.cpp
    branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp
    branches/soundsystem/source/blender/blenkernel/BKE_sequence.h
    branches/soundsystem/source/blender/blenkernel/BKE_sound.h
    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/CMakeLists.txt
    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/SConscript
    branches/soundsystem/source/blender/editors/space_sequencer/sequencer_add.c
    branches/soundsystem/source/blender/editors/space_sequencer/sequencer_draw.c

Modified: branches/soundsystem/intern/audaspace/AUD_C-API.h
===================================================================
--- branches/soundsystem/intern/audaspace/AUD_C-API.h	2009-07-24 17:17:04 UTC (rev 21862)
+++ branches/soundsystem/intern/audaspace/AUD_C-API.h	2009-07-24 18:28:09 UTC (rev 21863)
@@ -39,6 +39,12 @@
 	AUD_OPENAL_DEVICE
 } AUD_DeviceType;
 
+typedef struct
+{
+	AUD_Specs specs;
+	float length;
+} AUD_SoundInfo;
+
 #ifndef AUD_CAPI_IMPLEMENTATION
 	typedef void AUD_Sound;
 	typedef void AUD_Handle;
@@ -66,6 +72,13 @@
 extern void AUD_exit();
 
 /**
+ * Returns information about a sound.
+ * \param sound The sound to get the info about.
+ * \return The AUD_SoundInfo structure with filled in data.
+ */
+extern AUD_SoundInfo AUD_getInfo(AUD_Sound* sound);
+
+/**
  * Loads a sound file.
  * \param filename The filename of the sound file.
  * \return A handle of the sound file.
@@ -174,11 +187,9 @@
  * Seeks a playing or paused sound.
  * \param handle The handle to the sound.
  * \param seekTo From where the sound file should be played back in seconds.
- *               A negative value indicates the seconds that should be waited
- *               before playback starts.
  * \return Whether the handle has been valid or not.
  */
-extern int AUD_seek(AUD_Handle* handle, int seekTo);
+extern int AUD_seek(AUD_Handle* handle, float seekTo);
 
 /**
  * Returns the status of a playing, paused or stopped sound.

Modified: branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
===================================================================
--- branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2009-07-24 17:17:04 UTC (rev 21862)
+++ branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2009-07-24 18:28:09 UTC (rev 21863)
@@ -61,6 +61,9 @@
 
 	/// The first buffer to be read next.
 	int current;
+
+	/// Whether the stream doesn't return any more data.
+	bool data_end;
 };
 
 struct AUD_OpenALBufferedFactory
@@ -145,7 +148,7 @@
 					while(info--)
 					{
 						// if there's still data to play back
-						if(sound->current >= 0)
+						if(!sound->data_end)
 						{
 							// read data
 							length = m_buffersize;
@@ -154,7 +157,7 @@
 							// read nothing?
 							if(length == 0)
 							{
-								sound->current = -1;
+								sound->data_end = true;
 								break;
 							}
 
@@ -164,7 +167,7 @@
 							ALenum err;
 							if((err = alGetError()) != AL_NO_ERROR)
 							{
-								sound->current = -1;
+								sound->data_end = true;
 								break;
 							}
 
@@ -177,7 +180,7 @@
 
 							if(alGetError() != AL_NO_ERROR)
 							{
-								sound->current = -1;
+								sound->data_end = true;
 								break;
 							}
 
@@ -186,7 +189,7 @@
 											&sound->buffers[sound->current]);
 							if(alGetError() != AL_NO_ERROR)
 							{
-								sound->current = -1;
+								sound->data_end = true;
 								break;
 							}
 
@@ -204,14 +207,11 @@
 			if(info == AL_STOPPED)
 			{
 				// if it really stopped
-				if(sound->current < 0)
+				if(sound->data_end)
 				{
 					// pause or
 					if(sound->keep)
-					{
-						alSourceRewind(sound->source);
 						pause(sound);
-					}
 					// stop
 					else
 						stop(sound);
@@ -332,7 +332,6 @@
 		delete sound; AUD_DELETE("handle")
 		m_playingSounds->erase(m_playingSounds->begin());
 	}
-	delete m_playingSounds; AUD_DELETE("list")
 
 	// delete all paused sounds
 	while(!m_pausedSounds->empty())
@@ -347,7 +346,6 @@
 		delete sound; AUD_DELETE("handle")
 		m_pausedSounds->erase(m_pausedSounds->begin());
 	}
-	delete m_pausedSounds; AUD_DELETE("list")
 
 	// delete all buffered factories
 	while(!m_bufferedFactories->empty())
@@ -356,11 +354,14 @@
 		delete *m_bufferedFactories->begin(); AUD_DELETE("bufferedfactory");
 		m_bufferedFactories->erase(m_bufferedFactories->begin());
 	}
-	delete m_bufferedFactories; AUD_DELETE("list")
 
 	alcProcessContext(m_context);
 	unlock();
 
+	delete m_playingSounds; AUD_DELETE("list")
+	delete m_pausedSounds; AUD_DELETE("list")
+	delete m_bufferedFactories; AUD_DELETE("list")
+
 	// wait for the thread to stop
 	if(m_thread != 0)
 		pthread_join(m_thread, NULL);
@@ -521,6 +522,7 @@
 			sound->keep = keep;
 			sound->current = -1;
 			sound->isBuffered = true;
+			sound->data_end = true;
 
 			alcSuspendContext(m_context);
 
@@ -598,6 +600,7 @@
 	sound->reader = reader;
 	sound->current = 0;
 	sound->isBuffered = false;
+	sound->data_end = false;
 
 	valid &= getFormat(sound->format, specs);
 
@@ -702,15 +705,30 @@
 
 bool AUD_OpenALDevice::resume(AUD_Handle* handle)
 {
+	ALint info;
+	lock();
+
 	// only songs that are paused can be resumed
-	lock();
 	for(AUD_HandleIterator i = m_pausedSounds->begin();
 		i != m_pausedSounds->end(); i++)
 	{
 		if(*i == handle)
 		{
 			m_playingSounds->push_back(*i);
-			alSourcePlay((*i)->source);
+
+			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();
@@ -813,8 +831,11 @@
 		if(alhandle->isBuffered)
 			alSourcef(alhandle->source, AL_SEC_OFFSET, position);
 		else
+		{
 			alhandle->reader->seek((int)(position *
 										 alhandle->reader->getSpecs().rate));
+			alhandle->data_end = false;
+		}
 		unlock();
 		return true;
 	}
@@ -1098,6 +1119,8 @@
 	alListenerfv(AL_POSITION, (ALfloat*)data.position);
 	alListenerfv(AL_VELOCITY, (ALfloat*)data.velocity);
 	alListenerfv(AL_ORIENTATION, (ALfloat*)&(data.orientation[3]));
+
+	return true;
 }
 
 bool AUD_OpenALDevice::setSetting(AUD_3DSetting setting, float value)
@@ -1162,8 +1185,6 @@
 	return std::numeric_limits<float>::quiet_NaN();
 }
 
-#include <stdio.h>
-
 bool AUD_OpenALDevice::updateSource(AUD_Handle* handle, AUD_3DData &data)
 {
 	lock();

Modified: branches/soundsystem/intern/audaspace/intern/AUD_BufferReader.cpp
===================================================================
--- branches/soundsystem/intern/audaspace/intern/AUD_BufferReader.cpp	2009-07-24 17:17:04 UTC (rev 21862)
+++ branches/soundsystem/intern/audaspace/intern/AUD_BufferReader.cpp	2009-07-24 18:28:09 UTC (rev 21863)
@@ -45,7 +45,7 @@
 	if(position < 0)
 		m_position = 0;
 	else if(position > m_buffer.get()->getSize() / AUD_SAMPLE_SIZE(m_specs))
-		position = m_buffer.get()->getSize() / AUD_SAMPLE_SIZE(m_specs);
+		m_position = m_buffer.get()->getSize() / AUD_SAMPLE_SIZE(m_specs);
 	else
 		m_position = position;
 }

Modified: branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp
===================================================================
--- branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp	2009-07-24 17:17:04 UTC (rev 21862)
+++ branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp	2009-07-24 18:28:09 UTC (rev 21863)
@@ -36,13 +36,8 @@
 #include "AUD_LoopFactory.h"
 #include "AUD_ReadDevice.h"
 #include "AUD_SourceCaps.h"
+#include "AUD_IReader.h"
 
-/*
-#define WITH_SDL
-#define WITH_OPENAL
-#define WITH_FFMPEG
-//*/
-
 #ifdef WITH_SDL
 #include "AUD_SDLDevice.h"
 #include "AUD_FloatMixer.h"
@@ -138,6 +133,30 @@
 	AUD_3ddevice = NULL;
 }
 
+AUD_SoundInfo AUD_getInfo(AUD_Sound* sound)
+{
+	assert(sound);
+
+	AUD_IReader* reader = sound->createReader();
+
+	AUD_SoundInfo info;
+
+	if(reader)
+	{
+		info.specs = reader->getSpecs();
+		info.length = reader->getLength() / (float) info.specs.rate;
+	}
+	else
+	{
+		info.specs.channels = AUD_CHANNELS_INVALID;
+		info.specs.format = AUD_FORMAT_INVALID;
+		info.specs.rate = AUD_RATE_INVALID;
+		info.length = 0.0;
+	}
+
+	return info;
+}
+
 AUD_Sound* AUD_load(const char* filename)
 {
 	assert(filename);
@@ -291,11 +310,10 @@
 	return AUD_device->setKeep(handle, keep);
 }
 
-int AUD_seek(AUD_Handle* handle, double seekTo)
+int AUD_seek(AUD_Handle* handle, float seekTo)
 {
 	assert(AUD_device);
-	int position = (int)(seekTo * AUD_device->getSpecs().rate);
-	return AUD_device->seek(handle, position);
+	return AUD_device->seek(handle, seekTo);
 }
 
 AUD_Status AUD_getStatus(AUD_Handle* handle)

Modified: branches/soundsystem/source/blender/blenkernel/BKE_sequence.h
===================================================================
--- branches/soundsystem/source/blender/blenkernel/BKE_sequence.h	2009-07-24 17:17:04 UTC (rev 21862)
+++ branches/soundsystem/source/blender/blenkernel/BKE_sequence.h	2009-07-24 18:28:09 UTC (rev 21863)
@@ -9,7 +9,7 @@
  * of the License, or (at your option) any later version. The Blender
  * Foundation also sells licenses for use in proprietary software under
  * the Blender License.  See http://www.blender.org/BL/ for information
- * about this.	
+ * about this.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -37,6 +37,7 @@
 struct StripElem;
 struct ImBuf;
 struct Scene;
+struct bContext;
 
 #define MAXSEQ          32
 
@@ -44,7 +45,6 @@
 #define BUILD_SEQAR_COUNT_CURRENT  1
 #define BUILD_SEQAR_COUNT_CHILDREN 2
 
-
 /* sequence iterator */
 
 typedef struct SeqIterator {
@@ -65,7 +65,7 @@
 	SeqIterator iter;\
 		for(seq_begin(ed, &iter, 1); iter.valid; seq_next(&iter)) { \
 			seq= iter.seq;
-			
+
 #define SEQ_BEGIN(ed, seq) \
 	{ \
 		SeqIterator iter;\
@@ -90,41 +90,41 @@
 	/* init & init_plugin are _only_ called on first creation */
 	void (*init)(struct Sequence *seq);
 	void (*init_plugin)(struct Sequence *seq, const char *fname);
-	
-	/* number of input strips needed 
+
+	/* number of input strips needed
 		(called directly after construction) */
 	int (*num_inputs)();
-	
+
 	/* load is called first time after readblenfile in
 		get_sequence_effect automatically */
 	void (*load)(struct Sequence *seq);
-	
+
 	/* duplicate */
 	void (*copy)(struct Sequence *dst, struct Sequence *src);
-	
+
 	/* destruct */
 	void (*free)(struct Sequence *seq);
-	
+
 	/* returns: -1: no input needed,
-	0: no early out, 
-	1: out = ibuf1, 
+	0: no early out,
+	1: out = ibuf1,
 	2: out = ibuf2 */
 	int (*early_out)(struct Sequence *seq,
-					 float facf0, float facf1); 
-	
+					 float facf0, float facf1);
+
 	/* stores the y-range of the effect IPO */
 	void (*store_icu_yrange)(struct Sequence * seq,
 							 short adrcode, float *ymin, float *ymax);
-	
+
 	/* stores the default facf0 and facf1 if no IPO is present */
 	void (*get_default_fac)(struct Sequence *seq, int cfra,
 							float * facf0, float * facf1);
-	
+
 	/* execute the effect
 		sequence effects are only required to either support

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list