[][src]Trait bae_rs::sample_format::SampleFormat

pub trait SampleFormat: Default + Neg<Output = Self> + Add<Self, Output = Self> + AddAssign<Self> + Sub<Self, Output = Self> + SubAssign<Self> + Mul<Self, Output = Self> + MulAssign<Self> + Mul<SampleT, Output = Self> + MulAssign<SampleT> + Mul<MathT, Output = Self> + MulAssign<MathT> + From<SampleT> + Into<SampleT> + TryFrom<Vec<u8>, Error = String> + Into<Vec<u8>> + TryFrom<Vec<i16>, Error = String> + Into<Vec<i16>> + TryFrom<Vec<i32>, Error = String> + Into<Vec<i32>> {
    fn from_sample(x: SampleT) -> Self;
fn into_sample(self) -> SampleT;
fn num_samples() -> usize; }

Trait implementing the ability to perform math operations with a polyphonic sample format and a monophonic sample.

Dependencies:

  • Default - A good default value for audio samples is 0.
  • Most mathematical operators are required to be implemented to be able to perform common operations on sample values.
  • Mul/MulAssign is defined for both MathT as well as SampleT for the convenience of common audio operations.
  • From/Into implemented for SampleT - These functions should be simple calls to from_sample and into_sample respectively.
  • TryFrom/Into implemented for Vec<_> - These functions should convert the sample values to the given standard integer types. As Vecs are generic types, it cannot be assumed that any attempted conversions of Vecs to a given sample format will succeed. Therefore those conversions use TryFrom to indicate when there is an issue, which can be communicated with the given String used for the error type. An example of such an error could be (for the Stereo type):
format!("ERROR: Given vector was length {}. This function requires length 2.", v.len());

Required methods

fn from_sample(x: SampleT) -> Self

Creates an object from a single monophonic sample.

fn into_sample(self) -> SampleT

Converts the given polyphonic sample to a monophonic sample.

fn num_samples() -> usize

Returns the number of SampleT values held within a given SampleFormat. A common use for this would be for ensuring Vecs given to try_from have the correct size.

Loading content...

Implementors

impl SampleFormat for Mono[src]

impl SampleFormat for Stereo[src]

Loading content...