]> code.octet-stream.net Git - m17rt/blob - m17core/src/interleave.rs
Implementing soundmodem tx path
[m17rt] / m17core / src / interleave.rs
1 use crate::bits::{Bits, BitsMut};
2
3 static MAPPING: [usize; 368] = [
4 0, 137, 90, 227, 180, 317, 270, 39, 360, 129, 82, 219, 172, 309, 262, 31, 352, 121, 74, 211,
5 164, 301, 254, 23, 344, 113, 66, 203, 156, 293, 246, 15, 336, 105, 58, 195, 148, 285, 238, 7,
6 328, 97, 50, 187, 140, 277, 230, 367, 320, 89, 42, 179, 132, 269, 222, 359, 312, 81, 34, 171,
7 124, 261, 214, 351, 304, 73, 26, 163, 116, 253, 206, 343, 296, 65, 18, 155, 108, 245, 198, 335,
8 288, 57, 10, 147, 100, 237, 190, 327, 280, 49, 2, 139, 92, 229, 182, 319, 272, 41, 362, 131,
9 84, 221, 174, 311, 264, 33, 354, 123, 76, 213, 166, 303, 256, 25, 346, 115, 68, 205, 158, 295,
10 248, 17, 338, 107, 60, 197, 150, 287, 240, 9, 330, 99, 52, 189, 142, 279, 232, 1, 322, 91, 44,
11 181, 134, 271, 224, 361, 314, 83, 36, 173, 126, 263, 216, 353, 306, 75, 28, 165, 118, 255, 208,
12 345, 298, 67, 20, 157, 110, 247, 200, 337, 290, 59, 12, 149, 102, 239, 192, 329, 282, 51, 4,
13 141, 94, 231, 184, 321, 274, 43, 364, 133, 86, 223, 176, 313, 266, 35, 356, 125, 78, 215, 168,
14 305, 258, 27, 348, 117, 70, 207, 160, 297, 250, 19, 340, 109, 62, 199, 152, 289, 242, 11, 332,
15 101, 54, 191, 144, 281, 234, 3, 324, 93, 46, 183, 136, 273, 226, 363, 316, 85, 38, 175, 128,
16 265, 218, 355, 308, 77, 30, 167, 120, 257, 210, 347, 300, 69, 22, 159, 112, 249, 202, 339, 292,
17 61, 14, 151, 104, 241, 194, 331, 284, 53, 6, 143, 96, 233, 186, 323, 276, 45, 366, 135, 88,
18 225, 178, 315, 268, 37, 358, 127, 80, 217, 170, 307, 260, 29, 350, 119, 72, 209, 162, 299, 252,
19 21, 342, 111, 64, 201, 154, 291, 244, 13, 334, 103, 56, 193, 146, 283, 236, 5, 326, 95, 48,
20 185, 138, 275, 228, 365, 318, 87, 40, 177, 130, 267, 220, 357, 310, 79, 32, 169, 122, 259, 212,
21 349, 302, 71, 24, 161, 114, 251, 204, 341, 294, 63, 16, 153, 106, 243, 196, 333, 286, 55, 8,
22 145, 98, 235, 188, 325, 278, 47,
23 ];
24
25 pub fn interleave(payload: &[u8]) -> [u8; 46] {
26 let payload_bits = Bits::new(payload);
27 let mut new = [0; 46];
28 let mut new_bits = BitsMut::new(&mut new);
29 for (input, output) in MAPPING.iter().enumerate() {
30 new_bits.set_bit(*output, payload_bits.get_bit(input));
31 }
32 new
33 }
34
35 #[cfg(test)]
36 mod tests {
37 use super::*;
38
39 #[test]
40 fn interleaving_table() {
41 let mut mapping = [0; 368];
42 for i in 0..368i64 {
43 mapping[i as usize] = ((45 * i + 92 * i.pow(2)) % 368) as usize;
44 }
45 println!("{mapping:?}");
46 assert_eq!(mapping, MAPPING);
47 }
48 }