Initial commit

This commit is contained in:
Sebastian 2016-11-23 23:37:39 +01:00
commit 1126e570e8
5 changed files with 59 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target

14
Cargo.lock generated Normal file
View File

@ -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"

7
Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "apt-decoder"
version = "0.1.0"
authors = ["LongHairedHacker <sebastian@sebastians-site.de>"]
[dependencies]
hound = "2.0.0"

BIN
noaa19_short.wav Normal file

Binary file not shown.

37
src/main.rs Normal file
View File

@ -0,0 +1,37 @@
extern crate hound;
fn float_sample_iterator<'a>(reader: &'a mut hound::WavReader<std::io::BufReader<std::fs::File>>)
-> Box<Iterator<Item=f32> + 'a> {
match reader.spec().sample_format {
hound::SampleFormat::Float => Box::new(reader.samples::<f32>().map(|x| x.unwrap())),
hound::SampleFormat::Int => match reader.spec().bits_per_sample {
8 => Box::new(reader.samples::<i8>().map(|x| (x.unwrap() as f32) / (i16::max_value() as f32))),
16 => Box::new(reader.samples::<i16>().map(|x| (x.unwrap() as f32) / (i16::max_value() as f32))),
32 => Box::new(reader.samples::<i32>().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 )
}
}