mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-01 20:39:08 +00:00
Add AM spectrum ZOOM x3/x4 with optimized x4 decimation (#3304)
* Add AM spectrum zoom x3 and x4 * Optimize AM spectrum zoom x4 processing * Fix AM spectrum zoom formatting * Fix AM spectrum zoom header formatting
This commit is contained in:
@@ -37,6 +37,28 @@ using namespace tonekey;
|
||||
|
||||
namespace ui {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr uint8_t zoom_filter_offset(const OptionsField::value_t zoom_option) {
|
||||
return zoom_option == (int)AMSpectrumZoomOption::X1 ? 0 : 6;
|
||||
}
|
||||
|
||||
constexpr AMConfigureMessage::Zoom_waterfall zoom_spectrum_factor(
|
||||
const OptionsField::value_t zoom_option) {
|
||||
switch ((AMSpectrumZoomOption)zoom_option) {
|
||||
case AMSpectrumZoomOption::X2:
|
||||
return AMConfigureMessage::Zoom_waterfall::ZOOM_x_2;
|
||||
case AMSpectrumZoomOption::X3:
|
||||
return AMConfigureMessage::Zoom_waterfall::ZOOM_x_3;
|
||||
case AMSpectrumZoomOption::X4:
|
||||
return AMConfigureMessage::Zoom_waterfall::ZOOM_x_4;
|
||||
default:
|
||||
return AMConfigureMessage::Zoom_waterfall::ZOOM_x_1;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
/* AMOptionsView *********************************************************/
|
||||
|
||||
AMOptionsView::AMOptionsView(
|
||||
@@ -52,8 +74,10 @@ AMOptionsView::AMOptionsView(
|
||||
&zoom_config,
|
||||
});
|
||||
|
||||
zoom_config.on_change = [this, view](size_t, OptionsField::value_t n) { // n , has two option values. when GUI =zoom+1 => (0), when GUI=zoom+2 (6)
|
||||
receiver_model.set_am_configuration(view->get_previous_AM_mode_option() + n); // n (0 or 6)
|
||||
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),
|
||||
zoom_spectrum_factor(n));
|
||||
view->set_zoom_factor(AM_MODULATION, n);
|
||||
view->set_previous_zoom_option(n);
|
||||
};
|
||||
@@ -61,11 +85,13 @@ AMOptionsView::AMOptionsView(
|
||||
// restore zoom selection
|
||||
zoom_config.set_by_value(view->get_zoom_factor(AM_MODULATION));
|
||||
|
||||
freqman_set_bandwidth_option(AM_MODULATION, options_config); // freqman.cpp to the options_config, only allowing 5 modes freqman_bandwidths[AM] {"DSB 9k", 0}, {"DSB 6k", 1}, {"USB+3k", 2}, {"LSB-3k", 3}, {"CW", 4},
|
||||
options_config.set_by_value(receiver_model.am_configuration() - view->get_previous_zoom_option()); // restore AM GUI option mode , AM FIR index filters (0..11) values , <baseband::AMConfig, 12> am_configs has 12 fir index elements.
|
||||
freqman_set_bandwidth_option(AM_MODULATION, options_config); // freqman.cpp to the options_config, only allowing 5 modes freqman_bandwidths[AM] {"DSB 9k", 0}, {"DSB 6k", 1}, {"USB+3k", 2}, {"LSB-3k", 3}, {"CW", 4},
|
||||
options_config.set_by_value(receiver_model.am_configuration() - zoom_filter_offset(view->get_previous_zoom_option()));
|
||||
options_config.on_change = [this, view](size_t, OptionsField::value_t n) {
|
||||
receiver_model.set_am_configuration(n + view->get_previous_zoom_option()); // we select proper FIR AM filter (0..11), = 0..4 GUI AM modes + offset +6 (if zoom+2)
|
||||
view->set_previous_AM_mode_option(n); // (0..4) allowing 5 AM modes (DSB9K, DSB6K, USB,LSB, CW)
|
||||
receiver_model.set_am_configuration(
|
||||
n + zoom_filter_offset(view->get_previous_zoom_option()),
|
||||
zoom_spectrum_factor(view->get_previous_zoom_option()));
|
||||
view->set_previous_AM_mode_option(n);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -154,7 +180,9 @@ AMFMAptOptionsView::AMFMAptOptionsView(
|
||||
options_config.set_by_value(receiver_model.amfm_configuration());
|
||||
|
||||
zoom_config.on_change = [this, view](size_t, OptionsField::value_t n) {
|
||||
receiver_model.set_amfm_configuration(5 + n);
|
||||
receiver_model.set_amfm_configuration(
|
||||
5 + zoom_filter_offset(n),
|
||||
zoom_spectrum_factor(n));
|
||||
view->set_zoom_factor(AMFM_MODULATION, n);
|
||||
};
|
||||
|
||||
@@ -645,10 +673,19 @@ void AnalogAudioView::set_frequency_absolute(rf::Frequency frequency) {
|
||||
}
|
||||
|
||||
int32_t AnalogAudioView::sliding_limit() const {
|
||||
const bool zoom_x2 =
|
||||
receiver_model.modulation() == ReceiverModel::Mode::AMAudio &&
|
||||
previous_zoom != 0;
|
||||
return zoom_x2 ? sliding_limit_zoom_x2 : sliding_limit_zoom_x1;
|
||||
if (receiver_model.modulation() != ReceiverModel::Mode::AMAudio)
|
||||
return sliding_limit_zoom_x1;
|
||||
|
||||
switch (previous_zoom) {
|
||||
case (int)AMSpectrumZoomOption::X2:
|
||||
return sliding_limit_zoom_x2;
|
||||
case (int)AMSpectrumZoomOption::X3:
|
||||
return sliding_limit_zoom_x3;
|
||||
case (int)AMSpectrumZoomOption::X4:
|
||||
return sliding_limit_zoom_x4;
|
||||
default:
|
||||
return sliding_limit_zoom_x1;
|
||||
}
|
||||
}
|
||||
|
||||
void AnalogAudioView::reset_sliding_frequency(ReceiverModel::Mode modulation) {
|
||||
|
||||
@@ -69,6 +69,13 @@ class PralineOptionsView : public View {
|
||||
};
|
||||
#endif
|
||||
|
||||
enum class AMSpectrumZoomOption : int32_t {
|
||||
X1 = 0,
|
||||
X2 = 6,
|
||||
X3 = 12,
|
||||
X4 = 18,
|
||||
};
|
||||
|
||||
class AMOptionsView : public View {
|
||||
public:
|
||||
AMOptionsView(AnalogAudioView* view, Rect parent_rect, const Style* style);
|
||||
@@ -89,9 +96,10 @@ class AMOptionsView : public View {
|
||||
OptionsField zoom_config{
|
||||
{UI_POS_X_RIGHT(7), UI_POS_Y(0)},
|
||||
7,
|
||||
{{"ZOOM x1", 0},
|
||||
{"ZOOM x2", 6}} // offset index AM modes array FIR filters.
|
||||
};
|
||||
{{"ZOOM x1", (int)AMSpectrumZoomOption::X1},
|
||||
{"ZOOM x2", (int)AMSpectrumZoomOption::X2},
|
||||
{"ZOOM x3", (int)AMSpectrumZoomOption::X3},
|
||||
{"ZOOM x4", (int)AMSpectrumZoomOption::X4}}};
|
||||
};
|
||||
|
||||
class AMFMAptOptionsView : public View {
|
||||
@@ -114,9 +122,10 @@ class AMFMAptOptionsView : public View {
|
||||
OptionsField zoom_config{
|
||||
{UI_POS_X_RIGHT(7), UI_POS_Y(0)},
|
||||
7,
|
||||
{{"ZOOM x1", 0},
|
||||
{"ZOOM x2", 6}} // offset index array filters.
|
||||
};
|
||||
{{"ZOOM x1", (int)AMSpectrumZoomOption::X1},
|
||||
{"ZOOM x2", (int)AMSpectrumZoomOption::X2},
|
||||
{"ZOOM x3", (int)AMSpectrumZoomOption::X3},
|
||||
{"ZOOM x4", (int)AMSpectrumZoomOption::X4}}};
|
||||
};
|
||||
|
||||
class NBFMOptionsView : public View {
|
||||
@@ -265,12 +274,14 @@ class AnalogAudioView : public View {
|
||||
NavigationView& nav_;
|
||||
RxRadioState radio_state_{};
|
||||
uint8_t iq_phase_calibration_value{15}; // initial default RX IQ phase calibration value , used for both max2837 & max2839
|
||||
uint8_t zoom_factor_am{0}; // initial zoom factor in AM mode
|
||||
uint8_t zoom_factor_amfm{0}; // initial zoom factor in AMFM mode
|
||||
uint8_t previous_AM_mode_option{0}; // GUI 5 AM modes : (0..4 ) (DSB9K, DSB6K, USB,LSB, CW). Used to select proper FIR filter (0..11) AM mode + offset 0 (zoom+1) or +6 (if zoom+2)
|
||||
uint8_t previous_zoom{0}; // GUI ZOOM+1, ZOOM+2 , equivalent to two values offset 0 (zoom+1) or +6 (if zoom+2)
|
||||
uint8_t zoom_factor_am{0};
|
||||
uint8_t zoom_factor_amfm{0};
|
||||
uint8_t previous_AM_mode_option{0};
|
||||
uint8_t previous_zoom{0};
|
||||
static constexpr int32_t sliding_limit_zoom_x1 = 50000;
|
||||
static constexpr int32_t sliding_limit_zoom_x2 = 30000;
|
||||
static constexpr int32_t sliding_limit_zoom_x3 = 15000;
|
||||
static constexpr int32_t sliding_limit_zoom_x4 = 6250;
|
||||
rf::Frequency sliding_center_frequency{0};
|
||||
bool sliding_enabled{false};
|
||||
|
||||
|
||||
@@ -71,6 +71,10 @@ static void send_message(const Message* const message) {
|
||||
}
|
||||
|
||||
void AMConfig::apply() const {
|
||||
apply((AMConfigureMessage::Zoom_waterfall)spectrum_decimation_factor);
|
||||
}
|
||||
|
||||
void AMConfig::apply(const AMConfigureMessage::Zoom_waterfall spectrum_zoom) 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 .
|
||||
@@ -78,7 +82,7 @@ void AMConfig::apply() const {
|
||||
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)
|
||||
spectrum_decimation_factor}; // var parameter , waterfall no zoom : 1 ,for zoom x 2 : 2
|
||||
(size_t)spectrum_zoom};
|
||||
send_message(&message);
|
||||
audio::set_rate(audio::Rate::Hz_12000);
|
||||
}
|
||||
|
||||
@@ -41,9 +41,10 @@ struct AMConfig {
|
||||
const fir_taps_complex<64> channel;
|
||||
const AMConfigureMessage::Modulation modulation;
|
||||
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; // used to handle LCD AM waterfall zoom x1 / zoom x2.
|
||||
const size_t spectrum_decimation_factor;
|
||||
|
||||
void apply() const;
|
||||
void apply(AMConfigureMessage::Zoom_waterfall spectrum_zoom) const;
|
||||
};
|
||||
|
||||
struct NBFMConfig {
|
||||
|
||||
@@ -57,6 +57,12 @@ static constexpr std::array<baseband::AMConfig, 12> am_configs{{
|
||||
{taps_6k0_narrow_decim_1, taps_6k0_decim_2, taps_2k6_usb_wefax_channel, AMConfigureMessage::Modulation::SSB_FM, apt_audio_12k_lpf_1500hz_config, (int)AMConfigureMessage::Zoom_waterfall::ZOOM_x_2}, // SSB USB+FM to demod. Subcarrier FM Audio Tones to get APT Weather Fax with waterfall zoom x 2 (we need taps_6k0_narrow_decim_1 to minimize aliasing)
|
||||
}};
|
||||
|
||||
AMConfigureMessage::Zoom_waterfall spectrum_zoom_for_am_config(const size_t index) {
|
||||
return index < am_configs.size()
|
||||
? (AMConfigureMessage::Zoom_waterfall)am_configs[index].spectrum_decimation_factor
|
||||
: AMConfigureMessage::Zoom_waterfall::ZOOM_x_1;
|
||||
}
|
||||
|
||||
static constexpr std::array<baseband::NBFMConfig, 4> nbfm_configs{{
|
||||
{taps_4k25_decim_0, taps_4k25_decim_1, taps_4k25_channel, 2500},
|
||||
{taps_11k0_decim_0, taps_11k0_decim_1, taps_11k0_channel, 2500},
|
||||
@@ -166,6 +172,17 @@ uint8_t ReceiverModel::am_configuration() const {
|
||||
void ReceiverModel::set_am_configuration(uint8_t n) {
|
||||
if (n < am_configs.size()) {
|
||||
settings_.am_config_index = n;
|
||||
am_spectrum_zoom_ = spectrum_zoom_for_am_config(n);
|
||||
update_modulation();
|
||||
}
|
||||
}
|
||||
|
||||
void ReceiverModel::set_am_configuration(
|
||||
uint8_t n,
|
||||
AMConfigureMessage::Zoom_waterfall spectrum_zoom) {
|
||||
if (n < am_configs.size()) {
|
||||
settings_.am_config_index = n;
|
||||
am_spectrum_zoom_ = spectrum_zoom;
|
||||
update_modulation();
|
||||
}
|
||||
}
|
||||
@@ -177,6 +194,17 @@ uint8_t ReceiverModel::amfm_configuration() const {
|
||||
void ReceiverModel::set_amfm_configuration(uint8_t n) {
|
||||
if (n < am_configs.size()) {
|
||||
settings_.amfm_config_index = n;
|
||||
am_spectrum_zoom_ = spectrum_zoom_for_am_config(n);
|
||||
update_modulation();
|
||||
}
|
||||
}
|
||||
|
||||
void ReceiverModel::set_amfm_configuration(
|
||||
uint8_t n,
|
||||
AMConfigureMessage::Zoom_waterfall spectrum_zoom) {
|
||||
if (n < am_configs.size()) {
|
||||
settings_.amfm_config_index = n;
|
||||
am_spectrum_zoom_ = spectrum_zoom;
|
||||
update_modulation();
|
||||
}
|
||||
}
|
||||
@@ -288,6 +316,7 @@ void ReceiverModel::enable() {
|
||||
|
||||
void ReceiverModel::disable() {
|
||||
enabled_ = false;
|
||||
am_spectrum_zoom_ = spectrum_zoom_for_am_config(settings_.am_config_index);
|
||||
|
||||
// TODO: Responsibility for enabling/disabling the radio is muddy.
|
||||
// Some happens in ReceiverModel, some inside radio namespace.
|
||||
@@ -296,6 +325,7 @@ void ReceiverModel::disable() {
|
||||
|
||||
void ReceiverModel::initialize() {
|
||||
settings_ = settings_t{};
|
||||
am_spectrum_zoom_ = spectrum_zoom_for_am_config(settings_.am_config_index);
|
||||
}
|
||||
|
||||
void ReceiverModel::set_configuration_without_update(
|
||||
@@ -309,6 +339,7 @@ void ReceiverModel::set_configuration_without_update(
|
||||
settings_.mode = new_mode;
|
||||
settings_.frequency_step = new_frequency_step;
|
||||
settings_.am_config_index = new_am_config_index;
|
||||
am_spectrum_zoom_ = spectrum_zoom_for_am_config(new_am_config_index);
|
||||
settings_.nbfm_config_index = new_nbfm_config_index;
|
||||
settings_.wfm_config_index = new_wfm_config_index;
|
||||
settings_.wfmam_config_index = new_wfmam_config_index;
|
||||
@@ -455,11 +486,11 @@ void ReceiverModel::update_modulation() {
|
||||
}
|
||||
|
||||
void ReceiverModel::update_am_configuration() {
|
||||
am_configs[am_configuration()].apply();
|
||||
am_configs[am_configuration()].apply(am_spectrum_zoom_);
|
||||
}
|
||||
|
||||
void ReceiverModel::update_amfm_configuration() {
|
||||
am_configs[amfm_configuration()].apply(); // update with different index for Wefax.
|
||||
am_configs[amfm_configuration()].apply(am_spectrum_zoom_); // update with different index for Wefax.
|
||||
}
|
||||
|
||||
void ReceiverModel::update_nbfm_configuration() {
|
||||
|
||||
@@ -91,9 +91,11 @@ class ReceiverModel {
|
||||
|
||||
uint8_t am_configuration() const;
|
||||
void set_am_configuration(uint8_t n);
|
||||
void set_am_configuration(uint8_t n, AMConfigureMessage::Zoom_waterfall spectrum_zoom);
|
||||
|
||||
uint8_t amfm_configuration() const;
|
||||
void set_amfm_configuration(uint8_t n);
|
||||
void set_amfm_configuration(uint8_t n, AMConfigureMessage::Zoom_waterfall spectrum_zoom);
|
||||
|
||||
uint8_t nbfm_configuration() const;
|
||||
void set_nbfm_configuration(uint8_t n);
|
||||
@@ -140,6 +142,7 @@ class ReceiverModel {
|
||||
settings_t& settings() { return settings_; }
|
||||
|
||||
private:
|
||||
AMConfigureMessage::Zoom_waterfall am_spectrum_zoom_{AMConfigureMessage::Zoom_waterfall::ZOOM_x_1};
|
||||
settings_t settings_{};
|
||||
bool enabled_ = false;
|
||||
rf::Frequency hidden_offset = 0; // when we need to hide the offset from user, we set this. like when WeFax needs -300Hz.
|
||||
|
||||
Reference in New Issue
Block a user