Skip to main content

FrameSyncAudioRequest

Struct FrameSyncAudioRequest 

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

A validated, reusable audio capture for FrameSync::capture_audio and FrameSync::capture_audio_ref.

capture_at and for_input require an explicit positive sample rate, output channels and samples per channel. Construction checks the SDK’s signed byte stride and the 64 MiB packed sample payload limit before any native work. This bounds requested samples, not SDK internal memory use. Successful construction and request reuse allocate nothing in the wrapper; submitting a request performs no dimension checks, locks, or extra SDK queries. Returned descriptors and metadata are still validated after each capture.

Every request captures samples. To follow the source’s format, call FrameSync::audio_input_format until it returns Some, then build a request with for_input. Query again and rebuild when the application chooses to follow format changes. The SDK converts to the request’s rate and channel count even if the source changes meanwhile.

§Example

let framesync = FrameSync::new(receiver)?;

// Wait until the source's audio format is known.
let format = loop {
    if let Some(format) = framesync.audio_input_format()? {
        break format;
    }
    std::thread::sleep(Duration::from_millis(10));
};

// 1024 samples per channel, in the source's channels, at 48 kHz.
let request = FrameSyncAudioRequest::capture_at(48_000, format.num_channels(), 1_024)?;
let audio = framesync.capture_audio(request)?;
assert_eq!(audio.num_channels(), format.num_channels());

// Or in the source's rate and channels.
let request = FrameSyncAudioRequest::for_input(format, 1_024)?;

Implementations§

Source§

impl FrameSyncAudioRequest

Source

pub fn sample_rate(&self) -> u32

Requested output sample rate in Hz.

Source

pub fn num_channels(&self) -> u32

Requested number of output channels.

Source

pub fn num_samples(&self) -> u32

Requested number of output samples per channel.

Source

pub fn capture_at( sample_rate: u32, num_channels: u32, num_samples: u32, ) -> Result<Self>

Capture samples resampled to sample_rate Hz, converted to num_channels channels of num_samples samples each.

To follow the source’s format, use for_input.

A request can be copied and reused across borrowed and owned captures.

§Errors

Returns Error::InvalidInput with an crate::InputDefect::Layout cause for a rate or count outside 1..=i32::MAX, or a sample payload exceeding 64 MiB. Validation does not allocate sample storage.

Source

pub fn for_input(format: AudioInputFormat, num_samples: u32) -> Result<Self>

Capture samples at the sample rate and channel count of format, with num_samples samples per channel.

format comes from FrameSync::audio_input_format, which returns None until the source’s audio has arrived. The request fixes the format it was built from: if the source changes later the SDK converts to the request’s rate and channels. To follow such changes, query the format again and build a new request.

§Errors

As for capture_at: Error::InvalidInput for a zero or oversized num_samples, or a payload exceeding 64 MiB.

§Example
let framesync = FrameSync::new(receiver)?;

// Wait until the source's audio format is known.
let format = loop {
    if let Some(format) = framesync.audio_input_format()? {
        break format;
    }
    std::thread::sleep(Duration::from_millis(10));
};

let request = FrameSyncAudioRequest::for_input(format, 1_024)?;
let audio = framesync.capture_audio(request)?;
assert_eq!(audio.sample_rate(), format.sample_rate());
// To follow a source change, call `audio_input_format` again and
// build a new request.

Trait Implementations§

Source§

impl Clone for FrameSyncAudioRequest

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 Copy for FrameSyncAudioRequest

Source§

impl Debug for FrameSyncAudioRequest

Source§

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

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

impl Eq for FrameSyncAudioRequest

Source§

impl Hash for FrameSyncAudioRequest

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for FrameSyncAudioRequest

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FrameSyncAudioRequest

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.