* Fixed problem with MuteAll and some sounds not playing after muting other sounds (like game menu sound)

dev-ui
erihel 2013-04-09 13:20:31 +02:00
parent a66abd4990
commit 99d386b61a
4 changed files with 36 additions and 12 deletions

View File

@ -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);
}
}

View File

@ -85,7 +85,6 @@ class ALSound : public CSoundInterface
bool mEnabled;
bool m3D;
bool mMute;
float mAudioVolume;
float mMusicVolume;
ALCdevice* mDevice;

View File

@ -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;
}

View File

@ -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<SoundOper> mOper;
bool mReady;
bool mLoop;
bool mMute;
};