From 001da20f42855b832fe420798159f1cde016e7a9 Mon Sep 17 00:00:00 2001 From: auria Date: Thu, 19 Sep 2013 23:46:51 +0000 Subject: [PATCH] Fix audio master volume bug git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14107 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/audio/sfx_base.hpp | 1 + src/audio/sfx_manager.cpp | 6 +++--- src/audio/sfx_openal.cpp | 23 ++++++++++++++++++----- src/audio/sfx_openal.hpp | 4 ++++ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/audio/sfx_base.hpp b/src/audio/sfx_base.hpp index 7fd5a8ec4..b06daa7ae 100644 --- a/src/audio/sfx_base.hpp +++ b/src/audio/sfx_base.hpp @@ -55,6 +55,7 @@ public: virtual void resume() = 0; virtual void speed(float factor) = 0; virtual void volume(float gain) = 0; + virtual void masterVolume(float gain) = 0; virtual SFXManager::SFXStatus getStatus() = 0; virtual void onSoundEnabledBack() = 0; diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index afc6d0439..cc5d21969 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -313,7 +313,7 @@ SFXBase* SFXManager::createSoundSource(SFXBuffer* buffer, SFXBase* sfx = new DummySFX(buffer, positional, buffer->getGain(), owns_buffer); #endif - sfx->volume(m_master_gain); + sfx->masterVolume(m_master_gain); if (add_to_SFX_list) m_all_sfx.push_back(sfx); @@ -467,7 +467,7 @@ void SFXManager::setMasterSFXVolume(float gain) for (std::vector::iterator i=m_all_sfx.begin(); i!=m_all_sfx.end(); i++) { - (*i)->volume(m_master_gain); + (*i)->masterVolume(m_master_gain); } // for i in m_all_sfx } @@ -476,7 +476,7 @@ void SFXManager::setMasterSFXVolume(float gain) std::map::iterator i = m_quick_sounds.begin(); for (; i != m_quick_sounds.end(); i++) { - (*i).second->volume(m_master_gain); + (*i).second->masterVolume(m_master_gain); } } diff --git a/src/audio/sfx_openal.cpp b/src/audio/sfx_openal.cpp index 22a340851..3ccb8b30d 100644 --- a/src/audio/sfx_openal.cpp +++ b/src/audio/sfx_openal.cpp @@ -52,6 +52,7 @@ SFXOpenAL::SFXOpenAL(SFXBuffer* buffer, bool positional, float gain, bool ownsBu m_defaultGain = gain; m_loop = false; m_gain = -1.0f; + m_master_gain = 1.0f; m_owns_buffer = ownsBuffer; // Don't initialise anything else if the sfx manager was not correctly @@ -106,11 +107,11 @@ bool SFXOpenAL::init() if (m_gain < 0.0f) { - alSourcef (m_soundSource, AL_GAIN, m_defaultGain); + alSourcef (m_soundSource, AL_GAIN, m_defaultGain * m_master_gain); } else { - alSourcef (m_soundSource, AL_GAIN, m_gain); + alSourcef (m_soundSource, AL_GAIN, m_gain * m_master_gain); } if (m_positional) alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_FALSE); @@ -154,10 +155,22 @@ void SFXOpenAL::volume(float gain) if(!m_ok) return; - alSourcef(m_soundSource, AL_GAIN, m_defaultGain * gain); + alSourcef(m_soundSource, AL_GAIN, m_gain * m_master_gain); SFXManager::checkError("setting volume"); } // volume +//----------------------------------------------------------------------------- + +void SFXOpenAL::masterVolume(float gain) +{ + m_master_gain = gain; + + if(!m_ok) return; + + alSourcef(m_soundSource, AL_GAIN, (m_gain < 0.0f ? m_defaultGain : m_gain) * m_master_gain); + SFXManager::checkError("setting volume"); +} + //----------------------------------------------------------------------------- /** Loops this sound effect. */ @@ -266,7 +279,7 @@ void SFXOpenAL::position(const Vec3 &position) } else { - alSourcef(m_soundSource, AL_GAIN, (m_gain < 0.0f ? m_defaultGain : m_gain)); + alSourcef(m_soundSource, AL_GAIN, (m_gain < 0.0f ? m_defaultGain : m_gain) * m_master_gain); } SFXManager::checkError("positioning"); @@ -303,7 +316,7 @@ void SFXOpenAL::onSoundEnabledBack() alSourcef(m_soundSource, AL_GAIN, 0); play(); pause(); - alSourcef(m_soundSource, AL_GAIN, (m_gain < 0.0f ? m_defaultGain : m_gain)); + alSourcef(m_soundSource, AL_GAIN, (m_gain < 0.0f ? m_defaultGain : m_gain) * m_master_gain); } } } diff --git a/src/audio/sfx_openal.hpp b/src/audio/sfx_openal.hpp index edc0c30cd..9921f002a 100644 --- a/src/audio/sfx_openal.hpp +++ b/src/audio/sfx_openal.hpp @@ -55,6 +55,9 @@ private: the sound source won't be created and we'll be left with no clue when enabling sounds later. */ float m_gain; + + /** The master gain set in user preferences */ + float m_master_gain; bool m_owns_buffer; @@ -74,6 +77,7 @@ public: virtual void speed(float factor); virtual void position(const Vec3 &position); virtual void volume(float gain); + virtual void masterVolume(float gain); virtual SFXManager::SFXStatus getStatus(); virtual void onSoundEnabledBack(); virtual void setRolloff(float rolloff);