#[non_exhaustive]pub enum Format {
U8,
S16,
S32,
F32,
U8Planar,
S16Planar,
S32Planar,
F32Planar,
}Expand description
Raw PCM sample format.
Mirrors the WebCodecs AudioData.format enum so callers can pass
microphone or speaker buffers across the FFI boundary unchanged.
Interleaved variants pack samples as [c0_s0, c1_s0, c0_s1, c1_s1, ...].
Planar variants pack as [c0_s0, c0_s1, ..., c1_s0, c1_s1, ...].
See https://developer.mozilla.org/en-US/docs/Web/API/AudioData/format.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
U8
Interleaved unsigned 8-bit, silence at 128.
S16
Interleaved signed 16-bit little-endian.
S32
Interleaved signed 32-bit little-endian.
F32
Interleaved 32-bit float in [-1.0, 1.0]. The default: libopus’s native
layout, so it needs no conversion.
U8Planar
Planar unsigned 8-bit, silence at 128.
S16Planar
Planar signed 16-bit little-endian.
S32Planar
Planar signed 32-bit little-endian.
F32Planar
Planar 32-bit float in [-1.0, 1.0].
Implementations§
Source§impl Format
impl Format
Sourcepub fn bytes_per_sample(self) -> usize
pub fn bytes_per_sample(self) -> usize
Bytes used per single-channel sample.
Sourcepub fn is_planar(self) -> bool
pub fn is_planar(self) -> bool
Whether channels are stored planar (each channel contiguous) rather than interleaved.
Sourcepub fn as_interleaved_f32<'a>(
self,
data: &'a [u8],
channels: u32,
) -> Result<Cow<'a, [f32]>, Error>
pub fn as_interleaved_f32<'a>( self, data: &'a [u8], channels: u32, ) -> Result<Cow<'a, [f32]>, Error>
Convert a raw PCM buffer in this format to interleaved f32 in [-1.0, 1.0].
Returns a Cow::Borrowed when the input is already interleaved f32
(and the byte buffer is aligned), avoiding an allocation. Otherwise
returns a Cow::Owned holding the converted samples.