1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-09-02 13:17:48 -04:00

UDPSrc plugin: partial squelch implementation

This commit is contained in:
f4exb 2017-08-17 20:23:17 +02:00
parent 315d408eee
commit c6b58431fe
9 changed files with 177 additions and 17 deletions

View File

@ -35,6 +35,8 @@ UDPSrc::UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, BasebandSampl
m_audioStereo(false), m_audioStereo(false),
m_volume(20), m_volume(20),
m_fmDeviation(2500), m_fmDeviation(2500),
m_outMovingAverage(480, 1e-10),
m_inMovingAverage(480, 1e-10),
m_audioFifo(4, 24000), m_audioFifo(4, 24000),
m_settingsMutex(QMutex::Recursive) m_settingsMutex(QMutex::Recursive)
{ {
@ -67,6 +69,7 @@ UDPSrc::UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, BasebandSampl
m_this = 0; m_this = 0;
m_scale = 0; m_scale = 0;
m_magsq = 0; m_magsq = 0;
m_inMagsq = 0;
UDPFilter = new fftfilt(0.0, (m_rfBandwidth / 2.0) / m_outputSampleRate, udpBlockSize); UDPFilter = new fftfilt(0.0, (m_rfBandwidth / 2.0) / m_outputSampleRate, udpBlockSize);
m_phaseDiscri.setFMScaling((float) m_outputSampleRate / (2.0f * m_fmDeviation)); m_phaseDiscri.setFMScaling((float) m_outputSampleRate / (2.0f * m_fmDeviation));
@ -117,13 +120,17 @@ void UDPSrc::configureImmediate(MessageQueue* messageQueue,
bool audioActive, bool audioActive,
bool audioStereo, bool audioStereo,
Real boost, Real boost,
int volume) int volume,
Real squelchDB,
bool squelchEnabled)
{ {
Message* cmd = MsgUDPSrcConfigureImmediate::create( Message* cmd = MsgUDPSrcConfigureImmediate::create(
audioActive, audioActive,
audioStereo, audioStereo,
boost, boost,
volume); volume,
squelchDB,
squelchEnabled);
messageQueue->push(cmd); messageQueue->push(cmd);
} }
@ -149,7 +156,13 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector:
if(m_interpolator.decimate(&m_sampleDistanceRemain, c, &ci)) if(m_interpolator.decimate(&m_sampleDistanceRemain, c, &ci))
{ {
m_magsq = ((ci.real()*ci.real() + ci.imag()*ci.imag())*m_gain*m_gain) / (1<<30); double inMagSq = ci.real()*ci.real() + ci.imag()*ci.imag();
//m_magsq = (inMagSq*m_gain*m_gain) / (1<<30);
m_outMovingAverage.feed((inMagSq*m_gain*m_gain) / (1<<30));
m_inMovingAverage.feed(inMagSq / (1<<30));
m_magsq = m_outMovingAverage.average();
m_inMagsq = m_inMovingAverage.average();
Sample s(ci.real() * m_gain, ci.imag() * m_gain); Sample s(ci.real() * m_gain, ci.imag() * m_gain);
m_sampleBuffer.push_back(s); m_sampleBuffer.push_back(s);
m_sampleDistanceRemain += m_inputSampleRate / m_outputSampleRate; m_sampleDistanceRemain += m_inputSampleRate / m_outputSampleRate;
@ -220,7 +233,7 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector:
} }
else if (m_sampleFormat == FormatAMMono) else if (m_sampleFormat == FormatAMMono)
{ {
FixReal demod = (FixReal) (32768.0f * sqrt(m_magsq)); FixReal demod = (FixReal) (32768.0f * sqrt(inMagSq) * m_gain);
m_udpBufferMono->write(demod); m_udpBufferMono->write(demod);
} }
else // Raw I/Q samples else // Raw I/Q samples
@ -371,6 +384,9 @@ bool UDPSrc::handleMessage(const Message& cmd)
m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate; m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate;
UDPFilter->create_filter(0.0, (m_rfBandwidth / 2.0) / m_outputSampleRate); UDPFilter->create_filter(0.0, (m_rfBandwidth / 2.0) / m_outputSampleRate);
m_inMovingAverage.resize(m_inputSampleRate * 0.01, 1e-10); // 10 ms
m_outMovingAverage.resize(m_outputSampleRate * 0.01, 1e-10); // 10 ms
m_settingsMutex.unlock(); m_settingsMutex.unlock();
qDebug() << "UDPSrc::handleMessage: MsgUDPSrcConfigure: m_sampleFormat: " << m_sampleFormat qDebug() << "UDPSrc::handleMessage: MsgUDPSrcConfigure: m_sampleFormat: " << m_sampleFormat

View File

@ -25,6 +25,7 @@
#include "dsp/fftfilt.h" #include "dsp/fftfilt.h"
#include "dsp/interpolator.h" #include "dsp/interpolator.h"
#include "dsp/phasediscri.h" #include "dsp/phasediscri.h"
#include "dsp/movingaverage.h"
#include "util/udpsink.h" #include "util/udpsink.h"
#include "util/message.h" #include "util/message.h"
#include "audio/audiofifo.h" #include "audio/audiofifo.h"
@ -71,9 +72,12 @@ public:
bool audioActive, bool audioActive,
bool audioStereo, bool audioStereo,
Real gain, Real gain,
int volume); int volume,
Real squelchDB,
bool squelchEnabled);
void setSpectrum(MessageQueue* messageQueue, bool enabled); void setSpectrum(MessageQueue* messageQueue, bool enabled);
double getMagSq() const { return m_magsq; } double getMagSq() const { return m_magsq; }
double getInMagSq() const { return m_inMagsq; }
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly);
virtual void start(); virtual void start();
@ -151,36 +155,48 @@ protected:
int getVolume() const { return m_volume; } int getVolume() const { return m_volume; }
bool getAudioActive() const { return m_audioActive; } bool getAudioActive() const { return m_audioActive; }
bool getAudioStereo() const { return m_audioStereo; } bool getAudioStereo() const { return m_audioStereo; }
Real getSquelchDB() const { return m_squelchDB; }
bool getSquelchEnabled() const { return m_squelchEnabled; }
static MsgUDPSrcConfigureImmediate* create( static MsgUDPSrcConfigureImmediate* create(
bool audioActive, bool audioActive,
bool audioStereo, bool audioStereo,
int boost, int boost,
int volume) int volume,
Real squelchDB,
bool squelchEnabled)
{ {
return new MsgUDPSrcConfigureImmediate( return new MsgUDPSrcConfigureImmediate(
audioActive, audioActive,
audioStereo, audioStereo,
boost, boost,
volume); volume,
squelchDB,
squelchEnabled);
} }
private: private:
Real m_gain; Real m_gain;
int m_volume; int m_volume;
bool m_audioActive; bool m_audioActive;
bool m_audioStereo; bool m_audioStereo;
Real m_squelchDB;
bool m_squelchEnabled;
MsgUDPSrcConfigureImmediate( MsgUDPSrcConfigureImmediate(
bool audioActive, bool audioActive,
bool audioStereo, bool audioStereo,
Real gain, Real gain,
int volume) : int volume,
Real squelchDB,
bool squelchEnabled) :
Message(), Message(),
m_gain(gain), m_gain(gain),
m_volume(volume), m_volume(volume),
m_audioActive(audioActive), m_audioActive(audioActive),
m_audioStereo(audioStereo) m_audioStereo(audioStereo),
m_squelchDB(squelchDB),
m_squelchEnabled(squelchEnabled)
{ } { }
}; };
@ -222,6 +238,9 @@ protected:
int m_volume; int m_volume;
int m_fmDeviation; int m_fmDeviation;
double m_magsq; double m_magsq;
double m_inMagsq;
MovingAverage<double> m_outMovingAverage;
MovingAverage<double> m_inMovingAverage;
Real m_scale; Real m_scale;
Complex m_last, m_this; Complex m_last, m_this;

View File

@ -105,6 +105,7 @@ QByteArray UDPSrcGUI::serialize() const
s.writeS32(13, m_audioPort); s.writeS32(13, m_audioPort);
s.writeBool(14, m_audioStereo); s.writeBool(14, m_audioStereo);
s.writeS32(15, m_fmDeviation); s.writeS32(15, m_fmDeviation);
s.writeS32(16, ui->squelch->value());
return s.final(); return s.final();
} }
@ -189,6 +190,9 @@ bool UDPSrcGUI::deserialize(const QByteArray& data)
ui->audioStereo->setChecked(booltmp); ui->audioStereo->setChecked(booltmp);
d.readS32(15, &s32tmp, 2500); d.readS32(15, &s32tmp, 2500);
ui->fmDeviation->setText(QString("%1").arg(s32tmp)); ui->fmDeviation->setText(QString("%1").arg(s32tmp));
d.readS32(16, &s32tmp, -60);
ui->squelch->setValue(s32tmp);
ui->squelchText->setText(tr("%1").arg(s32tmp*1.0, 0, 'f', 0));
blockApplySettings(false); blockApplySettings(false);
m_channelMarker.blockSignals(false); m_channelMarker.blockSignals(false);
@ -222,6 +226,9 @@ void UDPSrcGUI::tick()
m_channelPowerAvg.feed(m_udpSrc->getMagSq()); m_channelPowerAvg.feed(m_udpSrc->getMagSq());
double powDb = CalcDb::dbPower(m_channelPowerAvg.average()); double powDb = CalcDb::dbPower(m_channelPowerAvg.average());
ui->channelPower->setText(QString::number(powDb, 'f', 1)); ui->channelPower->setText(QString::number(powDb, 'f', 1));
m_inPowerAvg.feed(m_udpSrc->getInMagSq());
double inPowDb = CalcDb::dbPower(m_inPowerAvg.average());
ui->inputPower->setText(QString::number(inPowDb, 'f', 1));
} }
m_tickCount++; m_tickCount++;
@ -235,6 +242,7 @@ UDPSrcGUI::UDPSrcGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget*
m_udpSrc(0), m_udpSrc(0),
m_channelMarker(this), m_channelMarker(this),
m_channelPowerAvg(4, 1e-10), m_channelPowerAvg(4, 1e-10),
m_inPowerAvg(4, 1e-10),
m_tickCount(0), m_tickCount(0),
m_gain(1.0), m_gain(1.0),
m_volume(20), m_volume(20),
@ -307,6 +315,7 @@ void UDPSrcGUI::displaySettings()
{ {
ui->gainText->setText(tr("%1").arg(ui->gain->value()/10.0, 0, 'f', 1)); ui->gainText->setText(tr("%1").arg(ui->gain->value()/10.0, 0, 'f', 1));
ui->volumeText->setText(QString("%1").arg(ui->volume->value())); ui->volumeText->setText(QString("%1").arg(ui->volume->value()));
ui->squelchText->setText(tr("%1").arg(ui->squelch->value()*1.0, 0, 'f', 0));
} }
void UDPSrcGUI::applySettingsImmediate() void UDPSrcGUI::applySettingsImmediate()
@ -322,7 +331,9 @@ void UDPSrcGUI::applySettingsImmediate()
m_audioActive, m_audioActive,
m_audioStereo, m_audioStereo,
m_gain, m_gain,
m_volume); m_volume,
ui->squelch->value() * 1.0f,
ui->squelch->value() != -100);
} }
} }
@ -518,11 +529,24 @@ void UDPSrcGUI::on_gain_valueChanged(int value)
void UDPSrcGUI::on_volume_valueChanged(int value) void UDPSrcGUI::on_volume_valueChanged(int value)
{ {
ui->volume->setValue(value);
ui->volumeText->setText(QString("%1").arg(value)); ui->volumeText->setText(QString("%1").arg(value));
applySettingsImmediate(); applySettingsImmediate();
} }
void UDPSrcGUI::on_squelch_valueChanged(int value)
{
if (value == -100) // means disabled
{
ui->squelchText->setText("---");
}
else
{
ui->squelchText->setText(tr("%1").arg(value*1.0, 0, 'f', 0));
}
applySettingsImmediate();
}
void UDPSrcGUI::onWidgetRolled(QWidget* widget, bool rollDown) void UDPSrcGUI::onWidgetRolled(QWidget* widget, bool rollDown)
{ {
if ((widget == ui->spectrumBox) && (m_udpSrc != 0)) if ((widget == ui->spectrumBox) && (m_udpSrc != 0))

View File

@ -74,6 +74,7 @@ private slots:
void onMenuDoubleClicked(); void onMenuDoubleClicked();
void on_gain_valueChanged(int value); void on_gain_valueChanged(int value);
void on_volume_valueChanged(int value); void on_volume_valueChanged(int value);
void on_squelch_valueChanged(int value);
void tick(); void tick();
private: private:
@ -83,6 +84,7 @@ private:
UDPSrc* m_udpSrc; UDPSrc* m_udpSrc;
ChannelMarker m_channelMarker; ChannelMarker m_channelMarker;
MovingAverage<double> m_channelPowerAvg; MovingAverage<double> m_channelPowerAvg;
MovingAverage<double> m_inPowerAvg;
uint32_t m_tickCount; uint32_t m_tickCount;
// settings // settings

View File

@ -580,6 +580,83 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="1">
<layout class="QHBoxLayout" name="SquelchLayout">
<item>
<widget class="QLabel" name="squelchLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>22</height>
</size>
</property>
<property name="text">
<string>Sq</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="squelch">
<property name="toolTip">
<string>Power squelch threshold (dB)</string>
</property>
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>0</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>-60</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="squelchText">
<property name="minimumSize">
<size>
<width>22</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Power squelch threshold (dB)</string>
</property>
<property name="text">
<string>-00</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="inputPower">
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Input power (dB) to which squelch applies</string>
</property>
<property name="text">
<string>-100.0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="spectrumBox" native="true"> <widget class="QWidget" name="spectrumBox" native="true">

View File

@ -232,6 +232,7 @@ bool UDPSink::handleMessage(const Message& cmd)
m_config.m_channelMute = cfg.getChannelMute(); m_config.m_channelMute = cfg.getChannelMute();
m_config.m_gain = cfg.getGain(); m_config.m_gain = cfg.getGain();
m_config.m_squelch = CalcDb::powerFromdB(cfg.getSquelchDB()); m_config.m_squelch = CalcDb::powerFromdB(cfg.getSquelchDB());
m_config.m_squelchEnabled = cfg.getSquelchEnabled();
apply(cfg.getForce()); apply(cfg.getForce());
@ -245,7 +246,8 @@ bool UDPSink::handleMessage(const Message& cmd)
<< " m_channelMute: " << m_config.m_channelMute << " m_channelMute: " << m_config.m_channelMute
<< " m_gain: " << m_config.m_gain << " m_gain: " << m_config.m_gain
<< " squelchDB: " << cfg.getSquelchDB() << " squelchDB: " << cfg.getSquelchDB()
<< " m_squelch: " << m_config.m_squelch; << " m_squelch: " << m_config.m_squelch
<< " m_squelchEnabled: " << m_config.m_squelchEnabled;
return true; return true;
} }
@ -332,6 +334,7 @@ void UDPSink::configure(MessageQueue* messageQueue,
bool channelMute, bool channelMute,
Real gain, Real gain,
Real squelchDB, Real squelchDB,
bool squelchEnabled,
bool force) bool force)
{ {
Message* cmd = MsgUDPSinkConfigure::create(sampleFormat, Message* cmd = MsgUDPSinkConfigure::create(sampleFormat,
@ -343,6 +346,7 @@ void UDPSink::configure(MessageQueue* messageQueue,
channelMute, channelMute,
gain, gain,
squelchDB, squelchDB,
squelchEnabled,
force); force);
messageQueue->push(cmd); messageQueue->push(cmd);
} }

View File

@ -69,6 +69,7 @@ public:
bool channelMute, bool channelMute,
Real gain, Real gain,
Real squelchDB, Real squelchDB,
bool squelchEnabled,
bool force = false); bool force = false);
void setSpectrum(MessageQueue* messageQueue, bool enabled); void setSpectrum(MessageQueue* messageQueue, bool enabled);
@ -95,6 +96,7 @@ private:
bool getChannelMute() const { return m_channelMute; } bool getChannelMute() const { return m_channelMute; }
Real getGain() const { return m_gain; } Real getGain() const { return m_gain; }
Real getSquelchDB() const { return m_squelchDB; } Real getSquelchDB() const { return m_squelchDB; }
bool getSquelchEnabled() const { return m_squelchEnabled; }
bool getForce() const { return m_force; } bool getForce() const { return m_force; }
static MsgUDPSinkConfigure* create(SampleFormat static MsgUDPSinkConfigure* create(SampleFormat
@ -107,6 +109,7 @@ private:
bool channelMute, bool channelMute,
Real gain, Real gain,
Real squelchDB, Real squelchDB,
bool squelchEnabled,
bool force) bool force)
{ {
return new MsgUDPSinkConfigure(sampleFormat, return new MsgUDPSinkConfigure(sampleFormat,
@ -118,6 +121,7 @@ private:
channelMute, channelMute,
gain, gain,
squelchDB, squelchDB,
squelchEnabled,
force); force);
} }
@ -131,6 +135,7 @@ private:
bool m_channelMute; bool m_channelMute;
Real m_gain; Real m_gain;
Real m_squelchDB; Real m_squelchDB;
bool m_squelchEnabled;
bool m_force; bool m_force;
MsgUDPSinkConfigure(SampleFormat sampleFormat, MsgUDPSinkConfigure(SampleFormat sampleFormat,
@ -142,6 +147,7 @@ private:
bool channelMute, bool channelMute,
Real gain, Real gain,
Real squelchDB, Real squelchDB,
bool squelchEnabled,
bool force) : bool force) :
Message(), Message(),
m_sampleFormat(sampleFormat), m_sampleFormat(sampleFormat),
@ -153,6 +159,7 @@ private:
m_channelMute(channelMute), m_channelMute(channelMute),
m_gain(gain), m_gain(gain),
m_squelchDB(squelchDB), m_squelchDB(squelchDB),
m_squelchEnabled(squelchEnabled),
m_force(force) m_force(force)
{ } { }
}; };
@ -188,6 +195,7 @@ private:
bool m_channelMute; bool m_channelMute;
Real m_gain; Real m_gain;
Real m_squelch; //!< squared magnitude Real m_squelch; //!< squared magnitude
bool m_squelchEnabled;
QString m_udpAddressStr; QString m_udpAddressStr;
quint16 m_udpPort; quint16 m_udpPort;
@ -203,6 +211,7 @@ private:
m_channelMute(false), m_channelMute(false),
m_gain(1.0), m_gain(1.0),
m_squelch(-50.0), m_squelch(-50.0),
m_squelchEnabled(true),
m_udpAddressStr("127.0.0.1"), m_udpAddressStr("127.0.0.1"),
m_udpPort(9999) m_udpPort(9999)
{} {}
@ -258,7 +267,7 @@ private:
inline void calculateSquelch(double value) inline void calculateSquelch(double value)
{ {
if (value > m_running.m_squelch) if ((!m_running.m_squelchEnabled) || (value > m_running.m_squelch))
{ {
if (m_squelchOpenCount < m_squelchThreshold) { if (m_squelchOpenCount < m_squelchThreshold) {
m_squelchOpenCount++; m_squelchOpenCount++;

View File

@ -177,7 +177,7 @@ bool UDPSinkGUI::deserialize(const QByteArray& data)
m_channelMarker.setTitle(strtmp); m_channelMarker.setTitle(strtmp);
this->setWindowTitle(m_channelMarker.getTitle()); this->setWindowTitle(m_channelMarker.getTitle());
d.readS32(14, &s32tmp, 10); d.readS32(14, &s32tmp, -60);
ui->squelch->setValue(s32tmp); ui->squelch->setValue(s32tmp);
ui->squelchText->setText(tr("%1").arg(s32tmp*1.0, 0, 'f', 0)); ui->squelchText->setText(tr("%1").arg(s32tmp*1.0, 0, 'f', 0));
@ -398,6 +398,7 @@ void UDPSinkGUI::applySettings(bool force)
ui->channelMute->isChecked(), ui->channelMute->isChecked(),
ui->gain->value() / 10.0f, ui->gain->value() / 10.0f,
ui->squelch->value() * 1.0f, ui->squelch->value() * 1.0f,
ui->squelch->value() != -100,
force); force);
ui->applyBtn->setEnabled(false); ui->applyBtn->setEnabled(false);
@ -465,7 +466,15 @@ void UDPSinkGUI::on_gain_valueChanged(int value)
void UDPSinkGUI::on_squelch_valueChanged(int value) void UDPSinkGUI::on_squelch_valueChanged(int value)
{ {
ui->squelchText->setText(tr("%1").arg(value*1.0, 0, 'f', 0)); if (value == -100) // means disabled
{
ui->squelchText->setText("---");
}
else
{
ui->squelchText->setText(tr("%1").arg(value*1.0, 0, 'f', 0));
}
applySettings(); applySettings();
} }

View File

@ -43,7 +43,7 @@
<x>2</x> <x>2</x>
<y>2</y> <y>2</y>
<width>340</width> <width>340</width>
<height>142</height> <height>141</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">