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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 EchoGeneratingPower(render_buffer, 0, | 129 EchoGeneratingPower(render_buffer, 0, |
130 kResidualEchoPowerRenderWindowSize - 1, &X2); | 130 kResidualEchoPowerRenderWindowSize - 1, &X2); |
131 } | 131 } |
132 | 132 |
133 // Subtract the stationary noise power to avoid stationary noise causing | 133 // Subtract the stationary noise power to avoid stationary noise causing |
134 // excessive echo suppression. | 134 // excessive echo suppression. |
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(aec_state, X2, Y2, R2); |
140 aec_state.HeadsetDetected() ? kHeadsetEchoPathGain : kFixedEchoPathGain, | |
141 X2, Y2, R2); | |
142 AddEchoReverb(*R2, aec_state.SaturatedEcho(), | 140 AddEchoReverb(*R2, aec_state.SaturatedEcho(), |
143 std::min(static_cast<size_t>(kAdaptiveFilterLength), | 141 std::min(static_cast<size_t>(kAdaptiveFilterLength), |
144 delay.value_or(kAdaptiveFilterLength)), | 142 delay.value_or(kAdaptiveFilterLength)), |
145 aec_state.ReverbDecayFactor(), R2); | 143 aec_state.ReverbDecayFactor(), R2); |
146 } | 144 } |
147 | 145 |
148 // If the echo is saturated, estimate the echo power as the maximum echo power | 146 // If the echo is saturated, estimate the echo power as the maximum echo power |
149 // with a leakage factor. | 147 // with a leakage factor. |
150 if (aec_state.SaturatedEcho()) { | 148 if (aec_state.SaturatedEcho()) { |
151 R2->fill((*std::max_element(R2->begin(), R2->end())) * 100.f); | 149 R2->fill((*std::max_element(R2->begin(), R2->end())) * 100.f); |
(...skipping 20 matching lines...) Expand all Loading... | |
172 std::array<float, kFftLengthBy2Plus1>* R2) { | 170 std::array<float, kFftLengthBy2Plus1>* R2) { |
173 std::fill(R2_hold_counter_.begin(), R2_hold_counter_.end(), 10.f); | 171 std::fill(R2_hold_counter_.begin(), R2_hold_counter_.end(), 10.f); |
174 std::transform(erle.begin(), erle.end(), S2_linear.begin(), R2->begin(), | 172 std::transform(erle.begin(), erle.end(), S2_linear.begin(), R2->begin(), |
175 [](float a, float b) { | 173 [](float a, float b) { |
176 RTC_DCHECK_LT(0.f, a); | 174 RTC_DCHECK_LT(0.f, a); |
177 return b / a; | 175 return b / a; |
178 }); | 176 }); |
179 } | 177 } |
180 | 178 |
181 void ResidualEchoEstimator::NonLinearEstimate( | 179 void ResidualEchoEstimator::NonLinearEstimate( |
182 float echo_path_gain, | 180 const AecState& aec_state, |
ivoc
2017/07/11 08:46:04
Since the function only uses aec_state.HeadsetDete
peah-webrtc
2017/07/11 08:53:01
Good point!
Done.
| |
183 const std::array<float, kFftLengthBy2Plus1>& X2, | 181 const std::array<float, kFftLengthBy2Plus1>& X2, |
184 const std::array<float, kFftLengthBy2Plus1>& Y2, | 182 const std::array<float, kFftLengthBy2Plus1>& Y2, |
185 std::array<float, kFftLengthBy2Plus1>* R2) { | 183 std::array<float, kFftLengthBy2Plus1>* R2) { |
184 // Choose gains. | |
185 const float echo_path_gain_lf = | |
186 aec_state.HeadsetDetected() ? kHeadsetEchoPathGain : 100; | |
187 const float echo_path_gain_mf = | |
188 aec_state.HeadsetDetected() ? kHeadsetEchoPathGain : 1000; | |
189 const float echo_path_gain_hf = | |
190 aec_state.HeadsetDetected() ? kHeadsetEchoPathGain : 5000; | |
191 | |
186 // Compute preliminary residual echo. | 192 // Compute preliminary residual echo. |
187 std::transform(X2.begin(), X2.end(), R2->begin(), | 193 std::transform( |
188 [echo_path_gain](float a) { return a * echo_path_gain; }); | 194 X2.begin(), X2.begin() + 12, R2->begin(), |
195 [echo_path_gain_lf](float a) { return a * echo_path_gain_lf; }); | |
196 std::transform( | |
197 X2.begin() + 12, X2.begin() + 25, R2->begin() + 12, | |
198 [echo_path_gain_mf](float a) { return a * echo_path_gain_mf; }); | |
199 std::transform( | |
200 X2.begin() + 25, X2.end(), R2->begin() + 25, | |
201 [echo_path_gain_hf](float a) { return a * echo_path_gain_hf; }); | |
189 | 202 |
190 for (size_t k = 0; k < R2->size(); ++k) { | 203 for (size_t k = 0; k < R2->size(); ++k) { |
191 // Update hold counter. | 204 // Update hold counter. |
192 R2_hold_counter_[k] = R2_old_[k] < (*R2)[k] ? 0 : R2_hold_counter_[k] + 1; | 205 R2_hold_counter_[k] = R2_old_[k] < (*R2)[k] ? 0 : R2_hold_counter_[k] + 1; |
193 | 206 |
194 // Compute the residual echo by holding a maximum echo powers and an echo | 207 // Compute the residual echo by holding a maximum echo powers and an echo |
195 // fading corresponding to a room with an RT60 value of about 50 ms. | 208 // fading corresponding to a room with an RT60 value of about 50 ms. |
196 (*R2)[k] = R2_hold_counter_[k] < 2 | 209 (*R2)[k] = R2_hold_counter_[k] < 2 |
197 ? std::max((*R2)[k], R2_old_[k]) | 210 ? std::max((*R2)[k], R2_old_[k]) |
198 : std::min((*R2)[k] + R2_old_[k] * 0.1f, Y2[k]); | 211 : std::min((*R2)[k] + R2_old_[k] * 0.1f, Y2[k]); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 } else { | 247 } else { |
235 std::copy(S2.begin(), S2.end(), S2_old_[S2_old_index_].begin()); | 248 std::copy(S2.begin(), S2.end(), S2_old_[S2_old_index_].begin()); |
236 } | 249 } |
237 | 250 |
238 // Add the power of the echo reverb to the residual echo power. | 251 // Add the power of the echo reverb to the residual echo power. |
239 std::transform(R2->begin(), R2->end(), R2_reverb_.begin(), R2->begin(), | 252 std::transform(R2->begin(), R2->end(), R2_reverb_.begin(), R2->begin(), |
240 std::plus<float>()); | 253 std::plus<float>()); |
241 } | 254 } |
242 | 255 |
243 } // namespace webrtc | 256 } // namespace webrtc |
OLD | NEW |