pub struct PcmSpec { /* private fields */ }Expand description
Audio format description for a PCM stream: channel count, sample rate, and sample encoding.
A PcmSpec is the validated, immutable contract shared by PCM buffers,
sources, and sinks. It is constructed through PcmSpec::i16 or
PcmSpec::f32, which reject a zero channel count or zero sample rate, so a
constructed value is always a usable audio configuration.
§Examples
use sim_lib_stream_audio::{PcmSampleFormat, PcmSpec};
let spec = PcmSpec::f32(2, 48_000)?;
assert_eq!(spec.channels(), 2);
assert_eq!(spec.sample_rate_hz(), 48_000);
assert_eq!(spec.sample_format(), PcmSampleFormat::F32);Implementations§
Source§impl PcmSpec
impl PcmSpec
Sourcepub fn i16(channels: usize, sample_rate_hz: u32) -> Result<Self>
pub fn i16(channels: usize, sample_rate_hz: u32) -> Result<Self>
Builds an interleaved 16-bit signed integer (PcmSampleFormat::I16)
spec.
Returns an error when channels or sample_rate_hz is zero.
Sourcepub fn f32(channels: usize, sample_rate_hz: u32) -> Result<Self>
pub fn f32(channels: usize, sample_rate_hz: u32) -> Result<Self>
Builds an interleaved 32-bit float (PcmSampleFormat::F32) spec.
Returns an error when channels or sample_rate_hz is zero.
Sourcepub fn sample_rate_hz(self) -> u32
pub fn sample_rate_hz(self) -> u32
Returns the sample rate in hertz (frames per second).
Sourcepub fn sample_format(self) -> PcmSampleFormat
pub fn sample_format(self) -> PcmSampleFormat
Returns the per-sample encoding.
Trait Implementations§
impl Copy for PcmSpec
impl Eq for PcmSpec
impl StructuralPartialEq for PcmSpec
Auto Trait Implementations§
impl Freeze for PcmSpec
impl RefUnwindSafe for PcmSpec
impl Send for PcmSpec
impl Sync for PcmSpec
impl Unpin for PcmSpec
impl UnsafeUnpin for PcmSpec
impl UnwindSafe for PcmSpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more