summaryrefslogtreecommitdiff
path: root/c2enc/src/main.rs
blob: eb097bdf59288c6d4a4b849b5f33cb1664ecb77e (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 speech in speech.chunks(nsam) {
        let mut bits = Vec::new();
        bits.reserve(nbits);
        c.encode(&speech, &mut bits);
        allbits.push(bits);
    }

    println!("{:?}", allbits);
}