Crates.io | wavv |
lib.rs | wavv |
version | 0.2.0 |
source | src |
created_at | 2021-03-27 21:27:45.127292 |
updated_at | 2024-11-06 21:18:32.228445 |
description | no_std library for parsing and creating wav files |
homepage | |
repository | https://github.com/samuelleeuwenburg/wavv |
max_upload_size | |
id | 374418 |
size | 817,365 |
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();
}