Module audio_core::translate
source · 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) / 2
such as0x8000
foru16
or0x80000000
foru32
. - 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.0
and utilises the range-1.0
to1.0
(inclusive).
These rules are applied to the following native Rust types:
u8
,u16
,u32
, andu64
for unsigned PCM 8 to 64 bit audio modulation.i8
,i16
,i32
, andi64
for signed PCM 8 to 64 bit audio modulation.f32
andf64
for 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
- Unable to translate an integer due to loss of precision.
Traits
- Trait used for translating one sample type to another.
- Trait for performing checked translations, where it’s checked if a translation would result in loss of precision.