diff options
author | kcgen <kcgen@users.noreply.github.com> | 2022-10-13 06:02:36 +0300 |
---|---|---|
committer | kcgen <1557255+kcgen@users.noreply.github.com> | 2022-10-14 05:18:46 +0300 |
commit | 4282def0e464406d9ffee0dc778565e8ade188a8 (patch) | |
tree | b79051316445f72913f2fa14cc21e191a16c0c47 | |
parent | a1069b4af4d3f6371d58199a40de81b80a54045a (diff) |
Use floats in gain and decibel conversion routines
-rw-r--r-- | include/math_utils.h | 8 | ||||
-rw-r--r-- | src/hardware/adlib_gold.cpp | 10 | ||||
-rw-r--r-- | src/hardware/mixer.cpp | 8 |
3 files changed, 13 insertions, 13 deletions
diff --git a/include/math_utils.h b/include/math_utils.h index 40e8f399d..34d4f37f3 100644 --- a/include/math_utils.h +++ b/include/math_utils.h @@ -127,14 +127,14 @@ constexpr T1 left_shift_signed(T1 value, T2 amount) return static_cast<T1>(shifted); } -inline double decibel_to_gain(const double decibel) +inline float decibel_to_gain(const float decibel) { - return pow(10.0, decibel / 20.0); + return powf(10.0f, decibel / 20.0f); } -inline double gain_to_decibel(const double gain) +inline float gain_to_decibel(const float gain) { - return 20.0 * log(gain) / log(10.0); + return 20.0f * logf(gain) / logf(10.0f); } // A wrapper to convert a scalar gain to a percentage. diff --git a/src/hardware/adlib_gold.cpp b/src/hardware/adlib_gold.cpp index 2367df1bf..dfc964cc4 100644 --- a/src/hardware/adlib_gold.cpp +++ b/src/hardware/adlib_gold.cpp @@ -151,13 +151,13 @@ void StereoProcessor::ControlWrite(const StereoProcessorControlReg reg, const uint8_t data) { auto calc_volume_gain = [](const int value) { - constexpr auto min_gain_db = -128.0; - constexpr auto max_gain_db = 6.0; - constexpr auto step_db = 2.0; + constexpr auto min_gain_db = -128.0f; + constexpr auto max_gain_db = 6.0f; + constexpr auto step_db = 2.0f; - auto val = value - volume_0db_value; + auto val = static_cast<float>(value - volume_0db_value); auto gain_db = clamp(val * step_db, min_gain_db, max_gain_db); - return static_cast<float>(decibel_to_gain(gain_db)); + return decibel_to_gain(gain_db); }; auto calc_filter_gain_db = [](const int value) { diff --git a/src/hardware/mixer.cpp b/src/hardware/mixer.cpp index fb8f9ab99..8d6b34af1 100644 --- a/src/hardware/mixer.cpp +++ b/src/hardware/mixer.cpp @@ -2366,10 +2366,10 @@ private: const std::string &chorus) { WriteOut(column_layout.c_str(), name.c_str(), - volume.left * 100.0f, - volume.right * 100.0f, - gain_to_decibel(volume.left), - gain_to_decibel(volume.right), + static_cast<double>(volume.left * 100.0f), + static_cast<double>(volume.right * 100.0f), + static_cast<double>(gain_to_decibel(volume.left)), + static_cast<double>(gain_to_decibel(volume.right)), mode.c_str(), xfeed.c_str(), reverb.c_str(), |