diff --git a/src/RageSound.cpp b/src/RageSound.cpp index d3dd0c2a0e..5943b86116 100644 --- a/src/RageSound.cpp +++ b/src/RageSound.cpp @@ -583,7 +583,7 @@ void RageSound::ApplyParams() m_pSource->SetProperty( "FadeInSeconds", m_Param.m_fFadeInSeconds ); m_pSource->SetProperty( "FadeSeconds", m_Param.m_fFadeOutSeconds ); - float fVolume = m_Param.m_Volume * SOUNDMAN->GetMixVolume(); + float fVolume = m_Param.m_Volume; if( !m_Param.m_bIsCriticalSound ) fVolume *= m_Param.m_fAttractVolume; m_pSource->SetProperty( "Volume", fVolume ); diff --git a/src/RageSoundManager.cpp b/src/RageSoundManager.cpp index bc6750a746..edb006771a 100644 --- a/src/RageSoundManager.cpp +++ b/src/RageSoundManager.cpp @@ -18,6 +18,7 @@ #include "Foreach.h" #include "LocalizedString.h" #include "Preference.h" +#include "RageSoundReader_PostBuffering.h" #include "arch/Sound/RageSoundDriver.h" @@ -35,7 +36,7 @@ static Preference g_sSoundDrivers( "SoundDrivers", "" ); // "" == DEFAU RageSoundManager *SOUNDMAN = NULL; -RageSoundManager::RageSoundManager(): m_pDriver(NULL), m_fMixVolume(1.0f), +RageSoundManager::RageSoundManager(): m_pDriver(NULL), m_fVolumeOfNonCriticalSounds(1.0f) {} static LocalizedString COULDNT_FIND_SOUND_DRIVER( "RageSoundManager", "Couldn't find a sound driver that works" ); @@ -187,9 +188,7 @@ static Preference g_fSoundVolume( "SoundVolume", 1.0f ); void RageSoundManager::SetMixVolume() { - g_SoundManMutex.Lock(); /* lock for access to m_fMixVolume */ - m_fMixVolume = clamp( g_fSoundVolume.Get(), 0.0f, 1.0f ); - g_SoundManMutex.Unlock(); /* finished with m_fMixVolume */ + RageSoundReader_PostBuffering::SetMasterVolume( g_fSoundVolume.Get() ); } void RageSoundManager::SetVolumeOfNonCriticalSounds( float fVolumeOfNonCriticalSounds ) diff --git a/src/RageSoundManager.h b/src/RageSoundManager.h index b5677f188f..a732fa06f2 100644 --- a/src/RageSoundManager.h +++ b/src/RageSoundManager.h @@ -29,7 +29,6 @@ public: void Init(); - float GetMixVolume() const { return m_fMixVolume; } void SetMixVolume(); float GetVolumeOfNonCriticalSounds() const { return m_fVolumeOfNonCriticalSounds; } void SetVolumeOfNonCriticalSounds( float fVolumeOfNonCriticalSounds ); @@ -54,7 +53,6 @@ private: RageSoundDriver *m_pDriver; /* Prefs: */ - float m_fMixVolume; float m_fVolumeOfNonCriticalSounds; // Swallow up warnings. If they must be used, define them. RageSoundManager& operator=(const RageSoundManager& rhs); diff --git a/src/RageSoundReader_PostBuffering.cpp b/src/RageSoundReader_PostBuffering.cpp index a93da53e20..2d7a124d55 100644 --- a/src/RageSoundReader_PostBuffering.cpp +++ b/src/RageSoundReader_PostBuffering.cpp @@ -1,12 +1,16 @@ #include "global.h" #include "RageSoundReader_PostBuffering.h" #include "RageSoundUtil.h" +#include "RageThreads.h" +#include "RageUtil.h" /* * This filter is normally inserted after extended buffering, implementing * properties that do not seek the sound, allowing these properties to be * changed with low latency. */ +RageMutex g_Mutex("PostBuffering"); +static float g_fMasterVolume = 1.0f; RageSoundReader_PostBuffering::RageSoundReader_PostBuffering( RageSoundReader *pSource ): RageSoundReader_Filter( pSource ) @@ -14,6 +18,10 @@ RageSoundReader_PostBuffering::RageSoundReader_PostBuffering( RageSoundReader *p m_fVolume = 1.0f; } +void RageSoundReader_PostBuffering::SetMasterVolume(float fVolume) { + LockMut(g_Mutex); + g_fMasterVolume = fVolume; +} int RageSoundReader_PostBuffering::Read( float *pBuf, int iFrames ) { @@ -21,8 +29,14 @@ int RageSoundReader_PostBuffering::Read( float *pBuf, int iFrames ) if( iFrames < 0 ) return iFrames; - if( m_fVolume != 1.0f ) - RageSoundUtil::Attenuate( pBuf, iFrames * this->GetNumChannels(), m_fVolume ); + // Combine the sound's volume with master volume. + g_Mutex.Lock(); + float fVolume = m_fVolume * g_fMasterVolume; + fVolume = clamp( fVolume, 0, 1 ); + g_Mutex.Unlock(); + + if( fVolume != 1.0f ) + RageSoundUtil::Attenuate( pBuf, iFrames * this->GetNumChannels(), fVolume ); return iFrames; } diff --git a/src/RageSoundReader_PostBuffering.h b/src/RageSoundReader_PostBuffering.h index 28668256c4..4994da571c 100644 --- a/src/RageSoundReader_PostBuffering.h +++ b/src/RageSoundReader_PostBuffering.h @@ -10,6 +10,7 @@ class RageSoundReader_PostBuffering: public RageSoundReader_Filter public: RageSoundReader_PostBuffering( RageSoundReader *pSource ); RageSoundReader_PostBuffering *Copy() const { return new RageSoundReader_PostBuffering(*this); } + static void SetMasterVolume( float fVolume ); virtual int Read( float *pBuf, int iFrames ); virtual bool SetProperty( const RString &sProperty, float fValue );