Skip to main content

FlacWriter

Struct FlacWriter 

Source
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

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for FlacWriter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for FlacWriter

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.