diff options
author | krzys-h <krzys_h@interia.pl> | 2013-03-31 10:22:08 +0200 |
---|---|---|
committer | krzys-h <krzys_h@interia.pl> | 2013-03-31 10:22:08 +0200 |
commit | 0625f064a74ab70b06534b2198fa2b10f42fa183 (patch) | |
tree | 6f710509bcb841bf017775b650e596c81a3684ab /src/sound | |
parent | 90301e24c0fc5fcd6bffb0399e203e5adea6aa2c (diff) | |
parent | 5a60a7a21958e2d8cfd33148f575d36e3bbd9ebb (diff) | |
download | colobot-0625f064a74ab70b06534b2198fa2b10f42fa183.tar.gz colobot-0625f064a74ab70b06534b2198fa2b10f42fa183.tar.bz2 colobot-0625f064a74ab70b06534b2198fa2b10f42fa183.zip |
Merge branch 'dev' of github.com:colobot/colobot into dev
Diffstat (limited to 'src/sound')
-rw-r--r-- | src/sound/oalsound/alsound.cpp | 49 | ||||
-rw-r--r-- | src/sound/oalsound/channel.cpp | 13 | ||||
-rw-r--r-- | src/sound/oalsound/channel.h | 1 |
3 files changed, 28 insertions, 35 deletions
diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 8c1cb81..e3a3f4b 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -81,6 +81,7 @@ bool ALSound::Create(bool b3D) return false; } alcMakeContextCurrent(mContext); + alListenerf(AL_GAIN, mAudioVolume); mCurrentMusic = new Channel(); GetLogger()->Info("Done.\n"); @@ -118,8 +119,7 @@ bool ALSound::GetEnable() void ALSound::SetAudioVolume(int volume) { - mAudioVolume = MIN(static_cast<float>(volume) / MAXVOLUME, 1.0f); - alListenerf(AL_GAIN, mAudioVolume); + mAudioVolume = static_cast<float>(volume) / MAXVOLUME; } @@ -134,9 +134,9 @@ int ALSound::GetAudioVolume() void ALSound::SetMusicVolume(int volume) { - mMusicVolume = MIN(static_cast<float>(volume) / MAXVOLUME, 1.0f); + mMusicVolume = static_cast<float>(volume) / MAXVOLUME; if (mCurrentMusic) { - mCurrentMusic->SetVolume(mMusicVolume * mAudioVolume); + mCurrentMusic->SetVolume(mMusicVolume); } } @@ -298,7 +298,6 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc if (!mEnabled) { return -1; } - if (mSounds.find(sound) == mSounds.end()) { GetLogger()->Warn("Sound %d was not loaded!\n", sound); return -1; @@ -323,7 +322,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(amplitude * mAudioVolume); + mChannels[channel]->SetVolume(powf(amplitude, 0.2f) * mAudioVolume); mChannels[channel]->SetLoop(bLoop); mChannels[channel]->Play(); @@ -426,17 +425,12 @@ bool ALSound::MuteAll(bool bMute) if (!mEnabled) return false; - float volume; mMute = bMute; - if (mMute) - volume = 0; - else - volume = mAudioVolume; - - for (auto channel : mChannels) { - channel.second->SetVolume(volume * mAudioVolume); + if (mMute) { + mCurrentMusic->SetVolume(0.0f); + } else { + mCurrentMusic->SetVolume(mMusicVolume); } - return true; } @@ -451,6 +445,11 @@ void ALSound::FrameMove(float delta) if (!it.second->IsPlaying()) { continue; } + + if (mMute) { + it.second->SetVolume(0.0f); + continue; + } if (!it.second->HasEnvelope()) continue; @@ -461,13 +460,19 @@ void ALSound::FrameMove(float delta) progress = MIN(progress, 1.0f); // setting volume - volume = progress * (oper.finalAmplitude - it.second->GetStartAmplitude()); - volume = (volume + it.second->GetStartAmplitude()) * mAudioVolume; - it.second->SetVolume(volume); + if (!mMute) { + volume = progress * (oper.finalAmplitude - it.second->GetStartAmplitude()); + volume = (volume + it.second->GetStartAmplitude()); + it.second->SetVolume(powf(volume, 0.2f) * mAudioVolume); + } // setting frequency - frequency = progress * (oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency() * it.second->GetInitFrequency(); - it.second->AdjustFrequency(frequency); + frequency = progress; + frequency *= oper.finalFrequency - it.second->GetStartFrequency(); + frequency += it.second->GetStartFrequency(); + frequency *= it.second->GetChangeFrequency(); + frequency = (frequency * it.second->GetInitFrequency()); + it.second->SetFrequency(frequency); if (oper.totalTime <= oper.currentTime) { if (oper.nextOper == SOPER_LOOP) { @@ -508,7 +513,7 @@ bool ALSound::PlayMusic(int rank, bool bRepeat) GetLogger()->Debug("Music loaded from cache\n"); mCurrentMusic->SetBuffer(music); - mCurrentMusic->SetVolume(mMusicVolume * mAudioVolume); + mCurrentMusic->SetVolume(mMusicVolume); mCurrentMusic->SetLoop(bRepeat); mCurrentMusic->Play(); return true; @@ -533,7 +538,7 @@ bool ALSound::PlayMusic(int rank, bool bRepeat) mMusicCache[rank] = buffer; } - mCurrentMusic->SetVolume(mMusicVolume * mAudioVolume); + mCurrentMusic->SetVolume(mMusicVolume); mCurrentMusic->SetLoop(bRepeat); mCurrentMusic->Play(); diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index 19394c6..f5967ab 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -17,8 +17,6 @@ #include "channel.h" -#define MIN(a, b) (a > b ? b : a) - Channel::Channel() { alGenSources(1, &mSource); @@ -89,15 +87,6 @@ bool Channel::SetFrequency(float freq) } -bool Channel::AdjustFrequency(float freq) -{ - if (!mReady || mBuffer == nullptr) - return false; - - return SetFrequency(mInitFrequency + fabs(freq)); -} - - float Channel::GetFrequency() { ALfloat freq; @@ -119,7 +108,7 @@ bool Channel::SetVolume(float vol) if (!mReady || vol < 0 || mBuffer == nullptr) return false; - alSourcef(mSource, AL_GAIN, MIN(powf(vol, 0.2f), 1.0f)); + alSourcef(mSource, AL_GAIN, vol); if (alCheck()) { GetLogger()->Warn("Could not set sound volume to '%f'. Code: %d\n", vol, alGetCode()); return false; diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h index 8965306..883ddf2 100644 --- a/src/sound/oalsound/channel.h +++ b/src/sound/oalsound/channel.h @@ -52,7 +52,6 @@ class Channel bool SetFrequency(float); float GetFrequency(); - bool AdjustFrequency(float); float GetCurrentTime(); void SetCurrentTime(float); |