This broke beat alignment, and after that was fixed, other questions

came up (like how to align beat effects correctly).  Revert this and
fix assist tick differently.

Add GetBeatAndBPSFromElapsedTimeNoOffset, GetBeatFromElapsedTimeNoOffset,
GetElapsedTimeFromBeatNoOffset.  Use them to ignore GlobalOffsetSeconds.
This commit is contained in:
Glenn Maynard
2006-03-29 11:12:20 +00:00
parent 48063cef68
commit 788ad134f1
7 changed files with 39 additions and 21 deletions
+7 -7
View File
@@ -207,7 +207,7 @@ static void StartMusic( MusicToPlay &ToPlay )
* common when starting a precached sound, but our sound isn't, so it'll * common when starting a precached sound, but our sound isn't, so it'll
* probably take a little longer. Nudge the latency up. */ * probably take a little longer. Nudge the latency up. */
const float fPresumedLatency = SOUND->GetPlayLatency() + 0.040f; const float fPresumedLatency = SOUND->GetPlayLatency() + 0.040f;
const float fCurSecond = GAMESTATE->m_fMusicSecondsNoOffset + fPresumedLatency; const float fCurSecond = GAMESTATE->m_fMusicSeconds + fPresumedLatency;
const float fCurBeat = g_Playing->m_Timing.GetBeatFromElapsedTime( fCurSecond ); const float fCurBeat = g_Playing->m_Timing.GetBeatFromElapsedTime( fCurSecond );
/* The beat that the new sound will start on. */ /* The beat that the new sound will start on. */
@@ -220,7 +220,7 @@ static void StartMusic( MusicToPlay &ToPlay )
const float fSecondToStartOn = g_Playing->m_Timing.GetElapsedTimeFromBeat( fCurBeatToStartOn ); const float fSecondToStartOn = g_Playing->m_Timing.GetElapsedTimeFromBeat( fCurBeatToStartOn );
const float fMaximumDistance = 2; const float fMaximumDistance = 2;
const float fDistance = min( fSecondToStartOn - GAMESTATE->m_fMusicSecondsNoOffset, fMaximumDistance ); const float fDistance = min( fSecondToStartOn - GAMESTATE->m_fMusicSeconds, fMaximumDistance );
when = GAMESTATE->m_LastBeatUpdate + fDistance; when = GAMESTATE->m_LastBeatUpdate + fDistance;
} }
@@ -490,8 +490,8 @@ void GameSoundManager::Update( float fDeltaTime )
if( !g_Playing->m_Music->IsPlaying() ) if( !g_Playing->m_Music->IsPlaying() )
{ {
/* There's no song playing. Fake it. */ /* There's no song playing. Fake it. */
CHECKPOINT_M( ssprintf("%f, delta %f", GAMESTATE->m_fMusicSecondsNoOffset, fDeltaTime) ); CHECKPOINT_M( ssprintf("%f, delta %f", GAMESTATE->m_fMusicSeconds, fDeltaTime) );
GAMESTATE->UpdateSongPosition( GAMESTATE->m_fMusicSecondsNoOffset + fDeltaTime, g_Playing->m_Timing ); GAMESTATE->UpdateSongPosition( GAMESTATE->m_fMusicSeconds + fDeltaTime, g_Playing->m_Timing );
return; return;
} }
@@ -509,7 +509,7 @@ void GameSoundManager::Update( float fDeltaTime )
if( PREFSMAN->m_bLogSkips && !g_Playing->m_bTimingDelayed ) if( PREFSMAN->m_bLogSkips && !g_Playing->m_bTimingDelayed )
{ {
const float fExpectedTimePassed = (tm - GAMESTATE->m_LastBeatUpdate) * g_Playing->m_Music->GetPlaybackRate(); const float fExpectedTimePassed = (tm - GAMESTATE->m_LastBeatUpdate) * g_Playing->m_Music->GetPlaybackRate();
const float fSoundTimePassed = fSeconds - GAMESTATE->m_fMusicSecondsNoOffset; const float fSoundTimePassed = fSeconds - GAMESTATE->m_fMusicSeconds;
const float fDiff = fExpectedTimePassed - fSoundTimePassed; const float fDiff = fExpectedTimePassed - fSoundTimePassed;
static RString sLastFile = ""; static RString sLastFile = "";
@@ -518,7 +518,7 @@ void GameSoundManager::Update( float fDeltaTime )
/* If fSoundTimePassed < 0, the sound has probably looped. */ /* If fSoundTimePassed < 0, the sound has probably looped. */
if( sLastFile == ThisFile && fSoundTimePassed >= 0 && fabsf(fDiff) > 0.003f ) if( sLastFile == ThisFile && fSoundTimePassed >= 0 && fabsf(fDiff) > 0.003f )
LOG->Trace("Song position skip in %s: expected %.3f, got %.3f (cur %f, prev %f) (%.3f difference)", LOG->Trace("Song position skip in %s: expected %.3f, got %.3f (cur %f, prev %f) (%.3f difference)",
Basename(ThisFile).c_str(), fExpectedTimePassed, fSoundTimePassed, fSeconds, GAMESTATE->m_fMusicSecondsNoOffset, fDiff ); Basename(ThisFile).c_str(), fExpectedTimePassed, fSoundTimePassed, fSeconds, GAMESTATE->m_fMusicSeconds, fDiff );
sLastFile = ThisFile; sLastFile = ThisFile;
} }
@@ -537,7 +537,7 @@ void GameSoundManager::Update( float fDeltaTime )
{ {
/* We're still waiting for the new sound to start playing, so keep using the /* We're still waiting for the new sound to start playing, so keep using the
* old timing data and fake the time. */ * old timing data and fake the time. */
GAMESTATE->UpdateSongPosition( GAMESTATE->m_fMusicSecondsNoOffset + fDeltaTime, g_Playing->m_Timing ); GAMESTATE->UpdateSongPosition( GAMESTATE->m_fMusicSeconds + fDeltaTime, g_Playing->m_Timing );
} }
else else
{ {
-5
View File
@@ -582,7 +582,6 @@ const float GameState::MUSIC_SECONDS_INVALID = -5000.0f;
void GameState::ResetMusicStatistics() void GameState::ResetMusicStatistics()
{ {
m_fMusicSeconds = 0; // MUSIC_SECONDS_INVALID; m_fMusicSeconds = 0; // MUSIC_SECONDS_INVALID;
m_fMusicSecondsNoOffset = 0;
m_fSongBeat = 0; m_fSongBeat = 0;
m_fCurBPS = 10; m_fCurBPS = 10;
m_bFreeze = false; m_bFreeze = false;
@@ -644,10 +643,6 @@ void GameState::ResetStageStatistics()
void GameState::UpdateSongPosition( float fPositionSeconds, const TimingData &timing, const RageTimer &timestamp ) void GameState::UpdateSongPosition( float fPositionSeconds, const TimingData &timing, const RageTimer &timestamp )
{ {
m_fMusicSecondsNoOffset = fPositionSeconds;
fPositionSeconds += PREFSMAN->m_fGlobalOffsetSeconds;
if( !timestamp.IsZero() ) if( !timestamp.IsZero() )
m_LastBeatUpdate = timestamp; m_LastBeatUpdate = timestamp;
else else
-1
View File
@@ -157,7 +157,6 @@ public:
// Let a lot of classes access this info here so the don't have to keep their own copies. // Let a lot of classes access this info here so the don't have to keep their own copies.
// //
float m_fMusicSeconds; // time into the current song float m_fMusicSeconds; // time into the current song
float m_fMusicSecondsNoOffset; // time into the current song, ignoring m_fGlobalOffsetSeconds
float m_fSongBeat; float m_fSongBeat;
float m_fCurBPS; float m_fCurBPS;
float m_fLightSongBeat; // g_fLightsFalloffSeconds ahead float m_fLightSongBeat; // g_fLightsFalloffSeconds ahead
+4 -4
View File
@@ -782,9 +782,9 @@ void ScreenEdit::PlayTicks()
* will start coming out the speaker. Compensate for this by boosting fPositionSeconds * will start coming out the speaker. Compensate for this by boosting fPositionSeconds
* ahead. This is just to make sure that we request the sound early enough for it to * ahead. This is just to make sure that we request the sound early enough for it to
* come out on time; the actual precise timing is handled by SetStartTime. */ * come out on time; the actual precise timing is handled by SetStartTime. */
float fPositionSeconds = GAMESTATE->m_fMusicSecondsNoOffset; float fPositionSeconds = GAMESTATE->m_fMusicSeconds;
fPositionSeconds += SOUND->GetPlayLatency() + (float)CommonMetrics::TICK_EARLY_SECONDS + 0.250f; fPositionSeconds += SOUND->GetPlayLatency() + (float)CommonMetrics::TICK_EARLY_SECONDS + 0.250f;
const float fSongBeat = GAMESTATE->m_pCurSong->GetBeatFromElapsedTime( fPositionSeconds ); const float fSongBeat = GAMESTATE->m_pCurSong->m_Timing.GetBeatFromElapsedTimeNoOffset( fPositionSeconds );
const int iSongRow = max( 0, BeatToNoteRowNotRounded( fSongBeat ) ); const int iSongRow = max( 0, BeatToNoteRowNotRounded( fSongBeat ) );
static int iRowLastCrossed = -1; static int iRowLastCrossed = -1;
@@ -802,8 +802,8 @@ void ScreenEdit::PlayTicks()
if( iTickRow != -1 ) if( iTickRow != -1 )
{ {
const float fTickBeat = NoteRowToBeat( iTickRow ); const float fTickBeat = NoteRowToBeat( iTickRow );
const float fTickSecond = GAMESTATE->m_pCurSong->m_Timing.GetElapsedTimeFromBeat( fTickBeat ); const float fTickSecond = GAMESTATE->m_pCurSong->m_Timing.GetElapsedTimeFromBeatNoOffset( fTickBeat );
float fSecondsUntil = fTickSecond - GAMESTATE->m_fMusicSecondsNoOffset; float fSecondsUntil = fTickSecond - GAMESTATE->m_fMusicSeconds;
fSecondsUntil /= m_soundMusic.GetPlaybackRate(); /* 2x music rate means the time until the tick is halved */ fSecondsUntil /= m_soundMusic.GetPlaybackRate(); /* 2x music rate means the time until the tick is halved */
RageSoundParams p; RageSoundParams p;
+4 -4
View File
@@ -1433,9 +1433,9 @@ void ScreenGameplay::PlayTicks()
* will start coming out the speaker. Compensate for this by boosting fPositionSeconds * will start coming out the speaker. Compensate for this by boosting fPositionSeconds
* ahead. This is just to make sure that we request the sound early enough for it to * ahead. This is just to make sure that we request the sound early enough for it to
* come out on time; the actual precise timing is handled by SetStartTime. */ * come out on time; the actual precise timing is handled by SetStartTime. */
float fPositionSeconds = GAMESTATE->m_fMusicSecondsNoOffset; float fPositionSeconds = GAMESTATE->m_fMusicSeconds;
fPositionSeconds += SOUND->GetPlayLatency() + (float)CommonMetrics::TICK_EARLY_SECONDS + 0.250f; fPositionSeconds += SOUND->GetPlayLatency() + (float)CommonMetrics::TICK_EARLY_SECONDS + 0.250f;
const float fSongBeat = GAMESTATE->m_pCurSong->GetBeatFromElapsedTime( fPositionSeconds ); const float fSongBeat = GAMESTATE->m_pCurSong->m_Timing.GetBeatFromElapsedTimeNoOffset( fPositionSeconds );
const int iSongRow = max( 0, BeatToNoteRowNotRounded( fSongBeat ) ); const int iSongRow = max( 0, BeatToNoteRowNotRounded( fSongBeat ) );
static int iRowLastCrossed = -1; static int iRowLastCrossed = -1;
@@ -1454,8 +1454,8 @@ void ScreenGameplay::PlayTicks()
if( iTickRow != -1 ) if( iTickRow != -1 )
{ {
const float fTickBeat = NoteRowToBeat( iTickRow ); const float fTickBeat = NoteRowToBeat( iTickRow );
const float fTickSecond = GAMESTATE->m_pCurSong->m_Timing.GetElapsedTimeFromBeat( fTickBeat ); const float fTickSecond = GAMESTATE->m_pCurSong->m_Timing.GetElapsedTimeFromBeatNoOffset( fTickBeat );
float fSecondsUntil = fTickSecond - GAMESTATE->m_fMusicSecondsNoOffset; float fSecondsUntil = fTickSecond - GAMESTATE->m_fMusicSeconds;
fSecondsUntil /= GAMESTATE->m_SongOptions.m_fMusicRate; /* 2x music rate means the time until the tick is halved */ fSecondsUntil /= GAMESTATE->m_SongOptions.m_fMusicRate; /* 2x music rate means the time until the tick is halved */
RageSoundParams p; RageSoundParams p;
+13
View File
@@ -1,5 +1,6 @@
#include "global.h" #include "global.h"
#include "TimingData.h" #include "TimingData.h"
#include "PrefsManager.h"
#include "RageUtil.h" #include "RageUtil.h"
#include "RageLog.h" #include "RageLog.h"
#include "NoteTypes.h" #include "NoteTypes.h"
@@ -197,6 +198,13 @@ BPMSegment& TimingData::GetBPMSegmentAtBeat( float fBeat )
} }
void TimingData::GetBeatAndBPSFromElapsedTime( float fElapsedTime, float &fBeatOut, float &fBPSOut, bool &bFreezeOut ) const void TimingData::GetBeatAndBPSFromElapsedTime( float fElapsedTime, float &fBeatOut, float &fBPSOut, bool &bFreezeOut ) const
{
fElapsedTime += PREFSMAN->m_fGlobalOffsetSeconds;
GetBeatAndBPSFromElapsedTimeNoOffset( fElapsedTime, fBeatOut, fBPSOut, bFreezeOut );
}
void TimingData::GetBeatAndBPSFromElapsedTimeNoOffset( float fElapsedTime, float &fBeatOut, float &fBPSOut, bool &bFreezeOut ) const
{ {
// LOG->Trace( "GetBeatAndBPSFromElapsedTime( fElapsedTime = %f )", fElapsedTime ); // LOG->Trace( "GetBeatAndBPSFromElapsedTime( fElapsedTime = %f )", fElapsedTime );
@@ -259,6 +267,11 @@ void TimingData::GetBeatAndBPSFromElapsedTime( float fElapsedTime, float &fBeatO
float TimingData::GetElapsedTimeFromBeat( float fBeat ) const float TimingData::GetElapsedTimeFromBeat( float fBeat ) const
{
return TimingData::GetElapsedTimeFromBeatNoOffset( fBeat ) - PREFSMAN->m_fGlobalOffsetSeconds;
}
float TimingData::GetElapsedTimeFromBeatNoOffset( float fBeat ) const
{ {
float fElapsedTime = 0; float fElapsedTime = 0;
fElapsedTime -= m_fBeat0OffsetInSeconds; fElapsedTime -= m_fBeat0OffsetInSeconds;
+11
View File
@@ -69,6 +69,17 @@ public:
return fBeat; return fBeat;
} }
float GetElapsedTimeFromBeat( float fBeat ) const; float GetElapsedTimeFromBeat( float fBeat ) const;
void GetBeatAndBPSFromElapsedTimeNoOffset( float fElapsedTime, float &fBeatOut, float &fBPSOut, bool &bFreezeOut ) const;
float GetBeatFromElapsedTimeNoOffset( float fElapsedTime ) const // shortcut for places that care only about the beat
{
float fBeat, fThrowAway;
bool bThrowAway;
GetBeatAndBPSFromElapsedTimeNoOffset( fElapsedTime, fBeat, fThrowAway, bThrowAway );
return fBeat;
}
float GetElapsedTimeFromBeatNoOffset( float fBeat ) const;
bool HasBpmChanges() const; bool HasBpmChanges() const;
bool HasStops() const; bool HasStops() const;