Function wave_stream::write_wav_to_file_path
source · pub fn write_wav_to_file_path(
file_path: &Path,
header: WavHeader
) -> Result<OpenWavWriter>Expand description
Starts writing a wav to a Path. Returns an OpenWavWriter struct that is used to write the contents of the wav
Arguments
- ‘file_path’ - The path to where the wav will be written
- ‘header’ - The header information in the wav. This specifies things like sampling rate, sample bit depth, ect
Examples
use std::path::Path;
use wave_stream::wave_header::{SampleFormat, WavHeader};
use wave_stream::{read_wav_from_file_path, write_wav_to_file_path};
let header = WavHeader {
sample_format: SampleFormat::Float,
channels: 2,
sample_rate: 96000,
};
let mut open_wav = write_wav_to_file_path(Path::new("some.wav"), header).unwrap();
let mut writer = open_wav.get_random_access_f32_writer().unwrap();
// Sample 0
writer.write_sample(0, 0, 0.0).unwrap(); // Channel 0
writer.write_sample(0, 1, 0.0).unwrap(); // Channel 1
// Sample 1
writer.write_sample(1, 0, 0.0).unwrap();
writer.write_sample(1, 1, 0.0).unwrap();
// Sample 2
writer.write_sample(2, 0, 0.0).unwrap();
writer.write_sample(3, 1, 0.0).unwrap();
writer.flush().unwrap();