blob: ec57ed5d592a50b262ec8ba13bd172fe5cce064b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
extern crate byteorder;
extern crate libcodec2;
use byteorder::{LittleEndian, ReadBytesExt};
use std::fs::File;
use std::io::prelude::*;
use std::io::Cursor;
use std::path::Path;
fn main() {
let path = Path::new("../../codec2/wav/cross.wav");
let mut file = File::open(&path).unwrap();
let mut buf = Vec::new();
file.read_to_end(&mut buf).unwrap();
let mut rdr = Cursor::new(buf);
let mut speech = Vec::new();
while let Ok(i) = rdr.read_i16::<LittleEndian>() {
speech.push(i);
}
let mut allbits = Vec::new();
let c = libcodec2::Codec2::new();
let nsam = c.samples_per_frame();
let _nbits = c.bytes_per_frame();
for samples in speech.chunks(nsam) {
let mut bits: [u8; 7] = [0, 0, 0, 0, 0, 0, 0]; // nbits assume 7
c.encode(&samples, &mut bits);
allbits.extend(bits);
}
let mut file = File::create("out.c2").unwrap();
file.write_all(&allbits).unwrap();
}
|