1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-11-14 04:03:25 -05:00

SpectrumVis: Spectrum max functionnality

This commit is contained in:
f4exb 2020-07-16 16:58:45 +02:00
parent 045c705bdb
commit 89fbfc734f
2 changed files with 27 additions and 0 deletions

View File

@ -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);

View File

@ -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<double> m_movingAverage;
FixedAverage2D<double> m_fixedAverage;
Max2D<double> m_max;
Real m_specMax;
uint64_t m_centerFrequency;
int m_sampleRate;