X-Git-Url: https://code.octet-stream.net/m17rt/blobdiff_plain/e67ea96c8a3d7c23ba29c6ed91ddb451927176a1..ed89ed42024f30e94e27084ec2b9ee0acb038b62:/demod/src/main.rs diff --git a/demod/src/main.rs b/demod/src/main.rs index f67f87d..0f7f031 100755 --- a/demod/src/main.rs +++ b/demod/src/main.rs @@ -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(); }