gqrx icon indicating copy to clipboard operation
gqrx copied to clipboard

Gain level setting not applied by default on SDRplay RSPdx

Open AsciiWolf opened this issue 2 years ago • 5 comments

Gqrx 2.14.4 on Fedora 34 with SDRplay RSPdx (using SoapySDR 0.7.2 with SDRplay RSP API 3.07.1). Gain (IFGR and RFGR) level seems to be set to a minimal gain when Gqrx is started. The sliders are displayed with correct values in Gqrx, but I have to manually check and uncheck the "Hardware AGC" checkbox to make the values be actually applied.

AsciiWolf avatar Sep 21 '21 10:09 AsciiWolf

I think the most likely explanation is a bug in gr-osmosdr. Unfortunately I don't have SDRplay hardware to test with, so there's not much I can do for now.

argilo avatar Oct 04 '21 15:10 argilo

I encounter the same with an SDRplay RSP2pro using gr-osmosdr from willcode. I analyzed the problem with gdb and found the following cause.

In gr-osmosdr/lib/source_impl.cc, function bool source_impl::set_gain_mode( bool automatic, size_t chan ) does this:

        if ( _gain_mode[ chan ] != automatic ) {
          _gain_mode[ chan ] = automatic;
          ...
        }

This is apparently the only place where _gain_mode is written. It is initially an empty map, and on the first call, the condition check accesses a map element before it is initialized. That returns 0, meaning no automatic gain. So if the "Hardware AGC" box is not checked on start, the function is called with automatic == 0, and then wrongly assumes that this has been already set. Unfortunately, the default inside the SDRplay specific routines is to have AGC enabled, causing an inconsistency. The manual gain settings are then overridden by the AGC.

By checking the AGC box before starting, the function gets called with a nonzero value in automatic, so _gain_mode[ chan ] gets properly initialized and the change is propagated to the SDRplay driver. Unchecking AGC again then works as expected.

That particular piece of code still exists in the upstream code of gr-osmosdr from osmocom, apparently also without proper initialization.

In theory, GQRX could work around this by emulating the check/uncheck of the AGC box in software, but it would be better if gr-osmosdr was fixed to correctly initialize _gain_mode or check if _gain_mode[ chan ] exists before reading it.

dl2kcd avatar Jan 01 '22 08:01 dl2kcd

This change in gr-osmosdr/lib/source_impl.cc fixes it for me:

-        if ( _gain_mode[ chan ] != automatic ) {
+        if ( (_gain_mode.count(chan) == 0) || (_gain_mode[ chan ] != automatic) ) {

dl2kcd avatar Jan 01 '22 10:01 dl2kcd

Upstream ticket: https://osmocom.org/issues/5562

AsciiWolf avatar May 13 '22 22:05 AsciiWolf

The issue was patched downstream in Fedora. Let's hope it will also be fixed in upstream and/or in other Linux distributions.

AsciiWolf avatar May 26 '22 13:05 AsciiWolf

Closing the ticket since this has to be fixed in gr-osmosdr, not Gqrx.

AsciiWolf avatar Apr 29 '23 12:04 AsciiWolf

Perhaps the issue would get more visibility in Osmocom's gitea instance: https://gitea.osmocom.org/sdr/gr-osmosdr/issues

argilo avatar Apr 29 '23 12:04 argilo