From e0e1ef8001fa3bb7ae75bc6e5e9dfcd82fbc7c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 26 May 2024 11:08:04 +0200 Subject: [PATCH] Fix incorrect channel panning value after changing volume Fix incorrect panning value (`1.0f`) being set for GUI and Global sound channels after sound volume is changed, whereas the panning value is initialized to `0.0f`. Now the panning value is set to `0.0f` consistently. This should not have had any effect, as GUI and Global sounds do not have a position which would be affected by the panning value. --- src/game/client/components/sounds.cpp | 75 ++++++++++++--------------- src/game/client/components/sounds.h | 9 ++-- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/src/game/client/components/sounds.cpp b/src/game/client/components/sounds.cpp index 6d38d943c..776b3e304 100644 --- a/src/game/client/components/sounds.cpp +++ b/src/game/client/components/sounds.cpp @@ -43,6 +43,38 @@ void CSoundLoading::Run() } } +void CSounds::UpdateChannels() +{ + const float NewGuiSoundVolume = g_Config.m_SndChatSoundVolume / 100.0f; + if(NewGuiSoundVolume != m_GuiSoundVolume) + { + m_GuiSoundVolume = NewGuiSoundVolume; + Sound()->SetChannel(CSounds::CHN_GUI, m_GuiSoundVolume, 0.0f); + } + + const float NewGameSoundVolume = g_Config.m_SndGameSoundVolume / 100.0f; + if(NewGameSoundVolume != m_GameSoundVolume) + { + m_GameSoundVolume = NewGameSoundVolume; + Sound()->SetChannel(CSounds::CHN_WORLD, 0.9f * m_GameSoundVolume, 1.0f); + Sound()->SetChannel(CSounds::CHN_GLOBAL, m_GameSoundVolume, 0.0f); + } + + const float NewMapSoundVolume = g_Config.m_SndMapSoundVolume / 100.0f; + if(NewMapSoundVolume != m_MapSoundVolume) + { + m_MapSoundVolume = NewMapSoundVolume; + Sound()->SetChannel(CSounds::CHN_MAPSOUND, m_MapSoundVolume, 1.0f); + } + + const float NewBackgroundMusicVolume = g_Config.m_SndBackgroundMusicVolume / 100.0f; + if(NewBackgroundMusicVolume != m_BackgroundMusicVolume) + { + m_BackgroundMusicVolume = NewBackgroundMusicVolume; + Sound()->SetChannel(CSounds::CHN_MUSIC, m_BackgroundMusicVolume, 1.0f); + } +} + int CSounds::GetSampleId(int SetId) { if(!g_Config.m_SndEnable || !Sound()->IsSoundEnabled() || m_WaitForSoundJob || SetId < 0 || SetId >= g_pData->m_NumSounds) @@ -67,18 +99,7 @@ int CSounds::GetSampleId(int SetId) void CSounds::OnInit() { - // setup sound channels - m_GuiSoundVolume = g_Config.m_SndChatSoundVolume / 100.0f; - m_GameSoundVolume = g_Config.m_SndGameSoundVolume / 100.0f; - m_MapSoundVolume = g_Config.m_SndMapSoundVolume / 100.0f; - m_BackgroundMusicVolume = g_Config.m_SndBackgroundMusicVolume / 100.0f; - - Sound()->SetChannel(CSounds::CHN_GUI, m_GuiSoundVolume, 0.0f); - Sound()->SetChannel(CSounds::CHN_MUSIC, m_BackgroundMusicVolume, 1.0f); - Sound()->SetChannel(CSounds::CHN_WORLD, 0.9f * m_GameSoundVolume, 1.0f); - Sound()->SetChannel(CSounds::CHN_GLOBAL, m_GameSoundVolume, 0.0f); - Sound()->SetChannel(CSounds::CHN_MAPSOUND, m_MapSoundVolume, 1.0f); - + UpdateChannels(); ClearQueue(); // load sounds @@ -125,35 +146,7 @@ void CSounds::OnRender() // set listener pos Sound()->SetListenerPos(m_pClient->m_Camera.m_Center.x, m_pClient->m_Camera.m_Center.y); - // update volume - float NewGuiSoundVol = g_Config.m_SndChatSoundVolume / 100.0f; - if(NewGuiSoundVol != m_GuiSoundVolume) - { - m_GuiSoundVolume = NewGuiSoundVol; - Sound()->SetChannel(CSounds::CHN_GUI, m_GuiSoundVolume, 1.0f); - } - - float NewGameSoundVol = g_Config.m_SndGameSoundVolume / 100.0f; - if(NewGameSoundVol != m_GameSoundVolume) - { - m_GameSoundVolume = NewGameSoundVol; - Sound()->SetChannel(CSounds::CHN_WORLD, 0.9f * m_GameSoundVolume, 1.0f); - Sound()->SetChannel(CSounds::CHN_GLOBAL, m_GameSoundVolume, 1.0f); - } - - float NewMapSoundVol = g_Config.m_SndMapSoundVolume / 100.0f; - if(NewMapSoundVol != m_MapSoundVolume) - { - m_MapSoundVolume = NewMapSoundVol; - Sound()->SetChannel(CSounds::CHN_MAPSOUND, m_MapSoundVolume, 1.0f); - } - - float NewBackgroundMusicVol = g_Config.m_SndBackgroundMusicVolume / 100.0f; - if(NewBackgroundMusicVol != m_BackgroundMusicVolume) - { - m_BackgroundMusicVolume = NewBackgroundMusicVol; - Sound()->SetChannel(CSounds::CHN_MUSIC, m_BackgroundMusicVolume, 1.0f); - } + UpdateChannels(); // play sound from queue if(m_QueuePos > 0) diff --git a/src/game/client/components/sounds.h b/src/game/client/components/sounds.h index 4ee5df561..b412425da 100644 --- a/src/game/client/components/sounds.h +++ b/src/game/client/components/sounds.h @@ -34,12 +34,13 @@ class CSounds : public CComponent std::shared_ptr m_pSoundJob; bool m_WaitForSoundJob; + void UpdateChannels(); int GetSampleId(int SetId); - float m_GuiSoundVolume; - float m_GameSoundVolume; - float m_MapSoundVolume; - float m_BackgroundMusicVolume; + float m_GuiSoundVolume = -1.0f; + float m_GameSoundVolume = -1.0f; + float m_MapSoundVolume = -1.0f; + float m_BackgroundMusicVolume = -1.0f; public: // sound channels