rodio

Trait Sample

Source
pub trait Sample: CpalSample {
    // Required methods
    fn lerp(first: Self, second: Self, numerator: u32, denominator: u32) -> Self;
    fn amplify(self, value: f32) -> Self;
    fn to_f32(self) -> f32;
    fn saturating_add(self, other: Self) -> Self;
    fn zero_value() -> Self;
}
Expand description

Represents a value of a single sample.

This trait is implemented by default on three types: i16, u16 and f32.

  • For i16, silence corresponds to the value 0. The minimum and maximum amplitudes are represented by i16::min_value() and i16::max_value() respectively.
  • For u16, silence corresponds to the value u16::max_value() / 2. The minimum and maximum amplitudes are represented by 0 and u16::max_value() respectively.
  • For f32, silence corresponds to the value 0.0. The minimum and maximum amplitudes are represented by -1.0 and 1.0 respectively.

You can implement this trait on your own type as well if you wish so.

Required Methods§

Source

fn lerp(first: Self, second: Self, numerator: u32, denominator: u32) -> Self

Linear interpolation between two samples.

The result should be equal to first * numerator / denominator + second * (1 - numerator / denominator).

Source

fn amplify(self, value: f32) -> Self

Multiplies the value of this sample by the given amount.

Source

fn to_f32(self) -> f32

Converts the sample to an f32 value.

Source

fn saturating_add(self, other: Self) -> Self

Calls saturating_add on the sample.

Source

fn zero_value() -> Self

Returns the value corresponding to the absence of sound.

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

Source§

fn lerp(first: f32, second: f32, numerator: u32, denominator: u32) -> f32

Source§

fn amplify(self, value: f32) -> f32

Source§

fn to_f32(self) -> f32

Source§

fn saturating_add(self, other: f32) -> f32

Source§

fn zero_value() -> f32

Source§

impl Sample for i16

Source§

fn lerp(first: i16, second: i16, numerator: u32, denominator: u32) -> i16

Source§

fn amplify(self, value: f32) -> i16

Source§

fn to_f32(self) -> f32

Source§

fn saturating_add(self, other: i16) -> i16

Source§

fn zero_value() -> i16

Source§

impl Sample for u16

Source§

fn lerp(first: u16, second: u16, numerator: u32, denominator: u32) -> u16

Source§

fn amplify(self, value: f32) -> u16

Source§

fn to_f32(self) -> f32

Source§

fn saturating_add(self, other: u16) -> u16

Source§

fn zero_value() -> u16

Implementors§