From 99d386b61a29e6f8cadf2f91019017736c681f00 Mon Sep 17 00:00:00 2001 From: erihel Date: Tue, 9 Apr 2013 13:20:31 +0200 Subject: * Fixed problem with MuteAll and some sounds not playing after muting other sounds (like game menu sound) --- src/sound/oalsound/alsound.cpp | 31 ++++++++++++++++++++----------- src/sound/oalsound/alsound.h | 1 - src/sound/oalsound/channel.cpp | 13 +++++++++++++ src/sound/oalsound/channel.h | 3 +++ 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index a5a6989..68bf515 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -26,7 +26,6 @@ ALSound::ALSound() m3D = false; mAudioVolume = 1.0f; mMusicVolume = 1.0f; - mMute = false; mCurrentMusic = nullptr; mEye.LoadZero(); mLookat.LoadZero(); @@ -290,7 +289,7 @@ bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded) int ALSound::Play(Sound sound, float amplitude, float frequency, bool bLoop) { - return Play(sound, Math::Vector(), amplitude, frequency, bLoop); + return Play(sound, mEye, amplitude, frequency, bLoop); } @@ -315,9 +314,12 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc return -1; } } + Position(channel, pos); if (!m3D) { ComputeVolumePan2D(channel, pos); + } else { + mChannels[channel]->SetVolume(1.0f); } // setting initial values @@ -326,7 +328,7 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc mChannels[channel]->SetChangeFrequency(1.0f); mChannels[channel]->ResetOper(); mChannels[channel]->SetFrequency(frequency); - mChannels[channel]->SetVolume(powf(amplitude, 0.2f) * mAudioVolume); + mChannels[channel]->SetVolume(powf(amplitude * mChannels[channel]->GetVolume(), 0.2f) * mAudioVolume); mChannels[channel]->SetLoop(bLoop); mChannels[channel]->Play(); @@ -432,9 +434,14 @@ bool ALSound::MuteAll(bool bMute) { if (!mEnabled) return false; + + for (auto it : mChannels) { + if (it.second->IsPlaying()) { + it.second->Mute(bMute); + } + } - mMute = bMute; - if (mMute) { + if (bMute) { mCurrentMusic->SetVolume(0.0f); } else { mCurrentMusic->SetVolume(mMusicVolume); @@ -455,7 +462,7 @@ void ALSound::FrameMove(float delta) continue; } - if (mMute) { + if (it.second->IsMuted()) { it.second->SetVolume(0.0f); continue; } @@ -469,11 +476,9 @@ void ALSound::FrameMove(float delta) progress = MIN(progress, 1.0f); // setting volume - if (!mMute) { - volume = progress * (oper.finalAmplitude - it.second->GetStartAmplitude()); - volume = (volume + it.second->GetStartAmplitude()); - it.second->SetVolume(powf(volume, 0.2f) * mAudioVolume); - } + volume = progress * (oper.finalAmplitude - it.second->GetStartAmplitude()); + volume = (volume + it.second->GetStartAmplitude()); + it.second->SetVolume(powf(volume, 0.2f) * mAudioVolume); // setting frequency frequency = progress; @@ -509,6 +514,10 @@ void ALSound::SetListener(Math::Vector eye, Math::Vector lookat) float orientation[] = {lookat.x, lookat.y, lookat.z, 0.f, 1.f, 0.f}; alListener3f(AL_POSITION, eye.x, eye.y, eye.z); alListenerfv(AL_ORIENTATION, orientation); + } else { + float orientation[] = {0.0f, 0.0f, 0.0f, 0.f, 1.f, 0.f}; + alListener3f(AL_POSITION, 0.0f, 0.0f, 0.0f); + alListenerfv(AL_ORIENTATION, orientation); } } diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index 725aa2a..5701997 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -85,7 +85,6 @@ class ALSound : public CSoundInterface bool mEnabled; bool m3D; - bool mMute; float mAudioVolume; float mMusicVolume; ALCdevice* mDevice; diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index 746282e..686e909 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -30,6 +30,7 @@ Channel::Channel() { mPriority = 0; mBuffer = nullptr; mLoop = false; + mMute = false; mInitFrequency = 0.0f; mStartAmplitude = 0.0f; mStartFrequency = 0.0f; @@ -351,3 +352,15 @@ void Channel::PopEnvelope() void Channel::SetLoop(bool loop) { mLoop = loop; } + + +void Channel::Mute(bool mute) +{ + mMute = mute; +} + + +bool Channel::IsMuted() +{ + return mMute; +} diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h index 883ddf2..f5f3bb9 100644 --- a/src/sound/oalsound/channel.h +++ b/src/sound/oalsound/channel.h @@ -86,6 +86,8 @@ class Channel void ResetOper(); Sound GetSoundType(); void SetLoop(bool); + void Mute(bool); + bool IsMuted(); private: Buffer *mBuffer; @@ -99,4 +101,5 @@ class Channel std::deque mOper; bool mReady; bool mLoop; + bool mMute; }; -- cgit v1.2.3-1-g7c22