#[non_exhaustive]pub enum SampleFormat {
U8,
S16,
S32,
F32,
F64,
S16p,
S32p,
F32p,
F64p,
S24,
S24p,
}Expand description
Core OxiMedia types: errors, codecs, pixel/sample formats, timestamps. Audio sample format.
Defines how audio samples are stored in memory, including bit depth, signedness, and whether samples are interleaved or planar.
Formats ending with ‘p’ are planar (one plane per channel).
§Examples
use oximedia_core::types::SampleFormat;
let format = SampleFormat::F32;
assert!(!format.is_planar());
assert_eq!(format.bytes_per_sample(), 4);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
U8
Unsigned 8-bit integer, interleaved.
S16
Signed 16-bit integer, interleaved.
S32
Signed 32-bit integer, interleaved.
F32
32-bit floating point, interleaved.
F64
64-bit floating point, interleaved.
S16p
Signed 16-bit integer, planar.
S32p
Signed 32-bit integer, planar.
F32p
32-bit floating point, planar.
F64p
64-bit floating point, planar.
S24
Signed 24-bit integer, interleaved (stored in 3 bytes per sample). Common in professional audio interfaces and WAV files.
S24p
Signed 24-bit integer, planar (stored in 3 bytes per sample). Planar variant for professional audio pipelines.
Implementations§
Source§impl SampleFormat
impl SampleFormat
Sourcepub const fn bytes_per_sample(&self) -> usize
pub const fn bytes_per_sample(&self) -> usize
Returns the number of bytes per sample.
§Examples
use oximedia_core::types::SampleFormat;
assert_eq!(SampleFormat::U8.bytes_per_sample(), 1);
assert_eq!(SampleFormat::S16.bytes_per_sample(), 2);
assert_eq!(SampleFormat::F32.bytes_per_sample(), 4);
assert_eq!(SampleFormat::F64.bytes_per_sample(), 8);Sourcepub const fn is_planar(&self) -> bool
pub const fn is_planar(&self) -> bool
Returns whether this format uses planar storage.
Planar formats store each channel in a separate contiguous memory region, as opposed to interleaved formats where samples alternate between channels.
§Examples
use oximedia_core::types::SampleFormat;
assert!(!SampleFormat::F32.is_planar());
assert!(SampleFormat::F32p.is_planar());Sourcepub const fn bits_per_sample(&self) -> u32
pub const fn bits_per_sample(&self) -> u32
Returns the number of bits per sample.
§Examples
use oximedia_core::types::SampleFormat;
assert_eq!(SampleFormat::U8.bits_per_sample(), 8);
assert_eq!(SampleFormat::S16.bits_per_sample(), 16);
assert_eq!(SampleFormat::F32.bits_per_sample(), 32);Sourcepub const fn is_float(&self) -> bool
pub const fn is_float(&self) -> bool
Returns whether this format uses floating point samples.
§Examples
use oximedia_core::types::SampleFormat;
assert!(SampleFormat::F32.is_float());
assert!(SampleFormat::F64p.is_float());
assert!(!SampleFormat::S16.is_float());Sourcepub const fn is_signed(&self) -> bool
pub const fn is_signed(&self) -> bool
Returns whether this format uses signed integer samples.
§Examples
use oximedia_core::types::SampleFormat;
assert!(SampleFormat::S16.is_signed());
assert!(SampleFormat::S32p.is_signed());
assert!(!SampleFormat::U8.is_signed());Sourcepub const fn to_packed(&self) -> SampleFormat
pub const fn to_packed(&self) -> SampleFormat
Returns the packed (interleaved) equivalent of this format.
If the format is already packed, returns self.
§Examples
use oximedia_core::types::SampleFormat;
assert_eq!(SampleFormat::F32p.to_packed(), SampleFormat::F32);
assert_eq!(SampleFormat::S16.to_packed(), SampleFormat::S16);Sourcepub const fn to_planar(&self) -> SampleFormat
pub const fn to_planar(&self) -> SampleFormat
Returns the planar equivalent of this format.
If the format is already planar, returns self. Note: U8 has no planar equivalent and returns U8.
§Examples
use oximedia_core::types::SampleFormat;
assert_eq!(SampleFormat::F32.to_planar(), SampleFormat::F32p);
assert_eq!(SampleFormat::S16p.to_planar(), SampleFormat::S16p);Source§impl SampleFormat
impl SampleFormat
Sourcepub const fn bit_depth(&self) -> u8
pub const fn bit_depth(&self) -> u8
Returns the bit depth of this sample format.
§Examples
use oximedia_core::types::SampleFormat;
assert_eq!(SampleFormat::U8.bit_depth(), 8);
assert_eq!(SampleFormat::S16.bit_depth(), 16);
assert_eq!(SampleFormat::S24.bit_depth(), 24);
assert_eq!(SampleFormat::F32.bit_depth(), 32);
assert_eq!(SampleFormat::F64.bit_depth(), 64);Sourcepub fn dynamic_range_db(&self) -> f64
pub fn dynamic_range_db(&self) -> f64
Returns the theoretical dynamic range in decibels for integer formats.
For floating-point formats, returns an approximate practical range.
The formula for integer formats is 6.02 * bits + 1.76 dB.
§Examples
use oximedia_core::types::SampleFormat;
let dr = SampleFormat::S16.dynamic_range_db();
assert!((dr - 98.09).abs() < 0.1); // ~96.3 + 1.76Sourcepub const fn buffer_size(&self, sample_count: usize, channels: usize) -> usize
pub const fn buffer_size(&self, sample_count: usize, channels: usize) -> usize
Returns the buffer size in bytes needed for sample_count samples
across channels channels.
For interleaved formats, all channels are stored in a single buffer. For planar formats, this returns the total size of all per-channel planes.
§Examples
use oximedia_core::types::SampleFormat;
// 1024 stereo F32 samples: 1024 * 2 * 4 = 8192 bytes
assert_eq!(SampleFormat::F32.buffer_size(1024, 2), 8192);
// Planar is the same total: 1024 * 4 * 2 planes = 8192
assert_eq!(SampleFormat::F32p.buffer_size(1024, 2), 8192);Trait Implementations§
Source§impl Clone for SampleFormat
impl Clone for SampleFormat
Source§fn clone(&self) -> SampleFormat
fn clone(&self) -> SampleFormat
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SampleFormat
impl Debug for SampleFormat
Source§impl Default for SampleFormat
impl Default for SampleFormat
Source§fn default() -> SampleFormat
fn default() -> SampleFormat
Source§impl<'de> Deserialize<'de> for SampleFormat
impl<'de> Deserialize<'de> for SampleFormat
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<SampleFormat, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<SampleFormat, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for SampleFormat
impl Display for SampleFormat
Source§impl FormatCost for SampleFormat
impl FormatCost for SampleFormat
Source§fn conversion_cost(&self, target: &SampleFormat) -> Option<u32>
fn conversion_cost(&self, target: &SampleFormat) -> Option<u32>
self to target, or None if no
conversion path is available.Source§impl FromStr for SampleFormat
impl FromStr for SampleFormat
Source§fn from_str(s: &str) -> Result<SampleFormat, <SampleFormat as FromStr>::Err>
fn from_str(s: &str) -> Result<SampleFormat, <SampleFormat as FromStr>::Err>
Parses a sample format name string.
§Examples
use oximedia_core::types::SampleFormat;
let fmt: SampleFormat = "f32".parse().expect("should parse");
assert_eq!(fmt, SampleFormat::F32);Source§impl Hash for SampleFormat
impl Hash for SampleFormat
Source§impl PartialEq for SampleFormat
impl PartialEq for SampleFormat
Source§impl Serialize for SampleFormat
impl Serialize for SampleFormat
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for SampleFormat
impl Eq for SampleFormat
impl StructuralPartialEq for SampleFormat
Auto Trait Implementations§
impl Freeze for SampleFormat
impl RefUnwindSafe for SampleFormat
impl Send for SampleFormat
impl Sync for SampleFormat
impl Unpin for SampleFormat
impl UnsafeUnpin for SampleFormat
impl UnwindSafe for SampleFormat
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,
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.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more