From: Michael Froman Date: Fri, 8 Aug 2025 15:49:00 -0500 Subject: Bug 1980479 - (fix-cc46fb91c5) fixes for c++20 support Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/313582b2ffb3f3f9aaffd399e07f55c2589a587d --- common_audio/window_generator.cc | 5 ++--- .../aec3/comfort_noise_generator.cc | 9 ++------- modules/audio_processing/agc/utility.cc | 4 +--- modules/audio_processing/ns/fast_math.cc | 5 ++--- modules/audio_processing/ns/noise_estimator.cc | 8 +------- modules/audio_processing/three_band_filter_bank.cc | 13 ++++--------- .../event_based_exponential_moving_average.cc | 3 +-- rtc_base/random.cc | 3 +-- 8 files changed, 14 insertions(+), 36 deletions(-) diff --git a/common_audio/window_generator.cc b/common_audio/window_generator.cc index 5a6de1aec1..d364eed826 100644 --- a/common_audio/window_generator.cc +++ b/common_audio/window_generator.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include "rtc_base/checks.h" @@ -41,7 +40,7 @@ void WindowGenerator::Hanning(int length, float* window) { RTC_CHECK(window != nullptr); for (int i = 0; i < length; ++i) { window[i] = - 0.5f * (1 - cosf(2 * std::numbers::pi_v * i / (length - 1))); + 0.5f * (1 - cosf(2 * static_cast(M_PI) * i / (length - 1))); } } @@ -56,7 +55,7 @@ void WindowGenerator::KaiserBesselDerived(float alpha, for (size_t i = 0; i <= half; ++i) { complex r = (4.0f * i) / length - 1.0f; - sum += I0(std::numbers::pi_v * alpha * sqrt(1.0f - r * r)).real(); + sum += I0(static_cast(M_PI) * alpha * sqrt(1.0f - r * r)).real(); window[i] = sum; } for (size_t i = length - 1; i >= half; --i) { diff --git a/modules/audio_processing/aec3/comfort_noise_generator.cc b/modules/audio_processing/aec3/comfort_noise_generator.cc index ce500a57d5..21d6ef9b5c 100644 --- a/modules/audio_processing/aec3/comfort_noise_generator.cc +++ b/modules/audio_processing/aec3/comfort_noise_generator.cc @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -36,8 +35,6 @@ namespace webrtc { namespace { -using std::numbers::sqrt2_v; - // Computes the noise floor value that matches a WGN input of noise_floor_dbfs. float GetNoiseFloorFactor(float noise_floor_dbfs) { // kdBfsNormalization = 20.f*log10(32768.f). @@ -46,16 +43,14 @@ float GetNoiseFloorFactor(float noise_floor_dbfs) { } // Table of sqrt(2) * sin(2*pi*i/32). -// clang-format off constexpr float kSqrt2Sin[32] = { +0.0000000f, +0.2758994f, +0.5411961f, +0.7856950f, +1.0000000f, - +1.1758756f, +1.3065630f, +1.3870398f, +sqrt2_v, +1.3870398f, + +1.1758756f, +1.3065630f, +1.3870398f, +1.4142136f, +1.3870398f, +1.3065630f, +1.1758756f, +1.0000000f, +0.7856950f, +0.5411961f, +0.2758994f, +0.0000000f, -0.2758994f, -0.5411961f, -0.7856950f, - -1.0000000f, -1.1758756f, -1.3065630f, -1.3870398f, -sqrt2_v, + -1.0000000f, -1.1758756f, -1.3065630f, -1.3870398f, -1.4142136f, -1.3870398f, -1.3065630f, -1.1758756f, -1.0000000f, -0.7856950f, -0.5411961f, -0.2758994f}; -// clang-format on void GenerateComfortNoise(Aec3Optimization optimization, const std::array& N2, diff --git a/modules/audio_processing/agc/utility.cc b/modules/audio_processing/agc/utility.cc index b8fa3605ea..2a87e5ce74 100644 --- a/modules/audio_processing/agc/utility.cc +++ b/modules/audio_processing/agc/utility.cc @@ -12,11 +12,9 @@ #include -#include - namespace webrtc { -static const double kLog10 = std::numbers::ln10; +static const double kLog10 = 2.30258509299; static const double kLinear2DbScale = 20.0 / kLog10; static const double kLinear2LoudnessScale = 13.4 / kLog10; diff --git a/modules/audio_processing/ns/fast_math.cc b/modules/audio_processing/ns/fast_math.cc index 7d52252201..d7c7a7b4fa 100644 --- a/modules/audio_processing/ns/fast_math.cc +++ b/modules/audio_processing/ns/fast_math.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include "api/array_view.h" #include "rtc_base/checks.h" @@ -56,7 +55,7 @@ float PowApproximation(float x, float p) { } float LogApproximation(float x) { - constexpr float kLogOf2 = std::numbers::ln2_v; + constexpr float kLogOf2 = 0.69314718056f; return FastLog2f(x) * kLogOf2; } @@ -67,7 +66,7 @@ void LogApproximation(ArrayView x, ArrayView y) { } float ExpApproximation(float x) { - constexpr float kLog10Ofe = std::numbers::log10e_v; + constexpr float kLog10Ofe = 0.4342944819f; return PowApproximation(10.f, x * kLog10Ofe); } diff --git a/modules/audio_processing/ns/noise_estimator.cc b/modules/audio_processing/ns/noise_estimator.cc index 00b647ca35..bf21d38d0b 100644 --- a/modules/audio_processing/ns/noise_estimator.cc +++ b/modules/audio_processing/ns/noise_estimator.cc @@ -14,7 +14,6 @@ #include #include #include -#include #include "api/array_view.h" #include "modules/audio_processing/ns/fast_math.h" @@ -26,14 +25,10 @@ namespace webrtc { namespace { -using std::numbers::ln10_v; - // Log(i). -// clang-format off constexpr std::array log_table = { 0.f, 0.f, 0.f, 0.f, 0.f, 1.609438f, 1.791759f, - 1.945910f, 2.079442f, 2.197225f, ln10_v, 2.397895f, 2.484907f, - 2.564949f, + 1.945910f, 2.079442f, 2.197225f, 2.302585f, 2.397895f, 2.484907f, 2.564949f, 2.639057f, 2.708050f, 2.772589f, 2.833213f, 2.890372f, 2.944439f, 2.995732f, 3.044522f, 3.091043f, 3.135494f, 3.178054f, 3.218876f, 3.258097f, 3.295837f, 3.332205f, 3.367296f, 3.401197f, 3.433987f, 3.465736f, 3.496507f, 3.526361f, @@ -51,7 +46,6 @@ constexpr std::array log_table = { 4.718499f, 4.727388f, 4.736198f, 4.744932f, 4.753591f, 4.762174f, 4.770685f, 4.779124f, 4.787492f, 4.795791f, 4.804021f, 4.812184f, 4.820282f, 4.828314f, 4.836282f, 4.844187f, 4.852030f}; -// clang-format on } // namespace diff --git a/modules/audio_processing/three_band_filter_bank.cc b/modules/audio_processing/three_band_filter_bank.cc index a04852a4c7..291026ca44 100644 --- a/modules/audio_processing/three_band_filter_bank.cc +++ b/modules/audio_processing/three_band_filter_bank.cc @@ -34,7 +34,6 @@ #include #include -#include #include "api/array_view.h" #include "rtc_base/checks.h" @@ -91,21 +90,17 @@ const float constexpr int kZeroFilterIndex1 = 3; constexpr int kZeroFilterIndex2 = 9; -constexpr float kSqrt3 = std::numbers::sqrt3_v; - -// clang-format off const float kDctModulation[ThreeBandFilterBank::kNumNonZeroFilters][kDctSize] = {{2.f, 2.f, 2.f}, - {kSqrt3, 0.f, -kSqrt3}, + {1.73205077f, 0.f, -1.73205077f}, {1.f, -2.f, 1.f}, {-1.f, 2.f, -1.f}, - {-kSqrt3, 0.f, kSqrt3}, + {-1.73205077f, 0.f, 1.73205077f}, {-2.f, -2.f, -2.f}, - {-kSqrt3, 0.f, kSqrt3}, + {-1.73205077f, 0.f, 1.73205077f}, {-1.f, 2.f, -1.f}, {1.f, -2.f, 1.f}, - {kSqrt3, 0.f, -kSqrt3}}; -// clang-format on + {1.73205077f, 0.f, -1.73205077f}}; // Filters the input signal `in` with the filter `filter` using a shift by // `in_shift`, taking into account the previous state. diff --git a/rtc_base/numerics/event_based_exponential_moving_average.cc b/rtc_base/numerics/event_based_exponential_moving_average.cc index 419902dc52..27b2066a97 100644 --- a/rtc_base/numerics/event_based_exponential_moving_average.cc +++ b/rtc_base/numerics/event_based_exponential_moving_average.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include "rtc_base/checks.h" @@ -36,7 +35,7 @@ EventBasedExponentialMovingAverage::EventBasedExponentialMovingAverage( } void EventBasedExponentialMovingAverage::SetHalfTime(int half_time) { - tau_ = static_cast(half_time) / std::numbers::ln2; + tau_ = static_cast(half_time) / log(2); Reset(); } diff --git a/rtc_base/random.cc b/rtc_base/random.cc index 319ad72177..3e0cc45262 100644 --- a/rtc_base/random.cc +++ b/rtc_base/random.cc @@ -12,7 +12,6 @@ #include #include -#include #include "rtc_base/checks.h" #include "rtc_base/numerics/safe_conversions.h" @@ -74,7 +73,7 @@ double Random::Gaussian(double mean, double standard_deviation) { // interval (0, 1]. Note that we rely on NextOutput to generate integers // in the range [1, 2^64-1]. Normally this behavior is a bit frustrating, // but here it is exactly what we need. - const double kPi = std::numbers::pi; + const double kPi = 3.14159265358979323846; double u1 = static_cast(NextOutput()) / static_cast(0xFFFFFFFFFFFFFFFFull); double u2 = static_cast(NextOutput()) /