Module fixedpoint

Source
Expand description

Fixed point representation of beat time and seconds time.

The representation uses 31 least significant bits for the fractional part.

§Example

let x = 1.330f64;
let beats = BeatTime::from(x);

assert_eq!(beats.0, (x * BeatTime::FACTOR as f64).round() as i64);

The constants: BeatTime::FACTOR and SecTime::FACTOR are set to: 2^31:

assert_eq!(BeatTime::FACTOR, 1i64 << 31);
assert_eq!(SecTime::FACTOR, 1i64 << 31);

Hence, the error of converting a f64 to BeatTime or SecTime and back is not going to exceed 2^(-31) ~ 0.0000000004656613.

let x = 17.932f64;
let y = f64::from(SecTime::from(x));

assert!(f64::abs(x - y) < (SecTime::FACTOR as f64).recip());

See also: https://github.com/free-audio/clap/blob/main/include/clap/fixedpoint.h.

Structs§

BeatTime
Time in beats.
SecTime
Time in seconds.