mirror of
https://github.com/aicodix/modem.git
synced 2026-04-27 14:30:34 +00:00
minor cleanup
This commit is contained in:
parent
cc3e9cc10f
commit
79c0aaf998
2 changed files with 33 additions and 31 deletions
31
decode.cc
31
decode.cc
|
|
@ -154,17 +154,18 @@ struct Decoder
|
|||
static const int symbol_len = (1280 * rate) / 8000;
|
||||
static const int filter_len = (((21 * rate) / 8000) & ~3) | 1;
|
||||
static const int guard_len = symbol_len / 8;
|
||||
static const int data_bits = 64800;
|
||||
static const int data_cols = 432;
|
||||
static const int data_rows = data_bits / data_cols / Mod::BITS;
|
||||
static const int data_off = -216;
|
||||
static const int code_bits = 64800;
|
||||
static const int data_bits = code_bits - 32;
|
||||
static const int code_cols = 432;
|
||||
static const int code_rows = code_bits / code_cols / Mod::BITS;
|
||||
static const int code_off = -216;
|
||||
static const int mls0_off = -126;
|
||||
static const int mls0_len = 127;
|
||||
static const int mls0_poly = 0b10001001;
|
||||
static const int mls1_len = 255;
|
||||
static const int mls1_off = -127;
|
||||
static const int mls1_poly = 0b100101011;
|
||||
static const int buffer_len = (data_rows + 8) * (symbol_len + guard_len);
|
||||
static const int buffer_len = (code_rows + 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;
|
||||
|
|
@ -306,8 +307,8 @@ struct Decoder
|
|||
call_sign[9] = 0;
|
||||
std::cerr << "call sign: " << call_sign << std::endl;
|
||||
|
||||
int dis = displacement(buf+symbol_pos-(data_rows+1)*(symbol_len+guard_len), buf+symbol_pos+2*(symbol_len+guard_len));
|
||||
sfo_rad = (dis * Const::TwoPi()) / ((data_rows+3)*(symbol_len+guard_len));
|
||||
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;
|
||||
if (dis) {
|
||||
value diff = sfo_rad * (rate / Const::TwoPi());
|
||||
|
|
@ -325,23 +326,23 @@ struct Decoder
|
|||
for (int i = 0; i < buffer_len; ++i)
|
||||
tdom[i] = resam[i] * osc();
|
||||
|
||||
cmplx *cur = tdom + symbol_pos - (data_rows + 1) * (symbol_len + guard_len);
|
||||
cmplx *cur = tdom + symbol_pos - (code_rows + 1) * (symbol_len + guard_len);
|
||||
fwd(fdom, cur);
|
||||
for (int j = 0; j < data_rows; ++j) {
|
||||
for (int i = 0; i < data_cols; ++i)
|
||||
head[bin(i+data_off)] = fdom[bin(i+data_off)];
|
||||
for (int j = 0; j < code_rows; ++j) {
|
||||
for (int i = 0; i < code_cols; ++i)
|
||||
head[bin(i+code_off)] = fdom[bin(i+code_off)];
|
||||
fwd(fdom, cur += symbol_len+guard_len);
|
||||
for (int i = 0; i < data_cols; ++i) {
|
||||
for (int i = 0; i < code_cols; ++i) {
|
||||
value tmp[Mod::BITS];
|
||||
Mod::hard(tmp, fdom[bin(i+data_off)] / head[bin(i+data_off)]);
|
||||
Mod::hard(tmp, fdom[bin(i+code_off)] / head[bin(i+code_off)]);
|
||||
for (int k = 0; k < Mod::BITS; ++k) {
|
||||
int l = Mod::BITS * (data_cols * j + i) + k;
|
||||
int l = Mod::BITS * (code_cols * j + i) + k;
|
||||
CODE::set_le_bit(out, l, tmp[k] < 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
crc1.reset();
|
||||
for (int i = 0; i < data_bits / 8; ++i)
|
||||
for (int i = 0; i < code_bits / 8; ++i)
|
||||
crc1(out[i]);
|
||||
if (crc1())
|
||||
std::cerr << "payload CRC error." << std::endl;
|
||||
|
|
|
|||
33
encode.cc
33
encode.cc
|
|
@ -26,9 +26,10 @@ struct Encoder
|
|||
typedef PhaseShiftKeying<8, cmplx, value> Mod;
|
||||
static const int symbol_len = (1280 * rate) / 8000;
|
||||
static const int guard_len = symbol_len / 8;
|
||||
static const int data_bits = 64800;
|
||||
static const int data_cols = 432;
|
||||
static const int data_rows = data_bits / data_cols / Mod::BITS;
|
||||
static const int code_bits = 64800;
|
||||
static const int data_bits = code_bits - 32;
|
||||
static const int code_cols = 432;
|
||||
static const int code_rows = code_bits / code_cols / Mod::BITS;
|
||||
static const int mls0_len = 127;
|
||||
static const int mls0_poly = 0b10001001;
|
||||
static const int mls1_len = 255;
|
||||
|
|
@ -43,7 +44,7 @@ struct Encoder
|
|||
cmplx tdom[symbol_len];
|
||||
cmplx guard[guard_len];
|
||||
cmplx papr_min, papr_max;
|
||||
int data_off;
|
||||
int code_off;
|
||||
int mls0_off;
|
||||
int mls1_off;
|
||||
|
||||
|
|
@ -81,14 +82,14 @@ struct Encoder
|
|||
void pilot_block()
|
||||
{
|
||||
CODE::MLS seq2(mls2_poly);
|
||||
value data_fac = sqrt(value(symbol_len) / value(data_cols));
|
||||
value code_fac = sqrt(value(symbol_len) / value(code_cols));
|
||||
for (int i = 0; i < symbol_len; ++i)
|
||||
fdom[i] = 0;
|
||||
for (int i = data_off; i < data_off + data_cols; ++i) {
|
||||
for (int i = code_off; i < code_off + code_cols; ++i) {
|
||||
value tmp[Mod::BITS];
|
||||
for (int k = 0; k < Mod::BITS; ++k)
|
||||
tmp[k] = 1 - 2 * seq2();
|
||||
fdom[bin(i)] = data_fac * Mod::map(tmp);
|
||||
fdom[bin(i)] = code_fac * Mod::map(tmp);
|
||||
}
|
||||
symbol();
|
||||
}
|
||||
|
|
@ -139,27 +140,27 @@ struct Encoder
|
|||
0b101011111, 0b111111001, 0b111000011, 0b100111001,
|
||||
0b110101001, 0b000011111, 0b110000111, 0b110110001})
|
||||
{
|
||||
data_off = (freq_off * symbol_len) / rate - data_cols / 2;
|
||||
mls0_off = data_off + 90;
|
||||
mls1_off = data_off + 89;
|
||||
code_off = (freq_off * symbol_len) / rate - code_cols / 2;
|
||||
mls0_off = code_off + 90;
|
||||
mls1_off = code_off + 89;
|
||||
papr_min = cmplx(1000, 1000), papr_max = cmplx(-1000, -1000);
|
||||
pilot_block();
|
||||
schmidl_cox();
|
||||
meta_data((call_sign << 8) | 2);
|
||||
pilot_block();
|
||||
crc1.reset();
|
||||
for (int i = 0; i < (data_bits-32)/8; ++i)
|
||||
for (int i = 0; i < data_bits/8; ++i)
|
||||
crc1(inp[i]);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
inp[(data_bits-32)/8+i] = (crc1() >> (8*i)) & 255;
|
||||
for (int j = 0; j < data_rows; ++j) {
|
||||
for (int i = 0; i < data_cols; ++i) {
|
||||
inp[data_bits/8+i] = (crc1() >> (8*i)) & 255;
|
||||
for (int j = 0; j < code_rows; ++j) {
|
||||
for (int i = 0; i < code_cols; ++i) {
|
||||
value tmp[Mod::BITS];
|
||||
for (int k = 0; k < Mod::BITS; ++k) {
|
||||
int l = Mod::BITS * (data_cols * j + i) + k;
|
||||
int l = Mod::BITS * (code_cols * j + i) + k;
|
||||
tmp[k] = 1 - 2 * CODE::get_le_bit(inp, l);
|
||||
}
|
||||
fdom[bin(i+data_off)] *= Mod::map(tmp);
|
||||
fdom[bin(i+code_off)] *= Mod::map(tmp);
|
||||
}
|
||||
symbol();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue