make volume changes affect playing sounds

This commit is contained in:
Chris Danford
2005-10-02 08:35:46 +00:00
parent 4f44d6591f
commit 7b345b5c75
5 changed files with 14 additions and 10 deletions
+7 -5
View File
@@ -50,7 +50,7 @@ RageSoundParams::RageSoundParams():
m_StartSecond = 0;
m_LengthSeconds = -1;
m_FadeLength = 0;
m_Volume = -1.0f; // use SOUNDMAN->GetMixVolume()
m_Volume = 1.0f;
m_Balance = 0; // center
speed_input_samples = speed_output_samples = 1;
m_bAccurateSync = false;
@@ -574,10 +574,6 @@ int RageSound::GetPCM( char *pBuffer, int iSize, int64_t iFrameno )
* playing, Stop is called. */
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 );
/* 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;
}
float RageSound::GetAbsoluteVolume() const
{
float f = m_Param.m_Volume * SOUNDMAN->GetMixVolume();
return f;
}
void RageSound::LockSound()
{
m_Mutex.Lock();
+3 -1
View File
@@ -22,6 +22,7 @@ public:
virtual int GetSampleRate() const = 0;
virtual RageTimer GetStartTime() const { return RageZeroTimer; }
virtual float GetVolume() const = 0;
virtual float GetAbsoluteVolume() const = 0;
virtual int GetID() const = 0;
virtual CString GetLoadedFilePath() const = 0;
virtual bool IsStreamingFromDisk() const = 0;
@@ -42,7 +43,7 @@ struct RageSoundParams
void SetNoFade() { m_FadeLength = 0; }
float m_Volume;
float m_Volume; // multiplies with SOUNDMAN->GetMixVolume()
/* Pan: -1, left; 1, right */
float m_Balance;
@@ -138,6 +139,7 @@ public:
float GetPlaybackRate() const;
RageTimer GetStartTime() const;
float GetVolume() const;
float GetAbsoluteVolume() const; // factors in SOUNDMAN->GetMixVolume()
int GetID() const { return m_iID; }
void SetParams( const RageSoundParams &p );
const RageSoundParams &GetParams() const { return m_Param; }
@@ -130,7 +130,7 @@ bool RageSound_ALSA9::stream::GetData( bool &bEOF )
bytes_read += 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 )
{
@@ -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. */
if(state != FLUSHING)
{
pcm->SetVolume( snd->GetVolume() );
pcm->SetVolume( snd->GetAbsoluteVolume() );
int bytes_read = 0;
int bytes_left = len;
@@ -181,7 +181,7 @@ void RageSound_Generic_Software::DecodeThread()
{
/* The volume can change while the sound is playing; update it. */
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.start_time = snd->GetStartTime();
s.sound_id = snd->GetID();
s.volume = snd->GetVolume();
s.volume = snd->GetAbsoluteVolume();
s.buffer.clear();
/* Initialize the sound buffer. */