blob: f68abd0bbb75925e6d6f3e23cb9ddf5b64d80f89 [file] [log] [blame]
Piotr Krysikdf978692017-09-27 21:58:24 +02001/* -*- c++ -*- */
2/*
3 * @file
4 * @author (C) 2017 by Piotr Krysik <ptrkrysik@gmail.com>
5 * @section LICENSE
6 *
7 * Gr-gsm is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
10 * any later version.
11 *
12 * Gr-gsm is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with gr-gsm; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#include <math.h>
24#include "time_sample_ref.h"
25
26namespace gr {
27 namespace gsm {
28 time_sample_ref::time_sample_ref(double samp_rate): d_samp_rate(samp_rate)
29 {
30 }
31
32 time_sample_ref::~time_sample_ref()
33 {
34 }
35
36 void time_sample_ref::update(time_spec_t last_rx_time, uint64_t current_start_offset)
37 {
38 d_last_rx_time = last_rx_time;
39 d_current_start_offset = current_start_offset;
40 }
41
42 time_spec_t time_sample_ref::offset_to_time(uint64_t offset)
43 {
44 uint64_t samples_from_last_rx_time = offset - d_current_start_offset;
Piotr Krysik554aa902018-11-02 11:52:43 +010045 time_spec_t time = time_spec_t::from_ticks(samples_from_last_rx_time, d_samp_rate) + d_last_rx_time;
Piotr Krysikdf978692017-09-27 21:58:24 +020046 return time;
47 }
48
49 uint64_t time_sample_ref::time_to_offset(time_spec_t time)
50 {
Piotr Krysik554aa902018-11-02 11:52:43 +010051 uint64_t samples_since_last_rx_time_tag = (time-d_last_rx_time).to_ticks(d_samp_rate);
52 uint64_t offset = samples_since_last_rx_time_tag + d_current_start_offset;
Piotr Krysikdf978692017-09-27 21:58:24 +020053 return offset;
54 }
55 } // namespace gsm
56} // namespace gr
57