Skip to content

Commit

Permalink
fix rtl-sdr handling for less common tuners
Browse files Browse the repository at this point in the history
fix: FATAL: rtlsdr: error getting tuner gains when tuner gains isn't 29
  • Loading branch information
wiedehopf committed Jan 26, 2025
1 parent 33a5b08 commit 7b76a6a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions sdr_rtlsdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,23 @@ bool rtlsdrOpen(void) {
fprintf(stderr, "FATAL: rtlsdr: error getting tuner gains\n");
return false;
}
//fprintf(stderr, "numgains: %d\n", RTLSDR.numgains);
// one extra step for tuner agc / max (but only for rtl tuners)
if (RTLSDR.numgains == 29) {
RTLSDR.use_rtl_agc = true;
RTLSDR.numgains++;
}

RTLSDR.gains = cmalloc(RTLSDR.numgains * sizeof (int));
if (rtlsdr_get_tuner_gains(RTLSDR.dev, RTLSDR.gains) != RTLSDR.numgains - 1) {
// allocate numgains + 1 for the AGC being added as a pseudo gain level (hacky)
RTLSDR.gains = cmalloc((RTLSDR.numgains + 1) * sizeof (int));
if (rtlsdr_get_tuner_gains(RTLSDR.dev, RTLSDR.gains) != RTLSDR.numgains) {
fprintf(stderr, "FATAL: rtlsdr: error getting tuner gains\n");
free(RTLSDR.gains);
return false;
}

if (RTLSDR.use_rtl_agc) {
//fprintf(stderr, "numgains: %d\n", RTLSDR.numgains);
// one extra step for tuner agc / max (but only for rtl tuners)
if (RTLSDR.numgains == 29) {
// this is hacky and relies on the fact that we allocate 1 extra element
RTLSDR.use_rtl_agc = true;
// set agc at 590 (MODES_RTL_AGC)
RTLSDR.gains[RTLSDR.numgains - 1] = MODES_RTL_AGC;
RTLSDR.gains[RTLSDR.numgains] = MODES_RTL_AGC;
RTLSDR.numgains++;
}

rtlsdrSetGain("");
Expand Down

0 comments on commit 7b76a6a

Please sign in to comment.