From b804bdb641f4738cd05e664cae469f408f6fae08 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 7 Dec 2015 22:19:22 +0100 Subject: Reduce CW clicks --- src/cw-example/cw.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/cw-example/cw.c b/src/cw-example/cw.c index 3b9df43..1e42469 100644 --- a/src/cw-example/cw.c +++ b/src/cw-example/cw.c @@ -251,19 +251,28 @@ static void cw_task(void *pvParameters) const float omega = 2.0f * FLOAT_PI * cw_fill_msg_current.freq / (float)cw_samplerate; + float ampl = 0.0f; + for (int i = 0; i < cw_fill_msg_current.on_buffer_end; i++) { for (int t = 0; t < samples_per_dit; t++) { int16_t s = 0; + // Remove clicks from CW if (cw_fill_msg_current.on_buffer[i]) { - nco_phase += omega; - if (nco_phase > FLOAT_PI) { - nco_phase -= 2.0f * FLOAT_PI; - } + const float remaining = 32768.0f - ampl; + ampl += remaining / 16.0f; + } + else { + ampl *= 0.8f; + } - s = 32768.0f * arm_sin_f32(nco_phase); + nco_phase += omega; + if (nco_phase > FLOAT_PI) { + nco_phase -= 2.0f * FLOAT_PI; } + s = ampl * arm_sin_f32(nco_phase); + if (buf_pos == AUDIO_BUF_LEN) { xQueueSendToBack(cw_audio_queue, &cw_audio_buf, portMAX_DELAY); buf_pos = 0; -- cgit v1.2.3