1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-17 13:51:47 -05:00

Simple AGC cleanup

This commit is contained in:
f4exb 2018-02-03 17:06:16 +01:00
parent b0a97510e2
commit a1c84718ef
3 changed files with 24 additions and 37 deletions

View File

@ -45,7 +45,7 @@ AMDemod::AMDemod(DeviceSourceAPI *deviceAPI) :
m_magsqSum(0.0f),
m_magsqPeak(0.0f),
m_magsqCount(0),
m_volumeAGC(1200, 1.0),
m_volumeAGC(0.003),
m_audioFifo(48000),
m_settingsMutex(QMutex::Recursive)
{
@ -54,7 +54,6 @@ AMDemod::AMDemod(DeviceSourceAPI *deviceAPI) :
m_audioBuffer.resize(1<<14);
m_audioBufferFill = 0;
m_volumeAGC.resize(4096, 0.003, 0);
m_magsq = 0.0;
DSPEngine::instance()->addAudioSink(&m_audioFifo);

View File

@ -144,7 +144,7 @@ private:
int m_magsqCount;
MovingAverageUtil<Real, double, 16> m_movingAverage;
SimpleAGC m_volumeAGC;
SimpleAGC<4096> m_volumeAGC;
Bandpass<Real> m_bandpass;
AudioVector m_audioBuffer;
@ -179,10 +179,6 @@ private:
{
if (m_squelchCount <= m_settings.m_audioSampleRate / 10)
{
if (m_squelchCount == m_settings.m_audioSampleRate / 20) {
m_volumeAGC.fill(1.0);
}
m_squelchCount++;
}
}

View File

@ -9,6 +9,7 @@
#define INCLUDE_GPL_DSP_AGC_H_
#include "movingaverage.h"
#include "util/movingaverage.h"
class AGC
{
@ -81,56 +82,47 @@ private:
bool m_squelchOpen;
};
template<uint32_t AvgSize>
class SimpleAGC
{
public:
SimpleAGC(int historySize, Real initial, Real cutoff=0, Real clip=0) :
m_squelchOpen(false),
m_fill(initial),
m_cutoff(cutoff),
m_clip(clip),
m_moving_average(historySize, initial)
SimpleAGC(Real cutoff=0, Real clip=0) :
m_squelchOpen(false),
m_cutoff(cutoff),
m_clip(clip)
{}
void resize(int historySize, Real initial, Real cutoff=0, Real clip=0)
void resize(Real cutoff=0, Real clip=0)
{
m_fill = initial;
m_cutoff = cutoff;
m_clip = clip;
m_moving_average.resize(historySize, initial);
}
void fill(double value)
{
m_moving_average.fill(value);
m_cutoff = cutoff;
m_clip = clip;
}
Real getValue()
{
if (m_moving_average.average() > m_clip)
{
return m_moving_average.average();
} else
{
return m_clip;
}
if ((Real) m_moving_average > m_clip)
{
return (Real) m_moving_average;
} else
{
return m_clip;
}
}
void feed(Real value)
{
if (value > m_cutoff)
{
m_moving_average.feed(value);
}
if (value > m_cutoff)
{
m_moving_average(value);
}
}
private:
bool m_squelchOpen; // open for processing
Real m_fill; // refill average at this level
Real m_cutoff; // consider samples only above this level
Real m_clip; // never go below this level
MovingAverage<double> m_moving_average; // Averaging engine. The stack length conditions the smoothness of AGC.
//MovingAverage<double> m_moving_average; // Averaging engine. The stack length conditions the smoothness of AGC.
MovingAverageUtil<Real, double, AvgSize> m_moving_average;
};
#endif /* INCLUDE_GPL_DSP_AGC_H_ */