rtl_tcp: remove gr-blocks usage for float-to-complex conversion

thanks to Hoernchen for the initial patch
This commit is contained in:
Dimitri Stolnikov 2013-08-04 00:18:45 +02:00
parent bd800ed89e
commit 6e29bf179f
5 changed files with 36 additions and 33 deletions

View File

@ -244,7 +244,7 @@ endif(ENABLE_RTL)
########################################################################
# Setup RTL_TCP component
########################################################################
GR_REGISTER_COMPONENT("RTLSDR TCP Client" ENABLE_RTL_TCP GNURADIO_BLOCKS_FOUND)
GR_REGISTER_COMPONENT("RTLSDR TCP Client" ENABLE_RTL_TCP)
if(ENABLE_RTL_TCP)
GR_INCLUDE_SUBDIRECTORY(rtl_tcp)
endif(ENABLE_RTL_TCP)

View File

@ -34,5 +34,5 @@ set(rtl_tcp_srcs
# Append gnuradio-osmosdr library sources
########################################################################
list(APPEND gr_osmosdr_srcs ${rtl_tcp_srcs})
list(APPEND gr_osmosdr_libs ${GNURADIO_BLOCKS_LIBRARIES})
#list(APPEND gr_osmosdr_libs ...)

View File

@ -26,8 +26,6 @@
#include <boost/algorithm/string.hpp>
#include <gnuradio/io_signature.h>
#include <gnuradio/blocks/deinterleave.h>
#include <gnuradio/blocks/float_to_complex.h>
#include "rtl_tcp_source_c.h"
@ -126,18 +124,7 @@ rtl_tcp_source_c::rtl_tcp_source_c(const std::string &args) :
_src->set_offset_tuning(offset_tune);
/* rtl tcp source provides a stream of interleaved IQ floats */
gr::blocks::deinterleave::sptr deinterleave = \
gr::blocks::deinterleave::make( sizeof(float) );
/* block to convert deinterleaved floats to a complex stream */
gr::blocks::float_to_complex::sptr f2c = \
gr::blocks::float_to_complex::make( 1 );
connect(_src, 0, deinterleave, 0);
connect(deinterleave, 0, f2c, 0); /* I */
connect(deinterleave, 1, f2c, 1); /* Q */
connect(f2c, 0, self(), 0);
connect(_src, 0, self(), 0);
}
rtl_tcp_source_c::~rtl_tcp_source_c()

View File

@ -90,13 +90,12 @@ rtl_tcp_source_f::rtl_tcp_source_f(size_t itemsize,
bool wait)
: gr::sync_block ("rtl_tcp_source_f",
gr::io_signature::make(0, 0, 0),
gr::io_signature::make(1, 1, sizeof(float))),
gr::io_signature::make(1, 1, sizeof(gr_complex))),
d_itemsize(itemsize),
d_payload_size(payload_size),
d_eof(eof),
d_wait(wait),
d_socket(-1),
d_temp_offset(0)
d_socket(-1)
{
int ret = 0;
#if defined(USING_WINSOCK) // for Windows (with MinGW)
@ -128,10 +127,19 @@ rtl_tcp_source_f::rtl_tcp_source_f(size_t itemsize,
// FIXME leaks if report_error throws below
d_temp_buff = new unsigned char[d_payload_size]; // allow it to hold up to payload_size bytes
d_LUT= new float[0xff+1];
for(int i=0; i <=(0xff);++i){
d_LUT[i] = (((float)(i&0xff))-127.4f)*(1.0f/128.0f);
}
d_LUT = new gr_complex[0xffff+1];
// create a lookup table for gr_complex values
for (unsigned int i = 0; i <= 0xffff; i++) {
#ifdef BOOST_LITTLE_ENDIAN
d_LUT[i] = gr_complex( (float(i >> 8) - 127.4f) * (1.0f/128.0f),
(float(i & 0xff) - 127.4f) * (1.0f/128.0f) );
#else // BOOST_BIG_ENDIAN
d_LUT[i] = gr_complex( (float(i & 0xff) - 127.4f) * (1.0f/128.0f),
(float(i >> 8) - 127.4f) * (1.0f/128.0f) );
#endif
}
// create socket
d_socket = socket(ip_src->ai_family, ip_src->ai_socktype,
ip_src->ai_protocol);
@ -214,6 +222,7 @@ rtl_tcp_source_f_sptr make_rtl_tcp_source_f (size_t itemsize,
rtl_tcp_source_f::~rtl_tcp_source_f ()
{
delete [] d_temp_buff;
delete [] d_LUT;
if (d_socket != -1){
shutdown(d_socket, SHUT_RDWR);
@ -235,11 +244,19 @@ int rtl_tcp_source_f::work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
float *out = (float *) output_items[0];
ssize_t r=0, nbytes=0, bytes_received=0;
ssize_t total_bytes = (ssize_t)(d_itemsize*noutput_items);
gr_complex *out = (gr_complex *) output_items[0];
size_t remaining = 0;
int bytesleft;
if( noutput_items * 2 < d_payload_size) {
bytesleft = noutput_items * 2;
remaining = noutput_items;
} else {
remaining = d_payload_size >> 1;
bytesleft = d_payload_size;
}
int bytesleft = noutput_items;
int index = 0;
int receivedbytes = 0;
while(bytesleft > 0) {
@ -252,12 +269,12 @@ int rtl_tcp_source_f::work (int noutput_items,
bytesleft -= receivedbytes;
index += receivedbytes;
}
r = noutput_items;
remaining = noutput_items;
for(int i=0; i<r; ++i)
out[i]=d_LUT[*(d_temp_buff+d_temp_offset+i)];
for(size_t i = 0; i < remaining; ++i)
out[i] = d_LUT[*(((unsigned short*)d_temp_buff)+i)];
return r;
return remaining;
}
#ifdef _WIN32

View File

@ -74,8 +74,7 @@ private:
bool d_wait; // wait if data if not immediately available
int d_socket; // handle to socket
unsigned char *d_temp_buff; // hold buffer between calls
size_t d_temp_offset; // point to temp buffer location offset
float *d_LUT;
gr_complex *d_LUT;
unsigned int d_tuner_type;
unsigned int d_tuner_gain_count;