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

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: Changes in response to reviewer comments 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 }
hlundin-webrtc 2017/02/22 15:24:07 DCHECK that averaging reached the desired end valu
peah-webrtc 2017/02/22 23:51:39 Done.
35
36 float BlockPower(rtc::ArrayView<const float> x) {
37 return std::accumulate(x.begin(), x.end(), 0.f,
38 [](float a, float b) -> float { return a + b * b; });
39 }
40
41 } // namespace
42
43 OutputSelector::OutputSelector() = default;
44
45 OutputSelector::~OutputSelector() = default;
46
47 void OutputSelector::FormLinearOutput(
48 rtc::ArrayView<const float> subtractor_output,
49 rtc::ArrayView<float> capture) {
50 rtc::ArrayView<const float>& e_main = subtractor_output;
hlundin-webrtc 2017/02/22 15:24:07 RTC_DCHECK_EQ(subtractor_output.size(), capture.si
peah-webrtc 2017/02/22 23:51:39 Done.
51 rtc::ArrayView<float> y = capture;
52
53 bool subtractor_output_is_best = (BlockPower(y) > BlockPower(e_main));
54
55 output_change_counter_ = subtractor_output_is_best != use_subtractor_output_
56 ? output_change_counter_ + 1
57 : 0;
58
59 if (subtractor_output_is_best != use_subtractor_output_ &&
60 output_change_counter_ > 15) {
61 use_subtractor_output_ = subtractor_output_is_best;
62 SmoothFrameTransition(use_subtractor_output_, e_main, y);
63 output_change_counter_ = 0;
64 } else if (use_subtractor_output_) {
65 std::copy(e_main.begin(), e_main.end(), y.begin());
66 }
67 }
68
69 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698