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

Side by Side Diff: webrtc/modules/audio_processing/aec3/erle_estimator.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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/audio_processing/aec3/erle_estimator.h" 11 #include "webrtc/modules/audio_processing/aec3/erle_estimator.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #include "webrtc/base/safe_minmax.h"
16
15 namespace webrtc { 17 namespace webrtc {
16 18
17 namespace { 19 namespace {
18 20
19 constexpr float kMinErle = 1.f; 21 constexpr float kMinErle = 1.f;
20 constexpr float kMaxLfErle = 8.f; 22 constexpr float kMaxLfErle = 8.f;
21 constexpr float kMaxHfErle = 1.5f; 23 constexpr float kMaxHfErle = 1.5f;
22 24
23 } // namespace 25 } // namespace
24 26
(...skipping 16 matching lines...) Expand all
41 constexpr float kX2Min = 44015068.0f; 43 constexpr float kX2Min = 44015068.0f;
42 44
43 // Update the estimates in a clamped minimum statistics manner. 45 // Update the estimates in a clamped minimum statistics manner.
44 auto erle_update = [&](size_t start, size_t stop, float max_erle) { 46 auto erle_update = [&](size_t start, size_t stop, float max_erle) {
45 for (size_t k = start; k < stop; ++k) { 47 for (size_t k = start; k < stop; ++k) {
46 if (X2[k] > kX2Min && E2[k] > 0.f) { 48 if (X2[k] > kX2Min && E2[k] > 0.f) {
47 const float new_erle = Y2[k] / E2[k]; 49 const float new_erle = Y2[k] / E2[k];
48 if (new_erle > erle_[k]) { 50 if (new_erle > erle_[k]) {
49 hold_counters_[k - 1] = 100; 51 hold_counters_[k - 1] = 100;
50 erle_[k] += 0.1f * (new_erle - erle_[k]); 52 erle_[k] += 0.1f * (new_erle - erle_[k]);
51 erle_[k] = std::max(kMinErle, std::min(erle_[k], max_erle)); 53 erle_[k] = rtc::SafeClamp(erle_[k], kMinErle, max_erle);
52 } 54 }
53 } 55 }
54 } 56 }
55 }; 57 };
56 erle_update(1, kFftLengthBy2 / 2, kMaxLfErle); 58 erle_update(1, kFftLengthBy2 / 2, kMaxLfErle);
57 erle_update(kFftLengthBy2 / 2, kFftLengthBy2, kMaxHfErle); 59 erle_update(kFftLengthBy2 / 2, kFftLengthBy2, kMaxHfErle);
58 60
59 std::for_each(hold_counters_.begin(), hold_counters_.end(), 61 std::for_each(hold_counters_.begin(), hold_counters_.end(),
60 [](int& a) { --a; }); 62 [](int& a) { --a; });
61 std::transform(hold_counters_.begin(), hold_counters_.end(), 63 std::transform(hold_counters_.begin(), hold_counters_.end(),
62 erle_.begin() + 1, erle_.begin() + 1, [](int a, float b) { 64 erle_.begin() + 1, erle_.begin() + 1, [](int a, float b) {
63 return a > 0 ? b : std::max(kMinErle, 0.97f * b); 65 return a > 0 ? b : std::max(kMinErle, 0.97f * b);
64 }); 66 });
65 67
66 erle_[0] = erle_[1]; 68 erle_[0] = erle_[1];
67 erle_[kFftLengthBy2] = erle_[kFftLengthBy2 - 1]; 69 erle_[kFftLengthBy2] = erle_[kFftLengthBy2 - 1];
68 } 70 }
69 71
70 } // namespace webrtc 72 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698