| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 RenderNoisePower(render_buffer, &X2_noise_floor_, &X2_noise_floor_counter_); | 104 RenderNoisePower(render_buffer, &X2_noise_floor_, &X2_noise_floor_counter_); |
| 105 | 105 |
| 106 // Estimate the residual echo power. | 106 // Estimate the residual echo power. |
| 107 const bool use_linear_echo_power = | 107 const bool use_linear_echo_power = |
| 108 aec_state.UsableLinearEstimate() && using_subtractor_output; | 108 aec_state.UsableLinearEstimate() && using_subtractor_output; |
| 109 if (use_linear_echo_power && !aec_state.HeadsetDetected()) { | 109 if (use_linear_echo_power && !aec_state.HeadsetDetected()) { |
| 110 RTC_DCHECK(aec_state.FilterDelay()); | 110 RTC_DCHECK(aec_state.FilterDelay()); |
| 111 const int filter_delay = *aec_state.FilterDelay(); | 111 const int filter_delay = *aec_state.FilterDelay(); |
| 112 LinearEstimate(S2_linear, aec_state.Erle(), filter_delay, R2); | 112 LinearEstimate(S2_linear, aec_state.Erle(), filter_delay, R2); |
| 113 AddEchoReverb(S2_linear, aec_state.SaturatedEcho(), filter_delay, | 113 AddEchoReverb(S2_linear, aec_state.SaturatedEcho(), filter_delay, |
| 114 aec_state.ReverbDecayFactor(), R2); | 114 aec_state.ReverbDecay(), R2); |
| 115 } else { | 115 } else { |
| 116 // Estimate the echo generating signal power. | 116 // Estimate the echo generating signal power. |
| 117 std::array<float, kFftLengthBy2Plus1> X2; | 117 std::array<float, kFftLengthBy2Plus1> X2; |
| 118 if (aec_state.ExternalDelay() || aec_state.FilterDelay()) { | 118 if (aec_state.ExternalDelay() || aec_state.FilterDelay()) { |
| 119 RTC_DCHECK(delay); | 119 RTC_DCHECK(delay); |
| 120 const int delay_use = static_cast<int>(*delay); | 120 const int delay_use = static_cast<int>(*delay); |
| 121 | 121 |
| 122 // Computes the spectral power over the blocks surrounding the delay. | 122 // Computes the spectral power over the blocks surrounding the delay. |
| 123 RTC_DCHECK_LT(delay_use, kResidualEchoPowerRenderWindowSize); | 123 RTC_DCHECK_LT(delay_use, kResidualEchoPowerRenderWindowSize); |
| 124 EchoGeneratingPower( | 124 EchoGeneratingPower( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 135 std::transform( | 135 std::transform( |
| 136 X2.begin(), X2.end(), X2_noise_floor_.begin(), X2.begin(), | 136 X2.begin(), X2.end(), X2_noise_floor_.begin(), X2.begin(), |
| 137 [](float a, float b) { return std::max(0.f, a - 10.f * b); }); | 137 [](float a, float b) { return std::max(0.f, a - 10.f * b); }); |
| 138 | 138 |
| 139 NonLinearEstimate( | 139 NonLinearEstimate( |
| 140 aec_state.HeadsetDetected() ? kHeadsetEchoPathGain : kFixedEchoPathGain, | 140 aec_state.HeadsetDetected() ? kHeadsetEchoPathGain : kFixedEchoPathGain, |
| 141 X2, Y2, R2); | 141 X2, Y2, R2); |
| 142 AddEchoReverb(*R2, aec_state.SaturatedEcho(), | 142 AddEchoReverb(*R2, aec_state.SaturatedEcho(), |
| 143 std::min(static_cast<size_t>(kAdaptiveFilterLength), | 143 std::min(static_cast<size_t>(kAdaptiveFilterLength), |
| 144 delay.value_or(kAdaptiveFilterLength)), | 144 delay.value_or(kAdaptiveFilterLength)), |
| 145 aec_state.ReverbDecayFactor(), R2); | 145 aec_state.ReverbDecay(), R2); |
| 146 } |
| 147 |
| 148 // If the echo is deemed inaudible, set the residual echo to zero. |
| 149 if (aec_state.InaudibleEcho()) { |
| 150 R2->fill(0.f); |
| 146 } | 151 } |
| 147 | 152 |
| 148 // If the echo is saturated, estimate the echo power as the maximum echo power | 153 // If the echo is saturated, estimate the echo power as the maximum echo power |
| 149 // with a leakage factor. | 154 // with a leakage factor. |
| 150 if (aec_state.SaturatedEcho()) { | 155 if (aec_state.SaturatedEcho()) { |
| 151 R2->fill((*std::max_element(R2->begin(), R2->end())) * 100.f); | 156 R2->fill((*std::max_element(R2->begin(), R2->end())) * 100.f); |
| 152 } | 157 } |
| 153 | 158 |
| 154 std::copy(R2->begin(), R2->end(), R2_old_.begin()); | 159 std::copy(R2->begin(), R2->end(), R2_old_.begin()); |
| 155 } | 160 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } else { | 239 } else { |
| 235 std::copy(S2.begin(), S2.end(), S2_old_[S2_old_index_].begin()); | 240 std::copy(S2.begin(), S2.end(), S2_old_[S2_old_index_].begin()); |
| 236 } | 241 } |
| 237 | 242 |
| 238 // Add the power of the echo reverb to the residual echo power. | 243 // Add the power of the echo reverb to the residual echo power. |
| 239 std::transform(R2->begin(), R2->end(), R2_reverb_.begin(), R2->begin(), | 244 std::transform(R2->begin(), R2->end(), R2_reverb_.begin(), R2->begin(), |
| 240 std::plus<float>()); | 245 std::plus<float>()); |
| 241 } | 246 } |
| 242 | 247 |
| 243 } // namespace webrtc | 248 } // namespace webrtc |
| OLD | NEW |