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

Unified Diff: webrtc/tools/agc/activity_metric.cc

Issue 2808513003: Add SafeClamp(), which accepts args of different types (Closed)
Patch Set: Created 3 years, 7 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/tools/agc/activity_metric.cc
diff --git a/webrtc/tools/agc/activity_metric.cc b/webrtc/tools/agc/activity_metric.cc
index 599777c3be81d757c145e559a3fa3ac1cb9e0ea9..fdf73c976da4fef35f2869c1d05e253d85d9c15c 100644
--- a/webrtc/tools/agc/activity_metric.cc
+++ b/webrtc/tools/agc/activity_metric.cc
@@ -17,6 +17,7 @@
#include <memory>
#include "webrtc/base/flags.h"
+#include "webrtc/base/safe_minmax.h"
#include "webrtc/modules/audio_processing/agc/agc.h"
#include "webrtc/modules/audio_processing/agc/loudness_histogram.h"
#include "webrtc/modules/audio_processing/agc/utility.h"
@@ -121,9 +122,7 @@ class AgcStat {
for (size_t n = 0; n < features.num_frames; n++) {
double p_active = p[n] * video_vad_[n];
double p_passive = (1 - p[n]) * (1 - video_vad_[n]);
- p[n] = p_active / (p_active + p_passive);
- // Limit probabilities.
- p[n] = std::min(std::max(p[n], 0.01), 0.99);
+ p[n] = rtc::SafeClamp(0.01, 0.99, p_active / (p_active + p_passive));
}
if (vad_->VoicingProbability(features, p) < 0)
return -1;

Powered by Google App Engine
This is Rietveld 408576698