From 25c1b973b2a00d04df4d0650a44a6673bc82c8a7 Mon Sep 17 00:00:00 2001 From: stickymango Date: Wed, 4 Jun 2014 21:07:24 +0000 Subject: [PATCH] Number of patches applied to fix multi-threaded issues identified by shenjoku (Potentially unstable) --- ChangeLog.txt | 9 ++++ OgreOggSoundLib_vc10.suo | Bin 148480 -> 158208 bytes include/OgreOggISound.h | 16 ++++--- include/OgreOggListener.h | 14 +++++-- include/OgreOggSound.h | 2 +- include/OgreOggSoundCallback.h | 2 +- include/OgreOggSoundFactory.h | 2 +- include/OgreOggSoundManager.h | 7 +++- include/OgreOggSoundPlugin.h | 2 +- include/OgreOggSoundPrereqs.h | 21 +++++++--- include/OgreOggSoundRecord.h | 2 +- include/OgreOggStaticSound.h | 2 +- include/OgreOggStaticWavSound.h | 2 +- include/OgreOggStreamSound.h | 2 +- include/OgreOggStreamWavSound.h | 2 +- include/apimainpage.txt | 2 +- src/OgreOggISound.cpp | 14 +++++-- src/OgreOggListener.cpp | 65 ++++++++++++++++++++++++++++- src/OgreOggSoundFactory.cpp | 2 +- src/OgreOggSoundManager.cpp | 39 ++++++++++++----- src/OgreOggSoundPlugin.cpp | 2 +- src/OgreOggSoundPluginDllStart.cpp | 2 +- src/OgreOggSoundRecord.cpp | 2 +- src/OgreOggStaticSound.cpp | 13 ++++-- src/OgreOggStaticWavSound.cpp | 13 ++++-- src/OgreOggStreamSound.cpp | 11 ++++- src/OgreOggStreamWavSound.cpp | 11 ++++- 27 files changed, 205 insertions(+), 56 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 77e451f..a000e4a 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,12 @@ +* version 1.26 (Potentially unstable multi-threaded version) + + * Added patches to fix a number of multi-threaded issues discovered by shenjoku: + * http://www.ogre3d.org/addonforums/viewtopic.php?f=19&t=30239&p=102725#p102725 + * http://www.ogre3d.org/addonforums/viewtopic.php?f=19&t=30243 + * http://www.ogre3d.org/addonforums/viewtopic.php?f=19&t=30240 + * http://www.ogre3d.org/addonforums/viewtopic.php?f=19&t=30246 + * http://www.ogre3d.org/addonforums/viewtopic.php?f=19&t=30244 + * version 1.25 * Added patches from shenjoku: http://www.ogre3d.org/addonforums/viewtopic.php?f=19&t=30226 diff --git a/OgreOggSoundLib_vc10.suo b/OgreOggSoundLib_vc10.suo index d5d0c771b5ca7e61121afe2c4403e0cbe36dc3c6..8332675bfa0b673527f497a43122e9d53e74b1ef 100644 GIT binary patch delta 7616 zcmai334Dy#7C-09O!jSLGP21s2|^;0SfW7;A(pgaD`{Usl;BAaf;P59y{>lCx=){0 zg{oFd31X{8szgz-RgseDYqjbrwY9dq|NXv+P9pF3=I7*p?>*<-<(zZxckfa3x=Yb1 zm(Ox_UU}vB-sn_xj2#F+M=qJE>&wpGDA(dAmVCmI%RF=?f9TyE9Abz>-0vLX6H9Gq z2xU_~O{EN}M^y5Z%NNXv)<0cS^|7csiKXvyRLNAgBAug$j;Nhtz30_We-JD;8_U~U zC*r-7P&d2otZ^xU*1g6SUSp^)C8G05G?u1Nc1f+VfH}0Jz%-K`6(*{VEV0w#hID2J zo9MPK4&IMoh5oQj8c3F{mYt*hWFg1aFabExRxa7IbH9N{Tlb9$h7n*RG4Lh_m6RQR zkf4jiq(zwnw|A++3Ev?s=84X8y>V#iCzaM`(DrU!{+Q7^Jt^b-z?#j>CR|pbW z9*WtT73-}Zhgl|xk)BF;-SRQ~V@?mj57?d~u6IyOJWwobqHMD%>~mB?Fo7n^7jd*s z8cD=1;w5piv;{UOu^D{|5c&KojUE6fT2)2K@rM0{Rtn z74#p_HPCOM>!2H;-$6G)w?MZ+cR+VRe}Mi3-2>eRJperfJp$E&2s>>15>_lud6b80 ziU@hg*_^9x*E(O^zT^oxeHUL0io6ae?BIi{icg5|=rO$?dqg!ELnV9Ty|;=F!J z&hk|yo$F2{G0;PawHpG}?uK=>_nbcbaMS4E0e_@ko|Rdw(0>RL6JHv?fFoEN=oZARNppL^Ma^aCJl>`9Jb)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VxRU%VQssb}mfV6P zG6_wKyy7OXgSF?Mo|{SJ<3QbsJYV)z!5$ZECEY@q(+BI%cAVd~-N;jMK3Q z`o>{kXBOtbsfZ1HnuGJJa5o4&UfN8&s zH0%NWIy0`0lKS&Ztd1&AG*nWEE5RG7!!%lmjnEsh+NC0Ffb$WnaV2hsv(czcqNa2# z@W0%0qvK7cg|pEW9eFZs&*JDt<#_1k;iNJLy^p*i!}r%BYMz0~<8VVx$1?ei@lrM} z3sq$#B^7oCjw!F6dD7I}-hAtEBo2oE{9$I4}3=@m}uBqr2Rjqbl0!31+@x z!%r~}s-yvVhIC!7i3(;>MQ_Dms{B7&ukXVh!_(WW%i)&cAB_}uY@tT&$)-sflp7-T rnufa|&zok!qawT+_|xDWvEm@W_P|8`8TSY$o(u{3jzT;+>ahE7R^nUx diff --git a/include/OgreOggISound.h b/include/OgreOggISound.h index cdd023f..6d4c2a0 100644 --- a/include/OgreOggISound.h +++ b/include/OgreOggISound.h @@ -1,7 +1,7 @@ /** * @file OgreOggISound.h * @author Ian Stangoe -* @version 1.24 +* @version 1.26 * * @section LICENSE * @@ -108,7 +108,8 @@ namespace OgreOggSound SS_NONE, SS_PLAYING, SS_PAUSED, - SS_STOPPED + SS_STOPPED, + SS_DESTROYED }; //!Structure describing an ogg stream @@ -128,10 +129,7 @@ namespace OgreOggSound { public: - - typedef std::vector BufferList; // A list of the IDs of all OpenAL buffers being used by a sound. This is a vector so that it can be passed around as an array to the various OpenAL functions. - typedef Ogre::SharedPtr BufferListPtr; // An Ogre::SharedPtr to the list of buffer IDs. This makes it easier to pass the values to multiple OgreOggISound instances without having - + //! Listener callback /** provides hooks into various sound states. */ @@ -526,10 +524,10 @@ namespace OgreOggSound /** Sets properties of a shared resource. @remarks Sets a number of properties relating to audio of a shared resource. - @param s - OgreOggISound pointer of parent sound. + @param buffer + Pointer to the shared buffer to copy the properties from. */ - void _setSharedProperties(OgreOggISound* s); + void _setSharedProperties(sharedAudioBuffer* buffer); /** Gets properties of a shared resource. @remarks diff --git a/include/OgreOggListener.h b/include/OgreOggListener.h index bf66230..8a00e39 100644 --- a/include/OgreOggListener.h +++ b/include/OgreOggListener.h @@ -1,7 +1,7 @@ /** * @file OgreOggSoundListener.h * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * @@ -81,7 +81,7 @@ namespace OgreOggSound void setPosition(const Ogre::Vector3 &pos); /** Gets the position of the listener. */ - const Ogre::Vector3& getPosition() { return mPosition; } + Ogre::Vector3 getPosition() const; /** Sets the orientation of the listener. @remarks Sets the 3D orientation of the listener. This is a manual method, @@ -104,7 +104,7 @@ namespace OgreOggSound void setOrientation(const Ogre::Quaternion &q); /** Gets the orientation of the listener. */ - Ogre::Vector3 getOrientation() { return Ogre::Vector3(mOrientation[0],mOrientation[1],mOrientation[2]); } + Ogre::Vector3 getOrientation() const; /** Sets sounds velocity. @param vel 3D x/y/z velocity @@ -169,6 +169,14 @@ namespace OgreOggSound private: +#if OGGSOUND_THREADED +# if POCO_THREAD + static Poco::Mutex mMutex; +# else + static boost::recursive_mutex mMutex; +# endif +#endif + /** * Positional variables */ diff --git a/include/OgreOggSound.h b/include/OgreOggSound.h index 3517efe..aee9d34 100644 --- a/include/OgreOggSound.h +++ b/include/OgreOggSound.h @@ -1,7 +1,7 @@ /** * @file OgreOggSound.h * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * diff --git a/include/OgreOggSoundCallback.h b/include/OgreOggSoundCallback.h index ade19bc..ecc7611 100644 --- a/include/OgreOggSoundCallback.h +++ b/include/OgreOggSoundCallback.h @@ -1,7 +1,7 @@ /** * @file OgreOggSoundCallback.h * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * diff --git a/include/OgreOggSoundFactory.h b/include/OgreOggSoundFactory.h index 9bca561..80c7d56 100644 --- a/include/OgreOggSoundFactory.h +++ b/include/OgreOggSoundFactory.h @@ -1,7 +1,7 @@ /** * @file OgreOggSoundFactory.h * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * diff --git a/include/OgreOggSoundManager.h b/include/OgreOggSoundManager.h index 3e70d14..c1d428b 100644 --- a/include/OgreOggSoundManager.h +++ b/include/OgreOggSoundManager.h @@ -1,7 +1,7 @@ /** * @file OgreOggSoundManager.h * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * @@ -627,6 +627,7 @@ namespace OgreOggSound static Poco::Mutex mMutex; # else static boost::recursive_mutex mMutex; + static boost::recursive_mutex mSoundMutex; # endif /** Pushes a sound action request onto the queue @@ -891,6 +892,10 @@ namespace OgreOggSound */ void _destroyListener(); + /** Calculates the distance a sound is from the specified listener position. + */ + static Ogre::Real _calculateDistanceToListener(OgreOggISound * sound, const Ogre::Vector3 & listenerPos); + /** * OpenAL device objects */ diff --git a/include/OgreOggSoundPlugin.h b/include/OgreOggSoundPlugin.h index 6009d86..9f563b3 100644 --- a/include/OgreOggSoundPlugin.h +++ b/include/OgreOggSoundPlugin.h @@ -1,7 +1,7 @@ /** * @file OgreOggSoundPlugin.h * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * diff --git a/include/OgreOggSoundPrereqs.h b/include/OgreOggSoundPrereqs.h index 94d4c7a..a32bf54 100644 --- a/include/OgreOggSoundPrereqs.h +++ b/include/OgreOggSoundPrereqs.h @@ -1,7 +1,7 @@ /** * @file OgreOggSoundPrereqs.h * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * @@ -91,14 +91,25 @@ namespace OgreOggSound { - class OgreOggISound; + typedef std::vector BufferList; // A list of the IDs of all OpenAL buffers being used by a sound. This is a vector so that it can be passed around as an array to the various OpenAL functions. + typedef Ogre::SharedPtr BufferListPtr; // An Ogre::SharedPtr to the list of buffer IDs. This makes it easier to pass the values to multiple OgreOggISound instances without having to manage memory. //! Holds information about a static shared audio buffer. struct sharedAudioBuffer { - ALuint mAudioBuffer; /// OpenAL buffer - unsigned int mRefCount; /// Reference counter - OgreOggISound* mParent; /// Parent OgreOggISound ptr for shared properties + sharedAudioBuffer() : + mAudioBuffer(AL_NONE) + ,mRefCount(0) + ,mBuffers() + ,mPlayTime(0.0) + ,mFormat(AL_NONE) + { } + + ALuint mAudioBuffer; /// OpenAL buffer + unsigned int mRefCount; /// Reference counter + BufferListPtr mBuffers; /// The cached common buffers to use between all sounds using this shared audio buffer. + float mPlayTime; /// The cached play time of the audio buffer. + ALenum mFormat; /// The cached format of the audio buffer. }; typedef std::map SharedBufferList; diff --git a/include/OgreOggSoundRecord.h b/include/OgreOggSoundRecord.h index 1c44a7b..b3f00e3 100644 --- a/include/OgreOggSoundRecord.h +++ b/include/OgreOggSoundRecord.h @@ -1,7 +1,7 @@ /** * @file OgreOggSoundRecord.h * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * diff --git a/include/OgreOggStaticSound.h b/include/OgreOggStaticSound.h index 9d54146..c1f1876 100644 --- a/include/OgreOggStaticSound.h +++ b/include/OgreOggStaticSound.h @@ -1,7 +1,7 @@ /** * @file OgreOggStaticSound.h * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * diff --git a/include/OgreOggStaticWavSound.h b/include/OgreOggStaticWavSound.h index 92e8d13..066a4bf 100644 --- a/include/OgreOggStaticWavSound.h +++ b/include/OgreOggStaticWavSound.h @@ -1,7 +1,7 @@ /** * @file OgreOggStaticWavSound.h * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * diff --git a/include/OgreOggStreamSound.h b/include/OgreOggStreamSound.h index e1f69d3..5700c4c 100644 --- a/include/OgreOggStreamSound.h +++ b/include/OgreOggStreamSound.h @@ -1,7 +1,7 @@ /** * @file OgreOggStreamSound.h * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * diff --git a/include/OgreOggStreamWavSound.h b/include/OgreOggStreamWavSound.h index e9d1ed7..87059ea 100644 --- a/include/OgreOggStreamWavSound.h +++ b/include/OgreOggStreamWavSound.h @@ -1,7 +1,7 @@ /** * @file OgreOggStreamWavSound.h * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * diff --git a/include/apimainpage.txt b/include/apimainpage.txt index df8f5d0..5f1d681 100644 --- a/include/apimainpage.txt +++ b/include/apimainpage.txt @@ -18,7 +18,7 @@ condenses the functionality down to a clean and simple OGRE-fied interface. Its current development status is stable and actively maintained. Current version - is 1.24 (Stable) + is 1.26 So, thanks for checking out the library and I hope it serves as a useful addition to your development tool collection. diff --git a/src/OgreOggISound.cpp b/src/OgreOggISound.cpp index 8dc97f2..bebb44c 100644 --- a/src/OgreOggISound.cpp +++ b/src/OgreOggISound.cpp @@ -1,7 +1,7 @@ /** * @file OgreOggISound.cpp * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * @@ -137,13 +137,17 @@ namespace OgreOggSound format = mFormat; } /*/////////////////////////////////////////////////////////////////*/ - void OgreOggISound::_setSharedProperties(OgreOggISound* s) + void OgreOggISound::_setSharedProperties(sharedAudioBuffer* buffer) { - s->_getSharedProperties(mBuffers, mPlayTime, mFormat); + mBuffers = buffer->mBuffers; + mPlayTime = buffer->mPlayTime; + mFormat = buffer->mFormat; } /*/////////////////////////////////////////////////////////////////*/ void OgreOggISound::play(bool immediate) { + assert(mState != SS_DESTROYED); + #if OGGSOUND_THREADED SoundAction action; action.mSound = mName; @@ -158,6 +162,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggISound::stop(bool immediate) { + assert(mState != SS_DESTROYED); + #if OGGSOUND_THREADED SoundAction action; action.mSound = mName; @@ -172,6 +178,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggISound::pause(bool immediate) { + assert(mState != SS_DESTROYED); + #if OGGSOUND_THREADED SoundAction action; action.mSound = mName; diff --git a/src/OgreOggListener.cpp b/src/OgreOggListener.cpp index 4ac43ce..4b6558a 100644 --- a/src/OgreOggListener.cpp +++ b/src/OgreOggListener.cpp @@ -1,7 +1,7 @@ /** * @file OgreOggListener.cpp * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * @@ -36,9 +36,24 @@ namespace OgreOggSound { +#if OGGSOUND_THREADED +# ifdef POCO_THREAD + Poco::Mutex OgreOggSound::OgreOggListener::mMutex; +# else + boost::recursive_mutex OgreOggSound::OgreOggListener::mMutex; +# endif +#endif + /*/////////////////////////////////////////////////////////////////*/ void OgreOggListener::setPosition(ALfloat x, ALfloat y, ALfloat z) { +#if OGGSOUND_THREADED +# ifdef POCO_THREAD + Poco::Mutex::ScopedLock l(mMutex); +# else + boost::recursive_mutex::scoped_lock lock(mMutex); +# endif +#endif mPosition.x = x; mPosition.y = y; mPosition.z = z; @@ -47,10 +62,30 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggListener::setPosition(const Ogre::Vector3 &pos) { +#if OGGSOUND_THREADED +# ifdef POCO_THREAD + Poco::Mutex::ScopedLock l(mMutex); +# else + boost::recursive_mutex::scoped_lock lock(mMutex); +# endif +#endif mPosition = pos; alListener3f(AL_POSITION,pos.x,pos.y,pos.z); } /*/////////////////////////////////////////////////////////////////*/ + Ogre::Vector3 OgreOggListener::getPosition() const + { + Ogre::Vector3 result; +#if OGGSOUND_THREADED + mMutex.lock(); +#endif + result = mPosition; +#if OGGSOUND_THREADED + mMutex.unlock(); +#endif + return result; + } + /*/////////////////////////////////////////////////////////////////*/ void OgreOggListener::setVelocity(float velx, float vely, float velz) { mVelocity.x = velx; @@ -67,6 +102,13 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggListener::setOrientation(ALfloat x,ALfloat y,ALfloat z,ALfloat upx,ALfloat upy,ALfloat upz) { +#if OGGSOUND_THREADED +# ifdef POCO_THREAD + Poco::Mutex::ScopedLock l(mMutex); +# else + boost::recursive_mutex::scoped_lock lock(mMutex); +# endif +#endif mOrientation[0] = x; mOrientation[1] = y; mOrientation[2] = z; @@ -78,6 +120,13 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggListener::setOrientation(const Ogre::Quaternion &q) { +#if OGGSOUND_THREADED +# ifdef POCO_THREAD + Poco::Mutex::ScopedLock l(mMutex); +# else + boost::recursive_mutex::scoped_lock lock(mMutex); +# endif +#endif Ogre::Vector3 vDirection = q.zAxis(); Ogre::Vector3 vUp = q.yAxis(); @@ -90,6 +139,20 @@ namespace OgreOggSound alListenerfv(AL_ORIENTATION,mOrientation); } /*/////////////////////////////////////////////////////////////////*/ + Ogre::Vector3 OgreOggListener::getOrientation() const + { + Ogre::Vector3 result; +#if OGGSOUND_THREADED + mMutex.lock(); +#endif + result = Ogre::Vector3(mOrientation[0],mOrientation[1],mOrientation[2]); +#if OGGSOUND_THREADED + mMutex.unlock(); +#endif + + return result; + } + /*/////////////////////////////////////////////////////////////////*/ void OgreOggListener::update() { if(mLocalTransformDirty) diff --git a/src/OgreOggSoundFactory.cpp b/src/OgreOggSoundFactory.cpp index 839e6d8..3ef8ef2 100644 --- a/src/OgreOggSoundFactory.cpp +++ b/src/OgreOggSoundFactory.cpp @@ -1,7 +1,7 @@ /** * @file OgreOggSoundFactory.cpp * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * diff --git a/src/OgreOggSoundManager.cpp b/src/OgreOggSoundManager.cpp index 553b35a..aaac94a 100644 --- a/src/OgreOggSoundManager.cpp +++ b/src/OgreOggSoundManager.cpp @@ -1,7 +1,7 @@ /** * @file OgreOggSoundManager.cpp * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * @@ -57,7 +57,7 @@ namespace OgreOggSound { using namespace Ogre; - const Ogre::String OgreOggSoundManager::OGREOGGSOUND_VERSION_STRING = "OgreOggSound v1.25"; + const Ogre::String OgreOggSoundManager::OGREOGGSOUND_VERSION_STRING = "OgreOggSound v1.26"; /*/////////////////////////////////////////////////////////////////*/ OgreOggSoundManager::OgreOggSoundManager() : @@ -870,8 +870,16 @@ namespace OgreOggSound if (!mSoundsToDestroy->empty() ) { OgreOggISound* s=0; - if ( mSoundsToDestroy->pop(s) ) - _destroySoundImpl(s); + int count=0; + do + { + if ( mSoundsToDestroy->pop(s) ) + { + _destroySoundImpl(s); + count++; + } + } + while(!mSoundsToDestroy->empty() && count<5); } } } @@ -1050,9 +1058,9 @@ namespace OgreOggSound d1 = snd1->getPosition().distance(mListener->getPosition()); if ( sound->isRelativeToListener() ) - d1 = sound->getPosition().length(); + d2 = sound->getPosition().length(); else - d1 = sound->getPosition().distance(mListener->getPosition()); + d2 = sound->getPosition().distance(mListener->getPosition()); // Needs swapping? if ( d1>d2 ) @@ -2143,6 +2151,9 @@ namespace OgreOggSound { // Use shared buffer if available sound->_openImpl(file, buffer); + + // Increment the reference count since this buffer is now being used for another sound. + ++buffer->mRefCount; } // If requested to preBuffer - grab free source and init @@ -2359,6 +2370,14 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggSoundManager::_releaseAll() { + // Clear all of the various containers of sounds. This will make releasing MUCH faster since each sound won't have to + // bother searching for and manually removing themselves from the lists, which really doesn't matter when everything is + // being destroyed. + mSoundsToReactivate.clear(); + mPausedSounds.clear(); + mWaitingSounds.clear(); + mActiveSounds.clear(); + stopAllSounds(); _destroyAllSoundsImpl(); @@ -2526,7 +2545,7 @@ namespace OgreOggSound alDeleteBuffers(1, &f->second->mAudioBuffer); // Delete struct - OGRE_FREE(f->second, Ogre::MEMCATEGORY_GENERAL); + OGRE_DELETE_T(f->second, sharedAudioBuffer, Ogre::MEMCATEGORY_GENERAL); // Remove from list mSharedBuffers.erase(f); @@ -2545,7 +2564,7 @@ namespace OgreOggSound if ( ( f = mSharedBuffers.find(sName) ) == mSharedBuffers.end() ) { // Create struct - sharedAudioBuffer* buf = OGRE_ALLOC_T(sharedAudioBuffer, 1, Ogre::MEMCATEGORY_GENERAL); + sharedAudioBuffer* buf = OGRE_NEW_T(sharedAudioBuffer, Ogre::MEMCATEGORY_GENERAL); // Set buffer buf->mAudioBuffer = buffer; @@ -2553,8 +2572,8 @@ namespace OgreOggSound // Set ref count buf->mRefCount = 1; - // Set parent ptr - buf->mParent = parent; + // Copy the shared information into the buffer so it can be passed around to every other sound that needs it. + parent->_getSharedProperties(buf->mBuffers, buf->mPlayTime, buf->mFormat); // Add to list mSharedBuffers[sName] = buf; diff --git a/src/OgreOggSoundPlugin.cpp b/src/OgreOggSoundPlugin.cpp index 4b35512..c370b6d 100644 --- a/src/OgreOggSoundPlugin.cpp +++ b/src/OgreOggSoundPlugin.cpp @@ -1,7 +1,7 @@ /** * @file OgreOggSoundPlugin.cpp * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * diff --git a/src/OgreOggSoundPluginDllStart.cpp b/src/OgreOggSoundPluginDllStart.cpp index 0825045..c2a50fa 100644 --- a/src/OgreOggSoundPluginDllStart.cpp +++ b/src/OgreOggSoundPluginDllStart.cpp @@ -1,7 +1,7 @@ /** * @file OgreOggSoundPluginDllStart.cpp * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * diff --git a/src/OgreOggSoundRecord.cpp b/src/OgreOggSoundRecord.cpp index e6b56c0..e5a12d7 100644 --- a/src/OgreOggSoundRecord.cpp +++ b/src/OgreOggSoundRecord.cpp @@ -1,7 +1,7 @@ /** * @file OgreOggSoundRecord.cpp * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * diff --git a/src/OgreOggStaticSound.cpp b/src/OgreOggStaticSound.cpp index 3523334..2356c56 100644 --- a/src/OgreOggStaticSound.cpp +++ b/src/OgreOggStaticSound.cpp @@ -1,7 +1,7 @@ /** * @file OgreOggStaticSound.cpp * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * @@ -46,7 +46,7 @@ namespace OgreOggSound ,mAudioName("") { mStream=false; - mBuffers.bind(new std::vector(1, AL_NONE)); + mBuffers.bind(new BufferList(1, AL_NONE)); } /*/////////////////////////////////////////////////////////////////*/ OgreOggStaticSound::~OgreOggStaticSound() @@ -132,7 +132,7 @@ namespace OgreOggSound if ( !buffer ) return; // Set buffer - _setSharedProperties(buffer->mParent); + _setSharedProperties(buffer); // Filename mAudioName = fName; @@ -283,6 +283,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggStaticSound::_pauseImpl() { + assert(mState != SS_DESTROYED); + if ( mSource==AL_NONE ) return; alSourcePause(mSource); @@ -295,6 +297,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggStaticSound::_playImpl() { + assert(mState != SS_DESTROYED); + if(isPlaying()) return; @@ -316,6 +320,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggStaticSound::_stopImpl() { + assert(mState != SS_DESTROYED); + if ( mSource==AL_NONE || isStopped() ) return; alSourceStop(mSource); @@ -329,6 +335,7 @@ namespace OgreOggSound // Mark for destruction if (mTemporary) { + mState = SS_DESTROYED; OgreOggSoundManager::getSingletonPtr()->_destroyTemporarySound(this); } // Give up source immediately if specfied diff --git a/src/OgreOggStaticWavSound.cpp b/src/OgreOggStaticWavSound.cpp index 8adb620..12235f4 100644 --- a/src/OgreOggStaticWavSound.cpp +++ b/src/OgreOggStaticWavSound.cpp @@ -1,7 +1,7 @@ /** * @file OgreOggStaticWavSound.cpp * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * @@ -46,7 +46,7 @@ namespace OgreOggSound mStream=false; mFormatData.mFormat=0; mBufferData.clear(); - mBuffers.bind(new std::vector(1, AL_NONE)); + mBuffers.bind(new BufferList(1, AL_NONE)); } /*/////////////////////////////////////////////////////////////////*/ OgreOggStaticWavSound::~OgreOggStaticWavSound() @@ -214,7 +214,7 @@ namespace OgreOggSound if ( !buffer ) return; // Set buffer - _setSharedProperties(buffer->mParent); + _setSharedProperties(buffer); // Filename mAudioName = fName; @@ -408,6 +408,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggStaticWavSound::_pauseImpl() { + assert(mState != SS_DESTROYED); + if ( mSource==AL_NONE ) return; alSourcePause(mSource); @@ -419,6 +421,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggStaticWavSound::_playImpl() { + assert(mState != SS_DESTROYED); + if(isPlaying()) return; @@ -439,6 +443,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggStaticWavSound::_stopImpl() { + assert(mState != SS_DESTROYED); + if ( mSource==AL_NONE ) return; alSourceStop(mSource); @@ -448,6 +454,7 @@ namespace OgreOggSound if (mTemporary) { + mState = SS_DESTROYED; OgreOggSoundManager::getSingleton()._destroyTemporarySound(this); } // Give up source immediately if specfied diff --git a/src/OgreOggStreamSound.cpp b/src/OgreOggStreamSound.cpp index 2124216..5b1409f 100644 --- a/src/OgreOggStreamSound.cpp +++ b/src/OgreOggStreamSound.cpp @@ -1,7 +1,7 @@ /** * @file OgreOggStreamSound.cpp * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * @@ -45,7 +45,7 @@ namespace OgreOggSound ,mLastOffset(0.f) { mStream=true; - mBuffers.bind(new std::vector(NUM_BUFFERS, AL_NONE)); + mBuffers.bind(new BufferList(NUM_BUFFERS, AL_NONE)); } /*/////////////////////////////////////////////////////////////////*/ OgreOggStreamSound::~OgreOggStreamSound() @@ -503,6 +503,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggStreamSound::_pauseImpl() { + assert(mState != SS_DESTROYED); + if(mSource == AL_NONE) return; alSourcePause(mSource); @@ -514,6 +516,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggStreamSound::_playImpl() { + assert(mState != SS_DESTROYED); + if (isPlaying()) return; @@ -539,6 +543,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggStreamSound::_stopImpl() { + assert(mState != SS_DESTROYED); + if(mSource != AL_NONE) { // Remove audio data from source @@ -549,6 +555,7 @@ namespace OgreOggSound if (mTemporary) { + mState = SS_DESTROYED; OgreOggSoundManager::getSingletonPtr()->_destroyTemporarySound(this); return; } diff --git a/src/OgreOggStreamWavSound.cpp b/src/OgreOggStreamWavSound.cpp index b415434..ed53318 100644 --- a/src/OgreOggStreamWavSound.cpp +++ b/src/OgreOggStreamWavSound.cpp @@ -1,7 +1,7 @@ /** * @file OgreOggStreamWavSound.cpp * @author Ian Stangoe -* @version v1.25 +* @version v1.26 * * @section LICENSE * @@ -44,7 +44,7 @@ namespace OgreOggSound , mStreamEOF(false) , mLastOffset(0.f) { - mBuffers.bind(new std::vector(NUM_BUFFERS, AL_NONE)); + mBuffers.bind(new BufferList(NUM_BUFFERS, AL_NONE)); mFormatData.mFormat=0; mStream = true; } @@ -625,6 +625,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggStreamWavSound::_pauseImpl() { + assert(mState != SS_DESTROYED); + if(mSource == AL_NONE) return; alSourcePause(mSource); @@ -636,6 +638,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggStreamWavSound::_playImpl() { + assert(mState != SS_DESTROYED); + if(isPlaying()) return; // Grab a source if not already attached @@ -721,6 +725,8 @@ namespace OgreOggSound /*/////////////////////////////////////////////////////////////////*/ void OgreOggStreamWavSound::_stopImpl() { + assert(mState != SS_DESTROYED); + if(mSource != AL_NONE) { // Remove audio data from source @@ -739,6 +745,7 @@ namespace OgreOggSound if (mTemporary) { + mState = SS_DESTROYED; OgreOggSoundManager::getSingleton()._destroyTemporarySound(this); } // Give up source immediately if specfied