Skip to content

Commit

Permalink
Smooth change gain on correction for FT8 TX
Browse files Browse the repository at this point in the history
  • Loading branch information
gdyuldin committed Sep 30, 2024
1 parent 71f8418 commit e2d625e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
9 changes: 8 additions & 1 deletion src/dialog_ft8.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit e2d625e

Please sign in to comment.