From 8ce3065bce68671b77daa2c27ebd02394fe5e45b Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Tue, 23 Dec 2014 01:12:14 -0500 Subject: [PATCH] cleanup / refactor / profiled --- src/CubicSDR.h | 3 +-- src/audio/AudioThread.cpp | 3 +-- src/demod/DemodDefs.h | 30 +++++++-------------------- src/demod/DemodulatorPreThread.cpp | 14 ++++++------- src/demod/DemodulatorThread.cpp | 32 +++++++++++++---------------- src/demod/DemodulatorWorkerThread.h | 15 +++++++------- src/sdr/SDRPostThread.cpp | 2 +- src/sdr/SDRThread.cpp | 2 ++ src/sdr/SDRThread.h | 2 +- src/util/GLFont.cpp | 6 +++--- src/util/MouseTracker.h | 10 ++++----- src/util/Timer.cpp | 2 +- src/visual/WaterfallCanvas.cpp | 3 +-- 13 files changed, 50 insertions(+), 74 deletions(-) diff --git a/src/CubicSDR.h b/src/CubicSDR.h index 5128368..4790aef 100644 --- a/src/CubicSDR.h +++ b/src/CubicSDR.h @@ -20,8 +20,7 @@ class CubicSDR: public wxApp { public: CubicSDR() : - m_glContext(NULL), t_PostSDR(NULL), t_SDR(NULL), audioVisualQueue(NULL), threadCmdQueueSDR(NULL), iqVisualQueue(NULL), frequency( - DEFAULT_FREQ), sdrPostThread(NULL), iqPostDataQueue(NULL), sdrThread(NULL) { + m_glContext(NULL), frequency(DEFAULT_FREQ), sdrThread(NULL), sdrPostThread(NULL), threadCmdQueueSDR(NULL), iqVisualQueue(NULL), iqPostDataQueue(NULL), audioVisualQueue(NULL), t_SDR(NULL), t_PostSDR(NULL) { } diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 9095186..706ce1c 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -10,8 +10,7 @@ std::map AudioThread::deviceThread; #endif AudioThread::AudioThread(AudioThreadInputQueue *inputQueue, DemodulatorThreadCommandQueue* threadQueueNotify) : - inputQueue(inputQueue), terminated(false), audio_queue_ptr(0), underflow_count(0), threadQueueNotify(threadQueueNotify), gain(1.0), active( - false) { +inputQueue(inputQueue), audio_queue_ptr(0), underflow_count(0), terminated(false), active(false), gain(1.0), threadQueueNotify(threadQueueNotify) { #ifdef __APPLE__ boundThreads = new std::vector; #endif diff --git a/src/demod/DemodDefs.h b/src/demod/DemodDefs.h index 88a7d25..e6cf822 100644 --- a/src/demod/DemodDefs.h +++ b/src/demod/DemodDefs.h @@ -26,12 +26,12 @@ public: }; DemodulatorThreadCommand() : - cmd(DEMOD_THREAD_CMD_NULL), int_value(0), context(NULL) { + cmd(DEMOD_THREAD_CMD_NULL), context(NULL), int_value(0) { } DemodulatorThreadCommand(DemodulatorThreadCommandEnum cmd) : - cmd(cmd), int_value(0), context(NULL) { + cmd(cmd), context(NULL), int_value(0) { } @@ -66,13 +66,6 @@ public: } - DemodulatorThreadIQData(const DemodulatorThreadIQData& o) { - frequency = o.frequency; - bandwidth = o.bandwidth; - data = o.data; - refCount.store(o.refCount.load()); - } - void setRefCount(int rc) { refCount.store(rc); } @@ -95,24 +88,16 @@ private: class DemodulatorThreadPostIQData { public: - std::vector *data; + std::vector data; float audio_resample_ratio; msresamp_rrrf audio_resampler; float resample_ratio; msresamp_crcf resampler; - DemodulatorThreadPostIQData(): audio_resample_ratio(0), audio_resampler(NULL), resample_ratio(0), resampler(NULL), data(NULL) { + DemodulatorThreadPostIQData(): audio_resample_ratio(0), audio_resampler(NULL), resample_ratio(0), resampler(NULL) { } - DemodulatorThreadPostIQData(const DemodulatorThreadPostIQData &o) { - audio_resample_ratio = o.audio_resample_ratio; - audio_resampler = o.audio_resampler; - resample_ratio = o.resample_ratio; - resampler = o.resampler; - data = o.data; - } - ~DemodulatorThreadPostIQData() { } @@ -128,14 +113,13 @@ public: std::vector *data; DemodulatorThreadAudioData() : - sampleRate(0), frequency(0), channels(0), data(NULL) { + frequency(0), sampleRate(0), channels(0), data(NULL) { } DemodulatorThreadAudioData(unsigned int frequency, unsigned int sampleRate, std::vector *data) : - data(data), sampleRate(sampleRate), frequency(frequency), channels( - 1) { + frequency(frequency), sampleRate(sampleRate), channels(1), data(data) { } @@ -145,7 +129,7 @@ public: }; typedef ThreadQueue DemodulatorThreadInputQueue; -typedef ThreadQueue DemodulatorThreadPostInputQueue; +typedef ThreadQueue DemodulatorThreadPostInputQueue; typedef ThreadQueue DemodulatorThreadCommandQueue; typedef ThreadQueue DemodulatorThreadControlCommandQueue; diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index e0635e8..8e70537 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -184,17 +184,15 @@ void DemodulatorPreThread::threadMain() { out_buf = temp_buf; } - DemodulatorThreadPostIQData resamp; - resamp.data = new std::vector; -// resamp.data->resize(bufSize); - resamp.data->assign(in_buf,in_buf+bufSize); + DemodulatorThreadPostIQData *resamp = new DemodulatorThreadPostIQData; + resamp->data.assign(in_buf,in_buf+bufSize); // firfilt_crcf_execute_block(fir_filter, in_buf, bufSize, &((*resamp.data)[0])); - resamp.audio_resample_ratio = audio_resample_ratio; - resamp.audio_resampler = audio_resampler; - resamp.resample_ratio = resample_ratio; - resamp.resampler = resampler; + resamp->audio_resample_ratio = audio_resample_ratio; + resamp->audio_resampler = audio_resampler; + resamp->resample_ratio = resample_ratio; + resamp->resampler = resampler; postInputQueue->push(resamp); inp->decRefCount(); diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index b0f059d..e66ec78 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -7,7 +7,7 @@ #endif DemodulatorThread::DemodulatorThread(DemodulatorThreadPostInputQueue* pQueue, DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify) : - postInputQueue(pQueue), visOutQueue(NULL), terminated(false), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify), threadQueueControl(threadQueueControl), agc(NULL), squelch_enabled(false), squelch_level(0), squelch_tolerance(0) { + postInputQueue(pQueue), visOutQueue(NULL), audioInputQueue(NULL), agc(NULL), terminated(false), threadQueueNotify(threadQueueNotify), threadQueueControl(threadQueueControl), squelch_level(0), squelch_tolerance(0), squelch_enabled(false) { float kf = 0.5; // modulation factor fdem = freqdem_create(kf); @@ -36,40 +36,36 @@ void DemodulatorThread::threadMain() { std::cout << "Demodulator thread started.." << std::endl; while (!terminated) { - DemodulatorThreadPostIQData inp; + DemodulatorThreadPostIQData *inp; postInputQueue->pop(inp); - if (!inp.data) { - continue; - } - - int bufSize = inp.data->size(); + int bufSize = inp->data.size(); if (!bufSize) { - delete inp.data; + delete inp; continue; } if (resampler == NULL) { - resampler = inp.resampler; - audio_resampler = inp.audio_resampler; - } else if (resampler != inp.resampler) { + resampler = inp->resampler; + audio_resampler = inp->audio_resampler; + } else if (resampler != inp->resampler) { msresamp_crcf_destroy(resampler); msresamp_rrrf_destroy(audio_resampler); - resampler = inp.resampler; - audio_resampler = inp.audio_resampler; + resampler = inp->resampler; + audio_resampler = inp->audio_resampler; } - int out_size = ceil((float) (bufSize) * inp.resample_ratio); + int out_size = ceil((float) (bufSize) * inp->resample_ratio); liquid_float_complex resampled_data[out_size]; liquid_float_complex agc_data[out_size]; unsigned int num_written; - msresamp_crcf_execute(resampler, &((*inp.data)[0]), bufSize, resampled_data, &num_written); + msresamp_crcf_execute(resampler, &(inp->data[0]), bufSize, resampled_data, &num_written); agc_crcf_execute_block(agc, resampled_data, num_written, agc_data); - float audio_resample_ratio = inp.audio_resample_ratio; + float audio_resample_ratio = inp->audio_resample_ratio; float demod_output[num_written]; freqdem_demodulate_block(fdem, agc_data, num_written, demod_output); @@ -136,7 +132,7 @@ void DemodulatorThread::threadMain() { } } - delete inp.data; + delete inp; } if (resampler != NULL) { @@ -156,6 +152,6 @@ void DemodulatorThread::threadMain() { void DemodulatorThread::terminate() { terminated = true; - DemodulatorThreadPostIQData inp; // push dummy to nudge queue + DemodulatorThreadPostIQData *inp = new DemodulatorThreadPostIQData; // push dummy to nudge queue postInputQueue->push(inp); } diff --git a/src/demod/DemodulatorWorkerThread.h b/src/demod/DemodulatorWorkerThread.h index 950b5f1..8edcec2 100644 --- a/src/demod/DemodulatorWorkerThread.h +++ b/src/demod/DemodulatorWorkerThread.h @@ -22,17 +22,19 @@ public: }; DemodulatorWorkerThreadResult() : - cmd(DEMOD_WORKER_THREAD_RESULT_NULL), audioSampleRate(0), bandwidth(0), inputRate(0), fir_filter(NULL), resampler(NULL), resample_ratio( - 0), audio_resampler(NULL), audio_resample_ratio(0) { + cmd(DEMOD_WORKER_THREAD_RESULT_NULL), fir_filter(NULL), resampler(NULL), resample_ratio( + 0), audio_resampler(NULL), audio_resample_ratio(0), inputRate(0), bandwidth(0), audioSampleRate(0) { } DemodulatorWorkerThreadResult(DemodulatorThreadResultEnum cmd) : - cmd(cmd), audioSampleRate(0), bandwidth(0), inputRate(0), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), audio_resample_ratio( - 0) { + cmd(cmd), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), audio_resample_ratio( + 0), inputRate(0), bandwidth(0), audioSampleRate(0) { } + DemodulatorThreadResultEnum cmd; + firfilt_crcf fir_filter; msresamp_crcf resampler; float resample_ratio; @@ -43,7 +45,6 @@ public: unsigned int bandwidth; unsigned int audioSampleRate; - DemodulatorThreadResultEnum cmd; }; class DemodulatorWorkerThreadCommand { @@ -62,12 +63,12 @@ public: } + DemodulatorThreadCommandEnum cmd; + unsigned int frequency; unsigned int inputRate; unsigned int bandwidth; unsigned int audioSampleRate; - - DemodulatorThreadCommandEnum cmd; }; typedef ThreadQueue DemodulatorThreadWorkerCommandQueue; diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index bee87f9..6f2b84c 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -4,7 +4,7 @@ #include "CubicSDR.h" SDRPostThread::SDRPostThread() : - iqDataInQueue(NULL), iqDataOutQueue(NULL), iqVisualQueue(NULL), terminated(false), dcFilter(NULL), sample_rate(SRATE) { + sample_rate(SRATE), iqDataOutQueue(NULL), iqDataInQueue(NULL), iqVisualQueue(NULL), terminated(false), dcFilter(NULL) { } SDRPostThread::~SDRPostThread() { diff --git a/src/sdr/SDRThread.cpp b/src/sdr/SDRThread.cpp index 30f34a6..adc10c9 100644 --- a/src/sdr/SDRThread.cpp +++ b/src/sdr/SDRThread.cpp @@ -145,6 +145,8 @@ void SDRThread::threadMain() { freq_changed = true; new_freq = command.int_value; break; + default: + break; } } diff --git a/src/sdr/SDRThread.h b/src/sdr/SDRThread.h index 72b45b5..b813689 100644 --- a/src/sdr/SDRThread.h +++ b/src/sdr/SDRThread.h @@ -46,7 +46,7 @@ public: } SDRThreadIQData(unsigned int bandwidth, unsigned int frequency, std::vector *data) : - data(data), frequency(frequency), bandwidth(bandwidth) { + frequency(frequency), bandwidth(bandwidth), data(data) { } diff --git a/src/util/GLFont.cpp b/src/util/GLFont.cpp index 4035c30..4fa2bed 100644 --- a/src/util/GLFont.cpp +++ b/src/util/GLFont.cpp @@ -5,7 +5,7 @@ #include GLFontChar::GLFontChar() : - id(0), x(0), y(0), width(0), height(0), xadvance(0), xoffset(0), yoffset(0), index(0), aspect(1) { + id(0), x(0), y(0), width(0), height(0), xoffset(0), yoffset(0), xadvance(0), aspect(1), index(0) { } @@ -96,7 +96,7 @@ int GLFontChar::getIndex() { } GLFont::GLFont() : - numCharacters(0), imageHeight(0), imageWidth(0), base(0), lineHeight(0), texId(0), loaded(false) { + numCharacters(0), lineHeight(0), base(0), imageWidth(0), imageHeight(0), loaded(false), texId(0) { } @@ -289,7 +289,7 @@ void GLFont::loadFont(std::string fontFile) { unsigned int ofs = 0; for (char_i = characters.begin(); char_i != characters.end(); char_i++) { - int charId = (*char_i).first; +// int charId = (*char_i).first; GLFontChar *fchar = (*char_i).second; float faspect = fchar->getAspect(); diff --git a/src/util/MouseTracker.h b/src/util/MouseTracker.h index dad15a3..ed0870f 100644 --- a/src/util/MouseTracker.h +++ b/src/util/MouseTracker.h @@ -5,14 +5,12 @@ class MouseTracker { public: MouseTracker(wxWindow *target) : - target(target), mouseX(0), mouseY(0), lastMouseX(0), lastMouseY(0), originMouseX(0), originMouseY(0), deltaMouseX(0), deltaMouseY(0), isMouseDown( - false), vertDragLock(false), horizDragLock(false), isMouseInView(false) { + mouseX(0), mouseY(0), lastMouseX(0), lastMouseY(0), originMouseX(0), originMouseY(0), deltaMouseX(0), deltaMouseY(0), vertDragLock(false), horizDragLock(false), isMouseDown(false), isMouseInView(false), target(target) { } MouseTracker() : - target(NULL), mouseX(0), mouseY(0), lastMouseX(0), lastMouseY(0), originMouseX(0), originMouseY(0), deltaMouseX(0), deltaMouseY(0), isMouseDown( - false), vertDragLock(false), horizDragLock(false), isMouseInView(false) { + mouseX(0), mouseY(0), lastMouseX(0), lastMouseY(0), originMouseX(0), originMouseY(0), deltaMouseX(0), deltaMouseY(0), vertDragLock(false), horizDragLock(false), isMouseDown(false), isMouseInView(false), target(NULL) { } @@ -43,10 +41,10 @@ public: private: float mouseX, mouseY; float lastMouseX, lastMouseY; - float deltaMouseX, deltaMouseY; float originMouseX, originMouseY; + float deltaMouseX, deltaMouseY; - bool isMouseDown, isMouseInView; bool vertDragLock, horizDragLock; + bool isMouseDown, isMouseInView; wxWindow *target; }; diff --git a/src/util/Timer.cpp b/src/util/Timer.cpp index 4237d42..99ca67a 100644 --- a/src/util/Timer.cpp +++ b/src/util/Timer.cpp @@ -5,7 +5,7 @@ #include #endif -Timer::Timer(void) : time_elapsed(0), system_milliseconds(0), start_time(0), end_time(0), last_update(0), paused_time(0), offset(0), paused_state(false), num_updates(0), lock_state(0), lock_rate(0) +Timer::Timer(void) : time_elapsed(0), system_milliseconds(0), start_time(0), end_time(0), last_update(0), num_updates(0), paused_time(0), offset(0), paused_state(false), lock_state(0), lock_rate(0) { } diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index d9426b5..cc8794d 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -30,8 +30,7 @@ wxEND_EVENT_TABLE() WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) : wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, - wxFULL_REPAINT_ON_RESIZE), parent(parent), frameTimer(0), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), shiftDown( - false), altDown(false), ctrlDown(false), activeDemodulatorBandwidth(0), activeDemodulatorFrequency(0) { + wxFULL_REPAINT_ON_RESIZE), parent(parent), frameTimer(0), activeDemodulatorBandwidth(0), activeDemodulatorFrequency(0), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), shiftDown(false), altDown(false), ctrlDown(false) { int in_block_size = FFT_SIZE; int out_block_size = FFT_SIZE;