diff options
author | erihel <erihel@gmail.com> | 2013-04-09 13:20:31 +0200 |
---|---|---|
committer | erihel <erihel@gmail.com> | 2013-04-09 13:20:31 +0200 |
commit | 99d386b61a29e6f8cadf2f91019017736c681f00 (patch) | |
tree | dfa93a0d9f4cc0ebf3c5c49f17b20e9eef10fa81 /src/sound/oalsound/alsound.cpp | |
parent | a66abd4990c6c415bafe3ce879bc67d7539a2901 (diff) | |
download | colobot-99d386b61a29e6f8cadf2f91019017736c681f00.tar.gz colobot-99d386b61a29e6f8cadf2f91019017736c681f00.tar.bz2 colobot-99d386b61a29e6f8cadf2f91019017736c681f00.zip |
* Fixed problem with MuteAll and some sounds not playing after muting other sounds (like game menu sound)
Diffstat (limited to 'src/sound/oalsound/alsound.cpp')
-rw-r--r-- | src/sound/oalsound/alsound.cpp | 31 |
1 files changed, 20 insertions, 11 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); } } |