Testing external clock detection and auto-switch

Simplified audio spectrum computation and transfer
ACARS RX in debug mode
Disabled ABI warnings
Updated binary
This commit is contained in:
furrtek
2018-06-12 07:55:12 +01:00
parent dc5d6fef70
commit 609235b19f
30 changed files with 318 additions and 182 deletions

View File

@@ -31,6 +31,7 @@
ACARSProcessor::ACARSProcessor() {
decim_0.configure(taps_11k0_decim_0.taps, 33554432);
decim_1.configure(taps_11k0_decim_1.taps, 131072);
packet.clear();
}
void ACARSProcessor::execute(const buffer_c8_t& buffer) {
@@ -54,9 +55,16 @@ void ACARSProcessor::consume_symbol(
const float raw_symbol
) {
const uint_fast8_t sliced_symbol = (raw_symbol >= 0.0f) ? 1 : 0;
const auto decoded_symbol = nrzi_decode(sliced_symbol);
//const auto decoded_symbol = acars_decode(sliced_symbol);
packet_builder.execute(decoded_symbol);
// DEBUG
packet.add(sliced_symbol);
if (packet.size() == 256) {
payload_handler(packet);
packet.clear();
}
//packet_builder.execute(decoded_symbol);
}
void ACARSProcessor::payload_handler(

View File

@@ -28,8 +28,6 @@
#include "rssi_thread.hpp"
#include "dsp_decimate.hpp"
#include "dsp_demodulate.hpp"
//#include "audio_compressor.hpp"
#include "spectrum_collector.hpp"
@@ -53,7 +51,48 @@
#include <cstddef>
#include <bitset>
#include "ais_baseband.hpp"
// AIS:
// IN: 2457600/8/8 = 38400
// Offset: 2457600/4 = 614400 (614400/8/8 = 9600)
// Deviation: 2400
// Symbol: 9600
// Decimate: 2
// 4 taps, 1 symbol, 1/4 cycle
// TPMS:
// IN: 2457600/4/2 = 307200
// Offset: 2457600/4 = 614400 (614400/4/2 = 76800)
// Deviation: 38400
// Symbol: 19200
// Decimate: 8
// 16 taps, 1 symbol, 2 cycles
// ACARS:
// IN: 2457600/8/8 = 38400
// Offset: 2457600/4 = 614400 (614400/8/8 = 9600)
// Deviation: ???
// Symbol: 2400
// Decimate: 8
// 16 taps, 1 symbol, 2 cycles
// Number of taps: size of one symbol in samples (in/symbol)
// Cycles:
// Translate+rectangular filter
// sample=38.4k, deviation=4800, symbol=2400
// Length: 16 taps, 1 symbol, 2 cycles of sinusoid
// This is actually the same as rect_taps_307k2_38k4_1t_19k2_p
constexpr std::array<std::complex<float>, 16> rect_taps_38k4_4k8_1t_2k4_p { {
{ 6.2500000000e-02f, 0.0000000000e+00f }, { 4.4194173824e-02f, 4.4194173824e-02f },
{ 0.0000000000e+00f, 6.2500000000e-02f }, { -4.4194173824e-02f, 4.4194173824e-02f },
{ -6.2500000000e-02f, 0.0000000000e+00f }, { -4.4194173824e-02f, -4.4194173824e-02f },
{ 0.0000000000e+00f, -6.2500000000e-02f }, { 4.4194173824e-02f, -4.4194173824e-02f },
{ 6.2500000000e-02f, 0.0000000000e+00f }, { 4.4194173824e-02f, 4.4194173824e-02f },
{ 0.0000000000e+00f, 6.2500000000e-02f }, { -4.4194173824e-02f, 4.4194173824e-02f },
{ -6.2500000000e-02f, 0.0000000000e+00f }, { -4.4194173824e-02f, -4.4194173824e-02f },
{ 0.0000000000e+00f, -6.2500000000e-02f }, { 4.4194173824e-02f, -4.4194173824e-02f },
} };
class ACARSProcessor : public BasebandProcessor {
public:
@@ -73,23 +112,24 @@ private:
dst.size()
};
dsp::decimate::FIRC8xR16x24FS4Decim8 decim_0 { };
dsp::decimate::FIRC8xR16x24FS4Decim8 decim_0 { }; // Translate already done here !
dsp::decimate::FIRC16xR16x32Decim8 decim_1 { };
dsp::matched_filter::MatchedFilter mf { baseband::ais::square_taps_38k4_1t_p, 2 };
dsp::matched_filter::MatchedFilter mf { rect_taps_38k4_4k8_1t_2k4_p, 8 };
clock_recovery::ClockRecovery<clock_recovery::FixedErrorFilter> clock_recovery {
19200, 2400, { 0.0555f },
4800, 2400, { 0.0555f },
[this](const float symbol) { this->consume_symbol(symbol); }
};
symbol_coding::NRZIDecoder nrzi_decode { };
PacketBuilder<BitPattern, NeverMatch, BitPattern> packet_builder {
{ 0b1001011010010110, 16, 1 }, // SYN, SYN
symbol_coding::ACARSDecoder acars_decode { };
/*PacketBuilder<BitPattern, NeverMatch, FixedLength> packet_builder {
{ 0b011010000110100010000000, 24, 1 }, // SYN, SYN, SOH
{ },
{ 0b11111111, 8, 1 },
{ 128 },
[this](const baseband::Packet& packet) {
this->payload_handler(packet);
}
};
};*/
baseband::Packet packet { };
void consume_symbol(const float symbol);
void payload_handler(const baseband::Packet& packet);

View File

@@ -66,47 +66,57 @@ void WidebandFMAudio::execute(const buffer_c8_t& buffer) {
auto audio_2fs = audio_dec_2.execute(audio_4fs, work_audio_buffer);
// Input: 96kHz int16_t[64]
// audio_spectrum_decimator piles up 256 bytes before doing FFT computation
// This should send an AudioSpectrum every sample rate/buffer size/(256/64)/refresh scaler = 3072000/2048/4/8 = ~47 Hz
// audio_spectrum_decimator piles up 256 samples before doing FFT computation
// This sends an AudioSpectrum every: sample rate/buffer size/refresh period = 3072000/2048/50 = 30 Hz
// When audio_spectrum_timer expires, the audio spectrum computation is triggered
// 0~3: feed continuous audio
// 4~31: ignore, wrap at 31
if (!(refresh_timer & 0xF8)) {
for (size_t i = 0; i < 64; i++) {
complex_audio[i] = { (int16_t)(work_audio_buffer.p[i] / 32), (int16_t)0 };
}
audio_spectrum_decimator.feed(
complex_audio_buffer,
[this](const buffer_c16_t& data) {
this->post_message(data);
}
);
} else {
// Spread the FFT workload in time to avoid making the audio skip
// "8" comes from the log2() of the size of audio_spectrum: log2(256) = 8
if (fft_stage && (fft_stage <= 8)) {
fft_c_preswapped(audio_spectrum, fft_stage - 1, fft_stage);
fft_stage++;
} else if (fft_stage > 8) {
AudioSpectrum spectrum;
const size_t spectrum_end = spectrum.db.size();
for(size_t i=0; i<spectrum_end; i++) {
//const auto corrected_sample = spectrum_window_hamming_3(audio_spectrum, i);
const auto corrected_sample = audio_spectrum[i];
const auto mag2 = magnitude_squared(corrected_sample * (1.0f / 32768.0f));
const float db = mag2_to_dbv_norm(mag2);
constexpr float mag_scale = 5.0f;
const unsigned int v = (db * mag_scale) + 255.0f;
spectrum.db[i] = std::max(0U, std::min(255U, v));
}
fifo.in(spectrum);
fft_stage = 0;
}
audio_spectrum_timer++;
if (audio_spectrum_timer == 50) {
audio_spectrum_timer = 0;
audio_spectrum_state = FEED;
}
if (refresh_timer == 31)
refresh_timer = 0;
else
refresh_timer++;
switch (audio_spectrum_state) {
case FEED:
// Convert audio to "complex" just so the FFT can be done :/
for (size_t i = 0; i < 64; i++) {
complex_audio[i] = { (int16_t)(work_audio_buffer.p[i] / 32), (int16_t)0 };
}
audio_spectrum_decimator.feed(
complex_audio_buffer,
[this](const buffer_c16_t& data) {
this->post_message(data);
}
);
break;
case FFT:
// Spread the FFT workload in time to avoid making the audio skip
// "8" comes from the log2() of the size of audio_spectrum: log2(256) = 8
if (fft_step < 8) {
fft_c_preswapped(audio_spectrum, fft_step, fft_step + 1);
fft_step++;
} else {
const size_t spectrum_end = spectrum.db.size();
for(size_t i=0; i<spectrum_end; i++) {
//const auto corrected_sample = spectrum_window_hamming_3(audio_spectrum, i);
const auto corrected_sample = audio_spectrum[i];
const auto mag2 = magnitude_squared(corrected_sample * (1.0f / 32768.0f));
const float db = mag2_to_dbv_norm(mag2);
constexpr float mag_scale = 5.0f;
const unsigned int v = (db * mag_scale) + 255.0f;
spectrum.db[i] = std::max(0U, std::min(255U, v));
}
AudioSpectrumMessage message { &spectrum };
shared_memory.application_queue.push(message);
audio_spectrum_state = IDLE;
}
break;
default:
break;
}
/* 96kHz int16_t[64]
* -> FIR filter, <15kHz (0.156fs) pass, >19kHz (0.198fs) stop, gain of 1
@@ -121,7 +131,8 @@ void WidebandFMAudio::execute(const buffer_c8_t& buffer) {
void WidebandFMAudio::post_message(const buffer_c16_t& data) {
// This is called when audio_spectrum_decimator is filled up to 256 samples
fft_swap(data, audio_spectrum);
fft_stage = 1;
audio_spectrum_state = FFT;
fft_step = 0;
}
void WidebandFMAudio::on_message(const Message* const message) {
@@ -167,9 +178,6 @@ void WidebandFMAudio::configure(const WFMConfigureMessage& message) {
channel_spectrum.set_decimation_factor(1);
configured = true;
AudioSpectrumConfigMessage config_message { &fifo };
shared_memory.application_queue.push(config_message);
}
void WidebandFMAudio::capture_config(const CaptureConfigMessage& message) {

View File

@@ -53,6 +53,7 @@ private:
dst.data(),
dst.size()
};
// work_audio_buffer and dst_buffer use the same data pointer
const buffer_s16_t work_audio_buffer {
(int16_t*)dst.data(),
sizeof(dst) / sizeof(int16_t)
@@ -78,11 +79,16 @@ private:
// For fs=96kHz FFT streaming
BlockDecimator<complex16_t, 256> audio_spectrum_decimator { 1 };
AudioSpectrum fifo_data[1 << AudioSpectrumConfigMessage::fifo_k] { };
AudioSpectrumFIFO fifo { fifo_data, AudioSpectrumConfigMessage::fifo_k };
std::array<std::complex<float>, 256> audio_spectrum { };
uint32_t refresh_timer { 0 };
uint32_t fft_stage { 0 };
uint32_t audio_spectrum_timer { 0 };
enum AudioSpectrumState {
IDLE = 0,
FEED,
FFT
};
AudioSpectrumState audio_spectrum_state { IDLE };
AudioSpectrum spectrum { };
uint32_t fft_step { 0 };
SpectrumCollector channel_spectrum { };
size_t spectrum_interval_samples = 0;

View File

@@ -39,6 +39,17 @@ private:
uint_fast8_t last { 0 };
};
class ACARSDecoder {
public:
uint_fast8_t operator()(const uint_fast8_t symbol) {
last ^= (~symbol & 1);
return last;
}
private:
uint_fast8_t last { 0 };
};
} /* namespace symbol_coding */
#endif/*__SYMBOL_CODING_H__*/