diff options
author | Krzysztof Halasa <khc@pm.wav.pl> | 2017-03-18 10:07:19 +0100 |
---|---|---|
committer | Dimitri Stolnikov <horiz0n@gmx.net> | 2017-06-11 21:30:38 +0200 |
commit | 33a8d1c2aef31ab7fb9f40e673c974334081853e (patch) | |
tree | 72cc71e18580e2dabec51c1a14dd952e7b62cab3 | |
parent | 5ecfa255d299b9b4842ccd09a02892a853fcd5a7 (diff) |
RTL-SDR: convert _lut to float[] to reduce size by a factor of 256
The _lut is being indexed by I + Q (16 bits = 65536 entries), however
both samples can be processed independently, resulting in 8-bit LUT.
Saves a bit of RAM and CPU cache.
-rw-r--r-- | lib/rtl/rtl_source_c.cc | 19 | ||||
-rw-r--r-- | lib/rtl/rtl_source_c.h | 4 |
2 files changed, 8 insertions, 15 deletions
diff --git a/lib/rtl/rtl_source_c.cc b/lib/rtl/rtl_source_c.cc index 97252a7..8a8df7c 100644 --- a/lib/rtl/rtl_source_c.cc +++ b/lib/rtl/rtl_source_c.cc @@ -172,15 +172,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 ); @@ -230,11 +223,11 @@ rtl_source_c::rtl_source_c (const std::string &args) 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 +341,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; diff --git a/lib/rtl/rtl_source_c.h b/lib/rtl/rtl_source_c.h index 76de400..902b386 100644 --- a/lib/rtl/rtl_source_c.h +++ b/lib/rtl/rtl_source_c.h @@ -122,11 +122,11 @@ private: static void _rtlsdr_wait(rtl_source_c *obj); void rtlsdr_wait(); - std::vector<gr_complex> _lut; + std::vector<float> _lut; rtlsdr_dev_t *_dev; gr::thread::thread _thread; - unsigned short **_buf; + unsigned char **_buf; unsigned int _buf_num; unsigned int _buf_len; unsigned int _buf_head; |