diff options
author | Ron Economos <w6rz@comcast.net> | 2019-04-04 01:36:15 -0700 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2019-04-19 19:09:05 +0200 |
commit | efac27ca6438a36fadcdaad5164f90b1b423e2b5 (patch) | |
tree | c200667fc0c0ff1595f70924a4553678ac6821d4 /gr-dtv | |
parent | 8c80f14fd9e9e74bae46932d8168a1afdd3fd0a2 (diff) |
dtv: Fix scrambler and BCH encoder for MEDIUM size frames.
DVB-S2X VL-SNR MEDIUM size frames are not divisible by 8.
Diffstat (limited to 'gr-dtv')
-rw-r--r-- | gr-dtv/lib/dvb/dvb_bbscrambler_bb_impl.cc | 23 | ||||
-rw-r--r-- | gr-dtv/lib/dvb/dvb_bbscrambler_bb_impl.h | 4 | ||||
-rw-r--r-- | gr-dtv/lib/dvb/dvb_bch_bb_impl.cc | 104 | ||||
-rw-r--r-- | gr-dtv/lib/dvb/dvb_bch_bb_impl.h | 5 |
4 files changed, 104 insertions, 32 deletions
diff --git a/gr-dtv/lib/dvb/dvb_bbscrambler_bb_impl.cc b/gr-dtv/lib/dvb/dvb_bbscrambler_bb_impl.cc index c9401258b7..90d5535599 100644 --- a/gr-dtv/lib/dvb/dvb_bbscrambler_bb_impl.cc +++ b/gr-dtv/lib/dvb/dvb_bbscrambler_bb_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015,2016 Free Software Foundation, Inc. + * Copyright 2015,2016,2019 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -246,6 +246,7 @@ namespace gr { } init_bb_randomiser(); + frame_size = framesize; set_output_multiple(kbch); } @@ -268,8 +269,8 @@ namespace gr { sr |= 0x4000; } } + bb_randomize32 = (uint32_t*)&bb_randomise[0]; bb_randomize64 = (uint64_t*)&bb_randomise[0]; - } int @@ -277,13 +278,23 @@ namespace gr { gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - // noutput_items is multiple of kbch and kbch is always divisible by 8 const uint64_t *in = (const uint64_t *) input_items[0]; uint64_t *out = (uint64_t *) output_items[0]; + const uint32_t *inm = (const uint32_t *) input_items[0]; + uint32_t *outm = (uint32_t *) output_items[0]; - for (int i = 0; i < noutput_items; i += kbch) { - for (int j = 0; j < kbch/8; ++j) { - *out++ = *in++ ^ bb_randomize64[j]; + if (frame_size != FECFRAME_MEDIUM) { + for (int i = 0; i < noutput_items; i += kbch) { + for (int j = 0; j < kbch / 8; ++j) { + *out++ = *in++ ^ bb_randomize64[j]; + } + } + } + else { + for (int i = 0; i < noutput_items; i += kbch) { + for (int j = 0; j < kbch / 4; ++j) { + *outm++ = *inm++ ^ bb_randomize32[j]; + } } } diff --git a/gr-dtv/lib/dvb/dvb_bbscrambler_bb_impl.h b/gr-dtv/lib/dvb/dvb_bbscrambler_bb_impl.h index 062e1b68a2..547cd3544d 100644 --- a/gr-dtv/lib/dvb/dvb_bbscrambler_bb_impl.h +++ b/gr-dtv/lib/dvb/dvb_bbscrambler_bb_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015 Free Software Foundation, Inc. + * Copyright 2015,2019 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +31,9 @@ namespace gr { { private: int kbch; + int frame_size; unsigned char bb_randomise[FRAME_SIZE_NORMAL]; + uint32_t* bb_randomize32; uint64_t* bb_randomize64; void init_bb_randomiser(void); diff --git a/gr-dtv/lib/dvb/dvb_bch_bb_impl.cc b/gr-dtv/lib/dvb/dvb_bch_bb_impl.cc index 6f184c8e05..48c73c3c75 100644 --- a/gr-dtv/lib/dvb/dvb_bch_bb_impl.cc +++ b/gr-dtv/lib/dvb/dvb_bch_bb_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015,2016,2018 Free Software Foundation, Inc. + * Copyright 2015,2016,2018,2019 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -390,6 +390,7 @@ namespace gr { } bch_poly_build_tables(); + frame_size = framesize; set_output_multiple(nbch); } @@ -455,6 +456,26 @@ namespace gr { } void + dvb_bch_bb_impl::calculate_medium_crc_table(void) + { + for (int divident = 0; divident < 16; divident++) { /* iterate over all possible input byte values 0 - 15 */ + std::bitset<MAX_BCH_PARITY_BITS> curByte(divident); + curByte <<= num_parity_bits - 4; + + for (unsigned char bit = 0; bit < 4; bit++) { + if ((curByte[num_parity_bits - 1]) != 0) { + curByte <<= 1; + curByte ^= polynome; + } + else { + curByte <<= 1; + } + } + crc_medium_table[divident] = curByte; + } + } + + void dvb_bch_bb_impl::bch_poly_build_tables(void) { // Normal polynomials @@ -569,6 +590,7 @@ for (unsigned int i = 0; i < num_parity_bits; i ++) {\ break; } calculate_crc_table(); + calculate_medium_crc_table(); } int @@ -585,34 +607,68 @@ for (unsigned int i = 0; i < num_parity_bits; i ++) {\ std::bitset<MAX_BCH_PARITY_BITS> parity_bits; int consumed = 0; - for (int i = 0; i < noutput_items; i += nbch) { - for (int j = 0; j < (int)kbch / 8; j++) { - b = 0; - - // calculate the crc using the lookup table, cf. http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html - for (int e = 0; e < 8; e++) { - temp = *in++; - *out++ = temp; - consumed++; - - b |= temp << (7 - e); + if (frame_size != FECFRAME_MEDIUM) { + for (int i = 0; i < noutput_items; i += nbch) { + for (int j = 0; j < (int)kbch / 8; j++) { + b = 0; + + // calculate the crc using the lookup table, cf. http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html + for (int e = 0; e < 8; e++) { + temp = *in++; + *out++ = temp; + consumed++; + + b |= temp << (7 - e); + } + + msb = 0; + for (int n = 1; n <= 8; n++) { + temp = parity_bits[num_parity_bits - n]; + msb |= temp << (8 - n); + } + /* XOR-in next input byte into MSB of crc and get this MSB, that's our new intermediate divident */ + unsigned char pos = (msb ^ b); + /* Shift out the MSB used for division per lookuptable and XOR with the remainder */ + parity_bits = (parity_bits << 8) ^ crc_table[pos]; } - msb = 0; - for (int n = 1; n <= 8; n++) { - temp = parity_bits[num_parity_bits - n]; - msb |= temp << (8 - n); + // Now add the parity bits to the output + for (unsigned int n = 0; n < num_parity_bits; n++) { + *out++ = (char) parity_bits[num_parity_bits - 1]; + parity_bits <<= 1; } - /* XOR-in next input byte into MSB of crc and get this MSB, that's our new intermediate divident */ - unsigned char pos = (msb ^ b); - /* Shift out the MSB used for division per lookuptable and XOR with the remainder */ - parity_bits = (parity_bits << 8) ^ crc_table[pos]; } + } + else { + for (int i = 0; i < noutput_items; i += nbch) { + for (int j = 0; j < (int)kbch / 4; j++) { + b = 0; + + // calculate the crc using the lookup table, cf. http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html + for (int e = 0; e < 4; e++) { + temp = *in++; + *out++ = temp; + consumed++; + + b |= temp << (3 - e); + } + + msb = 0; + for (int n = 1; n <= 4; n++) { + temp = parity_bits[num_parity_bits - n]; + msb |= temp << (4 - n); + } + /* XOR-in next input byte into MSB of crc and get this MSB, that's our new intermediate divident */ + unsigned char pos = (msb ^ b); + /* Shift out the MSB used for division per lookuptable and XOR with the remainder */ + parity_bits = (parity_bits << 4) ^ crc_medium_table[pos]; + } - // Now add the parity bits to the output - for (unsigned int n = 0; n < num_parity_bits; n++) { - *out++ = (char) parity_bits[num_parity_bits - 1]; - parity_bits <<= 1; + // Now add the parity bits to the output + for (unsigned int n = 0; n < num_parity_bits; n++) { + *out++ = (char) parity_bits[num_parity_bits - 1]; + parity_bits <<= 1; + } } } diff --git a/gr-dtv/lib/dvb/dvb_bch_bb_impl.h b/gr-dtv/lib/dvb/dvb_bch_bb_impl.h index d715161431..1d7282c892 100644 --- a/gr-dtv/lib/dvb/dvb_bch_bb_impl.h +++ b/gr-dtv/lib/dvb/dvb_bch_bb_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2015,2016 Free Software Foundation, Inc. + * Copyright 2015,2016,2019 Free Software Foundation, Inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,12 +36,15 @@ namespace gr { unsigned int kbch; unsigned int nbch; unsigned int bch_code; + unsigned int frame_size; std::bitset<MAX_BCH_PARITY_BITS> crc_table[256]; + std::bitset<MAX_BCH_PARITY_BITS> crc_medium_table[16]; unsigned int num_parity_bits; std::bitset<MAX_BCH_PARITY_BITS> polynome; void calculate_crc_table(); + void calculate_medium_crc_table(); int poly_mult(const int*, int, const int*, int, int*); void bch_poly_build_tables(void); |