forked from sdr/gr-osmosdr
HackRF: convert _lut to float[] to reduce size by a factor of 256
Similar to commit 33a8d1c
for RTL-SDR, this uses two lookups in a
256-element LUT instead of one lookup in a 65536-element LUT, which
saves a bit of CPU cache. It also eliminates a dependency on the
host's byte ordering.
Signed-off-by: Eric Wild <ewild@sysmocom.de>
This commit is contained in:
parent
800d2eaeaf
commit
2e7d343fed
|
@ -31,8 +31,6 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <boost/detail/endian.hpp>
|
|
||||||
|
|
||||||
#include <gnuradio/io_signature.h>
|
#include <gnuradio/io_signature.h>
|
||||||
|
|
||||||
#include "hackrf_source_c.h"
|
#include "hackrf_source_c.h"
|
||||||
|
@ -89,14 +87,8 @@ hackrf_source_c::hackrf_source_c (const std::string &args)
|
||||||
_samp_avail = _buf_len / BYTES_PER_SAMPLE;
|
_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 <= 0xff; i++) {
|
||||||
#ifdef BOOST_LITTLE_ENDIAN
|
_lut.push_back( float(i) * (1.0f/128.0f) );
|
||||||
_lut.push_back( gr_complex( (float(int8_t(i & 0xff))) * (1.0f/128.0f),
|
|
||||||
(float(int8_t(i >> 8))) * (1.0f/128.0f) ) );
|
|
||||||
#else // BOOST_BIG_ENDIAN
|
|
||||||
_lut.push_back( gr_complex( (float(int8_t(i >> 8))) * (1.0f/128.0f),
|
|
||||||
(float(int8_t(i & 0xff))) * (1.0f/128.0f) ) );
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( BUF_NUM != _buf_num || BUF_LEN != _buf_len ) {
|
if ( BUF_NUM != _buf_num || BUF_LEN != _buf_len ) {
|
||||||
|
@ -119,11 +111,11 @@ hackrf_source_c::hackrf_source_c (const std::string &args)
|
||||||
hackrf_common::set_bias(dict["bias"] == "1");
|
hackrf_common::set_bias(dict["bias"] == "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
_buf = (unsigned short **) malloc(_buf_num * sizeof(unsigned short *));
|
_buf = (unsigned char **) malloc(_buf_num * sizeof(unsigned char *));
|
||||||
|
|
||||||
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_len);
|
_buf[i] = (unsigned char *) malloc(_buf_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,17 +210,18 @@ int hackrf_source_c::work( int noutput_items,
|
||||||
if ( ! running )
|
if ( ! running )
|
||||||
return WORK_DONE;
|
return WORK_DONE;
|
||||||
|
|
||||||
unsigned short *buf = _buf[_buf_head] + _buf_offset;
|
const uint8_t *buf = _buf[_buf_head] + _buf_offset * BYTES_PER_SAMPLE;
|
||||||
|
#define TO_COMPLEX(p) gr_complex( _lut[(p)[0]], _lut[(p)[1]] )
|
||||||
|
|
||||||
if (noutput_items <= _samp_avail) {
|
if (noutput_items <= _samp_avail) {
|
||||||
for (int i = 0; i < noutput_items; ++i)
|
for (int i = 0; i < noutput_items; ++i)
|
||||||
*out++ = _lut[ *(buf + i) ];
|
*out++ = TO_COMPLEX( buf + i*BYTES_PER_SAMPLE );
|
||||||
|
|
||||||
_buf_offset += noutput_items;
|
_buf_offset += noutput_items;
|
||||||
_samp_avail -= noutput_items;
|
_samp_avail -= noutput_items;
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < _samp_avail; ++i)
|
for (int i = 0; i < _samp_avail; ++i)
|
||||||
*out++ = _lut[ *(buf + i) ];
|
*out++ = TO_COMPLEX( buf + i*BYTES_PER_SAMPLE );
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(_buf_mutex);
|
std::lock_guard<std::mutex> lock(_buf_mutex);
|
||||||
|
@ -242,7 +235,7 @@ int hackrf_source_c::work( int noutput_items,
|
||||||
int remaining = noutput_items - _samp_avail;
|
int remaining = noutput_items - _samp_avail;
|
||||||
|
|
||||||
for (int i = 0; i < remaining; ++i)
|
for (int i = 0; i < remaining; ++i)
|
||||||
*out++ = _lut[ *(buf + i) ];
|
*out++ = TO_COMPLEX( buf + i*BYTES_PER_SAMPLE );
|
||||||
|
|
||||||
_buf_offset = remaining;
|
_buf_offset = remaining;
|
||||||
_samp_avail = (_buf_len / BYTES_PER_SAMPLE) - remaining;
|
_samp_avail = (_buf_len / BYTES_PER_SAMPLE) - remaining;
|
||||||
|
|
|
@ -123,9 +123,9 @@ private:
|
||||||
static int _hackrf_rx_callback(hackrf_transfer* transfer);
|
static int _hackrf_rx_callback(hackrf_transfer* transfer);
|
||||||
int hackrf_rx_callback(unsigned char *buf, uint32_t len);
|
int hackrf_rx_callback(unsigned char *buf, uint32_t len);
|
||||||
|
|
||||||
std::vector<gr_complex> _lut;
|
std::vector<float> _lut;
|
||||||
|
|
||||||
unsigned short **_buf;
|
unsigned char **_buf;
|
||||||
unsigned int _buf_num;
|
unsigned int _buf_num;
|
||||||
unsigned int _buf_len;
|
unsigned int _buf_len;
|
||||||
unsigned int _buf_head;
|
unsigned int _buf_head;
|
||||||
|
|
Loading…
Reference in New Issue