From 15880eafd6c3a6360c02ac5ca9af5ad6443a0395 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Tue, 4 Oct 2005 06:51:06 +0000 Subject: [PATCH] When in attract and not playing attract sounds, have SOUNDMAN only play sounds with RageSoundParams.m_bCriticalSound == true. Currently, only the coin sound has RageSoundParams.m_bCriticalSound = true. --- stepmania/src/GameState.cpp | 2 +- stepmania/src/GameState.h | 2 +- stepmania/src/RageSound.cpp | 9 ++++----- stepmania/src/RageSound.h | 2 ++ stepmania/src/RageSoundManager.cpp | 10 +++++++++- stepmania/src/RageSoundManager.h | 6 +++++- stepmania/src/ScreenAttract.cpp | 3 +++ stepmania/src/ScreenDebugOverlay.cpp | 2 +- stepmania/src/ScreenDemonstration.cpp | 2 -- stepmania/src/ScreenGameplay.cpp | 2 +- stepmania/src/ScreenManager.cpp | 1 + stepmania/src/ScreenOptionsMaster.cpp | 2 +- stepmania/src/StepMania.cpp | 2 +- 13 files changed, 30 insertions(+), 15 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 75baf583f8..8234254724 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -1647,7 +1647,7 @@ bool GameState::OneIsHot() const return false; } -bool GameState::IsTimeToPlaySounds() const +bool GameState::IsTimeToPlayAttractSounds() const { if( !GAMESTATE->m_bDemonstrationOrJukebox ) return true; diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 23813b3abf..eb03884508 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -267,7 +267,7 @@ public: // Attract stuff // int m_iNumTimesThroughAttract; // negative means play regardless of m_iAttractSoundFrequency setting - bool IsTimeToPlaySounds() const; + bool IsTimeToPlayAttractSounds() const; void VisitAttractScreen( const CString sScreenName ); // diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 1b390c57aa..04c1983a31 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -29,7 +29,6 @@ #include "PrefsManager.h" #include "arch/ArchHooks/ArchHooks.h" #include "RageSoundUtil.h" -#include "GameState.h" #include "RageSoundReader_Preload.h" #include "RageSoundReader_Resample.h" @@ -52,14 +51,12 @@ RageSoundParams::RageSoundParams(): m_LengthSeconds = -1; m_FadeLength = 0; m_Volume = 1.0f; - - if( !GAMESTATE->IsTimeToPlaySounds() ) - m_Volume = 0; - m_Balance = 0; // center speed_input_samples = speed_output_samples = 1; m_bAccurateSync = false; StopMode = M_AUTO; + + m_bIsCriticalSound = false; } RageSound::RageSound(): @@ -890,6 +887,8 @@ float RageSound::GetAbsoluteVolume() const { float f = m_Param.m_Volume; f *= SOUNDMAN->GetMixVolume(); + if( SOUNDMAN->GetPlayOnlyCriticalSounds() && !m_Param.m_bIsCriticalSound ) + f *= 0; return f; } diff --git a/stepmania/src/RageSound.h b/stepmania/src/RageSound.h index 329e2bc103..79566ec8be 100644 --- a/stepmania/src/RageSound.h +++ b/stepmania/src/RageSound.h @@ -72,6 +72,8 @@ struct RageSoundParams M_CONTINUE, M_AUTO } StopMode; + + bool m_bIsCriticalSound; // "is a sound that should be played even during attract" }; class RageSound: public RageSoundBase diff --git a/stepmania/src/RageSoundManager.cpp b/stepmania/src/RageSoundManager.cpp index 42b29e9e0a..8130ac1022 100644 --- a/stepmania/src/RageSoundManager.cpp +++ b/stepmania/src/RageSoundManager.cpp @@ -32,6 +32,7 @@ RageSoundManager::RageSoundManager() { pos_map_queue.reserve( 1024 ); m_fMixVolume = 1.0f; + m_bPlayOnlyCriticalSounds = false; } void RageSoundManager::Init( CString sDrivers ) @@ -328,13 +329,20 @@ void RageSoundManager::PlayOnce( CString sPath ) DeleteSoundWhenFinished( pSound ); } -void RageSoundManager::SetPrefs( float fMixVol ) +void RageSoundManager::SetMixVolume( float fMixVol ) { g_SoundManMutex.Lock(); /* lock for access to m_fMixVolume */ m_fMixVolume = fMixVol; g_SoundManMutex.Unlock(); /* finished with m_fMixVolume */ } +void RageSoundManager::SetPlayOnlyCriticalSounds( bool bPlayOnlyCriticalSounds ) +{ + g_SoundManMutex.Lock(); /* lock for access to m_bPlayOnlyCriticalSounds */ + m_bPlayOnlyCriticalSounds = bPlayOnlyCriticalSounds; + g_SoundManMutex.Unlock(); /* finished with m_bPlayOnlyCriticalSounds */ +} + /* Standalone helpers: */ void RageSoundManager::AttenuateBuf( int16_t *pBuf, int iSamples, float fVolume ) { diff --git a/stepmania/src/RageSoundManager.h b/stepmania/src/RageSoundManager.h index 7b5a242e34..55a82e5ce0 100644 --- a/stepmania/src/RageSoundManager.h +++ b/stepmania/src/RageSoundManager.h @@ -29,7 +29,9 @@ public: void Init( CString sDrivers ); float GetMixVolume() const { return m_fMixVolume; } - void SetPrefs( float fMixVol ); + void SetMixVolume( float fMixVol ); + bool GetPlayOnlyCriticalSounds() const { return m_bPlayOnlyCriticalSounds; } + void SetPlayOnlyCriticalSounds( bool bPlayOnlyCriticalSounds ); void Update( float fDeltaTime ); void StartMixing( RageSoundBase *snd ); /* used by RageSound */ @@ -72,6 +74,8 @@ private: /* Prefs: */ float m_fMixVolume; + bool m_bPlayOnlyCriticalSounds; + struct queued_pos_map_t { int ID, pos, got_frames; diff --git a/stepmania/src/ScreenAttract.cpp b/stepmania/src/ScreenAttract.cpp index 5d78db8bd3..ffa0e9c4fc 100644 --- a/stepmania/src/ScreenAttract.cpp +++ b/stepmania/src/ScreenAttract.cpp @@ -14,6 +14,7 @@ #include "GameSoundManager.h" #include "CommonMetrics.h" #include "InputEventPlus.h" +#include "RageSoundManager.h" #define START_SCREEN(sScreenName) THEME->GetMetric (sScreenName,"StartScreen") @@ -26,6 +27,7 @@ ScreenAttract::ScreenAttract( CString sName, bool bResetGameState ) : ScreenWith GAMESTATE->Reset(); GAMESTATE->VisitAttractScreen( sName ); + SOUNDMAN->SetPlayOnlyCriticalSounds( GAMESTATE->IsTimeToPlayAttractSounds() ); // mute attract sounds } @@ -70,6 +72,7 @@ void ScreenAttract::AttractInput( const InputEventPlus &input, ScreenWithMenuEle SCREENMAN->PlayCoinSound(); pScreen->Cancel( SM_GoToStartScreen ); + SOUNDMAN->SetPlayOnlyCriticalSounds( false ); // unmute attract sounds break; default: ASSERT(0); diff --git a/stepmania/src/ScreenDebugOverlay.cpp b/stepmania/src/ScreenDebugOverlay.cpp index 160d7a740a..19bd9e5b22 100644 --- a/stepmania/src/ScreenDebugOverlay.cpp +++ b/stepmania/src/ScreenDebugOverlay.cpp @@ -333,7 +333,7 @@ void ChangeVolume( float fDelta ) fVol += fDelta; CLAMP( fVol, 0.0f, 1.0f ); PREFSMAN->m_fSoundVolume.Set( fVol ); - SOUNDMAN->SetPrefs( PREFSMAN->m_fSoundVolume ); + SOUNDMAN->SetMixVolume( PREFSMAN->m_fSoundVolume ); } diff --git a/stepmania/src/ScreenDemonstration.cpp b/stepmania/src/ScreenDemonstration.cpp index 39ad319679..cbe7b42dc8 100644 --- a/stepmania/src/ScreenDemonstration.cpp +++ b/stepmania/src/ScreenDemonstration.cpp @@ -86,13 +86,11 @@ void ScreenDemonstration::HandleScreenMessage( const ScreenMessage SM ) } else if( SM == SM_LoseFocus ) { - SOUNDMAN->SetPrefs( PREFSMAN->GetSoundVolume() ); // turn volume back on } else if( SM == SM_GoToNextScreen ) { if( m_pSoundMusic ) m_pSoundMusic->Stop(); - SOUNDMAN->SetPrefs( PREFSMAN->GetSoundVolume() ); // turn volume back on } ScreenJukebox::HandleScreenMessage( SM ); diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index a6e31965e7..8ca8083420 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -1374,7 +1374,7 @@ float ScreenGameplay::StartPlayingSong(float MinTimeToNotes, float MinTimeToMusi p.m_StartSecond = fStartSecond; // Silence music if not playing attract sounds in demonstration. - if( !GAMESTATE->IsTimeToPlaySounds() ) + if( !GAMESTATE->IsTimeToPlayAttractSounds() ) p.m_Volume = 0; ASSERT( !m_pSoundMusic->IsPlaying() ); diff --git a/stepmania/src/ScreenManager.cpp b/stepmania/src/ScreenManager.cpp index f80d2c8955..d550927f89 100644 --- a/stepmania/src/ScreenManager.cpp +++ b/stepmania/src/ScreenManager.cpp @@ -812,6 +812,7 @@ void ScreenManager::PlayCoinSound() { RageSoundParams p; p.m_Volume = PREFSMAN->m_fSoundVolume; + p.m_bIsCriticalSound = true; m_soundCoin.Play( &p ); } diff --git a/stepmania/src/ScreenOptionsMaster.cpp b/stepmania/src/ScreenOptionsMaster.cpp index 3a9fb24f05..9f5393f59d 100644 --- a/stepmania/src/ScreenOptionsMaster.cpp +++ b/stepmania/src/ScreenOptionsMaster.cpp @@ -215,7 +215,7 @@ void ScreenOptionsMaster::HandleScreenMessage( const ScreenMessage SM ) if( m_iChangeMask & OPT_APPLY_SOUND ) { - SOUNDMAN->SetPrefs( PREFSMAN->GetSoundVolume() ); + SOUNDMAN->SetMixVolume( PREFSMAN->GetSoundVolume() ); } if( m_iChangeMask & OPT_APPLY_SONG ) diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 39e8e5209f..00e9b876e1 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -1098,7 +1098,7 @@ int main(int argc, char* argv[]) LOG->Info( "Sound writeahead has been overridden to %i", PREFSMAN->m_iSoundWriteAhead.Get() ); SOUNDMAN = new RageSoundManager; SOUNDMAN->Init( PREFSMAN->GetSoundDrivers() ); - SOUNDMAN->SetPrefs( PREFSMAN->GetSoundVolume() ); + SOUNDMAN->SetMixVolume( PREFSMAN->GetSoundVolume() ); SOUND = new GameSoundManager; BOOKKEEPER = new Bookkeeper; LIGHTSMAN = new LightsManager( PREFSMAN->GetLightsDriver() );