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);
|
virtual size_t Read(char *buffer, size_t bytes);
|
||||||
|
|
||||||
MpgSnd_Decoder();
|
MpgSnd_Decoder();
|
||||||
|
public:
|
||||||
virtual ~MpgSnd_Decoder();
|
virtual ~MpgSnd_Decoder();
|
||||||
|
|
||||||
friend class SoundManager;
|
friend class SoundManager;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "openal_output.hpp"
|
#include "openal_output.hpp"
|
||||||
#include "sound_decoder.hpp"
|
#include "sound_decoder.hpp"
|
||||||
#include "sound.hpp"
|
#include "sound.hpp"
|
||||||
|
#include "soundmanager.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace MWSound
|
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;
|
int srate;
|
||||||
Sound_Decoder::ChannelConfig chans;
|
Sound_Decoder::ChannelConfig chans;
|
||||||
|
@ -86,10 +87,10 @@ class OpenAL_SoundStream : public Sound
|
||||||
ALenum Format;
|
ALenum Format;
|
||||||
ALsizei SampleRate;
|
ALsizei SampleRate;
|
||||||
|
|
||||||
std::auto_ptr<Sound_Decoder> Decoder;
|
DecoderPtr Decoder;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OpenAL_SoundStream(std::auto_ptr<Sound_Decoder> decoder);
|
OpenAL_SoundStream(DecoderPtr decoder);
|
||||||
virtual ~OpenAL_SoundStream();
|
virtual ~OpenAL_SoundStream();
|
||||||
|
|
||||||
void Play(float volume, float pitch);
|
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)
|
: Decoder(decoder)
|
||||||
{
|
{
|
||||||
throwALerror();
|
throwALerror();
|
||||||
|
@ -320,11 +321,11 @@ void OpenAL_Output::Deinitialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Sound* OpenAL_Output::PlaySound(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder,
|
Sound* OpenAL_Output::PlaySound(const std::string &fname, float volume, float pitch, bool loop)
|
||||||
float volume, float pitch, bool loop)
|
|
||||||
{
|
{
|
||||||
throwALerror();
|
throwALerror();
|
||||||
|
|
||||||
|
DecoderPtr decoder = mgr.getDecoder();
|
||||||
decoder->Open(fname);
|
decoder->Open(fname);
|
||||||
|
|
||||||
ALuint src=0, buf=0;
|
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();
|
return sound.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
Sound* OpenAL_Output::PlaySound3D(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder,
|
Sound* OpenAL_Output::PlaySound3D(const std::string &fname, const float *pos, float volume, float pitch,
|
||||||
const float *pos, float volume, float pitch,
|
|
||||||
float min, float max, bool loop)
|
float min, float max, bool loop)
|
||||||
{
|
{
|
||||||
throwALerror();
|
throwALerror();
|
||||||
|
|
||||||
|
DecoderPtr decoder = mgr.getDecoder();
|
||||||
decoder->Open(fname);
|
decoder->Open(fname);
|
||||||
|
|
||||||
ALuint src=0, buf=0;
|
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;
|
std::auto_ptr<OpenAL_SoundStream> sound;
|
||||||
|
|
||||||
|
DecoderPtr decoder = mgr.getDecoder();
|
||||||
decoder->Open(fname);
|
decoder->Open(fname);
|
||||||
|
|
||||||
sound.reset(new OpenAL_SoundStream(decoder));
|
sound.reset(new OpenAL_SoundStream(decoder));
|
||||||
|
|
|
@ -22,14 +22,11 @@ namespace MWSound
|
||||||
virtual bool Initialize(const std::string &devname="");
|
virtual bool Initialize(const std::string &devname="");
|
||||||
virtual void Deinitialize();
|
virtual void Deinitialize();
|
||||||
|
|
||||||
virtual Sound *PlaySound(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder,
|
virtual Sound *PlaySound(const std::string &fname, float volume, float pitch, bool loop);
|
||||||
float volume, float pitch, bool loop);
|
virtual Sound *PlaySound3D(const std::string &fname, const float *pos, float volume, float pitch,
|
||||||
virtual Sound *PlaySound3D(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder,
|
|
||||||
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, std::auto_ptr<Sound_Decoder> decoder,
|
virtual Sound *StreamSound(const std::string &fname, float volume, float pitch);
|
||||||
float volume, float pitch);
|
|
||||||
|
|
||||||
virtual void UpdateListener(const float *pos, const float *atdir, const float *updir);
|
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 bool Initialize(const std::string &devname="") = 0;
|
||||||
virtual void Deinitialize() = 0;
|
virtual void Deinitialize() = 0;
|
||||||
|
|
||||||
virtual Sound *PlaySound(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder,
|
virtual Sound *PlaySound(const std::string &fname, float volume, float pitch, bool loop) = 0;
|
||||||
float volume, float pitch, bool loop) = 0;
|
virtual Sound *PlaySound3D(const std::string &fname, const float *pos, float volume, float pitch,
|
||||||
virtual Sound *PlaySound3D(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder,
|
|
||||||
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, std::auto_ptr<Sound_Decoder> decoder,
|
virtual Sound *StreamSound(const std::string &fname, float volume, float pitch) = 0;
|
||||||
float volume, float pitch) = 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;
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,12 @@ namespace MWSound
|
||||||
Output.reset();
|
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
|
// Convert a soundId to file name, and modify the volume
|
||||||
// according to the sounds local volume setting, minRange and
|
// according to the sounds local volume setting, minRange and
|
||||||
// maxRange.
|
// maxRange.
|
||||||
|
@ -124,9 +130,8 @@ namespace MWSound
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Sound *sound;
|
Sound *sound;
|
||||||
const float *pos = ptr.getCellRef().pos.pos;
|
const ESM::Position &pos = ptr.getCellRef().pos;
|
||||||
std::auto_ptr<Sound_Decoder> decoder(new DEFAULT_DECODER);
|
sound = Output->PlaySound3D(file, pos.pos, volume, pitch, min, max, loop);
|
||||||
sound = Output->PlaySound3D(file, decoder, pos, volume, pitch, min, max, loop);
|
|
||||||
if(untracked)
|
if(untracked)
|
||||||
LooseSounds[id] = SoundPtr(sound);
|
LooseSounds[id] = SoundPtr(sound);
|
||||||
else
|
else
|
||||||
|
@ -163,8 +168,7 @@ namespace MWSound
|
||||||
{
|
{
|
||||||
if(mMusic)
|
if(mMusic)
|
||||||
mMusic->Stop();
|
mMusic->Stop();
|
||||||
std::auto_ptr<Sound_Decoder> decoder(new DEFAULT_DECODER);
|
mMusic.reset(Output->StreamSound(filename, 0.4f, 1.0f));
|
||||||
mMusic.reset(Output->StreamSound(filename, decoder, 0.4f, 1.0f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::streamMusic(const std::string& filename)
|
void SoundManager::streamMusic(const std::string& filename)
|
||||||
|
@ -274,8 +278,7 @@ namespace MWSound
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Sound *sound;
|
Sound *sound;
|
||||||
std::auto_ptr<Sound_Decoder> decoder(new DEFAULT_DECODER);
|
sound = Output->PlaySound(file, volume, pitch, loop);
|
||||||
sound = Output->PlaySound(file, decoder, volume, pitch, loop);
|
|
||||||
LooseSounds[soundId] = SoundPtr(sound);
|
LooseSounds[soundId] = SoundPtr(sound);
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
|
|
|
@ -25,6 +25,8 @@ namespace MWSound
|
||||||
class Sound_Decoder;
|
class Sound_Decoder;
|
||||||
class Sound;
|
class Sound;
|
||||||
|
|
||||||
|
typedef boost::shared_ptr<Sound_Decoder> DecoderPtr;
|
||||||
|
|
||||||
class SoundManager
|
class SoundManager
|
||||||
{
|
{
|
||||||
// This is used for case insensitive and slash-type agnostic file
|
// 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;
|
bool isPlaying(MWWorld::Ptr ptr, const std::string &id) const;
|
||||||
void updateRegionSound(float duration);
|
void updateRegionSound(float duration);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
DecoderPtr getDecoder();
|
||||||
|
friend class OpenAL_Output;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SoundManager(Ogre::Root*, Ogre::Camera*,
|
SoundManager(Ogre::Root*, Ogre::Camera*,
|
||||||
const Files::PathContainer& dataDir, bool useSound, bool fsstrict,
|
const Files::PathContainer& dataDir, bool useSound, bool fsstrict,
|
||||||
|
|
Loading…
Reference in a new issue