Skip to content

Commit 5b00875

Browse files
committed
Accumulate DC average for audio signal.
1 parent 22c810e commit 5b00875

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

multi_modem.c

+14
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@ unsigned char is_crc_in_queue(unsigned int chan, unsigned int crc) {
292292
*
293293
*------------------------------------------------------------------------------*/
294294

295+
static float dc_average[MAX_CHANS];
296+
297+
int multi_modem_get_dc_average (int chan)
298+
{
299+
// Scale to +- 200 so it will like the deviation measurement.
300+
301+
return ( (int) ((float)(dc_average[chan]) * (200.0f / 32767.0f) ) );
302+
}
295303

296304
__attribute__((hot))
297305
void multi_modem_process_sample (int chan, int audio_sample)
@@ -300,6 +308,12 @@ void multi_modem_process_sample (int chan, int audio_sample)
300308
int subchan;
301309
static int i = 0; /* for interleaving among multiple demodulators. */
302310

311+
// Accumulate an average DC bias level.
312+
// Shouldn't happen with a soundcard but could with mistuned SDR.
313+
314+
dc_average[chan] = dc_average[chan] * 0.999f + (float)audio_sample * 0.001f;
315+
316+
303317
// TODO: temp debug, remove this.
304318

305319
assert (save_audio_config_p->achan[chan].num_subchan > 0 && save_audio_config_p->achan[chan].num_subchan <= MAX_SUBCHANS);

multi_modem.h

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ void multi_modem_init (struct audio_s *pmodem);
1414

1515
void multi_modem_process_sample (int c, int audio_sample);
1616

17+
int multi_modem_get_dc_average (int chan);
18+
1719
void multi_modem_process_rec_frame (int chan, int subchan, int slice, unsigned char *fbuf, int flen, alevel_t alevel, retry_t retries);
1820

1921
#endif

0 commit comments

Comments
 (0)