summaryrefslogtreecommitdiffstats
path: root/src/sound
diff options
context:
space:
mode:
authorerihel <erihel@gmail.com>2013-03-30 16:03:25 +0100
committererihel <erihel@gmail.com>2013-03-30 16:03:25 +0100
commitb7b5f002a636154033166a2c828765386c14e5a5 (patch)
tree46950e3f29d20272a9d6344253f5cdf2f29da3b1 /src/sound
parent3569adb10377d83beeb705870f015cc1f40aeffc (diff)
downloadcolobot-b7b5f002a636154033166a2c828765386c14e5a5.tar.gz
colobot-b7b5f002a636154033166a2c828765386c14e5a5.tar.bz2
colobot-b7b5f002a636154033166a2c828765386c14e5a5.zip
* Removed warning while compiling brain.cpp
* Fix for issue #130 * Fix for issue #128 with wrong sound pitch
Diffstat (limited to 'src/sound')
-rw-r--r--src/sound/oalsound/alsound.cpp49
-rw-r--r--src/sound/oalsound/channel.cpp13
-rw-r--r--src/sound/oalsound/channel.h1
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);