pub struct AudioFrameBuilder { /* private fields */ }Expand description
Builder for an AudioFrame, reached through AudioFrame::builder.
Implementations§
Source§impl AudioFrameBuilder
impl AudioFrameBuilder
Sourcepub fn sample_rate(self, sample_rate: u32) -> Self
pub fn sample_rate(self, sample_rate: u32) -> Self
Set the sample rate in Hz.
Sourcepub fn num_channels(self, num_channels: u32) -> Self
pub fn num_channels(self, num_channels: u32) -> Self
Set the number of audio channels.
Sourcepub fn num_samples(self, num_samples: u32) -> Self
pub fn num_samples(self, num_samples: u32) -> Self
Set the number of samples per channel.
Sourcepub fn data(self, data: Vec<f32>) -> Self
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.
Sourcepub fn metadata<S: Into<String>>(self, metadata: S) -> Self
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.
Sourcepub fn supplied_data(&self) -> Option<&[f32]>
pub fn supplied_data(&self) -> Option<&[f32]>
The caller-supplied packed planar samples.
Sourcepub fn take_data(&mut self) -> Option<Vec<f32>>
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.
Sourcepub fn into_data(self) -> Option<Vec<f32>>
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.
Sourcepub fn clear_data(self) -> Self
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.
Sourcepub fn supplied_metadata(&self) -> Option<&str>
pub fn supplied_metadata(&self) -> Option<&str>
The supplied metadata before validation or termination.
Sourcepub fn take_metadata(&mut self) -> Option<String>
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.
Sourcepub fn clear_metadata(self) -> Self
pub fn clear_metadata(self) -> Self
Remove metadata, for example to repair a rejected builder.
Sourcepub fn build(self) -> Result<AudioFrame, Rejected<Self>>
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.