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

Side by Side Diff: webrtc/modules/audio_processing/aec3/output_selector.cc

Issue 2678423005: Finalization of the first version of EchoCanceller 3 (Closed)
Patch Set: Created 3 years, 10 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
(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 }
35
36 } // namespace
37
38 OutputSelector::OutputSelector() = default;
39
40 OutputSelector::~OutputSelector() = default;
41
42 void OutputSelector::FormLinearOutput(
43 rtc::ArrayView<const float> linear_aec_output,
44 rtc::ArrayView<float> capture) {
45 rtc::ArrayView<const float>& e_main = linear_aec_output;
46 rtc::ArrayView<float> y = capture;
47
48 float y2_sum =
49 std::accumulate(y.begin(), y.end(), 0.f,
50 [](float a, float b) -> float { return a + b * b; });
51 float e2_main_sum =
52 std::accumulate(e_main.begin(), e_main.end(), 0.f,
53 [](float a, float b) -> float { return a + b * b; });
54
55 bool subtractor_output_is_best = (y2_sum > e2_main_sum);
56
aleloi 2017/02/13 16:44:50 Please make y2_sum, e2_main_sum, subtractor_output
peah-webrtc 2017/02/20 07:37:17 Done.
57 if (subtractor_output_is_best != use_subtractor_output_) {
58 if (++output_change_counter_ > 15) {
59 use_subtractor_output_ = subtractor_output_is_best;
60
61 SmoothFrameTransition(use_subtractor_output_, e_main, y);
62 output_change_counter_ = 0;
63 } else if (use_subtractor_output_) {
64 std::copy(e_main.begin(), e_main.end(), y.begin());
65 }
66 } else {
67 output_change_counter_ = 0;
68
69 if (use_subtractor_output_) {
70 std::copy(e_main.begin(), e_main.end(), y.begin());
71 }
72 }
73 }
aleloi 2017/02/13 16:44:50 I think the control flow can be a little simplifie
peah-webrtc 2017/02/20 07:37:17 Good point! Done.
74
75 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698