From 8d5d7fc0c2d20dcc2a85fee329141f271855638b Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Wed, 21 Jul 2021 17:15:47 +0200 Subject: [PATCH] use the DVB recommended T=10 BCH code --- README.md | 4 ++-- decode.cc | 12 ++++++------ encode.cc | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d897e5e..cba0480 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ Quick start: -Create file ```uncoded.dat``` with ```43008``` bits of random data: +Create file ```uncoded.dat``` with ```43040``` bits of random data: ``` -dd if=/dev/urandom of=uncoded.dat bs=1 count=5376 +dd if=/dev/urandom of=uncoded.dat bs=1 count=5380 ``` Encode file ```uncoded.dat``` to ```encoded.wav``` [WAV](https://en.wikipedia.org/wiki/WAV) audio file with 8000 Hz sample rate, 16 bits and only 1 (real) channel: diff --git a/decode.cc b/decode.cc index c1f5b74..33b9003 100644 --- a/decode.cc +++ b/decode.cc @@ -162,7 +162,7 @@ struct Decoder static const int guard_len = symbol_len / 8; static const int ldpc_bits = 64800; static const int bch_bits = ldpc_bits - 21600; - static const int data_bits = bch_bits - 12 * 16; + static const int data_bits = bch_bits - 10 * 16; static const int mod_min = 2; static const int mod_max = 3; static const int cons_max = ldpc_bits / mod_min; @@ -187,12 +187,12 @@ struct Decoder CODE::CRC crc0; typedef CODE::GaloisField<16, 0b10000000000101101, uint16_t> GF; GF gf; - CODE::BoseChaudhuriHocquenghemDecoder<24, 1, 65343, GF> bchdec1; + CODE::BoseChaudhuriHocquenghemDecoder<20, 1, 65375, GF> bchdec1; CODE::OrderedStatisticsDecoder<255, 71, 4> osddec; CODE::LDPCDecoder ldpcdec; int8_t genmat[255*71]; int8_t code[ldpc_bits], bint[ldpc_bits]; - uint16_t erasures[24]; + uint16_t erasures[20]; cmplx head[symbol_len], tail[symbol_len], cons[cons_max]; cmplx fdom[symbol_len], tdom[buffer_len], resam[buffer_len]; value cfo_rad, sfo_rad; @@ -478,10 +478,10 @@ struct Decoder int ecnt = 0; for (int i = 0; i < bch_bits; ++i) { if (!code[i]) { - if (ecnt < 24) { + if (ecnt < 20) { erasures[ecnt++] = i; } else { - std::cerr << "payload LDPC produced more than 24 erasures." << std::endl; + std::cerr << "payload LDPC produced more than 20 erasures." << std::endl; return; } } @@ -548,7 +548,7 @@ int main(int argc, char **argv) std::cerr << "Couldn't open file \"" << output_name << "\" for writing." << std::endl; return 1; } - const int data_len = code_len - (12 * 16 + 21600) / 8; + const int data_len = code_len - (10 * 16 + 21600) / 8; CODE::Xorshift32 scrambler; for (int i = 0; i < data_len; ++i) output_data[i] ^= scrambler(); diff --git a/encode.cc b/encode.cc index f4efcfb..439befc 100644 --- a/encode.cc +++ b/encode.cc @@ -30,7 +30,7 @@ struct Encoder static const int guard_len = symbol_len / 8; static const int ldpc_bits = 64800; static const int bch_bits = ldpc_bits - 21600; - static const int data_bits = bch_bits - 12 * 16; + static const int data_bits = bch_bits - 10 * 16; static const int mls0_len = 127; static const int mls0_poly = 0b10001001; static const int mls1_len = 255; @@ -42,7 +42,7 @@ struct Encoder DSP::FastFourierTransform<4*symbol_len, cmplx, 1> bwd4; CODE::CRC crc0; CODE::BoseChaudhuriHocquenghemEncoder<255, 71> bchenc0; - CODE::BoseChaudhuriHocquenghemEncoder<65535, 65343> bchenc1; + CODE::BoseChaudhuriHocquenghemEncoder<65535, 65375> bchenc1; CODE::LDPCEncoder ldpcenc; int8_t code[ldpc_bits], bint[ldpc_bits]; cmplx fdom[symbol_len], fdom4[4*symbol_len]; @@ -199,7 +199,7 @@ struct Encoder 0b10000000000101101, 0b10000000101110011, 0b10000111110111101, 0b10101101001010101, 0b10001111100101111, 0b11111011110110101, 0b11010111101100101, 0b10111001101100111, 0b10000111010100001, - 0b10111010110100111, 0b10011101000101101, 0b10001101011100011}), + 0b10111010110100111}), oper_mode(oper_mode) { switch (oper_mode) { @@ -337,7 +337,7 @@ int main(int argc, char **argv) return 1; } const int code_len = 64800 / 8; - const int data_len = code_len - (12 * 16 + 21600) / 8; + const int data_len = code_len - (10 * 16 + 21600) / 8; uint8_t *input_data = new uint8_t[code_len]; for (int i = 0; i < data_len; ++i) input_data[i] = input_file.get();