keenerd/rtl-sdr — pull request #6 by mutability (2014-08-25 13:26:25+00:00)
Title: R820T finetuning by tweaking the RTL2832's IF

This changes R820T tuning to be even more precise - down to about 7Hz steps (28.8MHz / 2**22).

The tuners' set_freq interface is changed to report the actual tuner LO used. This is only implemented for tuner_r82xx which reports the actual LO (tuned freq + IF offset); other tuners just echo the requested frequency back (zero-IF mode). Potentially other tuners could report the actual LO (not sure with the interaction with zero-IF mode; it should be similar to offset tuning, though)

rtlsdr_set_center_freq then uses the actual LO frequency to set the RTL2832's downconverter to move the center frequency after tuning to baseband. This gives us some extra precision as the 2832's downconverter has 22-bit precision vs. the R820T's 16-bit PLL precision.

In theory these changes also handle offset tuning as that will result in a tuner LO that's offset from the desired frequency, and the downconverter gets set correctly. But I don't have hardware to test that on.

Other changes:

rtlsdr_get_center_freq() now returns the actually tuned frequency, which may be a few Hz away from what was requested. Apps can use this to adjust for the small offset from baseband (e.g. I've tweaked kalibrate to account for this when measuring oscillator error)

rtlsdr_set_if_bandwidth() had no implementation - removed the prototype. Setting the IF filter bandwidth happens implicitly when the sample rate is set.

The rest of the changes are sorting out the behaviour of rtlsdr_set_if_freq() and dealing with direct sampling. In summary the behaviour is now:

* In normal tuning mode, rtlsdr_set_if_freq() sets the tuner to use the specified IF and retunes everything to use it. This implicitly changes the 2832's downconverter as needed. The tuner IF filter is set to match the tuner IF. Subsequent calls to rtlsdr_set_center_freq() will use the newly set tuner IF.
* In direct sampling mode, rtlsdr_set_if_freq() and rtl_set_center_freq() both set the tuner IF filter and the 2832 downconverter settings only. The tuner is not retuned.
* A tuner reset (on init, or when exiting direct sampling) sets the tuner IF to the default