From 3ab6c0c5ba66f73a2fb1697a97056580ee73b531 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Tue, 29 Sep 2015 11:09:43 +0200 Subject: [PATCH] Sound channel volume not overriding individual volume for sounds. --- include/Sound/Sound.h | 3 +++ src/game/Sound/SoundSystem.cpp | 10 ++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/Sound/Sound.h b/include/Sound/Sound.h index 0992948..bc3aae8 100644 --- a/include/Sound/Sound.h +++ b/include/Sound/Sound.h @@ -16,10 +16,13 @@ class Sound : public Resource public: ALuint Buffer() { return m_Buffer; }; std::string Path() { return m_Path; }; + float Gain() { return m_Gain; }; + void SetGain(const float Gain) { m_Gain = Gain; }; private: Sound(std::string path); + float m_Gain = 1; ALuint m_Buffer; std::string m_Path; diff --git a/src/game/Sound/SoundSystem.cpp b/src/game/Sound/SoundSystem.cpp index 8fb89fd..5fca564 100644 --- a/src/game/Sound/SoundSystem.cpp +++ b/src/game/Sound/SoundSystem.cpp @@ -81,6 +81,7 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event) ALuint source = CreateSource(); ALuint buffer = sound->Buffer(); alSourcei(source, AL_BUFFER, buffer); + sound->SetGain(event.Gain); //Sound settings float relativeVolume = 1.f; @@ -97,10 +98,9 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event) relativeVolume = m_SFXMasterVolume; } - alSourcef(source, AL_GAIN, (event.Gain * relativeVolume)); + alSourcef(source, AL_GAIN, (sound->Gain() * relativeVolume)); alSourcef(source, AL_PITCH, event.Pitch); - //Play alSourcePlay(source); return true; @@ -133,13 +133,11 @@ bool dd::Systems::SoundSystem::OnStopSound(const dd::Events::StopSound &event) bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &event) { - //TODO: Make the Gain depend on the value given when stored. - //TODO: .. now it ONLY uses the master Gain if (event.IsAmbient) { m_BGMMasterVolume = event.Gain; for (auto& item : m_BGMSourcesToBuffers) { - alSourcef(item.first, AL_GAIN, event.Gain); + alSourcef(item.first, AL_GAIN, (item.second->Gain() * m_BGMMasterVolume)); } return true; } @@ -147,7 +145,7 @@ bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &ev m_SFXMasterVolume = event.Gain; for (auto& item : m_SFXSourcesToBuffers) { - alSourcef(item.first, AL_GAIN, event.Gain); + alSourcef(item.first, AL_GAIN, (item.second->Gain() * m_SFXMasterVolume)); } return true; }