2020-04-28 16:44:03 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2015-2020 Edouard Griffiths, F4EXB //
|
|
|
|
// //
|
|
|
|
// Symbol synchronizer or symbol clock recovery mostly encapsulating //
|
|
|
|
// liquid-dsp's symsync "object" //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-05-18 15:52:39 +00:00
|
|
|
#ifndef INCLUDE_SPECTRUMVIS_H
|
|
|
|
#define INCLUDE_SPECTRUMVIS_H
|
|
|
|
|
2015-10-22 00:27:56 +00:00
|
|
|
#include <QMutex>
|
2020-04-29 15:41:17 +00:00
|
|
|
|
|
|
|
#include "dsp/basebandsamplesink.h"
|
2014-05-18 15:52:39 +00:00
|
|
|
#include "dsp/fftengine.h"
|
2017-10-22 17:12:43 +00:00
|
|
|
#include "dsp/fftwindow.h"
|
2018-03-20 12:49:21 +00:00
|
|
|
#include "export.h"
|
2015-08-18 00:47:14 +00:00
|
|
|
#include "util/message.h"
|
2018-06-28 21:47:15 +00:00
|
|
|
#include "util/movingaverage2d.h"
|
2018-07-01 00:16:59 +00:00
|
|
|
#include "util/fixedaverage2d.h"
|
2018-10-12 06:47:14 +00:00
|
|
|
#include "util/max2d.h"
|
2020-04-29 15:41:17 +00:00
|
|
|
#include "websockets/wsspectrum.h"
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2020-04-28 16:44:03 +00:00
|
|
|
class GLSpectrumInterface;
|
2014-05-18 15:52:39 +00:00
|
|
|
class MessageQueue;
|
|
|
|
|
2018-03-03 19:23:38 +00:00
|
|
|
class SDRGUI_API SpectrumVis : public BasebandSampleSink {
|
2015-08-18 00:47:14 +00:00
|
|
|
|
2014-05-18 15:52:39 +00:00
|
|
|
public:
|
2018-10-12 06:47:14 +00:00
|
|
|
enum AvgMode
|
2018-07-01 00:16:59 +00:00
|
|
|
{
|
2018-07-01 20:36:36 +00:00
|
|
|
AvgModeNone,
|
2018-10-12 06:47:14 +00:00
|
|
|
AvgModeMovingAvg,
|
|
|
|
AvgModeFixedAvg,
|
|
|
|
AvgModeMax
|
2018-07-01 00:16:59 +00:00
|
|
|
};
|
|
|
|
|
2020-04-30 07:57:05 +00:00
|
|
|
SpectrumVis(Real scalef);
|
|
|
|
virtual ~SpectrumVis();
|
|
|
|
|
|
|
|
void setGLSpectrum(GLSpectrumInterface* glSpectrum) { m_glSpectrum = glSpectrum; }
|
|
|
|
void openWSSpectrum();
|
|
|
|
void closeWSSpectrum();
|
|
|
|
|
|
|
|
void configure(MessageQueue* msgQueue,
|
|
|
|
int fftSize,
|
|
|
|
float refLevel,
|
|
|
|
float powerRange,
|
|
|
|
int overlapPercent,
|
|
|
|
unsigned int averagingNb,
|
|
|
|
AvgMode averagingMode,
|
|
|
|
FFTWindow::Function window,
|
|
|
|
bool m_linear);
|
|
|
|
void configureDSP(uint64_t centerFrequency, int sampleRate);
|
|
|
|
void setScalef(Real scalef);
|
|
|
|
void configureWSSpectrum(const QString& address, uint16_t port);
|
|
|
|
|
|
|
|
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
|
|
|
|
void feedTriggered(const SampleVector::const_iterator& triggerPoint, const SampleVector::const_iterator& end, bool positiveOnly);
|
|
|
|
virtual void start();
|
|
|
|
virtual void stop();
|
|
|
|
virtual bool handleMessage(const Message& message);
|
|
|
|
|
|
|
|
private:
|
2018-03-03 20:19:59 +00:00
|
|
|
class MsgConfigureSpectrumVis : public Message {
|
2015-08-18 00:47:14 +00:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
2018-07-04 21:11:28 +00:00
|
|
|
MsgConfigureSpectrumVis(
|
|
|
|
int fftSize,
|
2020-04-29 15:41:17 +00:00
|
|
|
float refLevel,
|
|
|
|
float powerRange,
|
2018-07-04 21:11:28 +00:00
|
|
|
int overlapPercent,
|
|
|
|
unsigned int averageNb,
|
2019-08-04 23:56:29 +00:00
|
|
|
AvgMode avgMode,
|
2018-07-04 21:11:28 +00:00
|
|
|
FFTWindow::Function window,
|
|
|
|
bool linear) :
|
2015-08-18 00:47:14 +00:00
|
|
|
Message(),
|
|
|
|
m_fftSize(fftSize),
|
|
|
|
m_overlapPercent(overlapPercent),
|
2020-04-29 15:41:17 +00:00
|
|
|
m_refLevel(refLevel),
|
|
|
|
m_powerRange(powerRange),
|
2018-06-30 20:30:42 +00:00
|
|
|
m_averageNb(averageNb),
|
2019-08-04 23:56:29 +00:00
|
|
|
m_avgMode(avgMode),
|
2018-07-04 21:11:28 +00:00
|
|
|
m_window(window),
|
|
|
|
m_linear(linear)
|
2019-08-04 23:56:29 +00:00
|
|
|
{}
|
2015-08-18 00:47:14 +00:00
|
|
|
|
|
|
|
int getFFTSize() const { return m_fftSize; }
|
2020-04-29 15:41:17 +00:00
|
|
|
float getRefLevel() const { return m_refLevel; }
|
|
|
|
float getPowerRange() const { return m_powerRange; }
|
2015-08-18 00:47:14 +00:00
|
|
|
int getOverlapPercent() const { return m_overlapPercent; }
|
2018-06-30 20:30:42 +00:00
|
|
|
unsigned int getAverageNb() const { return m_averageNb; }
|
2018-10-12 06:47:14 +00:00
|
|
|
SpectrumVis::AvgMode getAvgMode() const { return m_avgMode; }
|
2015-08-18 00:47:14 +00:00
|
|
|
FFTWindow::Function getWindow() const { return m_window; }
|
2018-07-04 21:11:28 +00:00
|
|
|
bool getLinear() const { return m_linear; }
|
2015-08-18 00:47:14 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int m_fftSize;
|
|
|
|
int m_overlapPercent;
|
2020-04-29 15:41:17 +00:00
|
|
|
float m_refLevel;
|
|
|
|
float m_powerRange;
|
2018-06-30 20:30:42 +00:00
|
|
|
unsigned int m_averageNb;
|
2018-10-12 06:47:14 +00:00
|
|
|
SpectrumVis::AvgMode m_avgMode;
|
2015-08-18 00:47:14 +00:00
|
|
|
FFTWindow::Function m_window;
|
2018-07-04 21:11:28 +00:00
|
|
|
bool m_linear;
|
2015-08-18 00:47:14 +00:00
|
|
|
};
|
|
|
|
|
2020-04-29 15:41:17 +00:00
|
|
|
class MsgConfigureDSP : public Message
|
|
|
|
{
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
MsgConfigureDSP(uint64_t centerFrequency, int sampleRate) :
|
|
|
|
Message(),
|
|
|
|
m_centerFrequency(centerFrequency),
|
|
|
|
m_sampleRate(sampleRate)
|
|
|
|
{}
|
|
|
|
|
|
|
|
uint64_t getCenterFrequency() const { return m_centerFrequency; }
|
|
|
|
int getSampleRate() const { return m_sampleRate; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint64_t m_centerFrequency;
|
|
|
|
int m_sampleRate;
|
|
|
|
};
|
|
|
|
|
2019-10-26 20:30:53 +00:00
|
|
|
class MsgConfigureScalingFactor : public Message
|
|
|
|
{
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
MsgConfigureScalingFactor(Real scalef) :
|
|
|
|
Message(),
|
|
|
|
m_scalef(scalef)
|
|
|
|
{}
|
|
|
|
|
|
|
|
Real getScalef() const { return m_scalef; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Real m_scalef;
|
|
|
|
};
|
|
|
|
|
2020-04-30 07:57:05 +00:00
|
|
|
class MsgConfigureWSpectrumOpenClose : public Message
|
|
|
|
{
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2020-04-30 07:57:05 +00:00
|
|
|
public:
|
|
|
|
MsgConfigureWSpectrumOpenClose(bool openClose) :
|
|
|
|
Message(),
|
|
|
|
m_openClose(openClose)
|
|
|
|
{}
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2020-04-30 07:57:05 +00:00
|
|
|
Real getOpenClose() const { return m_openClose; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_openClose;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MsgConfigureWSpectrum : public Message
|
|
|
|
{
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
MsgConfigureWSpectrum(const QString& address, uint16_t port) :
|
|
|
|
Message(),
|
|
|
|
m_address(address),
|
|
|
|
m_port(port)
|
|
|
|
{}
|
|
|
|
|
|
|
|
const QString& getAddress() const { return m_address; }
|
|
|
|
uint16_t getPort() const { return m_port; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_address;
|
|
|
|
uint16_t m_port;
|
|
|
|
};
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
FFTEngine* m_fft;
|
|
|
|
FFTWindow m_window;
|
2020-03-12 05:27:38 +00:00
|
|
|
unsigned int m_fftEngineSequence;
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
std::vector<Complex> m_fftBuffer;
|
2018-07-05 23:34:05 +00:00
|
|
|
std::vector<Real> m_powerSpectrum;
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2015-08-14 03:00:28 +00:00
|
|
|
std::size_t m_fftSize;
|
2020-04-29 15:41:17 +00:00
|
|
|
float m_refLevel;
|
|
|
|
float m_powerRange;
|
2015-08-14 03:00:28 +00:00
|
|
|
std::size_t m_overlapPercent;
|
|
|
|
std::size_t m_overlapSize;
|
|
|
|
std::size_t m_refillSize;
|
|
|
|
std::size_t m_fftBufferFill;
|
2015-07-14 23:19:39 +00:00
|
|
|
bool m_needMoreSamples;
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2018-01-22 13:07:24 +00:00
|
|
|
Real m_scalef;
|
2020-04-28 16:44:03 +00:00
|
|
|
GLSpectrumInterface* m_glSpectrum;
|
2020-04-29 15:41:17 +00:00
|
|
|
WSSpectrum m_wsSpectrum;
|
2018-07-01 00:16:59 +00:00
|
|
|
MovingAverage2D<double> m_movingAverage;
|
|
|
|
FixedAverage2D<double> m_fixedAverage;
|
2018-10-12 06:47:14 +00:00
|
|
|
Max2D<double> m_max;
|
2018-06-28 21:47:15 +00:00
|
|
|
unsigned int m_averageNb;
|
2018-10-12 06:47:14 +00:00
|
|
|
AvgMode m_avgMode;
|
2018-07-05 23:34:05 +00:00
|
|
|
bool m_linear;
|
2018-06-28 21:47:15 +00:00
|
|
|
|
2020-04-29 15:41:17 +00:00
|
|
|
uint64_t m_centerFrequency;
|
|
|
|
int m_sampleRate;
|
|
|
|
|
2018-06-28 21:47:15 +00:00
|
|
|
Real m_ofs;
|
2018-07-05 23:34:05 +00:00
|
|
|
Real m_powFFTDiv;
|
2018-06-28 21:47:15 +00:00
|
|
|
static const Real m_mult;
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2015-10-22 00:27:56 +00:00
|
|
|
QMutex m_mutex;
|
|
|
|
|
2018-07-01 00:16:59 +00:00
|
|
|
void handleConfigure(int fftSize,
|
2020-04-29 15:41:17 +00:00
|
|
|
float refLevel,
|
|
|
|
float powerRange,
|
2018-07-01 00:16:59 +00:00
|
|
|
int overlapPercent,
|
|
|
|
unsigned int averageNb,
|
2018-10-12 06:47:14 +00:00
|
|
|
AvgMode averagingMode,
|
2018-07-05 23:34:05 +00:00
|
|
|
FFTWindow::Function window,
|
|
|
|
bool linear);
|
2020-04-30 07:57:05 +00:00
|
|
|
void handleWSOpenClose(bool openClose);
|
2020-04-29 15:41:17 +00:00
|
|
|
void handleConfigureDSP(uint64_t centerFrequency,
|
|
|
|
int sampleRate);
|
2019-10-26 20:30:53 +00:00
|
|
|
void handleScalef(Real scalef);
|
2020-04-30 07:57:05 +00:00
|
|
|
void handleConfigureWSSpectrum(const QString& address, uint16_t port);
|
2014-05-18 15:52:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDE_SPECTRUMVIS_H
|