Revision: 37711
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37711
Author:   nexyon
Date:     2011-06-21 20:21:43 +0000 (Tue, 21 Jun 2011)
Log Message:
-----------
3D Audio GSoC:
- Created Handle classes
- Changed Reference counting completely
- Fixing some streaming bugs
- Completely disabled OpenAL Buffered Factories (they were unused anyway)

Modified Paths:
--------------
    branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_DoubleReader.cpp
    branches/soc-2011-pepper/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
    branches/soc-2011-pepper/intern/audaspace/OpenAL/AUD_OpenALDevice.h
    branches/soc-2011-pepper/intern/audaspace/Python/AUD_PyAPI.cpp
    branches/soc-2011-pepper/intern/audaspace/Python/AUD_PyAPI.h
    branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_BufferReader.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.h
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_I3DDevice.h
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_IDevice.h
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_NULLDevice.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_NULLDevice.h
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_Reference.h
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerFactory.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.h
    branches/soc-2011-pepper/source/blender/blenkernel/intern/sound.c
    branches/soc-2011-pepper/source/gameengine/Ketsji/KX_SoundActuator.cpp

Added Paths:
-----------
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_I3DHandle.h
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_IHandle.h
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_ReferenceHandler.cpp

Modified: branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt    2011-06-21 
20:14:53 UTC (rev 37710)
+++ branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt    2011-06-21 
20:21:43 UTC (rev 37711)
@@ -87,8 +87,10 @@
        intern/AUD_FileFactory.cpp
        intern/AUD_FileFactory.h
        intern/AUD_I3DDevice.h
+       intern/AUD_I3DHandle.h
        intern/AUD_IDevice.h
        intern/AUD_IFactory.h
+       intern/AUD_IHandle.h
        intern/AUD_IReader.h
        intern/AUD_LinearResampleFactory.cpp
        intern/AUD_LinearResampleFactory.h
@@ -104,6 +106,7 @@
        intern/AUD_ReadDevice.cpp
        intern/AUD_ReadDevice.h
        intern/AUD_Reference.h
+       intern/AUD_ReferenceHandler.cpp
        intern/AUD_ResampleFactory.h
        intern/AUD_SequencerFactory.cpp
        intern/AUD_SequencerFactory.h

Modified: branches/soc-2011-pepper/intern/audaspace/FX/AUD_DoubleReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/FX/AUD_DoubleReader.cpp   
2011-06-21 20:14:53 UTC (rev 37710)
+++ branches/soc-2011-pepper/intern/audaspace/FX/AUD_DoubleReader.cpp   
2011-06-21 20:21:43 UTC (rev 37711)
@@ -91,6 +91,8 @@
 
 void AUD_DoubleReader::read(int& length, bool& eos, sample_t* buffer)
 {
+       eos = false;
+
        if(!m_finished1)
        {
                int len = length;

Modified: branches/soc-2011-pepper/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp       
2011-06-21 20:14:53 UTC (rev 37710)
+++ branches/soc-2011-pepper/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp       
2011-06-21 20:21:43 UTC (rev 37711)
@@ -43,58 +43,725 @@
 #include <unistd.h>
 #endif
 
-#define AUD_OPENAL_CYCLE_BUFFERS 3
+/*struct AUD_OpenALBufferedFactory
+{
+       /// The factory.
+       AUD_IFactory* factory;
 
-/// Saves the data for playback.
-struct AUD_OpenALHandle : AUD_Handle
+       /// The OpenAL buffer.
+       ALuint buffer;
+};*/
+
+typedef std::list<AUD_Reference<AUD_OpenALDevice::AUD_OpenALHandle> 
>::iterator AUD_HandleIterator;
+//typedef std::list<AUD_OpenALBufferedFactory*>::iterator AUD_BFIterator;
+
+
+/******************************************************************************/
+/*********************** AUD_OpenALHandle Handle Code 
*************************/
+/******************************************************************************/
+
+static const char* genbuffer_error = "AUD_OpenALDevice: Buffer couldn't be "
+                                                                        
"generated.";
+static const char* gensource_error = "AUD_OpenALDevice: Source couldn't be "
+                                                                        
"generated.";
+static const char* queue_error = "AUD_OpenALDevice: Buffer couldn't be "
+                                                                "queued to the 
source.";
+static const char* bufferdata_error = "AUD_OpenALDevice: Buffer couldn't be "
+                                                                         
"filled with data.";
+
+AUD_OpenALDevice::AUD_OpenALHandle::AUD_OpenALHandle(AUD_OpenALDevice* device, 
ALenum format, AUD_Reference<AUD_IReader> reader, bool keep) :
+       m_isBuffered(false), m_reader(reader), m_keep(keep), m_format(format), 
m_current(0),
+       m_eos(false), m_loopcount(0), m_stop(NULL), m_stop_data(NULL), 
m_status(AUD_STATUS_PLAYING),
+       m_device(device)
 {
-       /// Whether it's a buffered or a streamed source.
-       bool isBuffered;
+       AUD_DeviceSpecs specs = m_device->m_specs;
+       specs.specs = m_reader->getSpecs();
 
-       /// The reader source.
-       AUD_Reference<AUD_IReader> reader;
+       // OpenAL playback code
+       alGenBuffers(CYCLE_BUFFERS, m_buffers);
+       if(alGetError() != AL_NO_ERROR)
+               AUD_THROW(AUD_ERROR_OPENAL, genbuffer_error);
 
-       /// Whether to keep the source if end of it is reached.
-       bool keep;
+       try
+       {
+               m_device->m_buffer.assureSize(m_device->m_buffersize * 
AUD_DEVICE_SAMPLE_SIZE(specs));
+               int length;
+               bool eos;
 
-       /// OpenAL sample format.
-       ALenum format;
+               for(int i = 0; i < CYCLE_BUFFERS; i++)
+               {
+                       length = m_device->m_buffersize;
+                       reader->read(length, eos, 
m_device->m_buffer.getBuffer());
+                       alBufferData(m_buffers[i], m_format, 
m_device->m_buffer.getBuffer(),
+                                                length * 
AUD_DEVICE_SAMPLE_SIZE(specs),
+                                                specs.rate);
+                       if(alGetError() != AL_NO_ERROR)
+                               AUD_THROW(AUD_ERROR_OPENAL, bufferdata_error);
+               }
 
-       /// OpenAL source.
-       ALuint source;
+               alGenSources(1, &m_source);
+               if(alGetError() != AL_NO_ERROR)
+                       AUD_THROW(AUD_ERROR_OPENAL, gensource_error);
 
-       /// OpenAL buffers.
-       ALuint buffers[AUD_OPENAL_CYCLE_BUFFERS];
+               try
+               {
+                       alSourceQueueBuffers(m_source, CYCLE_BUFFERS,
+                                                                m_buffers);
+                       if(alGetError() != AL_NO_ERROR)
+                               AUD_THROW(AUD_ERROR_OPENAL, queue_error);
+               }
+               catch(AUD_Exception&)
+               {
+                       alDeleteSources(1, &m_source);
+                       throw;
+               }
+       }
+       catch(AUD_Exception&)
+       {
+               alDeleteBuffers(CYCLE_BUFFERS, m_buffers);
+               throw;
+       }
+       alSourcei(m_source, AL_SOURCE_RELATIVE, 1);
+}
 
-       /// The first buffer to be read next.
-       int current;
+bool AUD_OpenALDevice::AUD_OpenALHandle::pause()
+{
+       if(m_status)
+       {
+               m_device->lock();
 
-       /// Whether the stream doesn't return any more data.
-       bool eos;
+               if(m_status == AUD_STATUS_PLAYING)
+               {
+                       m_device->m_playingSounds.remove(this);
+                       m_device->m_pausedSounds.push_back(this);
 
-       /// The loop count of the source.
-       int loopcount;
+                       alSourcePause(m_source);
 
-       /// The stop callback.
-       stopCallback stop;
+                       m_status = AUD_STATUS_PAUSED;
+                       m_device->unlock();
 
-       /// Stop callback data.
-       void* stop_data;
-};
+                       return true;
+               }
 
-struct AUD_OpenALBufferedFactory
+               m_device->unlock();
+       }
+
+       return false;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::resume()
 {
-       /// The factory.
-       AUD_IFactory* factory;
+       if(m_status)
+       {
+               m_device->lock();
 
-       /// The OpenAL buffer.
-       ALuint buffer;
-};
+               if(m_status == AUD_STATUS_PAUSED)
+               {
+                       m_device->m_pausedSounds.remove(this);
+                       m_device->m_playingSounds.push_back(this);
 
-typedef std::list<AUD_OpenALHandle*>::iterator AUD_HandleIterator;
-typedef std::list<AUD_OpenALBufferedFactory*>::iterator AUD_BFIterator;
+                       m_device->start();
+                       m_status = AUD_STATUS_PLAYING;
+                       m_device->unlock();
+                       return true;
+               }
 
+               m_device->unlock();
+       }
+
+       return false;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::stop()
+{
+       if(!m_status)
+               return false;
+
+       m_device->lock();
+
+       if(m_status == AUD_STATUS_PLAYING)
+               m_device->m_playingSounds.remove(this);
+       else
+               m_device->m_pausedSounds.remove(this);
+
+       m_device->unlock();
+
+       alDeleteSources(1, &m_source);
+       if(!m_isBuffered)
+               alDeleteBuffers(CYCLE_BUFFERS, m_buffers);
+
+       m_status = AUD_STATUS_INVALID;
+       return true;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::getKeep()
+{
+       if(m_status)
+               return m_keep;
+
+       return false;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setKeep(bool keep)
+{
+       if(!m_status)
+               return false;
+
+       m_device->lock();
+
+       m_keep = keep;
+
+       m_device->unlock();
+
+       return true;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::seek(float position)
+{
+       if(!m_status)
+               return false;
+
+       m_device->lock();
+
+       if(m_isBuffered)
+               alSourcef(m_source, AL_SEC_OFFSET, position);
+       else
+       {
+               m_reader->seek((int)(position * m_reader->getSpecs().rate));
+               m_eos = false;
+
+               ALint info;
+
+               alGetSourcei(m_source, AL_SOURCE_STATE, &info);
+
+               if(info != AL_PLAYING)
+               {
+                       if(info == AL_PAUSED)
+                               alSourceStop(m_source);
+
+                       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));
+
+                               for(int i = 0; i < CYCLE_BUFFERS; i++)
+                               {
+                                       length = m_device->m_buffersize;
+                                       m_reader->read(length, m_eos, 
m_device->m_buffer.getBuffer());
+                                       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;
+                               }
+
+                               if(m_loopcount != 0)
+                                       m_eos = false;
+
+                               alSourceQueueBuffers(m_source, CYCLE_BUFFERS, 
m_buffers);
+                       }
+
+                       alSourceRewind(m_source);
+               }
+       }
+
+       m_device->unlock();
+
+       return true;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getPosition()
+{
+       if(!m_status)
+               return 0.0f;
+
+       m_device->lock();
+
+       float position = 0.0f;
+
+       alGetSourcef(m_source, AL_SEC_OFFSET, &position);
+
+       if(!m_isBuffered)
+       {
+               AUD_Specs specs = m_reader->getSpecs();
+               position += (m_reader->getPosition() - m_device->m_buffersize *
+                                        CYCLE_BUFFERS) / (float)specs.rate;
+       }
+
+       m_device->unlock();
+
+       return position;
+}
+
+AUD_Status AUD_OpenALDevice::AUD_OpenALHandle::getStatus()
+{
+       return m_status;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getVolume()
+{
+       float result = std::numeric_limits<float>::quiet_NaN();
+
+       if(!m_status)
+               return result;
+
+       m_device->lock();
+
+       alGetSourcef(m_source, AL_GAIN, &result);
+
+       m_device->unlock();
+
+       return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setVolume(float volume)
+{
+       if(!m_status)
+               return false;
+
+       m_device->lock();
+
+       alSourcef(m_source, AL_GAIN, volume);
+
+       m_device->unlock();
+
+       return true;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getPitch()
+{
+       float result = std::numeric_limits<float>::quiet_NaN();
+
+       if(!m_status)
+               return result;
+
+       m_device->lock();
+
+       alGetSourcef(m_source, AL_PITCH, &result);
+
+       m_device->unlock();
+
+       return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setPitch(float pitch)
+{
+       if(!m_status)
+               return false;
+
+       m_device->lock();
+
+       alSourcef(m_source, AL_PITCH, pitch);
+
+       m_device->unlock();
+
+       return true;
+}
+
+int AUD_OpenALDevice::AUD_OpenALHandle::getLoopCount()
+{
+       if(!m_status)
+               return 0;
+       return m_loopcount;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setLoopCount(int count)
+{
+       if(!m_status)
+               return false;
+       m_loopcount = count;
+       return true;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setStopCallback(stopCallback 
callback, void* data)
+{
+       if(!m_status)
+               return false;
+
+       m_device->lock();
+
+       m_stop = callback;
+       m_stop_data = data;
+
+       m_device->unlock();
+
+       return true;
+}
+
 
/******************************************************************************/
+/********************* AUD_OpenALHandle 3DHandle Code 
*************************/
+/******************************************************************************/
+
+AUD_Vector3 AUD_OpenALDevice::AUD_OpenALHandle::getSourceLocation()
+{
+       AUD_Vector3 result = AUD_Vector3(0, 0, 0);
+
+       if(!m_status)
+               return result;
+
+       m_device->lock();
+
+       ALfloat p[3];
+       alGetSourcefv(m_source, AL_POSITION, p);
+

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to