Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1123)

Unified Diff: webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc

Issue 2808513003: Add SafeClamp(), which accepts args of different types (Closed)
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc
diff --git a/webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc b/webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc
index fa8d1704c6775e31673c07a460d2e835fa5f1a58..deaeb27f44fd157e415c6eb1d94f296d62af6752 100644
--- a/webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc
+++ b/webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc
@@ -16,6 +16,8 @@
#include <algorithm>
#include <limits>
+#include "webrtc/base/safe_minmax.h"
+
namespace webrtc {
namespace intelligibility {
@@ -28,9 +30,9 @@ const float kMaxFactor = 100.f;
// Return |current| changed towards |target|, with the relative change being at
// most |limit|.
float UpdateFactor(float target, float current, float limit) {
- float gain = target / (current + std::numeric_limits<float>::epsilon());
- gain = std::min(std::max(gain, 1.f - limit), 1.f + limit);
- return std::min(std::max(current * gain, kMinFactor), kMaxFactor);;
+ const float gain = target / (current + std::numeric_limits<float>::epsilon());
+ const float clamped_gain = rtc::SafeClamp(gain, 1 - limit, 1 + limit);
+ return rtc::SafeClamp(current * clamped_gain, kMinFactor, kMaxFactor);
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698