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
impl FrameSyncAudioRequest
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Requested output sample rate in Hz.
Sourcepub fn num_channels(&self) -> u32
pub fn num_channels(&self) -> u32
Requested number of output channels.
Sourcepub fn num_samples(&self) -> u32
pub fn num_samples(&self) -> u32
Requested number of output samples per channel.
Sourcepub fn capture_at(
sample_rate: u32,
num_channels: u32,
num_samples: u32,
) -> Result<Self>
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.
Sourcepub fn for_input(format: AudioInputFormat, num_samples: u32) -> Result<Self>
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.