From 5b0087554964eedc50175fec8ce75600de938b4f Mon Sep 17 00:00:00 2001 From: wb2osz Date: Sat, 16 Dec 2017 10:10:36 -0500 Subject: [PATCH] Accumulate DC average for audio signal. --- multi_modem.c | 14 ++++++++++++++ multi_modem.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/multi_modem.c b/multi_modem.c index fd53b48..2d50f90 100644 --- a/multi_modem.c +++ b/multi_modem.c @@ -292,6 +292,14 @@ unsigned char is_crc_in_queue(unsigned int chan, unsigned int crc) { * *------------------------------------------------------------------------------*/ +static float dc_average[MAX_CHANS]; + +int multi_modem_get_dc_average (int chan) +{ + // Scale to +- 200 so it will like the deviation measurement. + + return ( (int) ((float)(dc_average[chan]) * (200.0f / 32767.0f) ) ); +} __attribute__((hot)) void multi_modem_process_sample (int chan, int audio_sample) @@ -300,6 +308,12 @@ void multi_modem_process_sample (int chan, int audio_sample) int subchan; static int i = 0; /* for interleaving among multiple demodulators. */ +// Accumulate an average DC bias level. +// Shouldn't happen with a soundcard but could with mistuned SDR. + + dc_average[chan] = dc_average[chan] * 0.999f + (float)audio_sample * 0.001f; + + // TODO: temp debug, remove this. assert (save_audio_config_p->achan[chan].num_subchan > 0 && save_audio_config_p->achan[chan].num_subchan <= MAX_SUBCHANS); diff --git a/multi_modem.h b/multi_modem.h index 77c5b6d..0c096ef 100644 --- a/multi_modem.h +++ b/multi_modem.h @@ -14,6 +14,8 @@ void multi_modem_init (struct audio_s *pmodem); void multi_modem_process_sample (int c, int audio_sample); +int multi_modem_get_dc_average (int chan); + void multi_modem_process_rec_frame (int chan, int subchan, int slice, unsigned char *fbuf, int flen, alevel_t alevel, retry_t retries); #endif