diff --git a/stepmania/src/RageSounds.cpp b/stepmania/src/RageSounds.cpp index 35da44e8e0..9d5ce9d7d7 100644 --- a/stepmania/src/RageSounds.cpp +++ b/stepmania/src/RageSounds.cpp @@ -263,7 +263,7 @@ int MusicThread_start( void *p ) { while( !g_Shutdown ) { - SDL_Delay( 10 ); + usleep( 10000 ); StartQueuedSounds(); } @@ -325,7 +325,7 @@ RageSounds::~RageSounds() delete pMusic; } -static float GetFrameTimingAdjustment( float fDeltaTime ) +float RageSounds::GetFrameTimingAdjustment( float fDeltaTime ) { /* * We get one update per frame, and we're updated early, almost immediately after vsync, @@ -501,28 +501,6 @@ float RageSounds::GetPlayLatency() const return SOUNDMAN->GetPlayLatency(); } -void RageSounds::TakeOverSound( RageSound *snd, const TimingData *Timing ) -{ - MusicPlaying *NewMusic = new MusicPlaying( snd ); - - NewMusic->m_TimingDelayed = false; - NewMusic->m_HasTiming = false; - if( Timing ) - { - NewMusic->m_HasTiming = true; - NewMusic->m_Timing = *Timing; - } - - LockMut( *g_Mutex ); - delete g_Playing; - g_Playing = NewMusic; - - Update( 0 ); - - const float fSeconds = g_Playing->m_Music->GetPositionSeconds(); - LOG->Trace("Updated: %f sec, %f beat", fSeconds, GAMESTATE->m_fSongBeat ); -} - /* * Copyright (c) 2003-2004 Glenn Maynard * All rights reserved. diff --git a/stepmania/src/RageSounds.h b/stepmania/src/RageSounds.h index 250ccfe754..5e3d9364ed 100644 --- a/stepmania/src/RageSounds.h +++ b/stepmania/src/RageSounds.h @@ -19,15 +19,13 @@ public: void StopMusic() { PlayMusic(""); } CString GetMusicPath() const; - /* Take ownership of snd; handle timing, free it, etc. */ - void TakeOverSound( RageSound *snd, const TimingData *Timing ); - void PlayOnce( CString sPath ); void PlayOnceFromDir( CString sDir ); void PlayOnceFromAnnouncer( CString sFolderName ); float GetPlayLatency() const; void HandleSongTimer( bool on=true ); + float GetFrameTimingAdjustment( float fDeltaTime ); }; extern RageSounds *SOUND; diff --git a/stepmania/src/ScreenDemonstration.cpp b/stepmania/src/ScreenDemonstration.cpp index 21ef7ffbe9..5010dfc326 100644 --- a/stepmania/src/ScreenDemonstration.cpp +++ b/stepmania/src/ScreenDemonstration.cpp @@ -99,7 +99,7 @@ void ScreenDemonstration::HandleScreenMessage( const ScreenMessage SM ) break; case SM_GoToNextScreen: - SOUND->StopMusic(); + m_soundMusic.Stop(); GAMESTATE->Reset(); SOUNDMAN->SetPrefs( PREFSMAN->m_fSoundVolume ); // turn volume back on SCREENMAN->SetNewScreen( NEXT_SCREEN ); diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index b8d3900d70..d22f88ec5e 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -103,7 +103,8 @@ void ScreenGameplay::Init() else LIGHTSMAN->SetLightsMode( LIGHTSMODE_GAMEPLAY ); - m_soundMusic = NULL; + /* We do this ourself. */ + SOUND->HandleSongTimer( false ); SECONDS_BETWEEN_COMMENTS.Refresh(); TICK_EARLY_SECONDS.Refresh(); @@ -768,6 +769,7 @@ ScreenGameplay::~ScreenGameplay() SAFE_DELETE( m_pInventory[p] ); } SAFE_DELETE( m_pCombinedLifeMeter ); + m_soundMusic.StopPlaying(); m_soundAssistTick.StopPlaying(); /* Stop any queued assist ticks. */ @@ -985,8 +987,7 @@ void ScreenGameplay::LoadNextSong() LL.LoadFromLRCFile(GAMESTATE->m_pCurSong->GetLyricsPath(), *GAMESTATE->m_pCurSong); - m_soundMusic = new RageSound; - m_soundMusic->Load( GAMESTATE->m_pCurSong->GetMusicPath() ); + m_soundMusic.Load( GAMESTATE->m_pCurSong->GetMusicPath() ); /* Set up song-specific graphics. */ @@ -1065,8 +1066,6 @@ float ScreenGameplay::StartPlayingSong(float MinTimeToNotes, float MinTimeToMusi fStartSecond = min(fStartSecond, -MinTimeToMusic); - ASSERT( m_soundMusic ); - RageSoundParams p; p.AccurateSync = true; p.SetPlaybackRate( GAMESTATE->m_SongOptions.m_fMusicRate ); @@ -1077,14 +1076,12 @@ float ScreenGameplay::StartPlayingSong(float MinTimeToNotes, float MinTimeToMusi //used for syncing up songs. NSMAN->StartRequest(); - m_soundMusic->Play( &p ); - - SOUND->TakeOverSound( m_soundMusic, &GAMESTATE->m_pCurSong->m_Timing ); - m_soundMusic = NULL; // SOUND owns it now + m_soundMusic.Play( &p ); /* Make sure GAMESTATE->m_fMusicSeconds is set up. */ GAMESTATE->m_fMusicSeconds = -5000; - SOUND->Update(0); + UpdateSongPosition(0); + ASSERT( GAMESTATE->m_fMusicSeconds > -4000 ); /* make sure the "fake timer" code doesn't trigger */ /* Return the amount of time until the first beat. */ @@ -1158,6 +1155,17 @@ void ScreenGameplay::PlayAnnouncer( CString type, float fSeconds ) m_pCombinedLifeMeter->OnTaunt(); } +void ScreenGameplay::UpdateSongPosition( float fDeltaTime ) +{ + if( !m_soundMusic.IsPlaying() ) + return; + + RageTimer tm; + const float fSeconds = m_soundMusic.GetPositionSeconds( NULL, &tm ); + const float fAdjust = SOUND->GetFrameTimingAdjustment( fDeltaTime ); + GAMESTATE->UpdateSongPosition( fSeconds+fAdjust, GAMESTATE->m_pCurSong->m_Timing, tm+fAdjust ); +} + void ScreenGameplay::Update( float fDeltaTime ) { if( GAMESTATE->m_pCurSong == NULL ) @@ -1202,6 +1210,8 @@ void ScreenGameplay::Update( float fDeltaTime ) } + UpdateSongPosition( fDeltaTime ); + if( m_bZeroDeltaOnNextUpdate ) { Screen::Update( 0 ); @@ -1607,8 +1617,8 @@ void ScreenGameplay::Input( const DeviceInput& DeviceI, const InputEventType typ * * We're doing #3. I'm not sure which is best. */ - SOUND->StopMusic(); - SOUND->HandleSongTimer( false ); + + m_soundMusic.StopPlaying(); m_soundAssistTick.StopPlaying(); /* Stop any queued assist ticks. */ this->ClearMessageQueue(); @@ -2196,8 +2206,7 @@ void ScreenGameplay::HandleScreenMessage( const ScreenMessage SM ) case SM_BeginFailed: m_DancingState = STATE_OUTRO; - SOUND->StopMusic(); - SOUND->HandleSongTimer( false ); + m_soundMusic.StopPlaying(); m_soundAssistTick.StopPlaying(); /* Stop any queued assist ticks. */ TweenOffScreen(); m_Failed.StartTransitioning( SM_GoToScreenAfterFail ); diff --git a/stepmania/src/ScreenGameplay.h b/stepmania/src/ScreenGameplay.h index e07ab90c20..b0ee63971e 100644 --- a/stepmania/src/ScreenGameplay.h +++ b/stepmania/src/ScreenGameplay.h @@ -83,6 +83,7 @@ protected: void PlayAnnouncer( CString type, float fSeconds ); void PlayTicks(); + void UpdateSongPosition( float fDeltaTime ); void UpdateLyrics( float fDeltaTime ); void UpdateCheckFail(); void SongFinished(); @@ -176,7 +177,7 @@ protected: bool m_bDemonstration; RageSound m_soundAssistTick; - RageSound *m_soundMusic; + RageSound m_soundMusic; BeginnerHelper m_BeginnerHelper; diff --git a/stepmania/src/ScreenJukebox.cpp b/stepmania/src/ScreenJukebox.cpp index 178fff3c89..ea44c184a9 100644 --- a/stepmania/src/ScreenJukebox.cpp +++ b/stepmania/src/ScreenJukebox.cpp @@ -216,7 +216,7 @@ void ScreenJukebox::HandleScreenMessage( const ScreenMessage SM ) m_Out.StartTransitioning( SM_GoToNextScreen ); return; case SM_GoToNextScreen: - SOUND->StopMusic(); + m_soundMusic.Stop(); SCREENMAN->SetNewScreen( "ScreenJukebox" ); return; }