make volume changes affect playing sounds
This commit is contained in:
@@ -50,7 +50,7 @@ RageSoundParams::RageSoundParams():
|
|||||||
m_StartSecond = 0;
|
m_StartSecond = 0;
|
||||||
m_LengthSeconds = -1;
|
m_LengthSeconds = -1;
|
||||||
m_FadeLength = 0;
|
m_FadeLength = 0;
|
||||||
m_Volume = -1.0f; // use SOUNDMAN->GetMixVolume()
|
m_Volume = 1.0f;
|
||||||
m_Balance = 0; // center
|
m_Balance = 0; // center
|
||||||
speed_input_samples = speed_output_samples = 1;
|
speed_input_samples = speed_output_samples = 1;
|
||||||
m_bAccurateSync = false;
|
m_bAccurateSync = false;
|
||||||
@@ -574,10 +574,6 @@ int RageSound::GetPCM( char *pBuffer, int iSize, int64_t iFrameno )
|
|||||||
* playing, Stop is called. */
|
* playing, Stop is called. */
|
||||||
void RageSound::StartPlaying()
|
void RageSound::StartPlaying()
|
||||||
{
|
{
|
||||||
// If no volume is set, use the default.
|
|
||||||
if( m_Param.m_Volume == -1 )
|
|
||||||
m_Param.m_Volume = SOUNDMAN->GetMixVolume();
|
|
||||||
|
|
||||||
ASSERT( !m_bPlaying );
|
ASSERT( !m_bPlaying );
|
||||||
|
|
||||||
/* If m_StartTime is in the past, then we probably set a start time but took too
|
/* If m_StartTime is in the past, then we probably set a start time but took too
|
||||||
@@ -885,6 +881,12 @@ float RageSound::GetVolume() const
|
|||||||
return m_Param.m_Volume;
|
return m_Param.m_Volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float RageSound::GetAbsoluteVolume() const
|
||||||
|
{
|
||||||
|
float f = m_Param.m_Volume * SOUNDMAN->GetMixVolume();
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
void RageSound::LockSound()
|
void RageSound::LockSound()
|
||||||
{
|
{
|
||||||
m_Mutex.Lock();
|
m_Mutex.Lock();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public:
|
|||||||
virtual int GetSampleRate() const = 0;
|
virtual int GetSampleRate() const = 0;
|
||||||
virtual RageTimer GetStartTime() const { return RageZeroTimer; }
|
virtual RageTimer GetStartTime() const { return RageZeroTimer; }
|
||||||
virtual float GetVolume() const = 0;
|
virtual float GetVolume() const = 0;
|
||||||
|
virtual float GetAbsoluteVolume() const = 0;
|
||||||
virtual int GetID() const = 0;
|
virtual int GetID() const = 0;
|
||||||
virtual CString GetLoadedFilePath() const = 0;
|
virtual CString GetLoadedFilePath() const = 0;
|
||||||
virtual bool IsStreamingFromDisk() const = 0;
|
virtual bool IsStreamingFromDisk() const = 0;
|
||||||
@@ -42,7 +43,7 @@ struct RageSoundParams
|
|||||||
|
|
||||||
void SetNoFade() { m_FadeLength = 0; }
|
void SetNoFade() { m_FadeLength = 0; }
|
||||||
|
|
||||||
float m_Volume;
|
float m_Volume; // multiplies with SOUNDMAN->GetMixVolume()
|
||||||
|
|
||||||
/* Pan: -1, left; 1, right */
|
/* Pan: -1, left; 1, right */
|
||||||
float m_Balance;
|
float m_Balance;
|
||||||
@@ -138,6 +139,7 @@ public:
|
|||||||
float GetPlaybackRate() const;
|
float GetPlaybackRate() const;
|
||||||
RageTimer GetStartTime() const;
|
RageTimer GetStartTime() const;
|
||||||
float GetVolume() const;
|
float GetVolume() const;
|
||||||
|
float GetAbsoluteVolume() const; // factors in SOUNDMAN->GetMixVolume()
|
||||||
int GetID() const { return m_iID; }
|
int GetID() const { return m_iID; }
|
||||||
void SetParams( const RageSoundParams &p );
|
void SetParams( const RageSoundParams &p );
|
||||||
const RageSoundParams &GetParams() const { return m_Param; }
|
const RageSoundParams &GetParams() const { return m_Param; }
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ bool RageSound_ALSA9::stream::GetData( bool &bEOF )
|
|||||||
bytes_read += got;
|
bytes_read += got;
|
||||||
bytes_left -= got;
|
bytes_left -= got;
|
||||||
|
|
||||||
RageSoundManager::AttenuateBuf( buf, got/sizeof(int16_t), snd->GetVolume() );
|
RageSoundManager::AttenuateBuf( buf, got/sizeof(int16_t), snd->GetAbsoluteVolume() );
|
||||||
|
|
||||||
if( bytes_left > 0 )
|
if( bytes_left > 0 )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ bool RageSound_DSound::stream::GetData( bool init, bool &bEOF )
|
|||||||
* fill anything in FLUSHING; in that case, we just clear the audio buffer. */
|
* fill anything in FLUSHING; in that case, we just clear the audio buffer. */
|
||||||
if(state != FLUSHING)
|
if(state != FLUSHING)
|
||||||
{
|
{
|
||||||
pcm->SetVolume( snd->GetVolume() );
|
pcm->SetVolume( snd->GetAbsoluteVolume() );
|
||||||
|
|
||||||
int bytes_read = 0;
|
int bytes_read = 0;
|
||||||
int bytes_left = len;
|
int bytes_left = len;
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ void RageSound_Generic_Software::DecodeThread()
|
|||||||
{
|
{
|
||||||
/* The volume can change while the sound is playing; update it. */
|
/* The volume can change while the sound is playing; update it. */
|
||||||
if( sounds[i].state == sound::PLAYING || sounds[i].state == sound::STOPPING )
|
if( sounds[i].state == sound::PLAYING || sounds[i].state == sound::STOPPING )
|
||||||
sounds[i].volume = sounds[i].snd->GetVolume();
|
sounds[i].volume = sounds[i].snd->GetAbsoluteVolume();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -327,7 +327,7 @@ void RageSound_Generic_Software::StartMixing( RageSoundBase *snd )
|
|||||||
s.snd = snd;
|
s.snd = snd;
|
||||||
s.start_time = snd->GetStartTime();
|
s.start_time = snd->GetStartTime();
|
||||||
s.sound_id = snd->GetID();
|
s.sound_id = snd->GetID();
|
||||||
s.volume = snd->GetVolume();
|
s.volume = snd->GetAbsoluteVolume();
|
||||||
s.buffer.clear();
|
s.buffer.clear();
|
||||||
|
|
||||||
/* Initialize the sound buffer. */
|
/* Initialize the sound buffer. */
|
||||||
|
|||||||
Reference in New Issue
Block a user