From be337ef7cc99bb5230105e8f19ba943dd06cb60c Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 28 Mar 2012 06:08:25 -0700 Subject: [PATCH] Return SoundPtr objects from playSound[3D] Note that each Sound object currently contains "precious" resources even after the sound is stopped. The reference should be reliquished as soon as it's no longer needed (the SoundManager will make sure the sound continues to play until it's finished). --- apps/openmw/mwsound/sound.hpp | 7 ++++--- apps/openmw/mwsound/soundmanager.cpp | 18 ++++++++++++------ apps/openmw/mwsound/soundmanager.hpp | 8 ++++---- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwsound/sound.hpp b/apps/openmw/mwsound/sound.hpp index b5d010aa0..2cbd48d96 100644 --- a/apps/openmw/mwsound/sound.hpp +++ b/apps/openmw/mwsound/sound.hpp @@ -5,9 +5,6 @@ namespace MWSound { class Sound { - virtual void stop() = 0; - virtual bool isPlaying() = 0; - virtual void setVolume(float volume) = 0; virtual void update(const float *pos) = 0; Sound& operator=(const Sound &rhs); @@ -20,6 +17,10 @@ namespace MWSound float mMaxDistance; public: + virtual void stop() = 0; + virtual bool isPlaying() = 0; + virtual void setVolume(float volume) = 0; + Sound() : mVolume(1.0f) , mBaseVolume(1.0f) , mMinDistance(20.0f) /* 1 * min_range_scale */ diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 8e2ef3a27..ad9e47f72 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -185,7 +185,8 @@ namespace MWSound std::string filePath = std::string("Sound/")+filename; const ESM::Position &pos = ptr.getCellRef().pos; - SoundPtr sound = mOutput->playSound3D(filePath, pos.pos, basevol, 1.0f, 20.0f, 12750.0f, false); + SoundPtr sound = mOutput->playSound3D(filePath, pos.pos, basevol, 1.0f, + 20.0f, 12750.0f, false); sound->mBaseVolume = basevol; mActiveSounds[sound] = std::make_pair(ptr, std::string("_say_sound")); @@ -202,15 +203,16 @@ namespace MWSound } - void SoundManager::playSound(const std::string& soundId, float volume, float pitch, bool loop) + SoundPtr SoundManager::playSound(const std::string& soundId, float volume, float pitch, bool loop) { + SoundPtr sound; try { float basevol = 1.0f; /* TODO: volume settings */ float min, max; std::string file = lookup(soundId, basevol, min, max); - SoundPtr sound = mOutput->playSound(file, volume*basevol, pitch, loop); + sound = mOutput->playSound(file, volume*basevol, pitch, loop); sound->mVolume = volume; sound->mBaseVolume = basevol; sound->mMinDistance = min; @@ -222,11 +224,14 @@ namespace MWSound { std::cout <<"Sound Error: "<playSound3D(file, pos.pos, volume*basevol, pitch, min, max, loop); + sound = mOutput->playSound3D(file, pos.pos, volume*basevol, pitch, min, max, loop); sound->mVolume = volume; sound->mBaseVolume = basevol; sound->mMinDistance = min; @@ -248,6 +253,7 @@ namespace MWSound { std::cout <<"Sound Error: "<