From 15823dd47fbd8b4346334317b77ff4dc02912078 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Sun, 3 Nov 2024 19:34:26 +0100 Subject: [PATCH] autogain: replace startingGain with lowestGain parameter --- README.md | 4 ++-- readsb.c | 20 +++++++++++--------- readsb.h | 1 + 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3bce11ef..e6fc8468 100644 --- a/README.md +++ b/README.md @@ -98,11 +98,11 @@ On the command line it's activated using `--gain=auto` an is silent by default. `--gain=auto-verbose` can be used to enable log messages for gain changes. To tweak the internals, more parameters can be passed: ``` ---gain=auto-verbose,,,, +--gain=auto-verbose,,,, ``` The defaults are: ``` ---gain=auto-verbose,43.9,25,31,243 +--gain=auto-verbose,0,25,31,243 ``` The thresholds are numbers 0 to 256, tweaking them requires some understanding of how it works. One option would be to change the noise thresholds up or down and then observe the log. diff --git a/readsb.c b/readsb.c index fba354ae..6cbfbb5a 100644 --- a/readsb.c +++ b/readsb.c @@ -116,13 +116,6 @@ static void configSetDefaults(void) { // Now initialise things that should not be 0/NULL to their defaults Modes.gain = MODES_MAX_GAIN; - Modes.autoGain = 1; - Modes.gainQuiet = 1; - - // 8 bit autogain defaults, will be squared and compared against magnitude data - Modes.loudThreshold = 243; - Modes.noiseLowThreshold = 25; - Modes.noiseHighThreshold = 31; Modes.freq = MODES_DEFAULT_FREQ; Modes.check_crc = 1; @@ -1549,21 +1542,29 @@ static void parseGainOpt(char *arg) { Modes.gainQuiet = 1; } Modes.autoGain = 1; + Modes.gain = 300; + char *argdup = strdup(arg); tokenize(&argdup, ",", token, maxTokens); if (token[1]) { - Modes.gain = (int) (atof(token[1])*10); // Gain is in tens of DBs + Modes.minGain = (int) (atof(token[1])*10); // Gain is in tens of DBs } else { - Modes.gain = 300; + Modes.minGain = 0; } if (token[2]) { Modes.noiseLowThreshold = atoi(token[2]); + } else { + Modes.noiseLowThreshold = 25; } if (token[3]) { Modes.noiseHighThreshold = atoi(token[3]); + } else { + Modes.noiseHighThreshold = 31; } if (token[4]) { Modes.loudThreshold = atoi(token[4]); + } else { + Modes.loudThreshold = 243; } fprintf(stderr, "startingGain: %4.1f noiseLowThreshold: %3d noiseHighThreshold: %3d loudThreshold: %3d\n", Modes.gain / 10.0, Modes.noiseLowThreshold, Modes.noiseHighThreshold, Modes.loudThreshold); @@ -1571,6 +1572,7 @@ static void parseGainOpt(char *arg) { Modes.gain = (int) (atof(arg)*10); // Gain is in tens of DBs Modes.autoGain = 0; Modes.gainQuiet = 0; + Modes.minGain = 0; } } diff --git a/readsb.h b/readsb.h index 8bbf2014..b1e9557c 100644 --- a/readsb.h +++ b/readsb.h @@ -543,6 +543,7 @@ struct _Modes uint32_t loudThreshold; uint32_t noiseLowThreshold; uint32_t noiseHighThreshold; + int minGain; int gain; int dc_filter; // should we apply a DC filter? int enable_agc;