idsp

Trait Coefficient

Source
pub trait Coefficient:
    'static
    + Copy
    + Num
    + AsPrimitive<Self::ACCU> {
    type ACCU: AsPrimitive<Self> + Num;

    const ONE: Self;
    const NEG_ONE: Self;
    const ZERO: Self;
    const MIN: Self;
    const MAX: Self;

    // Required methods
    fn macc(self, s: Self::ACCU, min: Self, max: Self, e1: Self) -> (Self, Self);
    fn clip(self, min: Self, max: Self) -> Self;
    fn mul_scaled(self, other: Self) -> Self;
    fn div_scaled(self, other: Self) -> Self;
    fn quantize<C>(value: C) -> Self
       where Self: AsPrimitive<C>,
             C: Float + AsPrimitive<Self>;
}
Expand description

Helper trait unifying fixed point and floating point coefficients/samples

Required Associated Constants§

Source

const ONE: Self

Multiplicative identity

Source

const NEG_ONE: Self

Negative multiplicative identity, equal to -Self::ONE.

Source

const ZERO: Self

Additive identity

Source

const MIN: Self

Lowest value

Source

const MAX: Self

Highest value

Required Associated Types§

Source

type ACCU: AsPrimitive<Self> + Num

Accumulator type

Required Methods§

Source

fn macc(self, s: Self::ACCU, min: Self, max: Self, e1: Self) -> (Self, Self)

Proper scaling and potentially using a wide accumulator. Clamp self such that min <= self <= max. Undefined result if max < min.

Source

fn clip(self, min: Self, max: Self) -> Self

Clamp to between min and max

Undefined if min > max.

Source

fn mul_scaled(self, other: Self) -> Self

Multiplication (scaled)

Source

fn div_scaled(self, other: Self) -> Self

Division (scaled)

Source

fn quantize<C>(value: C) -> Self
where Self: AsPrimitive<C>, C: Float + AsPrimitive<Self>,

Scale and quantize a floating point value.

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 Coefficient for f32

Source§

const ONE: Self = 1f32

Source§

const NEG_ONE: Self = -1f32

Source§

const ZERO: Self = 0f32

Source§

const MIN: Self = -Inf_f32

Source§

const MAX: Self = +Inf_f32

Source§

type ACCU = f32

Source§

fn macc(self, s: Self::ACCU, min: Self, max: Self, _e1: Self) -> (Self, Self)

Source§

fn clip(self, min: Self, max: Self) -> Self

Source§

fn div_scaled(self, other: Self) -> Self

Source§

fn mul_scaled(self, other: Self) -> Self

Source§

fn quantize<C: Float + AsPrimitive<Self>>(value: C) -> Self

Source§

impl Coefficient for f64

Source§

const ONE: Self = 1f64

Source§

const NEG_ONE: Self = -1f64

Source§

const ZERO: Self = 0f64

Source§

const MIN: Self = -Inf_f64

Source§

const MAX: Self = +Inf_f64

Source§

type ACCU = f64

Source§

fn macc(self, s: Self::ACCU, min: Self, max: Self, _e1: Self) -> (Self, Self)

Source§

fn clip(self, min: Self, max: Self) -> Self

Source§

fn div_scaled(self, other: Self) -> Self

Source§

fn mul_scaled(self, other: Self) -> Self

Source§

fn quantize<C: Float + AsPrimitive<Self>>(value: C) -> Self

Source§

impl Coefficient for i8

Source§

const ONE: Self = 64i8

Source§

const NEG_ONE: Self = -64i8

Source§

const ZERO: Self = 0i8

Source§

const MIN: Self = -128i8

Source§

const MAX: Self = 127i8

Source§

type ACCU = i16

Source§

fn macc(self, s: Self::ACCU, min: Self, max: Self, e1: Self) -> (Self, Self)

Source§

fn clip(self, min: Self, max: Self) -> Self

Source§

fn div_scaled(self, other: Self) -> Self

Source§

fn mul_scaled(self, other: Self) -> Self

Source§

fn quantize<C>(value: C) -> Self
where Self: AsPrimitive<C>, C: Float + AsPrimitive<Self>,

Source§

impl Coefficient for i16

Source§

const ONE: Self = 16_384i16

Source§

const NEG_ONE: Self = -16_384i16

Source§

const ZERO: Self = 0i16

Source§

const MIN: Self = -32_768i16

Source§

const MAX: Self = 32_767i16

Source§

type ACCU = i32

Source§

fn macc(self, s: Self::ACCU, min: Self, max: Self, e1: Self) -> (Self, Self)

Source§

fn clip(self, min: Self, max: Self) -> Self

Source§

fn div_scaled(self, other: Self) -> Self

Source§

fn mul_scaled(self, other: Self) -> Self

Source§

fn quantize<C>(value: C) -> Self
where Self: AsPrimitive<C>, C: Float + AsPrimitive<Self>,

Source§

impl Coefficient for i32

Source§

const ONE: Self = 1_073_741_824i32

Source§

const NEG_ONE: Self = -1_073_741_824i32

Source§

const ZERO: Self = 0i32

Source§

const MIN: Self = -2_147_483_648i32

Source§

const MAX: Self = 2_147_483_647i32

Source§

type ACCU = i64

Source§

fn macc(self, s: Self::ACCU, min: Self, max: Self, e1: Self) -> (Self, Self)

Source§

fn clip(self, min: Self, max: Self) -> Self

Source§

fn div_scaled(self, other: Self) -> Self

Source§

fn mul_scaled(self, other: Self) -> Self

Source§

fn quantize<C>(value: C) -> Self
where Self: AsPrimitive<C>, C: Float + AsPrimitive<Self>,

Source§

impl Coefficient for i64

Source§

const ONE: Self = 4_611_686_018_427_387_904i64

Source§

const NEG_ONE: Self = -4_611_686_018_427_387_904i64

Source§

const ZERO: Self = 0i64

Source§

const MIN: Self = -9_223_372_036_854_775_808i64

Source§

const MAX: Self = 9_223_372_036_854_775_807i64

Source§

type ACCU = i128

Source§

fn macc(self, s: Self::ACCU, min: Self, max: Self, e1: Self) -> (Self, Self)

Source§

fn clip(self, min: Self, max: Self) -> Self

Source§

fn div_scaled(self, other: Self) -> Self

Source§

fn mul_scaled(self, other: Self) -> Self

Source§

fn quantize<C>(value: C) -> Self
where Self: AsPrimitive<C>, C: Float + AsPrimitive<Self>,

Implementors§