| 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 #include "webrtc/modules/audio_processing/aec3/echo_remover.h" |   10 #include "webrtc/modules/audio_processing/aec3/echo_remover.h" | 
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  124   RTC_DCHECK_EQ(y->size(), NumBandsForRate(sample_rate_hz_)); |  124   RTC_DCHECK_EQ(y->size(), NumBandsForRate(sample_rate_hz_)); | 
|  125   RTC_DCHECK_EQ(x[0].size(), kBlockSize); |  125   RTC_DCHECK_EQ(x[0].size(), kBlockSize); | 
|  126   RTC_DCHECK_EQ((*y)[0].size(), kBlockSize); |  126   RTC_DCHECK_EQ((*y)[0].size(), kBlockSize); | 
|  127   const std::vector<float>& x0 = x[0]; |  127   const std::vector<float>& x0 = x[0]; | 
|  128   std::vector<float>& y0 = (*y)[0]; |  128   std::vector<float>& y0 = (*y)[0]; | 
|  129  |  129  | 
|  130   data_dumper_->DumpWav("aec3_echo_remover_capture_input", kBlockSize, &y0[0], |  130   data_dumper_->DumpWav("aec3_echo_remover_capture_input", kBlockSize, &y0[0], | 
|  131                         LowestBandRate(sample_rate_hz_), 1); |  131                         LowestBandRate(sample_rate_hz_), 1); | 
|  132   data_dumper_->DumpWav("aec3_echo_remover_render_input", kBlockSize, &x0[0], |  132   data_dumper_->DumpWav("aec3_echo_remover_render_input", kBlockSize, &x0[0], | 
|  133                         LowestBandRate(sample_rate_hz_), 1); |  133                         LowestBandRate(sample_rate_hz_), 1); | 
 |  134   data_dumper_->DumpRaw("aec3_echo_remover_capture_input", y0); | 
 |  135   data_dumper_->DumpRaw("aec3_echo_remover_render_input", x0); | 
|  134  |  136  | 
|  135   aec_state_.UpdateCaptureSaturation(capture_signal_saturation); |  137   aec_state_.UpdateCaptureSaturation(capture_signal_saturation); | 
|  136  |  138  | 
|  137   if (echo_path_variability.AudioPathChanged()) { |  139   if (echo_path_variability.AudioPathChanged()) { | 
|  138     subtractor_.HandleEchoPathChange(echo_path_variability); |  140     subtractor_.HandleEchoPathChange(echo_path_variability); | 
|  139     aec_state_.HandleEchoPathChange(echo_path_variability); |  141     aec_state_.HandleEchoPathChange(echo_path_variability); | 
|  140   } |  142   } | 
|  141  |  143  | 
|  142   std::array<float, kFftLengthBy2Plus1> Y2; |  144   std::array<float, kFftLengthBy2Plus1> Y2; | 
|  143   std::array<float, kFftLengthBy2Plus1> R2; |  145   std::array<float, kFftLengthBy2Plus1> R2; | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|  160   subtractor_.Process(render_buffer, y0, render_signal_analyzer_, aec_state_, |  162   subtractor_.Process(render_buffer, y0, render_signal_analyzer_, aec_state_, | 
|  161                       &subtractor_output); |  163                       &subtractor_output); | 
|  162  |  164  | 
|  163   // Compute spectra. |  165   // Compute spectra. | 
|  164   fft_.ZeroPaddedFft(y0, &Y); |  166   fft_.ZeroPaddedFft(y0, &Y); | 
|  165   LinearEchoPower(E_main, Y, &S2_linear); |  167   LinearEchoPower(E_main, Y, &S2_linear); | 
|  166   Y.Spectrum(optimization_, &Y2); |  168   Y.Spectrum(optimization_, &Y2); | 
|  167  |  169  | 
|  168   // Update the AEC state information. |  170   // Update the AEC state information. | 
|  169   aec_state_.Update(subtractor_.FilterFrequencyResponse(), |  171   aec_state_.Update(subtractor_.FilterFrequencyResponse(), | 
 |  172                     subtractor_.FilterImpulseResponse(), | 
|  170                     echo_path_delay_samples, render_buffer, E2_main, Y2, x0, |  173                     echo_path_delay_samples, render_buffer, E2_main, Y2, x0, | 
|  171                     echo_leakage_detected_); |  174                     subtractor_output.s_main, echo_leakage_detected_); | 
|  172  |  175  | 
|  173   // Choose the linear output. |  176   // Choose the linear output. | 
|  174   output_selector_.FormLinearOutput(!aec_state_.HeadsetDetected(), e_main, y0); |  177   output_selector_.FormLinearOutput(!aec_state_.HeadsetDetected(), e_main, y0); | 
|  175   data_dumper_->DumpWav("aec3_output_linear", kBlockSize, &y0[0], |  178   data_dumper_->DumpWav("aec3_output_linear", kBlockSize, &y0[0], | 
|  176                         LowestBandRate(sample_rate_hz_), 1); |  179                         LowestBandRate(sample_rate_hz_), 1); | 
 |  180   data_dumper_->DumpRaw("aec3_output_linear", y0); | 
|  177   const auto& E2 = output_selector_.UseSubtractorOutput() ? E2_main : Y2; |  181   const auto& E2 = output_selector_.UseSubtractorOutput() ? E2_main : Y2; | 
|  178  |  182  | 
|  179   // Estimate the residual echo power. |  183   // Estimate the residual echo power. | 
|  180   residual_echo_estimator_.Estimate(output_selector_.UseSubtractorOutput(), |  184   residual_echo_estimator_.Estimate(output_selector_.UseSubtractorOutput(), | 
|  181                                     aec_state_, render_buffer, S2_linear, Y2, |  185                                     aec_state_, render_buffer, S2_linear, Y2, | 
|  182                                     &R2); |  186                                     &R2); | 
|  183  |  187  | 
|  184   // Estimate the comfort noise. |  188   // Estimate the comfort noise. | 
|  185   cng_.Compute(aec_state_, Y2, &comfort_noise, &high_band_comfort_noise); |  189   cng_.Compute(aec_state_, Y2, &comfort_noise, &high_band_comfort_noise); | 
|  186  |  190  | 
|  187   // A choose and apply echo suppression gain. |  191   // A choose and apply echo suppression gain. | 
|  188   suppression_gain_.GetGain(E2, R2, cng_.NoiseSpectrum(), |  192   suppression_gain_.GetGain(E2, R2, cng_.NoiseSpectrum(), | 
|  189                             aec_state_.SaturatedEcho(), x, |  193                             aec_state_.SaturatedEcho(), x, | 
|  190                             aec_state_.ForcedZeroGain(), &high_bands_gain, &G); |  194                             aec_state_.ForcedZeroGain(), &high_bands_gain, &G); | 
|  191   suppression_filter_.ApplyGain(comfort_noise, high_band_comfort_noise, G, |  195   suppression_filter_.ApplyGain(comfort_noise, high_band_comfort_noise, G, | 
|  192                                 high_bands_gain, y); |  196                                 high_bands_gain, y); | 
|  193  |  197  | 
|  194   // Update the metrics. |  198   // Update the metrics. | 
|  195   metrics_.Update(aec_state_, cng_.NoiseSpectrum(), G); |  199   metrics_.Update(aec_state_, cng_.NoiseSpectrum(), G); | 
|  196  |  200  | 
 |  201   // Update the aec state with the aec output characteristics. | 
 |  202   aec_state_.UpdateWithOutput(y0); | 
 |  203  | 
|  197   // Debug outputs for the purpose of development and analysis. |  204   // Debug outputs for the purpose of development and analysis. | 
 |  205   data_dumper_->DumpWav("aec3_echo_estimate", kBlockSize, | 
 |  206                         &subtractor_output.s_main[0], | 
 |  207                         LowestBandRate(sample_rate_hz_), 1); | 
 |  208   data_dumper_->DumpRaw("aec3_output", y0); | 
|  198   data_dumper_->DumpRaw("aec3_N2", cng_.NoiseSpectrum()); |  209   data_dumper_->DumpRaw("aec3_N2", cng_.NoiseSpectrum()); | 
|  199   data_dumper_->DumpRaw("aec3_suppressor_gain", G); |  210   data_dumper_->DumpRaw("aec3_suppressor_gain", G); | 
|  200   data_dumper_->DumpWav("aec3_output", |  211   data_dumper_->DumpWav("aec3_output", | 
|  201                         rtc::ArrayView<const float>(&y0[0], kBlockSize), |  212                         rtc::ArrayView<const float>(&y0[0], kBlockSize), | 
|  202                         LowestBandRate(sample_rate_hz_), 1); |  213                         LowestBandRate(sample_rate_hz_), 1); | 
|  203   data_dumper_->DumpRaw("aec3_using_subtractor_output", |  214   data_dumper_->DumpRaw("aec3_using_subtractor_output", | 
|  204                         output_selector_.UseSubtractorOutput() ? 1 : 0); |  215                         output_selector_.UseSubtractorOutput() ? 1 : 0); | 
|  205   data_dumper_->DumpRaw("aec3_E2", E2); |  216   data_dumper_->DumpRaw("aec3_E2", E2); | 
|  206   data_dumper_->DumpRaw("aec3_E2_main", E2_main); |  217   data_dumper_->DumpRaw("aec3_E2_main", E2_main); | 
|  207   data_dumper_->DumpRaw("aec3_E2_shadow", E2_shadow); |  218   data_dumper_->DumpRaw("aec3_E2_shadow", E2_shadow); | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  226  |  237  | 
|  227 }  // namespace |  238 }  // namespace | 
|  228  |  239  | 
|  229 EchoRemover* EchoRemover::Create( |  240 EchoRemover* EchoRemover::Create( | 
|  230     const AudioProcessing::Config::EchoCanceller3& config, |  241     const AudioProcessing::Config::EchoCanceller3& config, | 
|  231     int sample_rate_hz) { |  242     int sample_rate_hz) { | 
|  232   return new EchoRemoverImpl(config, sample_rate_hz); |  243   return new EchoRemoverImpl(config, sample_rate_hz); | 
|  233 } |  244 } | 
|  234  |  245  | 
|  235 }  // namespace webrtc |  246 }  // namespace webrtc | 
| OLD | NEW |