Skip to main content

AudioFrameBuilder

Struct AudioFrameBuilder 

Source
pub struct AudioFrameBuilder { /* private fields */ }
Expand description

Builder for an AudioFrame, reached through AudioFrame::builder.

Implementations§

Source§

impl AudioFrameBuilder

Source

pub fn sample_rate(self, sample_rate: u32) -> Self

Set the sample rate in Hz.

Source

pub fn num_channels(self, num_channels: u32) -> Self

Set the number of audio channels.

Source

pub fn num_samples(self, num_samples: u32) -> Self

Set the number of samples per channel.

Source

pub fn timecode(self, timecode: Timecode) -> Self

Set the timecode.

Source

pub fn data(self, data: Vec<f32>) -> Self

Set packed planar 32-bit samples, with every sample of channel 0 first, then every sample of channel 1, and so on.

The length must equal num_channels * num_samples. For interleaved input, use AudioFrame::from_interleaved.

Source

pub fn metadata<S: Into<String>>(self, metadata: S) -> Self

Set the metadata text. A refused build retains this text; recover it with Self::supplied_metadata or Self::take_metadata to repair it. An owned string retains its allocation when there is capacity for the trailing NUL; invalid metadata leaves a rejected builder unchanged.

Source

pub fn supplied_data(&self) -> Option<&[f32]>

The caller-supplied packed planar samples.

Source

pub fn take_data(&mut self) -> Option<Vec<f32>>

Take supplied data while retaining the builder’s other settings.

This permits repairing a refused buffer and putting it back with Self::data. Until then, building uses the zero-filled default.

Source

pub fn into_data(self) -> Option<Vec<f32>>

Recover the original supplied samples, retaining allocation and capacity.

A rejected builder retains untouched samples. Returns None for default silent input.

Source

pub fn clear_data(self) -> Self

Use zero-filled default data instead of a supplied buffer.

Recover the buffer first with Self::take_data when it is needed again.

Source

pub fn supplied_metadata(&self) -> Option<&str>

The supplied metadata before validation or termination.

Source

pub fn take_metadata(&mut self) -> Option<String>

Recover metadata while retaining the builder’s other settings. Its allocation and text are unchanged after a refused build.

Source

pub fn clear_metadata(self) -> Self

Remove metadata, for example to repair a rejected builder.

Source

pub fn build(self) -> Result<AudioFrame, Rejected<Self>>

Build the audio frame.

Unset fields keep the defaults AudioFrame::builder lists. The frame stores packed planar data with channels num_samples * 4 bytes apart.

§Errors

Returns the unchanged builder with Error::InvalidFrame if the sample rate, channel or sample count, metadata size or supplied data length do not form a valid frame, and Error::InvalidCString for metadata containing a NUL byte.

Trait Implementations§

Source§

impl Clone for AudioFrameBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AudioFrameBuilder

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.