From 397905cb5079205e2a4bb64cca35517e60c01a58 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 13 Apr 2025 20:11:34 +0200 Subject: Compensate for tist_at_fct0 in tist_offset --- src/DabMultiplexer.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/DabMultiplexer.cpp') diff --git a/src/DabMultiplexer.cpp b/src/DabMultiplexer.cpp index b9575fc..58e0f9b 100644 --- a/src/DabMultiplexer.cpp +++ b/src/DabMultiplexer.cpp @@ -49,6 +49,8 @@ static vector split_pipe_separated_string(const std::string& s) uint64_t MuxTime::init(uint32_t tist_at_fct0_us) { + m_tist_at_fct0_us = tist_at_fct0_us; + /* At startup, derive edi_time, TIST and CIF count such that there is * a consistency across mux restarts. Ensure edi_time and TIST represent * current time. @@ -112,14 +114,19 @@ void MuxTime::increment_timestamp() std::pair MuxTime::get_time() { + // The user-visible configuration tist_offset is the effective + // offset, but since we implicityle add the tist_at_fct0 to it, + // we must compensate. + double corrected_tist_offset = tist_offset - (m_tist_at_fct0_us / 1e6); + // negative tist_offset not supported, because the calculation is annoying - if (tist_offset < 0) return {m_timestamp, m_edi_time}; + if (corrected_tist_offset < 0) return {m_timestamp, m_edi_time}; - double fractional_part = tist_offset - std::floor(tist_offset); + double fractional_part = corrected_tist_offset - std::floor(corrected_tist_offset); const size_t steps = std::lround(std::floor(fractional_part / 24e-3)); uint32_t timestamp = m_timestamp + (24 << 14) * steps; - std::time_t edi_time = m_edi_time + std::lround(std::floor(tist_offset)); + std::time_t edi_time = m_edi_time + std::lround(std::floor(corrected_tist_offset)); if (timestamp > 0xf9FFff) { edi_time += 1; -- cgit v1.2.3