Sample

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 {
Show 14 associated constants and 3 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;
}
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 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.

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: f32 = 0f32

Source§

const ONE: f32 = 1f32

Source§

const EPSILON: f32 = 1.1920929E-7f32

Source§

const PI: f32 = 3.14159274f32

Source§

const INV_PI: f32 = 0.318309873f32

Source§

const FRAC_PI_2: f32 = 1.57079637f32

Source§

const FRAC_PI_3: f32 = 1.04719758f32

Source§

const FRAC_PI_4: f32 = 0.785398185f32

Source§

const TAU: f32 = 6.28318548f32

Source§

const INV_TAU: f32 = 0.159154937f32

Source§

const PHI: f32 = 1.61803401f32

Source§

const E: f32 = 2.71828175f32

Source§

const SQRT_2: f32 = 1.41421354f32

Source§

const INV_SQRT_2: f32 = 0.707106769f32

Source§

fn from_f64(value: f64) -> f32

Source§

fn to_f64(self) -> f64

Source§

fn abs(self) -> f32

Source§

impl Sample for f64

Source§

const ZERO: f64 = 0f64

Source§

const ONE: f64 = 1f64

Source§

const EPSILON: f64 = 2.2204460492503131E-16f64

Source§

const PI: f64 = 3.1415926535897931f64

Source§

const INV_PI: f64 = 0.31830988618379069f64

Source§

const FRAC_PI_2: f64 = 1.5707963267948966f64

Source§

const FRAC_PI_3: f64 = 1.0471975511965979f64

Source§

const FRAC_PI_4: f64 = 0.78539816339744828f64

Source§

const TAU: f64 = 6.2831853071795862f64

Source§

const INV_TAU: f64 = 0.15915494309189535f64

Source§

const PHI: f64 = 1.6180339887498949f64

Source§

const E: f64 = 2.7182818284590451f64

Source§

const SQRT_2: f64 = 1.4142135623730951f64

Source§

const INV_SQRT_2: f64 = 0.70710678118654757f64

Source§

fn from_f64(value: f64) -> f64

Source§

fn to_f64(self) -> f64

Source§

fn abs(self) -> f64

Implementors§