mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-15 02:52:58 +00:00
Opt-in channel-power squelch for AM audio RX (#3315)
* AM: add opt-in channel-power squelch for AM audio RX Add an SDR++-style power squelch on the complex channel signal for the Analog Audio RX app in AM modes (DSB/SSB/CW). The squelch measures the mean channel power, converts it to dBFS, and mutes the demodulated audio when the signal is below a user-set threshold. Being carrier-based it keys on the AM carrier (e.g. airband/ATC) rather than on audio-band noise, which the existing FM squelch could not do for AM. A new 'SQ' field (0-99, 0 = off) is added to the AM options view and is persisted per app via app_settings. Default is 0, so existing AM behaviour is unchanged unless the user enables it. Threshold maps 1..99 to -80..-20 dBFS. Touches: message (AMConfigureMessage.squelch_level), baseband_api (AMConfig::apply), receiver_model (am_squelch_level get/set), app_settings (persistence), proc_am_audio (DSP), analog_audio_app (UI). * Refactor audio power calculation to use magnitude squared Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -203,6 +203,7 @@ void copy_to_radio_model(const AppSettings& settings) {
|
||||
settings.wfm_config_index,
|
||||
settings.wfmam_config_index,
|
||||
settings.squelch);
|
||||
receiver_model.set_am_squelch_level(settings.am_squelch);
|
||||
}
|
||||
|
||||
receiver_model.set_frequency_step(settings.step);
|
||||
@@ -227,6 +228,7 @@ void copy_from_radio_model(AppSettings& settings) {
|
||||
settings.vga = receiver_model.vga();
|
||||
settings.rx_amp = receiver_model.rf_amp();
|
||||
settings.squelch = receiver_model.squelch_level();
|
||||
settings.am_squelch = receiver_model.am_squelch_level();
|
||||
|
||||
settings.modulation = static_cast<uint8_t>(receiver_model.modulation());
|
||||
settings.am_config_index = receiver_model.am_configuration();
|
||||
@@ -288,6 +290,7 @@ SettingsManager::SettingsManager(
|
||||
bindings_.emplace_back("wfm_config_index"sv, &settings_.wfm_config_index);
|
||||
bindings_.emplace_back("wfmam_config_index"sv, &settings_.wfmam_config_index);
|
||||
bindings_.emplace_back("squelch"sv, &settings_.squelch);
|
||||
bindings_.emplace_back("am_squelch"sv, &settings_.am_squelch);
|
||||
}
|
||||
|
||||
// Common model settings.
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
// Bring in the string_view literal.
|
||||
using std::literals::operator""sv;
|
||||
|
||||
#define COMMON_APP_SETTINGS_COUNT 19
|
||||
#define COMMON_APP_SETTINGS_COUNT 20
|
||||
|
||||
/* Represents a named setting bound to a variable instance. */
|
||||
/* Using void* instead of std::variant, because variant is a pain to dispatch over. */
|
||||
@@ -150,6 +150,7 @@ struct AppSettings {
|
||||
uint8_t wfm_config_index = 0;
|
||||
uint8_t wfmam_config_index = 0;
|
||||
uint8_t squelch = 80;
|
||||
uint8_t am_squelch = 0; // AM channel-power squelch threshold (0 = off)
|
||||
uint8_t volume;
|
||||
// NOTE: update COMMON_APP_SETTINGS_COUNT when adding to this
|
||||
};
|
||||
|
||||
@@ -72,8 +72,15 @@ AMOptionsView::AMOptionsView(
|
||||
&label_config,
|
||||
&options_config,
|
||||
&zoom_config,
|
||||
&label_squelch,
|
||||
&field_squelch,
|
||||
});
|
||||
|
||||
field_squelch.set_value(receiver_model.am_squelch_level());
|
||||
field_squelch.on_change = [](int32_t v) {
|
||||
receiver_model.set_am_squelch_level(v);
|
||||
};
|
||||
|
||||
zoom_config.on_change = [this, view](size_t, OptionsField::value_t n) {
|
||||
receiver_model.set_am_configuration(
|
||||
view->get_previous_AM_mode_option() + zoom_filter_offset(n),
|
||||
|
||||
@@ -100,6 +100,17 @@ class AMOptionsView : public View {
|
||||
{"ZOOM x2", (int)AMSpectrumZoomOption::X2},
|
||||
{"ZOOM x3", (int)AMSpectrumZoomOption::X3},
|
||||
{"ZOOM x4", (int)AMSpectrumZoomOption::X4}}};
|
||||
|
||||
Text label_squelch{
|
||||
{UI_POS_X(10), UI_POS_Y(0), UI_POS_WIDTH(2), UI_POS_HEIGHT(1)},
|
||||
"SQ"};
|
||||
NumberField field_squelch{
|
||||
{UI_POS_X(13), UI_POS_Y(0)},
|
||||
2,
|
||||
{0, 99},
|
||||
1,
|
||||
' ',
|
||||
};
|
||||
};
|
||||
|
||||
class AMFMAptOptionsView : public View {
|
||||
|
||||
@@ -70,11 +70,11 @@ static void send_message(const Message* const message) {
|
||||
}
|
||||
}
|
||||
|
||||
void AMConfig::apply() const {
|
||||
apply((AMConfigureMessage::Zoom_waterfall)spectrum_decimation_factor);
|
||||
void AMConfig::apply(const uint8_t squelch_level) const {
|
||||
apply((AMConfigureMessage::Zoom_waterfall)spectrum_decimation_factor, squelch_level);
|
||||
}
|
||||
|
||||
void AMConfig::apply(const AMConfigureMessage::Zoom_waterfall spectrum_zoom) const {
|
||||
void AMConfig::apply(const AMConfigureMessage::Zoom_waterfall spectrum_zoom, const uint8_t squelch_level) const {
|
||||
const AMConfigureMessage message{
|
||||
taps_6k0_decim_0, // common FIR filter taps pre-decim_0 to all 6 x AM mod types.(AM-9K, AM-6K, USB, LSB, CW, AMFM-WFAX)
|
||||
decim_1, // var decim_1 FIR taps filter , variable values , to handle two spectrum decim factor 1 and 2 (zoom) and more APT LPF filtered .
|
||||
@@ -82,7 +82,8 @@ void AMConfig::apply(const AMConfigureMessage::Zoom_waterfall spectrum_zoom) con
|
||||
channel, // var channel FIR taps filter , variable values, depending selected AM mode, each one different (DSB-9K, DSB-6K, USB-3K, LSB-3K,CW,AMFM-WFAX)
|
||||
modulation, // var parameter . enum class Modulation : int32_t {DSB = 0, SSB = 1, SSB_FM = 2}
|
||||
audio_12k_iir_filter_config, // var parameter , 300 Hz hpf all except Wefax (1.500Hz lpf)
|
||||
(size_t)spectrum_zoom};
|
||||
(size_t)spectrum_zoom,
|
||||
squelch_level};
|
||||
send_message(&message);
|
||||
audio::set_rate(audio::Rate::Hz_12000);
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ struct AMConfig {
|
||||
const iir_biquad_config_t audio_12k_iir_filter_config; // added to handle two var IIR filter types : 300 hpf(as before) , 1500Hz lpf for Wefax.
|
||||
const size_t spectrum_decimation_factor;
|
||||
|
||||
void apply() const;
|
||||
void apply(AMConfigureMessage::Zoom_waterfall spectrum_zoom) const;
|
||||
void apply(uint8_t squelch_level = 0) const;
|
||||
void apply(AMConfigureMessage::Zoom_waterfall spectrum_zoom, uint8_t squelch_level = 0) const;
|
||||
};
|
||||
|
||||
struct NBFMConfig {
|
||||
|
||||
@@ -251,6 +251,15 @@ void ReceiverModel::set_squelch_level(uint8_t v) {
|
||||
update_modulation();
|
||||
}
|
||||
|
||||
uint8_t ReceiverModel::am_squelch_level() const {
|
||||
return settings_.am_squelch_level;
|
||||
}
|
||||
|
||||
void ReceiverModel::set_am_squelch_level(uint8_t v) {
|
||||
settings_.am_squelch_level = v;
|
||||
update_modulation();
|
||||
}
|
||||
|
||||
void ReceiverModel::set_antenna_bias() {
|
||||
update_antenna_bias();
|
||||
}
|
||||
@@ -486,7 +495,7 @@ void ReceiverModel::update_modulation() {
|
||||
}
|
||||
|
||||
void ReceiverModel::update_am_configuration() {
|
||||
am_configs[am_configuration()].apply(am_spectrum_zoom_);
|
||||
am_configs[am_configuration()].apply(am_spectrum_zoom_, am_squelch_level());
|
||||
}
|
||||
|
||||
void ReceiverModel::update_amfm_configuration() {
|
||||
|
||||
@@ -61,6 +61,7 @@ class ReceiverModel {
|
||||
uint8_t nbfm_config_index = 0;
|
||||
uint8_t wfm_config_index = 0;
|
||||
uint8_t squelch_level = 80;
|
||||
uint8_t am_squelch_level = 0; // AM channel-power squelch threshold (0 = off)
|
||||
};
|
||||
|
||||
/* The frequency to receive (no offset). */
|
||||
@@ -109,6 +110,9 @@ class ReceiverModel {
|
||||
uint8_t squelch_level() const;
|
||||
void set_squelch_level(uint8_t v);
|
||||
|
||||
uint8_t am_squelch_level() const;
|
||||
void set_am_squelch_level(uint8_t v);
|
||||
|
||||
void set_antenna_bias();
|
||||
|
||||
volume_t headphone_volume() const;
|
||||
|
||||
Reference in New Issue
Block a user