wav-dwt 0.2.1

An experimental implementation of the A Trous Wavelet Decomposition algorithms for audio instead of images
Documentation
use hound::WavSpec;

pub fn read_wav_file(file_path: &str) -> Result<(WavSpec, Vec<f32>), Box<dyn std::error::Error>> {
    let mut reader = hound::WavReader::open(file_path)?;
    let spec = reader.spec();
    let samples: Vec<f32> = reader
        .samples::<i16>()
        .map(|s| s.unwrap() as f32 / i16::MAX as f32)
        .collect();

    Ok((spec, samples))
}

pub fn write_wav_file(file_path: &str, data: Vec<f32>, spec: WavSpec) {
    let mut writer = hound::WavWriter::create(file_path, spec).unwrap();

    for (_, item) in data.iter().enumerate() {
        writer
            .write_sample((item * i16::MAX as f32) as i16)
            .unwrap();
    }
}