pub trait RawSamplewhere
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§
Sourcefn to_scaled_float<T: FloatCore + ToPrimitive>(&self) -> T
fn to_scaled_float<T: FloatCore + ToPrimitive>(&self) -> T
Convert the sample value to a float in the range -1.0 .. +1.0.
Sourcefn from_scaled_float<T: FloatCore + ToPrimitive>(
value: T,
) -> ConversionResult<Self>
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.