Switch from storing total seconds to storing deltas.

This is conceptually simpler and makes the files easier to manipulate and
concatenate. It also avoids a bug where we would send a large negative
time when we loop for multiple playbacks.
This commit is contained in:
Eli Ribble 2022-09-07 17:18:47 -06:00
parent 0d0d14cc39
commit 8985f990cb
2 changed files with 4 additions and 6 deletions

View File

@ -73,6 +73,8 @@ int dump_event(struct timespec* start, struct input_event* event, char* type) {
fprintf(stderr, "Unknown event type.\n");
return 1;
}
start->tv_sec = now.tv_sec;
start->tv_nsec = now.tv_nsec;
printf("%ld %ld,%s,%s\n",
diff.tv_sec,

View File

@ -51,8 +51,6 @@ int handle_keyboard(char* details, int udevice_fd) {
}
int handle_line(char* line, int udevice_fd) {
static time_t timer_seconds = 0;
static long timer_nanos = 0;
static time_t total_seconds = 0;
static long total_nanos = 0;
@ -74,8 +72,8 @@ int handle_line(char* line, int udevice_fd) {
remaining.tv_sec = 0;
remaining.tv_nsec = 0;
to_sleep.tv_sec = seconds - timer_seconds;
to_sleep.tv_nsec = nanos - timer_nanos;
to_sleep.tv_sec = seconds;
to_sleep.tv_nsec = nanos;
if(to_sleep.tv_nsec < 0) {
--to_sleep.tv_sec;
to_sleep.tv_nsec += 1000000000L;
@ -102,8 +100,6 @@ int handle_line(char* line, int udevice_fd) {
total_nanos -= 1000000000L;
total_seconds += 1;
}
timer_seconds = seconds;
timer_nanos = nanos;
// printf("%ld %ld\tslept %ld %ld\n",
// total_seconds, total_nanos, to_sleep.tv_sec, to_sleep.tv_nsec);