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

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: Fixed compilation error 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 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 const bool subtractor_output_is_best =
56 BlockPower(y) > 1.5f * BlockPower(e_main);
57 output_change_counter_ = subtractor_output_is_best != use_subtractor_output_
58 ? output_change_counter_ + 1
59 : 0;
60
61 if (subtractor_output_is_best != use_subtractor_output_ &&
62 ((subtractor_output_is_best && output_change_counter_ > 3) ||
63 (!subtractor_output_is_best && output_change_counter_ > 10))) {
64 use_subtractor_output_ = subtractor_output_is_best;
65 SmoothFrameTransition(use_subtractor_output_, e_main, y);
66 output_change_counter_ = 0;
67 } else if (use_subtractor_output_) {
68 std::copy(e_main.begin(), e_main.end(), y.begin());
69 }
70 }
71
72 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698