libflo_audio/core/
audio_constants.rs1pub const I16_MAX_F32: f32 = 32767.0;
3
4pub const I16_MIN_F32: f32 = -32768.0;
6
7pub const I16_MAX_F64: f64 = 32767.0;
9
10pub const I16_TO_F32_SCALE: f32 = 1.0 / 32767.0;
12
13pub const I16_TO_F32_SCALE_ALT: f32 = 1.0 / 32768.0;
15
16#[inline]
18pub fn f32_to_i32(sample: f32) -> i32 {
19 (sample * I16_MAX_F32).clamp(I16_MIN_F32, I16_MAX_F32) as i32
20}
21
22#[inline]
24pub fn i32_to_f32(sample: i32) -> f32 {
25 sample as f32 * I16_TO_F32_SCALE
26}
27
28#[inline]
30pub fn f32_to_i16(sample: f32) -> i16 {
31 (sample * I16_MAX_F32).clamp(I16_MIN_F32, I16_MAX_F32) as i16
32}
33
34#[inline]
36pub fn i16_to_f32(sample: i16) -> f32 {
37 sample as f32 * I16_TO_F32_SCALE
38}