OLD | NEW |
---|---|
(Empty) | |
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 "webrtc/modules/audio_processing/aec3/output_selector.h" | |
12 | |
13 #include <algorithm> | |
14 #include <numeric> | |
15 | |
16 #include "webrtc/base/checks.h" | |
17 | |
18 namespace webrtc { | |
19 namespace { | |
20 | |
21 // Performs the transition between the signals in a smooth manner. | |
22 void SmoothFrameTransition(bool from_y_to_e, | |
23 rtc::ArrayView<const float> e, | |
24 rtc::ArrayView<float> y) { | |
25 RTC_DCHECK_LT(0u, e.size()); | |
26 RTC_DCHECK_EQ(y.size(), e.size()); | |
27 | |
28 const float change_factor = (from_y_to_e ? 1.f : -1.f) / e.size(); | |
29 float averaging = from_y_to_e ? 0.f : 1.f; | |
30 for (size_t k = 0; k < e.size(); ++k) { | |
31 y[k] += averaging * (e[k] - y[k]); | |
32 averaging += change_factor; | |
33 } | |
34 RTC_DCHECK_EQ(from_y_to_e ? 1.f : 0.f, averaging); | |
35 } | |
36 | |
37 float BlockPower(rtc::ArrayView<const float> x) { | |
38 return std::accumulate(x.begin(), x.end(), 0.f, | |
39 [](float a, float b) -> float { return a + b * b; }); | |
40 } | |
41 | |
42 } // namespace | |
43 | |
44 OutputSelector::OutputSelector() = default; | |
45 | |
46 OutputSelector::~OutputSelector() = default; | |
47 | |
48 void OutputSelector::FormLinearOutput( | |
49 rtc::ArrayView<const float> subtractor_output, | |
50 rtc::ArrayView<float> capture) { | |
51 RTC_DCHECK_EQ(subtractor_output.size(), capture.size()); | |
52 rtc::ArrayView<const float>& e_main = subtractor_output; | |
53 rtc::ArrayView<float> y = capture; | |
54 | |
55 bool subtractor_output_is_best = BlockPower(y) > 1.5f * BlockPower(e_main); | |
aleloi
2017/02/23 10:56:45
const bool subtractor_output_is_best
peah-webrtc
2017/02/23 11:18:33
Done.
| |
56 output_change_counter_ = subtractor_output_is_best != use_subtractor_output_ | |
57 ? output_change_counter_ + 1 | |
58 : 0; | |
59 | |
60 if (subtractor_output_is_best != use_subtractor_output_ && | |
61 ((subtractor_output_is_best && output_change_counter_ > 3) || | |
62 (!subtractor_output_is_best && output_change_counter_ > 10))) { | |
63 use_subtractor_output_ = subtractor_output_is_best; | |
64 SmoothFrameTransition(use_subtractor_output_, e_main, y); | |
65 output_change_counter_ = 0; | |
66 } else if (use_subtractor_output_) { | |
67 std::copy(e_main.begin(), e_main.end(), y.begin()); | |
68 } | |
69 } | |
70 | |
71 } // namespace webrtc | |
OLD | NEW |