Skip to main content

AudioFrame

Struct AudioFrame 

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

Owned, tightly packed planar floating-point audio with a validated layout.

Channel samples are contiguous, with channels stored one after another. Conversion from borrowed SDK audio omits inter-channel padding. Cloning copies the samples, readable metadata and metadata status, including when received text was withheld.

Implementations§

Source§

impl AudioFrame

Source

pub fn sample_rate(&self) -> u32

Get the sample rate in Hz.

Source

pub fn num_channels(&self) -> u32

Get the number of audio channels.

Source

pub fn num_samples(&self) -> u32

Get the number of samples per channel.

Source

pub fn timecode(&self) -> Timecode

Get the timecode.

A built frame starts with Timecode::SYNTHESIZE; a copy of a received frame keeps the timecode it arrived with.

Source

pub fn timestamp(&self) -> Option<ReceivedTimestamp>

The source-dependent timestamp of the received frame.

A frame has one only when it was copied from a received frame that carries one; frames built for sending have none.

Source

pub fn format(&self) -> AudioFormat

Get the audio format.

It is a supported format, validated when the frame was constructed.

Source

pub fn channel_stride_bytes(&self) -> usize

Get the distance between the starts of consecutive channels in bytes.

It is one channel’s samples, since an owned frame has no padding.

Source

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

Get frame metadata as UTF-8 text, if present.

Empty metadata, Some(""), is distinct from none, None. Unreadable received text returns None; use Self::metadata_status to distinguish it from absent text.

Source

pub fn metadata_status(&self) -> FrameMetadataStatus

The metadata’s presence or the reason unreadable received text was withheld. Querying the cached status allocates nothing.

Source

pub fn channel_data(&self, channel: usize) -> Option<&[f32]>

Get one channel’s samples, or None for an invalid channel.

The slice borrows the frame’s samples without copying and excludes any padding between channels.

Samples for this channel are contiguous in the packed planar data.

Source

pub fn channels(&self) -> AudioChannels<'_> ⓘ

Iterate over the channels’ samples, in channel order, without copying or reading padding between channels.

Source

pub fn data(&self) -> &[f32]

Get tightly packed planar audio as 32-bit floats. Each channel’s samples are contiguous; channels follow one another.

Source

pub fn to_owned(&self) -> AudioFrame

Copy this frame, its readable metadata and its metadata status into independent owned storage.

Source

pub fn copy_into(&self, destination: &mut AudioFrame)

Copy samples, header, timestamp and metadata into a reusable owned frame. Existing sample and metadata capacity is reused when it is sufficient.

Source§

impl AudioFrame

Source

pub fn from_interleaved(source: &InterleavedAudioF32<'_>) -> Self

Copy validated interleaved floating-point samples into packed planar audio.

This conversion needs no NDI runtime and allocates only the output samples. It preserves the input’s timecode; metadata is absent and the received timestamp is None. Use Self::set_metadata to attach metadata.

Source

pub fn builder() -> AudioFrameBuilder

Create a builder for a frame to send.

Its defaults are 48 kHz stereo FLTP with 1024 samples per channel, planar input, Timecode::SYNTHESIZE, no metadata and silent samples.

Source

pub fn set_timecode(&mut self, timecode: Timecode)

Set the timecode without reallocating the samples.

Source

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

Recover tightly packed planar samples, retaining their allocation and capacity.

Source

pub fn swap_data( &mut self, data: Vec<f32>, ) -> Result<Vec<f32>, Rejected<Vec<f32>>>

Replace samples and return the previous vector for allocation reuse.

§Errors

Returns data unchanged with Error::InvalidFrame unless it has exactly the validated sample count. The frame is unchanged.

Source

pub fn data_mut(&mut self) -> &mut [f32]

Get mutable audio sample data without changing the validated layout.

Source

pub fn replace_data(&mut self, data: Vec<f32>) -> Result<(), Rejected<Vec<f32>>>

Replace the owned audio data while preserving the validated layout.

§Errors

Returns data, unused, with Error::InvalidFrame if it is not exactly the validated sample count. The frame is unchanged.

Source

pub fn set_metadata( &mut self, metadata: impl Into<String>, ) -> Result<(), Rejected<String>>

Replace frame metadata. Use Self::clear_metadata to remove it.

Valid replacement text sets FrameMetadataStatus::Text, including an empty string. Invalid replacement text leaves the existing metadata and its status unchanged.

§Errors

Returns the unchanged text in Rejected. Its reason is Error::InvalidCString if metadata contains an interior NUL byte, or Error::InvalidFrame if the emitted C string would exceed the metadata size cap. The NulError retains only the prefix through the first NUL; use Rejected::into_inner for the whole original string.

Source

pub fn clear_metadata(&mut self)

Remove frame metadata, setting FrameMetadataStatus::Absent and retaining its allocation for later copies.

Source

pub fn channel_data_mut(&mut self, channel: usize) -> Option<&mut [f32]>

Get mutable samples for one channel without allocating.

Trait Implementations§

Source§

impl AudioSource for AudioFrame

Source§

fn sample_rate(&self) -> u32

Sample rate in Hz.
Source§

fn num_channels(&self) -> u32

Number of channels.
Source§

fn num_samples(&self) -> u32

Number of active samples per channel.
Source§

fn timecode(&self) -> Timecode

Frame timecode, or the sender’s synthesis sentinel.
Source§

fn timestamp(&self) -> Option<ReceivedTimestamp>

Source-dependent timestamp supplied by the SDK for a captured frame.
Source§

fn format(&self) -> AudioFormat

Validated planar floating-point audio format.
Source§

fn channel_stride_bytes(&self) -> usize

Distance in bytes between consecutive channel starts.
Source§

fn metadata(&self) -> Option<&str>

UTF-8 metadata; an explicit empty string differs from no metadata. Unreadable received text is withheld; inspect Self::metadata_status.
Source§

fn metadata_status(&self) -> FrameMetadataStatus

Whether per-frame metadata is absent, readable, or withheld as unreadable.
Source§

fn channel_data(&self, channel: usize) -> Option<&[f32]>

One channel’s initialized samples, excluding any inter-channel padding.
Source§

fn channels(&self) -> AudioChannels<'_> ⓘ

Iterate initialized channel samples without allocating or reading padding.
Source§

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

Contiguous samples, or None when padding separates channels.
Source§

fn to_owned(&self) -> AudioFrame

Copy samples and readable metadata into a new owned, tightly packed planar frame. Withheld metadata keeps its status without its text. Allocates sample storage and, when present, readable metadata storage.
Source§

fn copy_into(&self, destination: &mut AudioFrame)

Copy into an owned destination, reusing sample and metadata allocations when their capacities permit. Padding is omitted. Absent source metadata clears the destination text while retaining its allocation.
Source§

impl Clone for AudioFrame

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 AudioFrame

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.