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() { |
Per Åhgren | ff04511 | 2020-03-20 11:20:39 +0100 | [diff] [blame] | 21 | s_refined.fill(0.f); |
Per Åhgren | 9d66198 | 2020-03-20 11:26:48 +0100 | [diff] [blame] | 22 | s_coarse.fill(0.f); |
Per Åhgren | ff04511 | 2020-03-20 11:20:39 +0100 | [diff] [blame] | 23 | e_refined.fill(0.f); |
Per Åhgren | 9d66198 | 2020-03-20 11:26:48 +0100 | [diff] [blame] | 24 | e_coarse.fill(0.f); |
Per Åhgren | ff04511 | 2020-03-20 11:20:39 +0100 | [diff] [blame] | 25 | E_refined.re.fill(0.f); |
| 26 | E_refined.im.fill(0.f); |
| 27 | E2_refined.fill(0.f); |
Per Åhgren | 9d66198 | 2020-03-20 11:26:48 +0100 | [diff] [blame] | 28 | E2_coarse.fill(0.f); |
Per Åhgren | ff04511 | 2020-03-20 11:20:39 +0100 | [diff] [blame] | 29 | e2_refined = 0.f; |
Per Åhgren | 9d66198 | 2020-03-20 11:26:48 +0100 | [diff] [blame] | 30 | e2_coarse = 0.f; |
Per Åhgren | ff04511 | 2020-03-20 11:20:39 +0100 | [diff] [blame] | 31 | s2_refined = 0.f; |
Per Åhgren | 9d66198 | 2020-03-20 11:26:48 +0100 | [diff] [blame] | 32 | s2_coarse = 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); |
Per Åhgren | ff04511 | 2020-03-20 11:20:39 +0100 | [diff] [blame] | 39 | e2_refined = |
| 40 | std::accumulate(e_refined.begin(), e_refined.end(), 0.f, sum_of_squares); |
Per Åhgren | 9d66198 | 2020-03-20 11:26:48 +0100 | [diff] [blame] | 41 | e2_coarse = |
| 42 | std::accumulate(e_coarse.begin(), e_coarse.end(), 0.f, sum_of_squares); |
Per Åhgren | ff04511 | 2020-03-20 11:20:39 +0100 | [diff] [blame] | 43 | s2_refined = |
| 44 | std::accumulate(s_refined.begin(), s_refined.end(), 0.f, sum_of_squares); |
Per Åhgren | 9d66198 | 2020-03-20 11:26:48 +0100 | [diff] [blame] | 45 | s2_coarse = |
| 46 | std::accumulate(s_coarse.begin(), s_coarse.end(), 0.f, sum_of_squares); |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 47 | |
Per Åhgren | ff04511 | 2020-03-20 11:20:39 +0100 | [diff] [blame] | 48 | s_refined_max_abs = *std::max_element(s_refined.begin(), s_refined.end()); |
| 49 | s_refined_max_abs = |
| 50 | std::max(s_refined_max_abs, |
| 51 | -(*std::min_element(s_refined.begin(), s_refined.end()))); |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 52 | |
Per Åhgren | 9d66198 | 2020-03-20 11:26:48 +0100 | [diff] [blame] | 53 | s_coarse_max_abs = *std::max_element(s_coarse.begin(), s_coarse.end()); |
| 54 | s_coarse_max_abs = std::max( |
| 55 | s_coarse_max_abs, -(*std::min_element(s_coarse.begin(), s_coarse.end()))); |
Per Åhgren | e4db6a1 | 2018-07-26 15:32:24 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | } // namespace webrtc |