Expand description
Utility traits for dealing with sample translations.
Primitive samples are encoded with PCM which have a midpoint of no amplitude (i.e. silence). The possible primitives are as follows:
- Unsigned samples have a span from 0 as its highest negative amplitude to
maximum as its highest positive amplitude. The midpoint is defined as
its
(max + 1) / 2such as0x8000foru16or0x80000000foru32. - Signed samples have a midpoint at 0 and utilises the full range of the type where its minimum is the highest negative amplitude and its maximum is its highest positive amplitude.
- Float samples have a midpoint at
0.0and utilises the range-1.0to1.0(inclusive).
These rules are applied to the following native Rust types:
u8,u16,u32, andu64for unsigned PCM 8 to 64 bit audio modulation.i8,i16,i32, andi64for signed PCM 8 to 64 bit audio modulation.f32andf64for 32 and 64 bit PCM floating-point audio modulation.
The primary traits that govern how something is translated are the Translate and TryTranslate. The first deals with non-fallible translations where conversion loss is expected (as with float-integer translations). TryTranslate deals with translations where an unexpected loss in precision would otherwise occur.
See the documentation for each trait for more information.
Structs§
- IntTranslation
Error - Unable to translate an integer due to loss of precision.
Traits§
- Translate
- Trait used for translating one sample type to another.
- TryTranslate
- Trait for performing checked translations, where it’s checked if a translation would result in loss of precision.