commit 1126e570e82db747974992557e8117b5e2b4f8c9 Author: LongHairedHacker Date: Wed Nov 23 23:37:39 2016 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..c46e54c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,14 @@ +[root] +name = "apt-decoder" +version = "0.1.0" +dependencies = [ + "hound 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hound" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum hound 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1e971fe26207d3ccdc66806fd9154508b28101fccb53fe152695e3ebcb53bd0f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..0c2973b --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "apt-decoder" +version = "0.1.0" +authors = ["LongHairedHacker "] + +[dependencies] +hound = "2.0.0" diff --git a/noaa19_short.wav b/noaa19_short.wav new file mode 100644 index 0000000..9a55b79 Binary files /dev/null and b/noaa19_short.wav differ diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..4d1602a --- /dev/null +++ b/src/main.rs @@ -0,0 +1,37 @@ +extern crate hound; + +fn float_sample_iterator<'a>(reader: &'a mut hound::WavReader>) + -> Box + 'a> { + match reader.spec().sample_format { + hound::SampleFormat::Float => Box::new(reader.samples::().map(|x| x.unwrap())), + hound::SampleFormat::Int => match reader.spec().bits_per_sample { + 8 => Box::new(reader.samples::().map(|x| (x.unwrap() as f32) / (i16::max_value() as f32))), + 16 => Box::new(reader.samples::().map(|x| (x.unwrap() as f32) / (i16::max_value() as f32))), + 32 => Box::new(reader.samples::().map(|x| (x.unwrap() as f32) / (i32::max_value() as f32))), + _ => panic!("Unsupported sample rate") + } + } +} + + +fn main() { + let carrier_freq = 2400; + + let mut reader = match hound::WavReader::open("noaa19_short.wav") { + Err(e) => panic!("Could not open inputfile: {}", e), + Ok(r) => r + }; + + if reader.spec().channels != 1 { + panic!("Expected a mono file"); + } + + let sample_rate = reader.spec().sample_rate; + println!("Samplerate: {}", sample_rate); + + let mut samples = float_sample_iterator(&mut reader); + + for sample in samples { + println!("Sample: {}", sample ) + } +}