diff options
author | Max Kellermann <max@duempel.org> | 2013-06-24 16:17:46 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-06-24 16:17:46 +0200 |
commit | ef48eca9cac875f65622daf500bd702e20d666f3 (patch) | |
tree | 52fe455c347fd0f0ab14b471e2482c17c8aed5e6 /src/Timer.cxx | |
parent | 906d2fbadf075b7d8e3a5be7134a9bebb09b7285 (diff) | |
parent | e9e55b08127dc45b4c6045e1f42e34115086a521 (diff) | |
download | mpd-ef48eca9cac875f65622daf500bd702e20d666f3.tar.gz mpd-ef48eca9cac875f65622daf500bd702e20d666f3.tar.xz mpd-ef48eca9cac875f65622daf500bd702e20d666f3.zip |
Merge branch 'master' of git://git.musicpd.org/dk/mpd
Diffstat (limited to '')
-rw-r--r-- | src/Timer.cxx (renamed from src/timer.c) | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/src/timer.c b/src/Timer.cxx index 9a3228465..7ddbda3da 100644 --- a/src/timer.c +++ b/src/Timer.cxx @@ -18,7 +18,7 @@ */ #include "config.h" -#include "timer.h" +#include "Timer.hxx" #include "audio_format.h" #include "clock.h" @@ -28,46 +28,37 @@ #include <limits.h> #include <stddef.h> -struct timer *timer_new(const struct audio_format *af) +Timer::Timer(const struct audio_format &af) + : time(0), + started(false), + rate(af.sample_rate * audio_format_frame_size(&af)) { - struct timer *timer = g_new(struct timer, 1); - timer->time = 0; // us - timer->started = 0; // false - timer->rate = af->sample_rate * audio_format_frame_size(af); // samples per second - - return timer; -} - -void timer_free(struct timer *timer) -{ - g_free(timer); } -void timer_start(struct timer *timer) +void Timer::Start() { - timer->time = monotonic_clock_us(); - timer->started = 1; + time = monotonic_clock_us(); + started = true; } -void timer_reset(struct timer *timer) +void Timer::Reset() { - timer->time = 0; - timer->started = 0; + time = 0; + started = false; } -void timer_add(struct timer *timer, int size) +void Timer::Add(int size) { - assert(timer->started); + assert(started); // (size samples) / (rate samples per second) = duration seconds // duration seconds * 1000000 = duration us - timer->time += ((uint64_t)size * 1000000) / timer->rate; + time += ((uint64_t)size * 1000000) / rate; } -unsigned -timer_delay(const struct timer *timer) +unsigned Timer::GetDelay() const { - int64_t delay = (int64_t)(timer->time - monotonic_clock_us()) / 1000; + int64_t delay = (int64_t)(time - monotonic_clock_us()) / 1000; if (delay < 0) return 0; @@ -77,13 +68,13 @@ timer_delay(const struct timer *timer) return delay; } -void timer_sync(struct timer *timer) +void Timer::Synchronize() const { int64_t sleep_duration; - assert(timer->started); + assert(started); - sleep_duration = timer->time - monotonic_clock_us(); + sleep_duration = time - monotonic_clock_us(); if (sleep_duration > 0) g_usleep(sleep_duration); } |