Browse Source

demodvormc: Fix uninitialized variable phase in radial calculation

Coverity reported an uninitialized scalar use of varPhase when the
reference and variable Goertzel filters completed at different times.
Store the last valid variable phase and magnitude values to ensure the
radial calculation always uses initialized data.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
chirpmodem-v8.0.0
Robin Getz 4 months ago
parent
commit
bb01f58f28
No known key found for this signature in database
GPG Key ID: 51C7231FFED0E060
  1. 14
      plugins/channelrx/demodvormc/vordemodmcsink.cpp
  2. 2
      plugins/channelrx/demodvormc/vordemodmcsink.h

14
plugins/channelrx/demodvormc/vordemodmcsink.cpp

@ -44,6 +44,8 @@ VORDemodMCSink::VORDemodMCSink(const VORDemodMCSettings& settings, int subChanne @@ -44,6 +44,8 @@ VORDemodMCSink::VORDemodMCSink(const VORDemodMCSettings& settings, int subChanne
m_volumeAGC(0.003),
m_audioFifo(48000),
m_refPrev(0.0f),
m_varPhase(0.0),
m_varMag(0.0),
m_movingAverageIdent(5000),
m_prevBit(0),
m_bitTime(0),
@ -204,13 +206,11 @@ void VORDemodMCSink::processOneSample(Complex &ci) @@ -204,13 +206,11 @@ void VORDemodMCSink::processOneSample(Complex &ci)
Real mag = std::sqrt(magsq);
// Calculate phase of 30Hz variable AM signal
double varPhase;
double varMag;
if (m_varGoertzel.size() == VORDEMOD_CHANNEL_SAMPLE_RATE - 1)
{
m_varGoertzel.goertzel(mag);
varPhase = Units::radiansToDegrees(m_varGoertzel.phase());
varMag = m_varGoertzel.mag();
m_varPhase = Units::radiansToDegrees(m_varGoertzel.phase());
m_varMag = m_varGoertzel.mag();
m_varGoertzel.reset();
}
else
@ -239,17 +239,17 @@ void VORDemodMCSink::processOneSample(Complex &ci) @@ -239,17 +239,17 @@ void VORDemodMCSink::processOneSample(Complex &ci)
float shiftedPhase = phaseDeg + filterPhaseShift;
// Calculate difference in phase, which is the radial
float phaseDifference = shiftedPhase - varPhase;
float phaseDifference = shiftedPhase - m_varPhase;
if (phaseDifference < 0.0)
phaseDifference += 360.0;
else if (phaseDifference >= 360.0)
phaseDifference -= 360.0;
// qDebug() << "Ref phase: " << phaseDeg << " var phase " << varPhase;
// qDebug() << "Ref phase: " << phaseDeg << " var phase " << m_varPhase;
if (getMessageQueueToGUI())
{
VORDemodMCReport::MsgReportRadial *msg = VORDemodMCReport::MsgReportRadial::create(m_subChannelId, phaseDifference, refMag, varMag);
VORDemodMCReport::MsgReportRadial *msg = VORDemodMCReport::MsgReportRadial::create(m_subChannelId, phaseDifference, refMag, m_varMag);
getMessageQueueToGUI()->push(msg);
}

2
plugins/channelrx/demodvormc/vordemodmcsink.h

@ -132,6 +132,8 @@ private: @@ -132,6 +132,8 @@ private:
Lowpass<Complex> m_lowpassRef;
Lowpass<Complex> m_lowpassIdent;
Complex m_refPrev;
double m_varPhase;
double m_varMag;
MovingAverageUtilVar<Real, double> m_movingAverageIdent;
static const int m_identBins = 10;
Real m_identMins[m_identBins];

Loading…
Cancel
Save