[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34982] trunk/blender/intern/audaspace: Audaspace:
Joerg Mueller
nexyon at gmail.com
Sat Feb 19 00:50:27 CET 2011
Revision: 34982
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34982
Author: nexyon
Date: 2011-02-18 23:50:27 +0000 (Fri, 18 Feb 2011)
Log Message:
-----------
Audaspace:
* Adding play method to the device classes to play back a reader (not used yet, preparation for a later feature).
* Using a linear resampler in case SRC is disabled.
Modified Paths:
--------------
trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.h
trunk/blender/intern/audaspace/intern/AUD_DefaultMixer.cpp
trunk/blender/intern/audaspace/intern/AUD_IDevice.h
trunk/blender/intern/audaspace/intern/AUD_NULLDevice.cpp
trunk/blender/intern/audaspace/intern/AUD_NULLDevice.h
trunk/blender/intern/audaspace/intern/AUD_SoftwareDevice.cpp
trunk/blender/intern/audaspace/intern/AUD_SoftwareDevice.h
Modified: trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
===================================================================
--- trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp 2011-02-18 23:47:37 UTC (rev 34981)
+++ trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp 2011-02-18 23:50:27 UTC (rev 34982)
@@ -534,81 +534,10 @@
static const char* bufferdata_error = "AUD_OpenALDevice: Buffer couldn't be "
"filled with data.";
-AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
+AUD_Handle* AUD_OpenALDevice::play(AUD_IReader* reader, bool keep)
{
- lock();
-
AUD_OpenALHandle* sound = NULL;
- try
- {
- // check if it is a buffered factory
- for(AUD_BFIterator i = m_bufferedFactories->begin();
- i != m_bufferedFactories->end(); i++)
- {
- if((*i)->factory == factory)
- {
- // create the handle
- sound = new AUD_OpenALHandle;
- sound->keep = keep;
- sound->current = -1;
- sound->isBuffered = true;
- sound->data_end = true;
- sound->loopcount = 0;
- sound->stop = NULL;
- sound->stop_data = NULL;
-
- alcSuspendContext(m_context);
-
- // OpenAL playback code
- try
- {
- alGenSources(1, &sound->source);
- if(alGetError() != AL_NO_ERROR)
- AUD_THROW(AUD_ERROR_OPENAL, gensource_error);
-
- try
- {
- alSourcei(sound->source, AL_BUFFER, (*i)->buffer);
- if(alGetError() != AL_NO_ERROR)
- AUD_THROW(AUD_ERROR_OPENAL, queue_error);
- }
- catch(AUD_Exception&)
- {
- alDeleteSources(1, &sound->source);
- throw;
- }
- }
- catch(AUD_Exception&)
- {
- delete sound;
- alcProcessContext(m_context);
- throw;
- }
-
- // play sound
- m_playingSounds->push_back(sound);
-
- alSourcei(sound->source, AL_SOURCE_RELATIVE, 1);
- start();
-
- alcProcessContext(m_context);
- }
- }
- }
- catch(AUD_Exception&)
- {
- unlock();
- throw;
- }
-
- unlock();
-
- if(sound)
- return sound;
-
- AUD_IReader* reader = factory->createReader();
-
AUD_DeviceSpecs specs = m_specs;
specs.specs = reader->getSpecs();
@@ -708,6 +637,82 @@
return sound;
}
+AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
+{
+ AUD_OpenALHandle* sound = NULL;
+
+ lock();
+
+ try
+ {
+ // check if it is a buffered factory
+ for(AUD_BFIterator i = m_bufferedFactories->begin();
+ i != m_bufferedFactories->end(); i++)
+ {
+ if((*i)->factory == factory)
+ {
+ // create the handle
+ sound = new AUD_OpenALHandle;
+ sound->keep = keep;
+ sound->current = -1;
+ sound->isBuffered = true;
+ sound->data_end = true;
+ sound->loopcount = 0;
+ sound->stop = NULL;
+ sound->stop_data = NULL;
+
+ alcSuspendContext(m_context);
+
+ // OpenAL playback code
+ try
+ {
+ alGenSources(1, &sound->source);
+ if(alGetError() != AL_NO_ERROR)
+ AUD_THROW(AUD_ERROR_OPENAL, gensource_error);
+
+ try
+ {
+ alSourcei(sound->source, AL_BUFFER, (*i)->buffer);
+ if(alGetError() != AL_NO_ERROR)
+ AUD_THROW(AUD_ERROR_OPENAL, queue_error);
+ }
+ catch(AUD_Exception&)
+ {
+ alDeleteSources(1, &sound->source);
+ throw;
+ }
+ }
+ catch(AUD_Exception&)
+ {
+ delete sound;
+ alcProcessContext(m_context);
+ throw;
+ }
+
+ // play sound
+ m_playingSounds->push_back(sound);
+
+ alSourcei(sound->source, AL_SOURCE_RELATIVE, 1);
+ start();
+
+ alcProcessContext(m_context);
+ }
+ }
+ }
+ catch(AUD_Exception&)
+ {
+ unlock();
+ throw;
+ }
+
+ unlock();
+
+ if(sound)
+ return sound;
+
+ return play(factory->createReader(), keep);
+}
+
bool AUD_OpenALDevice::pause(AUD_Handle* handle)
{
bool result = false;
Modified: trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.h
===================================================================
--- trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.h 2011-02-18 23:47:37 UTC (rev 34981)
+++ trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.h 2011-02-18 23:50:27 UTC (rev 34982)
@@ -142,6 +142,7 @@
virtual ~AUD_OpenALDevice();
virtual AUD_DeviceSpecs getSpecs() const;
+ virtual AUD_Handle* play(AUD_IReader* reader, bool keep = false);
virtual AUD_Handle* play(AUD_IFactory* factory, bool keep = false);
virtual bool pause(AUD_Handle* handle);
virtual bool resume(AUD_Handle* handle);
Modified: trunk/blender/intern/audaspace/intern/AUD_DefaultMixer.cpp
===================================================================
--- trunk/blender/intern/audaspace/intern/AUD_DefaultMixer.cpp 2011-02-18 23:47:37 UTC (rev 34981)
+++ trunk/blender/intern/audaspace/intern/AUD_DefaultMixer.cpp 2011-02-18 23:50:27 UTC (rev 34982)
@@ -27,6 +27,8 @@
#include "AUD_DefaultMixer.h"
#ifdef WITH_SAMPLERATE
#include "AUD_SRCResampleReader.h"
+#else
+#include "AUD_LinearResampleReader.h"
#endif
#include "AUD_ChannelMapperReader.h"
#include "AUD_ChannelMapperFactory.h"
@@ -53,10 +55,12 @@
specs.channels = m_specs.channels;
}
-#ifdef WITH_SAMPLERATE
// resample
if(specs.rate != m_specs.rate)
+#ifdef WITH_SAMPLERATE
reader = new AUD_SRCResampleReader(reader, m_specs.specs);
+#else
+ reader = new AUD_LinearResampleReader(reader, m_specs.specs);
#endif
// rechannel
Modified: trunk/blender/intern/audaspace/intern/AUD_IDevice.h
===================================================================
--- trunk/blender/intern/audaspace/intern/AUD_IDevice.h 2011-02-18 23:47:37 UTC (rev 34981)
+++ trunk/blender/intern/audaspace/intern/AUD_IDevice.h 2011-02-18 23:50:27 UTC (rev 34982)
@@ -29,6 +29,7 @@
#include "AUD_Space.h"
class AUD_IFactory;
+class AUD_IReader;
/// Handle structure, for inherition.
struct AUD_Handle
@@ -60,6 +61,18 @@
/**
* Plays a sound source.
+ * \param reader The reader to play.
+ * \param keep When keep is true the sound source will not be deleted but
+ * set to paused when its end has been reached.
+ * \return Returns a handle with which the playback can be controlled.
+ * This is NULL if the sound couldn't be played back.
+ * \exception AUD_Exception Thrown if there's an unexpected (from the
+ * device side) error during creation of the reader.
+ */
+ virtual AUD_Handle* play(AUD_IReader* reader, bool keep = false)=0;
+
+ /**
+ * Plays a sound source.
* \param factory The factory to create the reader for the sound source.
* \param keep When keep is true the sound source will not be deleted but
* set to paused when its end has been reached.
Modified: trunk/blender/intern/audaspace/intern/AUD_NULLDevice.cpp
===================================================================
--- trunk/blender/intern/audaspace/intern/AUD_NULLDevice.cpp 2011-02-18 23:47:37 UTC (rev 34981)
+++ trunk/blender/intern/audaspace/intern/AUD_NULLDevice.cpp 2011-02-18 23:50:27 UTC (rev 34982)
@@ -43,6 +43,11 @@
return specs;
}
+AUD_Handle* AUD_NULLDevice::play(AUD_IReader* reader, bool keep)
+{
+ return 0;
+}
+
AUD_Handle* AUD_NULLDevice::play(AUD_IFactory* factory, bool keep)
{
return 0;
Modified: trunk/blender/intern/audaspace/intern/AUD_NULLDevice.h
===================================================================
--- trunk/blender/intern/audaspace/intern/AUD_NULLDevice.h 2011-02-18 23:47:37 UTC (rev 34981)
+++ trunk/blender/intern/audaspace/intern/AUD_NULLDevice.h 2011-02-18 23:50:27 UTC (rev 34982)
@@ -41,6 +41,7 @@
AUD_NULLDevice();
virtual AUD_DeviceSpecs getSpecs() const;
+ virtual AUD_Handle* play(AUD_IReader* reader, bool keep = false);
virtual AUD_Handle* play(AUD_IFactory* factory, bool keep = false);
virtual bool pause(AUD_Handle* handle);
virtual bool resume(AUD_Handle* handle);
Modified: trunk/blender/intern/audaspace/intern/AUD_SoftwareDevice.cpp
===================================================================
--- trunk/blender/intern/audaspace/intern/AUD_SoftwareDevice.cpp 2011-02-18 23:47:37 UTC (rev 34981)
+++ trunk/blender/intern/audaspace/intern/AUD_SoftwareDevice.cpp 2011-02-18 23:50:27 UTC (rev 34982)
@@ -208,10 +208,8 @@
return m_specs;
}
-AUD_Handle* AUD_SoftwareDevice::play(AUD_IFactory* factory, bool keep)
+AUD_Handle* AUD_SoftwareDevice::play(AUD_IReader* reader, bool keep)
{
- AUD_IReader* reader = factory->createReader();
-
// prepare the reader
reader = m_mixer->prepare(reader);
if(reader == NULL)
@@ -236,6 +234,11 @@
return sound;
}
+AUD_Handle* AUD_SoftwareDevice::play(AUD_IFactory* factory, bool keep)
+{
+ return play(factory->createReader(), keep);
+}
+
bool AUD_SoftwareDevice::pause(AUD_Handle* handle)
{
bool result = false;
Modified: trunk/blender/intern/audaspace/intern/AUD_SoftwareDevice.h
===================================================================
--- trunk/blender/intern/audaspace/intern/AUD_SoftwareDevice.h 2011-02-18 23:47:37 UTC (rev 34981)
+++ trunk/blender/intern/audaspace/intern/AUD_SoftwareDevice.h 2011-02-18 23:50:27 UTC (rev 34982)
@@ -114,6 +114,7 @@
public:
virtual AUD_DeviceSpecs getSpecs() const;
+ virtual AUD_Handle* play(AUD_IReader* reader, bool keep = false);
virtual AUD_Handle* play(AUD_IFactory* factory, bool keep = false);
virtual bool pause(AUD_Handle* handle);
virtual bool resume(AUD_Handle* handle);
More information about the Bf-blender-cvs
mailing list