diff options
author | Joerg Mueller <nexyon@gmail.com> | 2013-08-15 01:21:00 +0400 |
---|---|---|
committer | Joerg Mueller <nexyon@gmail.com> | 2013-08-15 01:21:00 +0400 |
commit | c8f75fb5b1918a13a722ed39bb8cace1ee5b58b8 (patch) | |
tree | b2439e74b81c952801ef4c5615562d106792def1 /intern/audaspace/OpenAL/AUD_OpenALDevice.cpp | |
parent | 9e42f76bab4a5ee766e4fe09bd9c9b3579e3da8d (diff) |
Adding a new state for sound handles in audaspace: stopped.
Now sounds that stopped playing but are still kept in the device can be differentiated from paused sounds with this state.
This should also fix the performance issues mentioned in [#36466] End of SequencerEntrys not set correctly.
Please test if sound pausing, resuming and stopping works fine in the BGE and sequencer, my tests all worked fine, but there might be a use case that needs some fixing.
Diffstat (limited to 'intern/audaspace/OpenAL/AUD_OpenALDevice.cpp')
-rw-r--r-- | intern/audaspace/OpenAL/AUD_OpenALDevice.cpp | 66 |
1 files changed, 39 insertions, 27 deletions
diff --git a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp index 371e0007bd3..676a86e88fe 100644 --- a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp +++ b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp @@ -67,6 +67,35 @@ static const char* queue_error = "AUD_OpenALDevice: Buffer couldn't be " static const char* bufferdata_error = "AUD_OpenALDevice: Buffer couldn't be " "filled with data."; +bool AUD_OpenALDevice::AUD_OpenALHandle::pause(bool keep) +{ + if(m_status) + { + AUD_MutexLock lock(*m_device); + + if(m_status == AUD_STATUS_PLAYING) + { + for(AUD_HandleIterator it = m_device->m_playingSounds.begin(); it != m_device->m_playingSounds.end(); it++) + { + if(it->get() == this) + { + boost::shared_ptr<AUD_OpenALHandle> This = *it; + + m_device->m_playingSounds.erase(it); + m_device->m_pausedSounds.push_back(This); + + alSourcePause(m_source); + + m_status = keep ? AUD_STATUS_STOPPED : AUD_STATUS_PAUSED; + + return true; + } + } + } + } + + return false;} + AUD_OpenALDevice::AUD_OpenALHandle::AUD_OpenALHandle(AUD_OpenALDevice* device, ALenum format, boost::shared_ptr<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), @@ -124,32 +153,7 @@ AUD_OpenALDevice::AUD_OpenALHandle::AUD_OpenALHandle(AUD_OpenALDevice* device, A bool AUD_OpenALDevice::AUD_OpenALHandle::pause() { - if(m_status) - { - AUD_MutexLock lock(*m_device); - - if(m_status == AUD_STATUS_PLAYING) - { - for(AUD_HandleIterator it = m_device->m_playingSounds.begin(); it != m_device->m_playingSounds.end(); it++) - { - if(it->get() == this) - { - boost::shared_ptr<AUD_OpenALHandle> This = *it; - - m_device->m_playingSounds.erase(it); - m_device->m_pausedSounds.push_back(This); - - alSourcePause(m_source); - - m_status = AUD_STATUS_PAUSED; - - return true; - } - } - } - } - - return false; + return pause(false); } bool AUD_OpenALDevice::AUD_OpenALHandle::resume() @@ -302,6 +306,9 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::seek(float position) } } + if(m_status == AUD_STATUS_STOPPED) + m_status = AUD_STATUS_PAUSED; + return true; } @@ -409,7 +416,12 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setLoopCount(int count) { if(!m_status) return false; + + if(m_status == AUD_STATUS_STOPPED && (count > m_loopcount || count < 0)) + m_status = AUD_STATUS_PAUSED; + m_loopcount = count; + return true; } @@ -987,7 +999,7 @@ void AUD_OpenALDevice::updateStreams() } for(it = pauseSounds.begin(); it != pauseSounds.end(); it++) - (*it)->pause(); + (*it)->pause(true); for(it = stopSounds.begin(); it != stopSounds.end(); it++) (*it)->stop(); |