1 #ifndef INCLUDE_AL_TIME_HPP
2 #define INCLUDE_AL_TIME_HPP
55 typedef double al_sec;
58 #define al_time_ns2s 1.0e-9
59 #define al_time_s2ns 1.0e9
65 al_nsec al_system_time_nsec();
67 void al_start_steady_clock();
68 void al_reset_steady_clock();
69 al_sec al_steady_time();
70 al_nsec al_steady_time_nsec();
74 void al_sleep_nsec(al_nsec dt);
75 void al_sleep_until(al_sec target);
78 inline void wait(al_sec dt) {
al_sleep(dt); }
83 std::string
toTimecode(al_nsec t,
const std::string& format =
"D:H:M:S:m:u");
90 Timer(
bool setStartTime =
true) {
91 if (setStartTime)
start();
95 al_nsec
elapsed()
const {
return mStop - mStart; }
101 void start() { mStart = getTime(); }
104 void stop() { mStop = getTime(); }
110 al_nsec mStart = 0, mStop = 0;
111 static al_nsec getTime() {
return al_steady_time_nsec(); }
126 tperiod = step_period;
142 void operator()(al_sec realtime) {
step(realtime); }
197 al_sec
now()
const {
return mNow; }
198 al_sec operator()()
const {
return mNow; }
201 al_sec
dt()
const {
return mDT; }
204 double fps()
const {
return mFPS; }
207 unsigned frame()
const {
return mFrame; }
210 bool rt()
const {
return bUseRT; }
219 mFPS = mFPS + 0.1 * ((1. / mDT) - mFPS);
247 al_sec mNow, mReferenceTime, mDT;
bool rt() const
get current mode:
al_sec update()
update the internal clock.
al_sec now() const
get current clock time
unsigned frame() const
get current frame:
al_sec dt() const
get current delta time
double fps() const
get current FPS:
void useNRT(al_sec dt)
set NRT mode with specific frame rate:
Clock(bool useRT=true)
Constructor that defaults to realtime mode.
Clock(al_sec dt)
Constructor that defaults to a fixed 'frame rate'.
al_sec rate_smoothed() const
Get the current rate estimation (smoothed)
void step(al_sec realtime)
Trigger this from the periodic event.
al_sec rate_ideal() const
Get the ideal rate.
void setBandwidth(double bandwidth)
Set degree of smoothing.
al_sec period_smoothed() const
Get the current period estimation (smoothed)
al_sec realtime_interp(double alpha) const
Returns time estimate between current and next event.
al_sec period_ideal() const
Get the ideal period.
void reset()
Call this after an xrun: will reset the timing adjustments.
al_sec elapsedSec() const
Returns seconds between start() and stop() calls.
void print() const
Print current elapsed time.
void start()
Set start time to current time.
al_nsec elapsed() const
Returns nsec between start() and stop() calls.
void stop()
Set stop time to current time.
al_sec al_system_time()
Get current wall time in seconds.
std::string toTimecode(al_nsec t, const std::string &format="D:H:M:S:m:u")
Convert nanoseconds to timecode string.
void al_sleep(al_sec dt)
Sleep for an interval of seconds.