From 19ee0e344c2255b31aea3ac305d74d73720eb001 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sat, 11 Jul 2026 13:48:06 +0200 Subject: [PATCH] claude says this is the way --- src/rds95.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/rds95.c b/src/rds95.c index 921e8f7..f8f84ff 100644 --- a/src/rds95.c +++ b/src/rds95.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "../inih/ini.h" #include "rds.h" @@ -15,7 +16,25 @@ #define DEFAULT_STREAMS 1 #define MAX_STREAMS 4 -#define NUM_MPX_FRAMES 128 +static struct timespec next_deadline; +static int deadline_initialized = 0; + +static void sleep_until_next_group(double bits_per_group, double bit_rate) { + double interval_ns = 1e9 * bits_per_group / bit_rate; + + if (!deadline_initialized) { + clock_gettime(CLOCK_MONOTONIC, &next_deadline); + deadline_initialized = 1; + } + + next_deadline.tv_nsec += (long)interval_ns; + while (next_deadline.tv_nsec >= 1000000000L) { + next_deadline.tv_nsec -= 1000000000L; + next_deadline.tv_sec += 1; + } + + clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next_deadline, NULL); +} static uint8_t stop_rds = 0; @@ -173,7 +192,7 @@ int main(int argc, char **argv) { for (uint8_t s = 0; s < config.num_streams; s++) { ipc_send_bits(&client, &rdsEncoder, s); } - msleep((int)(4096 / 1187.5 * 1000)); + sleep_until_next_group(BITS_PER_GROUP, 1187.5); } ipc_close(&client);