1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 17:58:43 -05:00

SSB Demod: updated bandwidths maangement to same algorithms as with SSB Modulator. Makes code clearer and simpler

This commit is contained in:
f4exb 2017-11-03 03:30:24 +01:00
parent 0142b082b3
commit b620c8a5fa
3 changed files with 83 additions and 184 deletions

View File

@ -103,42 +103,9 @@ void SSBDemodGUI::on_audioFlipChannels_toggled(bool flip)
applySettings();
}
void SSBDemodGUI::on_dsb_toggled(bool dsb)
void SSBDemodGUI::on_dsb_toggled(bool dsb __attribute__((unused)))
{
m_dsb = dsb;
m_settings.m_dsb = dsb;
if (m_dsb)
{
if (ui->BW->value() < 0) {
ui->BW->setValue(-ui->BW->value());
}
m_channelMarker.setSidebands(ChannelMarker::dsb);
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);
applySettings();
}
else
{
if (ui->BW->value() < 0) {
m_channelMarker.setSidebands(ChannelMarker::lsb);
} else {
m_channelMarker.setSidebands(ChannelMarker::usb);
}
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);
}
setNewRate(m_spanLog2);
applyBandwidths();
}
void SSBDemodGUI::on_deltaFrequency_changed(qint64 value)
@ -148,66 +115,14 @@ void SSBDemodGUI::on_deltaFrequency_changed(qint64 value)
applySettings();
}
void SSBDemodGUI::on_BW_valueChanged(int value)
void SSBDemodGUI::on_BW_valueChanged(int value __attribute__((unused)))
{
QString s = QString::number(value/10.0, 'f', 1);
m_channelMarker.setBandwidth(value * 100 * 2);
if (m_dsb)
{
ui->BWText->setText(tr("%1%2k").arg(QChar(0xB1, 0x00)).arg(s));
}
else
{
ui->BWText->setText(tr("%1k").arg(s));
}
m_settings.m_rfBandwidth = value * 100;
on_lowCut_valueChanged(m_channelMarker.getLowCutoff()/100);
setNewRate(m_spanLog2);
applyBandwidths();
}
int SSBDemodGUI::getEffectiveLowCutoff(int lowCutoff)
void SSBDemodGUI::on_lowCut_valueChanged(int value __attribute__((unused)))
{
int ssbBW = m_channelMarker.getBandwidth() / 2;
int effectiveLowCutoff = lowCutoff;
const int guard = 100;
if (ssbBW < 0)
{
if (effectiveLowCutoff < ssbBW + guard)
{
effectiveLowCutoff = ssbBW + guard;
}
if (effectiveLowCutoff > 0)
{
effectiveLowCutoff = 0;
}
}
else
{
if (effectiveLowCutoff > ssbBW - guard)
{
effectiveLowCutoff = ssbBW - guard;
}
if (effectiveLowCutoff < 0)
{
effectiveLowCutoff = 0;
}
}
return effectiveLowCutoff;
}
void SSBDemodGUI::on_lowCut_valueChanged(int value)
{
int lowCutoff = getEffectiveLowCutoff(value * 100);
m_channelMarker.setLowCutoff(lowCutoff);
QString s = QString::number(lowCutoff/1000.0, 'f', 1);
ui->lowCutText->setText(tr("%1k").arg(s));
ui->lowCut->setValue(lowCutoff/100);
m_settings.m_lowCutoff = lowCutoff;
applySettings();
applyBandwidths();
}
void SSBDemodGUI::on_volume_valueChanged(int value)
@ -261,12 +176,11 @@ void SSBDemodGUI::on_audioMute_toggled(bool checked)
void SSBDemodGUI::on_spanLog2_valueChanged(int value)
{
if (setNewRate(value))
{
m_settings.m_spanLog2 = value;
applySettings();
}
if ((value < 1) || (value > 5)) {
return;
}
applyBandwidths();
}
void SSBDemodGUI::onWidgetRolled(QWidget* widget __attribute__((unused)), bool rollDown __attribute__((unused)))
@ -295,11 +209,8 @@ SSBDemodGUI::SSBDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, QWidget
m_channelMarker(this),
m_basicSettingsShown(false),
m_doApplySettings(true),
m_rate(6000),
m_spanLog2(3),
m_audioBinaural(false),
m_audioFlipChannels(false),
m_dsb(false),
m_audioMute(false),
m_squelchOpen(false)
{
@ -338,8 +249,7 @@ SSBDemodGUI::SSBDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, QWidget
ui->spectrumGUI->setBuddies(m_spectrumVis->getInputMessageQueue(), m_spectrumVis, ui->glSpectrum);
displaySettings();
applySettings(true);
setNewRate(m_spanLog2);
applyBandwidths(true);
}
SSBDemodGUI::~SSBDemodGUI()
@ -350,82 +260,6 @@ SSBDemodGUI::~SSBDemodGUI()
delete ui;
}
bool SSBDemodGUI::setNewRate(int spanLog2)
{
if ((spanLog2 < 1) || (spanLog2 > 5))
{
return false;
}
m_spanLog2 = spanLog2;
m_rate = 48000 / (1<<spanLog2);
if (ui->BW->value() < -m_rate/100)
{
ui->BW->setValue(-m_rate/100);
m_channelMarker.setBandwidth(-m_rate*2);
}
else if (ui->BW->value() > m_rate/100)
{
ui->BW->setValue(m_rate/100);
m_channelMarker.setBandwidth(m_rate*2);
}
if (ui->lowCut->value() < -m_rate/100)
{
ui->lowCut->setValue(-m_rate/100);
m_channelMarker.setLowCutoff(-m_rate);
}
else if (ui->lowCut->value() > m_rate/100)
{
ui->lowCut->setValue(m_rate/100);
m_channelMarker.setLowCutoff(m_rate);
}
QString s = QString::number(m_rate/1000.0, 'f', 1);
if (m_dsb)
{
ui->BW->setMinimum(0);
ui->BW->setMaximum(m_rate/100);
ui->lowCut->setMinimum(0);
ui->lowCut->setMaximum(m_rate/100);
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
{
ui->BW->setMinimum(-m_rate/100);
ui->BW->setMaximum(m_rate/100);
ui->lowCut->setMinimum(-m_rate/100);
ui->lowCut->setMaximum(m_rate/100);
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;
}
void SSBDemodGUI::blockApplySettings(bool block)
{
m_doApplySettings = !block;
@ -447,6 +281,76 @@ void SSBDemodGUI::applySettings(bool force)
}
}
void SSBDemodGUI::applyBandwidths(bool force)
{
bool dsb = ui->dsb->isChecked();
int spanLog2 = ui->spanLog2->value();
int bw = ui->BW->value();
int lw = ui->lowCut->value();
int bwMax = 480/(1<<spanLog2);
bw = bw < -bwMax ? -bwMax : bw > bwMax ? bwMax : bw;
if (bw < 0) {
lw = lw < bw+1 ? bw+1 : lw < 0 ? lw : 0;
} else if (bw > 0) {
lw = lw > bw-1 ? bw-1 : lw < 0 ? 0 : lw;
} else {
lw = 0;
}
if (dsb)
{
bw = bw < 0 ? -bw : bw;
lw = 0;
}
QString spanStr = QString::number(bwMax/10.0, 'f', 1);
QString bwStr = QString::number(bw/10.0, 'f', 1);
QString lwStr = QString::number(lw/10.0, 'f', 1);
if (dsb)
{
ui->BWText->setText(tr("%1%2k").arg(QChar(0xB1, 0x00)).arg(bwStr));
ui->spanText->setText(tr("%1%2k").arg(QChar(0xB1, 0x00)).arg(spanStr));
}
else
{
ui->BWText->setText(tr("%1k").arg(bwStr));
ui->spanText->setText(tr("%1k").arg(spanStr));
}
ui->lowCutText->setText(tr("%1k").arg(lwStr));
ui->BW->blockSignals(true);
ui->lowCut->blockSignals(true);
ui->BW->setMaximum(bwMax);
ui->BW->setMinimum(dsb ? 0 : -bwMax);
ui->BW->setValue(bw);
ui->lowCut->setMaximum(dsb ? 0 : bwMax);
ui->lowCut->setMinimum(dsb ? 0 : -bwMax);
ui->lowCut->setValue(lw);
ui->lowCut->blockSignals(false);
ui->BW->blockSignals(false);
m_settings.m_dsb = dsb;
m_settings.m_spanLog2 = spanLog2;
m_settings.m_rfBandwidth = bw * 100;
m_settings.m_lowCutoff = lw * 100;
applySettings(force);
blockApplySettings(true);
m_channelMarker.setBandwidth(bw * 200);
m_channelMarker.setSidebands(dsb ? ChannelMarker::dsb : bw < 0 ? ChannelMarker::lsb : ChannelMarker::usb);
blockApplySettings(false);
}
void SSBDemodGUI::displaySettings()
{
m_channelMarker.blockSignals(true);

View File

@ -67,11 +67,8 @@ private:
SSBDemodSettings m_settings;
bool m_basicSettingsShown;
bool m_doApplySettings;
int m_rate;
int m_spanLog2;
bool m_audioBinaural;
bool m_audioFlipChannels;
bool m_dsb;
bool m_audioMute;
bool m_squelchOpen;
uint32_t m_tickCount;
@ -83,11 +80,9 @@ private:
explicit SSBDemodGUI(PluginAPI* pluginAPI, DeviceUISet* deviceUISet, QWidget* parent = 0);
virtual ~SSBDemodGUI();
int getEffectiveLowCutoff(int lowCutoff);
bool setNewRate(int spanLog2);
void blockApplySettings(bool block);
void applySettings(bool force = false);
void applyBandwidths(bool force = false);
void displaySettings();
void displayUDPAddress();

View File

@ -7,7 +7,7 @@
const PluginDescriptor SSBPlugin::m_pluginDescriptor = {
QString("SSB Demodulator"),
QString("3.8.0"),
QString("3.8.1"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,