diff --git a/plugins/channelrx/demodam/amdemod.cpp b/plugins/channelrx/demodam/amdemod.cpp index 01d57940d..818fb28d1 100644 --- a/plugins/channelrx/demodam/amdemod.cpp +++ b/plugins/channelrx/demodam/amdemod.cpp @@ -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); diff --git a/plugins/channelrx/demodam/amdemod.h b/plugins/channelrx/demodam/amdemod.h index de54a4148..e42688151 100644 --- a/plugins/channelrx/demodam/amdemod.h +++ b/plugins/channelrx/demodam/amdemod.h @@ -144,7 +144,7 @@ private: int m_magsqCount; MovingAverageUtil m_movingAverage; - SimpleAGC m_volumeAGC; + SimpleAGC<4096> m_volumeAGC; Bandpass 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++; } } diff --git a/sdrbase/dsp/agc.h b/sdrbase/dsp/agc.h index a724b6374..8dbc8293c 100644 --- a/sdrbase/dsp/agc.h +++ b/sdrbase/dsp/agc.h @@ -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 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 m_moving_average; // Averaging engine. The stack length conditions the smoothness of AGC. + //MovingAverage m_moving_average; // Averaging engine. The stack length conditions the smoothness of AGC. + MovingAverageUtil m_moving_average; }; #endif /* INCLUDE_GPL_DSP_AGC_H_ */