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