]>
code.octet-stream.net Git - m17rt/blob - demod/src/main.rs
c1a7eb9e744a136e6b1856b9ee299c48de448c02
1 use cpal
::traits
::DeviceTrait
;
2 use cpal
::traits
::HostTrait
;
3 use cpal
::traits
::StreamTrait
;
4 use cpal
::{SampleFormat
, SampleRate
};
7 modem
::{Demodulator
, SoftDemodulator
},
8 protocol
::{Frame
, LichCollection
},
10 use std
::{fs
::File
, io
::Read
};
12 pub fn run_my_decode() {
13 let file
= File
::open("../../Data/test_vk7xt.rrc").unwrap
();
15 let mut baseband
= vec
![];
16 input
.read_to_end(&mut baseband
).unwrap
();
18 let mut lich
= LichCollection
::new();
19 let mut codec2_data
= vec
![];
20 let mut modem
= SoftDemodulator
::new();
22 for pair
in baseband
.chunks(2) {
23 let sample
: i16 = i16::from_le_bytes([pair
[0], pair
[1]]);
24 if let Some(frame
) = modem
.demod(sample
) {
25 debug
!("Modem demodulated frame: {:?}", frame
);
26 if let Frame
::Stream(s
) = frame
{
27 for b
in s
.stream_data
{
30 let valid_before
= lich
.valid_segments();
31 lich
.set_segment(s
.lich_idx
, s
.lich_part
);
32 let valid_after
= lich
.valid_segments();
33 if valid_before
!= valid_after
{
34 debug
!("Valid lich segments: {}", lich
.valid_segments());
36 if valid_before
== 5 && valid_after
== 6 {
37 if let Some(l
) = lich
.try_assemble() {
38 debug
!("Assembled complete lich: {l:?}");
43 debug
!("len of codec2 data: {}", codec2_data
.len());
44 assert_eq
!(codec2_data
.len(), 1504);
47 m17codec2
::decode_codec2(&codec2_data
, "../../Data/speech_out.raw");
48 let host
= cpal
::default_host();
49 let def
= host
.default_output_device().unwrap
();
50 let mut configs
= def
.supported_output_configs().unwrap
();
52 .find
(|c
| c
.channels() == 1 && c
.sample_format() == SampleFormat
::I16
)
54 .with_sample_rate(SampleRate(8000));
60 move |data
: &mut [i16], _
: &cpal
::OutputCallbackInfo
| {
62 "iteration {counter} asked for {} samples at time {}",
64 std
::time
::SystemTime
::now()
65 .duration_since(std
::time
::UNIX_EPOCH
)
70 let qty
= data
.len().min(samples
.len() - index
);
71 println
!("providing {qty} samples");
72 data
[0..qty
].copy_from_slice(&samples
[index
..(index
+ qty
)]);
76 println
!("error occurred");
81 stream
.play().unwrap
();
83 std
::thread
::sleep(std
::time
::Duration
::from_secs(10));
91 let host
= cpal
::default_host();
92 for d
in host
.devices().unwrap
() {
93 println
!("Found card: {:?}", d
.name().unwrap
());
95 let def
= host
.default_output_device().unwrap
();
96 println
!("the default output device is: {}", def
.name().unwrap
());
98 for c
in def
.supported_output_configs().unwrap
() {
99 println
!("config supported: {:?}", c
);
102 println
!("all supported output configs shown");