pub struct BorrowedAudioFrame<'buf> { /* private fields */ }Expand description
Validated planar floating-point audio borrowed from application storage.
Samples and optional NUL-terminated metadata are borrowed for the frame’s
lifetime. Synchronous sending and crate::audio_conversion::AudioConverter
use the original channel stride without copying samples or allocating.
Inspect channels with Self::channel_data or Self::channels; those
slices exclude inter-channel padding.
Implementations§
Source§impl<'buf> BorrowedAudioFrame<'buf>
impl<'buf> BorrowedAudioFrame<'buf>
Sourcepub fn builder(
data: &'buf [f32],
sample_rate: u32,
num_channels: u32,
num_samples: u32,
) -> BorrowedAudioFrameBuilder<'buf>
pub fn builder( data: &'buf [f32], sample_rate: u32, num_channels: u32, num_samples: u32, ) -> BorrowedAudioFrameBuilder<'buf>
Configure a borrowed planar frame with explicit sample rate and shape.
Defaults to tightly packed channels, Timecode::SYNTHESIZE and no
metadata. A larger input slice is permitted; only the checked frame
extent is retained. All validation occurs in the builder’s build.
use grafton_ndi::{AudioSource, BorrowedAudioFrame};
let samples = [1.0, 2.0, 99.0, 3.0, 4.0];
let frame = BorrowedAudioFrame::builder(&samples, 48_000, 2, 2)
.channel_stride_bytes(12)
.build()?;
let source: &dyn AudioSource = &frame;
assert_eq!(source.channels().collect::<Vec<_>>(), [&[1.0, 2.0][..], &[3.0, 4.0][..]]);
assert!(source.data().is_none());Sourcepub fn with_timecode(self, timecode: Timecode) -> Self
pub fn with_timecode(self, timecode: Timecode) -> Self
Return this frame with the supplied timecode; no samples are copied.
Source§impl<'buf> BorrowedAudioFrame<'buf>
impl<'buf> BorrowedAudioFrame<'buf>
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Get the sample rate in Hz.
Sourcepub fn num_channels(&self) -> u32
pub fn num_channels(&self) -> u32
Get the number of audio channels.
Sourcepub fn num_samples(&self) -> u32
pub fn num_samples(&self) -> u32
Get the number of samples per channel.
Sourcepub fn timestamp(&self) -> Option<ReceivedTimestamp>
pub fn timestamp(&self) -> Option<ReceivedTimestamp>
The source-dependent timestamp of the received frame.
Application input has no received timestamp.
Sourcepub fn format(&self) -> AudioFormat
pub fn format(&self) -> AudioFormat
Get the audio format.
It is a supported format, validated when the frame was constructed.
Sourcepub fn channel_stride_bytes(&self) -> usize
pub fn channel_stride_bytes(&self) -> usize
Get the distance between the starts of consecutive channels in bytes.
Includes any configured inter-channel padding.
Sourcepub fn metadata(&self) -> Option<&str>
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.
Sourcepub fn metadata_status(&self) -> FrameMetadataStatus
pub fn metadata_status(&self) -> FrameMetadataStatus
The metadata’s presence or the reason unreadable received text was withheld. Querying the cached status allocates nothing.
Sourcepub fn channel_data(&self, channel: usize) -> Option<&[f32]>
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.
Borrows the caller’s active samples without reading padding.
Sourcepub fn channels(&self) -> AudioChannels<'_> ⓘ
pub fn channels(&self) -> AudioChannels<'_> ⓘ
Iterate over the channels’ samples, in channel order, without copying or reading padding between channels.
Sourcepub fn data(&self) -> Option<&[f32]>
pub fn data(&self) -> Option<&[f32]>
Contiguous active samples, or None when padding separates channels.
Sourcepub fn to_owned(&self) -> AudioFrame
pub fn to_owned(&self) -> AudioFrame
Copy initialized samples and metadata into a new tightly packed frame. The returned frame retains no borrow; padding is omitted.
Sourcepub fn copy_into(&self, destination: &mut AudioFrame)
pub fn copy_into(&self, destination: &mut AudioFrame)
Copy into an existing packed frame, reusing its sample and metadata allocations when their capacity and lengths permit. A copy without metadata retains the destination’s text allocation.
Trait Implementations§
Source§impl<'buf> AudioSource for BorrowedAudioFrame<'buf>
impl<'buf> AudioSource for BorrowedAudioFrame<'buf>
Source§fn sample_rate(&self) -> u32
fn sample_rate(&self) -> u32
Source§fn num_channels(&self) -> u32
fn num_channels(&self) -> u32
Source§fn num_samples(&self) -> u32
fn num_samples(&self) -> u32
Source§fn timestamp(&self) -> Option<ReceivedTimestamp>
fn timestamp(&self) -> Option<ReceivedTimestamp>
Source§fn format(&self) -> AudioFormat
fn format(&self) -> AudioFormat
Source§fn channel_stride_bytes(&self) -> usize
fn channel_stride_bytes(&self) -> usize
Source§fn metadata(&self) -> Option<&str>
fn metadata(&self) -> Option<&str>
Self::metadata_status.