From c411e8fbf5e3642e5a1bc7507f74f81284d5bdc5 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 14 Jul 2024 21:51:22 +0200 Subject: [PATCH] WDSP receiver: implement dB or S points option for the signal strength meter --- plugins/channelrx/wdsprx/wdsprxgui.cpp | 16 +- plugins/channelrx/wdsprx/wdsprxgui.h | 1 + plugins/channelrx/wdsprx/wdsprxgui.ui | 11 +- plugins/channelrx/wdsprx/wdsprxsettings.cpp | 5 + plugins/channelrx/wdsprx/wdsprxsettings.h | 3 + plugins/channelrx/wdsprx/wdsprxsink.cpp | 2 +- sdrbase/dsp/physicalunit.h | 3 +- sdrgui/gui/levelmeter.cpp | 4 +- sdrgui/gui/levelmeter.h | 3 +- sdrgui/gui/scaleengine.cpp | 348 +++++++++++++++++--- sdrgui/gui/scaleengine.h | 4 + wdsp/channel.hpp | 4 +- wdsp/meter.cpp | 26 +- 13 files changed, 370 insertions(+), 60 deletions(-) diff --git a/plugins/channelrx/wdsprx/wdsprxgui.cpp b/plugins/channelrx/wdsprx/wdsprxgui.cpp index e57ae72c5..540fb40e8 100644 --- a/plugins/channelrx/wdsprx/wdsprxgui.cpp +++ b/plugins/channelrx/wdsprx/wdsprxgui.cpp @@ -283,6 +283,14 @@ void WDSPRxGUI::on_ritFrequency_valueChanged(int value) applySettings(); } +void WDSPRxGUI::on_dbOrS_toggled(bool checked) +{ + ui->dbOrS->setText(checked ? "dB": "S"); + m_settings.m_dbOrS = checked; + m_settings.m_profiles[m_settings.m_profileIndex].m_dbOrS = m_settings.m_dbOrS; + ui->channelPowerMeter->setRange(WDSPRxSettings::m_minPowerThresholdDB, 0, !checked); +} + void WDSPRxGUI::on_audioMute_toggled(bool checked) { m_audioMute = checked; @@ -333,6 +341,7 @@ void WDSPRxGUI::on_profileIndex_valueChanged(int value) m_settings.m_audioBinaural = m_settings.m_profiles[m_settings.m_profileIndex].m_audioBinaural; m_settings.m_audioFlipChannels = m_settings.m_profiles[m_settings.m_profileIndex].m_audioFlipChannels; m_settings.m_dsb = m_settings.m_profiles[m_settings.m_profileIndex].m_dsb; + m_settings.m_dbOrS = m_settings.m_profiles[m_settings.m_profileIndex].m_dbOrS; // AGC setup m_settings.m_agc = m_settings.m_profiles[m_settings.m_profileIndex].m_agc; m_settings.m_agcGain = m_settings.m_profiles[m_settings.m_profileIndex].m_agcGain; @@ -730,8 +739,6 @@ void WDSPRxGUI::applyBandwidths(unsigned int spanLog2, bool force) ui->lowCut->blockSignals(false); ui->BW->blockSignals(false); - ui->channelPowerMeter->setRange(WDSPRxSettings::m_minPowerThresholdDB, 0); - m_settings.m_dsb = dsb; m_settings.m_profiles[m_settings.m_profileIndex].m_dsb = dsb; m_settings.m_profiles[m_settings.m_profileIndex].m_spanLog2 = spanLog2; @@ -843,6 +850,9 @@ void WDSPRxGUI::displaySettings() ui->BWText->setText(tr("%1k").arg(s)); } + ui->dbOrS->setText(m_settings.m_dbOrS ? "dB": "S"); + ui->channelPowerMeter->setRange(WDSPRxSettings::m_minPowerThresholdDB, 0, !m_settings.m_dbOrS); + ui->spanLog2->blockSignals(false); ui->dsb->blockSignals(false); ui->BW->blockSignals(false); @@ -857,6 +867,7 @@ void WDSPRxGUI::displaySettings() ui->volume->setValue(volume); ui->volumeText->setText(QString("%1").arg(volume)); + updateIndexLabel(); getRollupContents()->restoreState(m_rollupState); @@ -1364,6 +1375,7 @@ void WDSPRxGUI::makeUIConnections() QObject::connect(ui->equalizer, &ButtonSwitch::toggled, this, &WDSPRxGUI::on_equalizer_toggled); QObject::connect(ui->rit, &ButtonSwitch::toggled, this, &WDSPRxGUI::on_rit_toggled); QObject::connect(ui->ritFrequency, &QDial::valueChanged, this, &WDSPRxGUI::on_ritFrequency_valueChanged); + QObject::connect(ui->dbOrS, &QToolButton::toggled, this, &WDSPRxGUI::on_dbOrS_toggled); } void WDSPRxGUI::updateAbsoluteCenterFrequency() diff --git a/plugins/channelrx/wdsprx/wdsprxgui.h b/plugins/channelrx/wdsprx/wdsprxgui.h index 807e4f307..ebc44fb8c 100644 --- a/plugins/channelrx/wdsprx/wdsprxgui.h +++ b/plugins/channelrx/wdsprx/wdsprxgui.h @@ -149,6 +149,7 @@ private slots: void on_equalizer_toggled(bool checked); void on_rit_toggled(bool checked); void on_ritFrequency_valueChanged(int value); + void on_dbOrS_toggled(bool checked); void onWidgetRolled(QWidget* widget, bool rollDown); void onMenuDialogCalled(const QPoint& p); void handleInputMessages(); diff --git a/plugins/channelrx/wdsprx/wdsprxgui.ui b/plugins/channelrx/wdsprx/wdsprxgui.ui index d758ff25f..1b09b804a 100644 --- a/plugins/channelrx/wdsprx/wdsprxgui.ui +++ b/plugins/channelrx/wdsprx/wdsprxgui.ui @@ -331,10 +331,19 @@ - + + + Toggle between dB and S units + dB + + true + + + true + diff --git a/plugins/channelrx/wdsprx/wdsprxsettings.cpp b/plugins/channelrx/wdsprx/wdsprxsettings.cpp index 2335b0b1c..c0a0098d9 100644 --- a/plugins/channelrx/wdsprx/wdsprxsettings.cpp +++ b/plugins/channelrx/wdsprx/wdsprxsettings.cpp @@ -46,6 +46,7 @@ void WDSPRxSettings::resetToDefaults() m_audioFlipChannels = false; m_dsb = false; m_audioMute = false; + m_dbOrS = true; // AGC m_agc = false; m_agcMode = WDSPRxProfile::AGCMedium; @@ -126,6 +127,7 @@ QByteArray WDSPRxSettings::serialize() const } s.writeU32( 5, m_rgbColor); + s.writeBool( 7, m_dbOrS); s.writeBool( 8, m_audioBinaural); s.writeBool( 9, m_audioFlipChannels); s.writeBool( 10, m_dsb); @@ -224,6 +226,7 @@ QByteArray WDSPRxSettings::serialize() const s.writeBool (105 + 100*i, (int) m_profiles[i].m_audioBinaural); s.writeBool (106 + 100*i, (int) m_profiles[i].m_audioFlipChannels); s.writeBool (107 + 100*i, (int) m_profiles[i].m_dsb); + s.writeBool (108 + 100*i, (int) m_profiles[i].m_dbOrS); // Filter s.writeS32 (100 + 100*i, m_profiles[i].m_spanLog2); s.writeS32 (101 + 100*i, m_profiles[i].m_highCutoff / 100.0); @@ -332,6 +335,7 @@ bool WDSPRxSettings::deserialize(const QByteArray& data) } d.readU32( 5, &m_rgbColor); + d.readBool( 7, &m_dbOrS, true); d.readBool( 8, &m_audioBinaural, false); d.readBool( 9, &m_audioFlipChannels, false); d.readBool( 10, &m_dsb, false); @@ -451,6 +455,7 @@ bool WDSPRxSettings::deserialize(const QByteArray& data) d.readBool( 105 + 100*i, &m_profiles[i].m_audioBinaural, false); d.readBool( 106 + 100*i, &m_profiles[i].m_audioFlipChannels, false); d.readBool( 107 + 100*i, &m_profiles[i].m_dsb, false); + d.readBool( 108 + 100*i, &m_profiles[i].m_dbOrS, true); // Filter d.readS32 (100 + 100*i, &m_profiles[i].m_spanLog2, 3); d.readS32 (101 + 100*i, &tmp, 30); diff --git a/plugins/channelrx/wdsprx/wdsprxsettings.h b/plugins/channelrx/wdsprx/wdsprxsettings.h index e40d442ff..80052b24a 100644 --- a/plugins/channelrx/wdsprx/wdsprxsettings.h +++ b/plugins/channelrx/wdsprx/wdsprxsettings.h @@ -89,6 +89,7 @@ struct WDSPRxProfile bool m_audioBinaural; bool m_audioFlipChannels; bool m_dsb; + bool m_dbOrS; // Filter int m_spanLog2; Real m_highCutoff; @@ -151,6 +152,7 @@ struct WDSPRxProfile m_audioBinaural(false), m_audioFlipChannels(false), m_dsb(false), + m_dbOrS(true), m_spanLog2(3), m_highCutoff(3000), m_lowCutoff(300), @@ -214,6 +216,7 @@ struct WDSPRxSettings bool m_audioFlipChannels; bool m_dsb; bool m_audioMute; + bool m_dbOrS; // AGC bool m_agc; WDSPRxProfile::WDSPRxAGCMode m_agcMode; diff --git a/plugins/channelrx/wdsprx/wdsprxsink.cpp b/plugins/channelrx/wdsprx/wdsprxsink.cpp index b10eb716d..a03704f48 100644 --- a/plugins/channelrx/wdsprx/wdsprxsink.cpp +++ b/plugins/channelrx/wdsprx/wdsprxsink.cpp @@ -123,7 +123,7 @@ WDSPRxSink::WDSPRxSink() : m_sAvg = 0.0; m_sPeak = 0.0; - m_sCount = 1; + m_sCount = m_wdspBufSize; m_rxa = WDSP::RXA::create_rxa( m_wdspSampleRate, // input samplerate diff --git a/sdrbase/dsp/physicalunit.h b/sdrbase/dsp/physicalunit.h index 8eb472cbb..71849cced 100644 --- a/sdrbase/dsp/physicalunit.h +++ b/sdrbase/dsp/physicalunit.h @@ -33,7 +33,8 @@ namespace Unit { Time, TimeHMS, Volt, - Scientific + Scientific, + SUnits }; }; diff --git a/sdrgui/gui/levelmeter.cpp b/sdrgui/gui/levelmeter.cpp index 94e11233f..54c08b759 100644 --- a/sdrgui/gui/levelmeter.cpp +++ b/sdrgui/gui/levelmeter.cpp @@ -309,9 +309,9 @@ LevelMeterSignalDB::~LevelMeterSignalDB() { } -void LevelMeterSignalDB::setRange(int min, int max) +void LevelMeterSignalDB::setRange(int min, int max, bool sUnits) { - m_scaleEngine.setRange(Unit::Decibel, min, max); + m_scaleEngine.setRange(sUnits ? Unit::SUnits : Unit::Decibel, min, max); } void LevelMeterSignalDB::resized() diff --git a/sdrgui/gui/levelmeter.h b/sdrgui/gui/levelmeter.h index ca75eb37e..f7fe300c5 100644 --- a/sdrgui/gui/levelmeter.h +++ b/sdrgui/gui/levelmeter.h @@ -186,7 +186,8 @@ public: virtual ~LevelMeterSignalDB(); void setColorTheme(ColorTheme colorTheme) { m_colorTheme = colorTheme; } - void setRange(int min, int max); + void setRange(int min, int max, bool sUnits = false); + void setS(bool s); static const QColor m_avgColor[4]; static const QColor m_decayedPeakColor[4]; diff --git a/sdrgui/gui/scaleengine.cpp b/sdrgui/gui/scaleengine.cpp index b1587e931..c65d02831 100644 --- a/sdrgui/gui/scaleengine.cpp +++ b/sdrgui/gui/scaleengine.cpp @@ -36,20 +36,20 @@ QString ScaleEngine::formatTick(double value, int decimalPlaces) { if (m_physicalUnit != Unit::TimeHMS) { - if (m_physicalUnit == Unit::Scientific) { + if (m_physicalUnit == Unit::Scientific) { return QString("%1").arg(m_makeOpposite ? -value : value, 0, 'e', m_fixedDecimalPlaces); - } else { - return QString("%1%2%3") + } else { + return QString("%1%2%3") .arg(m_truncated ? "'" : "") .arg(m_makeOpposite ? -value : value, 0, 'f', decimalPlaces) .arg(m_truncated ? m_multiplierStr : ""); - } + } } else { if (m_scale < 1.0f) { // sub second prints just as is - return QString("%1").arg(m_makeOpposite ? -value : value, 0, 'f', decimalPlaces); - } + return QString("%1").arg(m_makeOpposite ? -value : value, 0, 'f', decimalPlaces); + } QString str; double actual = value * m_scale; // this is the actual value in seconds @@ -66,7 +66,7 @@ QString ScaleEngine::formatTick(double value, int decimalPlaces) str += QString("%1.").arg(tmp, 0, 'f', 0); actual -= tmp * 86400.0; - if (actual < 0.0) { + if (actual < 0.0) { actual *= -1.0; } } @@ -197,6 +197,10 @@ void ScaleEngine::calcScaleFactor() m_unitStr = QString("dB"); break; + case Unit::SUnits: + m_unitStr = QString("S"); + break; + case Unit::DecibelMilliWatt: m_unitStr = QString("dBm"); break; @@ -223,9 +227,9 @@ void ScaleEngine::calcScaleFactor() m_unitStr = QString("s"); m_multiplierStr = ""; } else { - m_unitStr = QString("ks"); + m_unitStr = QString("ks"); m_multiplierStr = "k"; - m_scale = 1000.0; + m_scale = 1000.0; } break; @@ -393,6 +397,15 @@ void ScaleEngine::forceTwoTicks() } void ScaleEngine::reCalc() +{ + if (m_physicalUnit == Unit::SUnits) { + reCalcS(); + } else { + reCalcStd(); + } +} + +void ScaleEngine::reCalcStd() { float majorTickSize; double rangeMinScaled; @@ -430,7 +443,7 @@ void ScaleEngine::reCalc() rangeMinScaled = rangeMin / m_scale; rangeMaxScaled = rangeMax / m_scale; - if(m_orientation == Qt::Vertical) + if (m_orientation == Qt::Vertical) { maxNumMajorTicks = (int)(m_size / (fontMetrics.lineSpacing() * 1.3f)); m_majorTickValueDistance = calcMajorTickUnits((rangeMaxScaled - rangeMinScaled) / maxNumMajorTicks, &m_decimalPlaces); @@ -439,10 +452,10 @@ void ScaleEngine::reCalc() { majorTickSize = (calcTickTextSize((rangeMaxScaled - rangeMinScaled) / 20) + 2) * m_charSize; - if(majorTickSize != 0.0) { - maxNumMajorTicks = (int)(m_size / majorTickSize); + if (majorTickSize != 0.0) { + maxNumMajorTicks = (int)(m_size / majorTickSize); } else { - maxNumMajorTicks = 20; + maxNumMajorTicks = 20; } m_majorTickValueDistance = calcMajorTickUnits((rangeMaxScaled - rangeMinScaled) / maxNumMajorTicks, &m_decimalPlaces); @@ -450,29 +463,33 @@ void ScaleEngine::reCalc() numMajorTicks = (int)((rangeMaxScaled - rangeMinScaled) / m_majorTickValueDistance); - if(numMajorTicks == 0) { + if (numMajorTicks == 0) + { forceTwoTicks(); return; } if(maxNumMajorTicks > 0) m_numMinorTicks = (int)(m_size / (maxNumMajorTicks * fontMetrics.height())); - else m_numMinorTicks = 0; - if(m_numMinorTicks < 1) + else + m_numMinorTicks = 0; + + if (m_numMinorTicks < 1) m_numMinorTicks = 0; - else if(m_numMinorTicks < 2) + else if (m_numMinorTicks < 2) m_numMinorTicks = 1; - else if(m_numMinorTicks < 5) + else if (m_numMinorTicks < 5) m_numMinorTicks = 2; - else if(m_numMinorTicks < 10) + else if (m_numMinorTicks < 10) m_numMinorTicks = 5; - else m_numMinorTicks = 10; + else + m_numMinorTicks = 10; m_firstMajorTickValue = floor(rangeMinScaled / m_majorTickValueDistance) * m_majorTickValueDistance; skip = 0; - if(rangeMinScaled == rangeMaxScaled) + if (rangeMinScaled == rangeMaxScaled) return; while (true) @@ -490,25 +507,33 @@ void ScaleEngine::reCalc() for (j = 1; j < m_numMinorTicks; j++) { value2 = value + minorTickValue(j); - if(value2 < rangeMinScaled) + + if (value2 < rangeMinScaled) continue; - if(value2 > rangeMaxScaled) + + if (value2 > rangeMaxScaled) break; - pos = getPosFromValueTrunc((value + minorTickValue(j)) * m_scale); - if((pos >= 0) && (pos < m_size)) { + + pos = getPosFromValueTrunc((value + minorTickValue(j)) * m_scale); + + if ((pos >= 0) && (pos < m_size)) + { tick.pos = pos; tick.major = false; tick.textPos = -1; tick.textSize = -1; tick.text.clear(); } + m_tickList.append(tick); } pos = getPosFromValueTrunc(value * m_scale); - if(pos < 0.0) + + if (pos < 0.0) continue; - if(pos >= m_size) + + if (pos >= m_size) break; tick.pos = pos; @@ -517,49 +542,295 @@ void ScaleEngine::reCalc() tick.textSize = -1; tick.text.clear(); - if(step % (skip + 1) != 0) { + if (step % (skip + 1) != 0) + { m_tickList.append(tick); step++; continue; } - step++; + step++; str = formatTick(value, m_decimalPlaces); tick.text = str; tick.textSize = fontMetrics.boundingRect(tick.text).width(); - if(m_orientation == Qt::Vertical) { + + if (m_orientation == Qt::Vertical) + { tick.textPos = pos - fontMetrics.ascent() / 2; endPos = tick.textPos + fontMetrics.ascent(); - } else { + } + else + { tick.textPos = pos - fontMetrics.boundingRect(tick.text).width() / 2; endPos = tick.textPos + tick.textSize; } - if(lastEndPos >= tick.textPos) { + if (lastEndPos >= tick.textPos) + { done = false; break; - } else { + } + else + { lastEndPos = endPos; } m_tickList.append(tick); } - if(done) + + if (done) break; - skip++; + + skip++; } // make sure we have at least two major ticks with numbers numMajorTicks = 0; - for(i = 0; i < m_tickList.count(); i++) { + + for (i = 0; i < m_tickList.count(); i++) + { tick = m_tickList.at(i); - if(tick.major) + + if (tick.major) numMajorTicks++; } - if(numMajorTicks < 2) + + if (numMajorTicks < 2) forceTwoTicks(); } +void ScaleEngine::reCalcS() +{ + float majorTickSize; + double rangeMinScaled; + double rangeMaxScaled; + int maxNumMajorTicks; + int numMajorTicks; + Tick tick; + QString str; + QFontMetricsF fontMetrics(m_font); + + if (!m_recalc) { + return; + } + + updateTruncation(); + + m_recalc = false; + m_tickList.clear(); + + calcScaleFactor(); + + double rangeMin = m_truncated ? m_rangeMin - m_truncationValue : m_rangeMin; + double rangeMax = m_truncated ? m_rangeMax - m_truncationValue : m_rangeMax; + + rangeMinScaled = rangeMin / m_scale; + rangeMaxScaled = rangeMax / m_scale; + + if (m_orientation == Qt::Vertical) + { + maxNumMajorTicks = (int)(m_size / (fontMetrics.lineSpacing() * 1.3f)); + m_majorTickValueDistance = calcMajorTickUnits((rangeMaxScaled - rangeMinScaled) / maxNumMajorTicks, &m_decimalPlaces); + } + else + { + majorTickSize = (calcTickTextSize((rangeMaxScaled - rangeMinScaled) / 20) + 2) * m_charSize; + + if (majorTickSize != 0.0) { + maxNumMajorTicks = (int)(m_size / majorTickSize); + } else { + maxNumMajorTicks = 20; + } + + m_majorTickValueDistance = calcMajorTickUnits((rangeMaxScaled - rangeMinScaled) / maxNumMajorTicks, &m_decimalPlaces); + } + + numMajorTicks = (int)((rangeMaxScaled - rangeMinScaled) / m_majorTickValueDistance); + + if (numMajorTicks == 0) + { + forceTwoTicks(); + return; + } + + if (maxNumMajorTicks > 0) + m_numMinorTicks = (int)(m_size / (maxNumMajorTicks * fontMetrics.height())); + else + m_numMinorTicks = 0; + + if (m_numMinorTicks < 1) + m_numMinorTicks = 0; + else if (m_numMinorTicks < 2) + m_numMinorTicks = 1; + else if (m_numMinorTicks < 5) + m_numMinorTicks = 2; + else if (m_numMinorTicks < 10) + m_numMinorTicks = 5; + else + m_numMinorTicks = 10; + + m_firstMajorTickValue = floor(rangeMinScaled / m_majorTickValueDistance) * m_majorTickValueDistance; + // skip = 0; + + if (rangeMinScaled == rangeMaxScaled) + return; + + if (rangeMinScaled > -73.0) { + return; + } + + if (rangeMaxScaled < -73.0) { + return; + } + + // qDebug("ScaleEngine::reCalcS: m_numMinorTicks: %d maxNumMajorTicks: %d m_firstMajorTickValue: %le rangeMinScaled: %le rangeMaxScaled: %le", + // m_numMinorTicks, maxNumMajorTicks, m_firstMajorTickValue, rangeMinScaled, rangeMaxScaled); + + std::vector sVals; + std::vector dbVals; + + int nbSVals = ((int) (-73.0 - rangeMinScaled)) / 6; + double sFloor = -73.0 - (double) nbSVals*6; + + for (int i = 0; i < nbSVals; i++) { + sVals.push_back(sFloor + 6*i); + } + + sVals.push_back(-73.0); + + int nbDbVals = ((int) (rangeMaxScaled - -73.0)) / 10; + + for (int i = 1; i < nbDbVals; i++) { + dbVals.push_back(-73.0 + 10*i); + } + + truncS(maxNumMajorTicks, sVals, dbVals); + + double minTickShiftS = 0.0; + double minTickShiftDb = 0.0; + m_tickList.clear(); + + if ((m_numMinorTicks > 1) && (sVals.size() > 1)) { + minTickShiftS = (sVals[1] - sVals[0]) / m_numMinorTicks; + } + + if ((m_numMinorTicks > 1) && (dbVals.size() > 1)) { + minTickShiftDb = (dbVals[1] - dbVals[0]) / m_numMinorTicks; + } + + for (auto sVal : sVals) + { + int s = (int) (sVal + 6*9 - -73.0) / 6; + // qDebug("ScaleEngine::reCalcS: S : %le (%d)", sVal, s); + tick.pos = getPosFromValue(sVal); + tick.major = true; + tick.textPos = -1; + tick.textSize = -1; + tick.text.clear(); + tick.text = QString("%1").arg(s); + adjustText(fontMetrics, tick); + m_tickList.append(tick); + + if (s == 9) + { + if (dbVals.size() != 0) + { + tick.pos = getPosFromValue(sVal + minTickShiftDb); + tick.major = false; + tick.textPos = -1; + tick.textSize = -1; + tick.text.clear(); + m_tickList.append(tick); + } + } + else + { + for (int i = 1; i < m_numMinorTicks; i++) + { + tick.pos = getPosFromValue(sVal + i*(minTickShiftS / (m_numMinorTicks - 1))); + tick.major = false; + tick.textPos = -1; + tick.textSize = -1; + tick.text.clear(); + m_tickList.append(tick); + } + } + } + + for (auto dbVal : dbVals) + { + int db = (int) (dbVal - -73.0); + // qDebug("ScaleEngine::reCalcS: dB: %le (+%d)", dbVal, db); + tick.pos = getPosFromValue(dbVal); + tick.major = true; + tick.textPos = -1; + tick.textSize = -1; + tick.text.clear(); + tick.text = QString("+%1").arg(db); + adjustText(fontMetrics, tick); + m_tickList.append(tick); + + for (int i = 1; i < m_numMinorTicks; i++) + { + tick.pos = getPosFromValue(dbVal + i*(minTickShiftDb / (m_numMinorTicks - 1))); + tick.major = false; + tick.textPos = -1; + tick.textSize = -1; + tick.text.clear(); + m_tickList.append(tick); + } + } +} + +void ScaleEngine::truncS(int nbMaxTicks, std::vector& sVals, std::vector& dbVals) +{ + int nbAvailDb = nbMaxTicks - (int) sVals.size(); + + if (nbAvailDb <= 0) + { + dbVals.clear(); + + if (nbMaxTicks == (int) sVals.size()) { + return; + } + + std::vector newSVals; + int n = sVals.size() / nbMaxTicks; + + for (int i = 0; n*i < (int) sVals.size(); i++) { + newSVals.push_back(sVals[sVals.size() -1 -n*i]); + } + + sVals = newSVals; + } + + if (nbAvailDb < (int) dbVals.size()) + { + std::vector newDbVals; + int n = dbVals.size() / nbAvailDb; + + for (int i = 0; n*i < (int) dbVals.size(); i++) { + newDbVals.push_back(dbVals[n*i]); + } + + dbVals = newDbVals; + } +} + +void ScaleEngine::adjustText(const QFontMetricsF& fontMetrics, Tick& tick) +{ + tick.textSize = fontMetrics.boundingRect(tick.text).width(); + + if (m_orientation == Qt::Vertical) + { + tick.textPos = tick.pos - fontMetrics.ascent() / 2; + } + else + { + tick.textPos = tick.pos - fontMetrics.boundingRect(tick.text).width() / 2; + } +} + double ScaleEngine::majorTickValue(int tick) { return m_firstMajorTickValue + (tick * m_majorTickValueDistance); @@ -569,6 +840,7 @@ double ScaleEngine::minorTickValue(int tick) { if(m_numMinorTicks < 1) return 0.0; + return (m_majorTickValueDistance * tick) / m_numMinorTicks; } diff --git a/sdrgui/gui/scaleengine.h b/sdrgui/gui/scaleengine.h index 46552c9a6..2ca92f38f 100644 --- a/sdrgui/gui/scaleengine.h +++ b/sdrgui/gui/scaleengine.h @@ -94,6 +94,10 @@ private: int calcTickTextSize(double distance); void forceTwoTicks(); void reCalc(); + void reCalcStd(); + void reCalcS(); + void truncS(int nbMaxTicks, std::vector& sVals, std::vector& dbVals); + void adjustText(const QFontMetricsF& fontMetrics, Tick& tick); void updateTruncation(); inline int order(double value) { diff --git a/wdsp/channel.hpp b/wdsp/channel.hpp index d46e21e36..ae04cd4ae 100644 --- a/wdsp/channel.hpp +++ b/wdsp/channel.hpp @@ -28,8 +28,6 @@ warren@wpratt.com #ifndef wdsp_channel_h #define wdsp_channel_h -#include - #include #include "export.h" @@ -55,7 +53,7 @@ public: int bfo; // 'block_for_output', block fexchange until output is available volatile long flushflag; QThread channelThread; - std::atomic upslew; + long upslew; // struct //io buffers // { // IOB pc, pd, pe, pf; // copies for console calls, dsp, exchange, and flush thread diff --git a/wdsp/meter.cpp b/wdsp/meter.cpp index 095f0b1a4..1ab61d4ae 100644 --- a/wdsp/meter.cpp +++ b/wdsp/meter.cpp @@ -81,10 +81,11 @@ void METER::flush_meter (METER *a) { a->avg = 0.0; a->peak = 0.0; - a->result[a->enum_av] = -400.0; - a->result[a->enum_pk] = -400.0; + a->result[a->enum_av] = -100.0; + a->result[a->enum_pk] = -100.0; + if ((a->pgain != 0) && (a->enum_gain >= 0)) - a->result[a->enum_gain] = -400.0; + a->result[a->enum_gain] = 0.0; } void METER::xmeter (METER *a) @@ -107,7 +108,9 @@ void METER::xmeter (METER *a) smag = a->buff[2 * i + 0] * a->buff[2 * i + 0] + a->buff[2 * i + 1] * a->buff[2 * i + 1]; a->avg = a->avg * a->mult_average + (1.0 - a->mult_average) * smag; a->peak *= a->mult_peak; - if (smag > np) np = smag; + + if (smag > np) + np = smag; } if (np > a->peak) @@ -121,9 +124,12 @@ void METER::xmeter (METER *a) } else { - if (a->enum_av >= 0) a->result[a->enum_av] = -400.0; - if (a->enum_pk >= 0) a->result[a->enum_pk] = -400.0; - if (a->enum_gain >= 0) a->result[a->enum_gain] = 0.0; + if (a->enum_av >= 0) + a->result[a->enum_av] = -100.0; + if (a->enum_pk >= 0) + a->result[a->enum_pk] = -100.0; + if (a->enum_gain >= 0) + a->result[a->enum_gain] = 0.0; } } @@ -152,8 +158,7 @@ void METER::setSize_meter (METER *a, int size) double METER::GetMeter (RXA& rxa, int mt) { - double val; - val = rxa.meter[mt]; + double val = rxa.meter[mt]; return val; } @@ -165,8 +170,7 @@ double METER::GetMeter (RXA& rxa, int mt) double METER::GetMeter (TXA& txa, int mt) { - double val; - val = txa.meter[mt]; + double val = txa.meter[mt]; return val; }