Trait Sample

Source
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§

Source

const ZERO: Self

The zero value for this sample type (silence).

Source

const ONE: Self

The unit value for this sample type (full scale).

Source

const EPSILON: Self

Machine epsilon i.e. the difference between 1.0 and the next larger representable number.

Source

const PI: Self

Pi (π).

Source

const INV_PI: Self

The reciprocal of pi (1/π).

Source

const FRAC_PI_2: Self

Half of pi (π/2).

Source

const FRAC_PI_3: Self

Third of pi (π/3).

Source

const FRAC_PI_4: Self

Quarter of pi (π/4).

Source

const TAU: Self

Tau; full circle constant (τ = 2π).

Source

const INV_TAU: Self

Inverse tau (1/τ = 1/2π).

Source

const PHI: Self

The golden ratio (φ).

Source

const E: Self

Euler’s number (e).

Source

const SQRT_2: Self

Square root of 2.

Source

const INV_SQRT_2: Self

Inverse square root of 2.

Required Associated Types§

Source

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§

Source

fn from_f64(value: f64) -> Self

Convert from an f64 value.

Source

fn to_f64(self) -> f64

Convert to an f64 value.

Source

fn abs(self) -> Self

Returns the absolute value of this sample.

Source

fn simd_splat(value: Self) -> Self::Simd

Create a SIMD vector with all lanes set to the given value.

Source

fn simd_from_slice(slice: &[Self]) -> Self::Simd

Load a SIMD vector from a slice (must have at least SIMD_LANES elements).

Source

fn simd_to_array(simd: Self::Simd) -> [Self; 4]

Convert a SIMD vector to an array.

Source

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].

Source

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].

Source

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.

Implementations on Foreign Types§

Source§

impl Sample for f32

Source§

const ZERO: Self = 0f32

Source§

const ONE: Self = 1f32

Source§

const EPSILON: Self = 1.1920929E-7f32

Source§

const PI: Self = 3.14159274f32

Source§

const INV_PI: Self = 0.318309873f32

Source§

const FRAC_PI_2: Self = 1.57079637f32

Source§

const FRAC_PI_3: Self = 1.04719758f32

Source§

const FRAC_PI_4: Self = 0.785398185f32

Source§

const TAU: Self = 6.28318548f32

Source§

const INV_TAU: Self = 0.159154937f32

Source§

const PHI: Self = 1.61803401f32

Source§

const E: Self = 2.71828175f32

Source§

const SQRT_2: Self = 1.41421354f32

Source§

const INV_SQRT_2: Self = 0.707106769f32

Source§

type Simd = Simd<f32, 4>

Source§

fn from_f64(value: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn abs(self) -> Self

Source§

fn simd_splat(value: Self) -> Self::Simd

Source§

fn simd_from_slice(slice: &[Self]) -> Self::Simd

Source§

fn simd_to_array(simd: Self::Simd) -> [Self; 4]

Source§

fn simd_select_gt( a: Self::Simd, b: Self::Simd, if_true: Self::Simd, if_false: Self::Simd, ) -> Self::Simd

Source§

fn simd_select_lt( a: Self::Simd, b: Self::Simd, if_true: Self::Simd, if_false: Self::Simd, ) -> Self::Simd

Source§

fn simd_lane_offsets() -> Self::Simd

Source§

impl Sample for f64

Source§

const ZERO: Self = 0f64

Source§

const ONE: Self = 1f64

Source§

const EPSILON: Self = 2.2204460492503131E-16f64

Source§

const PI: Self = 3.1415926535897931f64

Source§

const INV_PI: Self = 0.31830988618379069f64

Source§

const FRAC_PI_2: Self = 1.5707963267948966f64

Source§

const FRAC_PI_3: Self = 1.0471975511965979f64

Source§

const FRAC_PI_4: Self = 0.78539816339744828f64

Source§

const TAU: Self = 6.2831853071795862f64

Source§

const INV_TAU: Self = 0.15915494309189535f64

Source§

const PHI: Self = 1.6180339887498949f64

Source§

const E: Self = 2.7182818284590451f64

Source§

const SQRT_2: Self = 1.4142135623730951f64

Source§

const INV_SQRT_2: Self = 0.70710678118654757f64

Source§

type Simd = Simd<f64, 4>

Source§

fn from_f64(value: f64) -> Self

Source§

fn to_f64(self) -> f64

Source§

fn abs(self) -> Self

Source§

fn simd_splat(value: Self) -> Self::Simd

Source§

fn simd_from_slice(slice: &[Self]) -> Self::Simd

Source§

fn simd_to_array(simd: Self::Simd) -> [Self; 4]

Source§

fn simd_select_gt( a: Self::Simd, b: Self::Simd, if_true: Self::Simd, if_false: Self::Simd, ) -> Self::Simd

Source§

fn simd_select_lt( a: Self::Simd, b: Self::Simd, if_true: Self::Simd, if_false: Self::Simd, ) -> Self::Simd

Source§

fn simd_lane_offsets() -> Self::Simd

Implementors§