Files
Oleg Belousov b048b8f4f1 Feature/sliding freq (#3280)
* Add sliding-frequency audio receiver tuning
* Move ADS-B receiver to external app
* Move AIS receiver to external app
* Move APRS receiver to external app
* Move APRS transmitter to external app
* Isolate filtered spectrum collection from WFM
* Fixed the issues #3280
* fpga_bridge.c: init registers per reference fpga_init, add quarter-shift mode setter
* radio.hpp: expose cached FPGA quarter-rate shift
* radio.cpp: program FPGA quarter-rate shift together with tuning offset
* tuning.hpp: pass AFE rate and direction to tuning config, add quarter_shift field
* tuning.cpp: import full PRALINE RX/TX tuning tables with quarter-shift offsets
* clock_manager: stop writing bogus RX digital gain, keep quarter shift across rate changes
* receiver_model: port LPF bandwidth from reference auto_bandwidth, use cached quarter shift
* adsb_rx: enable RF amp by default on first run
* ui_geomap.hpp: add hemisphere fields, degrees become magnitude
* ui_geomap: use hemisphere selector for lat/lon sign, fix minute/second wrap carry
* ui_menu: guard select against empty menu
* waterfall_designer: header updates for profile file handling
* waterfall_designer: exception-free profile parsing, CRLF handling, deferred nav callbacks, backup cleanup
* external.ld: scope app section globs to their own object directories
* CMakeLists: relink when external.ld changes
* tools: add external app symbol placement checker
* tools: add guru meditation address lookup script
* tools: add per-function stack usage report script
Co-authored-by: gullradriel <gullradriel@users.noreply.github.com>
2026-08-08 21:47:54 +02:00

178 lines
6.7 KiB
C++

/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "proc_am_audio.hpp"
#include "audio_output.hpp"
#include "audio_dma.hpp"
#include "event_m4.hpp"
#include <array>
#include "dsp_hilbert.hpp"
// Phase 2: Constructor to start threads AFTER object is fully initialized
NarrowbandAMAudio::NarrowbandAMAudio() {
// Initialize members that threads might access
channel_spectrum.set_decimation_factor(1);
// Start threads AFTER everything initialized
baseband_thread.start();
rssi_thread.start();
}
void NarrowbandAMAudio::execute(const buffer_c8_t& buffer) {
if (!configured) {
return;
}
const auto decim_0_out = decim_0.execute(buffer, dst_buffer);
const auto audio_decim_0_out = audio_decim_0.execute(decim_0_out, dst_buffer);
spectrum_samples += decim_0_out.count;
if (!spectrum_capture_active &&
spectrum_samples >= spectrum_interval_samples) {
spectrum_samples -= spectrum_interval_samples;
channel_spectrum.start_capture(spectrum_zoom_x2 ? 4 : 2);
spectrum_capture_active = true;
}
if (spectrum_capture_active &&
channel_spectrum.feed(
audio_decim_0_out,
channel_filter_low_f,
channel_filter_high_f,
channel_filter_transition)) {
spectrum_capture_active = false;
}
const auto decim_1_out = translating_decim_1.execute(audio_decim_0_out, dst_buffer);
const auto decim_2_out = decim_2.execute(decim_1_out, dst_buffer);
const auto channel_out = channel_filter.execute(decim_2_out, dst_buffer);
// TODO: Feed channel_stats post-decimation data?
feed_channel_stats(channel_out);
auto audio = demodulate(channel_out); // now 3 AM demodulation types : demod_am, demod_ssb, demod_ssb_fm (for Wefax)
audio_compressor.execute_in_place(audio);
audio_output.write(audio);
}
buffer_f32_t NarrowbandAMAudio::demodulate(const buffer_c16_t& channel) {
switch (modulation_ssb) { // enum class Modulation : int32_t {DSB = 0, SSB = 1, SSB_FM = 2}
case (int)(AMConfigureMessage::Modulation::DSB):
return demod_am.execute(channel, audio_buffer);
break;
case (int)(AMConfigureMessage::Modulation::SSB):
return demod_ssb.execute(channel, audio_buffer);
break;
case (int)(AMConfigureMessage::Modulation::SSB_FM): // Added to handle Weather Fax mode.
// chDbgPanic("case SSB_FM demodulation"); // Debug.
return demod_ssb_fm.execute(channel, audio_buffer); // Calling a derivative of demod_ssb (USB) , but with different FIR taps + FM audio tones demod.
break;
// return demod am as a default
default:
return demod_am.execute(channel, audio_buffer);
break;
}
}
void NarrowbandAMAudio::on_message(const Message* const message) {
switch (message->id) {
case Message::ID::UpdateSpectrum:
case Message::ID::SpectrumStreamingConfig:
channel_spectrum.on_message(message);
break;
case Message::ID::AMConfigure:
configure(*reinterpret_cast<const AMConfigureMessage*>(message));
break;
case Message::ID::CaptureConfig:
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
break;
case Message::ID::AudioDDCConfig:
ddc_config(*reinterpret_cast<const AudioDDCConfigMessage*>(message));
break;
default:
break;
}
}
void NarrowbandAMAudio::configure(const AMConfigureMessage& message) {
constexpr size_t decim_0_input_fs = baseband_fs;
constexpr size_t decim_0_output_fs = decim_0_input_fs / decim_0.decimation_factor;
constexpr size_t audio_decim_0_output_fs = decim_0_output_fs / 2;
constexpr size_t decim_1_output_fs =
audio_decim_0_output_fs / translating_decim_1.decimation_factor;
constexpr size_t decim_2_input_fs = decim_1_output_fs;
constexpr size_t decim_2_output_fs = decim_2_input_fs / decim_2_decimation_factor;
constexpr size_t channel_filter_input_fs = decim_2_output_fs;
// const size_t channel_filter_output_fs = channel_filter_input_fs / channel_filter_decimation_factor;
decim_0.configure(message.decim_0_filter.taps, 33554432);
audio_decim_0.configure(taps_audio_wide_halfband_0.taps);
translating_decim_1.configure(
message.decim_1_filter.taps, audio_decim_0_output_fs);
decim_2.configure(message.decim_2_filter.taps, decim_2_decimation_factor);
channel_filter.configure(message.channel_filter.taps, channel_filter_decimation_factor);
channel_filter_low_f = message.channel_filter.low_frequency_normalized * channel_filter_input_fs;
channel_filter_high_f = message.channel_filter.high_frequency_normalized * channel_filter_input_fs;
channel_filter_transition = message.channel_filter.transition_normalized * channel_filter_input_fs;
modulation_ssb = (int)message.modulation; // now sending by message , 3 types of AM demod : enum class Modulation : int32_t {DSB = 0, SSB = 1, SSB_FM = 2}
spectrum_zoom_x2 = message.channel_spectrum_decimation_factor == 2;
channel_spectrum.set_decimation_factor(1);
spectrum_interval_samples =
decim_0_output_fs / spectrum_rate_hz;
audio_output.configure(message.audio_hpf_lpf_config); // hpf in all AM demod modes (AM-6K/9K, USB/LSB,DSB), except Wefax (lpf there).
configured = true;
}
void NarrowbandAMAudio::ddc_config(const AudioDDCConfigMessage& message) {
translating_decim_1.set_frequency(message.frequency);
channel_spectrum.set_channel_filter_offset(message.frequency);
}
void NarrowbandAMAudio::capture_config(const CaptureConfigMessage& message) {
if (message.config) {
audio_output.set_stream(std::make_unique<StreamInput>(message.config));
} else {
audio_output.set_stream(nullptr);
}
}
int main() {
audio::dma::init_audio_out();
EventDispatcher event_dispatcher{std::make_unique<NarrowbandAMAudio>()};
event_dispatcher.run();
return 0;
}