Skip to content

Commit

Permalink
SSB demod: mitigate AGC steep transitions causing audio clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed Nov 30, 2023
1 parent 3b969ac commit b402739
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
26 changes: 21 additions & 5 deletions plugins/channelrx/demodssb/ssbdemodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ SSBDemodSink::SSBDemodSink() :
m_demodBufferFill = 0;

m_usb = true;
m_magsq = 0.0f;
m_magsqSum = 0.0f;
m_magsqPeak = 0.0f;
m_magsq = 0.0;
m_magsqSum = 0.0;
m_magsqPeak = 0.0;
m_magsqCount = 0;
m_magsqCur = 0.0;
m_magsqPrev = 0.0;

m_agc.setClampMax(SDR_RX_SCALED/100.0);
m_agc.setClamping(m_agcClamping);
Expand Down Expand Up @@ -170,10 +172,24 @@ void SSBDemodSink::processOneSample(Complex &ci)
m_sum.imag(0.0);
}

float agcVal = m_agcActive ? m_agc.feedAndGetValue(sideband[i]) : 0.1;
float agcVal = m_agcActive ? m_agc.feedAndGetValue(sideband[i]) : 1.0;
fftfilt::cmplx& delayedSample = m_squelchDelayLine.readBack(m_agc.getStepDownDelay());
m_audioActive = delayedSample.real() != 0.0;
m_squelchDelayLine.write(sideband[i]*agcVal);
m_magsqCur = std::norm(sideband[i]*agcVal);

// Prevent overload if squared magnitude variation is 90% full scale (0.9*.0.9 = 0.81)
// Only if AGC is active
if (m_agcActive && (m_magsqCur - m_magsqPrev > m_agcTarget*m_agcTarget*8.1))
{
m_agc.reset(m_agcTarget*100.0); // Quench AGC at -20dB the target
m_squelchDelayLine.write(sideband[i]);
}
else
{
m_squelchDelayLine.write(sideband[i]*agcVal);
}

m_magsqPrev = m_magsqCur;

if (m_audioMute)
{
Expand Down
2 changes: 2 additions & 0 deletions plugins/channelrx/demodssb/ssbdemodsink.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class SSBDemodSink : public ChannelSampleSink {
double m_magsqSum;
double m_magsqPeak;
int m_magsqCount;
double m_magsqCur;
double m_magsqPrev;
MagSqLevelsStore m_magSqLevelStore;
MagAGC m_agc;
bool m_agcActive;
Expand Down
1 change: 1 addition & 0 deletions sdrbase/dsp/agc.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SDRBASE_API AGC
void setOrder(double R) { m_R = R; }
Real getValue();
Real getAverage();
void reset(double R) { m_moving_average.fill(R); }
virtual void feed(Complex& ci) = 0;

protected:
Expand Down

0 comments on commit b402739

Please sign in to comment.