From 83bc1bd355f888302a936ef51831a18c59c2ea27 Mon Sep 17 00:00:00 2001 From: Hannes Matuschek Date: Fri, 1 Aug 2014 14:22:47 +0200 Subject: [PATCH] Fixed RTLSource to provide possible tuner gains. --- src/rtlsource.cc | 21 ++++++++++++++------- src/rtlsource.hh | 4 ++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/rtlsource.cc b/src/rtlsource.cc index c5dea4b..2473b20 100644 --- a/src/rtlsource.cc +++ b/src/rtlsource.cc @@ -5,7 +5,7 @@ using namespace sdr; RTLSource::RTLSource(double frequency, double sample_rate, size_t device_idx) - : Source(), _frequency(frequency), _sample_rate(sample_rate), _agc_enabled(true), + : Source(), _frequency(frequency), _sample_rate(sample_rate), _agc_enabled(true), _gains(), _buffer_size(131072), _device(0) { { @@ -18,11 +18,13 @@ RTLSource::RTLSource(double frequency, double sample_rate, size_t device_idx) // Open device if (0 < rtlsdr_get_device_count()) { if (rtlsdr_open(&_device, device_idx)) { - ConfigError err; err << "Can not open RTL2832 USB device " << device_idx; throw err; + ConfigError err; err << "Can not open RTL2832 USB device " << device_idx; + throw err; } } else { - ConfigError err; err << "Can not open RTL2832 USB device: No with index " - << device_idx << " found."; throw err; + ConfigError err; err << "Can not open RTL2832 USB device: No device with index " + << device_idx << " found."; + throw err; } { @@ -33,10 +35,15 @@ RTLSource::RTLSource(double frequency, double sample_rate, size_t device_idx) // Try to set center frequency if (0 < _frequency) { setFrequency(_frequency); } - // Set sample rate - if (_sample_rate > 0) { - setSampleRate(sample_rate); + if (_sample_rate > 0) { setSampleRate(sample_rate); } + + // Query gain factors: + int num_gains = rtlsdr_get_tuner_gains(_device, 0); + if (num_gains > 0) { + int gains[num_gains]; rtlsdr_get_tuner_gains(_device, gains); + _gains.reserve(num_gains); + for (int i=0; i & gainFactors() const { return _gains; } /** Starts the reception. */ void start(); @@ -74,6 +76,8 @@ protected: double _sample_rate; /** If true, the AGC is enabled. */ bool _agc_enabled; + /** A vector of gain factors supported by the device. */ + std::vector _gains; /** The buffer size. */ size_t _buffer_size; /** The RTL2832 device object. */