GNSS-SDR  0.0.13
An Open Source GNSS Software Defined Receiver
unpack_2bit_samples.h
Go to the documentation of this file.
1 /*!
2  * \file unpack_2bit_samples.h
3  *
4  * \brief Unpacks 2 bit samples
5  * samples may be packed in any of the following ways:
6  * 1) Into bytes [ item == byte ]
7  * 1a) Big endian ordering within the byte
8  * 1b) Little endian ordering within the byte
9  * 2) Into shorts [ item == short ]
10  * 2a) Big endian ordering of bytes, big endian within the byte
11  * 2b) Big endian ordering of bytes, little endian within the byte
12  * 2c) Little endian ordering of bytes, big endian within the byte
13  * 2d) Little endian ordering of bytes, little endian within the byte
14  *
15  * Within a byte the two possibilities look like this:
16  * 7 6 5 4 3 2 1 0 : Bit number
17  * x_n,1 x_n,0 x_n+1,1 x_n+1,0 x_n+2,1 x_n+2,0 x_n+3,1 x_n+3,0 : Little endian
18  * x_n+3,1 x_n+3,0 x_n+2,1 x_n+2,0 x_n+1,0 x_n+1,0 x_n,1 x_n, 0 : Big Endian
19  *
20  * For a short (uint16_t) the bytes are either transmitted as follows:
21  *
22  * 1 0 : Byte number
23  * Byte_n Byte_n+1 : Little endian
24  * Byte_n+1 Byte_n : Bit endian
25  *
26  * The two bit values are assumed to have the following mapping:
27  *
28  * x_1 x_0 Value
29  * 0 0 +1
30  * 0 1 +3
31  * 1 0 -3
32  * 1 1 -1
33  *
34  * Letting x denote the two's complement interpretation of x_1 x_0, then:
35  *
36  * Value = 2*x + 1
37  *
38  * We want to output the data in the order:
39  *
40  * Value_0, Value_1, Value_2, ..., Value_n, Value_n+1, Value_n+2, ...
41  *
42  * \author Cillian O'Driscoll cillian.odriscoll (at) gmail . com
43  * -----------------------------------------------------------------------------
44  *
45  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
46  *
47  * GNSS-SDR is a software defined Global Navigation
48  * Satellite Systems receiver
49  *
50  * This file is part of GNSS-SDR.
51  *
52  * SPDX-License-Identifier: GPL-3.0-or-later
53  *
54  * -----------------------------------------------------------------------------
55  */
56 
57 #ifndef GNSS_SDR_UNPACK_2BIT_SAMPLES_H
58 #define GNSS_SDR_UNPACK_2BIT_SAMPLES_H
59 
60 #include <gnuradio/sync_interpolator.h>
61 #include <cstdint>
62 #include <vector>
63 #if GNURADIO_USES_STD_POINTERS
64 #include <memory>
65 #else
66 #include <boost/shared_ptr.hpp>
67 #endif
68 
70 
71 #if GNURADIO_USES_STD_POINTERS
72 using unpack_2bit_samples_sptr = std::shared_ptr<unpack_2bit_samples>;
73 #else
74 using unpack_2bit_samples_sptr = boost::shared_ptr<unpack_2bit_samples>;
75 #endif
76 
77 unpack_2bit_samples_sptr make_unpack_2bit_samples(
78  bool big_endian_bytes,
79  size_t item_size,
80  bool big_endian_items,
81  bool reverse_interleaving = false);
82 
83 /*!
84  * \brief This class takes 2 bit samples that have been packed into bytes or
85  * shorts as input and generates a byte for each sample. It generates eight
86  * times as much data as is input (every two bits become 16 bits)
87  */
88 class unpack_2bit_samples : public gr::sync_interpolator
89 {
90 public:
91  ~unpack_2bit_samples() = default;
92 
93  unpack_2bit_samples(bool big_endian_bytes,
94  size_t item_size,
95  bool big_endian_items,
96  bool reverse_interleaving);
97 
98  int work(int noutput_items,
99  gr_vector_const_void_star &input_items,
100  gr_vector_void_star &output_items);
101 
102 private:
103  friend unpack_2bit_samples_sptr make_unpack_2bit_samples_sptr(
104  bool big_endian_bytes,
105  size_t item_size,
106  bool big_endian_items,
107  bool reverse_interleaving);
108 
109  std::vector<int8_t> work_buffer_;
110  size_t item_size_;
111  bool big_endian_bytes_;
112  bool big_endian_items_;
113  bool swap_endian_items_;
114  bool swap_endian_bytes_;
115  bool reverse_interleaving_;
116 };
117 
118 #endif // GNSS_SDR_UNPACK_2BIT_SAMPLES_H
This class takes 2 bit samples that have been packed into bytes or shorts as input and generates a by...