Trait audiostream::Sample [-]  [+] [src]

pub trait Sample: Add<Self> + Mul<Self> + Div<Self> + NumCast + FromPrimitive + Debug + Copy + Send {
    fn max() -> Self;
    fn min() -> Self;
    fn clips_hard() -> bool;
    fn clip(&self) -> Self;

    fn to_float<F: Float + Sample>(x: Self) -> F { ... }
    fn from_float<F: Float + Sample>(x: F) -> Self { ... }
    fn convert<X: Sample>(a: Self) -> X { ... }
}

Type bound for sample formats.

Required Methods

fn max() -> Self

Maximum value of a valid sample.

fn min() -> Self

Minimum value of a valid sample.

fn clips_hard() -> bool

True if this type has a hard limit on values in range [min, max].

If false, values outside this range are representable and may be used but may incur loss of precision.

fn clip(&self) -> Self

Clip a value to be in range min, max.

Provided Methods

fn to_float<F: Float + Sample>(x: Self) -> F

Get a floating-point representation of a sample.

Full-scale output is in the range -1 to 1. Soft-clipped types may yield values outside this range.

fn from_float<F: Float + Sample>(x: F) -> Self

Convert a floating-point sample to any other format.

Values outside the normal sample range in soft-clipped formats will not be clipped. When converting to a hard-clipped format, clipping may occur.

fn convert<X: Sample>(a: Self) -> X

Convert from Self to an arbitrary other sample format.

Does not currently clip values. This should be added.

The default intermediate format here is f64, capable of losslessly converting all formats shorter than 52 bits.

Implementors