made number of active carriers a constructor argument

This commit is contained in:
Ahmet Inan 2021-06-16 13:57:48 +02:00
commit 463836c41f
2 changed files with 28 additions and 25 deletions

View file

@ -152,7 +152,7 @@ void base37_decoder(char *str, long long int val, int len)
str[i] = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[val%37];
}
template <typename value, typename cmplx, int rate>
template <typename value, typename cmplx, int rate, int cols_min>
struct Decoder
{
typedef DSP::Const<value> Const;
@ -163,19 +163,17 @@ struct Decoder
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 code_cols = 432;
static const int cons_cnt = ldpc_bits / Mod::BITS;
static const int code_rows = cons_cnt / code_cols;
static const int code_off = -216;
static const int mls0_off = -126;
static const int rows_max = cons_cnt / cols_min;
static const int mls0_len = 127;
static const int mls0_off = - mls0_len + 1;
static const int mls0_poly = 0b10001001;
static const int mls1_len = 255;
static const int mls1_off = -127;
static const int mls1_off = - mls1_len / 2;
static const int mls1_poly = 0b100101011;
static const int mls3_poly = 0b10001000000001011;
static const int mls4_poly = 0b10111010010000001;
static const int buffer_len = (code_rows + 8) * (symbol_len + guard_len);
static const int buffer_len = (rows_max + 8) * (symbol_len + guard_len);
static const int search_pos = buffer_len - 4 * (symbol_len + guard_len);
DSP::ReadPCM<value> *pcm;
DSP::FastFourierTransform<symbol_len, cmplx, -1> fwd;
@ -264,7 +262,7 @@ struct Decoder
for (int k = 0; k < Mod::BITS; ++k)
bint[Mod::BITS*i+k] = code[cons_cnt*k+i];
}
Decoder(uint8_t *out, DSP::ReadPCM<value> *pcm, int skip_count) :
Decoder(uint8_t *out, DSP::ReadPCM<value> *pcm, int skip_count, int code_cols) :
pcm(pcm), resample(rate, (rate * 19) / 40, 2), correlator(mls0_seq()), crc0(0xA8F4)
{
CODE::BoseChaudhuriHocquenghemGenerator<255, 71>::matrix(genmat, true, {
@ -338,6 +336,9 @@ struct Decoder
call_sign[9] = 0;
std::cerr << "call sign: " << call_sign << std::endl;
int code_rows = cons_cnt / code_cols;
int code_off = - code_cols / 2;
int dis = displacement(buf+symbol_pos-(code_rows+1)*(symbol_len+guard_len), buf+symbol_pos+2*(symbol_len+guard_len));
sfo_rad = (dis * Const::TwoPi()) / ((code_rows+3)*(symbol_len+guard_len));
std::cerr << "coarse sfo: " << 1000000 * sfo_rad / Const::TwoPi() << " ppm" << std::endl;
@ -461,21 +462,21 @@ int main(int argc, char **argv)
if (argc > 3)
skip_count = std::atoi(argv[3]);
const int code_len = 64800 / 8;
const int code_len = 64800 / 8, code_cols = 432, cols_min = 360;
uint8_t *output_data = new uint8_t[code_len];
switch (input_file.rate()) {
case 8000:
delete new Decoder<value, cmplx, 8000>(output_data, &input_file, skip_count);
delete new Decoder<value, cmplx, 8000, cols_min>(output_data, &input_file, skip_count, code_cols);
break;
case 16000:
delete new Decoder<value, cmplx, 16000>(output_data, &input_file, skip_count);
delete new Decoder<value, cmplx, 16000, cols_min>(output_data, &input_file, skip_count, code_cols);
break;
case 44100:
delete new Decoder<value, cmplx, 44100>(output_data, &input_file, skip_count);
delete new Decoder<value, cmplx, 44100, cols_min>(output_data, &input_file, skip_count, code_cols);
break;
case 48000:
delete new Decoder<value, cmplx, 48000>(output_data, &input_file, skip_count);
delete new Decoder<value, cmplx, 48000, cols_min>(output_data, &input_file, skip_count, code_cols);
break;
default:
std::cerr << "Unsupported sample rate." << std::endl;

View file

@ -31,9 +31,7 @@ struct Encoder
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 code_cols = 432;
static const int cons_cnt = ldpc_bits / Mod::BITS;
static const int code_rows = cons_cnt / code_cols;
static const int mls0_len = 127;
static const int mls0_poly = 0b10001001;
static const int mls1_len = 255;
@ -55,6 +53,8 @@ struct Encoder
cmplx temp[symbol_len];
cmplx guard[guard_len];
cmplx papr_min, papr_max;
int code_cols;
int code_rows;
int code_off;
int mls0_off;
int mls1_off;
@ -180,7 +180,7 @@ struct Encoder
for (int k = 0; k < Mod::BITS; ++k)
bint[Mod::BITS*i+k] = code[cons_cnt*k+i];
}
Encoder(DSP::WritePCM<value> *pcm, uint8_t *inp, int freq_off, uint64_t call_sign) :
Encoder(DSP::WritePCM<value> *pcm, uint8_t *inp, int freq_off, uint64_t call_sign, int code_cols) :
pcm(pcm), crc0(0xA8F4), bchenc0({
0b100011101, 0b101110111, 0b111110011, 0b101101001,
0b110111101, 0b111100111, 0b100101011, 0b111010111,
@ -191,11 +191,13 @@ struct Encoder
0b10000000000101101, 0b10000000101110011, 0b10000111110111101,
0b10101101001010101, 0b10001111100101111, 0b11111011110110101,
0b11010111101100101, 0b10111001101100111, 0b10000111010100001,
0b10111010110100111, 0b10011101000101101, 0b10001101011100011})
0b10111010110100111, 0b10011101000101101, 0b10001101011100011}),
code_cols(code_cols), code_rows(cons_cnt / code_cols)
{
code_off = (freq_off * symbol_len) / rate - code_cols / 2;
mls0_off = code_off + 90;
mls1_off = code_off + 89;
int offset = (freq_off * symbol_len) / rate;
code_off = offset - code_cols / 2;
mls0_off = offset - mls0_len + 1;
mls1_off = offset - mls1_len / 2;
papr_min = cmplx(1000, 1000), papr_max = cmplx(-1000, -1000);
pilot_block();
schmidl_cox();
@ -283,7 +285,7 @@ int main(int argc, char **argv)
std::cerr << "Couldn't open file \"" << input_name << "\" for reading." << std::endl;
return 1;
}
const int code_len = 64800 / 8;
const int code_len = 64800 / 8, code_cols = 432;
const int data_len = code_len - (12 * 16 + 21600) / 8;
uint8_t *input_data = new uint8_t[code_len];
for (int i = 0; i < data_len; ++i)
@ -293,16 +295,16 @@ int main(int argc, char **argv)
output_file.silence(output_rate);
switch (output_rate) {
case 8000:
delete new Encoder<value, cmplx, 8000>(&output_file, input_data, freq_off, call_sign);
delete new Encoder<value, cmplx, 8000>(&output_file, input_data, freq_off, call_sign, code_cols);
break;
case 16000:
delete new Encoder<value, cmplx, 16000>(&output_file, input_data, freq_off, call_sign);
delete new Encoder<value, cmplx, 16000>(&output_file, input_data, freq_off, call_sign, code_cols);
break;
case 44100:
delete new Encoder<value, cmplx, 44100>(&output_file, input_data, freq_off, call_sign);
delete new Encoder<value, cmplx, 44100>(&output_file, input_data, freq_off, call_sign, code_cols);
break;
case 48000:
delete new Encoder<value, cmplx, 48000>(&output_file, input_data, freq_off, call_sign);
delete new Encoder<value, cmplx, 48000>(&output_file, input_data, freq_off, call_sign, code_cols);
break;
default:
std::cerr << "Unsupported sample rate." << std::endl;