From 5b99d357bf1ce8793085df2bbd55694db0b811a8 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Wed, 2 Jul 2025 12:09:38 +0200 Subject: [PATCH] moved crc0 and data array to common struct --- common.hh | 5 +++++ decode.cc | 12 ++++-------- encode.cc | 14 +++++--------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/common.hh b/common.hh index 4a990b1..f45cb1b 100644 --- a/common.hh +++ b/common.hh @@ -6,6 +6,7 @@ Copyright 2025 Ahmet Inan #pragma once +#include "crc.hh" #include "polar_tables.hh" #include "hadamard_encoder.hh" @@ -27,8 +28,10 @@ struct Common static const int block_skew = 3; static const int first_pilot = 4; static const int first_reserved = 9; + CODE::CRC crc0; CODE::HadamardEncoder<6> hadamard_encoder; int8_t mode[32]; + uint8_t data[data_max]; const uint32_t *frozen_bits; int mod_bits; int data_bits; @@ -39,6 +42,8 @@ struct Common int reserved_off; int symbol_count; + Common() : crc0(0x8F6E37A0) {} + void setup(int oper_mode) { switch (oper_mode) { diff --git a/decode.cc b/decode.cc index d8e4333..9c12cb8 100644 --- a/decode.cc +++ b/decode.cc @@ -24,7 +24,6 @@ namespace DSP { using std::abs; using std::min; using std::cos; using std::sin; #include "pcm.hh" #include "fft.hh" #include "mls.hh" -#include "crc.hh" #include "psk.hh" #include "qam.hh" #include "polar_list_decoder.hh" @@ -51,10 +50,8 @@ struct Decoder : Common DSP::BipBuffer input_hist; DSP::TheilSenEstimator tse; SchmidlCox correlator; - CODE::CRC crc0; CODE::HadamardDecoder<6> hadamard_decoder; CODE::PolarListDecoder polar_decoder; - uint8_t output_data[data_max]; mesg_type mesg[bits_max]; code_type code[bits_max], perm[bits_max]; cmplx demod[tones_max], chan[tone_count], tone[tone_count]; @@ -144,8 +141,7 @@ struct Decoder : Common tmp = hilbert(blockdc(tmp.real())); return input_hist(tmp); } - Decoder(DSP::ReadPCM *pcm, const char *const *output_names, int output_count) : - pcm(pcm), correlator(mls0_seq()), crc0(0x8F6E37A0) + Decoder(DSP::ReadPCM *pcm, const char *const *output_names, int output_count) : pcm(pcm), correlator(mls0_seq()) { blockdc.samples(filter_len); DSP::Phasor osc; @@ -279,7 +275,7 @@ struct Decoder : Common continue; } for (int i = 0; i < data_bits; ++i) - CODE::set_le_bit(output_data, i, mesg[i].v[best] < 0); + CODE::set_le_bit(data, i, mesg[i].v[best] < 0); const char *output_name = output_names[output_index++]; if (output_count == 1 && output_name[0] == '-' && output_name[1] == 0) @@ -291,9 +287,9 @@ struct Decoder : Common } CODE::Xorshift32 scrambler; for (int i = 0; i < data_bytes; ++i) - output_data[i] ^= scrambler(); + data[i] ^= scrambler(); for (int i = 0; i < data_bytes; ++i) - output_file.put(output_data[i]); + output_file.put(data[i]); } } }; diff --git a/encode.cc b/encode.cc index 580b21c..49e3cc4 100644 --- a/encode.cc +++ b/encode.cc @@ -17,7 +17,6 @@ Copyright 2021 Ahmet Inan #include "wav.hh" #include "pcm.hh" #include "mls.hh" -#include "crc.hh" #include "psk.hh" #include "qam.hh" #include "polar_encoder.hh" @@ -31,9 +30,7 @@ struct Encoder : public Common DSP::WritePCM *pcm; DSP::FastFourierTransform fwd; DSP::FastFourierTransform bwd; - CODE::CRC crc0; CODE::PolarEncoder polar_encoder; - uint8_t input_data[data_max]; code_type code[bits_max], perm[bits_max], mesg[bits_max]; cmplx fdom[symbol_len]; cmplx tdom[symbol_len]; @@ -229,8 +226,7 @@ struct Encoder : public Common for (int i = guard_len / 4 + guard_len / 2; i < guard_len; ++i) weight[i] = 1; } - Encoder(DSP::WritePCM *pcm, const char *const *input_names, int input_count, int freq_off, int oper_mode) : - pcm(pcm), crc0(0x8F6E37A0) + Encoder(DSP::WritePCM *pcm, const char *const *input_names, int input_count, int freq_off, int oper_mode) : pcm(pcm) { setup(oper_mode); int offset = (freq_off * symbol_len) / rate; @@ -261,16 +257,16 @@ struct Encoder : public Common continue; } for (int i = 0; i < data_bytes; ++i) - input_data[i] = std::max(input_file.get(), 0); + data[i] = std::max(input_file.get(), 0); CODE::Xorshift32 scrambler; for (int i = 0; i < data_bytes; ++i) - input_data[i] ^= scrambler(); + data[i] ^= scrambler(); schmidl_cox(); for (int i = 0; i < data_bits; ++i) - mesg[i] = nrz(CODE::get_le_bit(input_data, i)); + mesg[i] = nrz(CODE::get_le_bit(data, i)); crc0.reset(); for (int i = 0; i < data_bytes; ++i) - crc0(input_data[i]); + crc0(data[i]); for (int i = 0; i < 32; ++i) mesg[i+data_bits] = nrz((crc0()>>i)&1); polar_encoder(code, mesg, frozen_bits, code_order);