Skip to main content

RawSample

Trait RawSample 

Source
pub trait RawSample
where Self: Sized,
{ // Required methods fn to_scaled_float<T: FloatCore + ToPrimitive>(&self) -> T; fn from_scaled_float<T: FloatCore + ToPrimitive>( value: T, ) -> ConversionResult<Self>; }
Expand description

A trait for converting a given sample type to and from floating point values. The floating point values use the range -1.0 to +1.0. When converting to/from signed integers, the range does not include +1.0. For example, an 8-bit signed integer supports the range -128 to +127. When these values are converted to float, 0 becomes 0.0, -128 becomes -1.0, and 127 becomes 127/128 ≈ 0.992. Unsigned integers are also converted to the same -1.0 to +1.0 range. For an 8-but unsigned integer, 128 is the center point and becomes 0.0. The value 0 becomes -1.0, and 255 becomes 127/128 ≈ 0.992.

Required Methods§

Source

fn to_scaled_float<T: FloatCore + ToPrimitive>(&self) -> T

Convert the sample value to a float in the range -1.0 .. +1.0.

Source

fn from_scaled_float<T: FloatCore + ToPrimitive>( value: T, ) -> ConversionResult<Self>

Convert a float in the range -1.0 .. +1.0 to a sample value. Values outside the allowed range are clipped to the nearest limit.

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

Source§

impl RawSample for f64

Source§

impl RawSample for i8

Source§

impl RawSample for i16

Source§

impl RawSample for i32

Source§

impl RawSample for i64

Source§

impl RawSample for u8

Source§

impl RawSample for u16

Source§

impl RawSample for u32

Source§

impl RawSample for u64

Implementors§