diff --git a/sdrbase/dsp/spectrumvis.cpp b/sdrbase/dsp/spectrumvis.cpp index 61950dd1a..719a20af5 100644 --- a/sdrbase/dsp/spectrumvis.cpp +++ b/sdrbase/dsp/spectrumvis.cpp @@ -58,6 +58,7 @@ SpectrumVis::SpectrumVis(Real scalef) : m_needMoreSamples(false), m_scalef(scalef), m_glSpectrum(nullptr), + m_specMax(0.0f), m_centerFrequency(0), m_sampleRate(48000), m_ofs(0), @@ -331,12 +332,15 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV if (m_settings.m_averagingMode == GLSpectrumSettings::AvgModeNone) { + m_specMax = 0.0f; + if ( positiveOnly ) { for (std::size_t i = 0; i < halfSize; i++) { c = fftOut[i]; v = c.real() * c.real() + c.imag() * c.imag(); + m_specMax = v > m_specMax ? v : m_specMax; v = m_settings.m_linear ? v/m_powFFTDiv : m_mult * log2f(v) + m_ofs; m_powerSpectrum[i * 2] = v; m_powerSpectrum[i * 2 + 1] = v; @@ -348,11 +352,13 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV { c = fftOut[i + halfSize]; v = c.real() * c.real() + c.imag() * c.imag(); + m_specMax = v > m_specMax ? v : m_specMax; v = m_settings.m_linear ? v/m_powFFTDiv : m_mult * log2f(v) + m_ofs; m_powerSpectrum[i] = v; c = fftOut[i]; v = c.real() * c.real() + c.imag() * c.imag(); + m_specMax = v > m_specMax ? v : m_specMax; v = m_settings.m_linear ? v/m_powFFTDiv : m_mult * log2f(v) + m_ofs; m_powerSpectrum[i + halfSize] = v; } @@ -379,6 +385,8 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV } else if (m_settings.m_averagingMode == GLSpectrumSettings::AvgModeMoving) { + m_specMax = 0.0f; + if ( positiveOnly ) { for (std::size_t i = 0; i < halfSize; i++) @@ -386,6 +394,7 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV c = fftOut[i]; v = c.real() * c.real() + c.imag() * c.imag(); v = m_movingAverage.storeAndGetAvg(v, i); + m_specMax = v > m_specMax ? v : m_specMax; v = m_settings.m_linear ? v/m_powFFTDiv : m_mult * log2f(v) + m_ofs; m_powerSpectrum[i * 2] = v; m_powerSpectrum[i * 2 + 1] = v; @@ -398,12 +407,14 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV c = fftOut[i + halfSize]; v = c.real() * c.real() + c.imag() * c.imag(); v = m_movingAverage.storeAndGetAvg(v, i+halfSize); + m_specMax = v > m_specMax ? v : m_specMax; v = m_settings.m_linear ? v/m_powFFTDiv : m_mult * log2f(v) + m_ofs; m_powerSpectrum[i] = v; c = fftOut[i]; v = c.real() * c.real() + c.imag() * c.imag(); v = m_movingAverage.storeAndGetAvg(v, i); + m_specMax = v > m_specMax ? v : m_specMax; v = m_settings.m_linear ? v/m_powFFTDiv : m_mult * log2f(v) + m_ofs; m_powerSpectrum[i + halfSize] = v; } @@ -433,6 +444,7 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV else if (m_settings.m_averagingMode == GLSpectrumSettings::AvgModeFixed) { double avg; + Real specMax = 0.0f; if ( positiveOnly ) { @@ -441,8 +453,10 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV c = fftOut[i]; v = c.real() * c.real() + c.imag() * c.imag(); + // result available if (m_fixedAverage.storeAndGetAvg(avg, v, i)) { + specMax = avg > specMax ? avg : specMax; avg = m_settings.m_linear ? avg/m_powFFTDiv : m_mult * log2f(avg) + m_ofs; m_powerSpectrum[i * 2] = avg; m_powerSpectrum[i * 2 + 1] = avg; @@ -459,6 +473,7 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV // result available if (m_fixedAverage.storeAndGetAvg(avg, v, i+halfSize)) { + specMax = avg > specMax ? avg : specMax; avg = m_settings.m_linear ? avg/m_powFFTDiv : m_mult * log2f(avg) + m_ofs; m_powerSpectrum[i] = avg; } @@ -469,6 +484,7 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV // result available if (m_fixedAverage.storeAndGetAvg(avg, v, i)) { + specMax = avg > specMax ? avg : specMax; avg = m_settings.m_linear ? avg/m_powFFTDiv : m_mult * log2f(avg) + m_ofs; m_powerSpectrum[i + halfSize] = avg; } @@ -478,6 +494,8 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV // result available if (m_fixedAverage.nextAverage()) { + m_specMax = specMax; + // send new data to visualisation if (m_glSpectrum) { m_glSpectrum->newSpectrum(m_powerSpectrum, m_settings.m_fftSize); @@ -501,6 +519,7 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV else if (m_settings.m_averagingMode == GLSpectrumSettings::AvgModeMax) { double max; + Real specMax = 0.0f; if ( positiveOnly ) { @@ -509,8 +528,10 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV c = fftOut[i]; v = c.real() * c.real() + c.imag() * c.imag(); + // result available if (m_max.storeAndGetMax(max, v, i)) { + specMax = max > specMax ? max : specMax; max = m_settings.m_linear ? max/m_powFFTDiv : m_mult * log2f(max) + m_ofs; m_powerSpectrum[i * 2] = max; m_powerSpectrum[i * 2 + 1] = max; @@ -527,6 +548,7 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV // result available if (m_max.storeAndGetMax(max, v, i+halfSize)) { + specMax = max > specMax ? max : specMax; max = m_settings.m_linear ? max/m_powFFTDiv : m_mult * log2f(max) + m_ofs; m_powerSpectrum[i] = max; } @@ -537,6 +559,7 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV // result available if (m_max.storeAndGetMax(max, v, i)) { + specMax = max > specMax ? max : specMax; max = m_settings.m_linear ? max/m_powFFTDiv : m_mult * log2f(max) + m_ofs; m_powerSpectrum[i + halfSize] = max; } @@ -546,6 +569,8 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV // result available if (m_max.nextMax()) { + m_specMax = specMax; + // send new data to visualisation if (m_glSpectrum) { m_glSpectrum->newSpectrum(m_powerSpectrum, m_settings.m_fftSize); diff --git a/sdrbase/dsp/spectrumvis.h b/sdrbase/dsp/spectrumvis.h index ad27ac589..8eb384d2e 100644 --- a/sdrbase/dsp/spectrumvis.h +++ b/sdrbase/dsp/spectrumvis.h @@ -122,6 +122,7 @@ public: void setScalef(Real scalef); void configureWSSpectrum(const QString& address, uint16_t port); const GLSpectrumSettings& getSettings() const { return m_settings; } + Real getSpecMax() const { return m_specMax / m_powFFTDiv; } virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual void feed(const Complex *begin, unsigned int length); //!< direct FFT feed @@ -196,6 +197,7 @@ private: MovingAverage2D m_movingAverage; FixedAverage2D m_fixedAverage; Max2D m_max; + Real m_specMax; uint64_t m_centerFrequency; int m_sampleRate;