From e2d625e8049805b1c61e62559562125a7f3c3304 Mon Sep 17 00:00:00 2001 From: Georgy Dyuldin Date: Mon, 30 Sep 2024 10:20:58 +0300 Subject: [PATCH] Smooth change gain on correction for FT8 TX --- src/audio.c | 20 ++++++++++++++++++++ src/audio.h | 1 + src/dialog_ft8.c | 9 ++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/audio.c b/src/audio.c index 6adc7f0..59f559f 100644 --- a/src/audio.c +++ b/src/audio.c @@ -194,6 +194,26 @@ void audio_gain_db(int16_t *buf, size_t samples, float gain, int16_t *out) { } } +void audio_gain_db_transition(int16_t *buf, size_t samples, float gain1, float gain2, int16_t *out) { + float scale1 = exp10f(gain1 / 10.0f); + float scale2 = exp10f(gain2 / 10.0f); + float scale; + for (uint16_t i = 0; i < samples; i++) { + scale = scale1 + i * (scale2 - scale1) / samples; + int32_t x = buf[i] * scale; + + if (x > 32767) { + x = 32767; + } + + if (x < -32767) { + x = -32767; + } + + out[i] = x; + } +} + void audio_play_en(bool on) { if (on) { x6100_control_hmic_set(0); diff --git a/src/audio.h b/src/audio.h index 6dae198..2a04e13 100644 --- a/src/audio.h +++ b/src/audio.h @@ -20,3 +20,4 @@ void audio_play_wait(); void audio_play_en(bool on); void audio_gain_db(int16_t *buf, size_t samples, float gain, int16_t *out); +void audio_gain_db_transition(int16_t *buf, size_t samples, float gain1, float gain2, int16_t *out); diff --git a/src/dialog_ft8.c b/src/dialog_ft8.c index 5a145af..23130b8 100644 --- a/src/dialog_ft8.c +++ b/src/dialog_ft8.c @@ -1317,6 +1317,7 @@ static void tx_worker() { float target_pwr = LV_MIN(params.pwr, MAX_PWR); float base_gain_scale = -8.2f + log10f(target_pwr) * 5; float gain_scale = base_gain_scale + params.ft8_output_gain_offset.x; + float prev_gain_scale = gain_scale; size_t counter = 0; while (true) { @@ -1330,7 +1331,13 @@ static void tx_worker() { break; } part = LV_MIN(1024 * 2, n_samples); - audio_gain_db(ptr, part, gain_scale, ptr); + if (gain_scale == prev_gain_scale) { + audio_gain_db(ptr, part, gain_scale, ptr); + } else { + // Smooth change gain + audio_gain_db_transition(ptr, part, prev_gain_scale, gain_scale, ptr); + prev_gain_scale = gain_scale; + } audio_play(ptr, part); n_samples -= part;