rtl: introduce buflen argument

this might be helful for rates <1MSPS
value must be multiple of 512 bytes
This commit is contained in:
Dimitri Stolnikov 2012-11-28 20:44:43 +01:00
parent 380d23ae72
commit 8041472ff7
2 changed files with 23 additions and 13 deletions

View File

@ -44,7 +44,7 @@
using namespace boost::assign; 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_NUM 32
#define BUF_SKIP 1 // buffers to skip due to initial garbage #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")) if (dict.count("offset_tune"))
offset_tune = boost::lexical_cast< unsigned int >( dict["offset_tune"] ); offset_tune = boost::lexical_cast< unsigned int >( dict["offset_tune"] );
_buf_num = BUF_NUM; _buf_num = _buf_len = _buf_head = _buf_used = _buf_offset = 0;
_buf_head = _buf_used = _buf_offset = 0;
_samp_avail = BUF_SIZE / BYTES_PER_SAMPLE;
if (dict.count("buffers")) { if (dict.count("buffers"))
_buf_num = (unsigned int)boost::lexical_cast< double >( dict["buffers"] ); _buf_num = boost::lexical_cast< unsigned int >( dict["buffers"] );
if (0 == _buf_num)
_buf_num = BUF_NUM; if (dict.count("buflen"))
std::cerr << "Using " << _buf_num << " buffers of size " << BUF_SIZE << "." _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; << std::endl;
} }
_samp_avail = _buf_len / BYTES_PER_SAMPLE;
// create a lookup table for gr_complex values // create a lookup table for gr_complex values
for (unsigned int i = 0; i <= 0xffff; i++) { for (unsigned int i = 0; i <= 0xffff; i++) {
#ifdef BOOST_LITTLE_ENDIAN #ifdef BOOST_LITTLE_ENDIAN
@ -198,7 +207,7 @@ rtl_source_c::rtl_source_c (const std::string &args)
if (direct_samp) { if (direct_samp) {
ret = rtlsdr_set_direct_sampling(_dev, direct_samp); ret = rtlsdr_set_direct_sampling(_dev, direct_samp);
if (ret < 0) 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) { if (offset_tune) {
@ -217,7 +226,7 @@ rtl_source_c::rtl_source_c (const std::string &args)
if (_buf) { if (_buf) {
for(unsigned int i = 0; i < _buf_num; ++i) 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); _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() 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; _running = false;
@ -335,7 +344,7 @@ int rtl_source_c::work( int noutput_items,
*out++ = _lut[ *(buf + i) ]; *out++ = _lut[ *(buf + i) ];
_buf_offset = remaining; _buf_offset = remaining;
_samp_avail = (BUF_SIZE / BYTES_PER_SAMPLE) - remaining; _samp_avail = (_buf_len / BYTES_PER_SAMPLE) - remaining;
} }
return noutput_items; return noutput_items;

View File

@ -124,6 +124,7 @@ private:
gruel::thread _thread; gruel::thread _thread;
unsigned short **_buf; unsigned short **_buf;
unsigned int _buf_num; unsigned int _buf_num;
unsigned int _buf_len;
unsigned int _buf_head; unsigned int _buf_head;
unsigned int _buf_used; unsigned int _buf_used;
boost::mutex _buf_mutex; boost::mutex _buf_mutex;