Module translate

Module 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 as 0x8000 for u16 or 0x80000000 for u32.
  • 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 to 1.0 (inclusive).

These rules are applied to the following native Rust types:

  • u8, u16, u32, and u64 for unsigned PCM 8 to 64 bit audio modulation.
  • i8, i16, i32, and i64 for signed PCM 8 to 64 bit audio modulation.
  • f32 and f64 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§

IntTranslationError
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.