aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Krysik <ptrkrysik@gmail.com>2018-11-02 11:52:43 +0100
committerPiotr Krysik <ptrkrysik@gmail.com>2018-11-02 11:52:43 +0100
commit554aa905e47c4626dcbd0f02283905a4b59576d6 (patch)
tree0a1767433349dfd1145a034d081f7f3d3fb5b335
parent89dc99016efb165bd2a494b6cfa958330158e80a (diff)
receiver/time_sample_ref: improve accuracy of offset<->time conversions
-rw-r--r--lib/receiver/time_sample_ref.cc9
1 files changed, 3 insertions, 6 deletions
diff --git a/lib/receiver/time_sample_ref.cc b/lib/receiver/time_sample_ref.cc
index 0cf85ed..f68abd0 100644
--- a/lib/receiver/time_sample_ref.cc
+++ b/lib/receiver/time_sample_ref.cc
@@ -42,17 +42,14 @@ namespace gr {
time_spec_t time_sample_ref::offset_to_time(uint64_t offset)
{
uint64_t samples_from_last_rx_time = offset - d_current_start_offset;
- time_spec_t time = time_spec_t(static_cast<double>(samples_from_last_rx_time)/d_samp_rate) + d_last_rx_time;
-
+ time_spec_t time = time_spec_t::from_ticks(samples_from_last_rx_time, d_samp_rate) + d_last_rx_time;
return time;
}
uint64_t time_sample_ref::time_to_offset(time_spec_t time)
{
- double samples_since_last_rx_time_tag = (time-d_last_rx_time).get_real_secs()*d_samp_rate;
-// double fractional_part = round(samples_since_last_rx_time_tag) - samples_since_last_rx_time_tag;
- uint64_t offset = static_cast<uint64_t>(round(samples_since_last_rx_time_tag)) + d_current_start_offset;
-
+ uint64_t samples_since_last_rx_time_tag = (time-d_last_rx_time).to_ticks(d_samp_rate);
+ uint64_t offset = samples_since_last_rx_time_tag + d_current_start_offset;
return offset;
}
} // namespace gsm