1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 10:05:46 -05:00

AM demod: use MagAGC for synchronous AM

This commit is contained in:
f4exb 2018-05-14 00:34:37 +02:00
parent 21840c5dd3
commit 85d4d8029c
2 changed files with 330 additions and 310 deletions

View File

@ -54,6 +54,7 @@ AMDemod::AMDemod(DeviceSourceAPI *deviceAPI) :
m_magsqPeak(0.0f),
m_magsqCount(0),
m_volumeAGC(0.003),
m_syncAMAGC(12000, 0.1, 1e-2),
m_audioFifo(48000),
m_settingsMutex(QMutex::Recursive)
{
@ -68,6 +69,8 @@ AMDemod::AMDemod(DeviceSourceAPI *deviceAPI) :
m_audioSampleRate = DSPEngine::instance()->getAudioDeviceManager()->getOutputSampleRate();
DSBFilter = new fftfilt((2.0f * m_settings.m_rfBandwidth) / m_audioSampleRate, 2 * 1024);
SSBFilter = new fftfilt(0.0f, m_settings.m_rfBandwidth / m_audioSampleRate, 1024);
m_syncAMAGC.setThresholdEnable(false);
m_syncAMAGC.resize(12000, 6000, 0.1);
applyChannelSettings(m_inputSampleRate, m_inputFrequencyOffset, true);
applySettings(m_settings, true);
@ -251,6 +254,8 @@ void AMDemod::applyAudioSampleRate(int sampleRate)
m_volumeAGC.resizeNew(sampleRate/10, 0.003);
}
m_syncAMAGC.resize(sampleRate/4, sampleRate/8, 0.1);
m_settingsMutex.unlock();
m_audioSampleRate = sampleRate;
}
@ -308,7 +313,7 @@ void AMDemod::applySettings(const AMDemodSettings& settings, bool force)
if ((m_settings.m_squelch != settings.m_squelch) || force)
{
m_squelchLevel = pow(10.0, settings.m_squelch / 10.0);
m_squelchLevel = CalcDb::powerFromdB(settings.m_squelch);
}
if ((settings.m_audioDeviceName != m_settings.m_audioDeviceName) || force)

View File

@ -33,6 +33,8 @@
#include "audio/audiofifo.h"
#include "util/message.h"
#include "util/doublebufferfifo.h"
#include "util/stepfunctions.h"
#include "amdemodsettings.h"
class DeviceSourceAPI;
@ -175,6 +177,7 @@ private:
fftfilt* SSBFilter;
Real m_syncAMBuff[2*1024];
uint32_t m_syncAMBuffIndex;
MagAGC m_syncAMAGC;
AudioVector m_audioBuffer;
uint32_t m_audioBufferFill;
@ -249,21 +252,33 @@ private:
for (int i = 0; i < n_out; i++)
{
float agcVal = m_syncAMAGC.feedAndGetValue(sideband[i]);
fftfilt::cmplx z = sideband[i] * agcVal; // * m_syncAMAGC.getStepValue();
if (m_settings.m_syncAMOperation == AMDemodSettings::SyncAMDSB) {
m_syncAMBuff[i] = (sideband[i].real() + sideband[i].imag())/2.0f;
m_syncAMBuff[i] = (z.real() + z.imag())/2.0f;
} else if (m_settings.m_syncAMOperation == AMDemodSettings::SyncAMUSB) {
m_syncAMBuff[i] = (sideband[i].real() + sideband[i].imag());
m_syncAMBuff[i] = (z.real() + z.imag());
} else {
m_syncAMBuff[i] = (sideband[i].real() + sideband[i].imag());
m_syncAMBuff[i] = (z.real() + z.imag());
}
// if (m_settings.m_syncAMOperation == AMDemodSettings::SyncAMDSB) {
// m_syncAMBuff[i] = (sideband[i].real() + sideband[i].imag())/2.0f;
// } else if (m_settings.m_syncAMOperation == AMDemodSettings::SyncAMUSB) {
// m_syncAMBuff[i] = (sideband[i].real() + sideband[i].imag());
// } else {
// m_syncAMBuff[i] = (sideband[i].real() + sideband[i].imag());
// }
m_syncAMBuffIndex = 0;
}
m_syncAMBuffIndex = m_syncAMBuffIndex < 2*1024 ? m_syncAMBuffIndex : 0;
demod = m_syncAMBuff[m_syncAMBuffIndex++]*(SDR_RX_SCALEF/602.0f);
m_volumeAGC.feed(demod);
demod /= (10.0*m_volumeAGC.getValue());
demod = m_syncAMBuff[m_syncAMBuffIndex++]*4.0f; // mos pifometrico
// demod = m_syncAMBuff[m_syncAMBuffIndex++]*(SDR_RX_SCALEF/602.0f);
// m_volumeAGC.feed(demod);
// demod /= (10.0*m_volumeAGC.getValue());
}
else
{
@ -279,7 +294,7 @@ private:
}
Real attack = (m_squelchCount - 0.05f * m_audioSampleRate) / (0.05f * m_audioSampleRate);
sample = demod * attack * (m_audioSampleRate/24) * m_settings.m_volume;
sample = demod * StepFunctions::smootherstep(attack) * (m_audioSampleRate/24) * m_settings.m_volume;
}
else
{