aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rtl/rtl_source_c.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rtl/rtl_source_c.cc')
-rw-r--r--lib/rtl/rtl_source_c.cc27
1 files changed, 14 insertions, 13 deletions
diff --git a/lib/rtl/rtl_source_c.cc b/lib/rtl/rtl_source_c.cc
index 97252a7..a371464 100644
--- a/lib/rtl/rtl_source_c.cc
+++ b/lib/rtl/rtl_source_c.cc
@@ -92,6 +92,7 @@ rtl_source_c::rtl_source_c (const std::string &args)
{
int ret;
int index;
+ int bias_tee = 0;
unsigned int dev_index = 0, rtl_freq = 0, tuner_freq = 0, direct_samp = 0;
unsigned int offset_tune = 0;
char manufact[256];
@@ -150,6 +151,9 @@ rtl_source_c::rtl_source_c (const std::string &args)
if (dict.count("offset_tune"))
offset_tune = boost::lexical_cast< unsigned int >( dict["offset_tune"] );
+ if (dict.count("bias"))
+ bias_tee = boost::lexical_cast<bool>( dict["bias"] );
+
_buf_num = _buf_len = _buf_head = _buf_used = _buf_offset = 0;
if (dict.count("buffers"))
@@ -172,15 +176,8 @@ rtl_source_c::rtl_source_c (const std::string &args)
_samp_avail = _buf_len / BYTES_PER_SAMPLE;
// create a lookup table for gr_complex values
- for (unsigned int i = 0; i <= 0xffff; i++) {
-#ifdef BOOST_LITTLE_ENDIAN
- _lut.push_back( gr_complex( (float(i & 0xff) - 127.4f) * (1.0f/128.0f),
- (float(i >> 8) - 127.4f) * (1.0f/128.0f) ) );
-#else // BOOST_BIG_ENDIAN
- _lut.push_back( gr_complex( (float(i >> 8) - 127.4f) * (1.0f/128.0f),
- (float(i & 0xff) - 127.4f) * (1.0f/128.0f) ) );
-#endif
- }
+ for (unsigned int i = 0; i < 0x100; i++)
+ _lut.push_back((i - 127.4f) / 128.0f);
_dev = NULL;
ret = rtlsdr_open( &_dev, dev_index );
@@ -224,17 +221,21 @@ rtl_source_c::rtl_source_c (const std::string &args)
throw std::runtime_error("Failed to enable offset tuning.");
}
+ ret = rtlsdr_set_bias_tee(_dev, bias_tee);
+ if (ret < 0)
+ throw std::runtime_error("Failed to set bias tee.");
+
ret = rtlsdr_reset_buffer( _dev );
if (ret < 0)
throw std::runtime_error("Failed to reset usb buffers.");
set_if_gain( 24 ); /* preset to a reasonable default (non-GRC use case) */
- _buf = (unsigned short **) malloc(_buf_num * sizeof(unsigned short *));
+ _buf = (unsigned char **)malloc(_buf_num * sizeof(unsigned char *));
if (_buf) {
for(unsigned int i = 0; i < _buf_num; ++i)
- _buf[i] = (unsigned short *) malloc(_buf_len);
+ _buf[i] = (unsigned char *)malloc(_buf_len);
}
}
@@ -348,10 +349,10 @@ int rtl_source_c::work( int noutput_items,
while (noutput_items && _buf_used) {
const int nout = std::min(noutput_items, _samp_avail);
- const unsigned short *buf = _buf[_buf_head] + _buf_offset;
+ const unsigned char *buf = _buf[_buf_head] + _buf_offset * 2;
for (int i = 0; i < nout; ++i)
- *out++ = _lut[ *(buf + i) ];
+ *out++ = gr_complex(_lut[buf[i * 2]], _lut[buf[i * 2 + 1]]);
noutput_items -= nout;
_samp_avail -= nout;