forked from sdr/gr-osmosdr
rtl: clean up work function
This commit is contained in:
parent
674e084bdf
commit
6194958d71
|
@ -27,7 +27,7 @@
|
|||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <rtl_source_c.h>
|
||||
#include "rtl_source_c.h"
|
||||
#include <gr_io_signature.h>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
|
@ -45,7 +45,9 @@ using namespace boost::assign;
|
|||
|
||||
#define BUF_SIZE (16 * 32 * 512)
|
||||
#define BUF_NUM 32
|
||||
#define BUF_SKIP 1 // buffers to skip due to garbage
|
||||
#define BUF_SKIP 1 // buffers to skip due to initial garbage
|
||||
|
||||
#define BYTES_PER_SAMPLE 2 // rtl device delivers 8 bit unsigned IQ data
|
||||
|
||||
/*
|
||||
* Create a new instance of rtl_source_c and return
|
||||
|
@ -109,7 +111,7 @@ rtl_source_c::rtl_source_c (const std::string &args)
|
|||
_buf[i] = (unsigned short *) malloc(BUF_SIZE);
|
||||
|
||||
_buf_head = _buf_used = _buf_offset = 0;
|
||||
_samp_avail = BUF_SIZE;
|
||||
_samp_avail = BUF_SIZE / BYTES_PER_SAMPLE;
|
||||
|
||||
// create a lookup table for gr_complex values
|
||||
for (unsigned int i = 0; i <= 0xffff; i++) {
|
||||
|
@ -248,25 +250,24 @@ int rtl_source_c::work( int noutput_items,
|
|||
{
|
||||
boost::mutex::scoped_lock lock( _buf_mutex );
|
||||
|
||||
while (_buf_used < 3 && _running)
|
||||
while (_buf_used < 3 && _running) // collect at least 3 buffers
|
||||
_buf_cond.wait( lock );
|
||||
}
|
||||
|
||||
if (!_running)
|
||||
return WORK_DONE;
|
||||
|
||||
unsigned short *buf = _buf[_buf_head];
|
||||
unsigned short *buf = _buf[_buf_head] + _buf_offset;
|
||||
|
||||
if (noutput_items <= int(_samp_avail)) {
|
||||
for (int i = 0; i < noutput_items; ++i)
|
||||
*out++ = _lut[ *(buf + _buf_offset + i) ];
|
||||
*out++ = _lut[ *(buf + i) ];
|
||||
|
||||
_buf_offset += noutput_items;
|
||||
_samp_avail -= noutput_items;
|
||||
return noutput_items;
|
||||
} else {
|
||||
for (int i = 0; i < int(_samp_avail); ++i)
|
||||
*out++ = _lut[ *(buf + _buf_offset + i) ];
|
||||
*out++ = _lut[ *(buf + i) ];
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock( _buf_mutex );
|
||||
|
@ -276,18 +277,14 @@ int rtl_source_c::work( int noutput_items,
|
|||
}
|
||||
|
||||
buf = _buf[_buf_head];
|
||||
_buf_offset = 0;
|
||||
|
||||
int remaining = noutput_items - _samp_avail;
|
||||
|
||||
for (int i = 0; i < remaining; ++i)
|
||||
*out++ = _lut[ *(buf + _buf_offset + i) ];
|
||||
*out++ = _lut[ *(buf + i) ];
|
||||
|
||||
_buf_offset = remaining;
|
||||
|
||||
_samp_avail = (BUF_SIZE/2) - remaining;
|
||||
|
||||
return noutput_items;
|
||||
_samp_avail = (BUF_SIZE / BYTES_PER_SAMPLE) - remaining;
|
||||
}
|
||||
|
||||
return noutput_items;
|
||||
|
|
Loading…
Reference in New Issue