M17: FrameDecoder: drop stream frames with high BER

In case the number of bit errors detected by the viterbi algorithm in a
stream frame are above a given threshold, do not copy its payload. This
prevents audio artifacts when data is processed by codec2 decoder.
This commit is contained in:
Ryan Turner 2025-10-10 20:50:27 -05:00 committed by Silvano Seva
parent 5fe5cb287b
commit 76ffe2d612
2 changed files with 7 additions and 2 deletions

View File

@ -140,6 +140,9 @@ private:
///< Maximum allowed hamming distance when determining the frame type.
static constexpr uint8_t MAX_SYNC_HAMM_DISTANCE = 4;
///< Maximum number of corrected bit errors allowed in a stream frame.
static constexpr uint16_t MAX_VITERBI_ERRORS = 15;
};
} // namespace M17

View File

@ -155,8 +155,10 @@ void M17FrameDecoder::decodeStream(const std::array<uint8_t, 46> &data)
begin += lich.size();
std::copy(begin, data.end(), punctured.begin());
viterbi.decodePunctured(punctured, tmp, DATA_PUNCTURE);
memcpy(&streamFrame.data, tmp.data(), tmp.size());
// Skip payload copy if BER is too high to avoid audio artifacts
uint16_t bitErrs = viterbi.decodePunctured(punctured, tmp, DATA_PUNCTURE);
if (bitErrs < MAX_VITERBI_ERRORS)
memcpy(&streamFrame.data, tmp.data(), tmp.size());
}
bool M17FrameDecoder::decodeLich(std::array<uint8_t, 6> &segment,