pub trait Sample:
Debug
+ Copy
+ Clone
+ Send
+ Sync
+ Add<Output = Self>
+ Sub<Output = Self>
+ Mul<Output = Self>
+ Div<Output = Self>
+ Neg<Output = Self>
+ AddAssign
+ SubAssign
+ MulAssign
+ DivAssign
+ PartialOrd
+ PartialEq
+ 'static {
type Simd: SimdFloat<Scalar = Self> + StdFloat + SimdPartialOrd + Copy + Add<Output = Self::Simd> + Sub<Output = Self::Simd> + Mul<Output = Self::Simd> + Div<Output = Self::Simd> + Rem<Output = Self::Simd>;
Show 14 associated constants and 9 methods
const ZERO: Self;
const ONE: Self;
const EPSILON: Self;
const PI: Self;
const INV_PI: Self;
const FRAC_PI_2: Self;
const FRAC_PI_3: Self;
const FRAC_PI_4: Self;
const TAU: Self;
const INV_TAU: Self;
const PHI: Self;
const E: Self;
const SQRT_2: Self;
const INV_SQRT_2: Self;
// Required methods
fn from_f64(value: f64) -> Self;
fn to_f64(self) -> f64;
fn abs(self) -> Self;
fn simd_splat(value: Self) -> Self::Simd;
fn simd_from_slice(slice: &[Self]) -> Self::Simd;
fn simd_to_array(simd: Self::Simd) -> [Self; 4];
fn simd_select_gt(
a: Self::Simd,
b: Self::Simd,
if_true: Self::Simd,
if_false: Self::Simd,
) -> Self::Simd;
fn simd_select_lt(
a: Self::Simd,
b: Self::Simd,
if_true: Self::Simd,
if_false: Self::Simd,
) -> Self::Simd;
fn simd_lane_offsets() -> Self::Simd;
}Expand description
A floating-point type suitable for audio sample data.
This trait abstracts over f32 and f64, allowing DSP blocks and graphs
to be generic over sample precision. Use f32 for performance-critical
real-time processing, or f64 when higher precision is required.
When the simd feature is enabled, this trait also provides associated
types and methods for SIMD vectorization.
Required Associated Constants§
Sourceconst EPSILON: Self
const EPSILON: Self
Machine epsilon i.e. the difference between 1.0 and the next larger representable number.
Sourceconst INV_SQRT_2: Self
const INV_SQRT_2: Self
Inverse square root of 2.
Required Associated Types§
Sourcetype Simd: SimdFloat<Scalar = Self> + StdFloat + SimdPartialOrd + Copy + Add<Output = Self::Simd> + Sub<Output = Self::Simd> + Mul<Output = Self::Simd> + Div<Output = Self::Simd> + Rem<Output = Self::Simd>
type Simd: SimdFloat<Scalar = Self> + StdFloat + SimdPartialOrd + Copy + Add<Output = Self::Simd> + Sub<Output = Self::Simd> + Mul<Output = Self::Simd> + Div<Output = Self::Simd> + Rem<Output = Self::Simd>
The SIMD vector type for this sample type.
This associated type provides all necessary SIMD operations for DSP processing.
Required Methods§
Sourcefn simd_splat(value: Self) -> Self::Simd
fn simd_splat(value: Self) -> Self::Simd
Create a SIMD vector with all lanes set to the given value.
Sourcefn simd_from_slice(slice: &[Self]) -> Self::Simd
fn simd_from_slice(slice: &[Self]) -> Self::Simd
Load a SIMD vector from a slice (must have at least SIMD_LANES elements).
Sourcefn simd_to_array(simd: Self::Simd) -> [Self; 4]
fn simd_to_array(simd: Self::Simd) -> [Self; 4]
Convert a SIMD vector to an array.
Sourcefn simd_select_gt(
a: Self::Simd,
b: Self::Simd,
if_true: Self::Simd,
if_false: Self::Simd,
) -> Self::Simd
fn simd_select_gt( a: Self::Simd, b: Self::Simd, if_true: Self::Simd, if_false: Self::Simd, ) -> Self::Simd
Select elements based on a greater-than comparison.
Returns if_true[i] where a[i] > b[i], otherwise if_false[i].
Sourcefn simd_select_lt(
a: Self::Simd,
b: Self::Simd,
if_true: Self::Simd,
if_false: Self::Simd,
) -> Self::Simd
fn simd_select_lt( a: Self::Simd, b: Self::Simd, if_true: Self::Simd, if_false: Self::Simd, ) -> Self::Simd
Select elements based on a less-than comparison.
Returns if_true[i] where a[i] < b[i], otherwise if_false[i].
Sourcefn simd_lane_offsets() -> Self::Simd
fn simd_lane_offsets() -> Self::Simd
Returns a SIMD vector with lane offsets [0.0, 1.0, 2.0, 3.0].
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.