diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-11-06 17:55:46 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-11-06 17:55:46 +0100 |
commit | 823043497a9fd59ac86e9596c56df8e692340974 (patch) | |
tree | 0cba1739c400ae4c2d2c22549f99157ca25d7d24 /AlignSample.hpp | |
parent | ff7a3d92d6192f6dd201ef165978b1d3df3815b6 (diff) | |
download | odr-dpd-823043497a9fd59ac86e9596c56df8e692340974.tar.gz odr-dpd-823043497a9fd59ac86e9596c56df8e692340974.tar.bz2 odr-dpd-823043497a9fd59ac86e9596c56df8e692340974.zip |
Move AlignSample to separate file
Diffstat (limited to 'AlignSample.hpp')
-rw-r--r-- | AlignSample.hpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/AlignSample.hpp b/AlignSample.hpp new file mode 100644 index 0000000..31b5de2 --- /dev/null +++ b/AlignSample.hpp @@ -0,0 +1,98 @@ +/* + Copyright (C) 2015 + Matthias P. Braendli, matthias.braendli@mpb.li + + http://opendigitalradio.org + */ +/* + This file is part of ODR-DPD. + + ODR-DPD is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + ODR-DPD is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ODR-DPD. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "utils.hpp" +#include <thread> +#include <vector> +#include <deque> +#include <mutex> +#include <complex> + +typedef std::complex<float> complexf; + +struct CorrelationResult { + CorrelationResult(size_t len) : + correlation(len), + rx_power(0), + tx_power(0), + rx_timestamp(0), + tx_timestamp(0) {} + + std::vector<complexf> correlation; + double rx_power; + double tx_power; + + double rx_timestamp; + double tx_timestamp; +}; + +class AlignSample { + public: + AlignSample() { + m_first_rx_sample_time = 0; + m_first_tx_sample_time = 0; + m_num_rx_samples_dropped = 0; + m_num_tx_samples_dropped = 0; + } + + void push_tx_samples(complexf* samps, size_t len, double first_sample_time); + + void push_rx_samples(complexf* samps, size_t len, double first_sample_time); + + bool ready(size_t min_samples); + + void debug() { + std::lock_guard<std::mutex> lock(m_mutex); + MDEBUG("Aligner\n"); + MDEBUG(" RX: %f %zu\n", m_rx_sample_time(), m_rxsamples.size()); + MDEBUG(" TX: %f %zu\n", m_tx_sample_time(), m_txsamples.size()); + } + + CorrelationResult crosscorrelate(size_t max_offset, size_t len); + + void consume(size_t samples); + + private: + bool align(); + + double m_rx_sample_time() const { + return m_first_rx_sample_time + + (double)m_num_rx_samples_dropped / samplerate; + } + + double m_tx_sample_time() const { + return m_first_tx_sample_time + + (double)m_num_tx_samples_dropped / samplerate; + } + + std::mutex m_mutex; + double m_first_rx_sample_time; + size_t m_num_rx_samples_dropped; + std::deque<complexf> m_rxsamples; + + double m_first_tx_sample_time; + size_t m_num_tx_samples_dropped; + std::deque<complexf> m_txsamples; +}; + + |