]> code.octet-stream.net Git - m17rt/blob - m17codec2/src/lib.rs
KISS frame decoding
[m17rt] / m17codec2 / src / lib.rs
1 pub(crate) use codec2::{Codec2, Codec2Mode};
2 use std::fs::File;
3 use std::io::Write;
4 use std::path::Path;
5
6 pub fn decode_codec2<P: AsRef<Path>>(data: &[u8], out_path: P) {
7 let codec2 = Codec2::new(Codec2Mode::MODE_3200);
8 let var_name = codec2;
9 let mut codec = var_name;
10 let mut all_samples: Vec<i16> = vec![];
11 for i in 0..(data.len() / 8) {
12 let mut samples = vec![0; codec.samples_per_frame()];
13 codec.decode(&mut samples, &data[i * 8..((i + 1) * 8)]);
14 all_samples.append(&mut samples);
15 }
16
17 // dude this works
18 let mut speech_out = File::create(out_path).unwrap();
19 for b in all_samples {
20 speech_out.write_all(&b.to_le_bytes()).unwrap();
21 }
22 }