From 6d85e80a407148db2eb6ca5e67ea467f87695f99 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Sat, 22 Nov 2014 13:41:57 +0000 Subject: adjust eol and set svn property svn:eol-style native git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@3085 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/base/UBeatTimer.pas | 54 ++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'src/base/UBeatTimer.pas') diff --git a/src/base/UBeatTimer.pas b/src/base/UBeatTimer.pas index bc03de76..7f68deb6 100644 --- a/src/base/UBeatTimer.pas +++ b/src/base/UBeatTimer.pas @@ -170,38 +170,38 @@ var MasterClock: real; TimeDiff: real; const - AVG_HISTORY_FACTOR = 0.7; - PAUSE_THRESHOLD = 0.010; // 10ms - FORWARD_THRESHOLD = 0.010; // 10ms + AVG_HISTORY_FACTOR = 0.7; + PAUSE_THRESHOLD = 0.010; // 10ms + FORWARD_THRESHOLD = 0.010; // 10ms begin - MasterClock := fSyncSource.GetClock(); - Result := LyricTime; - - // do not sync if lyrics are paused externally or if the timestamp is old - if (fPaused or (MasterClock = fLastClock)) then + MasterClock := fSyncSource.GetClock(); + Result := LyricTime; + + // do not sync if lyrics are paused externally or if the timestamp is old + if (fPaused or (MasterClock = fLastClock)) then Exit; // calculate average time difference (some sort of weighted mean). - // The bigger AVG_HISTORY_FACTOR is, the smoother is the average diff. - // This is done as some timestamps might be wrong or even lower - // than their predecessor. - TimeDiff := MasterClock - LyricTime; - if (fAvgSyncDiff = -1) then - fAvgSyncDiff := TimeDiff - else - fAvgSyncDiff := TimeDiff * (1-AVG_HISTORY_FACTOR) + - fAvgSyncDiff * AVG_HISTORY_FACTOR; - - {$IFDEF LOG_SYNC} - //Log.LogError(Format('TimeDiff: %.3f', [TimeDiff])); - {$ENDIF} - + // The bigger AVG_HISTORY_FACTOR is, the smoother is the average diff. + // This is done as some timestamps might be wrong or even lower + // than their predecessor. + TimeDiff := MasterClock - LyricTime; + if (fAvgSyncDiff = -1) then + fAvgSyncDiff := TimeDiff + else + fAvgSyncDiff := TimeDiff * (1-AVG_HISTORY_FACTOR) + + fAvgSyncDiff * AVG_HISTORY_FACTOR; + + {$IFDEF LOG_SYNC} + //Log.LogError(Format('TimeDiff: %.3f', [TimeDiff])); + {$ENDIF} + // do not go backwards in time as this could mess up the score if (fAvgSyncDiff > FORWARD_THRESHOLD) then begin {$IFDEF LOG_SYNC} - Log.LogError('Sync: ' + floatToStr(MasterClock) + ' > ' + floatToStr(LyricTime)); - {$ENDIF} + Log.LogError('Sync: ' + floatToStr(MasterClock) + ' > ' + floatToStr(LyricTime)); + {$ENDIF} Result := LyricTime + fAvgSyncDiff; fTimer.SetTime(Result); @@ -219,14 +219,14 @@ begin end else if (fTimer.GetState = rtsPaused) and (fAvgSyncDiff >= 0) then begin - fTimer.Start(); + fTimer.Start(); {$IFDEF LOG_SYNC} Log.LogError('Unpause: ' + floatToStr(LyricTime)); {$ENDIF} end; fLastClock := MasterClock; -end; +end; function TLyricsState.GetCurrentTime(): real; var @@ -241,7 +241,7 @@ end; procedure TLyricsState.SetSyncSource(SyncSource: TSyncSource); begin - fSyncSource := SyncSource; + fSyncSource := SyncSource; end; (** -- cgit v1.2.3