]> code.octet-stream.net Git - m17rt/blob - demod/src/main.rs
KISS frame decoding
[m17rt] / demod / src / main.rs
1 use log::debug;
2 use m17core::{
3 modem::{Demodulator, SoftDemodulator},
4 protocol::{Frame, LichCollection},
5 };
6 pub(crate) use std::{fs::File, io::Read};
7
8 pub fn run_my_decode() {
9 let file = File::open("../../Data/test_vk7xt.rrc").unwrap();
10 let mut input = file;
11 let mut baseband = vec![];
12 input.read_to_end(&mut baseband).unwrap();
13
14 let mut lich = LichCollection::new();
15 let mut codec2_data = vec![];
16 let mut modem = SoftDemodulator::new();
17
18 for pair in baseband.chunks(2) {
19 let sample: i16 = i16::from_le_bytes([pair[0], pair[1]]);
20 if let Some(frame) = modem.demod(sample) {
21 debug!("Modem demodulated frame: {:?}", frame);
22 if let Frame::Stream(s) = frame {
23 for b in s.stream_data {
24 codec2_data.push(b);
25
26 let valid_before = lich.valid_segments();
27 lich.set_segment(s.lich_idx, s.lich_part);
28 let valid_after = lich.valid_segments();
29 if valid_before != valid_after {
30 debug!("Valid lich segments: {}", lich.valid_segments());
31 }
32 if valid_before == 5 && valid_after == 6 {
33 if let Some(l) = lich.try_assemble() {
34 debug!("Assembled complete lich: {l:?}");
35 }
36 }
37 }
38 if s.end_of_stream {
39 debug!("len of codec2 data: {}", codec2_data.len());
40 assert_eq!(codec2_data.len(), 1504);
41
42 m17codec2::decode_codec2(&codec2_data, "../../Data/speech_out.raw");
43 }
44 }
45 }
46 }
47 }
48
49 fn main() {
50 env_logger::init();
51 run_my_decode();
52 }