From 45b223aed9f74a963b38580e61d0bb4702e8d278 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Fri, 26 Dec 2014 16:15:35 -0500 Subject: [PATCH] eliminate fp/int IQ data conversions --- src/AppFrame.cpp | 2 +- src/CubicSDR.cpp | 4 +-- src/CubicSDR.h | 4 +-- src/demod/DemodDefs.h | 2 +- src/demod/DemodulatorPreThread.cpp | 11 +++---- src/sdr/SDRPostThread.cpp | 50 +++++++++++++++--------------- src/sdr/SDRPostThread.h | 8 ++--- src/visual/SpectrumCanvas.cpp | 6 ++-- src/visual/SpectrumCanvas.h | 2 +- src/visual/WaterfallCanvas.cpp | 6 ++-- src/visual/WaterfallCanvas.h | 2 +- 11 files changed, 47 insertions(+), 50 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 50a088c..beb251f 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -96,7 +96,7 @@ void AppFrame::OnIdle(wxIdleEvent& event) { // std::this_thread::yield(); //#endif if (!wxGetApp().getIQVisualQueue()->empty()) { - SDRThreadIQData *iqData; + DemodulatorThreadIQData *iqData; wxGetApp().getIQVisualQueue()->pop(iqData); if (iqData && iqData->data.size()) { diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index fc78863..f2e6e8a 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -30,7 +30,7 @@ bool CubicSDR::OnInit() { sdrPostThread = new SDRPostThread(); iqPostDataQueue = new SDRThreadIQDataQueue; - iqVisualQueue = new SDRThreadIQDataQueue; + iqVisualQueue = new DemodulatorThreadInputQueue; iqVisualQueue->set_max_num_items(1); sdrThread->setIQDataOutQueue(iqPostDataQueue); @@ -115,7 +115,7 @@ DemodulatorThreadOutputQueue* CubicSDR::getAudioVisualQueue() { return audioVisualQueue; } -SDRThreadIQDataQueue* CubicSDR::getIQVisualQueue() { +DemodulatorThreadInputQueue* CubicSDR::getIQVisualQueue() { return iqVisualQueue; } diff --git a/src/CubicSDR.h b/src/CubicSDR.h index 4790aef..b84e23e 100644 --- a/src/CubicSDR.h +++ b/src/CubicSDR.h @@ -33,7 +33,7 @@ public: int getFrequency(); DemodulatorThreadOutputQueue* getAudioVisualQueue(); - SDRThreadIQDataQueue* getIQVisualQueue(); + DemodulatorThreadInputQueue* getIQVisualQueue(); DemodulatorMgr &getDemodMgr(); void bindDemodulator(DemodulatorInstance *demod); @@ -50,8 +50,8 @@ private: SDRPostThread *sdrPostThread; SDRThreadCommandQueue* threadCmdQueueSDR; - SDRThreadIQDataQueue* iqVisualQueue; SDRThreadIQDataQueue* iqPostDataQueue; + DemodulatorThreadInputQueue* iqVisualQueue; DemodulatorThreadOutputQueue* audioVisualQueue; std::thread *t_SDR; diff --git a/src/demod/DemodDefs.h b/src/demod/DemodDefs.h index 29d8d05..c8ddf22 100644 --- a/src/demod/DemodDefs.h +++ b/src/demod/DemodDefs.h @@ -55,7 +55,7 @@ class DemodulatorThreadIQData: public ReferenceCounter { public: unsigned int frequency; unsigned int bandwidth; - std::vector data; + std::vector data; DemodulatorThreadIQData() : frequency(0), bandwidth(0) { diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index f0e26d4..065141f 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -166,9 +166,9 @@ void DemodulatorPreThread::threadMain() { } // std::lock_guard < std::mutex > lock(inp->m_mutex); - std::vector *data = &inp->data; + std::vector *data = &inp->data; if (data->size()) { - int bufSize = data->size() / 2; + int bufSize = data->size(); if (in_buf_data.size() != bufSize) { if (in_buf_data.capacity() < bufSize) { @@ -179,15 +179,12 @@ void DemodulatorPreThread::threadMain() { out_buf_data.resize(bufSize); } + in_buf_data.assign(inp->data.begin(),inp->data.end()); + liquid_float_complex *in_buf = &in_buf_data[0]; liquid_float_complex *out_buf = &out_buf_data[0]; liquid_float_complex *temp_buf = NULL; - for (int i = 0; i < bufSize; i++) { - in_buf[i].real = (float) (*data)[i * 2] / 127.0f; - in_buf[i].imag = (float) (*data)[i * 2 + 1] / 127.0f; - } - if (shift_freq != 0) { if (shift_freq < 0) { nco_crcf_mix_block_up(nco_shift, in_buf, out_buf, bufSize); diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index d0e3b96..bb93b6d 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -27,10 +27,10 @@ void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) { void SDRPostThread::setIQDataInQueue(SDRThreadIQDataQueue* iqDataQueue) { iqDataInQueue = iqDataQueue; } -void SDRPostThread::setIQDataOutQueue(SDRThreadIQDataQueue* iqDataQueue) { +void SDRPostThread::setIQDataOutQueue(DemodulatorThreadInputQueue* iqDataQueue) { iqDataOutQueue = iqDataQueue; } -void SDRPostThread::setIQVisualQueue(SDRThreadIQDataQueue *iqVisQueue) { +void SDRPostThread::setIQVisualQueue(DemodulatorThreadInputQueue *iqVisQueue) { iqVisualQueue = iqVisQueue; } @@ -47,13 +47,12 @@ void SDRPostThread::threadMain() { dcFilter = iirfilt_crcf_create_dc_blocker(0.0005); - liquid_float_complex x, y; - std::cout << "SDR post-processing thread started.." << std::endl; std::deque buffers; std::deque::iterator buffers_i; - std::vector dataOut; + std::vector fpData; + std::vector dataOut; while (!terminated) { SDRThreadIQData *data_in; @@ -62,34 +61,35 @@ void SDRPostThread::threadMain() { // std::lock_guard < std::mutex > lock(data_in->m_mutex); if (data_in && data_in->data.size()) { - if (data_in->data.size() > dataOut.capacity()) { - dataOut.reserve(data_in->data.size()); + int dataSize = data_in->data.size()/2; + if (dataSize > fpData.capacity()) { + fpData.reserve(dataSize); + dataOut.reserve(dataSize); + } + if (dataSize != fpData.size()) { + fpData.resize(dataSize); + dataOut.resize(dataSize); } - dataOut.assign(data_in->data.begin(), data_in->data.end()); - - for (int i = 0, iMax = dataOut.size() / 2; i < iMax; i++) { - x.real = (float) dataOut[i * 2] / 127.0; - x.imag = (float) dataOut[i * 2 + 1] / 127.0; - - iirfilt_crcf_execute(dcFilter, x, &y); - - dataOut[i * 2] = (signed char) floor(y.real * 127.0); - dataOut[i * 2 + 1] = (signed char) floor(y.imag * 127.0); + 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; } + iirfilt_crcf_execute_block(dcFilter, &fpData[0], dataSize, &dataOut[0]); + if (iqDataOutQueue != NULL) { - SDRThreadIQData *visDataOut = new SDRThreadIQData; + DemodulatorThreadIQData *pipeDataOut = new DemodulatorThreadIQData; - visDataOut->frequency = data_in->frequency; - visDataOut->bandwidth = data_in->bandwidth; - visDataOut->data.assign(dataOut.begin(), dataOut.end()); - iqDataOutQueue.load()->push(visDataOut); + pipeDataOut->frequency = data_in->frequency; + pipeDataOut->bandwidth = data_in->bandwidth; + pipeDataOut->data.assign(dataOut.begin(), dataOut.end()); + iqDataOutQueue.load()->push(pipeDataOut); } if (iqVisualQueue != NULL && iqVisualQueue.load()->empty()) { - SDRThreadIQData *visualDataOut = new SDRThreadIQData; - visualDataOut->data.assign(dataOut.begin(), dataOut.begin() + (FFT_SIZE * 2)); + DemodulatorThreadIQData *visualDataOut = new DemodulatorThreadIQData; + visualDataOut->data.assign(dataOut.begin(), dataOut.begin() + FFT_SIZE); iqVisualQueue.load()->push(visualDataOut); } @@ -148,7 +148,7 @@ void SDRPostThread::threadMain() { demodDataOut->frequency = data_in->frequency; demodDataOut->bandwidth = data_in->bandwidth; demodDataOut->setRefCount(activeDemods); - demodDataOut->data.assign(dataOut.begin(), dataOut.begin() + dataOut.size()); + demodDataOut->data.assign(dataOut.begin(), dataOut.end()); std::vector::iterator i; for (i = demodulators.begin(); i != demodulators.end(); i++) { diff --git a/src/sdr/SDRPostThread.h b/src/sdr/SDRPostThread.h index 6846aa1..e70f082 100644 --- a/src/sdr/SDRPostThread.h +++ b/src/sdr/SDRPostThread.h @@ -12,8 +12,8 @@ public: void removeDemodulator(DemodulatorInstance *demod); void setIQDataInQueue(SDRThreadIQDataQueue* iqDataQueue); - void setIQDataOutQueue(SDRThreadIQDataQueue* iqDataQueue); - void setIQVisualQueue(SDRThreadIQDataQueue* iqVisQueue); + void setIQDataOutQueue(DemodulatorThreadInputQueue* iqDataQueue); + void setIQVisualQueue(DemodulatorThreadInputQueue* iqVisQueue); void threadMain(); void terminate(); @@ -21,9 +21,9 @@ public: protected: uint32_t sample_rate; - std::atomic iqDataOutQueue; std::atomic iqDataInQueue; - std::atomic iqVisualQueue; + std::atomic iqDataOutQueue; + std::atomic iqVisualQueue; std::vector demodulators; std::vector demodulators_add; diff --git a/src/visual/SpectrumCanvas.cpp b/src/visual/SpectrumCanvas.cpp index 1ac98ef..e9b9c27 100644 --- a/src/visual/SpectrumCanvas.cpp +++ b/src/visual/SpectrumCanvas.cpp @@ -73,7 +73,7 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { SwapBuffers(); } -void SpectrumCanvas::setData(std::vector *data) { +void SpectrumCanvas::setData(std::vector *data) { if (data && data->size()) { if (spectrum_points.size() < FFT_SIZE * 2) { @@ -81,8 +81,8 @@ void SpectrumCanvas::setData(std::vector *data) { } for (int i = 0; i < FFT_SIZE; i++) { - in[i][0] = (float) (*data)[i * 2] / 127.0f; - in[i][1] = (float) (*data)[i * 2 + 1] / 127.0f; + in[i][0] = (*data)[i].real; + in[i][1] = (*data)[i].imag; } fftw_execute(plan); diff --git a/src/visual/SpectrumCanvas.h b/src/visual/SpectrumCanvas.h index 5f96fd5..d02f4fe 100644 --- a/src/visual/SpectrumCanvas.h +++ b/src/visual/SpectrumCanvas.h @@ -17,7 +17,7 @@ public: SpectrumCanvas(wxWindow *parent, int *attribList = NULL); ~SpectrumCanvas(); - void setData(std::vector *data); + void setData(std::vector *data); private: void OnPaint(wxPaintEvent& event); diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 1b82be2..2d07282 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -206,7 +206,7 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) { } } -void WaterfallCanvas::setData(std::vector *data) { +void WaterfallCanvas::setData(std::vector *data) { if (data && data->size()) { if (spectrum_points.size() < FFT_SIZE * 2) { @@ -214,8 +214,8 @@ void WaterfallCanvas::setData(std::vector *data) { } for (int i = 0; i < FFT_SIZE; i++) { - in[i][0] = (float) (*data)[i * 2] / 127.0f; - in[i][1] = (float) (*data)[i * 2 + 1] / 127.0f; + in[i][0] = (*data)[i].real; + in[i][1] = (*data)[i].imag; } fftw_execute(plan); diff --git a/src/visual/WaterfallCanvas.h b/src/visual/WaterfallCanvas.h index 2600682..e320a73 100644 --- a/src/visual/WaterfallCanvas.h +++ b/src/visual/WaterfallCanvas.h @@ -21,7 +21,7 @@ public: WaterfallCanvas(wxWindow *parent, int *attribList = NULL); ~WaterfallCanvas(); - void setData(std::vector *data); + void setData(std::vector *data); int GetFrequencyAt(float x); private: