implement virtually arbitrary gain values

internally, this will pick a certain gain value out of the valid gains
using the "smallest error" strategy.
gr3.6
Dimitri Stolnikov 11 years ago
parent ba0b52868a
commit 3a066ff258
  1. 23
      lib/rtl/rtl_source_c.cc

@ -435,10 +435,31 @@ bool rtl_source_c::get_gain_mode( size_t chan )
return _auto_gain;
}
double pick_closest_gain(osmosdr::gain_range_t &gains, double required)
{
double result = required;
double distance = 100;
BOOST_FOREACH(osmosdr::range_t gain, gains)
{
double diff = fabs(gain.start() - required);
if (diff < distance) {
distance = diff;
result = gain.start();
}
}
return result;
}
double rtl_source_c::set_gain( double gain, size_t chan )
{
osmosdr::gain_range_t gains = rtl_source_c::get_gain_range( chan );
double picked_gain = pick_closest_gain( gains, gain );
if (_dev)
rtlsdr_set_tuner_gain( _dev, int(gain * 10.0) );
rtlsdr_set_tuner_gain( _dev, int(picked_gain * 10.0) );
return get_gain( chan );
}

Loading…
Cancel
Save