diff --git a/sdrbase/CMakeLists.txt b/sdrbase/CMakeLists.txt index ad54e2f67..8348681b3 100644 --- a/sdrbase/CMakeLists.txt +++ b/sdrbase/CMakeLists.txt @@ -126,6 +126,7 @@ set(sdrbase_SOURCES dsp/devicesamplesink.cpp dsp/devicesamplemimo.cpp dsp/devicesamplestatic.cpp + dsp/spectrumvis.cpp device/deviceapi.cpp device/deviceenumerator.cpp @@ -268,6 +269,7 @@ set(sdrbase_HEADERS dsp/devicesamplesink.h dsp/devicesamplemimo.h dsp/devicesamplestatic.h + dsp/spectrumvis.h device/deviceapi.h device/deviceenumerator.h diff --git a/sdrbase/dsp/glspectruminterface.h b/sdrbase/dsp/glspectruminterface.h new file mode 100644 index 000000000..1e1e0446c --- /dev/null +++ b/sdrbase/dsp/glspectruminterface.h @@ -0,0 +1,32 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2020 Edouard Griffiths, F4EXB. // +// // +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef SDRBASE_DSP_GLSPECTRUMINTERFACE_H_ +#define SDRBASE_DSP_GLSPECTRUMINTERFACE_H_ + +#include +#include "dsptypes.h" + +class GLSpectrumInterface +{ +public: + GLSpectrumInterface() {} + virtual ~GLSpectrumInterface() {} + virtual void newSpectrum(const std::vector& spectrum, int fftSize) {} +}; + +#endif // SDRBASE_DSP_GLSPECTRUMINTERFACE_H_ diff --git a/sdrgui/dsp/spectrumvis.cpp b/sdrbase/dsp/spectrumvis.cpp similarity index 87% rename from sdrgui/dsp/spectrumvis.cpp rename to sdrbase/dsp/spectrumvis.cpp index e3b52fca6..5de0d409f 100644 --- a/sdrgui/dsp/spectrumvis.cpp +++ b/sdrbase/dsp/spectrumvis.cpp @@ -1,10 +1,31 @@ -#include "dsp/spectrumvis.h" -#include "gui/glspectrum.h" -#include "dsp/dspcommands.h" -#include "dsp/dspengine.h" -#include "dsp/fftfactory.h" +/////////////////////////////////////////////////////////////////////////////////// +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "glspectruminterface.h" +#include "dspcommands.h" +#include "dspengine.h" +#include "fftfactory.h" #include "util/messagequeue.h" +#include "spectrumvis.h" + #define MAX_FFT_SIZE 4096 #ifndef LINUX @@ -19,7 +40,7 @@ MESSAGE_CLASS_DEFINITION(SpectrumVis::MsgConfigureScalingFactor, Message) const Real SpectrumVis::m_mult = (10.0f / log2f(10.0f)); -SpectrumVis::SpectrumVis(Real scalef, GLSpectrum* glSpectrum) : +SpectrumVis::SpectrumVis(Real scalef, GLSpectrumInterface* glSpectrum) : BasebandSampleSink(), m_fft(nullptr), m_fftEngineSequence(0), diff --git a/sdrgui/dsp/spectrumvis.h b/sdrbase/dsp/spectrumvis.h similarity index 65% rename from sdrgui/dsp/spectrumvis.h rename to sdrbase/dsp/spectrumvis.h index 678ffffe3..819c3f53c 100644 --- a/sdrgui/dsp/spectrumvis.h +++ b/sdrbase/dsp/spectrumvis.h @@ -1,3 +1,23 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + #ifndef INCLUDE_SPECTRUMVIS_H #define INCLUDE_SPECTRUMVIS_H @@ -11,7 +31,7 @@ #include "util/fixedaverage2d.h" #include "util/max2d.h" -class GLSpectrum; +class GLSpectrumInterface; class MessageQueue; class SDRGUI_API SpectrumVis : public BasebandSampleSink { @@ -77,7 +97,7 @@ public: Real m_scalef; }; - SpectrumVis(Real scalef, GLSpectrum* glSpectrum = 0); + SpectrumVis(Real scalef, GLSpectrumInterface* glSpectrum = nullptr); virtual ~SpectrumVis(); void configure(MessageQueue* msgQueue, @@ -111,7 +131,7 @@ private: bool m_needMoreSamples; Real m_scalef; - GLSpectrum* m_glSpectrum; + GLSpectrumInterface* m_glSpectrum; MovingAverage2D m_movingAverage; FixedAverage2D m_fixedAverage; Max2D m_max; diff --git a/sdrgui/CMakeLists.txt b/sdrgui/CMakeLists.txt index 341129f64..cde208ddc 100644 --- a/sdrgui/CMakeLists.txt +++ b/sdrgui/CMakeLists.txt @@ -56,7 +56,6 @@ set(sdrgui_SOURCES dsp/scopevis.cpp dsp/scopevisxy.cpp - dsp/spectrumvis.cpp dsp/spectrumscopecombovis.cpp device/deviceuiset.cpp @@ -129,7 +128,6 @@ set(sdrgui_HEADERS dsp/scopevis.h dsp/scopevisxy.h - dsp/spectrumvis.h dsp/spectrumscopecombovis.h device/deviceuiset.h diff --git a/sdrgui/gui/glspectrum.cpp b/sdrgui/gui/glspectrum.cpp index 020a86d9c..fcd169398 100644 --- a/sdrgui/gui/glspectrum.cpp +++ b/sdrgui/gui/glspectrum.cpp @@ -156,17 +156,22 @@ GLSpectrum::~GLSpectrum() QMutexLocker mutexLocker(&m_mutex); - if(m_waterfallBuffer != NULL) { + if (m_waterfallBuffer) + { delete m_waterfallBuffer; - m_waterfallBuffer = NULL; + m_waterfallBuffer = nullptr; } - if(m_histogramBuffer != NULL) { + + if (m_histogramBuffer) + { delete m_histogramBuffer; - m_histogramBuffer = NULL; + m_histogramBuffer = nullptr; } - if(m_histogram != NULL) { + + if (m_histogram) + { delete[] m_histogram; - m_histogram = NULL; + m_histogram = nullptr; } } @@ -304,23 +309,27 @@ void GLSpectrum::setDisplayGrid(bool display) void GLSpectrum::setDisplayGridIntensity(int intensity) { m_displayGridIntensity = intensity; + if (m_displayGridIntensity > 100) { m_displayGridIntensity = 100; } else if (m_displayGridIntensity < 0) { m_displayGridIntensity = 0; } - update(); + + update(); } void GLSpectrum::setDisplayTraceIntensity(int intensity) { m_displayTraceIntensity = intensity; + if (m_displayTraceIntensity > 100) { m_displayTraceIntensity = 100; } else if (m_displayTraceIntensity < 0) { m_displayTraceIntensity = 0; } - update(); + + update(); } void GLSpectrum::setLinear(bool linear) @@ -371,12 +380,14 @@ void GLSpectrum::newSpectrum(const std::vector& spectrum, int fftSize) m_displayChanged = true; - if(m_changesPending) { + if (m_changesPending) + { m_fftSize = fftSize; return; } - if(fftSize != m_fftSize) { + if (fftSize != m_fftSize) + { m_fftSize = fftSize; m_changesPending = true; return; @@ -388,15 +399,19 @@ void GLSpectrum::newSpectrum(const std::vector& spectrum, int fftSize) void GLSpectrum::updateWaterfall(const std::vector& spectrum) { - if(m_waterfallBufferPos < m_waterfallBuffer->height()) { + if (m_waterfallBufferPos < m_waterfallBuffer->height()) + { quint32* pix = (quint32*)m_waterfallBuffer->scanLine(m_waterfallBufferPos); - for(int i = 0; i < m_fftSize; i++) { + for (int i = 0; i < m_fftSize; i++) + { int v = (int)((spectrum[i] - m_referenceLevel) * 2.4 * 100.0 / m_powerRange + 240.0); - if(v > 239) + + if (v > 239) { v = 239; - else if(v < 0) + } else if (v < 0) { v = 0; + } *pix++ = m_waterfallPalette[(int)v]; } @@ -522,7 +537,8 @@ void GLSpectrum::initializeGL() { QOpenGLContext *glCurrentContext = QOpenGLContext::currentContext(); - if (glCurrentContext) { + if (glCurrentContext) + { if (QOpenGLContext::currentContext()->isValid()) { qDebug() << "GLSpectrum::initializeGL: context:" << " major: " << (QOpenGLContext::currentContext()->format()).majorVersion() @@ -532,7 +548,9 @@ void GLSpectrum::initializeGL() else { qDebug() << "GLSpectrum::initializeGL: current context is invalid"; } - } else { + } + else + { qCritical() << "GLSpectrum::initializeGL: no current context"; return; } @@ -1593,7 +1611,7 @@ void GLSpectrum::applyChanges() bool fftSizeChanged = true; - if(m_waterfallBuffer != NULL) { + if (m_waterfallBuffer) { fftSizeChanged = m_waterfallBuffer->width() != m_fftSize; } @@ -1601,7 +1619,7 @@ void GLSpectrum::applyChanges() if (fftSizeChanged || windowSizeChanged) { - if(m_waterfallBuffer != 0) { + if (m_waterfallBuffer) { delete m_waterfallBuffer; } @@ -1614,13 +1632,15 @@ void GLSpectrum::applyChanges() if(fftSizeChanged) { - if(m_histogramBuffer != NULL) { + if (m_histogramBuffer) + { delete m_histogramBuffer; - m_histogramBuffer = NULL; + m_histogramBuffer = nullptr; } - if(m_histogram != NULL) { + + if (m_histogram) { delete[] m_histogram; - m_histogram = NULL; + m_histogram = nullptr; } m_histogramBuffer = new QImage(m_fftSize, 100, QImage::Format_RGB32); diff --git a/sdrgui/gui/glspectrum.h b/sdrgui/gui/glspectrum.h index 75940813e..8605e3434 100644 --- a/sdrgui/gui/glspectrum.h +++ b/sdrgui/gui/glspectrum.h @@ -28,7 +28,7 @@ #include #include #include -#include "dsp/dsptypes.h" +#include "dsp/glspectruminterface.h" #include "gui/scaleengine.h" #include "gui/glshadersimple.h" #include "gui/glshadertextured.h" @@ -40,7 +40,7 @@ class QOpenGLShaderProgram; class MessageQueue; -class SDRGUI_API GLSpectrum : public QGLWidget { +class SDRGUI_API GLSpectrum : public QGLWidget, public GLSpectrumInterface { Q_OBJECT public: @@ -61,8 +61,8 @@ public: quint32 m_sampleRate; }; - GLSpectrum(QWidget* parent = NULL); - ~GLSpectrum(); + GLSpectrum(QWidget* parent = nullptr); + virtual ~GLSpectrum(); void setCenterFrequency(qint64 frequency); void setSampleRate(qint32 sampleRate); @@ -89,7 +89,7 @@ public: void removeChannelMarker(ChannelMarker* channelMarker); void setMessageQueueToGUI(MessageQueue* messageQueue) { m_messageQueueToGUI = messageQueue; } - void newSpectrum(const std::vector& spectrum, int fftSize); + virtual void newSpectrum(const std::vector& spectrum, int fftSize); void clearSpectrumHistogram(); Real getWaterfallShare() const { return m_waterfallShare; }