pub struct WavWriter<W: Write + Seek> { /* private fields */ }Expand description
A streaming WAV writer that finalises a correct header.
Streaming synthesis does not know the sample count until the run ends, so a provisional header
is written first and patched by WavWriter::finish. That seek-back is why the sink must be
Seek: an unseekable sink cannot carry a correct length, and silently emitting a wrong one is
the corruption this type exists to prevent.
If the run is cut short — cancellation, a full disk — calling finish still yields a valid
file describing the samples that made it, which is the partial-output promise in plan §9.6.
Implementations§
Source§impl<W: Write + Seek> WavWriter<W>
impl<W: Write + Seek> WavWriter<W>
Sourcepub fn write_samples(&mut self, pcm: &[f32]) -> Result<()>
pub fn write_samples(&mut self, pcm: &[f32]) -> Result<()>
Append one packet of decoded f32 samples.
§Errors
If the sink rejects the write. The count of samples already accepted stays accurate, so a
later WavWriter::finish still describes the file truthfully.
Sourcepub const fn samples_written(&self) -> usize
pub const fn samples_written(&self) -> usize
Samples accepted so far.
Sourcepub const fn duration_millis(&self) -> u64
pub const fn duration_millis(&self) -> u64
Duration of the audio written so far, in milliseconds.
Trait Implementations§
Source§impl<W: Write + Seek> Drop for WavWriter<W>
impl<W: Write + Seek> Drop for WavWriter<W>
Source§fn drop(&mut self)
fn drop(&mut self)
Best-effort finalisation for a writer dropped without WavWriter::finish.
A dropped writer means an abnormal end — a panic, an early return, a cancelled run. Leaving
the provisional zero-length header would make the file claim it contains no audio while
holding a megabyte of it. The error is deliberately swallowed because Drop cannot report,
which is exactly why finish exists and should be called explicitly.