From 5ac3f08d15102040f592695d304baf9894c673ae Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 2 Nov 2026 18:36:32 +0100 Subject: [PATCH] AM output: switch and drive keep attenuator room for the modulation (issue #107) --- sa_core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sa_core.c b/sa_core.c index a38f77c..f43ec0c 100644 --- a/sa_core.c +++ b/sa_core.c @@ -277,7 +277,9 @@ void set_output_path(freq_t f, float level) switch_atten = 31.0; #endif float a = level - level_max(); // convert to all settings maximum power output equals a = zero - if (a < -switch_atten + BELOW_MAX_DRIVE(0)) { // Switch needed + // Switch needed. AM: switch as soon as possible, else just above the threshold the attenuator is near + // its maximum and has no room left for the modulation troughs + if (a < -switch_atten + (setting.modulation == MO_AM ? 0 : BELOW_MAX_DRIVE(0))) { a = a + switch_atten; setting.atten_step = true; } else @@ -308,7 +310,8 @@ void set_output_path(freq_t f, float level) int ar = 31 - ATTENUATION_RESERVE; if (setting.modulation == MO_AM) // reserve attenuator range for AM modulation ar = 6; - while (a + ar < blw && d > LOWEST_LEVEL) { // reduce till it fits attenuator ((ar+ATTENUATION_RESERVE) .. ATTENUATION_RESERVE) + while (a + ar < blw && d > LOWEST_LEVEL // reduce till it fits attenuator ((ar+ATTENUATION_RESERVE) .. ATTENUATION_RESERVE) + && (setting.modulation != MO_AM || BELOW_MAX_DRIVE(d-1) >= a)) { // AM: a drive step larger than ar must not use the reserve for the peaks d--; blw = BELOW_MAX_DRIVE(d); }