fix: use clock instead of timeofday
This commit is contained in:
@@ -11,7 +11,6 @@ AC_CHECK_HEADERS([stdlib.h])
|
||||
AC_CHECK_HEADERS([sys/ioctl.h])
|
||||
AC_CHECK_HEADERS([sys/mman.h])
|
||||
AC_CHECK_HEADERS([sys/stat.h])
|
||||
AC_CHECK_HEADERS([sys/time.h])
|
||||
AC_CHECK_HEADERS([sys/types.h])
|
||||
AC_CHECK_HEADERS([sys/wait.h])
|
||||
|
||||
|
||||
+6
-12
@@ -1,19 +1,13 @@
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "tempo.h"
|
||||
|
||||
static long now() {
|
||||
struct timeval now;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
|
||||
return now.tv_sec * 1000 + now.tv_usec / 1000;
|
||||
}
|
||||
static long now_ms() { return 1000 * clock() / CLOCKS_PER_SEC; }
|
||||
|
||||
static void reset_tap_chain(Tempo *tempo, long t) {
|
||||
tempo->last_reset = t;
|
||||
@@ -93,7 +87,7 @@ static void add_tap_to_chain(Tempo *tempo, long t) {
|
||||
void tempo_init(Tempo *tempo, float value) {
|
||||
long t;
|
||||
|
||||
t = now();
|
||||
t = now_ms();
|
||||
|
||||
reset_tap_chain(tempo, t);
|
||||
|
||||
@@ -105,7 +99,7 @@ void tempo_set(Tempo *tempo, float value) {
|
||||
long t;
|
||||
long progress;
|
||||
|
||||
t = now();
|
||||
t = now_ms();
|
||||
|
||||
progress = (t - tempo->last_reset) % tempo->beat_length;
|
||||
|
||||
@@ -118,7 +112,7 @@ void tempo_set(Tempo *tempo, float value) {
|
||||
void tempo_tap(Tempo *tempo) {
|
||||
long t;
|
||||
|
||||
t = now();
|
||||
t = now_ms();
|
||||
|
||||
if (!is_chain_active(*tempo, t)) {
|
||||
reset_tap_chain(tempo, t);
|
||||
@@ -130,7 +124,7 @@ void tempo_tap(Tempo *tempo) {
|
||||
double tempo_total(const Tempo *tempo) {
|
||||
long t;
|
||||
|
||||
t = now();
|
||||
t = now_ms();
|
||||
|
||||
return (double)(t - tempo->last_reset) / (double)tempo->beat_length;
|
||||
}
|
||||
|
||||
+5
-7
@@ -1,4 +1,4 @@
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
void timer_init(Timer *timer, const unsigned int target) {
|
||||
timer->counter = 0;
|
||||
timer->target = target;
|
||||
|
||||
gettimeofday(&timer->start, NULL);
|
||||
timer->start = clock();
|
||||
}
|
||||
|
||||
bool timer_inc(Timer *timer) {
|
||||
@@ -17,14 +16,13 @@ bool timer_inc(Timer *timer) {
|
||||
}
|
||||
|
||||
double timer_reset(Timer *timer) {
|
||||
struct timeval stop;
|
||||
clock_t stop;
|
||||
double secs;
|
||||
double per_secs;
|
||||
|
||||
gettimeofday(&stop, NULL);
|
||||
stop = clock();
|
||||
|
||||
secs = (double)(stop.tv_usec - timer->start.tv_usec) / 1000000 +
|
||||
(double)(stop.tv_sec - timer->start.tv_sec);
|
||||
secs = (double)(stop - timer->start) / CLOCKS_PER_SEC;
|
||||
per_secs = (double)timer->counter / secs;
|
||||
|
||||
timer->start = stop;
|
||||
|
||||
+1
-1
@@ -279,7 +279,7 @@ typedef struct StateBackgroundWriteArgs {
|
||||
// timer.c
|
||||
|
||||
typedef struct Timer {
|
||||
struct timeval start;
|
||||
clock_t start;
|
||||
unsigned int counter;
|
||||
unsigned int target;
|
||||
} Timer;
|
||||
|
||||
Reference in New Issue
Block a user