Return SoundPtr objects from the playSound and streamSound methods

actorid
Chris Robinson 13 years ago
parent f0db2ab82f
commit c6c06f1140

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

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

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

@ -136,7 +136,7 @@ namespace MWSound
{
if(mMusic)
mMusic->stop();
mMusic.reset(mOutput->streamSound(filename, 0.4f, 1.0f));
mMusic = mOutput->streamSound(filename, 0.4f, 1.0f);
}
catch(std::exception &e)
{
@ -180,7 +180,7 @@ namespace MWSound
const ESM::Position &pos = ptr.getCellRef().pos;
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;
}
catch(std::exception &e)
@ -201,7 +201,7 @@ namespace MWSound
try
{
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;
}
catch(std::exception &e)
@ -220,7 +220,7 @@ namespace MWSound
const ESM::Position &pos = ptr.getCellRef().pos;
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;
}
catch(std::exception &e)

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

Loading…
Cancel
Save