From 18e41b32ffa9046287d7cb1d438ad1343a50fd71 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 15 Apr 2020 15:03:11 -0700 Subject: math: Add dB_to_lin() and lin_to_dB() These are simply shorthands, but make the code a little more readable with respect to intent. It allows to replace const double power_db = 10 * std::log10(power_lin); with const double power_db = lin_to_dB(power_lin); which expresses the intent a little more clearly and concisely. --- host/include/uhd/utils/math.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/host/include/uhd/utils/math.hpp b/host/include/uhd/utils/math.hpp index aca0b7c92..d442d6a94 100644 --- a/host/include/uhd/utils/math.hpp +++ b/host/include/uhd/utils/math.hpp @@ -234,6 +234,17 @@ UHD_INLINE bool frequencies_are_equal(double lhs, double rhs) == fp_compare::fp_compare_delta(rhs, FREQ_COMPARISON_DELTA_HZ)); } +inline double dB_to_lin(const double dB_val) +{ + return std::pow(10, (dB_val) / 10.0); +} + +inline double lin_to_dB(const double val) +{ + return 10 * std::log10(val); +} + + //! Portable version of lcm() across Boost versions template inline IntegerType lcm(IntegerType x, IntegerType y) -- cgit v1.2.3