23 const double d_samp_rate;
24 size_t d_current_index;
27 std::vector<double> d_times;
28 std::vector<double> d_delays_samples;
29 std::vector<gr::filter::kernel::fir_filter_ccf> d_filters;
30 const double d_fir_delay;
31 const int d_taps_per_filter;
32 std::vector<gr::tag_t> d_future_tags;
35 const pmt::pmt_t d_rx_time_key;
38 const pmt::pmt_t d_pck_n_key;
39 const pmt::pmt_t d_full_key;
40 const pmt::pmt_t d_frac_key;
42 double d_current_time;
43 double d_current_delay;
47 void adjust_current_index()
49 while ((d_current_index > 0) && (d_times[d_current_index] > d_t0)) {
54 void read_delay_file(
const std::string& filename);
56 void update_time_from_tags(
int noutput_items)
58 std::vector<gr::tag_t> tags;
59 get_tags_in_window(tags, 0, 0, noutput_items);
60 for (
const auto& tag : tags) {
63 if (pmt::eqv(tag.key, d_rx_time_key)) {
64 if (pmt::is_tuple(tag.value)) {
65 t0 =
static_cast<double>(
66 pmt::to_uint64(pmt::tuple_ref(tag.value, 0))) +
67 pmt::to_double(pmt::tuple_ref(tag.value, 1));
70 }
else if (pmt::eqv(tag.key, d_pck_n_key)) {
71 if (pmt::is_dict(tag.value)) {
73 pmt::dict_ref(tag.value, d_full_key, pmt::PMT_NIL);
75 pmt::dict_ref(tag.value, d_frac_key, pmt::PMT_NIL);
76 if (pmt::is_integer(full_pmt) && pmt::is_uint64(frac_pmt)) {
77 const auto full = pmt::to_long(full_pmt);
78 const auto frac = pmt::to_uint64(frac_pmt);
81 static_cast<double>(full) + 1e-12 *
static_cast<double>(frac);
88 d_sample_t0 = tag.offset;
90 d_logger->info(
"set time {} at sample {}", d_t0, d_sample_t0);
91 adjust_current_index();
97 double compute_time(uint64_t sample_absolute_idx)
const
99 return d_t0 +
static_cast<double>(
static_cast<int64_t
>(sample_absolute_idx) -
100 static_cast<int64_t
>(d_sample_t0)) /
104 double compute_delay(
double time)
108 while (d_current_index + 1 < d_times.size() &&
109 d_times[d_current_index + 1] <=
time) {
112 if ((
time < d_times[d_current_index]) ||
113 (d_current_index + 1 == d_times.size())) {
116 return d_delays_samples[d_current_index];
119 double alpha = (
time - d_times[d_current_index]) /
120 (d_times[d_current_index + 1] - d_times[d_current_index]);
121 return (1.0 - alpha) * d_delays_samples[d_current_index] +
122 alpha * d_delays_samples[d_current_index + 1];
126 double compute_tag_delay(
double time)
const
128 size_t current_index = d_current_index;
130 while (current_index >= 1 && d_times[current_index] >
time) {
135 while (current_index + 1 < d_times.size() && d_times[current_index + 1] <=
time) {
138 if ((
time < d_times[current_index]) || (current_index + 1 == d_times.size())) {
141 return d_delays_samples[current_index];
144 double alpha = (
time - d_times[current_index]) /
145 (d_times[current_index + 1] - d_times[current_index]);
146 return (1.0 - alpha) * d_delays_samples[current_index] +
147 alpha * d_delays_samples[current_index + 1];
154 const std::vector<float>& taps,
162 gr::thread::scoped_lock guard(d_setlock);
163 return d_current_time;
168 gr::thread::scoped_lock guard(d_setlock);
169 return d_current_delay / d_samp_rate;
173 gr_vector_const_void_star& input_items,
174 gr_vector_void_star& output_items)
override;