pub const I16_MAX_F32: f32 = 32767.0;
pub const I16_MIN_F32: f32 = -32768.0;
pub const I16_MAX_F64: f64 = 32767.0;
pub const I16_SCALE_F32: f32 = 32768.0;
pub const I16_TO_F32_SCALE: f32 = 1.0 / 32768.0;
#[inline]
pub fn f32_to_i32(sample: f32) -> i32 {
libm::roundf(sample * I16_SCALE_F32).clamp(I16_MIN_F32, I16_MAX_F32) as i32
}
#[inline]
pub fn i32_to_f32(sample: i32) -> f32 {
sample as f32 * I16_TO_F32_SCALE
}
#[inline]
pub fn f32_to_i16(sample: f32) -> i16 {
libm::roundf(sample * I16_SCALE_F32).clamp(I16_MIN_F32, I16_MAX_F32) as i16
}
#[inline]
pub fn i16_to_f32(sample: i16) -> f32 {
sample as f32 * I16_TO_F32_SCALE
}