pub struct PcmPacket { /* private fields */ }Expand description
A block of interleaved PCM audio samples.
Carries channels interleaved channels of frames frames each in a single
sample format. The total sample count always equals channels * frames.
Equality compares f32 samples bitwise so packets with NaN payloads still
round-trip consistently.
Implementations§
Source§impl PcmPacket
impl PcmPacket
Sourcepub fn i16(
channels: usize,
frames: usize,
samples_i16: Vec<i16>,
) -> Result<Self>
pub fn i16( channels: usize, frames: usize, samples_i16: Vec<i16>, ) -> Result<Self>
Builds an PcmSampleFormat::I16 packet from interleaved samples.
Returns an error when channels is zero or samples_i16.len() does
not equal channels * frames.
§Examples
use sim_lib_stream_core::{PcmPacket, PcmSampleFormat};
// Two channels, two frames -> four interleaved samples.
let packet = PcmPacket::i16(2, 2, vec![0, 1, 2, 3]).unwrap();
assert_eq!(packet.channels(), 2);
assert_eq!(packet.frames(), 2);
assert_eq!(packet.sample_format(), PcmSampleFormat::I16);
assert_eq!(packet.samples_i16(), &[0, 1, 2, 3]);Sourcepub fn f32(
channels: usize,
frames: usize,
samples_f32: Vec<f32>,
) -> Result<Self>
pub fn f32( channels: usize, frames: usize, samples_f32: Vec<f32>, ) -> Result<Self>
Builds an PcmSampleFormat::F32 packet from interleaved samples.
Returns an error when channels is zero, the sample length does not
equal channels * frames, or any sample is not finite.
Sourcepub fn sample_format(&self) -> PcmSampleFormat
pub fn sample_format(&self) -> PcmSampleFormat
Returns the sample format of the stored samples.
Sourcepub fn samples_i16(&self) -> &[i16]
pub fn samples_i16(&self) -> &[i16]
Returns the interleaved i16 samples.
§Panics
Panics if the packet holds f32 samples; check
sample_format first.
Sourcepub fn samples_f32(&self) -> &[f32]
pub fn samples_f32(&self) -> &[f32]
Returns the interleaved f32 samples.
§Panics
Panics if the packet holds i16 samples; check
sample_format first.