mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-03 13:47:50 -04:00
UDP source plugin: implemented AM with DC filtering and AGC
This commit is contained in:
parent
4e53552a99
commit
79f53275de
@ -32,11 +32,13 @@ MESSAGE_CLASS_DEFINITION(UDPSrc::MsgUDPSrcSpectrum, Message)
|
||||
UDPSrc::UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, BasebandSampleSink* spectrum) :
|
||||
m_outMovingAverage(480, 1e-10),
|
||||
m_inMovingAverage(480, 1e-10),
|
||||
m_amMovingAverage(480, 1e-10),
|
||||
m_audioFifo(4, 24000),
|
||||
m_squelchOpen(false),
|
||||
m_squelchOpenCount(0),
|
||||
m_squelchCloseCount(0),
|
||||
m_squelchThreshold(4800),
|
||||
m_agc(12000, m_agcTarget, 1e-6),
|
||||
m_settingsMutex(QMutex::Recursive)
|
||||
{
|
||||
setObjectName("UDPSrc");
|
||||
@ -78,6 +80,9 @@ UDPSrc::UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, BasebandSampl
|
||||
qWarning("UDPSrc::UDPSrc: cannot bind audio port");
|
||||
}
|
||||
|
||||
m_agc.setClampMax(32768.0*32768.0);
|
||||
m_agc.setClamping(true);
|
||||
|
||||
//DSPEngine::instance()->addAudioSink(&m_audioFifo);
|
||||
}
|
||||
|
||||
@ -122,6 +127,7 @@ void UDPSrc::configureImmediate(MessageQueue* messageQueue,
|
||||
Real squelchDB,
|
||||
Real squelchGate,
|
||||
bool squelchEnabled,
|
||||
bool agc,
|
||||
bool force)
|
||||
{
|
||||
Message* cmd = MsgUDPSrcConfigureImmediate::create(
|
||||
@ -132,6 +138,7 @@ void UDPSrc::configureImmediate(MessageQueue* messageQueue,
|
||||
squelchDB,
|
||||
squelchGate,
|
||||
squelchEnabled,
|
||||
agc,
|
||||
force);
|
||||
messageQueue->push(cmd);
|
||||
}
|
||||
@ -158,7 +165,21 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector:
|
||||
|
||||
if(m_interpolator.decimate(&m_sampleDistanceRemain, c, &ci))
|
||||
{
|
||||
double inMagSq = ci.real()*ci.real() + ci.imag()*ci.imag();
|
||||
double inMagSq;
|
||||
double agcFactor = 1.0;
|
||||
|
||||
if ((m_running.m_agc) &&
|
||||
(m_running.m_sampleFormat != FormatNFM) &&
|
||||
(m_running.m_sampleFormat != FormatNFMMono) &&
|
||||
(m_running.m_sampleFormat != FormatS16LE))
|
||||
{
|
||||
agcFactor = m_agc.feedAndGetValue(ci);
|
||||
inMagSq = m_agc.getMagSq();
|
||||
}
|
||||
else
|
||||
{
|
||||
inMagSq = ci.real()*ci.real() + ci.imag()*ci.imag();
|
||||
}
|
||||
|
||||
m_inMovingAverage.feed(inMagSq / (1<<30));
|
||||
m_inMagsq = m_inMovingAverage.average();
|
||||
@ -172,6 +193,7 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector:
|
||||
|
||||
if (m_running.m_sampleFormat == FormatLSB) // binaural LSB
|
||||
{
|
||||
ci *= agcFactor;
|
||||
int n_out = UDPFilter->runSSB(ci, &sideband, false);
|
||||
|
||||
if (n_out)
|
||||
@ -187,6 +209,7 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector:
|
||||
}
|
||||
if (m_running.m_sampleFormat == FormatUSB) // binaural USB
|
||||
{
|
||||
ci *= agcFactor;
|
||||
int n_out = UDPFilter->runSSB(ci, &sideband, true);
|
||||
|
||||
if (n_out)
|
||||
@ -214,6 +237,7 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector:
|
||||
}
|
||||
else if (m_running.m_sampleFormat == FormatLSBMono) // Monaural LSB
|
||||
{
|
||||
ci *= agcFactor;
|
||||
int n_out = UDPFilter->runSSB(ci, &sideband, false);
|
||||
|
||||
if (n_out)
|
||||
@ -228,6 +252,7 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector:
|
||||
}
|
||||
else if (m_running.m_sampleFormat == FormatUSBMono) // Monaural USB
|
||||
{
|
||||
ci *= agcFactor;
|
||||
int n_out = UDPFilter->runSSB(ci, &sideband, true);
|
||||
|
||||
if (n_out)
|
||||
@ -242,10 +267,26 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector:
|
||||
}
|
||||
else if (m_running.m_sampleFormat == FormatAMMono)
|
||||
{
|
||||
FixReal demod = m_squelchOpen ? (FixReal) (sqrt(inMagSq) * m_running.m_gain) : 0;
|
||||
FixReal demod = m_squelchOpen ? (FixReal) (sqrt(inMagSq) * agcFactor * m_running.m_gain) : 0;
|
||||
m_udpBufferMono->write(demod);
|
||||
m_outMovingAverage.feed((demod * demod) / (1<<30));
|
||||
m_outMovingAverage.feed((demod * demod) / 1073741824.0);
|
||||
}
|
||||
else if (m_running.m_sampleFormat == FormatAMNoDCMono)
|
||||
{
|
||||
m_amMovingAverage.feed(inMagSq);
|
||||
|
||||
if (m_squelchOpen)
|
||||
{
|
||||
FixReal demod = (FixReal) ((sqrt(inMagSq) - sqrt(m_amMovingAverage.average())) * agcFactor * m_running.m_gain);
|
||||
m_udpBufferMono->write(demod);
|
||||
m_outMovingAverage.feed((demod * demod) / 1073741824.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_udpBufferMono->write(0);
|
||||
m_outMovingAverage.feed(0);
|
||||
}
|
||||
}
|
||||
else // Raw I/Q samples
|
||||
{
|
||||
if (m_squelchOpen)
|
||||
@ -314,6 +355,7 @@ bool UDPSrc::handleMessage(const Message& cmd)
|
||||
m_config.m_squelch = CalcDb::powerFromdB(cfg.getSquelchDB());
|
||||
m_config.m_squelchGate = cfg.getSquelchGate();
|
||||
m_config.m_squelchEnabled = cfg.getSquelchEnabled();
|
||||
m_config.m_agc = cfg.getAGC();
|
||||
|
||||
apply(cfg.getForce());
|
||||
|
||||
@ -324,7 +366,8 @@ bool UDPSrc::handleMessage(const Message& cmd)
|
||||
<< " m_squelchEnabled: " << m_config.m_squelchEnabled
|
||||
<< " m_squelch: " << m_config.m_squelch
|
||||
<< " getSquelchDB: " << cfg.getSquelchDB()
|
||||
<< " m_squelchGate" << m_config.m_squelchGate;
|
||||
<< " m_squelchGate" << m_config.m_squelchGate
|
||||
<< " m_agc" << m_config.m_agc;
|
||||
|
||||
return true;
|
||||
|
||||
@ -388,10 +431,16 @@ void UDPSrc::apply(bool force)
|
||||
m_interpolator.create(16, m_config.m_inputSampleRate, m_config.m_rfBandwidth / 2.0);
|
||||
m_sampleDistanceRemain = m_config.m_inputSampleRate / m_config.m_outputSampleRate;
|
||||
|
||||
m_squelchThreshold = m_config.m_outputSampleRate * m_config.m_squelchGate;
|
||||
int gateNbSamples = m_config.m_inputSampleRate * m_config.m_squelchGate;
|
||||
int agcTimeNbSamples = m_config.m_inputSampleRate * 0.2; // Fixed 200 ms
|
||||
m_squelchThreshold = gateNbSamples;
|
||||
initSquelch(m_squelchOpen);
|
||||
m_agc.resize(agcTimeNbSamples, m_agcTarget);
|
||||
m_agc.setStepDownDelay(gateNbSamples);
|
||||
m_agc.setGate(gateNbSamples);
|
||||
|
||||
m_inMovingAverage.resize(m_config.m_outputSampleRate * 0.01, 1e-10); // 10 ms
|
||||
m_inMovingAverage.resize(m_config.m_inputSampleRate * 0.01, 1e-10); // 10 ms
|
||||
m_amMovingAverage.resize(m_config.m_inputSampleRate * 0.01, 1e-10); // 10 ms
|
||||
m_outMovingAverage.resize(m_config.m_outputSampleRate * 0.01, 1e-10); // 10 ms
|
||||
}
|
||||
|
||||
@ -410,8 +459,16 @@ void UDPSrc::apply(bool force)
|
||||
|
||||
if ((m_config.m_squelchGate != m_running.m_squelchGate) || force)
|
||||
{
|
||||
m_squelchThreshold = m_config.m_outputSampleRate * m_config.m_squelchGate;
|
||||
int gateNbSamples = m_config.m_inputSampleRate * m_config.m_squelchGate;
|
||||
m_squelchThreshold = gateNbSamples;
|
||||
initSquelch(m_squelchOpen);
|
||||
m_agc.setStepDownDelay(gateNbSamples); // same delay for up and down
|
||||
m_agc.setGate(gateNbSamples);
|
||||
}
|
||||
|
||||
if ((m_config.m_squelch != m_running.m_squelch) || force)
|
||||
{
|
||||
m_agc.setThreshold(m_config.m_squelch * (1<<30));
|
||||
}
|
||||
|
||||
if ((m_config.m_udpAddressStr != m_running.m_udpAddressStr) || force)
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "dsp/interpolator.h"
|
||||
#include "dsp/phasediscri.h"
|
||||
#include "dsp/movingaverage.h"
|
||||
#include "dsp/agc.h"
|
||||
#include "util/udpsink.h"
|
||||
#include "util/message.h"
|
||||
#include "audio/audiofifo.h"
|
||||
@ -47,6 +48,7 @@ public:
|
||||
FormatLSBMono,
|
||||
FormatUSBMono,
|
||||
FormatAMMono,
|
||||
FormatAMNoDCMono,
|
||||
FormatNone
|
||||
};
|
||||
|
||||
@ -77,6 +79,7 @@ public:
|
||||
Real squelchDB,
|
||||
Real squelchGate,
|
||||
bool squelchEnabled,
|
||||
bool agc,
|
||||
bool force);
|
||||
void setSpectrum(MessageQueue* messageQueue, bool enabled);
|
||||
double getMagSq() const { return m_magsq; }
|
||||
@ -168,6 +171,7 @@ protected:
|
||||
Real getSquelchDB() const { return m_squelchDB; }
|
||||
Real getSquelchGate() const { return m_squelchGate; }
|
||||
bool getSquelchEnabled() const { return m_squelchEnabled; }
|
||||
bool getAGC() const { return m_agc; }
|
||||
bool getForce() const { return m_force; }
|
||||
|
||||
static MsgUDPSrcConfigureImmediate* create(
|
||||
@ -178,6 +182,7 @@ protected:
|
||||
Real squelchDB,
|
||||
Real squelchGate,
|
||||
bool squelchEnabled,
|
||||
bool agc,
|
||||
bool force)
|
||||
{
|
||||
return new MsgUDPSrcConfigureImmediate(
|
||||
@ -188,6 +193,7 @@ protected:
|
||||
squelchDB,
|
||||
squelchGate,
|
||||
squelchEnabled,
|
||||
agc,
|
||||
force);
|
||||
}
|
||||
|
||||
@ -199,6 +205,7 @@ protected:
|
||||
Real m_squelchDB;
|
||||
Real m_squelchGate; // seconds
|
||||
bool m_squelchEnabled;
|
||||
bool m_agc;
|
||||
bool m_force;
|
||||
|
||||
MsgUDPSrcConfigureImmediate(
|
||||
@ -209,6 +216,7 @@ protected:
|
||||
Real squelchDB,
|
||||
Real squelchGate,
|
||||
bool squelchEnabled,
|
||||
bool agc,
|
||||
bool force) :
|
||||
Message(),
|
||||
m_gain(gain),
|
||||
@ -218,6 +226,7 @@ protected:
|
||||
m_squelchDB(squelchDB),
|
||||
m_squelchGate(squelchGate),
|
||||
m_squelchEnabled(squelchEnabled),
|
||||
m_agc(agc),
|
||||
m_force(force)
|
||||
{ }
|
||||
};
|
||||
@ -254,6 +263,7 @@ protected:
|
||||
Real m_squelch; //!< squared magnitude
|
||||
Real m_squelchGate; //!< seconds
|
||||
bool m_squelchEnabled;
|
||||
bool m_agc;
|
||||
bool m_audioActive;
|
||||
bool m_audioStereo;
|
||||
int m_volume;
|
||||
@ -274,6 +284,7 @@ protected:
|
||||
m_squelch(1e-6),
|
||||
m_squelchGate(0.0),
|
||||
m_squelchEnabled(true),
|
||||
m_agc(false),
|
||||
m_audioActive(false),
|
||||
m_audioStereo(false),
|
||||
m_volume(20),
|
||||
@ -294,6 +305,7 @@ protected:
|
||||
double m_inMagsq;
|
||||
MovingAverage<double> m_outMovingAverage;
|
||||
MovingAverage<double> m_inMovingAverage;
|
||||
MovingAverage<double> m_amMovingAverage;
|
||||
|
||||
Real m_scale;
|
||||
Complex m_last, m_this;
|
||||
@ -319,6 +331,7 @@ protected:
|
||||
|
||||
char *m_udpAudioBuf;
|
||||
static const int m_udpAudioPayloadSize = 8192; //!< UDP audio samples buffer. No UDP block on Earth is larger than this
|
||||
static const Real m_agcTarget = 16384.0f;
|
||||
|
||||
PhaseDiscriminators m_phaseDiscri;
|
||||
|
||||
@ -327,6 +340,8 @@ protected:
|
||||
int m_squelchCloseCount;
|
||||
int m_squelchThreshold; //!< number of samples computed from given gate
|
||||
|
||||
MagAGC m_agc;
|
||||
|
||||
QMutex m_settingsMutex;
|
||||
|
||||
void apply(bool force);
|
||||
|
@ -347,6 +347,7 @@ void UDPSrcGUI::applySettingsImmediate(bool force)
|
||||
ui->squelch->value() * 1.0f,
|
||||
ui->squelchGate->value() * 0.01f,
|
||||
ui->squelch->value() != -100,
|
||||
ui->agc->isChecked(),
|
||||
force);
|
||||
}
|
||||
}
|
||||
@ -448,6 +449,10 @@ void UDPSrcGUI::applySettings(bool force)
|
||||
sampleFormat = UDPSrc::FormatAMMono;
|
||||
ui->fmDeviation->setEnabled(false);
|
||||
break;
|
||||
case 8:
|
||||
sampleFormat = UDPSrc::FormatAMNoDCMono;
|
||||
ui->fmDeviation->setEnabled(false);
|
||||
break;
|
||||
default:
|
||||
sampleFormat = UDPSrc::FormatS16LE;
|
||||
ui->fmDeviation->setEnabled(false);
|
||||
@ -544,6 +549,11 @@ void UDPSrcGUI::on_audioStereo_toggled(bool stereo __attribute__((unused)))
|
||||
applySettingsImmediate();
|
||||
}
|
||||
|
||||
void UDPSrcGUI::on_agc_toggled(bool agc __attribute__((unused)))
|
||||
{
|
||||
applySettingsImmediate();
|
||||
}
|
||||
|
||||
void UDPSrcGUI::on_gain_valueChanged(int value)
|
||||
{
|
||||
ui->gainText->setText(tr("%1").arg(value/10.0, 0, 'f', 1));
|
||||
|
@ -76,6 +76,7 @@ private slots:
|
||||
void on_volume_valueChanged(int value);
|
||||
void on_squelch_valueChanged(int value);
|
||||
void on_squelchGate_valueChanged(int value);
|
||||
void on_agc_toggled(bool agc);
|
||||
void tick();
|
||||
|
||||
private:
|
||||
|
@ -333,6 +333,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ButtonSwitch" name="agc">
|
||||
<property name="toolTip">
|
||||
<string>Toggle AGC (only for AM and SSB)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>AGC</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="audioActive">
|
||||
<property name="toolTip">
|
||||
@ -504,6 +517,11 @@
|
||||
<string>S16LE AM Mono</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>S16LE AM !DC Mono</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@ -782,6 +800,11 @@
|
||||
<header>gui/valuedialz.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ButtonSwitch</class>
|
||||
<extends>QToolButton</extends>
|
||||
<header>gui/buttonswitch.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../../sdrbase/resources/res.qrc"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user