#[non_exhaustive]pub enum SampleType {
U8,
I16,
I24,
I32,
F32,
F64,
}Expand description
Identifies the numeric type used to represent individual audio samples.
§Purpose
SampleType provides a runtime representation of the sample format that can
be inspected, serialised, and used for dispatch without needing generic type
parameters. It mirrors the set of types that implement AudioSample.
§Intended Usage
Use SampleType when the sample format must be described at runtime – for
example when reading audio file headers, serialising audio metadata, or
routing to SIMD dispatch paths via SampleType::from_type_id.
§Variants
| Variant | Type | Width | Notes |
|---|---|---|---|
U8 | u8 | 8-bit unsigned | Mid-scale 128 = silence |
I16 | i16 | 16-bit signed | CD-quality |
I24 | I24 | 24-bit signed | From the i24 crate |
I32 | i32 | 32-bit signed | |
F32 | f32 | 32-bit float | Native DSP format |
F64 | f64 | 64-bit float | High-precision |
I24: crate::I24
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
U8
8-bit unsigned integer (u8). Mid-scale value 128 represents silence.
I16
16-bit signed integer (i16). CD-quality audio.
I24
24-bit signed integer (I24(crate::I24)). Common in studio audio.
I32
32-bit signed integer (i32). High-dynamic-range integer audio.
F32
32-bit floating point (f32). Native format for most DSP operations.
F64
64-bit floating point (f64). High-precision processing.
Implementations§
Source§impl SampleType
impl SampleType
Sourcepub const fn description(self) -> &'static str
pub const fn description(self) -> &'static str
Returns a human-readable descriptive name
Sourcepub const fn is_integer(self) -> bool
pub const fn is_integer(self) -> bool
Returns true if this is an integer-based sample format (U8, I16, I24, or I32).
Sourcepub const fn is_signed(self) -> bool
pub const fn is_signed(self) -> bool
Returns true if this is a signed integer format (I16, I24, or I32).
Note: U8 is an integer type but is unsigned, so this returns false for it.
Sourcepub const fn is_unsigned(self) -> bool
pub const fn is_unsigned(self) -> bool
Returns true if this is an unsigned integer format (currently only U8).
Sourcepub const fn is_dsp_native(self) -> bool
pub const fn is_dsp_native(self) -> bool
True if this format is usable for DSP operations without conversion
Source§impl SampleType
impl SampleType
Sourcepub fn from_type_id(type_id: TypeId) -> Option<Self>
pub fn from_type_id(type_id: TypeId) -> Option<Self>
Returns the SampleType corresponding to a TypeId, or None if unrecognized.
This is useful for SIMD dispatch code that needs to determine the concrete sample type at runtime.
§Example
use audio_samples::SampleType;
use std::any::TypeId;
assert_eq!(SampleType::from_type_id(TypeId::of::<f32>()), Some(SampleType::F32));
assert_eq!(SampleType::from_type_id(TypeId::of::<String>()), None);Trait Implementations§
Source§impl Clone for SampleType
impl Clone for SampleType
Source§fn clone(&self) -> SampleType
fn clone(&self) -> SampleType
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SampleType
impl Debug for SampleType
Source§impl Display for SampleType
Formats the sample type as a string.
impl Display for SampleType
Formats the sample type as a string.
The standard format ({}) uses the short machine-readable identifier (e.g. "f32").
The alternate format ({:#}) uses the human-readable description (e.g. "32-bit floating point").
§Examples
use audio_samples::SampleType;
assert_eq!(format!("{}", SampleType::F32), "f32");
assert_eq!(format!("{:#}", SampleType::F32), "32-bit floating point");Source§impl Hash for SampleType
impl Hash for SampleType
Source§impl PartialEq for SampleType
impl PartialEq for SampleType
Source§impl TryFrom<&str> for SampleType
Parses a SampleType from its canonical short-name string.
impl TryFrom<&str> for SampleType
Parses a SampleType from its canonical short-name string.
Accepts "u8", "i16", "i24", "i32", "f32", and "f64".
Returns Err(()) for any unrecognised string.
§Examples
use audio_samples::SampleType;
assert_eq!(SampleType::try_from("f32"), Ok(SampleType::F32));
assert_eq!(SampleType::try_from("i16"), Ok(SampleType::I16));
assert!(SampleType::try_from("unknown").is_err());impl Copy for SampleType
impl Eq for SampleType
impl StructuralPartialEq for SampleType
Auto Trait Implementations§
impl Freeze for SampleType
impl RefUnwindSafe for SampleType
impl Send for SampleType
impl Sync for SampleType
impl Unpin for SampleType
impl UnsafeUnpin for SampleType
impl UnwindSafe for SampleType
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<Src, Dst> ConvertTo<Dst> for Srcwhere
Dst: ConvertFrom<Src>,
impl<Src, Dst> ConvertTo<Dst> for Srcwhere
Dst: ConvertFrom<Src>,
Source§fn convert_to(self) -> Dst
fn convert_to(self) -> Dst
Dst using audio-aware scaling. Read more