* Fixed problem with MuteAll and some sounds not playing after muting other sounds (like game menu sound)
parent
a66abd4990
commit
99d386b61a
|
@ -26,7 +26,6 @@ ALSound::ALSound()
|
||||||
m3D = false;
|
m3D = false;
|
||||||
mAudioVolume = 1.0f;
|
mAudioVolume = 1.0f;
|
||||||
mMusicVolume = 1.0f;
|
mMusicVolume = 1.0f;
|
||||||
mMute = false;
|
|
||||||
mCurrentMusic = nullptr;
|
mCurrentMusic = nullptr;
|
||||||
mEye.LoadZero();
|
mEye.LoadZero();
|
||||||
mLookat.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)
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Position(channel, pos);
|
Position(channel, pos);
|
||||||
if (!m3D) {
|
if (!m3D) {
|
||||||
ComputeVolumePan2D(channel, pos);
|
ComputeVolumePan2D(channel, pos);
|
||||||
|
} else {
|
||||||
|
mChannels[channel]->SetVolume(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// setting initial values
|
// 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]->SetChangeFrequency(1.0f);
|
||||||
mChannels[channel]->ResetOper();
|
mChannels[channel]->ResetOper();
|
||||||
mChannels[channel]->SetFrequency(frequency);
|
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]->SetLoop(bLoop);
|
||||||
mChannels[channel]->Play();
|
mChannels[channel]->Play();
|
||||||
|
|
||||||
|
@ -432,9 +434,14 @@ bool ALSound::MuteAll(bool bMute)
|
||||||
{
|
{
|
||||||
if (!mEnabled)
|
if (!mEnabled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
for (auto it : mChannels) {
|
||||||
|
if (it.second->IsPlaying()) {
|
||||||
|
it.second->Mute(bMute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mMute = bMute;
|
if (bMute) {
|
||||||
if (mMute) {
|
|
||||||
mCurrentMusic->SetVolume(0.0f);
|
mCurrentMusic->SetVolume(0.0f);
|
||||||
} else {
|
} else {
|
||||||
mCurrentMusic->SetVolume(mMusicVolume);
|
mCurrentMusic->SetVolume(mMusicVolume);
|
||||||
|
@ -455,7 +462,7 @@ void ALSound::FrameMove(float delta)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mMute) {
|
if (it.second->IsMuted()) {
|
||||||
it.second->SetVolume(0.0f);
|
it.second->SetVolume(0.0f);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -469,11 +476,9 @@ void ALSound::FrameMove(float delta)
|
||||||
progress = MIN(progress, 1.0f);
|
progress = MIN(progress, 1.0f);
|
||||||
|
|
||||||
// setting volume
|
// setting volume
|
||||||
if (!mMute) {
|
volume = progress * (oper.finalAmplitude - it.second->GetStartAmplitude());
|
||||||
volume = progress * (oper.finalAmplitude - it.second->GetStartAmplitude());
|
volume = (volume + it.second->GetStartAmplitude());
|
||||||
volume = (volume + it.second->GetStartAmplitude());
|
it.second->SetVolume(powf(volume, 0.2f) * mAudioVolume);
|
||||||
it.second->SetVolume(powf(volume, 0.2f) * mAudioVolume);
|
|
||||||
}
|
|
||||||
|
|
||||||
// setting frequency
|
// setting frequency
|
||||||
frequency = progress;
|
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};
|
float orientation[] = {lookat.x, lookat.y, lookat.z, 0.f, 1.f, 0.f};
|
||||||
alListener3f(AL_POSITION, eye.x, eye.y, eye.z);
|
alListener3f(AL_POSITION, eye.x, eye.y, eye.z);
|
||||||
alListenerfv(AL_ORIENTATION, orientation);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,6 @@ class ALSound : public CSoundInterface
|
||||||
|
|
||||||
bool mEnabled;
|
bool mEnabled;
|
||||||
bool m3D;
|
bool m3D;
|
||||||
bool mMute;
|
|
||||||
float mAudioVolume;
|
float mAudioVolume;
|
||||||
float mMusicVolume;
|
float mMusicVolume;
|
||||||
ALCdevice* mDevice;
|
ALCdevice* mDevice;
|
||||||
|
|
|
@ -30,6 +30,7 @@ Channel::Channel() {
|
||||||
mPriority = 0;
|
mPriority = 0;
|
||||||
mBuffer = nullptr;
|
mBuffer = nullptr;
|
||||||
mLoop = false;
|
mLoop = false;
|
||||||
|
mMute = false;
|
||||||
mInitFrequency = 0.0f;
|
mInitFrequency = 0.0f;
|
||||||
mStartAmplitude = 0.0f;
|
mStartAmplitude = 0.0f;
|
||||||
mStartFrequency = 0.0f;
|
mStartFrequency = 0.0f;
|
||||||
|
@ -351,3 +352,15 @@ void Channel::PopEnvelope()
|
||||||
void Channel::SetLoop(bool loop) {
|
void Channel::SetLoop(bool loop) {
|
||||||
mLoop = loop;
|
mLoop = loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Channel::Mute(bool mute)
|
||||||
|
{
|
||||||
|
mMute = mute;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Channel::IsMuted()
|
||||||
|
{
|
||||||
|
return mMute;
|
||||||
|
}
|
||||||
|
|
|
@ -86,6 +86,8 @@ class Channel
|
||||||
void ResetOper();
|
void ResetOper();
|
||||||
Sound GetSoundType();
|
Sound GetSoundType();
|
||||||
void SetLoop(bool);
|
void SetLoop(bool);
|
||||||
|
void Mute(bool);
|
||||||
|
bool IsMuted();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Buffer *mBuffer;
|
Buffer *mBuffer;
|
||||||
|
@ -99,4 +101,5 @@ class Channel
|
||||||
std::deque<SoundOper> mOper;
|
std::deque<SoundOper> mOper;
|
||||||
bool mReady;
|
bool mReady;
|
||||||
bool mLoop;
|
bool mLoop;
|
||||||
|
bool mMute;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue