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

Side by Side Diff: webrtc/modules/audio_processing/aec3/shadow_filter_update_gain_unittest.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/shadow_filter_update_gain.h" 11 #include "webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <numeric> 14 #include <numeric>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/base/random.h" 18 #include "webrtc/base/random.h"
19 #include "webrtc/base/safe_minmax.h"
19 #include "webrtc/modules/audio_processing/aec3/adaptive_fir_filter.h" 20 #include "webrtc/modules/audio_processing/aec3/adaptive_fir_filter.h"
21 #include "webrtc/modules/audio_processing/aec3/aec3_common.h"
20 #include "webrtc/modules/audio_processing/aec3/aec_state.h" 22 #include "webrtc/modules/audio_processing/aec3/aec_state.h"
21 #include "webrtc/modules/audio_processing/aec3/aec3_common.h"
22 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" 23 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h"
23 #include "webrtc/test/gtest.h" 24 #include "webrtc/test/gtest.h"
24 25
25 namespace webrtc { 26 namespace webrtc {
26 namespace { 27 namespace {
27 28
28 // Method for performing the simulations needed to test the main filter update 29 // Method for performing the simulations needed to test the main filter update
29 // gain functionality. 30 // gain functionality.
30 void RunFilterUpdateTest(int num_blocks_to_process, 31 void RunFilterUpdateTest(int num_blocks_to_process,
31 size_t delay_samples, 32 size_t delay_samples,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 delay_buffer.Delay(x[0], y); 69 delay_buffer.Delay(x[0], y);
69 render_buffer.Insert(x); 70 render_buffer.Insert(x);
70 render_signal_analyzer.Update( 71 render_signal_analyzer.Update(
71 render_buffer, rtc::Optional<size_t>(delay_samples / kBlockSize)); 72 render_buffer, rtc::Optional<size_t>(delay_samples / kBlockSize));
72 73
73 shadow_filter.Filter(render_buffer, &S); 74 shadow_filter.Filter(render_buffer, &S);
74 fft.Ifft(S, &s); 75 fft.Ifft(S, &s);
75 std::transform(y.begin(), y.end(), s.begin() + kFftLengthBy2, 76 std::transform(y.begin(), y.end(), s.begin() + kFftLengthBy2,
76 e_shadow.begin(), 77 e_shadow.begin(),
77 [&](float a, float b) { return a - b * kScale; }); 78 [&](float a, float b) { return a - b * kScale; });
78 std::for_each(e_shadow.begin(), e_shadow.end(), [](float& a) { 79 std::for_each(e_shadow.begin(), e_shadow.end(),
79 a = std::max(std::min(a, 32767.0f), -32768.0f); 80 [](float& a) { a = rtc::SafeClamp(a, -32768.f, 32767.f); });
80 });
81 fft.ZeroPaddedFft(e_shadow, &E_shadow); 81 fft.ZeroPaddedFft(e_shadow, &E_shadow);
82 82
83 shadow_gain.Compute(render_buffer, render_signal_analyzer, E_shadow, 83 shadow_gain.Compute(render_buffer, render_signal_analyzer, E_shadow,
84 shadow_filter.SizePartitions(), saturation, &G); 84 shadow_filter.SizePartitions(), saturation, &G);
85 shadow_filter.Adapt(render_buffer, G); 85 shadow_filter.Adapt(render_buffer, G);
86 } 86 }
87 87
88 std::copy(e_shadow.begin(), e_shadow.end(), e_last_block->begin()); 88 std::copy(e_shadow.begin(), e_shadow.end(), e_last_block->begin());
89 std::copy(y.begin(), y.end(), y_last_block->begin()); 89 std::copy(y.begin(), y.end(), y_last_block->begin());
90 std::copy(G.re.begin(), G.re.end(), G_last_block->re.begin()); 90 std::copy(G.re.begin(), G.re.end(), G_last_block->re.begin());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 G_a_ref.re.fill(0.f); 178 G_a_ref.re.fill(0.f);
179 G_a_ref.im.fill(0.f); 179 G_a_ref.im.fill(0.f);
180 180
181 RunFilterUpdateTest(100, 65, blocks_with_saturation, &e, &y, &G_a); 181 RunFilterUpdateTest(100, 65, blocks_with_saturation, &e, &y, &G_a);
182 182
183 EXPECT_EQ(G_a_ref.re, G_a.re); 183 EXPECT_EQ(G_a_ref.re, G_a.re);
184 EXPECT_EQ(G_a_ref.im, G_a.im); 184 EXPECT_EQ(G_a_ref.im, G_a.im);
185 } 185 }
186 186
187 } // namespace webrtc 187 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698