Skip to content

Commit

Permalink
micro optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
phip1611 committed Sep 22, 2024
1 parent 66b6ec7 commit 962a091
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit 962a091

Please sign in to comment.