1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-25 04:03:30 -05:00
sdrangel/sdrgui/dsp/spectrumvis.h

120 lines
3.0 KiB
C
Raw Normal View History

#ifndef INCLUDE_SPECTRUMVIS_H
#define INCLUDE_SPECTRUMVIS_H
#include <dsp/basebandsamplesink.h>
#include <QMutex>
#include "dsp/fftengine.h"
#include "dsp/fftwindow.h"
#include "export.h"
#include "util/message.h"
2018-06-28 17:47:15 -04:00
#include "util/movingaverage2d.h"
2018-06-30 20:16:59 -04:00
#include "util/fixedaverage2d.h"
#include "util/max2d.h"
class GLSpectrum;
class MessageQueue;
2018-03-03 14:23:38 -05:00
class SDRGUI_API SpectrumVis : public BasebandSampleSink {
public:
enum AvgMode
2018-06-30 20:16:59 -04:00
{
AvgModeNone,
AvgModeMovingAvg,
AvgModeFixedAvg,
AvgModeMax
2018-06-30 20:16:59 -04:00
};
class MsgConfigureSpectrumVis : public Message {
MESSAGE_CLASS_DECLARATION
public:
2018-07-04 17:11:28 -04:00
MsgConfigureSpectrumVis(
int fftSize,
int overlapPercent,
unsigned int averageNb,
int preProcessMode,
2018-07-04 17:11:28 -04:00
FFTWindow::Function window,
bool linear) :
Message(),
m_fftSize(fftSize),
m_overlapPercent(overlapPercent),
2018-06-30 16:30:42 -04:00
m_averageNb(averageNb),
2018-07-04 17:11:28 -04:00
m_window(window),
m_linear(linear)
2018-06-30 20:16:59 -04:00
{
m_avgMode = preProcessMode < 0 ? AvgModeNone : preProcessMode > 3 ? AvgModeMax : (SpectrumVis::AvgMode) preProcessMode;
2018-06-30 20:16:59 -04:00
}
int getFFTSize() const { return m_fftSize; }
int getOverlapPercent() const { return m_overlapPercent; }
2018-06-30 16:30:42 -04:00
unsigned int getAverageNb() const { return m_averageNb; }
SpectrumVis::AvgMode getAvgMode() const { return m_avgMode; }
FFTWindow::Function getWindow() const { return m_window; }
2018-07-04 17:11:28 -04:00
bool getLinear() const { return m_linear; }
private:
int m_fftSize;
int m_overlapPercent;
2018-06-30 16:30:42 -04:00
unsigned int m_averageNb;
SpectrumVis::AvgMode m_avgMode;
FFTWindow::Function m_window;
2018-07-04 17:11:28 -04:00
bool m_linear;
};
SpectrumVis(Real scalef, GLSpectrum* glSpectrum = 0);
2015-08-13 23:00:28 -04:00
virtual ~SpectrumVis();
2018-06-30 20:16:59 -04:00
void configure(MessageQueue* msgQueue,
int fftSize,
int overlapPercent,
unsigned int averagingNb,
int averagingMode,
2018-07-04 17:11:28 -04:00
FFTWindow::Function window,
bool m_linear);
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly);
2017-05-25 14:13:34 -04:00
void feedTriggered(const SampleVector::const_iterator& triggerPoint, const SampleVector::const_iterator& end, bool positiveOnly);
2015-08-13 23:00:28 -04:00
virtual void start();
virtual void stop();
virtual bool handleMessage(const Message& message);
private:
FFTEngine* m_fft;
FFTWindow m_window;
std::vector<Complex> m_fftBuffer;
std::vector<Real> m_powerSpectrum;
2015-08-13 23:00:28 -04:00
std::size_t m_fftSize;
std::size_t m_overlapPercent;
std::size_t m_overlapSize;
std::size_t m_refillSize;
std::size_t m_fftBufferFill;
bool m_needMoreSamples;
Real m_scalef;
GLSpectrum* m_glSpectrum;
2018-06-30 20:16:59 -04:00
MovingAverage2D<double> m_movingAverage;
FixedAverage2D<double> m_fixedAverage;
Max2D<double> m_max;
2018-06-28 17:47:15 -04:00
unsigned int m_averageNb;
AvgMode m_avgMode;
bool m_linear;
2018-06-28 17:47:15 -04:00
Real m_ofs;
Real m_powFFTDiv;
2018-06-28 17:47:15 -04:00
static const Real m_mult;
QMutex m_mutex;
2018-06-30 20:16:59 -04:00
void handleConfigure(int fftSize,
int overlapPercent,
unsigned int averageNb,
AvgMode averagingMode,
FFTWindow::Function window,
bool linear);
};
#endif // INCLUDE_SPECTRUMVIS_H