mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 11:39:41 +00:00
Mute sounds that go outside the max distance
This commit is contained in:
parent
fc167dbc83
commit
5adeee20fd
1 changed files with 22 additions and 12 deletions
|
@ -77,6 +77,7 @@ class OpenAL_SoundStream : public Sound
|
||||||
ALuint mBufferSize;
|
ALuint mBufferSize;
|
||||||
|
|
||||||
DecoderPtr mDecoder;
|
DecoderPtr mDecoder;
|
||||||
|
bool mIs3D;
|
||||||
|
|
||||||
volatile bool mIsFinished;
|
volatile bool mIsFinished;
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ class OpenAL_SoundStream : public Sound
|
||||||
OpenAL_SoundStream& operator=(const OpenAL_SoundStream &rhs);
|
OpenAL_SoundStream& operator=(const OpenAL_SoundStream &rhs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OpenAL_SoundStream(OpenAL_Output &output, ALuint src, DecoderPtr decoder);
|
OpenAL_SoundStream(OpenAL_Output &output, ALuint src, DecoderPtr decoder, bool is3D);
|
||||||
virtual ~OpenAL_SoundStream();
|
virtual ~OpenAL_SoundStream();
|
||||||
|
|
||||||
virtual void stop();
|
virtual void stop();
|
||||||
|
@ -164,8 +165,8 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
OpenAL_SoundStream::OpenAL_SoundStream(OpenAL_Output &output, ALuint src, DecoderPtr decoder)
|
OpenAL_SoundStream::OpenAL_SoundStream(OpenAL_Output &output, ALuint src, DecoderPtr decoder, bool is3D)
|
||||||
: mOutput(output), mSource(src), mDecoder(decoder), mIsFinished(true)
|
: mOutput(output), mSource(src), mDecoder(decoder), mIs3D(is3D), mIsFinished(true)
|
||||||
{
|
{
|
||||||
throwALerror();
|
throwALerror();
|
||||||
|
|
||||||
|
@ -256,7 +257,10 @@ bool OpenAL_SoundStream::isPlaying()
|
||||||
|
|
||||||
void OpenAL_SoundStream::update()
|
void OpenAL_SoundStream::update()
|
||||||
{
|
{
|
||||||
alSourcef(mSource, AL_GAIN, mVolume*mBaseVolume);
|
if(mIs3D && mPos.squaredDistance(mOutput.mPos) > mMaxDistance*mMaxDistance)
|
||||||
|
alSourcef(mSource, AL_GAIN, 0.0f);
|
||||||
|
else
|
||||||
|
alSourcef(mSource, AL_GAIN, mVolume*mBaseVolume);
|
||||||
alSource3f(mSource, AL_POSITION, mPos[0], mPos[2], -mPos[1]);
|
alSource3f(mSource, AL_POSITION, mPos[0], mPos[2], -mPos[1]);
|
||||||
alSource3f(mSource, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
|
alSource3f(mSource, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
|
||||||
alSource3f(mSource, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
|
alSource3f(mSource, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
|
||||||
|
@ -323,11 +327,13 @@ class OpenAL_Sound : public Sound
|
||||||
ALuint mSource;
|
ALuint mSource;
|
||||||
ALuint mBuffer;
|
ALuint mBuffer;
|
||||||
|
|
||||||
|
bool mIs3D;
|
||||||
|
|
||||||
OpenAL_Sound(const OpenAL_Sound &rhs);
|
OpenAL_Sound(const OpenAL_Sound &rhs);
|
||||||
OpenAL_Sound& operator=(const OpenAL_Sound &rhs);
|
OpenAL_Sound& operator=(const OpenAL_Sound &rhs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OpenAL_Sound(OpenAL_Output &output, ALuint src, ALuint buf);
|
OpenAL_Sound(OpenAL_Output &output, ALuint src, ALuint buf, bool is3D);
|
||||||
virtual ~OpenAL_Sound();
|
virtual ~OpenAL_Sound();
|
||||||
|
|
||||||
virtual void stop();
|
virtual void stop();
|
||||||
|
@ -335,8 +341,8 @@ public:
|
||||||
virtual void update();
|
virtual void update();
|
||||||
};
|
};
|
||||||
|
|
||||||
OpenAL_Sound::OpenAL_Sound(OpenAL_Output &output, ALuint src, ALuint buf)
|
OpenAL_Sound::OpenAL_Sound(OpenAL_Output &output, ALuint src, ALuint buf, bool is3D)
|
||||||
: mOutput(output), mSource(src), mBuffer(buf)
|
: mOutput(output), mSource(src), mBuffer(buf), mIs3D(is3D)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
OpenAL_Sound::~OpenAL_Sound()
|
OpenAL_Sound::~OpenAL_Sound()
|
||||||
|
@ -366,7 +372,10 @@ bool OpenAL_Sound::isPlaying()
|
||||||
|
|
||||||
void OpenAL_Sound::update()
|
void OpenAL_Sound::update()
|
||||||
{
|
{
|
||||||
alSourcef(mSource, AL_GAIN, mVolume*mBaseVolume);
|
if(mIs3D && mPos.squaredDistance(mOutput.mPos) > mMaxDistance*mMaxDistance)
|
||||||
|
alSourcef(mSource, AL_GAIN, 0.0f);
|
||||||
|
else
|
||||||
|
alSourcef(mSource, AL_GAIN, mVolume*mBaseVolume);
|
||||||
alSource3f(mSource, AL_POSITION, mPos[0], mPos[2], -mPos[1]);
|
alSource3f(mSource, AL_POSITION, mPos[0], mPos[2], -mPos[1]);
|
||||||
alSource3f(mSource, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
|
alSource3f(mSource, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
|
||||||
alSource3f(mSource, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
|
alSource3f(mSource, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
|
||||||
|
@ -583,7 +592,7 @@ SoundPtr OpenAL_Output::playSound(const std::string &fname, float volume, float
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
buf = getBuffer(fname);
|
buf = getBuffer(fname);
|
||||||
sound.reset(new OpenAL_Sound(*this, src, buf));
|
sound.reset(new OpenAL_Sound(*this, src, buf, false));
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
{
|
{
|
||||||
|
@ -632,7 +641,7 @@ SoundPtr OpenAL_Output::playSound3D(const std::string &fname, const Ogre::Vector
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
buf = getBuffer(fname);
|
buf = getBuffer(fname);
|
||||||
sound.reset(new OpenAL_Sound(*this, src, buf));
|
sound.reset(new OpenAL_Sound(*this, src, buf, true));
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
{
|
{
|
||||||
|
@ -651,7 +660,8 @@ SoundPtr OpenAL_Output::playSound3D(const std::string &fname, const Ogre::Vector
|
||||||
alSourcef(src, AL_MAX_DISTANCE, max);
|
alSourcef(src, AL_MAX_DISTANCE, max);
|
||||||
alSourcef(src, AL_ROLLOFF_FACTOR, 1.0f);
|
alSourcef(src, AL_ROLLOFF_FACTOR, 1.0f);
|
||||||
|
|
||||||
alSourcef(src, AL_GAIN, volume);
|
alSourcef(src, AL_GAIN, (pos.squaredDistance(mPos) > max*max) ?
|
||||||
|
0.0f : volume);
|
||||||
alSourcef(src, AL_PITCH, pitch);
|
alSourcef(src, AL_PITCH, pitch);
|
||||||
|
|
||||||
alSourcei(src, AL_SOURCE_RELATIVE, AL_FALSE);
|
alSourcei(src, AL_SOURCE_RELATIVE, AL_FALSE);
|
||||||
|
@ -682,7 +692,7 @@ SoundPtr OpenAL_Output::streamSound(const std::string &fname, float volume, floa
|
||||||
{
|
{
|
||||||
DecoderPtr decoder = mManager.getDecoder();
|
DecoderPtr decoder = mManager.getDecoder();
|
||||||
decoder->open(fname);
|
decoder->open(fname);
|
||||||
sound.reset(new OpenAL_SoundStream(*this, src, decoder));
|
sound.reset(new OpenAL_SoundStream(*this, src, decoder, false));
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue