1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "modules/audio_processing/aec3/output_selector.h"
12
13 #include <algorithm>
14 #include <array>
15
16 #include "modules/audio_processing/aec3/aec3_common.h"
17 #include "test/gtest.h"
18
19 namespace webrtc {
20
21 // Verifies that the switching between the signals in the output works as
22 // intended.
TEST(OutputSelector,ProperSwitching)23 TEST(OutputSelector, ProperSwitching) {
24 OutputSelector selector;
25
26 std::array<float, kBlockSize> y;
27 std::array<float, kBlockSize> e;
28 std::array<float, kBlockSize> e_ref;
29 std::array<float, kBlockSize> y_ref;
30 auto init_blocks = [](std::array<float, kBlockSize>* e,
31 std::array<float, kBlockSize>* y) {
32 e->fill(10.f);
33 y->fill(20.f);
34 };
35
36 init_blocks(&e_ref, &y_ref);
37
38 init_blocks(&e, &y);
39 selector.FormLinearOutput(false, e, y);
40 EXPECT_EQ(y_ref, y);
41
42 init_blocks(&e, &y);
43 selector.FormLinearOutput(true, e, y);
44 EXPECT_NE(e_ref, y);
45 EXPECT_NE(y_ref, y);
46
47 init_blocks(&e, &y);
48 selector.FormLinearOutput(true, e, y);
49 EXPECT_EQ(e_ref, y);
50
51 init_blocks(&e, &y);
52 selector.FormLinearOutput(true, e, y);
53 EXPECT_EQ(e_ref, y);
54
55 init_blocks(&e, &y);
56 selector.FormLinearOutput(false, e, y);
57 EXPECT_NE(e_ref, y);
58 EXPECT_NE(y_ref, y);
59
60 init_blocks(&e, &y);
61 selector.FormLinearOutput(false, e, y);
62 EXPECT_EQ(y_ref, y);
63
64 init_blocks(&e, &y);
65 selector.FormLinearOutput(false, e, y);
66 EXPECT_EQ(y_ref, y);
67 }
68
69 } // namespace webrtc
70