From 74a9e294b1171692131e58a3e36b0702db3b7f5f Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 4 Jan 2023 16:45:11 +0100 Subject: [PATCH] Make gain_to_db() branchless --- src/util.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/util.rs b/src/util.rs index 488ee88b..c4a53e61 100644 --- a/src/util.rs +++ b/src/util.rs @@ -39,11 +39,7 @@ pub fn db_to_gain(dbs: f32) -> f32 { /// [`MINUS_INFINITY_DB`]. #[inline] pub fn gain_to_db(gain: f32) -> f32 { - if gain > MINUS_INFINITY_GAIN { - gain.log10() * 20.0 - } else { - MINUS_INFINITY_DB - } + f32::max(gain, MINUS_INFINITY_GAIN).log10() * 20.0 } /// Convert a MIDI note ID to a frequency at A4 = 440 Hz equal temperament and middle C = note 60 =