]>
code.octet-stream.net Git - m17rt/blob - m17core/src/encode.rs
4 interleave
::interleave
,
5 protocol
::{LsfFrame
, PacketFrame
, StreamFrame
, LSF_SYNC
},
9 pub(crate) fn encode_lsf(frame
: &LsfFrame
) -> [f32; 192] {
10 let type3
= fec
::encode(&frame
.0, 240, p_1
);
11 let mut interleaved
= interleave(&type3
);
12 random_xor(&mut interleaved
);
13 let mut out
= [0f32; 192];
14 for (val
, o
) in LSF_SYNC
.iter
().zip(out
.iter
_m
ut
()) {
17 let bits
= Bits
::new(&interleaved
);
18 let mut out_bits
= bits
.iter
();
19 for o
in out
[8..].iter
_m
ut
() {
20 *o
= match (out_bits
.next().unwrap
(), out_bits
.next().unwrap
()) {
31 /*pub(crate) fn encode_stream(frame: &StreamFrame) -> [f32; 192] {
32 let type3 = fec::encode(&frame.0, 240, p_1);
33 let mut interleaved = interleave(&type3);
34 random_xor(&mut interleaved);
35 let mut out = [0f32; 192];
36 for (val, o) in LSF_SYNC.iter().zip(out.iter_mut()) {
39 let bits = Bits::new(&interleaved);
40 let mut out_bits = bits.iter();
41 for o in out[8..].iter_mut() {
42 *o = match (out_bits.next().unwrap(), out_bits.next().unwrap()) {
53 /*pub(crate) fn encode_packet(frame: &PacketFrame) -> [f32; 192] {
54 let type3 = fec::encode(&frame.0, 240, p_1);
55 let mut interleaved = interleave(&type3);
56 random_xor(&mut interleaved);
57 let mut out = [0f32; 192];
58 for (val, o) in LSF_SYNC.iter().zip(out.iter_mut()) {
61 let bits = Bits::new(&interleaved);
62 let mut out_bits = bits.iter();
63 for o in out[8..].iter_mut() {
64 *o = match (out_bits.next().unwrap(), out_bits.next().unwrap()) {
75 pub(crate) fn encode_lich(counter
: u8, part
: [u8; 5]) -> [u8; 12] {
76 let mut out
= [0u8; 12];
78 ((part
[0] as u16) << 4) | ((part
[1] as u16) >> 4),
79 ((part
[1] as u16 & 0x000f) << 8) | part
[2] as u16,
80 ((part
[3] as u16) << 4) | ((part
[4] as u16) >> 4),
81 ((part
[4] as u16 & 0x000f) << 8) | ((counter
as u16) << 5),
83 for (i
, o
) in to_encode
.into
_iter
().zip(out
.chunks_mut(3)) {
84 let encoded
= cai_golay
::extended
::encode(i
).to_be_bytes();
85 o
[0..3].copy_from_slice(&encoded
[1..4]);
97 255, 255, 255, 255, 255, 255, 0, 0, 0, 159, 221, 81, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 0, 0, 0, 0, 0, 131, 53,
100 let encoded
= encode_lsf(&lsf
);
101 let decoded
= crate::decode
::parse_lsf(&encoded
);
102 assert_eq
!(decoded
, Some(lsf
));
107 let input
= [221, 81, 5, 5, 0];
109 let expected_output
= [221, 82, 162, 16, 85, 200, 5, 14, 254, 4, 13, 153];
110 assert_eq
!(encode_lich(counter
, input
), expected_output
);
114 fn lich_round_trip() {
115 let input
= [1, 255, 0, 90, 10];
118 crate::decode
::decode_lich(&encode_lich(counter
, input
.clone())),
119 Some((counter
, input
))