diff --git a/src/CubicSDRDefs.h b/src/CubicSDRDefs.h index 4829712..729d09f 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 2b3b76a..1fa8896 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -7,6 +7,20 @@ 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 +96,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..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] - 127; - } + memcpy(&dataOut->data[0], buf, n_read); double time_slice = (double) n_read / (double) sampleRate; seconds += time_slice; 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) {