OLD | NEW |
---|---|
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/output_selector.h" | 11 #include "webrtc/modules/audio_processing/aec3/output_selector.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <array> | 14 #include <array> |
15 | 15 |
16 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" | 16 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" |
17 #include "webrtc/test/gtest.h" | 17 #include "webrtc/test/gtest.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 | 20 |
21 // Verifies that the switching between the signals in the output works as | 21 // Verifies that the switching between the signals in the output works as |
22 // intended. | 22 // intended. |
23 TEST(OutputSelector, ProperSwitching) { | 23 TEST(OutputSelector, ProperSwitching) { |
24 OutputSelector selector; | 24 OutputSelector selector; |
25 | 25 |
26 constexpr int kNumBlocksToSwitchToSubtractor = 3; | |
27 constexpr int kNumBlocksToSwitchFromSubtractor = 10; | |
28 | |
29 std::array<float, kBlockSize> weaker; | |
30 std::array<float, kBlockSize> stronger; | |
31 std::array<float, kBlockSize> y; | 26 std::array<float, kBlockSize> y; |
32 std::array<float, kBlockSize> e; | 27 std::array<float, kBlockSize> e; |
33 weaker.fill(10.f); | 28 std::array<float, kBlockSize> e_ref; |
34 stronger.fill(20.f); | 29 std::array<float, kBlockSize> y_ref; |
35 | 30 auto init_blocks = [](std::array<float, kBlockSize>* e, |
36 bool y_is_weakest = false; | 31 std::array<float, kBlockSize>* y) { |
37 | 32 e->fill(10.f); |
38 const auto form_e_and_y = [&](bool y_equals_weaker) { | 33 y->fill(20.f); |
39 if (y_equals_weaker) { | |
40 std::copy(weaker.begin(), weaker.end(), y.begin()); | |
41 std::copy(stronger.begin(), stronger.end(), e.begin()); | |
42 } else { | |
43 std::copy(stronger.begin(), stronger.end(), y.begin()); | |
44 std::copy(weaker.begin(), weaker.end(), e.begin()); | |
45 } | |
46 }; | 34 }; |
47 | 35 |
48 for (int k = 0; k < 30; ++k) { | 36 init_blocks(&e_ref, &y_ref); |
49 // Verify that it takes a while for the signals transition to take effect. | 37 e_ref.fill(10.f); |
ivoc
2017/04/05 15:21:25
Isn't this already done in the init_blocks functio
peah-webrtc
2017/04/06 07:20:32
True.
Done.
| |
50 const int num_blocks_to_switch = y_is_weakest | 38 y_ref.fill(20.f); |
51 ? kNumBlocksToSwitchFromSubtractor | |
52 : kNumBlocksToSwitchToSubtractor; | |
53 for (int j = 0; j < num_blocks_to_switch; ++j) { | |
54 form_e_and_y(y_is_weakest); | |
55 selector.FormLinearOutput(e, y); | |
56 EXPECT_EQ(stronger, y); | |
57 EXPECT_EQ(y_is_weakest, selector.UseSubtractorOutput()); | |
58 } | |
59 | 39 |
60 // Verify that the transition block is a mix between the signals. | 40 init_blocks(&e, &y); |
61 form_e_and_y(y_is_weakest); | 41 selector.FormLinearOutput(false, e, y); |
62 selector.FormLinearOutput(e, y); | 42 EXPECT_EQ(y_ref, y); |
63 EXPECT_NE(weaker, y); | |
64 EXPECT_NE(stronger, y); | |
65 EXPECT_EQ(!y_is_weakest, selector.UseSubtractorOutput()); | |
66 | 43 |
67 y_is_weakest = !y_is_weakest; | 44 init_blocks(&e, &y); |
68 } | 45 selector.FormLinearOutput(true, e, y); |
46 EXPECT_NE(e_ref, y); | |
47 EXPECT_NE(y_ref, y); | |
48 | |
49 init_blocks(&e, &y); | |
50 selector.FormLinearOutput(true, e, y); | |
51 EXPECT_EQ(e_ref, y); | |
52 | |
53 init_blocks(&e, &y); | |
54 selector.FormLinearOutput(true, e, y); | |
55 EXPECT_EQ(e_ref, y); | |
56 | |
57 init_blocks(&e, &y); | |
58 selector.FormLinearOutput(false, e, y); | |
59 EXPECT_NE(e_ref, y); | |
60 EXPECT_NE(y_ref, y); | |
61 | |
62 init_blocks(&e, &y); | |
63 selector.FormLinearOutput(false, e, y); | |
64 EXPECT_EQ(y_ref, y); | |
65 | |
66 init_blocks(&e, &y); | |
67 selector.FormLinearOutput(false, e, y); | |
68 EXPECT_EQ(y_ref, y); | |
69 } | 69 } |
70 | 70 |
71 } // namespace webrtc | 71 } // namespace webrtc |
OLD | NEW |