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_analyzer.h" 12 13 #include <algorithm> 14 15 #include "modules/audio_processing/aec3/aec3_common.h" 16 17 namespace webrtc { 18 SubtractorOutputAnalyzer(size_t num_capture_channels)19SubtractorOutputAnalyzer::SubtractorOutputAnalyzer(size_t num_capture_channels) 20 : filters_converged_(num_capture_channels, false) {} 21 Update(rtc::ArrayView<const SubtractorOutput> subtractor_output,bool * any_filter_converged,bool * all_filters_diverged)22void SubtractorOutputAnalyzer::Update( 23 rtc::ArrayView<const SubtractorOutput> subtractor_output, 24 bool* any_filter_converged, 25 bool* all_filters_diverged) { 26 RTC_DCHECK(any_filter_converged); 27 RTC_DCHECK(all_filters_diverged); 28 RTC_DCHECK_EQ(subtractor_output.size(), filters_converged_.size()); 29 30 *any_filter_converged = false; 31 *all_filters_diverged = true; 32 33 for (size_t ch = 0; ch < subtractor_output.size(); ++ch) { 34 const float y2 = subtractor_output[ch].y2; 35 const float e2_refined = subtractor_output[ch].e2_refined; 36 const float e2_coarse = subtractor_output[ch].e2_coarse; 37 38 constexpr float kConvergenceThreshold = 50 * 50 * kBlockSize; 39 bool refined_filter_converged = 40 e2_refined < 0.5f * y2 && y2 > kConvergenceThreshold; 41 bool coarse_filter_converged = 42 e2_coarse < 0.05f * y2 && y2 > kConvergenceThreshold; 43 float min_e2 = std::min(e2_refined, e2_coarse); 44 bool filter_diverged = min_e2 > 1.5f * y2 && y2 > 30.f * 30.f * kBlockSize; 45 filters_converged_[ch] = 46 refined_filter_converged || coarse_filter_converged; 47 48 *any_filter_converged = *any_filter_converged || filters_converged_[ch]; 49 *all_filters_diverged = *all_filters_diverged && filter_diverged; 50 } 51 } 52 HandleEchoPathChange()53void SubtractorOutputAnalyzer::HandleEchoPathChange() { 54 std::fill(filters_converged_.begin(), filters_converged_.end(), false); 55 } 56 57 } // namespace webrtc 58