Piotr Krysik | df97869 | 2017-09-27 21:58:24 +0200 | [diff] [blame] | 1 | /* -*- 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 | |
| 26 | namespace 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 Krysik | 554aa90 | 2018-11-02 11:52:43 +0100 | [diff] [blame] | 45 | time_spec_t time = time_spec_t::from_ticks(samples_from_last_rx_time, d_samp_rate) + d_last_rx_time; |
Piotr Krysik | df97869 | 2017-09-27 21:58:24 +0200 | [diff] [blame] | 46 | return time; |
| 47 | } |
| 48 | |
| 49 | uint64_t time_sample_ref::time_to_offset(time_spec_t time) |
| 50 | { |
Piotr Krysik | 554aa90 | 2018-11-02 11:52:43 +0100 | [diff] [blame] | 51 | 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 Krysik | df97869 | 2017-09-27 21:58:24 +0200 | [diff] [blame] | 53 | return offset; |
| 54 | } |
| 55 | } // namespace gsm |
| 56 | } // namespace gr |
| 57 | |