From a2c6e0bf911d6f01ea4487662a932a63fb50b216 Mon Sep 17 00:00:00 2001 From: Ryndzionek Mariusz Date: Tue, 3 Feb 2015 18:42:44 +0100 Subject: [PATCH 1/3] Added LUT for IQ mapping with proper scaling --- src/sdr/SDRPostThread.cpp | 19 +++++++++++++++++-- src/sdr/SDRPostThread.h | 3 +++ src/sdr/SDRThread.cpp | 2 +- src/sdr/SDRThread.h | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index 2b3b76a..8cfed28 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -2,11 +2,27 @@ #include "CubicSDRDefs.h" #include "CubicSDR.h" +#include +#include #include #include SDRPostThread::SDRPostThread() : iqDataOutQueue(NULL), iqDataInQueue(NULL), iqVisualQueue(NULL), terminated(false), dcFilter(NULL), num_vis_samples(16384) { + + // create a lookup table + for (unsigned int i = 0; i <= 0xffff; i++) { + liquid_float_complex tmp; +# if (__BYTE_ORDER == __LITTLE_ENDIAN) + tmp.real = (float(i & 0xff) - 127.4f) * (1.0f/128.0f); + tmp.imag = (float(i >> 8) - 127.4f) * (1.0f/128.0f); + _lut.push_back(tmp); +#else // BIG_ENDIAN + tmp.real = (float(i >> 8) - 127.4f) * (1.0f/128.0f); + tmp.imag = (float(i & 0xff) - 127.4f) * (1.0f/128.0f); + _lut.push_back(tmp); +#endif + } } SDRPostThread::~SDRPostThread() { @@ -82,8 +98,7 @@ void SDRPostThread::threadMain() { } for (int i = 0, iMax = dataSize; i < iMax; i++) { - fpData[i].real = (float) data_in->data[i * 2] / 127.0; - fpData[i].imag = (float) data_in->data[i * 2 + 1] / 127.0; + fpData[i] = _lut[*((uint16_t*)&data_in->data[2*i])]; } iirfilt_crcf_execute_block(dcFilter, &fpData[0], dataSize, &dataOut[0]); diff --git a/src/sdr/SDRPostThread.h b/src/sdr/SDRPostThread.h index c76aecf..142c04b 100644 --- a/src/sdr/SDRPostThread.h +++ b/src/sdr/SDRPostThread.h @@ -32,4 +32,7 @@ protected: std::atomic terminated; iirfilt_crcf dcFilter; int num_vis_samples; + +private: + std::vector _lut; }; diff --git a/src/sdr/SDRThread.cpp b/src/sdr/SDRThread.cpp index 0d47918..ce3f096 100644 --- a/src/sdr/SDRThread.cpp +++ b/src/sdr/SDRThread.cpp @@ -256,7 +256,7 @@ void SDRThread::threadMain() { } for (int i = 0; i < n_read; i++) { - dataOut->data[i] = buf[i] - 127; + dataOut->data[i] = buf[i]; } double time_slice = (double) n_read / (double) sampleRate; diff --git a/src/sdr/SDRThread.h b/src/sdr/SDRThread.h index 032178f..f6bd976 100644 --- a/src/sdr/SDRThread.h +++ b/src/sdr/SDRThread.h @@ -99,7 +99,7 @@ class SDRThreadIQData: public ReferenceCounter { public: long long frequency; long long sampleRate; - std::vector data; + std::vector data; SDRThreadIQData() : frequency(0), sampleRate(DEFAULT_SAMPLE_RATE) { From 9cf8799a58c0e295f3436a4a23949d20167c51da Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 5 Feb 2015 19:30:06 -0500 Subject: [PATCH 2/3] Patch for Windows / OSX --- src/CubicSDRDefs.h | 16 ++++++++++++++++ src/sdr/SDRPostThread.cpp | 2 -- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/CubicSDRDefs.h b/src/CubicSDRDefs.h index 88b5cbe..b1cb38c 100644 --- a/src/CubicSDRDefs.h +++ b/src/CubicSDRDefs.h @@ -3,6 +3,22 @@ #define CUBICSDR_VERSION "v0.01a" #define CUBICSDR_TITLE "CubicSDR " CUBICSDR_VERSION " by Charles J. Cliffe (@ccliffe)" +#ifndef __BYTE_ORDER + #ifdef _WIN32 + #define ATTRIBUTE + #define __LITTLE_ENDIAN 1234 + #define __BIG_ENDIAN 4321 + #define __PDP_ENDIAN 3412 + #define __BYTE_ORDER __LITTLE_ENDIAN + #else + #ifdef __APPLE__ + #include + #else + #include + #endif + #endif +#endif + const char filePathSeparator = #ifdef _WIN32 '\\'; diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index 8cfed28..1fa8896 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -2,8 +2,6 @@ #include "CubicSDRDefs.h" #include "CubicSDR.h" -#include -#include #include #include From 6deee5a936588365b2ac809b2c7f75593a03a9c3 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 5 Feb 2015 19:45:01 -0500 Subject: [PATCH 3/3] loop->memcpy --- src/sdr/SDRThread.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sdr/SDRThread.cpp b/src/sdr/SDRThread.cpp index ce3f096..82838e5 100644 --- a/src/sdr/SDRThread.cpp +++ b/src/sdr/SDRThread.cpp @@ -255,9 +255,7 @@ void SDRThread::threadMain() { dataOut->data.resize(n_read); } - for (int i = 0; i < n_read; i++) { - dataOut->data[i] = buf[i]; - } + memcpy(&dataOut->data[0], buf, n_read); double time_slice = (double) n_read / (double) sampleRate; seconds += time_slice;