Skip to content

Commit

Permalink
Fixed zero divide in possible race conditions and also return to init…
Browse files Browse the repository at this point in the history
…ial state when changing decode mode
  • Loading branch information
f4exb committed Aug 22, 2019
1 parent a0f4694 commit b8ecee6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dsd_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ void DSDDecoder::setDecodeMode(DSDDecodeMode mode, bool on)
default:
break;
}

resetFrameSync();
noCarrier();
m_squelchTimeoutCount = 0;
m_nxdnInterSyncCount = -1; // reset to quiet state
}

void DSDDecoder::setAudioGain(float gain)
Expand Down
6 changes: 6 additions & 0 deletions dsd_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ bool DSDSymbol::pushSample(short sample)

if (m_sampleIndex == m_samplesPerSymbol - 1) // conclusion
{
if (m_count == 0) // out of sync for example because of race condition
{
m_sampleIndex = 0; // return to the beginning of a symbol
return false; // and wait for next sample
}

m_symbol = m_sum / m_count;
m_dsdDecoder->m_state.symbolcnt++;

Expand Down

0 comments on commit b8ecee6

Please sign in to comment.