Skip to content

Commit

Permalink
Add CLOCK_MONOTONIC_RAW as second audio log clock
Browse files Browse the repository at this point in the history
I've had to correct part of the sound effects during editing because
they were logged to have happened like 0-2 seconds late, I didn't know
you could also choose a different clock. Let's choose the "raw hard-
ware-based time that is not subject to NTP adjustments or the
incremental adjustments performed by adjtime(3)."

See clock_gettime(2)
  • Loading branch information
Daaaav committed Sep 20, 2021
1 parent 9308f9c commit 83e6fb8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions desktop_version/src/Music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ musicclass::musicclass(void)

void musicclass::audio_log_set_timestamp(void)
{
clock_gettime(CLOCK_REALTIME, &audio_log_t);
sprintf(audio_log_timestring_lol, "%lu.%lu", audio_log_t.tv_sec, audio_log_t.tv_nsec);
clock_gettime(CLOCK_REALTIME, &audio_log_t_realtime);
clock_gettime(CLOCK_MONOTONIC_RAW, &audio_log_t_monotonic);

sprintf(audio_log_timestring_lol, "%lu.%lu;%lu.%lu",
audio_log_t_realtime.tv_sec, audio_log_t_realtime.tv_nsec,
audio_log_t_monotonic.tv_sec, audio_log_t_monotonic.tv_nsec
);
}

void musicclass::start_audio_log(void)
Expand Down
3 changes: 2 additions & 1 deletion desktop_version/src/Music.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class musicclass
int num_mmmmmm_tracks;

// Audio log
struct timespec audio_log_t;
struct timespec audio_log_t_realtime;
struct timespec audio_log_t_monotonic;
char audio_log_timestring_lol[100];

bool audio_log_started;
Expand Down

0 comments on commit 83e6fb8

Please sign in to comment.