From 576a77e09544f105d3dc588f4866b355aa8422d5 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 24 Dec 2014 01:28:33 -0500 Subject: [PATCH] Update remaining buffers, cleanup --- src/audio/AudioThread.cpp | 21 +++++--- src/audio/AudioThread.h | 5 +- src/demod/DemodDefs.h | 83 +++++++++++++---------------- src/demod/DemodulatorInstance.cpp | 9 ++-- src/demod/DemodulatorInstance.h | 9 +--- src/demod/DemodulatorPreThread.cpp | 40 +++++++++++--- src/demod/DemodulatorPreThread.h | 1 - src/demod/DemodulatorThread.cpp | 50 +++++++++++++---- src/demod/DemodulatorThread.h | 6 +-- src/demod/DemodulatorWorkerThread.h | 8 +-- src/sdr/SDRPostThread.cpp | 16 +++--- src/sdr/SDRThread.cpp | 8 +-- src/visual/WaterfallCanvas.cpp | 13 +++-- 13 files changed, 159 insertions(+), 110 deletions(-) diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 9a4cbf2..de94c66 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -10,7 +10,8 @@ std::map AudioThread::deviceThread; #endif AudioThread::AudioThread(AudioThreadInputQueue *inputQueue, DemodulatorThreadCommandQueue* threadQueueNotify) : -currentInput(NULL), inputQueue(inputQueue), audio_queue_ptr(0), underflow_count(0), terminated(false), active(false), gain(1.0), threadQueueNotify(threadQueueNotify) { + currentInput(NULL), 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 @@ -72,11 +73,13 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu srcmix->audio_queue_ptr = 0; continue; } - + + std::lock_guard < std::mutex > lock(srcmix->currentInput->m_mutex); + if (srcmix->currentInput->channels == 0 || !srcmix->currentInput->data.size()) { if (!srcmix->inputQueue->empty()) { if (srcmix->currentInput) { - delete srcmix->currentInput; + srcmix->currentInput->decRefCount(); srcmix->currentInput = NULL; } if (srcmix->terminated) { @@ -92,7 +95,7 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu for (int i = 0; i < nBufferFrames; i++) { if (srcmix->audio_queue_ptr >= srcmix->currentInput->data.size()) { if (srcmix->currentInput) { - delete srcmix->currentInput; + srcmix->currentInput->decRefCount(); srcmix->currentInput = NULL; } if (srcmix->terminated) { @@ -112,7 +115,7 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu for (int i = 0, iMax = src->currentInput->channels * nBufferFrames; i < iMax; i++) { if (srcmix->audio_queue_ptr >= srcmix->currentInput->data.size()) { if (srcmix->currentInput) { - delete srcmix->currentInput; + srcmix->currentInput->decRefCount(); srcmix->currentInput = NULL; } if (srcmix->terminated) { @@ -143,17 +146,19 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu if (status) { std::cout << "Audio buffer underflow.." << (src->underflow_count++) << std::endl; } - + if (!src->currentInput) { src->inputQueue->pop(src->currentInput); src->audio_queue_ptr = 0; return 0; } + std::lock_guard < std::mutex > lock(src->currentInput->m_mutex); + if (src->currentInput->channels == 0 || !src->currentInput->data.size()) { if (!src->inputQueue->empty()) { if (src->currentInput) { - delete src->currentInput; + src->currentInput->decRefCount(); src->currentInput = NULL; } if (src->terminated) { @@ -169,7 +174,7 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu for (int i = 0; i < nBufferFrames; i++) { if (src->audio_queue_ptr >= src->currentInput->data.size()) { if (src->currentInput) { - delete src->currentInput; + src->currentInput->decRefCount(); src->currentInput = NULL; } if (src->terminated) { diff --git a/src/audio/AudioThread.h b/src/audio/AudioThread.h index 444e9c0..da411b3 100644 --- a/src/audio/AudioThread.h +++ b/src/audio/AudioThread.h @@ -18,14 +18,15 @@ #include "RtAudio.h" #include "DemodDefs.h" -class AudioThreadInput: public ReferenceCounter { +class AudioThreadInput: public ReferenceCounter { public: int frequency; int sampleRate; int channels; std::vector data; - AudioThreadInput(): frequency(0), sampleRate(0), channels(0) { + AudioThreadInput() : + frequency(0), sampleRate(0), channels(0) { } diff --git a/src/demod/DemodDefs.h b/src/demod/DemodDefs.h index 634268c..29d8d05 100644 --- a/src/demod/DemodDefs.h +++ b/src/demod/DemodDefs.h @@ -8,10 +8,7 @@ #include enum DemodulatorType { - DEMOD_TYPE_NULL, - DEMOD_TYPE_AM, - DEMOD_TYPE_FM, - DEMOD_TYPE_LSB, DEMOD_TYPE_USB + DEMOD_TYPE_NULL, DEMOD_TYPE_AM, DEMOD_TYPE_FM, DEMOD_TYPE_LSB, DEMOD_TYPE_USB }; class DemodulatorThread; @@ -34,19 +31,17 @@ public: DemodulatorThreadCommand(DemodulatorThreadCommandEnum cmd) : cmd(cmd), context(NULL), int_value(0) { - } + } - DemodulatorThreadCommandEnum cmd; - void *context; - int int_value; + DemodulatorThreadCommandEnum cmd; + void *context; + int int_value; }; class DemodulatorThreadControlCommand { public: enum DemodulatorThreadControlCommandEnum { - DEMOD_THREAD_CMD_CTL_NULL, - DEMOD_THREAD_CMD_CTL_SQUELCH_AUTO, - DEMOD_THREAD_CMD_CTL_SQUELCH_OFF + DEMOD_THREAD_CMD_CTL_NULL, DEMOD_THREAD_CMD_CTL_SQUELCH_AUTO, DEMOD_THREAD_CMD_CTL_SQUELCH_OFF }; DemodulatorThreadControlCommand() : @@ -56,62 +51,61 @@ public: DemodulatorThreadControlCommandEnum cmd; }; -class DemodulatorThreadIQData : public ReferenceCounter { +class DemodulatorThreadIQData: public ReferenceCounter { public: - unsigned int frequency; - unsigned int bandwidth; - std::vector data; + unsigned int frequency; + unsigned int bandwidth; + std::vector data; - DemodulatorThreadIQData() : - frequency(0), bandwidth(0) { + DemodulatorThreadIQData() : + frequency(0), bandwidth(0) { - } + } - ~DemodulatorThreadIQData() { + ~DemodulatorThreadIQData() { - } + } }; -class DemodulatorThreadPostIQData : public ReferenceCounter { +class DemodulatorThreadPostIQData: public ReferenceCounter { public: - std::vector data; - float audio_resample_ratio; - msresamp_rrrf audio_resampler; + 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) { + DemodulatorThreadPostIQData() : + audio_resample_ratio(0), audio_resampler(NULL), resample_ratio(0), resampler(NULL) { - } + } - ~DemodulatorThreadPostIQData() { + ~DemodulatorThreadPostIQData() { - } + } }; - -class DemodulatorThreadAudioData : public ReferenceCounter { +class DemodulatorThreadAudioData: public ReferenceCounter { public: - unsigned int frequency; - unsigned int sampleRate; - unsigned char channels; + unsigned int frequency; + unsigned int sampleRate; + unsigned char channels; - std::vector *data; + std::vector *data; - DemodulatorThreadAudioData() : - frequency(0), sampleRate(0), channels(0), data(NULL) { + DemodulatorThreadAudioData() : + frequency(0), sampleRate(0), channels(0), data(NULL) { - } + } - DemodulatorThreadAudioData(unsigned int frequency, unsigned int sampleRate, - std::vector *data) : - frequency(frequency), sampleRate(sampleRate), channels(1), data(data) { + DemodulatorThreadAudioData(unsigned int frequency, unsigned int sampleRate, std::vector *data) : + frequency(frequency), sampleRate(sampleRate), channels(1), data(data) { - } + } - ~DemodulatorThreadAudioData() { + ~DemodulatorThreadAudioData() { - } + } }; typedef ThreadQueue DemodulatorThreadInputQueue; @@ -119,7 +113,6 @@ typedef ThreadQueue DemodulatorThreadPostInputQue typedef ThreadQueue DemodulatorThreadCommandQueue; typedef ThreadQueue DemodulatorThreadControlCommandQueue; - class DemodulatorThreadParameters { public: unsigned int frequency; @@ -131,7 +124,7 @@ public: DemodulatorThreadParameters() : frequency(0), inputRate(SRATE), bandwidth(200000), audioSampleRate( - AUDIO_FREQUENCY), demodType(DEMOD_TYPE_FM) { + AUDIO_FREQUENCY), demodType(DEMOD_TYPE_FM) { } diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 9d46565..ab26849 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -77,12 +77,12 @@ DemodulatorThreadParameters &DemodulatorInstance::getParams() { } void DemodulatorInstance::terminate() { - std::cout << "Terminating demodulator preprocessor thread.." << std::endl; - demodulatorPreThread->terminate(); - std::cout << "Terminating demodulator thread.." << std::endl; - demodulatorThread->terminate(); std::cout << "Terminating demodulator audio thread.." << std::endl; audioThread->terminate(); + std::cout << "Terminating demodulator thread.." << std::endl; + demodulatorThread->terminate(); + std::cout << "Terminating demodulator preprocessor thread.." << std::endl; + demodulatorPreThread->terminate(); } std::string DemodulatorInstance::getLabel() { @@ -146,7 +146,6 @@ void DemodulatorInstance::setActive(bool state) { audioThread->setActive(state); } - void DemodulatorInstance::squelchAuto() { DemodulatorThreadControlCommand command; command.cmd = DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_AUTO; diff --git a/src/demod/DemodulatorInstance.h b/src/demod/DemodulatorInstance.h index ccd14be..2853d6c 100644 --- a/src/demod/DemodulatorInstance.h +++ b/src/demod/DemodulatorInstance.h @@ -49,16 +49,11 @@ public: bool isActive(); void setActive(bool state); - void squelchAuto(); - bool isSquelchEnabled(); + void squelchAuto();bool isSquelchEnabled(); void setSquelchEnabled(bool state); private: - std::atomic label; - bool terminated; - bool demodTerminated; - bool audioTerminated; - bool preDemodTerminated; + std::atomic label;bool terminated;bool demodTerminated;bool audioTerminated;bool preDemodTerminated; std::atomic active; std::atomic squelch; }; diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index 20e84e1..4e5691d 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -10,7 +10,8 @@ DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* pQueueIn, DemodulatorThreadPostInputQueue* pQueueOut, DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify) : inputQueue(pQueueIn), postInputQueue(pQueueOut), terminated(false), initialized(false), audio_resampler(NULL), resample_ratio(1), audio_resample_ratio( - 1), resampler(NULL), commandQueue(NULL), fir_filter(NULL), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify), threadQueueControl(threadQueueControl) { + 1), resampler(NULL), commandQueue(NULL), fir_filter(NULL), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify), threadQueueControl( + threadQueueControl) { float kf = 0.5; // modulation factor fdem = freqdem_create(kf); @@ -90,7 +91,7 @@ void DemodulatorPreThread::threadMain() { #ifdef __APPLE__ pthread_t tID = pthread_self(); // ID of this thread int priority = sched_get_priority_max( SCHED_FIFO )-1; - sched_param prio = { priority }; // scheduling priority of thread + sched_param prio = {priority}; // scheduling priority of thread pthread_setschedparam(tID, SCHED_FIFO, &prio); #endif @@ -99,6 +100,10 @@ void DemodulatorPreThread::threadMain() { } std::cout << "Demodulator preprocessor thread started.." << std::endl; + + std::deque buffers; + std::deque::iterator buffers_i; + while (!terminated) { DemodulatorThreadIQData *inp; inputQueue->pop(inp); @@ -157,7 +162,7 @@ void DemodulatorPreThread::threadMain() { continue; } - std::lock_guard < std::mutex > lock(inp->m_mutex); +// std::lock_guard < std::mutex > lock(inp->m_mutex); std::vector *data = &inp->data; if (data->size()) { int bufSize = data->size() / 2; @@ -174,8 +179,6 @@ void DemodulatorPreThread::threadMain() { in_buf[i].imag = (float) (*data)[i * 2 + 1] / 127.0f; } - inp->decRefCount(); - if (shift_freq != 0) { if (shift_freq < 0) { nco_crcf_mix_block_up(nco_shift, in_buf, out_buf, bufSize); @@ -187,8 +190,22 @@ void DemodulatorPreThread::threadMain() { out_buf = temp_buf; } - DemodulatorThreadPostIQData *resamp = new DemodulatorThreadPostIQData; - resamp->data.assign(in_buf,in_buf+bufSize); + DemodulatorThreadPostIQData *resamp = NULL; + + for (buffers_i = buffers.begin(); buffers_i != buffers.end(); buffers_i++) { + if ((*buffers_i)->getRefCount() <= 0) { + resamp = (*buffers_i); + break; + } + } + + if (resamp == NULL) { + resamp = new DemodulatorThreadPostIQData; + buffers.push_back(resamp); + } + + resamp->setRefCount(1); + resamp->data.assign(in_buf, in_buf + bufSize); // firfilt_crcf_execute_block(fir_filter, in_buf, bufSize, &((*resamp.data)[0])); @@ -198,6 +215,8 @@ void DemodulatorPreThread::threadMain() { resamp->resampler = resampler; postInputQueue->push(resamp); + + inp->decRefCount(); } else { inp->decRefCount(); } @@ -230,6 +249,13 @@ void DemodulatorPreThread::threadMain() { } } + while (!buffers.empty()) { + DemodulatorThreadPostIQData *iqDataDel = buffers.front(); + buffers.pop_front(); + std::lock_guard < std::mutex > lock(iqDataDel->m_mutex); + delete iqDataDel; + } + std::cout << "Demodulator preprocessor thread done." << std::endl; DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED); tCmd.context = this; diff --git a/src/demod/DemodulatorPreThread.h b/src/demod/DemodulatorPreThread.h index 0295984..95304da 100644 --- a/src/demod/DemodulatorPreThread.h +++ b/src/demod/DemodulatorPreThread.h @@ -32,7 +32,6 @@ public: threadQueueControl = tQueue; } - DemodulatorThreadParameters &getParams() { return params; } diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 20826fd..925af72 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -6,8 +6,10 @@ #include #endif -DemodulatorThread::DemodulatorThread(DemodulatorThreadPostInputQueue* pQueue, DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify) : - postInputQueue(pQueue), visOutQueue(NULL), audioInputQueue(NULL), agc(NULL), terminated(false), threadQueueNotify(threadQueueNotify), threadQueueControl(threadQueueControl), squelch_level(0), squelch_tolerance(0), squelch_enabled(false) { +DemodulatorThread::DemodulatorThread(DemodulatorThreadPostInputQueue* pQueue, DemodulatorThreadControlCommandQueue *threadQueueControl, + DemodulatorThreadCommandQueue* threadQueueNotify) : + 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); @@ -35,14 +37,19 @@ void DemodulatorThread::threadMain() { agc_crcf_set_bandwidth(agc, 1e-3f); std::cout << "Demodulator thread started.." << std::endl; + + std::deque buffers; + std::deque::iterator buffers_i; + while (!terminated) { DemodulatorThreadPostIQData *inp; postInputQueue->pop(inp); + std::lock_guard < std::mutex > lock(inp->m_mutex); int bufSize = inp->data.size(); if (!bufSize) { - delete inp; + inp->decRefCount(); continue; } @@ -76,26 +83,40 @@ void DemodulatorThread::threadMain() { unsigned int num_audio_written; msresamp_rrrf_execute(audio_resampler, demod_output, num_written, resampled_audio_output, &num_audio_written); - AudioThreadInput *ati = new AudioThreadInput; - ati->channels = 1; - ati->data.assign(resampled_audio_output,resampled_audio_output+num_audio_written); - if (audioInputQueue != NULL) { if (!squelch_enabled || ((agc_crcf_get_signal_level(agc)) >= 0.1)) { + AudioThreadInput *ati = NULL; + + for (buffers_i = buffers.begin(); buffers_i != buffers.end(); buffers_i++) { + if ((*buffers_i)->getRefCount() <= 0) { + ati = (*buffers_i); + break; + } + } + + if (ati == NULL) { + ati = new AudioThreadInput; + buffers.push_back(ati); + } + + ati->setRefCount(1); + ati->channels = 1; + ati->data.assign(resampled_audio_output, resampled_audio_output + num_audio_written); + audioInputQueue->push(ati); } } if (visOutQueue != NULL && visOutQueue->empty()) { AudioThreadInput *ati_vis = new AudioThreadInput; - ati_vis->channels = ati->channels; + ati_vis->channels = 1; int num_vis = DEMOD_VIS_SIZE; if (num_audio_written > num_written) { if (num_vis > num_audio_written) { num_vis = num_audio_written; } - ati_vis->data.assign(ati->data.begin(), ati->data.begin()+num_vis); + ati_vis->data.assign(resampled_audio_output, resampled_audio_output + num_vis); } else { if (num_vis > num_written) { num_vis = num_written; @@ -115,7 +136,7 @@ void DemodulatorThread::threadMain() { switch (command.cmd) { case DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_AUTO: squelch_level = agc_crcf_get_signal_level(agc); - squelch_tolerance = agc_crcf_get_signal_level(agc)/2.0; + squelch_tolerance = agc_crcf_get_signal_level(agc) / 2.0; squelch_enabled = true; break; case DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_OFF: @@ -129,7 +150,7 @@ void DemodulatorThread::threadMain() { } } - delete inp; + inp->decRefCount(); } if (resampler != NULL) { @@ -141,6 +162,13 @@ void DemodulatorThread::threadMain() { agc_crcf_destroy(agc); + while (!buffers.empty()) { + AudioThreadInput *audioDataDel = buffers.front(); + buffers.pop_front(); + std::lock_guard < std::mutex > lock(audioDataDel->m_mutex); + delete audioDataDel; + } + std::cout << "Demodulator thread done." << std::endl; DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED); tCmd.context = this; diff --git a/src/demod/DemodulatorThread.h b/src/demod/DemodulatorThread.h index 925580d..3fb4bf6 100644 --- a/src/demod/DemodulatorThread.h +++ b/src/demod/DemodulatorThread.h @@ -13,7 +13,8 @@ typedef ThreadQueue DemodulatorThreadOutputQueue; class DemodulatorThread { public: - DemodulatorThread(DemodulatorThreadPostInputQueue* pQueueIn, DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify); + DemodulatorThread(DemodulatorThreadPostInputQueue* pQueueIn, DemodulatorThreadControlCommandQueue *threadQueueControl, + DemodulatorThreadCommandQueue* threadQueueNotify); ~DemodulatorThread(); #ifdef __APPLE__ @@ -53,6 +54,5 @@ protected: DemodulatorThreadCommandQueue* threadQueueNotify; DemodulatorThreadControlCommandQueue *threadQueueControl; float squelch_level; - float squelch_tolerance; - bool squelch_enabled; + float squelch_tolerance;bool squelch_enabled; }; diff --git a/src/demod/DemodulatorWorkerThread.h b/src/demod/DemodulatorWorkerThread.h index 8edcec2..8db4c5a 100644 --- a/src/demod/DemodulatorWorkerThread.h +++ b/src/demod/DemodulatorWorkerThread.h @@ -22,14 +22,14 @@ public: }; DemodulatorWorkerThreadResult() : - 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) { + 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), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), audio_resample_ratio( - 0), inputRate(0), bandwidth(0), audioSampleRate(0) { + cmd(cmd), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), audio_resample_ratio(0), inputRate(0), bandwidth( + 0), audioSampleRate(0) { } diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index a3aa4ce..b80c5da 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -41,7 +41,7 @@ void SDRPostThread::threadMain() { #ifdef __APPLE__ pthread_t tID = pthread_self(); // ID of this thread int priority = sched_get_priority_max( SCHED_FIFO) - 1; - sched_param prio = { priority }; // scheduling priority of thread + sched_param prio = {priority}; // scheduling priority of thread pthread_setschedparam(tID, SCHED_FIFO, &prio); #endif @@ -123,22 +123,22 @@ void SDRPostThread::threadMain() { } if (demodulators.size()) { - + DemodulatorThreadIQData *demodDataOut = NULL; - + for (buffers_i = buffers.begin(); buffers_i != buffers.end(); buffers_i++) { if ((*buffers_i)->getRefCount() <= 0) { demodDataOut = (*buffers_i); break; } } - + if (demodDataOut == NULL) { demodDataOut = new DemodulatorThreadIQData; buffers.push_back(demodDataOut); } - - std::lock_guard < std::mutex > lock(demodDataOut->m_mutex); + +// std::lock_guard < std::mutex > lock(demodDataOut->m_mutex); demodDataOut->frequency = data_in->frequency; demodDataOut->bandwidth = data_in->bandwidth; demodDataOut->setRefCount(activeDemods); @@ -183,8 +183,8 @@ void SDRPostThread::threadMain() { while (!buffers.empty()) { DemodulatorThreadIQData *demodDataDel = buffers.front(); buffers.pop_front(); - std::lock_guard < std::mutex > lock(demodDataDel->m_mutex); - delete demodDataDel; +// std::lock_guard < std::mutex > lock(demodDataDel->m_mutex); +// delete demodDataDel; } std::cout << "SDR post-processing thread done." << std::endl; diff --git a/src/sdr/SDRThread.cpp b/src/sdr/SDRThread.cpp index 0d88944..b52f960 100644 --- a/src/sdr/SDRThread.cpp +++ b/src/sdr/SDRThread.cpp @@ -92,7 +92,7 @@ void SDRThread::threadMain() { #ifdef __APPLE__ pthread_t tID = pthread_self(); // ID of this thread int priority = sched_get_priority_max( SCHED_FIFO) - 1; - sched_param prio = { priority }; // scheduling priority of thread + sched_param prio = {priority}; // scheduling priority of thread pthread_setschedparam(tID, SCHED_FIFO, &prio); #endif @@ -176,7 +176,7 @@ void SDRThread::threadMain() { buffers.push_back(dataOut); } - std::lock_guard < std::mutex > lock(dataOut->m_mutex); +// std::lock_guard < std::mutex > lock(dataOut->m_mutex); dataOut->setRefCount(1); dataOut->frequency = frequency; dataOut->bandwidth = bandwidth; @@ -200,8 +200,8 @@ void SDRThread::threadMain() { while (!buffers.empty()) { SDRThreadIQData *iqDataDel = buffers.front(); buffers.pop_front(); - std::lock_guard < std::mutex > lock(iqDataDel->m_mutex); - delete iqDataDel; +// std::lock_guard < std::mutex > lock(iqDataDel->m_mutex); +// delete iqDataDel; } std::cout << "SDR thread done." << std::endl; diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 685cf3c..1b82be2 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -30,7 +30,8 @@ wxEND_EVENT_TABLE() WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) : wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, - 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) { + 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; @@ -76,7 +77,8 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { DemodulatorInstance *activeDemodulator = wxGetApp().getDemodMgr().getActiveDemodulator(); DemodulatorInstance *lastActiveDemodulator = wxGetApp().getDemodMgr().getLastActiveDemodulator(); - bool isNew = shiftDown || (wxGetApp().getDemodMgr().getLastActiveDemodulator() && !wxGetApp().getDemodMgr().getLastActiveDemodulator()->isActive()); + bool isNew = shiftDown + || (wxGetApp().getDemodMgr().getLastActiveDemodulator() && !wxGetApp().getDemodMgr().getLastActiveDemodulator()->isActive()); if (mTracker.mouseInView()) { if (nextDragState == WF_DRAG_RANGE) { @@ -163,7 +165,7 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) { case WXK_RIGHT: freq = wxGetApp().getFrequency(); if (shiftDown) { - freq += SRATE*10; + freq += SRATE * 10; } else { freq += SRATE / 2; } @@ -173,7 +175,7 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) { case WXK_LEFT: freq = wxGetApp().getFrequency(); if (shiftDown) { - freq -= SRATE*10; + freq -= SRATE * 10; } else { freq -= SRATE / 2; } @@ -438,7 +440,8 @@ void WaterfallCanvas::mouseReleased(wxMouseEvent& event) { altDown = event.AltDown(); ctrlDown = event.ControlDown(); - bool isNew = shiftDown || (wxGetApp().getDemodMgr().getLastActiveDemodulator() && !wxGetApp().getDemodMgr().getLastActiveDemodulator()->isActive()); + bool isNew = shiftDown + || (wxGetApp().getDemodMgr().getLastActiveDemodulator() && !wxGetApp().getDemodMgr().getLastActiveDemodulator()->isActive()); mTracker.setVertDragLock(false); mTracker.setHorizDragLock(false);