X-Git-Url: https://code.octet-stream.net/m17rt/blobdiff_plain/bd5155840661f90aab8c06413fb1e9f256824b55..71a448efcc3c8f53d523c291f12b0f08f3e2f372:/m17core/src/decode.rs diff --git a/m17core/src/decode.rs b/m17core/src/decode.rs index ba21a27..7ec2224 100755 --- a/m17core/src/decode.rs +++ b/m17core/src/decode.rs @@ -88,6 +88,7 @@ pub(crate) fn frame_initial_decode(frame: &[f32] /* length 192 */) -> [u8; 46] { pub(crate) fn parse_lsf(frame: &[f32] /* length 192 */) -> Option { let deinterleaved = frame_initial_decode(frame); + debug!("deinterleaved: {:?}", deinterleaved); let lsf = match fec::decode(&deinterleaved, 240, p_1) { Some(lsf) => LsfFrame(lsf), None => return None, @@ -105,20 +106,6 @@ pub(crate) fn parse_lsf(frame: &[f32] /* length 192 */) -> Option { Some(lsf) } -pub(crate) fn try_lich_decode(type2_bits: &[u8]) -> Option<(u8, [u8; 5])> { - let mut decoded = 0u64; - for (input_idx, input_bytes) in type2_bits.chunks(3).enumerate() { - let mut input: u32 = 0; - for (idx, byte) in input_bytes.iter().enumerate() { - input |= (*byte as u32) << (16 - (8 * idx)); - } - let (val, _dist) = cai_golay::extended::decode(input)?; - decoded |= (val as u64) << ((3 - input_idx) * 12); - } - let b = decoded.to_be_bytes(); - Some((b[7] >> 5, [b[2], b[3], b[4], b[5], b[6]])) -} - pub(crate) fn parse_stream(frame: &[f32] /* length 192 */) -> Option { let deinterleaved = frame_initial_decode(frame); let stream_part = &deinterleaved[12..]; @@ -131,8 +118,11 @@ pub(crate) fn parse_stream(frame: &[f32] /* length 192 */) -> Option Option Option<(u8, [u8; 5])> { + let mut decoded = 0u64; + for (input_idx, input_bytes) in type2_bits.chunks(3).enumerate() { + let mut input: u32 = 0; + for (idx, byte) in input_bytes.iter().enumerate() { + input |= (*byte as u32) << (16 - (8 * idx)); + } + let (val, _dist) = cai_golay::extended::decode(input)?; + decoded |= (val as u64) << ((3 - input_idx) * 12); + } + let b = decoded.to_be_bytes(); + Some((b[7] >> 5, [b[2], b[3], b[4], b[5], b[6]])) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_lich_decode() { + let input = [221, 82, 162, 16, 85, 200, 5, 14, 254, 4, 13, 153]; + let expected_counter = 2; + let expected_part = [221, 81, 5, 5, 0]; + assert_eq!(decode_lich(&input), Some((expected_counter, expected_part))); + } +}