mirror of
https://github.com/aicodix/modem.git
synced 2026-04-27 22:35:41 +00:00
moved crc0 and data array to common struct
This commit is contained in:
parent
8cab519b16
commit
5b99d357bf
3 changed files with 14 additions and 17 deletions
|
|
@ -6,6 +6,7 @@ Copyright 2025 Ahmet Inan <inan@aicodix.de>
|
|||
|
||||
#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<uint32_t> 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) {
|
||||
|
|
|
|||
12
decode.cc
12
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<cmplx, buffer_len> input_hist;
|
||||
DSP::TheilSenEstimator<value, tone_count> tse;
|
||||
SchmidlCox<value, cmplx, search_pos, symbol_len, guard_len> correlator;
|
||||
CODE::CRC<uint32_t> crc0;
|
||||
CODE::HadamardDecoder<6> hadamard_decoder;
|
||||
CODE::PolarListDecoder<mesg_type, code_max> 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<value> *pcm, const char *const *output_names, int output_count) :
|
||||
pcm(pcm), correlator(mls0_seq()), crc0(0x8F6E37A0)
|
||||
Decoder(DSP::ReadPCM<value> *pcm, const char *const *output_names, int output_count) : pcm(pcm), correlator(mls0_seq())
|
||||
{
|
||||
blockdc.samples(filter_len);
|
||||
DSP::Phasor<cmplx> 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]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
14
encode.cc
14
encode.cc
|
|
@ -17,7 +17,6 @@ Copyright 2021 Ahmet Inan <inan@aicodix.de>
|
|||
#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<value> *pcm;
|
||||
DSP::FastFourierTransform<symbol_len, cmplx, -1> fwd;
|
||||
DSP::FastFourierTransform<symbol_len, cmplx, 1> bwd;
|
||||
CODE::CRC<uint32_t> crc0;
|
||||
CODE::PolarEncoder<code_type> 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<value> *pcm, const char *const *input_names, int input_count, int freq_off, int oper_mode) :
|
||||
pcm(pcm), crc0(0x8F6E37A0)
|
||||
Encoder(DSP::WritePCM<value> *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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue