Revision: 23499
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23499
Author:   nexyon
Date:     2009-09-26 22:03:01 +0200 (Sat, 26 Sep 2009)

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

* Threading buxfix letting MSVC Debug builds crash because of corrupted 
std::lists
* Adopted two property ranges
* Changed the mixdown volume to set the device volume instead of the volume of 
every sound.

I also removed the private redefinition of m_logicmgr in SCA_BasicEventManager, 
which was already defined protected in the parent class SCA_EventManager and 
thus caused a bug letting GE crash here because of an uninitialized pointer.

Modified Paths:
--------------
    trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
    trunk/blender/intern/audaspace/intern/AUD_C-API.cpp
    trunk/blender/intern/audaspace/intern/AUD_C-API.h
    trunk/blender/intern/audaspace/intern/AUD_SoftwareDevice.cpp
    trunk/blender/source/blender/blenkernel/intern/sound.c
    trunk/blender/source/blender/makesrna/intern/rna_scene.c
    trunk/blender/source/gameengine/GameLogic/SCA_BasicEventManager.h

Modified: trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
===================================================================
--- trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp  2009-09-26 
19:50:59 UTC (rev 23498)
+++ trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp  2009-09-26 
20:03:01 UTC (rev 23499)
@@ -127,101 +127,103 @@
 
                alcSuspendContext(m_context);
 
-               // for all sounds
-               AUD_HandleIterator it = m_playingSounds->begin();
-               while(it != m_playingSounds->end())
                {
-                       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)
+                       // for all sounds
+                       AUD_HandleIterator it = m_playingSounds->begin();
+                       while(it != m_playingSounds->end())
                        {
-                               // check for buffer refilling
-                               alGetSourcei(sound->source, 
AL_BUFFERS_PROCESSED, &info);
+                               sound = *it;
+                               // increment the iterator to make sure it's 
valid,
+                               // in case the sound gets deleted after stopping
+                               ++it;
 
-                               if(info)
+                               // is it a streamed sound?
+                               if(!sound->isBuffered)
                                {
-                                       specs = sound->reader->getSpecs();
+                                       // check for buffer refilling
+                                       alGetSourcei(sound->source, 
AL_BUFFERS_PROCESSED, &info);
 
-                                       // for all empty buffers
-                                       while(info--)
+                                       if(info)
                                        {
-                                               // if there's still data to 
play back
-                                               if(!sound->data_end)
+                                               specs = 
sound->reader->getSpecs();
+
+                                               // for all empty buffers
+                                               while(info--)
                                                {
-                                                       // read data
-                                                       length = m_buffersize;
-                                                       
sound->reader->read(length, buffer);
-
-                                                       // read nothing?
-                                                       if(length == 0)
+                                                       // if there's still 
data to play back
+                                                       if(!sound->data_end)
                                                        {
-                                                               sound->data_end 
= true;
-                                                               break;
-                                                       }
+                                                               // read data
+                                                               length = 
m_buffersize;
+                                                               
sound->reader->read(length, buffer);
 
-                                                       // unqueue buffer
-                                                       
alSourceUnqueueBuffers(sound->source, 1,
-                                                                               
        &sound->buffers[sound->current]);
-                                                       ALenum err;
-                                                       if((err = alGetError()) 
!= AL_NO_ERROR)
-                                                       {
-                                                               sound->data_end 
= true;
-                                                               break;
-                                                       }
+                                                               // read nothing?
+                                                               if(length == 0)
+                                                               {
+                                                                       
sound->data_end = true;
+                                                                       break;
+                                                               }
 
-                                                       // fill with new data
-                                                       
alBufferData(sound->buffers[sound->current],
-                                                                               
 sound->format,
-                                                                               
 buffer,
-                                                                               
 length * AUD_SAMPLE_SIZE(specs),
-                                                                               
 specs.rate);
+                                                               // unqueue 
buffer
+                                                               
alSourceUnqueueBuffers(sound->source, 1,
+                                                                               
                &sound->buffers[sound->current]);
+                                                               ALenum err;
+                                                               if((err = 
alGetError()) != AL_NO_ERROR)
+                                                               {
+                                                                       
sound->data_end = true;
+                                                                       break;
+                                                               }
 
-                                                       if(alGetError() != 
AL_NO_ERROR)
-                                                       {
-                                                               sound->data_end 
= true;
-                                                               break;
+                                                               // fill with 
new data
+                                                               
alBufferData(sound->buffers[sound->current],
+                                                                               
         sound->format,
+                                                                               
         buffer,
+                                                                               
         length * AUD_SAMPLE_SIZE(specs),
+                                                                               
         specs.rate);
+
+                                                               if(alGetError() 
!= AL_NO_ERROR)
+                                                               {
+                                                                       
sound->data_end = true;
+                                                                       break;
+                                                               }
+
+                                                               // and queue 
again
+                                                               
alSourceQueueBuffers(sound->source, 1,
+                                                                               
                &sound->buffers[sound->current]);
+                                                               if(alGetError() 
!= AL_NO_ERROR)
+                                                               {
+                                                                       
sound->data_end = true;
+                                                                       break;
+                                                               }
+
+                                                               sound->current 
= (sound->current+1) %
+                                                                               
                 AUD_OPENAL_CYCLE_BUFFERS;
                                                        }
-
-                                                       // and queue again
-                                                       
alSourceQueueBuffers(sound->source, 1,
-                                                                               
        &sound->buffers[sound->current]);
-                                                       if(alGetError() != 
AL_NO_ERROR)
-                                                       {
-                                                               sound->data_end 
= true;
+                                                       else
                                                                break;
-                                                       }
-
-                                                       sound->current = 
(sound->current+1) %
-                                                                               
         AUD_OPENAL_CYCLE_BUFFERS;
                                                }
-                                               else
-                                                       break;
                                        }
                                }
-                       }
 
-                       // check if the sound has been stopped
-                       alGetSourcei(sound->source, AL_SOURCE_STATE, &info);
+                               // check if the sound has been stopped
+                               alGetSourcei(sound->source, AL_SOURCE_STATE, 
&info);
 
-                       if(info != AL_PLAYING)
-                       {
-                               // if it really stopped
-                               if(sound->data_end)
+                               if(info != AL_PLAYING)
                                {
-                                       // pause or
-                                       if(sound->keep)
-                                               pause(sound);
-                                       // stop
+                                       // if it really stopped
+                                       if(sound->data_end)
+                                       {
+                                               // pause or
+                                               if(sound->keep)
+                                                       pause(sound);
+                                               // stop
+                                               else
+                                                       stop(sound);
+                                       }
+                                       // continue playing
                                        else
-                                               stop(sound);
+                                               alSourcePlay(sound->source);
                                }
-                               // continue playing
-                               else
-                                       alSourcePlay(sound->source);
                        }
                }
 
@@ -516,61 +518,74 @@
 
 AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
 {
-       // check if it is a buffered factory
-       for(AUD_BFIterator i = m_bufferedFactories->begin();
-               i != m_bufferedFactories->end(); i++)
+       lock();
+
+       AUD_OpenALHandle* sound = NULL;
+
+       try
        {
-               if((*i)->factory == factory)
+               // check if it is a buffered factory
+               for(AUD_BFIterator i = m_bufferedFactories->begin();
+                       i != m_bufferedFactories->end(); i++)
                {
-                       // create the handle
-                       AUD_OpenALHandle* sound = new AUD_OpenALHandle; 
AUD_NEW("handle")
-                       sound->keep = keep;
-                       sound->current = -1;
-                       sound->isBuffered = true;
-                       sound->data_end = true;
+                       if((*i)->factory == factory)
+                       {
+                               // create the handle
+                               sound = new AUD_OpenALHandle; AUD_NEW("handle")
+                               sound->keep = keep;
+                               sound->current = -1;
+                               sound->isBuffered = true;
+                               sound->data_end = true;
 
-                       alcSuspendContext(m_context);
+                               alcSuspendContext(m_context);
 
-                       // OpenAL playback code
-                       try
-                       {
-                               alGenSources(1, &sound->source);
-                               if(alGetError() != AL_NO_ERROR)
-                                       AUD_THROW(AUD_ERROR_OPENAL);
-
+                               // OpenAL playback code
                                try
                                {
-                                       alSourcei(sound->source, AL_BUFFER, 
(*i)->buffer);
+                                       alGenSources(1, &sound->source);
                                        if(alGetError() != AL_NO_ERROR)
                                                AUD_THROW(AUD_ERROR_OPENAL);
+
+                                       try
+                                       {
+                                               alSourcei(sound->source, 
AL_BUFFER, (*i)->buffer);
+                                               if(alGetError() != AL_NO_ERROR)
+                                                       
AUD_THROW(AUD_ERROR_OPENAL);
+                                       }
+                                       catch(AUD_Exception)
+                                       {
+                                               alDeleteSources(1, 
&sound->source);
+                                               throw;
+                                       }
                                }
                                catch(AUD_Exception)
                                {
-                                       alDeleteSources(1, &sound->source);
+                                       delete sound; AUD_DELETE("handle")
+                                       alcProcessContext(m_context);
                                        throw;
                                }
-                       }
-                       catch(AUD_Exception)
-                       {
-                               delete sound; AUD_DELETE("handle")
-                               alcProcessContext(m_context);
-                               unlock();
-                               throw;
-                       }
 
-                       // play sound
-                       m_playingSounds->push_back(sound);
+                               // play sound
+                               m_playingSounds->push_back(sound);
 
-                       alSourcei(sound->source, AL_SOURCE_RELATIVE, 1);
-                       start();
+                               alSourcei(sound->source, AL_SOURCE_RELATIVE, 1);
+                               start();
 
-                       alcProcessContext(m_context);
-                       unlock();
-
-                       return sound;
+                               alcProcessContext(m_context);
+                       }
                }
        }
+       catch(AUD_Exception)
+       {
+               unlock();
+               throw;
+       }
 
+       unlock();
+
+       if(sound)
+               return sound;
+
        AUD_IReader* reader = factory->createReader();
 
        if(reader == NULL)
@@ -596,7 +611,7 @@
        }
 
        // create the handle
-       AUD_OpenALHandle* sound = new AUD_OpenALHandle; AUD_NEW("handle")
+       sound = new AUD_OpenALHandle; AUD_NEW("handle")
        sound->keep = keep;
        sound->reader = reader;
        sound->current = 0;
@@ -683,8 +698,11 @@
 
 bool AUD_OpenALDevice::pause(AUD_Handle* handle)
 {
+       bool result = false;
+
+       lock();
+
        // only songs that are played can be paused
-       lock();
        for(AUD_HandleIterator i = m_playingSounds->begin();
                i != m_playingSounds->end(); i++)
        {
@@ -693,16 +711,20 @@
                        m_pausedSounds->push_back(*i);
                        alSourcePause((*i)->source);
                        m_playingSounds->erase(i);
-                       unlock();
-                       return true;
+                       result = true;
+                       break;
                }
        }
+
        unlock();
-       return false;
+
+       return result;
 }
 
 bool AUD_OpenALDevice::resume(AUD_Handle* handle)
 {
+       bool result = false;
+
        lock();
 
        // only songs that are paused can be resumed
@@ -714,19 +736,24 @@
                        m_playingSounds->push_back(*i);
                        start();
                        m_pausedSounds->erase(i);
-                       unlock();
-                       return true;
+                       result = true;
+                       break;
                }
        }
+
        unlock();
-       return false;
+
+       return result;
 }
 
 bool AUD_OpenALDevice::stop(AUD_Handle* handle)
 {
        AUD_OpenALHandle* sound;
 
+       bool result = false;
+
        lock();
+
        for(AUD_HandleIterator i = m_playingSounds->begin();
                i != m_playingSounds->end(); i++)
        {
@@ -741,51 +768,60 @@
                        }
                        delete *i; AUD_DELETE("handle")
                        m_playingSounds->erase(i);
-                       unlock();
-                       return true;
+                       result = true;
+                       break;
                }
        }
-       for(AUD_HandleIterator i = m_pausedSounds->begin();
-               i != m_pausedSounds->end(); i++)
+       if(!result)
        {
-               if(*i == handle)
+               for(AUD_HandleIterator i = m_pausedSounds->begin();
+                       i != m_pausedSounds->end(); i++)
                {
-                       sound = *i;
-                       alDeleteSources(1, &sound->source);
-                       if(!sound->isBuffered)
+                       if(*i == handle)
                        {
-                               delete sound->reader; AUD_DELETE("reader")
-                               alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, 
sound->buffers);
+                               sound = *i;
+                               alDeleteSources(1, &sound->source);
+                               if(!sound->isBuffered)
+                               {
+                                       delete sound->reader; 
AUD_DELETE("reader")
+                                       
alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
+                               }
+                               delete *i; AUD_DELETE("handle")
+                               m_pausedSounds->erase(i);
+                               result = true;
+                               break;
                        }
-                       delete *i; AUD_DELETE("handle")
-                       m_pausedSounds->erase(i);
-                       unlock();
-                       return true;
                }
        }
+
        unlock();
-       return false;
+
+       return result;
 }
 
 bool AUD_OpenALDevice::setKeep(AUD_Handle* handle, bool keep)
 {
+       bool result = false;
+
        lock();
+
        if(isValid(handle))
        {
                ((AUD_OpenALHandle*)handle)->keep = keep;
-               unlock();
-               return true;
+               result = true;
        }
+
        unlock();
-       return false;
+
+       return result;
 }
 
 bool AUD_OpenALDevice::sendMessage(AUD_Handle* handle, AUD_Message &message)
 {
+       bool result = false;
+
        lock();
 
-       bool result = false;
-
        if(handle == 0)
        {
                for(AUD_HandleIterator i = m_playingSounds->begin();
@@ -800,12 +836,16 @@
        else if(isValid(handle))
                if(!((AUD_OpenALHandle*)handle)->isBuffered)
                        result = 
((AUD_OpenALHandle*)handle)->reader->notify(message);
+
        unlock();
+
        return result;
 }
 
 bool AUD_OpenALDevice::seek(AUD_Handle* handle, float position)
 {
+       bool result = false;
+
        lock();
 
        if(isValid(handle))
@@ -857,20 +897,19 @@
                                alSourceRewind(alhandle->source);
                        }
                }
-               unlock();
-               return true;
+               result = true;
        }
 
        unlock();
-       return false;
+       return result;
 }
 
 float AUD_OpenALDevice::getPosition(AUD_Handle* handle)
 {
+       float position = 0.0;
+
        lock();
 
-       float position = 0.0;
-

@@ 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