]> code.octet-stream.net Git - m17rt/blobdiff - demod/src/main.rs
Modem support for parsing packet frames
[m17rt] / demod / src / main.rs
index f67f87dccbbe18de1bfc41326815d1e57bc509c6..0f7f031d236a1adeaae1c4c8f49ef24c58983559 100755 (executable)
@@ -1,52 +1,19 @@
-use log::debug;
-use m17core::{
-    modem::{Demodulator, SoftDemodulator},
-    protocol::{Frame, LichCollection},
-};
-pub(crate) use std::{fs::File, io::Read};
+use m17app::app::M17App;
+use m17app::soundmodem::{InputRrcFile, Soundmodem};
+use m17codec2::Codec2Adapter;
+use std::path::PathBuf;
 
-pub fn run_my_decode() {
-    let file = File::open("../../Data/test_vk7xt.rrc").unwrap();
-    let mut input = file;
-    let mut baseband = vec![];
-    input.read_to_end(&mut baseband).unwrap();
-
-    let mut lich = LichCollection::new();
-    let mut codec2_data = vec![];
-    let mut modem = SoftDemodulator::new();
-
-    for pair in baseband.chunks(2) {
-        let sample: i16 = i16::from_le_bytes([pair[0], pair[1]]);
-        if let Some(frame) = modem.demod(sample) {
-            debug!("Modem demodulated frame: {:?}", frame);
-            if let Frame::Stream(s) = frame {
-                for b in s.stream_data {
-                    codec2_data.push(b);
-
-                    let valid_before = lich.valid_segments();
-                    lich.set_segment(s.lich_idx, s.lich_part);
-                    let valid_after = lich.valid_segments();
-                    if valid_before != valid_after {
-                        debug!("Valid lich segments: {}", lich.valid_segments());
-                    }
-                    if valid_before == 5 && valid_after == 6 {
-                        if let Some(l) = lich.try_assemble() {
-                            debug!("Assembled complete lich: {l:?}");
-                        }
-                    }
-                }
-                if s.end_of_stream {
-                    debug!("len of codec2 data: {}", codec2_data.len());
-                    assert_eq!(codec2_data.len(), 1504);
-
-                    m17codec2::decode_codec2(&codec2_data, "../../Data/speech_out.raw");
-                }
-            }
-        }
-    }
+pub fn m17app_test() {
+    let path = PathBuf::from("../../Data/test_vk7xt.rrc");
+    let source = InputRrcFile::new(path);
+    let soundmodem = Soundmodem::new_with_input(source);
+    let app = M17App::new(soundmodem);
+    app.add_stream_adapter(Codec2Adapter::new());
+    app.start();
+    std::thread::sleep(std::time::Duration::from_secs(15));
 }
 
 fn main() {
     env_logger::init();
-    run_my_decode();
+    m17app_test();
 }