New functions rtlsdr_set_tuner_bandwidth()

Signed-off-by: Steve Markgraf <steve@steve-m.de>
master
Jiří Pinkava 10 years ago committed by Steve Markgraf
parent d892279085
commit 92df068dc5
  1. 9
      include/rtl-sdr.h
  2. 35
      src/librtlsdr.c

@ -215,6 +215,15 @@ RTLSDR_API int rtlsdr_get_tuner_gains(rtlsdr_dev_t *dev, int *gains);
*/ */
RTLSDR_API int rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain); RTLSDR_API int rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain);
/*!
* Set the bandwidth for the device.
*
* \param dev the device handle given by rtlsdr_open()
* \param bw bandwidth in Hz. Zero means automatic BW selection.
* \return 0 on success
*/
RTLSDR_API int rtlsdr_set_tuner_bandwidth(rtlsdr_dev_t *dev, uint32_t bw);
/*! /*!
* Get actual gain the device is configured to. * Get actual gain the device is configured to.
* *

@ -113,6 +113,7 @@ struct rtlsdr_dev {
rtlsdr_tuner_iface_t *tuner; rtlsdr_tuner_iface_t *tuner;
uint32_t tun_xtal; /* Hz */ uint32_t tun_xtal; /* Hz */
uint32_t freq; /* Hz */ uint32_t freq; /* Hz */
uint32_t bw;
uint32_t offs_freq; /* Hz */ uint32_t offs_freq; /* Hz */
int corr; /* ppm */ int corr; /* ppm */
int gain; /* tenth dB */ int gain; /* tenth dB */
@ -1008,6 +1009,24 @@ int rtlsdr_get_tuner_gains(rtlsdr_dev_t *dev, int *gains)
} }
} }
int rtlsdr_set_tuner_bandwidth(rtlsdr_dev_t *dev, uint32_t bw)
{
int r = 0;
if (!dev || !dev->tuner)
return -1;
if (dev->tuner->set_bw) {
rtlsdr_set_i2c_repeater(dev, 1);
r = dev->tuner->set_bw(dev, bw > 0 ? bw : dev->rate);
rtlsdr_set_i2c_repeater(dev, 0);
if (r)
return r;
dev->bw = bw;
}
return r;
}
int rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain) int rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain)
{ {
int r = 0; int r = 0;
@ -1095,14 +1114,14 @@ int rtlsdr_set_sample_rate(rtlsdr_dev_t *dev, uint32_t samp_rate)
if ( ((double)samp_rate) != real_rate ) if ( ((double)samp_rate) != real_rate )
fprintf(stderr, "Exact sample rate is: %f Hz\n", real_rate); fprintf(stderr, "Exact sample rate is: %f Hz\n", real_rate);
dev->rate = (uint32_t)real_rate;
if (dev->tuner && dev->tuner->set_bw) { if (dev->tuner && dev->tuner->set_bw) {
rtlsdr_set_i2c_repeater(dev, 1); rtlsdr_set_i2c_repeater(dev, 1);
dev->tuner->set_bw(dev, (int)real_rate); dev->tuner->set_bw(dev, dev->bw > 0 ? dev->bw : dev->rate);
rtlsdr_set_i2c_repeater(dev, 0); rtlsdr_set_i2c_repeater(dev, 0);
} }
dev->rate = (uint32_t)real_rate;
tmp = (rsamp_ratio >> 16); tmp = (rsamp_ratio >> 16);
r |= rtlsdr_demod_write_reg(dev, 1, 0x9f, tmp, 2); r |= rtlsdr_demod_write_reg(dev, 1, 0x9f, tmp, 2);
tmp = rsamp_ratio & 0xffff; tmp = rsamp_ratio & 0xffff;
@ -1219,6 +1238,7 @@ int rtlsdr_get_direct_sampling(rtlsdr_dev_t *dev)
int rtlsdr_set_offset_tuning(rtlsdr_dev_t *dev, int on) int rtlsdr_set_offset_tuning(rtlsdr_dev_t *dev, int on)
{ {
int r = 0; int r = 0;
int bw;
if (!dev) if (!dev)
return -1; return -1;
@ -1236,7 +1256,14 @@ int rtlsdr_set_offset_tuning(rtlsdr_dev_t *dev, int on)
if (dev->tuner && dev->tuner->set_bw) { if (dev->tuner && dev->tuner->set_bw) {
rtlsdr_set_i2c_repeater(dev, 1); rtlsdr_set_i2c_repeater(dev, 1);
dev->tuner->set_bw(dev, on ? (2 * dev->offs_freq) : dev->rate); if (on) {
bw = 2 * dev->offs_freq;
} else if (dev->bw > 0) {
bw = dev->bw;
} else {
bw = dev->rate;
}
dev->tuner->set_bw(dev, bw);
rtlsdr_set_i2c_repeater(dev, 0); rtlsdr_set_i2c_repeater(dev, 0);
} }

Loading…
Cancel
Save