From 44fc204864f15485c53d9f80492679d0b7b19d5a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 17 Mar 2012 23:30:43 -0700 Subject: [PATCH] Avoid passing a sound decoder to the play methods --- apps/openmw/mwsound/mpgsnd_decoder.hpp | 1 + apps/openmw/mwsound/openal_output.cpp | 20 +++++++++++--------- apps/openmw/mwsound/openal_output.hpp | 9 +++------ apps/openmw/mwsound/sound_output.hpp | 9 +++------ apps/openmw/mwsound/soundmanager.cpp | 17 ++++++++++------- apps/openmw/mwsound/soundmanager.hpp | 6 ++++++ 6 files changed, 34 insertions(+), 28 deletions(-) diff --git a/apps/openmw/mwsound/mpgsnd_decoder.hpp b/apps/openmw/mwsound/mpgsnd_decoder.hpp index 391cfbd6d..cd7e468da 100644 --- a/apps/openmw/mwsound/mpgsnd_decoder.hpp +++ b/apps/openmw/mwsound/mpgsnd_decoder.hpp @@ -26,6 +26,7 @@ namespace MWSound virtual size_t Read(char *buffer, size_t bytes); MpgSnd_Decoder(); + public: virtual ~MpgSnd_Decoder(); friend class SoundManager; diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index 0cff2303f..e9df0738b 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -5,6 +5,7 @@ #include "openal_output.hpp" #include "sound_decoder.hpp" #include "sound.hpp" +#include "soundmanager.hpp" namespace MWSound @@ -47,7 +48,7 @@ static ALenum getALFormat(Sound_Decoder::ChannelConfig chans, Sound_Decoder::Sam } -ALuint LoadBuffer(std::auto_ptr decoder) +ALuint LoadBuffer(DecoderPtr decoder) { int srate; Sound_Decoder::ChannelConfig chans; @@ -86,10 +87,10 @@ class OpenAL_SoundStream : public Sound ALenum Format; ALsizei SampleRate; - std::auto_ptr Decoder; + DecoderPtr Decoder; public: - OpenAL_SoundStream(std::auto_ptr decoder); + OpenAL_SoundStream(DecoderPtr decoder); virtual ~OpenAL_SoundStream(); void Play(float volume, float pitch); @@ -113,7 +114,7 @@ public: }; -OpenAL_SoundStream::OpenAL_SoundStream(std::auto_ptr decoder) +OpenAL_SoundStream::OpenAL_SoundStream(DecoderPtr decoder) : Decoder(decoder) { throwALerror(); @@ -320,11 +321,11 @@ void OpenAL_Output::Deinitialize() } -Sound* OpenAL_Output::PlaySound(const std::string &fname, std::auto_ptr decoder, - float volume, float pitch, bool loop) +Sound* OpenAL_Output::PlaySound(const std::string &fname, float volume, float pitch, bool loop) { throwALerror(); + DecoderPtr decoder = mgr.getDecoder(); decoder->Open(fname); ALuint src=0, buf=0; @@ -367,12 +368,12 @@ Sound* OpenAL_Output::PlaySound(const std::string &fname, std::auto_ptr decoder, - const float *pos, float volume, float pitch, +Sound* OpenAL_Output::PlaySound3D(const std::string &fname, const float *pos, float volume, float pitch, float min, float max, bool loop) { throwALerror(); + DecoderPtr decoder = mgr.getDecoder(); decoder->Open(fname); ALuint src=0, buf=0; @@ -416,10 +417,11 @@ Sound* OpenAL_Output::PlaySound3D(const std::string &fname, std::auto_ptr decoder, float volume, float pitch) +Sound* OpenAL_Output::StreamSound(const std::string &fname, float volume, float pitch) { std::auto_ptr sound; + DecoderPtr decoder = mgr.getDecoder(); decoder->Open(fname); sound.reset(new OpenAL_SoundStream(decoder)); diff --git a/apps/openmw/mwsound/openal_output.hpp b/apps/openmw/mwsound/openal_output.hpp index b941aea3a..7d5bd25f6 100644 --- a/apps/openmw/mwsound/openal_output.hpp +++ b/apps/openmw/mwsound/openal_output.hpp @@ -22,14 +22,11 @@ namespace MWSound virtual bool Initialize(const std::string &devname=""); virtual void Deinitialize(); - virtual Sound *PlaySound(const std::string &fname, std::auto_ptr decoder, - float volume, float pitch, bool loop); - virtual Sound *PlaySound3D(const std::string &fname, std::auto_ptr decoder, - const float *pos, float volume, float pitch, + virtual Sound *PlaySound(const std::string &fname, float volume, float pitch, bool loop); + virtual Sound *PlaySound3D(const std::string &fname, const float *pos, float volume, float pitch, float min, float max, bool loop); - virtual Sound *StreamSound(const std::string &fname, std::auto_ptr decoder, - float volume, float pitch); + virtual Sound *StreamSound(const std::string &fname, float volume, float pitch); virtual void UpdateListener(const float *pos, const float *atdir, const float *updir); diff --git a/apps/openmw/mwsound/sound_output.hpp b/apps/openmw/mwsound/sound_output.hpp index c69247cc9..8dfc0f21e 100644 --- a/apps/openmw/mwsound/sound_output.hpp +++ b/apps/openmw/mwsound/sound_output.hpp @@ -19,13 +19,10 @@ namespace MWSound virtual bool Initialize(const std::string &devname="") = 0; virtual void Deinitialize() = 0; - virtual Sound *PlaySound(const std::string &fname, std::auto_ptr decoder, - float volume, float pitch, bool loop) = 0; - virtual Sound *PlaySound3D(const std::string &fname, std::auto_ptr decoder, - const float *pos, float volume, float pitch, + virtual Sound *PlaySound(const std::string &fname, float volume, float pitch, bool loop) = 0; + virtual Sound *PlaySound3D(const std::string &fname, const float *pos, float volume, float pitch, float min, float max, bool loop) = 0; - virtual Sound *StreamSound(const std::string &fname, std::auto_ptr decoder, - float volume, float pitch) = 0; + virtual Sound *StreamSound(const std::string &fname, float volume, float pitch) = 0; virtual void UpdateListener(const float *pos, const float *atdir, const float *updir) = 0; diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 7cd8f4ea7..a603763e5 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -83,6 +83,12 @@ namespace MWSound Output.reset(); } + // Return a new decoder instance, used as needed by the output implementations + DecoderPtr SoundManager::getDecoder() + { + return DecoderPtr(new DEFAULT_DECODER); + } + // Convert a soundId to file name, and modify the volume // according to the sounds local volume setting, minRange and // maxRange. @@ -124,9 +130,8 @@ namespace MWSound try { Sound *sound; - const float *pos = ptr.getCellRef().pos.pos; - std::auto_ptr decoder(new DEFAULT_DECODER); - sound = Output->PlaySound3D(file, decoder, pos, volume, pitch, min, max, loop); + const ESM::Position &pos = ptr.getCellRef().pos; + sound = Output->PlaySound3D(file, pos.pos, volume, pitch, min, max, loop); if(untracked) LooseSounds[id] = SoundPtr(sound); else @@ -163,8 +168,7 @@ namespace MWSound { if(mMusic) mMusic->Stop(); - std::auto_ptr decoder(new DEFAULT_DECODER); - mMusic.reset(Output->StreamSound(filename, decoder, 0.4f, 1.0f)); + mMusic.reset(Output->StreamSound(filename, 0.4f, 1.0f)); } void SoundManager::streamMusic(const std::string& filename) @@ -274,8 +278,7 @@ namespace MWSound try { Sound *sound; - std::auto_ptr decoder(new DEFAULT_DECODER); - sound = Output->PlaySound(file, decoder, volume, pitch, loop); + sound = Output->PlaySound(file, volume, pitch, loop); LooseSounds[soundId] = SoundPtr(sound); } catch(std::exception &e) diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index 62e452cde..6b188c9e4 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -25,6 +25,8 @@ namespace MWSound class Sound_Decoder; class Sound; + typedef boost::shared_ptr DecoderPtr; + class SoundManager { // This is used for case insensitive and slash-type agnostic file @@ -67,6 +69,10 @@ namespace MWSound bool isPlaying(MWWorld::Ptr ptr, const std::string &id) const; void updateRegionSound(float duration); + protected: + DecoderPtr getDecoder(); + friend class OpenAL_Output; + public: SoundManager(Ogre::Root*, Ogre::Camera*, const Files::PathContainer& dataDir, bool useSound, bool fsstrict,