Trait FromNativeSample
pub trait FromNativeSample: Sized + Copy + Default + 'static
Create an arbitrary sample type from one of the defined sample types.
Should be compiled to a no-op where the file contains the predicted sample
type. The slice functions should be optimized into a memcpy where there is
no conversion needed.
Required Methods
fn from_f16(value: f16) -> SelfCreate this sample from a f16, trying to represent the same numerical value
fn from_f32(value: f32) -> SelfCreate this sample from a f32, trying to represent the same numerical value
fn from_u32(value: u32) -> SelfCreate this sample from a u32, trying to represent the same numerical value
Provided Methods
fn from_f16s(from: &[f16], to: &mut [Self])Convert all values from the slice into this type. This function exists to allow the compiler to perform a vectorization optimization. Note that this default implementation will not be vectorized by the compiler automatically. For maximum performance you will need to override this function and implement it via an explicit batched conversion such as
convert_to_f32_slicefn from_f32s(from: &[f32], to: &mut [Self])Convert all values from the slice into this type. This function exists to allow the compiler to perform a vectorization optimization. Note that this default implementation will be vectorized by the compiler automatically.
fn from_u32s(from: &[u32], to: &mut [Self])Convert all values from the slice into this type. This function exists to allow the compiler to perform a vectorization optimization. Note that this default implementation will be vectorized by the compiler automatically, provided that the CPU supports the necessary conversion instructions. For example,
x86_64lacks the instructions to convertu32to floats, so this will inevitably be slow onx86_64.
Implementors
impl FromNativeSample for Sampleimpl FromNativeSample for f16impl FromNativeSample for f32impl FromNativeSample for u32