From c399e98203720cd42b11036d47ade56d95173c37 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Mon, 7 Mar 2022 23:38:28 -0500 Subject: Fix incorrect xas_bank_entry_duration() --- src/bank.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bank.c b/src/bank.c index 1759a54..d9b85bb 100644 --- a/src/bank.c +++ b/src/bank.c @@ -166,10 +166,14 @@ void xas_bank_entry_duration(xas_bank *bank, size_t entry_index, struct timeval *tv) { xas_bank_entry *entry = entry_by_index(bank, entry_index); - size_t count = entry->duration; - tv->tv_sec = count / bank->format.sample_rate; - tv->tv_usec = (count % bank->format.sample_rate) * 1000000; + size_t seconds = entry->duration / bank->format.sample_rate, + remainder = entry->duration % bank->format.sample_rate; + + double subseconds = (double)remainder / (double)bank->format.sample_rate; + + tv->tv_sec = (time_t)seconds; + tv->tv_usec = (suseconds_t)(subseconds * 1000000.0); } int xas_bank_player_set_entry(xas_bank_player *player, size_t entry) { -- cgit v1.2.3