Skip to content

Commit

Permalink
autogain: replace startingGain with lowestGain parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed Nov 3, 2024
1 parent 7be4ddf commit 15823dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,<startingGain>,<noiseLowThreshold>,<noiseHighThreshold>,<loudThreshold>
--gain=auto-verbose,<lowestGain>,<noiseLowThreshold>,<noiseHighThreshold>,<loudThreshold>
```
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.
Expand Down
20 changes: 11 additions & 9 deletions readsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1549,28 +1542,37 @@ 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);
} else {
Modes.gain = (int) (atof(arg)*10); // Gain is in tens of DBs
Modes.autoGain = 0;
Modes.gainQuiet = 0;
Modes.minGain = 0;
}
}

Expand Down
1 change: 1 addition & 0 deletions readsb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 15823dd

Please sign in to comment.