From d2f4807fa2adddc6dbafeb8e6b6d359f818ebc0a Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Sat, 5 Nov 2022 18:27:08 +0100 Subject: [PATCH] Navradio: disable low-pass filter when changing selected freq or leaving GPS slave mode When the selected frequency is changed or when leaving GPS slave mode, disable the low-pass filter applied to signal quality. Otherwise, the following may happen for instance: - the active frequency corresponds to a navaid whose signal is well received; - user makes it so that the Morse code for the navaid ID can be heard; - user then changes the selected frequency to one that doesn't belong to a navaid that is close enough to be usable; - yet, as soon as the frequency is changed, the Morse code for the ID of the newly selected navaid (if any), even if it is way too far for its signal to be received, will be very clearly heard for about one second---and likely truncated. This is because before this commit, after the frequency change, the low-pass filter applied to signal quality made the code behave as if the signal, supposedly coming from the new navaid, were still strong---which of course doesn't correspond to physical reality. This fixes the bug reported at [1]. [1] https://forum.flightgear.org/viewtopic.php?f=25&t=40890#p405708 --- src/Instrumentation/navradio.cxx | 14 +++++++++----- src/Instrumentation/navradio.hxx | 4 ++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Instrumentation/navradio.cxx b/src/Instrumentation/navradio.cxx index 9d3232ad2..b722da6ac 100644 --- a/src/Instrumentation/navradio.cxx +++ b/src/Instrumentation/navradio.cxx @@ -511,9 +511,12 @@ void FGNavRadio::updateReceiver(double dt) signal_quality_norm = 1/(range_exceed_norm*range_exceed_norm); } - signal_quality_norm = fgGetLowPass( last_signal_quality_norm, - signal_quality_norm, dt ); - + if (_apply_lowpass_filter) { + signal_quality_norm = fgGetLowPass( last_signal_quality_norm, + signal_quality_norm, dt ); + } + _apply_lowpass_filter = true; + signal_quality_norm_node->setDoubleValue( signal_quality_norm ); bool inrange = signal_quality_norm > 0.2; inrange_node->setBoolValue( inrange ); @@ -693,11 +696,12 @@ void FGNavRadio::valueChanged (SGPropertyNode* prop) } // slave-to-GPS enabled/disabled, resync NAV station (update all outputs) _navaid = NULL; + _apply_lowpass_filter = false; _time_before_search_sec = 0; } else if ((prop == freq_node) || (prop == alt_freq_node)) { updateFormattedFrequencies(); - // force a frequency update - _time_before_search_sec = 0.0; + _apply_lowpass_filter = false; // signal quality allowed to vary quickly + _time_before_search_sec = 0.0; // force a frequency update } } diff --git a/src/Instrumentation/navradio.hxx b/src/Instrumentation/navradio.hxx index 3e2b39e04..63ee81a25 100644 --- a/src/Instrumentation/navradio.hxx +++ b/src/Instrumentation/navradio.hxx @@ -113,6 +113,10 @@ class FGNavRadio : public AbstractInstrument, // internal (private) values + // When the selected frequency is changed or when leaving GPS slave mode, + // the low-pass filter applied to signal quality must be disabled. Setting + // this member to 'false' has one-shot behavior. + bool _apply_lowpass_filter = false; int play_count; bool _nav_search; double _last_freq;