31 |
31 |
#include <stdexcept>
|
32 |
32 |
#include <iostream>
|
33 |
33 |
|
34 |
|
#include <boost/detail/endian.hpp>
|
35 |
|
|
36 |
34 |
#include <gnuradio/io_signature.h>
|
37 |
35 |
|
38 |
36 |
#include "hackrf_source_c.h"
|
... | ... | |
89 |
87 |
_samp_avail = _buf_len / BYTES_PER_SAMPLE;
|
90 |
88 |
|
91 |
89 |
// create a lookup table for gr_complex values
|
92 |
|
for (unsigned int i = 0; i <= 0xffff; i++) {
|
93 |
|
#ifdef BOOST_LITTLE_ENDIAN
|
94 |
|
_lut.push_back( gr_complex( (float(int8_t(i & 0xff))) * (1.0f/128.0f),
|
95 |
|
(float(int8_t(i >> 8))) * (1.0f/128.0f) ) );
|
96 |
|
#else // BOOST_BIG_ENDIAN
|
97 |
|
_lut.push_back( gr_complex( (float(int8_t(i >> 8))) * (1.0f/128.0f),
|
98 |
|
(float(int8_t(i & 0xff))) * (1.0f/128.0f) ) );
|
99 |
|
#endif
|
|
90 |
for (unsigned int i = 0; i <= 0xff; i++) {
|
|
91 |
_lut.push_back( float(i) * (1.0f/128.0f) );
|
100 |
92 |
}
|
101 |
93 |
|
102 |
94 |
if ( BUF_NUM != _buf_num || BUF_LEN != _buf_len ) {
|
... | ... | |
119 |
111 |
hackrf_common::set_bias(dict["bias"] == "1");
|
120 |
112 |
}
|
121 |
113 |
|
122 |
|
_buf = (unsigned short **) malloc(_buf_num * sizeof(unsigned short *));
|
|
114 |
_buf = (unsigned char **) malloc(_buf_num * sizeof(unsigned char *));
|
123 |
115 |
|
124 |
116 |
if (_buf) {
|
125 |
117 |
for(unsigned int i = 0; i < _buf_num; ++i)
|
126 |
|
_buf[i] = (unsigned short *) malloc(_buf_len);
|
|
118 |
_buf[i] = (unsigned char *) malloc(_buf_len);
|
127 |
119 |
}
|
128 |
120 |
}
|
129 |
121 |
|
... | ... | |
218 |
210 |
if ( ! running )
|
219 |
211 |
return WORK_DONE;
|
220 |
212 |
|
221 |
|
unsigned short *buf = _buf[_buf_head] + _buf_offset;
|
|
213 |
const uint8_t *buf = _buf[_buf_head] + _buf_offset * BYTES_PER_SAMPLE;
|
|
214 |
#define TO_COMPLEX(p) gr_complex( _lut[(p)[0]], _lut[(p)[1]] )
|
222 |
215 |
|
223 |
216 |
if (noutput_items <= _samp_avail) {
|
224 |
217 |
for (int i = 0; i < noutput_items; ++i)
|
225 |
|
*out++ = _lut[ *(buf + i) ];
|
|
218 |
*out++ = TO_COMPLEX( buf + i*BYTES_PER_SAMPLE );
|
226 |
219 |
|
227 |
220 |
_buf_offset += noutput_items;
|
228 |
221 |
_samp_avail -= noutput_items;
|
229 |
222 |
} else {
|
230 |
223 |
for (int i = 0; i < _samp_avail; ++i)
|
231 |
|
*out++ = _lut[ *(buf + i) ];
|
|
224 |
*out++ = TO_COMPLEX( buf + i*BYTES_PER_SAMPLE );
|
232 |
225 |
|
233 |
226 |
{
|
234 |
227 |
std::unique_lock<std::mutex> lock(_buf_mutex);
|
... | ... | |
242 |
235 |
int remaining = noutput_items - _samp_avail;
|
243 |
236 |
|
244 |
237 |
for (int i = 0; i < remaining; ++i)
|
245 |
|
*out++ = _lut[ *(buf + i) ];
|
|
238 |
*out++ = TO_COMPLEX( buf + i*BYTES_PER_SAMPLE );
|
246 |
239 |
|
247 |
240 |
_buf_offset = remaining;
|
248 |
241 |
_samp_avail = (_buf_len / BYTES_PER_SAMPLE) - remaining;
|