forked from mirror/openmw-tes3mp
Avoid passing a sound decoder to the play methods
This commit is contained in:
parent
ddfa906922
commit
44fc204864
6 changed files with 34 additions and 28 deletions
|
@ -26,6 +26,7 @@ namespace MWSound
|
|||
virtual size_t Read(char *buffer, size_t bytes);
|
||||
|
||||
MpgSnd_Decoder();
|
||||
public:
|
||||
virtual ~MpgSnd_Decoder();
|
||||
|
||||
friend class SoundManager;
|
||||
|
|
|
@ -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<Sound_Decoder> 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<Sound_Decoder> Decoder;
|
||||
DecoderPtr Decoder;
|
||||
|
||||
public:
|
||||
OpenAL_SoundStream(std::auto_ptr<Sound_Decoder> 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<Sound_Decoder> 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<Sound_Decoder> 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<Sound_De
|
|||
return sound.release();
|
||||
}
|
||||
|
||||
Sound* OpenAL_Output::PlaySound3D(const std::string &fname, std::auto_ptr<Sound_Decoder> 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<Sound_
|
|||
}
|
||||
|
||||
|
||||
Sound* OpenAL_Output::StreamSound(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder, float volume, float pitch)
|
||||
Sound* OpenAL_Output::StreamSound(const std::string &fname, float volume, float pitch)
|
||||
{
|
||||
std::auto_ptr<OpenAL_SoundStream> sound;
|
||||
|
||||
DecoderPtr decoder = mgr.getDecoder();
|
||||
decoder->Open(fname);
|
||||
|
||||
sound.reset(new OpenAL_SoundStream(decoder));
|
||||
|
|
|
@ -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<Sound_Decoder> decoder,
|
||||
float volume, float pitch, bool loop);
|
||||
virtual Sound *PlaySound3D(const std::string &fname, std::auto_ptr<Sound_Decoder> 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<Sound_Decoder> 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);
|
||||
|
||||
|
|
|
@ -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<Sound_Decoder> decoder,
|
||||
float volume, float pitch, bool loop) = 0;
|
||||
virtual Sound *PlaySound3D(const std::string &fname, std::auto_ptr<Sound_Decoder> 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<Sound_Decoder> 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;
|
||||
|
||||
|
|
|
@ -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<Sound_Decoder> 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<Sound_Decoder> 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<Sound_Decoder> 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)
|
||||
|
|
|
@ -25,6 +25,8 @@ namespace MWSound
|
|||
class Sound_Decoder;
|
||||
class Sound;
|
||||
|
||||
typedef boost::shared_ptr<Sound_Decoder> 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,
|
||||
|
|
Loading…
Reference in a new issue