From bf728520ca7e1de9b0ba565478d655afec91ad1f Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 19 Jan 2019 10:24:25 +0100 Subject: [PATCH] Optimize exponential interpolation. --- libs/pbd/pbd/control_math.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/pbd/pbd/control_math.h b/libs/pbd/pbd/control_math.h index 9a59a3c9e5..c4f0566226 100644 --- a/libs/pbd/pbd/control_math.h +++ b/libs/pbd/pbd/control_math.h @@ -86,12 +86,18 @@ interpolate_linear (double from, double to, double fraction) } static inline double -interpolate_logarithmic (double from, double to, double fraction, double lower, double upper) +interpolate_logarithmic (double from, double to, double fraction, double /*lower*/, double /*upper*/) { - // this is expensive -- optimize +#if 0 + /* this is expensive, original math incl. range-check assertions */ double l0 = logscale_to_position (from, lower, upper); double l1 = logscale_to_position (to, lower, upper); return position_to_logscale (l0 + fraction * (l1 - l0), lower, upper); +#else + assert (from > 0 && from * to > 0); + assert (fraction >= 0 && fraction <= 1); + return from * pow (to / from, fraction); +#endif } static inline double