pothosware / SoapyRTLSDR

SoapySDR RTL-SDR Support Module
https://github.com/pothosware/SoapyRTLSDR/wiki
MIT License
124 stars 29 forks source link

Automatic gain mode setting, rtlsdr_set_tuner_gain_mode(dev, 0) equivalent #21

Closed rxseger closed 5 years ago

rxseger commented 8 years ago

librtlsdr implements rtlsdr_set_tuner_gain_mode() here for setting "automatic" (0) or "manual" (1) gain mode, this API doesn't appear to be bridged in SoapyRTLSDR.

Should it be, or how can one enable auto gain? (curious how CubicSDR does it). Without setting some gain, I can only receive silence, using 40 dB as a default for now but having the hardware/driver automatically choose the default gain values seems to be preferable, especially if it can differ between devices or other configurations.

(Note, mainly to self: automatic gain is distinct from automatic gain correction (agc), librtlsdr's rtlsdr_set_agc_mode(), which is bridged in SoapyRTLSDR setGainMode(bool). But not https://github.com/pothosware/SoapyRTLSDR/search?q=rtlsdr_set_tuner_gain_mode)

cjcliffe commented 8 years ago

Not sure; I'll take a look at the gain functions again -- at the time of writing I don't recall there being a second option -- AGC seems to be functional here so I'm not sure if this is just a more recent development?

CubicSDR has only used/bundled git://git.osmocom.org/rtl-sdr.git to date as it is still considered the official source to my knowledge.

rxseger commented 8 years ago

Ah, git://git.osmocom.org/rtl-sdr.git is the official librtlsdr not https://github.com/librtlsdr/librtlsdr? Too many forks, confusing :/

But rtlsdr_set_tuner_gainmode is in osmocom/rtl-sdr as well, was added back in 2012: https://github.com/librtlsdr/librtlsdr/commit/86c34428aabebc79ac0de7f1194e6b755a6fa213. The librtlsdr rtl* tools will enable auto gain mode if no -g command-line argument is specified (verbose_auto_gain() -> rtlsdr_set_tuner_gain_mode(dev, 0);). With -g #, they'll enable manual gain mode and set the tuner gain (verbose_gain_set() -> rtlsdr_set_tuner_gain_mode(dev, 1); rtlsdr_set_tuner_gain(dev, gain);). AGC can be enabled/disabled independently of auto/manual gain mode, I believe.

cjcliffe commented 8 years ago

@rxseger ah, I see it now -- I'll try that here soon unless you work up a PR in the meantime I can merge; thanks for catching that 👍

zuckschwerdt commented 5 years ago

I'd like to add rtlsdr_set_tuner_gain_mode() for automatic tuner gain. What would be the best way to fit that into the SoapySDR API? Is a magic value for setGain() acceptable (i.e. extend the gain range to 41dB and use that as switch)? Or should I add the switch to the writeSetting/readSetting facility? I guess adding a new gain element TUNER_AUTO=0/1 could be done too but seems obscure.

guruofquality commented 5 years ago

I see, yea setGainMode is already taken by rtlsdr_set_agc_mode(), and rtlsdr_set_tuner_gain_mode() is like AGC but for just specifically the tuner. I think this could merit an API to set gain mode, but per gain element: example void setGainMode(const int direction, const size_t channel, const std::string &name, const bool automatic)

In the meantime, it doesnt hurt to use writeSetting/readSetting which will work nicely in cubic, and for that matter a device argument keyword, just to make command line utils easier.

I wonder if the current setGainMode() should set both tuner gain mode and agc though? Are they often set in tandem when no specific gain setting is supplied?

zuckschwerdt commented 5 years ago

I can't really say if people like to use AGC, for me it's always off and the tuner gain mode to auto. I'll code the setting option and run some tests.

zuckschwerdt commented 5 years ago

Maybe I'm wrong but the "AGC" with rtlsdr_set_agc_mode() is a digital gain stage and not too useful. The actual switch between manual gain and automatic gain in the tuner (analog) side is rtlsdr_set_tuner_gain_mode(). I know it's a hard decision to break existing interfaces and will cause grief. Nevertheless I need to propose, setGainMode() should switch automatic gain on the tuner as setGain() sets a manual gain there. And the digital AGC should be an option switch hidden away with the settings :) That said I'm fine with the (current) other way around, as long as I can access the features.

zuckschwerdt commented 5 years ago

I have outlined both ideas in #32 and #33.

guruofquality commented 5 years ago

I personally like breaking setGainMode() to use rtlsdr_set_tuner_gain_mode() which sounds more useful and possibly better intentioned. Lets sit on this for a while and see if anyone else has any reasoned objections. :-D

guruofquality commented 5 years ago

Cool, the PR is merged, I will update the changelog