pub struct FlacWriter { /* private fields */ }Expand description
Writer that streams recording chunks to a FLAC file.
Pass interleaved f32 samples (the same format as flexaudio’s AudioChunk.data) to
write_chunk, then finalize the header with
finalize. Encoding runs synchronously on the caller thread.
Dropping an open writer without calling finalize still attempts to close the file (writing remaining samples and finalizing the header). Drop never retries a failed writer and never panics; call finalize to detect errors.
Implementations§
Source§impl FlacWriter
impl FlacWriter
Sourcepub fn create<P: AsRef<Path>>(
path: P,
sample_rate: u32,
channels: u16,
) -> Result<FlacWriter>
pub fn create<P: AsRef<Path>>( path: P, sample_rate: u32, channels: u16, ) -> Result<FlacWriter>
Create a new 16-bit FLAC file at path, overwriting any existing file.
Supported values are channels 1..=2 and sample_rate 1..=96,000 Hz. Out-of-range
values return EncodeError::Unsupported without creating a file.
Sourcepub fn write_chunk(&mut self, interleaved: &[f32]) -> Result<()>
pub fn write_chunk(&mut self, interleaved: &[f32]) -> Result<()>
Append interleaved f32 samples.
The length must be a multiple of channels (AudioChunk.data from flexaudio can be
passed directly). Otherwise, this returns EncodeError::Unsupported and writes
nothing. Encoding or I/O failure permanently fails the writer; later writes and
finalize return the first cause. A partial block is buffered and written by the next call or during finalize.
Sourcepub fn finalize(self) -> Result<()>
pub fn finalize(self) -> Result<()>
Write any remaining samples, finalize the header, and close the file.
Consumes self, so the type prevents further calls to
write_chunk. Drop makes a best-effort attempt at the same
operation, but only finalize reports write errors, so finalize is recommended.