6 releases
new 0.2.0 | Nov 6, 2024 |
---|---|
0.1.4 | Jul 30, 2021 |
0.1.3 | Mar 31, 2021 |
#1078 in Audio
195KB
633 lines
wavv
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();
}