| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 void ResidualEchoEstimator::Estimate( | 88 void ResidualEchoEstimator::Estimate( |
| 89 bool using_subtractor_output, | 89 bool using_subtractor_output, |
| 90 const AecState& aec_state, | 90 const AecState& aec_state, |
| 91 const RenderBuffer& render_buffer, | 91 const RenderBuffer& render_buffer, |
| 92 const std::array<float, kFftLengthBy2Plus1>& S2_linear, | 92 const std::array<float, kFftLengthBy2Plus1>& S2_linear, |
| 93 const std::array<float, kFftLengthBy2Plus1>& Y2, | 93 const std::array<float, kFftLengthBy2Plus1>& Y2, |
| 94 std::array<float, kFftLengthBy2Plus1>* R2) { | 94 std::array<float, kFftLengthBy2Plus1>* R2) { |
| 95 RTC_DCHECK(R2); | 95 RTC_DCHECK(R2); |
| 96 | 96 |
| 97 const rtc::Optional<size_t> delay = | 97 const rtc::Optional<size_t> delay = |
| 98 aec_state.FilterDelay() | 98 aec_state.ExternalDelay() |
| 99 ? aec_state.FilterDelay() | 99 ? (aec_state.FilterDelay() ? aec_state.FilterDelay() |
| 100 : (aec_state.ExternalDelay() ? aec_state.ExternalDelay() | 100 : aec_state.ExternalDelay()) |
| 101 : rtc::Optional<size_t>()); | 101 : rtc::Optional<size_t>(); |
| 102 | 102 |
| 103 // Estimate the power of the stationary noise in the render signal. | 103 // Estimate the power of the stationary noise in the render signal. |
| 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.ReverbDecay(), 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( |
| 125 render_buffer, std::max(0, delay_use - 1), | 125 render_buffer, std::max(0, delay_use - 1), |
| 126 std::min(kResidualEchoPowerRenderWindowSize - 1, delay_use + 1), &X2); | 126 std::min(kResidualEchoPowerRenderWindowSize - 1, delay_use + 1), &X2); |
| 127 } else { | 127 } else { |
| 128 // Computes the spectral power over the latest blocks. | 128 // Computes the spectral power over the latest blocks. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } else { | 251 } else { |
| 252 std::copy(S2.begin(), S2.end(), S2_old_[S2_old_index_].begin()); | 252 std::copy(S2.begin(), S2.end(), S2_old_[S2_old_index_].begin()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 // Add the power of the echo reverb to the residual echo power. | 255 // Add the power of the echo reverb to the residual echo power. |
| 256 std::transform(R2->begin(), R2->end(), R2_reverb_.begin(), R2->begin(), | 256 std::transform(R2->begin(), R2->end(), R2_reverb_.begin(), R2->begin(), |
| 257 std::plus<float>()); | 257 std::plus<float>()); |
| 258 } | 258 } |
| 259 | 259 |
| 260 } // namespace webrtc | 260 } // namespace webrtc |
| OLD | NEW |