fix: master volume not updating on playing sounds. (via smx)

This commit is contained in:
Colby Klein
2019-03-15 18:10:19 -07:00
parent 567f8363e8
commit 996b69cb01
5 changed files with 21 additions and 9 deletions
+16 -2
View File
@@ -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;
}