Tanoda
FixedIntervalClock.cs
Go to the documentation of this file.
1/*
2* NatCorder
3* Copyright (c) 2020 Yusuf Olokoba.
4*/
5
6using System.Runtime.CompilerServices;
7
9{
14 public sealed class FixedIntervalClock : IClock
15 {
19 public double interval { get; set; }
20
25 public long timestamp
26 {
27 [MethodImpl(MethodImplOptions.Synchronized)]
28 get => (long) ((autoTick ? ticks++ : ticks) * interval * 1e+9);
29 }
30
36 public FixedIntervalClock(int framerate, bool autoTick = true) : this(1.0 / framerate, autoTick)
37 {
38 }
39
45 public FixedIntervalClock(double interval, bool autoTick = true)
46 {
47 this.interval = interval;
48 ticks = 0;
49 this.autoTick = autoTick;
50 }
51
55 [MethodImpl(MethodImplOptions.Synchronized)]
56 public void Tick()
57 {
58 ticks++;
59 }
60
61 private readonly bool autoTick;
62 private int ticks;
63 }
64}
Clock that produces timestamps spaced at a fixed interval. This clock is useful for enforcing a fixed...
FixedIntervalClock(int framerate, bool autoTick=true)
Create a fixed interval clock for a given framerate.
long timestamp
Current timestamp in nanoseconds. The very first value reported by this property will always be zero.
void Tick()
Advance the clock by its time interval.
FixedIntervalClock(double interval, bool autoTick=true)
Create a fixed interval clock with a given timestamp interval.
double interval
Interval between consecutive timestamps generated by the clock in seconds.
Clock for generating recording timestamps. Clocks are important for synchronizing audio and video tra...
Definition: IClock.cs:14