pub trait SampleType: SampleFrom {
type ImplFor;
type Longer;
type Shorter;
type Signed;
type Unsigned;
const MIDNUM: Self;
const TYPE_NAME: &'static str;
Show 66 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 clamp_to_i8(self) -> i8;
fn clamp_to_i16(self) -> i16;
fn clamp_to_i24(self) -> i24;
fn clamp_to_i32(self) -> i32;
fn clamp_to_i64(self) -> i64;
fn clamp_to_u8(self) -> u8;
fn clamp_to_u16(self) -> u16;
fn clamp_to_u24(self) -> u24;
fn clamp_to_u32(self) -> u32;
fn clamp_to_u64(self) -> u64;
fn clamp_to_f32(self) -> f32;
fn clamp_to_f64(self) -> f64;
fn clamp_to_i128(self) -> i128;
fn clamp_to_u128(self) -> u128;
fn to_longer(self) -> Self::Longer;
fn to_shorter(self) -> Self::Shorter;
fn as_longer(self) -> Self::Longer;
fn as_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 interpolate(self, target: Self, s: f64) -> Self;
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
SampleType
for 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 clamp_to_i8(self) -> i8
fn clamp_to_i8(self) -> i8
Clamp to i8
Sourcefn clamp_to_i16(self) -> i16
fn clamp_to_i16(self) -> i16
Clamp to i16
Sourcefn clamp_to_i24(self) -> i24
fn clamp_to_i24(self) -> i24
Clamp to i24
Sourcefn clamp_to_i32(self) -> i32
fn clamp_to_i32(self) -> i32
Clamp to i32
Sourcefn clamp_to_i64(self) -> i64
fn clamp_to_i64(self) -> i64
Clamp to i64
Sourcefn clamp_to_u8(self) -> u8
fn clamp_to_u8(self) -> u8
Clamp to u8
Sourcefn clamp_to_u16(self) -> u16
fn clamp_to_u16(self) -> u16
Clamp to u16
Sourcefn clamp_to_u24(self) -> u24
fn clamp_to_u24(self) -> u24
Clamp to u24
Sourcefn clamp_to_u32(self) -> u32
fn clamp_to_u32(self) -> u32
Clamp to u32
Sourcefn clamp_to_u64(self) -> u64
fn clamp_to_u64(self) -> u64
Clamp to u64
Sourcefn clamp_to_f32(self) -> f32
fn clamp_to_f32(self) -> f32
Clamp to f32
Sourcefn clamp_to_f64(self) -> f64
fn clamp_to_f64(self) -> f64
Clamp to f64
Sourcefn clamp_to_i128(self) -> i128
fn clamp_to_i128(self) -> i128
Clamp to i128
Sourcefn clamp_to_u128(self) -> u128
fn clamp_to_u128(self) -> u128
Clamp to u128
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 as_shorter(self) -> Self::Shorter
fn as_shorter(self) -> Self::Shorter
Cast 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
x
doesn’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
x
doesn’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.
Sourcefn interpolate(self, target: Self, s: f64) -> Self
fn interpolate(self, target: Self, s: f64) -> Self
interpolate between self
to target
by s
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.