Per Åhgren | e4db6a1 | 2018-07-26 15:32:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 "modules/audio_processing/aec3/subtractor_output.h" |
| 12 | |
| 13 | #include <numeric> |
| 14 | |
| 15 | namespace webrtc { |
| 16 | |
| 17 | SubtractorOutput::SubtractorOutput() = default; |
| 18 | SubtractorOutput::~SubtractorOutput() = default; |
| 19 | |
| 20 | void SubtractorOutput::Reset() { |
| 21 | s_main.fill(0.f); |
Per Åhgren | 7802675 | 2018-08-01 16:24:08 +0200 | [diff] [blame] | 22 | s_shadow.fill(0.f); |
Per Åhgren | e4db6a1 | 2018-07-26 15:32:24 +0200 | [diff] [blame] | 23 | e_main.fill(0.f); |
| 24 | e_shadow.fill(0.f); |
| 25 | E_main.re.fill(0.f); |
| 26 | E_main.im.fill(0.f); |
| 27 | E2_main.fill(0.f); |
| 28 | E2_shadow.fill(0.f); |
| 29 | e2_main = 0.f; |
| 30 | e2_shadow = 0.f; |
Per Åhgren | 7802675 | 2018-08-01 16:24:08 +0200 | [diff] [blame] | 31 | s2_main = 0.f; |
| 32 | s2_shadow = 0.f; |
Per Åhgren | e4db6a1 | 2018-07-26 15:32:24 +0200 | [diff] [blame] | 33 | y2 = 0.f; |
| 34 | } |
| 35 | |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 36 | void SubtractorOutput::ComputeMetrics(rtc::ArrayView<const float> y) { |
Per Åhgren | e4db6a1 | 2018-07-26 15:32:24 +0200 | [diff] [blame] | 37 | const auto sum_of_squares = [](float a, float b) { return a + b * b; }; |
| 38 | y2 = std::accumulate(y.begin(), y.end(), 0.f, sum_of_squares); |
| 39 | e2_main = std::accumulate(e_main.begin(), e_main.end(), 0.f, sum_of_squares); |
| 40 | e2_shadow = |
| 41 | std::accumulate(e_shadow.begin(), e_shadow.end(), 0.f, sum_of_squares); |
Per Åhgren | 7802675 | 2018-08-01 16:24:08 +0200 | [diff] [blame] | 42 | s2_main = std::accumulate(s_main.begin(), s_main.end(), 0.f, sum_of_squares); |
| 43 | s2_shadow = |
| 44 | std::accumulate(s_shadow.begin(), s_shadow.end(), 0.f, sum_of_squares); |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 45 | |
| 46 | s_main_max_abs = *std::max_element(s_main.begin(), s_main.end()); |
| 47 | s_main_max_abs = std::max(s_main_max_abs, |
| 48 | -(*std::min_element(s_main.begin(), s_main.end()))); |
| 49 | |
| 50 | s_shadow_max_abs = *std::max_element(s_shadow.begin(), s_shadow.end()); |
| 51 | s_shadow_max_abs = std::max( |
| 52 | s_shadow_max_abs, -(*std::min_element(s_shadow.begin(), s_shadow.end()))); |
Per Åhgren | e4db6a1 | 2018-07-26 15:32:24 +0200 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | } // namespace webrtc |