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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 if (echo_path_variability.AudioPathChanged()) { | 90 if (echo_path_variability.AudioPathChanged()) { |
91 blocks_since_last_saturation_ = 0; | 91 blocks_since_last_saturation_ = 0; |
92 active_render_blocks_ = 0; | 92 active_render_blocks_ = 0; |
93 echo_path_change_counter_ = kEchoPathChangeCounterMax; | 93 echo_path_change_counter_ = kEchoPathChangeCounterMax; |
94 usable_linear_estimate_ = false; | 94 usable_linear_estimate_ = false; |
95 echo_leakage_detected_ = false; | 95 echo_leakage_detected_ = false; |
96 capture_signal_saturation_ = false; | 96 capture_signal_saturation_ = false; |
97 echo_saturation_ = false; | 97 echo_saturation_ = false; |
98 headset_detected_ = false; | 98 headset_detected_ = false; |
99 previous_max_sample_ = 0.f; | 99 previous_max_sample_ = 0.f; |
| 100 |
| 101 if (echo_path_variability.delay_change) { |
| 102 force_zero_gain_counter_ = 0; |
| 103 force_zero_gain_ = true; |
| 104 } |
100 } | 105 } |
101 } | 106 } |
102 | 107 |
103 void AecState::Update(const std::vector<std::array<float, kFftLengthBy2Plus1>>& | 108 void AecState::Update(const std::vector<std::array<float, kFftLengthBy2Plus1>>& |
104 adaptive_filter_frequency_response, | 109 adaptive_filter_frequency_response, |
105 const rtc::Optional<size_t>& external_delay_samples, | 110 const rtc::Optional<size_t>& external_delay_samples, |
106 const RenderBuffer& render_buffer, | 111 const RenderBuffer& render_buffer, |
107 const std::array<float, kFftLengthBy2Plus1>& E2_main, | 112 const std::array<float, kFftLengthBy2Plus1>& E2_main, |
108 const std::array<float, kFftLengthBy2Plus1>& Y2, | 113 const std::array<float, kFftLengthBy2Plus1>& Y2, |
109 rtc::ArrayView<const float> x, | 114 rtc::ArrayView<const float> x, |
110 bool echo_leakage_detected) { | 115 bool echo_leakage_detected) { |
111 // Store input parameters. | 116 // Store input parameters. |
112 echo_leakage_detected_ = echo_leakage_detected; | 117 echo_leakage_detected_ = echo_leakage_detected; |
113 | 118 |
114 // Update counters. | 119 // Update counters. |
115 const float x_energy = std::inner_product(x.begin(), x.end(), x.begin(), 0.f); | 120 const float x_energy = std::inner_product(x.begin(), x.end(), x.begin(), 0.f); |
116 const bool active_render_block = x_energy > 10000.f * kFftLengthBy2; | 121 const bool active_render_block = x_energy > 10000.f * kFftLengthBy2; |
117 active_render_blocks_ += active_render_block ? 1 : 0; | 122 active_render_blocks_ += active_render_block ? 1 : 0; |
118 --echo_path_change_counter_; | 123 --echo_path_change_counter_; |
119 | 124 |
| 125 // Force zero echo suppression gain after an echo path change to allow at |
| 126 // least some render data to be collected in order to avoid an initial echo |
| 127 // burst. |
| 128 constexpr size_t kZeroGainBlocksAfterChange = kNumBlocksPerSecond / 5; |
| 129 force_zero_gain_ = (++force_zero_gain_counter_) < kZeroGainBlocksAfterChange; |
| 130 |
120 // Estimate delays. | 131 // Estimate delays. |
121 filter_delay_ = EstimateFilterDelay(adaptive_filter_frequency_response); | 132 filter_delay_ = EstimateFilterDelay(adaptive_filter_frequency_response); |
122 external_delay_ = | 133 external_delay_ = |
123 external_delay_samples | 134 external_delay_samples |
124 ? rtc::Optional<size_t>(*external_delay_samples / kBlockSize) | 135 ? rtc::Optional<size_t>(*external_delay_samples / kBlockSize) |
125 : rtc::Optional<size_t>(); | 136 : rtc::Optional<size_t>(); |
126 | 137 |
127 // Update the ERL and ERLE measures. | 138 // Update the ERL and ERLE measures. |
128 if (filter_delay_ && echo_path_change_counter_ <= 0) { | 139 if (filter_delay_ && echo_path_change_counter_ <= 0) { |
129 const auto& X2 = render_buffer.Spectrum(*filter_delay_); | 140 const auto& X2 = render_buffer.Spectrum(*filter_delay_); |
(...skipping 21 matching lines...) Expand all Loading... |
151 filter_delay_ && echo_path_change_counter_ <= 0; | 162 filter_delay_ && echo_path_change_counter_ <= 0; |
152 | 163 |
153 // After an amount of active render samples for which an echo should have been | 164 // After an amount of active render samples for which an echo should have been |
154 // detected in the capture signal if the ERL was not infinite, flag that a | 165 // detected in the capture signal if the ERL was not infinite, flag that a |
155 // headset is used. | 166 // headset is used. |
156 headset_detected_ = !external_delay_ && !filter_delay_ && | 167 headset_detected_ = !external_delay_ && !filter_delay_ && |
157 active_render_blocks_ >= kEchoPathChangeConvergenceBlocks; | 168 active_render_blocks_ >= kEchoPathChangeConvergenceBlocks; |
158 } | 169 } |
159 | 170 |
160 } // namespace webrtc | 171 } // namespace webrtc |
OLD | NEW |