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) -> Self

Create this sample from a f16, trying to represent the same numerical value

fn from_f32(value: f32) -> Self

Create this sample from a f32, trying to represent the same numerical value

fn from_u32(value: u32) -> Self

Create 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_slice

fn 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_64 lacks the instructions to convert u32 to floats, so this will inevitably be slow on x86_64.

Implementors