aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-02-27 20:00:14 +0100
committerMax Kellermann <max@duempel.org>2013-02-27 20:00:14 +0100
commit8017301de5207b49e6353c26bb5d98eceaf5db01 (patch)
tree07854a499d68b62c7ef700cba9b0e2ff8743c984 /src
parent496f70fc0d717719a6defb645918785381efa22b (diff)
parent46528783ef07d1180d7059f3916d277a2f9a0c31 (diff)
downloadmpd-8017301de5207b49e6353c26bb5d98eceaf5db01.tar.gz
mpd-8017301de5207b49e6353c26bb5d98eceaf5db01.tar.xz
mpd-8017301de5207b49e6353c26bb5d98eceaf5db01.zip
Merge branch 'v0.17.x'
Diffstat (limited to 'src')
-rw-r--r--src/clock.c5
-rw-r--r--src/timer.c8
2 files changed, 9 insertions, 4 deletions
diff --git a/src/clock.c b/src/clock.c
index 4100fa2d8..d987aed48 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -25,6 +25,9 @@
#include <mach/mach_time.h>
#else
#include <time.h>
+#ifndef CLOCK_MONOTONIC
+#include <sys/time.h>
+#endif
#endif
unsigned
@@ -89,7 +92,7 @@ monotonic_clock_us(void)
/* we have no monotonic clock, fall back to gettimeofday() */
struct timeval tv;
gettimeofday(&tv, 0);
- return (uint64_t)tv.tv_sec * 1000 + (uint64_t)(tv.tv_usec) / 1000(;
+ return (uint64_t)tv.tv_sec * 1000 + (uint64_t)tv.tv_usec;
#endif
}
diff --git a/src/timer.c b/src/timer.c
index 2d9550706..9a3228465 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -31,9 +31,9 @@
struct timer *timer_new(const struct audio_format *af)
{
struct timer *timer = g_new(struct timer, 1);
- timer->time = 0;
- timer->started = 0;
- timer->rate = af->sample_rate * audio_format_frame_size(af);
+ timer->time = 0; // us
+ timer->started = 0; // false
+ timer->rate = af->sample_rate * audio_format_frame_size(af); // samples per second
return timer;
}
@@ -59,6 +59,8 @@ void timer_add(struct timer *timer, int size)
{
assert(timer->started);
+ // (size samples) / (rate samples per second) = duration seconds
+ // duration seconds * 1000000 = duration us
timer->time += ((uint64_t)size * 1000000) / timer->rate;
}