#[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 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.
Trait Implementations§
impl Copy for Format
impl Eq for Format
impl StructuralPartialEq for Format
Auto Trait Implementations§
impl Freeze for Format
impl RefUnwindSafe for Format
impl Send for Format
impl Sync for Format
impl Unpin for Format
impl UnsafeUnpin for Format
impl UnwindSafe for Format
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.