From de74f27c9afe46b34572169cc2beab4076ab1f5c Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 22 Jul 2017 04:23:10 +0200 Subject: [PATCH] SSB demod: show LSB and DSB values appropriately --- plugins/channelrx/demodssb/ssbdemodgui.cpp | 103 +++++++++++---------- sdrbase/gui/glspectrum.cpp | 12 ++- sdrbase/gui/glspectrum.h | 4 +- sdrbase/gui/scaleengine.cpp | 14 ++- sdrbase/gui/scaleengine.h | 2 + 5 files changed, 79 insertions(+), 56 deletions(-) diff --git a/plugins/channelrx/demodssb/ssbdemodgui.cpp b/plugins/channelrx/demodssb/ssbdemodgui.cpp index 8679fc394..d9c384312 100644 --- a/plugins/channelrx/demodssb/ssbdemodgui.cpp +++ b/plugins/channelrx/demodssb/ssbdemodgui.cpp @@ -162,27 +162,32 @@ void SSBDemodGUI::on_dsb_toggled(bool dsb) { m_dsb = dsb; - if (!m_dsb) + if (m_dsb) { - if (ui->BW->value() < 0) { - m_channelMarker.setSidebands(ChannelMarker::lsb); - } else { - m_channelMarker.setSidebands(ChannelMarker::usb); - } + if (ui->BW->value() < 0) { + ui->BW->setValue(-ui->BW->value()); + } - ui->glSpectrum->setCenterFrequency(m_rate/4); - ui->glSpectrum->setSampleRate(m_rate/2); - ui->glSpectrum->setSsbSpectrum(true); + m_channelMarker.setSidebands(ChannelMarker::dsb); - on_lowCut_valueChanged(m_channelMarker.getLowCutoff()/100); + QString bwStr = QString::number(ui->BW->value()/10.0, 'f', 1); + ui->BWText->setText(tr("%1%2k").arg(QChar(0xB1, 0x00)).arg(bwStr)); + ui->lowCut->setValue(0); + ui->lowCut->setEnabled(false); } else { - m_channelMarker.setSidebands(ChannelMarker::dsb); + if (ui->BW->value() < 0) { + m_channelMarker.setSidebands(ChannelMarker::lsb); + } else { + m_channelMarker.setSidebands(ChannelMarker::usb); + } - ui->glSpectrum->setCenterFrequency(0); - ui->glSpectrum->setSampleRate(m_rate); - ui->glSpectrum->setSsbSpectrum(false); + QString bwStr = QString::number(ui->BW->value()/10.0, 'f', 1); + ui->BWText->setText(tr("%1k").arg(bwStr)); + ui->lowCut->setEnabled(true); + + on_lowCut_valueChanged(m_channelMarker.getLowCutoff()/100); } applySettings(); @@ -197,27 +202,19 @@ void SSBDemodGUI::on_deltaFrequency_changed(qint64 value) void SSBDemodGUI::on_BW_valueChanged(int value) { QString s = QString::number(value/10.0, 'f', 1); - ui->BWText->setText(tr("%1k").arg(s)); m_channelMarker.setBandwidth(value * 100 * 2); - if (!m_dsb) + if (m_dsb) { - if (value < 0) - { - m_channelMarker.setSidebands(ChannelMarker::lsb); - } - else - { - m_channelMarker.setSidebands(ChannelMarker::usb); - } + ui->BWText->setText(tr("%1%2k").arg(QChar(0xB1, 0x00)).arg(s)); } else { - m_channelMarker.setSidebands(ChannelMarker::dsb); + ui->BWText->setText(tr("%1k").arg(s)); } - on_lowCut_valueChanged(m_channelMarker.getLowCutoff()/100); + setNewRate(m_spanLog2); } int SSBDemodGUI::getEffectiveLowCutoff(int lowCutoff) @@ -333,11 +330,8 @@ SSBDemodGUI::SSBDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidg ui->deltaFrequency->setValueRange(false, 7, -9999999, 9999999); ui->channelPowerMeter->setColorTheme(LevelMeterSignalDB::ColorGreenAndBlue); - ui->glSpectrum->setCenterFrequency(m_rate/2); - ui->glSpectrum->setSampleRate(m_rate); ui->glSpectrum->setDisplayWaterfall(true); ui->glSpectrum->setDisplayMaxHold(true); - ui->glSpectrum->setSsbSpectrum(true); ui->glSpectrum->connectTimer(m_pluginAPI->getMainWindow()->getMasterTimer()); connect(&m_pluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); @@ -405,35 +399,46 @@ bool SSBDemodGUI::setNewRate(int spanLog2) m_channelMarker.setLowCutoff(m_rate); } - ui->BW->setMinimum(-m_rate/100); - ui->lowCut->setMinimum(-m_rate/100); - ui->BW->setMaximum(m_rate/100); - ui->lowCut->setMaximum(m_rate/100); QString s = QString::number(m_rate/1000.0, 'f', 1); - ui->spanText->setText(tr("%1k").arg(s)); - //ui->glSpectrum->setCenterFrequency(m_rate/2); - //ui->glSpectrum->setSampleRate(m_rate); - if (!m_dsb) + if (m_dsb) { - if (ui->BW->value() < 0) { - m_channelMarker.setSidebands(ChannelMarker::lsb); - } else { - m_channelMarker.setSidebands(ChannelMarker::usb); - } + ui->BW->setMinimum(0); + ui->BW->setMaximum(m_rate/100); + ui->lowCut->setMinimum(0); + ui->lowCut->setMaximum(m_rate/100); - ui->glSpectrum->setCenterFrequency(m_rate/2); - ui->glSpectrum->setSampleRate(m_rate); - ui->glSpectrum->setSsbSpectrum(true); + m_channelMarker.setSidebands(ChannelMarker::dsb); + + ui->spanText->setText(tr("%1%2k").arg(QChar(0xB1, 0x00)).arg(s)); + ui->glSpectrum->setCenterFrequency(0); + ui->glSpectrum->setSampleRate(2*m_rate); + ui->glSpectrum->setSsbSpectrum(false); + ui->glSpectrum->setLsbDisplay(false); } else { - m_channelMarker.setSidebands(ChannelMarker::dsb); + ui->BW->setMinimum(-m_rate/100); + ui->BW->setMaximum(m_rate/100); + ui->lowCut->setMinimum(-m_rate/100); + ui->lowCut->setMaximum(m_rate/100); - ui->glSpectrum->setCenterFrequency(0); - ui->glSpectrum->setSampleRate(2*m_rate); - ui->glSpectrum->setSsbSpectrum(false); + if (ui->BW->value() < 0) + { + m_channelMarker.setSidebands(ChannelMarker::lsb); + ui->glSpectrum->setLsbDisplay(true); + } + else + { + m_channelMarker.setSidebands(ChannelMarker::usb); + ui->glSpectrum->setLsbDisplay(false); + } + + ui->spanText->setText(tr("%1k").arg(s)); + ui->glSpectrum->setCenterFrequency(m_rate/2); + ui->glSpectrum->setSampleRate(m_rate); + ui->glSpectrum->setSsbSpectrum(true); } return true; diff --git a/sdrbase/gui/glspectrum.cpp b/sdrbase/gui/glspectrum.cpp index 5015b6ab5..3f11108c5 100644 --- a/sdrbase/gui/glspectrum.cpp +++ b/sdrbase/gui/glspectrum.cpp @@ -52,6 +52,7 @@ GLSpectrum::GLSpectrum(QWidget* parent) : m_waterfallTexturePos(0), m_displayWaterfall(true), m_ssbSpectrum(false), + m_lsbDisplay(false), m_histogramBuffer(NULL), m_histogram(NULL), m_histogramHoldoff(NULL), @@ -140,7 +141,7 @@ GLSpectrum::~GLSpectrum() } } -void GLSpectrum::setCenterFrequency(quint64 frequency) +void GLSpectrum::setCenterFrequency(qint64 frequency) { m_centerFrequency = frequency; m_changesPending = true; @@ -209,6 +210,12 @@ void GLSpectrum::setSsbSpectrum(bool ssbSpectrum) update(); } +void GLSpectrum::setLsbDisplay(bool lsbDisplay) +{ + m_lsbDisplay = lsbDisplay; + update(); +} + void GLSpectrum::setInvertedWaterfall(bool inv) { m_invertedWaterfall = inv; @@ -1059,6 +1066,7 @@ void GLSpectrum::applyChanges() m_frequencyScale.setSize(width() - leftMargin - rightMargin); m_frequencyScale.setRange(Unit::Frequency, m_centerFrequency - m_sampleRate / 2, m_centerFrequency + m_sampleRate / 2); + m_frequencyScale.setMakeOpposite(m_lsbDisplay); m_glWaterfallBoxMatrix.setToIdentity(); m_glWaterfallBoxMatrix.translate( @@ -1155,6 +1163,7 @@ void GLSpectrum::applyChanges() m_frequencyScale.setSize(width() - leftMargin - rightMargin); m_frequencyScale.setRange(Unit::Frequency, m_centerFrequency - m_sampleRate / 2.0, m_centerFrequency + m_sampleRate / 2.0); + m_frequencyScale.setMakeOpposite(m_lsbDisplay); m_glWaterfallBoxMatrix.setToIdentity(); m_glWaterfallBoxMatrix.translate( @@ -1206,6 +1215,7 @@ void GLSpectrum::applyChanges() m_frequencyScale.setSize(width() - leftMargin - rightMargin); m_frequencyScale.setRange(Unit::Frequency, m_centerFrequency - m_sampleRate / 2, m_centerFrequency + m_sampleRate / 2); + m_frequencyScale.setMakeOpposite(m_lsbDisplay); m_glHistogramSpectrumMatrix.setToIdentity(); m_glHistogramSpectrumMatrix.translate( diff --git a/sdrbase/gui/glspectrum.h b/sdrbase/gui/glspectrum.h index 5b79c19dc..0dbae94a5 100644 --- a/sdrbase/gui/glspectrum.h +++ b/sdrbase/gui/glspectrum.h @@ -43,7 +43,7 @@ public: GLSpectrum(QWidget* parent = NULL); ~GLSpectrum(); - void setCenterFrequency(quint64 frequency); + void setCenterFrequency(qint64 frequency); void setSampleRate(qint32 sampleRate); void setReferenceLevel(Real referenceLevel); void setPowerRange(Real powerRange); @@ -52,6 +52,7 @@ public: void setHistoStroke(int stroke); void setDisplayWaterfall(bool display); void setSsbSpectrum(bool ssbSpectrum); + void setLsbDisplay(bool lsbDisplay); void setInvertedWaterfall(bool inv); void setDisplayMaxHold(bool display); void setDisplayCurrent(bool display); @@ -140,6 +141,7 @@ private: QMatrix4x4 m_glWaterfallBoxMatrix; bool m_displayWaterfall; bool m_ssbSpectrum; + bool m_lsbDisplay; QRgb m_histogramPalette[240]; QImage* m_histogramBuffer; diff --git a/sdrbase/gui/scaleengine.cpp b/sdrbase/gui/scaleengine.cpp index 4d0151771..2683bafbc 100644 --- a/sdrbase/gui/scaleengine.cpp +++ b/sdrbase/gui/scaleengine.cpp @@ -29,9 +29,12 @@ static double trunc(double d) QString ScaleEngine::formatTick(double value, int decimalPlaces, bool fancyTime) { - if((m_physicalUnit != Unit::Time) || (!fancyTime) || 1) { - return QString("%1").arg(value, 0, 'f', decimalPlaces); - } else { + if((m_physicalUnit != Unit::Time) || (!fancyTime) || 1) + { + return QString("%1").arg(m_makeOpposite ? -value : value, 0, 'f', decimalPlaces); + } + else + { QString str; double orig = fabs(value); double tmp; @@ -60,7 +63,7 @@ QString ScaleEngine::formatTick(double value, int decimalPlaces, bool fancyTime) value *= -1.0; } - tmp = value; + tmp = m_makeOpposite ? -value : value; str += QString("%1").arg(tmp, 2, 'f', decimalPlaces, QChar('0')); return str; @@ -496,7 +499,8 @@ ScaleEngine::ScaleEngine() : m_majorTickValueDistance(1.0), m_firstMajorTickValue(1.0), m_numMinorTicks(1), - m_decimalPlaces(1) + m_decimalPlaces(1), + m_makeOpposite(false) { } diff --git a/sdrbase/gui/scaleengine.h b/sdrbase/gui/scaleengine.h index 7b43afa5a..3746dbe05 100644 --- a/sdrbase/gui/scaleengine.h +++ b/sdrbase/gui/scaleengine.h @@ -56,6 +56,7 @@ private: double m_firstMajorTickValue; int m_numMinorTicks; int m_decimalPlaces; + bool m_makeOpposite; // will show -value instead of value QString formatTick(double value, int decimalPlaces, bool fancyTime = true); void calcCharSize(); @@ -76,6 +77,7 @@ public: void setSize(float size); float getSize() { return m_size; } void setRange(Unit::Physical physicalUnit, float rangeMin, float rangeMax); + void setMakeOpposite(bool makeOpposite) { m_makeOpposite = makeOpposite; } float getPosFromValue(double value); float getValueFromPos(double pos);