wavv

Crates.iowavv
lib.rswavv
version0.2.0
sourcesrc
created_at2021-03-27 21:27:45.127292
updated_at2024-11-06 21:18:32.228445
descriptionno_std library for parsing and creating wav files
homepage
repositoryhttps://github.com/samuelleeuwenburg/wavv
max_upload_size
id374418
size817,365
Samuel (samuelleeuwenburg)

documentation

https://docs.rs/wavv

README

wavv

.github/workflows/main.yml Crates.io docs.rs

Basic no_std library for parsing and creating WAV files.

Reading a WAV file:

use std::fs;
use std::path::Path;
use wavv::{Wav, Data};

fn main() {
    let bytes = fs::read(Path::new("./test_files/stereo_16_48000.wav")).unwrap();
	let wav = Wav::from_bytes(&bytes).unwrap();

    assert_eq!(wav.fmt.num_channels, 2);
    assert_eq!(wav.fmt.bit_depth, 16);
    assert_eq!(wav.fmt.sample_rate, 48_000);

    match wav.data {
        Data::BitDepth8(samples) => println!("{:?}", samples),
        Data::BitDepth16(samples) => println!("{:?}", samples),
        Data::BitDepth24(samples) => println!("{:?}", samples),
    }
}

Writing a WAV file:

use std::fs::File;
use std::io::Write;
use std::path::Path;
use wavv::{Wav, Data};

fn main() {
    let data = Data::BitDepth16(vec![0, 0, 0, 0, 0, 0]);
	let wav = Wav::from_data(data, 48_000, 2);

    let path = Path::new("output.wav");
    let mut file = File::create(&path).unwrap();
    file.write_all(&wav.to_bytes()).unwrap();
}
Commit count: 13

cargo fmt