Trait culsynth::DspType

source ·
pub trait DspType<T: DspFormatBase>: Copy + Default + Send + Add<Self, Output = Self> + Sub<Self, Output = Self> + PartialOrd {
    const PI: Self;
    const TAU: Self;

    // Required methods
    fn zero() -> Self;
    fn one() -> Self;
    fn dsp_saturating_add(self, rhs: Self) -> Self;
    fn multiply(self, rhs: Self) -> Self;
    fn divide_by_two(self) -> Self;
    fn scale(self, rhs: T::Scalar) -> Self;
}
Expand description

A trait to simplify common operations on DSP Types. This is used to maximize the amount of code that can be agnostic to fixed and floating point

Required Associated Constants§

source

const PI: Self

A constant representing the value PI (3.14159…)

source

const TAU: Self

A constant representing the value 2*[PI]

Required Methods§

source

fn zero() -> Self

Returns zero

source

fn one() -> Self

Returns one

source

fn dsp_saturating_add(self, rhs: Self) -> Self

This function will perform a saturating addition for fixed-point types, and a normal addition for floating-point types

Used for when saturation is desired to avoid overflows, not correctness

source

fn multiply(self, rhs: Self) -> Self

Multiply this type with itself. This trait does not provide any specified behavior for fixed-point overflow.

source

fn divide_by_two(self) -> Self

Divide a value by two

source

fn scale(self, rhs: T::Scalar) -> Self

Multiply this type by a Scalar. This will never overflow (by definition, the result will always be smaller)

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl DspType<i16> for I4F28

source§

const PI: Self = PhaseFxP::PI

source§

const TAU: Self = PhaseFxP::TAU

source§

fn zero() -> Self

source§

fn one() -> Self

source§

fn dsp_saturating_add(self, rhs: Self) -> Self

source§

fn multiply(self, rhs: Self) -> Self

source§

fn divide_by_two(self) -> Self

source§

fn scale(self, rhs: ScalarFxP) -> Self

Implementors§

source§

impl DspType<i16> for FrequencyFxP

source§

const PI: Self = FrequencyFxP::PI

source§

const TAU: Self = FrequencyFxP::TAU

source§

impl<T> DspType<T> for T
where T: From<IScalarFxP> + From<NoteFxP> + Float + Send,

source§

const PI: Self = Self::PI

source§

const TAU: Self = Self::TAU

source§

impl<T: Fixed16 + Send> DspType<i16> for T

source§

const PI: Self = T::PI

source§

const TAU: Self = T::TAU