#[non_exhaustive]pub enum AudioFormat {
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
S16
S32
F32
Default: matches libopus’s native interleaved layout.
U8Planar
S16Planar
S32Planar
F32Planar
Implementations§
Source§impl AudioFormat
impl AudioFormat
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]>, AudioError>
pub fn as_interleaved_f32<'a>( self, data: &'a [u8], channels: u32, ) -> Result<Cow<'a, [f32]>, AudioError>
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.
Sourcepub fn from_interleaved_f32(
self,
samples: &[f32],
channels: u32,
) -> Result<Vec<u8>, AudioError>
pub fn from_interleaved_f32( self, samples: &[f32], channels: u32, ) -> Result<Vec<u8>, AudioError>
Convert interleaved f32 PCM to this format’s raw byte
representation. Returns owned bytes; integer formats clamp
out-of-range samples rather than wrapping.
Trait Implementations§
Source§impl Clone for AudioFormat
impl Clone for AudioFormat
Source§fn clone(&self) -> AudioFormat
fn clone(&self) -> AudioFormat
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for AudioFormat
Source§impl Debug for AudioFormat
impl Debug for AudioFormat
Source§impl Default for AudioFormat
impl Default for AudioFormat
Source§fn default() -> AudioFormat
fn default() -> AudioFormat
impl Eq for AudioFormat
Source§impl PartialEq for AudioFormat
impl PartialEq for AudioFormat
Source§fn eq(&self, other: &AudioFormat) -> bool
fn eq(&self, other: &AudioFormat) -> bool
self and other values to be equal, and is used by ==.