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.

Object Safety§

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§