1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 11:53:53 +00:00

Return SoundPtr objects from the playSound and streamSound methods

This commit is contained in:
Chris Robinson 2012-03-27 05:59:09 -07:00
parent f0db2ab82f
commit c6c06f1140
5 changed files with 33 additions and 31 deletions

View file

@ -559,11 +559,11 @@ void OpenAL_Output::bufferFinished(ALuint buf)
} }
Sound* OpenAL_Output::playSound(const std::string &fname, float volume, float pitch, bool loop) SoundPtr OpenAL_Output::playSound(const std::string &fname, float volume, float pitch, bool loop)
{ {
throwALerror(); throwALerror();
std::auto_ptr<OpenAL_Sound> sound; boost::shared_ptr<OpenAL_Sound> sound;
ALuint src=0, buf=0; ALuint src=0, buf=0;
if(mFreeSources.empty()) if(mFreeSources.empty())
@ -604,15 +604,15 @@ Sound* OpenAL_Output::playSound(const std::string &fname, float volume, float pi
alSourcePlay(src); alSourcePlay(src);
throwALerror(); throwALerror();
return sound.release(); return sound;
} }
Sound* OpenAL_Output::playSound3D(const std::string &fname, const float *pos, float volume, float pitch, SoundPtr OpenAL_Output::playSound3D(const std::string &fname, const float *pos, float volume, float pitch,
float min, float max, bool loop) float min, float max, bool loop)
{ {
throwALerror(); throwALerror();
std::auto_ptr<OpenAL_Sound> sound; boost::shared_ptr<OpenAL_Sound> sound;
ALuint src=0, buf=0; ALuint src=0, buf=0;
if(mFreeSources.empty()) if(mFreeSources.empty())
@ -653,15 +653,15 @@ Sound* OpenAL_Output::playSound3D(const std::string &fname, const float *pos, fl
alSourcePlay(src); alSourcePlay(src);
throwALerror(); throwALerror();
return sound.release(); return sound;
} }
Sound* OpenAL_Output::streamSound(const std::string &fname, float volume, float pitch) SoundPtr OpenAL_Output::streamSound(const std::string &fname, float volume, float pitch)
{ {
throwALerror(); throwALerror();
std::auto_ptr<OpenAL_SoundStream> sound; boost::shared_ptr<OpenAL_SoundStream> sound;
ALuint src; ALuint src;
if(mFreeSources.empty()) if(mFreeSources.empty())
@ -697,15 +697,15 @@ Sound* OpenAL_Output::streamSound(const std::string &fname, float volume, float
throwALerror(); throwALerror();
sound->play(); sound->play();
return sound.release(); return sound;
} }
Sound* OpenAL_Output::streamSound3D(const std::string &fname, const float *pos, float volume, float pitch, SoundPtr OpenAL_Output::streamSound3D(const std::string &fname, const float *pos, float volume, float pitch,
float min, float max) float min, float max)
{ {
throwALerror(); throwALerror();
std::auto_ptr<OpenAL_SoundStream> sound; boost::shared_ptr<OpenAL_SoundStream> sound;
ALuint src; ALuint src;
if(mFreeSources.empty()) if(mFreeSources.empty())
@ -741,7 +741,7 @@ Sound* OpenAL_Output::streamSound3D(const std::string &fname, const float *pos,
throwALerror(); throwALerror();
sound->play(); sound->play();
return sound.release(); return sound;
} }

View file

@ -42,13 +42,13 @@ namespace MWSound
virtual void init(const std::string &devname=""); virtual void init(const std::string &devname="");
virtual void deinit(); virtual void deinit();
virtual Sound *playSound(const std::string &fname, float volume, float pitch, bool loop); virtual SoundPtr 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, virtual SoundPtr playSound3D(const std::string &fname, const float *pos, float volume, float pitch,
float min, float max, bool loop); float min, float max, bool loop);
virtual Sound *streamSound(const std::string &fname, float volume, float pitch); virtual SoundPtr streamSound(const std::string &fname, float volume, float pitch);
virtual Sound *streamSound3D(const std::string &fname, const float *pos, float volume, float pitch, virtual SoundPtr streamSound3D(const std::string &fname, const float *pos, float volume, float pitch,
float min, float max); float min, float max);
virtual void updateListener(const float *pos, const float *atdir, const float *updir); virtual void updateListener(const float *pos, const float *atdir, const float *updir);

View file

@ -4,6 +4,8 @@
#include <string> #include <string>
#include <memory> #include <memory>
#include "soundmanager.hpp"
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
namespace MWSound namespace MWSound
@ -20,12 +22,12 @@ namespace MWSound
virtual void init(const std::string &devname="") = 0; virtual void init(const std::string &devname="") = 0;
virtual void deinit() = 0; virtual void deinit() = 0;
virtual Sound *playSound(const std::string &fname, float volume, float pitch, bool loop) = 0; virtual SoundPtr 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, virtual SoundPtr playSound3D(const std::string &fname, const float *pos, float volume, float pitch,
float min, float max, bool loop) = 0; float min, float max, bool loop) = 0;
virtual Sound *streamSound(const std::string &fname, float volume, float pitch) = 0; virtual SoundPtr streamSound(const std::string &fname, float volume, float pitch) = 0;
virtual Sound *streamSound3D(const std::string &fname, const float *pos, float volume, float pitch, virtual SoundPtr streamSound3D(const std::string &fname, const float *pos, float volume, float pitch,
float min, float max) = 0; float min, float max) = 0;
virtual void updateListener(const float *pos, const float *atdir, const float *updir) = 0; virtual void updateListener(const float *pos, const float *atdir, const float *updir) = 0;

View file

@ -136,7 +136,7 @@ namespace MWSound
{ {
if(mMusic) if(mMusic)
mMusic->stop(); mMusic->stop();
mMusic.reset(mOutput->streamSound(filename, 0.4f, 1.0f)); mMusic = mOutput->streamSound(filename, 0.4f, 1.0f);
} }
catch(std::exception &e) catch(std::exception &e)
{ {
@ -180,7 +180,7 @@ namespace MWSound
const ESM::Position &pos = ptr.getCellRef().pos; const ESM::Position &pos = ptr.getCellRef().pos;
std::string filePath = std::string("Sound/")+filename; std::string filePath = std::string("Sound/")+filename;
SoundPtr sound(mOutput->playSound3D(filePath, pos.pos, 1.0f, 1.0f, 100.0f, 20000.0f, false)); SoundPtr sound = mOutput->playSound3D(filePath, pos.pos, 1.0f, 1.0f, 100.0f, 20000.0f, false);
mActiveSounds[std::make_pair(ptr, std::string("_say_sound"))] = sound; mActiveSounds[std::make_pair(ptr, std::string("_say_sound"))] = sound;
} }
catch(std::exception &e) catch(std::exception &e)
@ -201,7 +201,7 @@ namespace MWSound
try try
{ {
std::string file = lookup(soundId, volume, min, max); std::string file = lookup(soundId, volume, min, max);
SoundPtr sound = SoundPtr(mOutput->playSound(file, volume, pitch, loop)); SoundPtr sound = mOutput->playSound(file, volume, pitch, loop);
mActiveSounds[std::make_pair(MWWorld::Ptr(), soundId)] = sound; mActiveSounds[std::make_pair(MWWorld::Ptr(), soundId)] = sound;
} }
catch(std::exception &e) catch(std::exception &e)
@ -220,7 +220,7 @@ namespace MWSound
const ESM::Position &pos = ptr.getCellRef().pos; const ESM::Position &pos = ptr.getCellRef().pos;
std::string file = lookup(soundId, volume, min, max); std::string file = lookup(soundId, volume, min, max);
SoundPtr sound(mOutput->playSound3D(file, pos.pos, volume, pitch, min, max, loop)); SoundPtr sound = mOutput->playSound3D(file, pos.pos, volume, pitch, min, max, loop);
mActiveSounds[std::make_pair((untracked?MWWorld::Ptr():ptr), soundId)] = sound; mActiveSounds[std::make_pair((untracked?MWWorld::Ptr():ptr), soundId)] = sound;
} }
catch(std::exception &e) catch(std::exception &e)

View file

@ -28,6 +28,7 @@ namespace MWSound
class Sound; class Sound;
typedef boost::shared_ptr<Sound_Decoder> DecoderPtr; typedef boost::shared_ptr<Sound_Decoder> DecoderPtr;
typedef boost::shared_ptr<Sound> SoundPtr;
class SoundManager class SoundManager
{ {
@ -40,7 +41,6 @@ namespace MWSound
boost::shared_ptr<Sound> mMusic; boost::shared_ptr<Sound> mMusic;
std::string mCurrentPlaylist; std::string mCurrentPlaylist;
typedef boost::shared_ptr<Sound> SoundPtr;
typedef std::pair<MWWorld::Ptr,std::string> PtrIDPair; typedef std::pair<MWWorld::Ptr,std::string> PtrIDPair;
typedef std::map<PtrIDPair,SoundPtr> SoundMap; typedef std::map<PtrIDPair,SoundPtr> SoundMap;
SoundMap mActiveSounds; SoundMap mActiveSounds;