@@ -21,6 +21,30 @@ public sealed class InterpolatingFramedClock : IFrameBasedClock, ISourceChangeab
2121 /// </remarks>
2222 public double AllowableErrorMilliseconds { get ; set ; } = 1000.0 / 60 * 2 ;
2323
24+ /// <summary>
25+ /// Drift recovery half-life in milliseconds. Defaults to 50 ms.
26+ /// </summary>
27+ /// <remarks>
28+ /// The time error decays exponentially toward the source.
29+ /// Every <see cref="DriftRecoveryHalfLife"/> ms, the remaining error halves.
30+ ///
31+ /// An example, starting at 10 ms error with an 50 ms half-life:
32+ ///
33+ /// - at 0 ms, error is 10 ms.
34+ /// - at 50 ms, error is 5 ms.
35+ /// - at 100 ms, error is 2.5 ms.
36+ /// - at 150 ms, error is 1.25 ms.
37+ /// ...
38+ ///
39+ /// To an observer, it will look like time has a temporary ramp applied to it:
40+ ///
41+ /// - If source is ahead, time will speed up and gradually approach original speed.
42+ /// - If source is behind, time will slow down and gradually approach original speed.
43+ ///
44+ /// Only applies when the error is within <see cref="AllowableErrorMilliseconds"/>.
45+ /// </remarks>
46+ public double DriftRecoveryHalfLife { get ; set ; } = 50 ;
47+
2448 /// <summary>
2549 /// Whether interpolation was applied at the last processed frame.
2650 /// </summary>
@@ -107,9 +131,8 @@ public void ProcessFrame()
107131 // Then check the post-interpolated time.
108132 // If we differ from the current time of the source, gradually approach the ground truth.
109133 //
110- // The remaining error halves every halfTime ms.
111- // This may need further tweaking to be less discernible by users (upwards, likely?).
112- currentTime = Interpolation . DampContinuously ( currentTime , framedSourceClock . CurrentTime , 50 , realtimeClock . ElapsedFrameTime ) ;
134+ // The remaining error halves every half-life ms.
135+ currentTime = Interpolation . DampContinuously ( currentTime , framedSourceClock . CurrentTime , DriftRecoveryHalfLife , realtimeClock . ElapsedFrameTime ) ;
113136
114137 bool withinAllowableError = Math . Abs ( framedSourceClock . CurrentTime - currentTime ) <= AllowableErrorMilliseconds * Rate ;
115138
0 commit comments