From 62288e485f77357ebeccd1b57faea7910445aee9 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sat, 2 Jan 2016 01:38:17 -0500 Subject: [PATCH] Improve peak hold usability; add 30 frame delay between resets; don't drag old data around --- src/process/SpectrumVisualProcessor.cpp | 70 ++++++++++++++----------- src/process/SpectrumVisualProcessor.h | 2 + src/visual/SpectrumCanvas.cpp | 1 + 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/src/process/SpectrumVisualProcessor.cpp b/src/process/SpectrumVisualProcessor.cpp index d7c7f36..6efd3da 100644 --- a/src/process/SpectrumVisualProcessor.cpp +++ b/src/process/SpectrumVisualProcessor.cpp @@ -22,6 +22,7 @@ SpectrumVisualProcessor::SpectrumVisualProcessor() : lastInputBandwidth(0), last newFFTSize.store(0); lastView = false; peakHold.store(false); + peakReset.store(false); } SpectrumVisualProcessor::~SpectrumVisualProcessor() { @@ -78,13 +79,12 @@ long SpectrumVisualProcessor::getBandwidth() { } void SpectrumVisualProcessor::setPeakHold(bool peakHold_in) { - fft_ceil_peak = fft_floor_maa; - fft_floor_peak = fft_ceil_maa; - - for (int i = 0, iMax = fft_result_peak.size(); i < iMax; i++) { - fft_result_peak[i] = fft_floor_maa; + if (peakHold.load() && peakHold_in) { + peakReset.store(PEAK_RESET_COUNT); + } else { + peakHold.store(peakHold_in); + peakReset.store(1); } - peakHold.store(peakHold_in); } bool SpectrumVisualProcessor::getPeakHold() { @@ -175,7 +175,32 @@ void SpectrumVisualProcessor::process() { iqData->busy_rw.lock(); busy_run.lock(); - bool doPeak = peakHold.load(); + bool doPeak = peakHold.load() && (peakReset.load() == 0); + + if (fft_result.size() != fftSizeInternal) { + if (fft_result.capacity() < fftSizeInternal) { + fft_result.reserve(fftSizeInternal); + fft_result_ma.reserve(fftSizeInternal); + fft_result_maa.reserve(fftSizeInternal); + fft_result_peak.reserve(fftSizeInternal); + } + fft_result.resize(fftSizeInternal); + fft_result_ma.resize(fftSizeInternal); + fft_result_maa.resize(fftSizeInternal); + fft_result_temp.resize(fftSizeInternal); + fft_result_peak.resize(fftSizeInternal); + } + + if (peakReset.load() != 0) { + peakReset--; + if (peakReset.load() == 0) { + for (int i = 0, iMax = fftSizeInternal; i < iMax; i++) { + fft_result_peak[i] = fft_floor_maa; + } + fft_ceil_peak = fft_floor_maa; + fft_floor_peak = fft_ceil_maa; + } + } std::vector *data = &iqData->data; @@ -227,18 +252,19 @@ void SpectrumVisualProcessor::process() { if (freqDiff > 0) { memmove(&fft_result_ma[0], &fft_result_ma[numShift], (fftSizeInternal-numShift) * sizeof(double)); memmove(&fft_result_maa[0], &fft_result_maa[numShift], (fftSizeInternal-numShift) * sizeof(double)); - memmove(&fft_result_peak[0], &fft_result_peak[numShift], (fftSizeInternal-numShift) * sizeof(double)); - memset(&fft_result_peak[fftSizeInternal-numShift], 0, numShift * sizeof(double)); +// memmove(&fft_result_peak[0], &fft_result_peak[numShift], (fftSizeInternal-numShift) * sizeof(double)); +// memset(&fft_result_peak[fftSizeInternal-numShift], 0, numShift * sizeof(double)); } else { memmove(&fft_result_ma[numShift], &fft_result_ma[0], (fftSizeInternal-numShift) * sizeof(double)); memmove(&fft_result_maa[numShift], &fft_result_maa[0], (fftSizeInternal-numShift) * sizeof(double)); - memmove(&fft_result_peak[numShift], &fft_result_peak[0], (fftSizeInternal-numShift) * sizeof(double)); - memset(&fft_result_peak[0], 0, numShift * sizeof(double)); +// memmove(&fft_result_peak[numShift], &fft_result_peak[0], (fftSizeInternal-numShift) * sizeof(double)); +// memset(&fft_result_peak[0], 0, numShift * sizeof(double)); } } } } } + peakReset.store(PEAK_RESET_COUNT); } if (shiftBuffer.size() != desired_input_size) { @@ -270,6 +296,7 @@ void SpectrumVisualProcessor::process() { lastBandwidth = resampleBw; lastInputBandwidth = iqData->sampleRate; newResampler = true; + peakReset.store(PEAK_RESET_COUNT); } @@ -362,20 +389,6 @@ void SpectrumVisualProcessor::process() { float fft_ceil = 0, fft_floor = 1; - if (fft_result.size() != fftSizeInternal) { - if (fft_result.capacity() < fftSizeInternal) { - fft_result.reserve(fftSizeInternal); - fft_result_ma.reserve(fftSizeInternal); - fft_result_maa.reserve(fftSizeInternal); - fft_result_peak.reserve(fftSizeInternal); - } - fft_result.resize(fftSizeInternal); - fft_result_ma.resize(fftSizeInternal); - fft_result_maa.resize(fftSizeInternal); - fft_result_temp.resize(fftSizeInternal); - fft_result_peak.resize(fftSizeInternal); - } - for (int i = 0, iMax = fftSizeInternal / 2; i < iMax; i++) { float a = fftwOutput[i][0]; float b = fftwOutput[i][1]; @@ -428,13 +441,6 @@ void SpectrumVisualProcessor::process() { } } } - if (newResampler) { - for (int i = 0, iMax = fftSizeInternal; i < iMax; i++) { - fft_result_peak[i] = fft_floor_maa; - } - fft_ceil_peak = fft_floor_maa; - fft_floor_peak = fft_ceil_maa; - } for (int i = 0, iMax = fftSizeInternal; i < iMax; i++) { if (fft_result_maa[i] != fft_result_maa[i]) fft_result_maa[i] = fft_result[i]; diff --git a/src/process/SpectrumVisualProcessor.h b/src/process/SpectrumVisualProcessor.h index 00e92d7..953ad7f 100644 --- a/src/process/SpectrumVisualProcessor.h +++ b/src/process/SpectrumVisualProcessor.h @@ -6,6 +6,7 @@ #include #define SPECTRUM_VZM 2 +#define PEAK_RESET_COUNT 30 class SpectrumVisualData : public ReferenceCounter { public: @@ -88,6 +89,7 @@ private: std::atomic_int desiredInputSize; std::mutex busy_run; std::atomic_bool hideDC, peakHold; + std::atomic_int peakReset; std::atomic scaleFactor; std::atomic_bool fftSizeChanged; }; diff --git a/src/visual/SpectrumCanvas.cpp b/src/visual/SpectrumCanvas.cpp index 6ae1d4a..27787a5 100644 --- a/src/visual/SpectrumCanvas.cpp +++ b/src/visual/SpectrumCanvas.cpp @@ -260,6 +260,7 @@ void SpectrumCanvas::OnMouseRightReleased(wxMouseEvent& event) { mouseTracker.setHorizDragLock(false); if (!mouseTracker.getOriginDeltaMouseY()) { resetScaleFactor = true; + wxGetApp().getSpectrumProcessor()->setPeakHold(wxGetApp().getSpectrumProcessor()->getPeakHold()); } mouseTracker.OnMouseRightReleased(event); }