GNU Radio's DVBS2RX Package
gr_bch.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright (c) 2023 Igor Freire.
4 *
5 * This file is part of gr-dvbs2rx.
6 *
7 * SPDX-License-Identifier: GPL-3.0-or-later
8 */
9#ifndef INCLUDED_GR_BCH_H
10#define INCLUDED_GR_BCH_H
11
12#include "api.h"
13#include "bch.h"
14#include "bose_chaudhuri_hocquenghem_decoder.hh"
15#include "galois_field.hh"
16#include <bitset>
17#include <memory>
18#include <vector>
19
20#define MAX_BCH_PARITY_BITS 192
21
22namespace gr {
23namespace dvbs2 {
24
25typedef CODE::GaloisField<16, 0b10000000000101101, uint16_t> GF_NORMAL;
26typedef CODE::GaloisField<15, 0b1000000000101101, uint16_t> GF_MEDIUM;
27typedef CODE::GaloisField<14, 0b100000000101011, uint16_t> GF_SHORT;
28typedef CODE::BoseChaudhuriHocquenghemDecoder<24, 1, 65343, GF_NORMAL> BCH_NORMAL_12;
29typedef CODE::BoseChaudhuriHocquenghemDecoder<20, 1, 65375, GF_NORMAL> BCH_NORMAL_10;
30typedef CODE::BoseChaudhuriHocquenghemDecoder<16, 1, 65407, GF_NORMAL> BCH_NORMAL_8;
31typedef CODE::BoseChaudhuriHocquenghemDecoder<24, 1, 32587, GF_MEDIUM> BCH_MEDIUM_12;
32typedef CODE::BoseChaudhuriHocquenghemDecoder<24, 1, 16215, GF_SHORT> BCH_SHORT_12;
33
34/**
35 * @brief Wrapper for GNU Radio's in-tree BCH Encoder
36 *
37 * Based on gr-dtv/lib/dvb/dvb_bch_bb_impl.cc from the GR sources.
38 */
40{
41private:
42 int m_K; // Message length in bits.
43 int m_N; // Codeword length in bits.
44 int m_t; // t-error correction capability
45 int m_parity; // Parity bits
46 std::bitset<MAX_BCH_PARITY_BITS> m_crc_table[256];
47 std::bitset<MAX_BCH_PARITY_BITS> m_gen_poly;
48
49 void compute_gen_poly(bool normal_fecframe);
50 void compute_crc_table();
51
52public:
53 GrBchEncoder(int k, int n, int t);
54 void encode(const std::vector<int>& ref_bits, std::vector<int>& enc_bits);
55};
56
57/**
58 * @brief Wrapper for gr-dvbs2rx's original BCH Decoder
59 *
60 */
62{
63private:
64 int m_K; // Message length in bits.
65 int m_N; // Codeword length in bits.
66 int m_t; // Error correction capability.
67 std::unique_ptr<GF_NORMAL> m_gf_normal;
68 std::unique_ptr<GF_SHORT> m_gf_short;
69 std::unique_ptr<BCH_NORMAL_12> m_dvbs2rx_decoder_n12;
70 std::unique_ptr<BCH_NORMAL_10> m_dvbs2rx_decoder_n10;
71 std::unique_ptr<BCH_NORMAL_8> m_dvbs2rx_decoder_n8;
72 std::unique_ptr<BCH_SHORT_12> m_dvbs2rx_decoder_s12;
73 std::array<uint8_t, 8192> m_packed_code;
74 std::array<uint8_t, 24> m_packed_parity;
75
76
77 /**
78 * @brief Pack bits into bytes.
79 *
80 * @param in_bits Vector with the input bits.
81 */
82 void pack_bits(const std::vector<int>& in_bits);
83
84 /**
85 * @brief Unpack bits from bytes.
86 *
87 * @param dec_bits Vector to hold the resulting (unpacked) decoded bits.
88 */
89 void unpack_bits(std::vector<int>& dec_bits);
90
91public:
92 GrBchDecoder(int k, int n, int t);
93 void decode(const std::vector<int>& in_bits, std::vector<int>& dec_bits);
94};
95
96/**
97 * @brief Wrapper for the new BCH Codec implementation
98 *
99 */
101{
102private:
105 std::vector<uint8_t> m_packed_msg;
106 std::vector<uint8_t> m_packed_codeword;
107
108public:
109 NewBchCodec(int N, int t);
110 void encode(const std::vector<int>& ref_bits, std::vector<int>& enc_bits);
111 void decode(const std::vector<int>& in_bits, std::vector<int>& dec_bits);
112};
113
114} // namespace dvbs2
115} // namespace gr
116
117#endif /* INCLUDED_GR_BCH_H */
#define DVBS2_GR_BCH_BENCH_API
Definition bench/fec/src/gr_bch/api.h:4
Wrapper for gr-dvbs2rx's original BCH Decoder.
Definition gr_bch.h:62
GrBchDecoder(int k, int n, int t)
void decode(const std::vector< int > &in_bits, std::vector< int > &dec_bits)
Wrapper for GNU Radio's in-tree BCH Encoder.
Definition gr_bch.h:40
GrBchEncoder(int k, int n, int t)
void encode(const std::vector< int > &ref_bits, std::vector< int > &enc_bits)
Wrapper for the new BCH Codec implementation.
Definition gr_bch.h:101
void decode(const std::vector< int > &in_bits, std::vector< int > &dec_bits)
void encode(const std::vector< int > &ref_bits, std::vector< int > &enc_bits)
NewBchCodec(int N, int t)
BCH coder/decoder.
Definition bch.h:29
Galois Field GF(2^m).
Definition gf.h:66
CODE::GaloisField< 16, 0b10000000000101101, uint16_t > GF_NORMAL
Definition gr_bch.h:25
CODE::BoseChaudhuriHocquenghemDecoder< 24, 1, 32587, GF_MEDIUM > BCH_MEDIUM_12
Definition gr_bch.h:31
CODE::GaloisField< 14, 0b100000000101011, uint16_t > GF_SHORT
Definition gr_bch.h:27
CODE::BoseChaudhuriHocquenghemDecoder< 16, 1, 65407, GF_NORMAL > BCH_NORMAL_8
Definition gr_bch.h:30
CODE::BoseChaudhuriHocquenghemDecoder< 24, 1, 16215, GF_SHORT > BCH_SHORT_12
Definition gr_bch.h:32
CODE::BoseChaudhuriHocquenghemDecoder< 20, 1, 65375, GF_NORMAL > BCH_NORMAL_10
Definition gr_bch.h:29
CODE::BoseChaudhuriHocquenghemDecoder< 24, 1, 65343, GF_NORMAL > BCH_NORMAL_12
Definition gr_bch.h:28
CODE::GaloisField< 15, 0b1000000000101101, uint16_t > GF_MEDIUM
Definition gr_bch.h:26
Fixed-length double-ended queue with contiguous volk-aligned elements.
Definition gr_bch.h:22