pub trait SampleType: SampleFrom {
type ImplFor;
type Longer;
type Shorter;
type Signed;
type Unsigned;
const MIDNUM: Self;
const TYPE_NAME: &'static str;
Show 49 methods
// Required methods
fn new() -> Self;
fn zero() -> Self;
fn scale_from<T>(v: T) -> Self
where T: SampleType;
fn cast_from<T>(v: T) -> Self
where T: SampleType;
fn average(s1: Self, s2: Self) -> Self;
fn average_arr(arr: &[Self]) -> Self;
fn to_i8(self) -> i8;
fn to_i16(self) -> i16;
fn to_i24(self) -> i24;
fn to_i32(self) -> i32;
fn to_i64(self) -> i64;
fn to_u8(self) -> u8;
fn to_u16(self) -> u16;
fn to_u24(self) -> u24;
fn to_u32(self) -> u32;
fn to_u64(self) -> u64;
fn to_f32(self) -> f32;
fn to_f64(self) -> f64;
fn to_i128(self) -> i128;
fn to_u128(self) -> u128;
fn as_i8(self) -> i8;
fn as_i16(self) -> i16;
fn as_i24(self) -> i24;
fn as_i32(self) -> i32;
fn as_i64(self) -> i64;
fn as_u8(self) -> u8;
fn as_u16(self) -> u16;
fn as_u24(self) -> u24;
fn as_u32(self) -> u32;
fn as_u64(self) -> u64;
fn as_f32(self) -> f32;
fn as_f64(self) -> f64;
fn as_i128(self) -> i128;
fn as_u128(self) -> u128;
fn to_longer(self) -> Self::Longer;
fn to_shorter(self) -> Self::Shorter;
fn is_signed() -> bool;
fn is_unsigned() -> bool;
fn is_integer() -> bool;
fn is_float() -> bool;
fn to_signed(self) -> Self::Signed;
fn to_unsigned(self) -> Self::Unsigned;
fn sin<S>(self) -> S
where S: SampleType;
fn cos<S>(self) -> S
where S: SampleType;
fn read_le<T>(r: &mut T) -> Result<Self, Error>
where T: Read + ?Sized;
fn read_be<T>(r: &mut T) -> Result<Self, Error>
where T: Read + ?Sized;
fn write_le<T>(self, w: &mut T) -> Result<(), Error>
where T: Write + ?Sized;
fn write_be<T>(self, w: &mut T) -> Result<(), Error>
where T: Write + ?Sized;
// Provided method
fn sizeof(self) -> usize { ... }
}Expand description
- The
SampleTypefor audio processing. - The
to_*()methods are for scaling the sample to the another format. - The
as_*()methods are for casting the sample to the another format.
Required Associated Constants§
Required Associated Types§
Required Methods§
Sourcefn new() -> Self
fn new() -> Self
Create a new sample, the value is the middle value of the range of the format.
Sourcefn scale_from<T>(v: T) -> Selfwhere
T: SampleType,
fn scale_from<T>(v: T) -> Selfwhere
T: SampleType,
Scale a sample to this specified format.
Sourcefn cast_from<T>(v: T) -> Selfwhere
T: SampleType,
fn cast_from<T>(v: T) -> Selfwhere
T: SampleType,
Cast a sample to this specified format.
Sourcefn average_arr(arr: &[Self]) -> Self
fn average_arr(arr: &[Self]) -> Self
Get the average value from a sample array.
Sourcefn to_shorter(self) -> Self::Shorter
fn to_shorter(self) -> Self::Shorter
Scale to a shorter type, the shortest type is i8 or u8
Sourcefn is_unsigned() -> bool
fn is_unsigned() -> bool
Is this type an unsigned type?
Sourcefn is_integer() -> bool
fn is_integer() -> bool
Is this type an integer type?
Sourcefn to_unsigned(self) -> Self::Unsigned
fn to_unsigned(self) -> Self::Unsigned
Convert to an unsigned number type. No effects to f32 and f64
Sourcefn sin<S>(self) -> Swhere
S: SampleType,
fn sin<S>(self) -> Swhere
S: SampleType,
Sine wave generator
- The input
xdoesn’t need to be related to PI. - e.g. The type is
i8, the value is -128, then you will get sin(-PI). - e.g. The type is
u8, the value is 0, then you will get sin(-PI) too.
Sourcefn cos<S>(self) -> Swhere
S: SampleType,
fn cos<S>(self) -> Swhere
S: SampleType,
Cosine wave generator
- The input
xdoesn’t need to be related to PI. - e.g. The type is
i8, the value is -128, then you will get cos(-PI). - e.g. The type is
u8, the value is 0, then you will get cos(-PI) too.
Provided Methods§
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.