From 962a091eb4263c91cae46b670d7060def7183711 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Sun, 22 Sep 2024 14:59:29 +0200 Subject: [PATCH] micro optimization --- src/util.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util.rs b/src/util.rs index f4b43f4..beaf2a4 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,11 +4,13 @@ /// Transforms an audio sample in range `i16::MIN..=i16::MAX` to a `f32` in /// range `-1.0..1.0`. #[inline] -pub fn i16_sample_to_f32(mut val: i16) -> f32 { +pub fn i16_sample_to_f32(val: i16) -> f32 { + // If to prevent division result >1.0. if val == i16::MIN { - val += 1; + -1.0 + } else { + val as f32 / i16::MAX as f32 } - val as f32 / i16::MAX as f32 } /// The sample is out of range `-1.0..1.0`.