| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 const float change_factor = (from_y_to_e ? 1.f : -1.f) / e.size(); | 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; | 29 float averaging = from_y_to_e ? 0.f : 1.f; |
| 30 for (size_t k = 0; k < e.size(); ++k) { | 30 for (size_t k = 0; k < e.size(); ++k) { |
| 31 y[k] += averaging * (e[k] - y[k]); | 31 y[k] += averaging * (e[k] - y[k]); |
| 32 averaging += change_factor; | 32 averaging += change_factor; |
| 33 } | 33 } |
| 34 RTC_DCHECK_EQ(from_y_to_e ? 1.f : 0.f, averaging); | 34 RTC_DCHECK_EQ(from_y_to_e ? 1.f : 0.f, averaging); |
| 35 } | 35 } |
| 36 | 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 | 37 } // namespace |
| 43 | 38 |
| 44 OutputSelector::OutputSelector() = default; | 39 OutputSelector::OutputSelector() = default; |
| 45 | 40 |
| 46 OutputSelector::~OutputSelector() = default; | 41 OutputSelector::~OutputSelector() = default; |
| 47 | 42 |
| 48 void OutputSelector::FormLinearOutput( | 43 void OutputSelector::FormLinearOutput( |
| 44 bool use_subtractor_output, |
| 49 rtc::ArrayView<const float> subtractor_output, | 45 rtc::ArrayView<const float> subtractor_output, |
| 50 rtc::ArrayView<float> capture) { | 46 rtc::ArrayView<float> capture) { |
| 51 RTC_DCHECK_EQ(subtractor_output.size(), capture.size()); | 47 RTC_DCHECK_EQ(subtractor_output.size(), capture.size()); |
| 52 rtc::ArrayView<const float>& e_main = subtractor_output; | 48 rtc::ArrayView<const float>& e_main = subtractor_output; |
| 53 rtc::ArrayView<float> y = capture; | 49 rtc::ArrayView<float> y = capture; |
| 54 | 50 |
| 55 const bool subtractor_output_is_best = | 51 if (use_subtractor_output != use_subtractor_output_) { |
| 56 BlockPower(y) > 1.5f * BlockPower(e_main); | 52 use_subtractor_output_ = use_subtractor_output; |
| 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); | 53 SmoothFrameTransition(use_subtractor_output_, e_main, y); |
| 66 output_change_counter_ = 0; | |
| 67 } else if (use_subtractor_output_) { | 54 } else if (use_subtractor_output_) { |
| 68 std::copy(e_main.begin(), e_main.end(), y.begin()); | 55 std::copy(e_main.begin(), e_main.end(), y.begin()); |
| 69 } | 56 } |
| 70 } | 57 } |
| 71 | 58 |
| 72 } // namespace webrtc | 59 } // namespace webrtc |
| OLD | NEW |