aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rtl
diff options
context:
space:
mode:
authorDimitri Stolnikov <horiz0n@gmx.net>2012-11-28 20:44:43 +0100
committerDimitri Stolnikov <horiz0n@gmx.net>2012-11-28 20:52:41 +0100
commit8041472ff783d23cd2ae1c001fa3e6dab9b01982 (patch)
tree5317dea0800c3acca47365c3f3e5472bed751698 /lib/rtl
parent380d23ae72671b40b61f23a0a8547057d3b00efc (diff)
rtl: introduce buflen argument
this might be helful for rates <1MSPS value must be multiple of 512 bytes
Diffstat (limited to 'lib/rtl')
-rw-r--r--lib/rtl/rtl_source_c.cc35
-rw-r--r--lib/rtl/rtl_source_c.h1
2 files changed, 23 insertions, 13 deletions
diff --git a/lib/rtl/rtl_source_c.cc b/lib/rtl/rtl_source_c.cc
index 8016e34..efa28fa 100644
--- a/lib/rtl/rtl_source_c.cc
+++ b/lib/rtl/rtl_source_c.cc
@@ -44,7 +44,7 @@
using namespace boost::assign;
-#define BUF_SIZE (16 * 32 * 512)
+#define BUF_LEN (16 * 32 * 512) /* must be multiple of 512 */
#define BUF_NUM 32
#define BUF_SKIP 1 // buffers to skip due to initial garbage
@@ -143,18 +143,27 @@ 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"] );
- _buf_num = BUF_NUM;
- _buf_head = _buf_used = _buf_offset = 0;
- _samp_avail = BUF_SIZE / BYTES_PER_SAMPLE;
+ _buf_num = _buf_len = _buf_head = _buf_used = _buf_offset = 0;
- if (dict.count("buffers")) {
- _buf_num = (unsigned int)boost::lexical_cast< double >( dict["buffers"] );
- if (0 == _buf_num)
- _buf_num = BUF_NUM;
- std::cerr << "Using " << _buf_num << " buffers of size " << BUF_SIZE << "."
+ if (dict.count("buffers"))
+ _buf_num = boost::lexical_cast< unsigned int >( dict["buffers"] );
+
+ if (dict.count("buflen"))
+ _buf_len = boost::lexical_cast< unsigned int >( dict["buflen"] );
+
+ if (0 == _buf_num)
+ _buf_num = BUF_NUM;
+
+ if (0 == _buf_len || _buf_len % 512 != 0) /* len must be multiple of 512 */
+ _buf_len = BUF_LEN;
+
+ if ( BUF_NUM != _buf_num || BUF_LEN != _buf_len ) {
+ std::cerr << "Using " << _buf_num << " buffers of size " << _buf_len << "."
<< std::endl;
}
+ _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
@@ -198,7 +207,7 @@ rtl_source_c::rtl_source_c (const std::string &args)
if (direct_samp) {
ret = rtlsdr_set_direct_sampling(_dev, direct_samp);
if (ret < 0)
- throw std::runtime_error("Failed to enable direct sampling mode.");
+ throw std::runtime_error("Failed to enable direct sampling.");
}
if (offset_tune) {
@@ -217,7 +226,7 @@ rtl_source_c::rtl_source_c (const std::string &args)
if (_buf) {
for(unsigned int i = 0; i < _buf_num; ++i)
- _buf[i] = (unsigned short *) malloc(BUF_SIZE);
+ _buf[i] = (unsigned short *) malloc(_buf_len);
}
_thread = gruel::thread(_rtlsdr_wait, this);
@@ -284,7 +293,7 @@ void rtl_source_c::_rtlsdr_wait(rtl_source_c *obj)
void rtl_source_c::rtlsdr_wait()
{
- int ret = rtlsdr_read_async( _dev, _rtlsdr_callback, (void *)this, 0, BUF_SIZE );
+ int ret = rtlsdr_read_async( _dev, _rtlsdr_callback, (void *)this, 0, _buf_len );
_running = false;
@@ -335,7 +344,7 @@ int rtl_source_c::work( int noutput_items,
*out++ = _lut[ *(buf + i) ];
_buf_offset = remaining;
- _samp_avail = (BUF_SIZE / BYTES_PER_SAMPLE) - remaining;
+ _samp_avail = (_buf_len / BYTES_PER_SAMPLE) - remaining;
}
return noutput_items;
diff --git a/lib/rtl/rtl_source_c.h b/lib/rtl/rtl_source_c.h
index 5f4ccdd..fd2395c 100644
--- a/lib/rtl/rtl_source_c.h
+++ b/lib/rtl/rtl_source_c.h
@@ -124,6 +124,7 @@ private:
gruel::thread _thread;
unsigned short **_buf;
unsigned int _buf_num;
+ unsigned int _buf_len;
unsigned int _buf_head;
unsigned int _buf_used;
boost::mutex _buf_mutex;