Skip to main content

Module wav

Module wav 

Source
Expand description

Reading and writing WAV files, through the hound crate.

Samples are always f32 in [-1, 1], interleaved by channel, which is what the synthesiser produces and what crate::asset::SoundAsset holds. Writing produces 16-bit PCM, which every player and editor reads; reading accepts 8, 16, 24 and 32-bit PCM and 32-bit float.

use proof_engine::audio::wav::{read_wav, write_wav};
// A tenth of a second of a 440 Hz sine, mono.
let sine: Vec<f32> = (0..4410)
    .map(|i| (i as f32 / 44100.0 * 440.0 * std::f32::consts::TAU).sin() * 0.5)
    .collect();
write_wav(&path, 44100, 1, &sine).unwrap();
let clip = read_wav(&std::fs::read(&path).unwrap()).unwrap();
assert_eq!((clip.sample_rate, clip.channels, clip.samples.len()), (44100, 1, 4410));

Structs§

WavClip
A decoded WAV file.

Functions§

load_wav
Read a WAV file from disk.
read_wav
Decode a WAV file held in memory.
write_wav
Write interleaved f32 samples to path as 16-bit PCM WAV.