subtractor_output.cc (1979B)
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 <algorithm> 14 #include <numeric> 15 16 #include "api/array_view.h" 17 18 namespace webrtc { 19 20 SubtractorOutput::SubtractorOutput() = default; 21 SubtractorOutput::~SubtractorOutput() = default; 22 23 void SubtractorOutput::Reset() { 24 s_refined.fill(0.f); 25 s_coarse.fill(0.f); 26 e_refined.fill(0.f); 27 e_coarse.fill(0.f); 28 E_refined.re.fill(0.f); 29 E_refined.im.fill(0.f); 30 E2_refined.fill(0.f); 31 E2_coarse.fill(0.f); 32 e2_refined = 0.f; 33 e2_coarse = 0.f; 34 s2_refined = 0.f; 35 s2_coarse = 0.f; 36 y2 = 0.f; 37 } 38 39 void SubtractorOutput::ComputeMetrics(ArrayView<const float> y) { 40 const auto sum_of_squares = [](float a, float b) { return a + b * b; }; 41 y2 = std::accumulate(y.begin(), y.end(), 0.f, sum_of_squares); 42 e2_refined = 43 std::accumulate(e_refined.begin(), e_refined.end(), 0.f, sum_of_squares); 44 e2_coarse = 45 std::accumulate(e_coarse.begin(), e_coarse.end(), 0.f, sum_of_squares); 46 s2_refined = 47 std::accumulate(s_refined.begin(), s_refined.end(), 0.f, sum_of_squares); 48 s2_coarse = 49 std::accumulate(s_coarse.begin(), s_coarse.end(), 0.f, sum_of_squares); 50 51 s_refined_max_abs = *std::max_element(s_refined.begin(), s_refined.end()); 52 s_refined_max_abs = 53 std::max(s_refined_max_abs, 54 -(*std::min_element(s_refined.begin(), s_refined.end()))); 55 56 s_coarse_max_abs = *std::max_element(s_coarse.begin(), s_coarse.end()); 57 s_coarse_max_abs = std::max( 58 s_coarse_max_abs, -(*std::min_element(s_coarse.begin(), s_coarse.end()))); 59 } 60 61 } // namespace webrtc