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 ) } }