| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
| 11 #include "webrtc/modules/audio_processing/audio_processing_impl.h" | 11 #include "webrtc/modules/audio_processing/audio_processing_impl.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 | 14 |
| 15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/platform_file.h" | 16 #include "webrtc/base/platform_file.h" |
| 17 #include "webrtc/base/trace_event.h" | 17 #include "webrtc/base/trace_event.h" |
| 18 #include "webrtc/common_audio/audio_converter.h" | 18 #include "webrtc/common_audio/audio_converter.h" |
| 19 #include "webrtc/common_audio/channel_buffer.h" | 19 #include "webrtc/common_audio/channel_buffer.h" |
| 20 #include "webrtc/common_audio/include/audio_util.h" | 20 #include "webrtc/common_audio/include/audio_util.h" |
| 21 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 21 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
| 22 #include "webrtc/modules/audio_processing/aec/aec_core.h" | 22 #include "webrtc/modules/audio_processing/aec/aec_core.h" |
| 23 #include "webrtc/modules/audio_processing/aec3/echo_canceller3.h" |
| 23 #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h" | 24 #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h" |
| 24 #include "webrtc/modules/audio_processing/audio_buffer.h" | 25 #include "webrtc/modules/audio_processing/audio_buffer.h" |
| 25 #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" | 26 #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" |
| 26 #include "webrtc/modules/audio_processing/common.h" | 27 #include "webrtc/modules/audio_processing/common.h" |
| 27 #include "webrtc/modules/audio_processing/echo_cancellation_impl.h" | 28 #include "webrtc/modules/audio_processing/echo_cancellation_impl.h" |
| 28 #include "webrtc/modules/audio_processing/echo_control_mobile_impl.h" | 29 #include "webrtc/modules/audio_processing/echo_control_mobile_impl.h" |
| 29 #include "webrtc/modules/audio_processing/gain_control_for_experimental_agc.h" | 30 #include "webrtc/modules/audio_processing/gain_control_for_experimental_agc.h" |
| 30 #include "webrtc/modules/audio_processing/gain_control_impl.h" | 31 #include "webrtc/modules/audio_processing/gain_control_impl.h" |
| 31 #if WEBRTC_INTELLIGIBILITY_ENHANCER | 32 #if WEBRTC_INTELLIGIBILITY_ENHANCER |
| 32 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc
er.h" | 33 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc
er.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 bool AudioProcessingImpl::ApmSubmoduleStates::Update( | 161 bool AudioProcessingImpl::ApmSubmoduleStates::Update( |
| 161 bool low_cut_filter_enabled, | 162 bool low_cut_filter_enabled, |
| 162 bool echo_canceller_enabled, | 163 bool echo_canceller_enabled, |
| 163 bool mobile_echo_controller_enabled, | 164 bool mobile_echo_controller_enabled, |
| 164 bool residual_echo_detector_enabled, | 165 bool residual_echo_detector_enabled, |
| 165 bool noise_suppressor_enabled, | 166 bool noise_suppressor_enabled, |
| 166 bool intelligibility_enhancer_enabled, | 167 bool intelligibility_enhancer_enabled, |
| 167 bool beamformer_enabled, | 168 bool beamformer_enabled, |
| 168 bool adaptive_gain_controller_enabled, | 169 bool adaptive_gain_controller_enabled, |
| 169 bool level_controller_enabled, | 170 bool level_controller_enabled, |
| 171 bool echo_canceller3_enabled, |
| 170 bool voice_activity_detector_enabled, | 172 bool voice_activity_detector_enabled, |
| 171 bool level_estimator_enabled, | 173 bool level_estimator_enabled, |
| 172 bool transient_suppressor_enabled) { | 174 bool transient_suppressor_enabled) { |
| 173 bool changed = false; | 175 bool changed = false; |
| 174 changed |= (low_cut_filter_enabled != low_cut_filter_enabled_); | 176 changed |= (low_cut_filter_enabled != low_cut_filter_enabled_); |
| 175 changed |= (echo_canceller_enabled != echo_canceller_enabled_); | 177 changed |= (echo_canceller_enabled != echo_canceller_enabled_); |
| 176 changed |= | 178 changed |= |
| 177 (mobile_echo_controller_enabled != mobile_echo_controller_enabled_); | 179 (mobile_echo_controller_enabled != mobile_echo_controller_enabled_); |
| 178 changed |= | 180 changed |= |
| 179 (residual_echo_detector_enabled != residual_echo_detector_enabled_); | 181 (residual_echo_detector_enabled != residual_echo_detector_enabled_); |
| 180 changed |= (noise_suppressor_enabled != noise_suppressor_enabled_); | 182 changed |= (noise_suppressor_enabled != noise_suppressor_enabled_); |
| 181 changed |= | 183 changed |= |
| 182 (intelligibility_enhancer_enabled != intelligibility_enhancer_enabled_); | 184 (intelligibility_enhancer_enabled != intelligibility_enhancer_enabled_); |
| 183 changed |= (beamformer_enabled != beamformer_enabled_); | 185 changed |= (beamformer_enabled != beamformer_enabled_); |
| 184 changed |= | 186 changed |= |
| 185 (adaptive_gain_controller_enabled != adaptive_gain_controller_enabled_); | 187 (adaptive_gain_controller_enabled != adaptive_gain_controller_enabled_); |
| 186 changed |= (level_controller_enabled != level_controller_enabled_); | 188 changed |= (level_controller_enabled != level_controller_enabled_); |
| 189 changed |= (echo_canceller3_enabled != echo_canceller3_enabled_); |
| 187 changed |= (level_estimator_enabled != level_estimator_enabled_); | 190 changed |= (level_estimator_enabled != level_estimator_enabled_); |
| 188 changed |= | 191 changed |= |
| 189 (voice_activity_detector_enabled != voice_activity_detector_enabled_); | 192 (voice_activity_detector_enabled != voice_activity_detector_enabled_); |
| 190 changed |= (transient_suppressor_enabled != transient_suppressor_enabled_); | 193 changed |= (transient_suppressor_enabled != transient_suppressor_enabled_); |
| 191 if (changed) { | 194 if (changed) { |
| 192 low_cut_filter_enabled_ = low_cut_filter_enabled; | 195 low_cut_filter_enabled_ = low_cut_filter_enabled; |
| 193 echo_canceller_enabled_ = echo_canceller_enabled; | 196 echo_canceller_enabled_ = echo_canceller_enabled; |
| 194 mobile_echo_controller_enabled_ = mobile_echo_controller_enabled; | 197 mobile_echo_controller_enabled_ = mobile_echo_controller_enabled; |
| 195 residual_echo_detector_enabled_ = residual_echo_detector_enabled; | 198 residual_echo_detector_enabled_ = residual_echo_detector_enabled; |
| 196 noise_suppressor_enabled_ = noise_suppressor_enabled; | 199 noise_suppressor_enabled_ = noise_suppressor_enabled; |
| 197 intelligibility_enhancer_enabled_ = intelligibility_enhancer_enabled; | 200 intelligibility_enhancer_enabled_ = intelligibility_enhancer_enabled; |
| 198 beamformer_enabled_ = beamformer_enabled; | 201 beamformer_enabled_ = beamformer_enabled; |
| 199 adaptive_gain_controller_enabled_ = adaptive_gain_controller_enabled; | 202 adaptive_gain_controller_enabled_ = adaptive_gain_controller_enabled; |
| 200 level_controller_enabled_ = level_controller_enabled; | 203 level_controller_enabled_ = level_controller_enabled; |
| 204 echo_canceller3_enabled_ = echo_canceller3_enabled; |
| 201 level_estimator_enabled_ = level_estimator_enabled; | 205 level_estimator_enabled_ = level_estimator_enabled; |
| 202 voice_activity_detector_enabled_ = voice_activity_detector_enabled; | 206 voice_activity_detector_enabled_ = voice_activity_detector_enabled; |
| 203 transient_suppressor_enabled_ = transient_suppressor_enabled; | 207 transient_suppressor_enabled_ = transient_suppressor_enabled; |
| 204 } | 208 } |
| 205 | 209 |
| 206 changed |= first_update_; | 210 changed |= first_update_; |
| 207 first_update_ = false; | 211 first_update_ = false; |
| 208 return changed; | 212 return changed; |
| 209 } | 213 } |
| 210 | 214 |
| 211 bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandSubModulesActive() | 215 bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandSubModulesActive() |
| 212 const { | 216 const { |
| 213 #if WEBRTC_INTELLIGIBILITY_ENHANCER | 217 #if WEBRTC_INTELLIGIBILITY_ENHANCER |
| 214 return CaptureMultiBandProcessingActive() || | 218 return CaptureMultiBandProcessingActive() || |
| 215 intelligibility_enhancer_enabled_ || | 219 intelligibility_enhancer_enabled_ || |
| 216 voice_activity_detector_enabled_ || residual_echo_detector_enabled_; | 220 voice_activity_detector_enabled_ || residual_echo_detector_enabled_; |
| 217 #else | 221 #else |
| 218 return CaptureMultiBandProcessingActive() || | 222 return CaptureMultiBandProcessingActive() || |
| 219 voice_activity_detector_enabled_ || residual_echo_detector_enabled_; | 223 voice_activity_detector_enabled_ || residual_echo_detector_enabled_; |
| 220 #endif | 224 #endif |
| 221 } | 225 } |
| 222 | 226 |
| 223 bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandProcessingActive() | 227 bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandProcessingActive() |
| 224 const { | 228 const { |
| 225 return low_cut_filter_enabled_ || echo_canceller_enabled_ || | 229 return low_cut_filter_enabled_ || echo_canceller_enabled_ || |
| 226 mobile_echo_controller_enabled_ || noise_suppressor_enabled_ || | 230 mobile_echo_controller_enabled_ || noise_suppressor_enabled_ || |
| 227 beamformer_enabled_ || adaptive_gain_controller_enabled_; | 231 beamformer_enabled_ || adaptive_gain_controller_enabled_ || |
| 232 echo_canceller3_enabled_; |
| 228 } | 233 } |
| 229 | 234 |
| 230 bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandSubModulesActive() | 235 bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandSubModulesActive() |
| 231 const { | 236 const { |
| 232 return RenderMultiBandProcessingActive() || echo_canceller_enabled_ || | 237 return RenderMultiBandProcessingActive() || echo_canceller_enabled_ || |
| 233 mobile_echo_controller_enabled_ || adaptive_gain_controller_enabled_ || | 238 mobile_echo_controller_enabled_ || adaptive_gain_controller_enabled_ || |
| 234 residual_echo_detector_enabled_; | 239 residual_echo_detector_enabled_ || echo_canceller3_enabled_; |
| 235 } | 240 } |
| 236 | 241 |
| 237 bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandProcessingActive() | 242 bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandProcessingActive() |
| 238 const { | 243 const { |
| 239 #if WEBRTC_INTELLIGIBILITY_ENHANCER | 244 #if WEBRTC_INTELLIGIBILITY_ENHANCER |
| 240 return intelligibility_enhancer_enabled_; | 245 return intelligibility_enhancer_enabled_; |
| 241 #else | 246 #else |
| 242 return false; | 247 return false; |
| 243 #endif | 248 #endif |
| 244 } | 249 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 264 | 269 |
| 265 struct AudioProcessingImpl::ApmPrivateSubmodules { | 270 struct AudioProcessingImpl::ApmPrivateSubmodules { |
| 266 explicit ApmPrivateSubmodules(NonlinearBeamformer* beamformer) | 271 explicit ApmPrivateSubmodules(NonlinearBeamformer* beamformer) |
| 267 : beamformer(beamformer) {} | 272 : beamformer(beamformer) {} |
| 268 // Accessed internally from capture or during initialization | 273 // Accessed internally from capture or during initialization |
| 269 std::unique_ptr<NonlinearBeamformer> beamformer; | 274 std::unique_ptr<NonlinearBeamformer> beamformer; |
| 270 std::unique_ptr<AgcManagerDirect> agc_manager; | 275 std::unique_ptr<AgcManagerDirect> agc_manager; |
| 271 std::unique_ptr<LowCutFilter> low_cut_filter; | 276 std::unique_ptr<LowCutFilter> low_cut_filter; |
| 272 std::unique_ptr<LevelController> level_controller; | 277 std::unique_ptr<LevelController> level_controller; |
| 273 std::unique_ptr<ResidualEchoDetector> residual_echo_detector; | 278 std::unique_ptr<ResidualEchoDetector> residual_echo_detector; |
| 279 std::unique_ptr<EchoCanceller3> echo_canceller3; |
| 274 }; | 280 }; |
| 275 | 281 |
| 276 AudioProcessing* AudioProcessing::Create() { | 282 AudioProcessing* AudioProcessing::Create() { |
| 277 webrtc::Config config; | 283 webrtc::Config config; |
| 278 return Create(config, nullptr); | 284 return Create(config, nullptr); |
| 279 } | 285 } |
| 280 | 286 |
| 281 AudioProcessing* AudioProcessing::Create(const webrtc::Config& config) { | 287 AudioProcessing* AudioProcessing::Create(const webrtc::Config& config) { |
| 282 return Create(config, nullptr); | 288 return Create(config, nullptr); |
| 283 } | 289 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 // Called from both threads. Thread check is therefore not possible. | 432 // Called from both threads. Thread check is therefore not possible. |
| 427 if (processing_config == formats_.api_format && !force_initialization) { | 433 if (processing_config == formats_.api_format && !force_initialization) { |
| 428 return kNoError; | 434 return kNoError; |
| 429 } | 435 } |
| 430 | 436 |
| 431 rtc::CritScope cs_capture(&crit_capture_); | 437 rtc::CritScope cs_capture(&crit_capture_); |
| 432 return InitializeLocked(processing_config); | 438 return InitializeLocked(processing_config); |
| 433 } | 439 } |
| 434 | 440 |
| 435 int AudioProcessingImpl::InitializeLocked() { | 441 int AudioProcessingImpl::InitializeLocked() { |
| 436 const int capture_audiobuffer_num_channels = | 442 int capture_audiobuffer_num_channels; |
| 437 capture_nonlocked_.beamformer_enabled | 443 if (private_submodules_->echo_canceller3) { |
| 438 ? formats_.api_format.input_stream().num_channels() | 444 // TODO(peah): Ensure that the echo canceller can operate on more than one |
| 439 : formats_.api_format.output_stream().num_channels(); | 445 // microphone channel. |
| 446 RTC_DCHECK(!capture_nonlocked_.beamformer_enabled); |
| 447 capture_audiobuffer_num_channels = 1; |
| 448 } else { |
| 449 capture_audiobuffer_num_channels = |
| 450 capture_nonlocked_.beamformer_enabled |
| 451 ? formats_.api_format.input_stream().num_channels() |
| 452 : formats_.api_format.output_stream().num_channels(); |
| 453 } |
| 440 const int render_audiobuffer_num_output_frames = | 454 const int render_audiobuffer_num_output_frames = |
| 441 formats_.api_format.reverse_output_stream().num_frames() == 0 | 455 formats_.api_format.reverse_output_stream().num_frames() == 0 |
| 442 ? formats_.render_processing_format.num_frames() | 456 ? formats_.render_processing_format.num_frames() |
| 443 : formats_.api_format.reverse_output_stream().num_frames(); | 457 : formats_.api_format.reverse_output_stream().num_frames(); |
| 444 if (formats_.api_format.reverse_input_stream().num_channels() > 0) { | 458 if (formats_.api_format.reverse_input_stream().num_channels() > 0) { |
| 445 render_.render_audio.reset(new AudioBuffer( | 459 render_.render_audio.reset(new AudioBuffer( |
| 446 formats_.api_format.reverse_input_stream().num_frames(), | 460 formats_.api_format.reverse_input_stream().num_frames(), |
| 447 formats_.api_format.reverse_input_stream().num_channels(), | 461 formats_.api_format.reverse_input_stream().num_channels(), |
| 448 formats_.render_processing_format.num_frames(), | 462 formats_.render_processing_format.num_frames(), |
| 449 formats_.render_processing_format.num_channels(), | 463 formats_.render_processing_format.num_channels(), |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 #if WEBRTC_INTELLIGIBILITY_ENHANCER | 515 #if WEBRTC_INTELLIGIBILITY_ENHANCER |
| 502 InitializeIntelligibility(); | 516 InitializeIntelligibility(); |
| 503 #endif | 517 #endif |
| 504 InitializeLowCutFilter(); | 518 InitializeLowCutFilter(); |
| 505 public_submodules_->noise_suppression->Initialize(num_proc_channels(), | 519 public_submodules_->noise_suppression->Initialize(num_proc_channels(), |
| 506 proc_sample_rate_hz()); | 520 proc_sample_rate_hz()); |
| 507 public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz()); | 521 public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz()); |
| 508 public_submodules_->level_estimator->Initialize(); | 522 public_submodules_->level_estimator->Initialize(); |
| 509 InitializeLevelController(); | 523 InitializeLevelController(); |
| 510 InitializeResidualEchoDetector(); | 524 InitializeResidualEchoDetector(); |
| 525 InitializeEchoCanceller3(); |
| 511 | 526 |
| 512 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 527 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 513 if (debug_dump_.debug_file->is_open()) { | 528 if (debug_dump_.debug_file->is_open()) { |
| 514 int err = WriteInitMessage(); | 529 int err = WriteInitMessage(); |
| 515 if (err != kNoError) { | 530 if (err != kNoError) { |
| 516 return err; | 531 return err; |
| 517 } | 532 } |
| 518 } | 533 } |
| 519 #endif | 534 #endif |
| 520 | 535 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 capture_nonlocked_.capture_processing_format = | 569 capture_nonlocked_.capture_processing_format = |
| 555 StreamConfig(capture_processing_rate); | 570 StreamConfig(capture_processing_rate); |
| 556 | 571 |
| 557 int render_processing_rate = FindNativeProcessRateToUse( | 572 int render_processing_rate = FindNativeProcessRateToUse( |
| 558 std::min(formats_.api_format.reverse_input_stream().sample_rate_hz(), | 573 std::min(formats_.api_format.reverse_input_stream().sample_rate_hz(), |
| 559 formats_.api_format.reverse_output_stream().sample_rate_hz()), | 574 formats_.api_format.reverse_output_stream().sample_rate_hz()), |
| 560 submodule_states_.CaptureMultiBandSubModulesActive() || | 575 submodule_states_.CaptureMultiBandSubModulesActive() || |
| 561 submodule_states_.RenderMultiBandSubModulesActive()); | 576 submodule_states_.RenderMultiBandSubModulesActive()); |
| 562 // TODO(aluebs): Remove this restriction once we figure out why the 3-band | 577 // TODO(aluebs): Remove this restriction once we figure out why the 3-band |
| 563 // splitting filter degrades the AEC performance. | 578 // splitting filter degrades the AEC performance. |
| 564 if (render_processing_rate > kSampleRate32kHz) { | 579 // TODO(peah): Verify that the band splitting is needed for the AEC3. |
| 580 if (render_processing_rate > kSampleRate32kHz && |
| 581 !capture_nonlocked_.echo_canceller3_enabled) { |
| 565 render_processing_rate = submodule_states_.RenderMultiBandProcessingActive() | 582 render_processing_rate = submodule_states_.RenderMultiBandProcessingActive() |
| 566 ? kSampleRate32kHz | 583 ? kSampleRate32kHz |
| 567 : kSampleRate16kHz; | 584 : kSampleRate16kHz; |
| 568 } | 585 } |
| 569 // If the forward sample rate is 8 kHz, the render stream is also processed | 586 // If the forward sample rate is 8 kHz, the render stream is also processed |
| 570 // at this rate. | 587 // at this rate. |
| 571 if (capture_nonlocked_.capture_processing_format.sample_rate_hz() == | 588 if (capture_nonlocked_.capture_processing_format.sample_rate_hz() == |
| 572 kSampleRate8kHz) { | 589 kSampleRate8kHz) { |
| 573 render_processing_rate = kSampleRate8kHz; | 590 render_processing_rate = kSampleRate8kHz; |
| 574 } else { | 591 } else { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 } | 639 } |
| 623 LOG(LS_INFO) << "Level controller activated: " | 640 LOG(LS_INFO) << "Level controller activated: " |
| 624 << capture_nonlocked_.level_controller_enabled; | 641 << capture_nonlocked_.level_controller_enabled; |
| 625 | 642 |
| 626 private_submodules_->level_controller->ApplyConfig(config_.level_controller); | 643 private_submodules_->level_controller->ApplyConfig(config_.level_controller); |
| 627 | 644 |
| 628 InitializeLowCutFilter(); | 645 InitializeLowCutFilter(); |
| 629 | 646 |
| 630 LOG(LS_INFO) << "Highpass filter activated: " | 647 LOG(LS_INFO) << "Highpass filter activated: " |
| 631 << config_.high_pass_filter.enabled; | 648 << config_.high_pass_filter.enabled; |
| 649 |
| 650 config_ok = EchoCanceller3::Validate(config_.echo_canceller3); |
| 651 if (!config_ok) { |
| 652 LOG(LS_ERROR) << "AudioProcessing module config error" << std::endl |
| 653 << "echo canceller 3: " |
| 654 << EchoCanceller3::ToString(config_.echo_canceller3) |
| 655 << std::endl |
| 656 << "Reverting to default parameter set"; |
| 657 config_.echo_canceller3 = AudioProcessing::Config::EchoCanceller3(); |
| 658 } |
| 659 |
| 660 if (config.echo_canceller3.enabled != |
| 661 capture_nonlocked_.echo_canceller3_enabled) { |
| 662 capture_nonlocked_.echo_canceller3_enabled = |
| 663 config_.echo_canceller3.enabled; |
| 664 InitializeEchoCanceller3(); |
| 665 LOG(LS_INFO) << "Echo canceller 3 activated: " |
| 666 << capture_nonlocked_.echo_canceller3_enabled; |
| 667 } |
| 632 } | 668 } |
| 633 | 669 |
| 634 void AudioProcessingImpl::SetExtraOptions(const webrtc::Config& config) { | 670 void AudioProcessingImpl::SetExtraOptions(const webrtc::Config& config) { |
| 635 // Run in a single-threaded manner when setting the extra options. | 671 // Run in a single-threaded manner when setting the extra options. |
| 636 rtc::CritScope cs_render(&crit_render_); | 672 rtc::CritScope cs_render(&crit_render_); |
| 637 rtc::CritScope cs_capture(&crit_capture_); | 673 rtc::CritScope cs_capture(&crit_capture_); |
| 638 | 674 |
| 639 public_submodules_->echo_cancellation->SetExtraOptions(config); | 675 public_submodules_->echo_cancellation->SetExtraOptions(config); |
| 640 | 676 |
| 641 if (capture_.transient_suppressor_enabled != | 677 if (capture_.transient_suppressor_enabled != |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 capture_nonlocked_.capture_processing_format.num_frames())); | 1137 capture_nonlocked_.capture_processing_format.num_frames())); |
| 1102 if (++rms_interval_counter_ >= 1000) { | 1138 if (++rms_interval_counter_ >= 1000) { |
| 1103 rms_interval_counter_ = 0; | 1139 rms_interval_counter_ = 0; |
| 1104 RmsLevel::Levels levels = rms_.AverageAndPeak(); | 1140 RmsLevel::Levels levels = rms_.AverageAndPeak(); |
| 1105 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureInputLevelAverageRms", | 1141 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureInputLevelAverageRms", |
| 1106 levels.average, 1, RmsLevel::kMinLevelDb, 64); | 1142 levels.average, 1, RmsLevel::kMinLevelDb, 64); |
| 1107 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureInputLevelPeakRms", | 1143 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureInputLevelPeakRms", |
| 1108 levels.peak, 1, RmsLevel::kMinLevelDb, 64); | 1144 levels.peak, 1, RmsLevel::kMinLevelDb, 64); |
| 1109 } | 1145 } |
| 1110 | 1146 |
| 1147 if (private_submodules_->echo_canceller3) { |
| 1148 private_submodules_->echo_canceller3->AnalyzeCapture(capture_buffer); |
| 1149 } |
| 1150 |
| 1111 if (constants_.use_experimental_agc && | 1151 if (constants_.use_experimental_agc && |
| 1112 public_submodules_->gain_control->is_enabled()) { | 1152 public_submodules_->gain_control->is_enabled()) { |
| 1113 private_submodules_->agc_manager->AnalyzePreProcess( | 1153 private_submodules_->agc_manager->AnalyzePreProcess( |
| 1114 capture_buffer->channels()[0], capture_buffer->num_channels(), | 1154 capture_buffer->channels()[0], capture_buffer->num_channels(), |
| 1115 capture_nonlocked_.capture_processing_format.num_frames()); | 1155 capture_nonlocked_.capture_processing_format.num_frames()); |
| 1116 } | 1156 } |
| 1117 | 1157 |
| 1118 if (submodule_states_.CaptureMultiBandSubModulesActive() && | 1158 if (submodule_states_.CaptureMultiBandSubModulesActive() && |
| 1119 SampleRateSupportsMultiBand( | 1159 SampleRateSupportsMultiBand( |
| 1120 capture_nonlocked_.capture_processing_format.sample_rate_hz())) { | 1160 capture_nonlocked_.capture_processing_format.sample_rate_hz())) { |
| 1121 capture_buffer->SplitIntoFrequencyBands(); | 1161 capture_buffer->SplitIntoFrequencyBands(); |
| 1122 } | 1162 } |
| 1123 | 1163 |
| 1124 if (capture_nonlocked_.beamformer_enabled) { | 1164 if (capture_nonlocked_.beamformer_enabled) { |
| 1125 private_submodules_->beamformer->AnalyzeChunk( | 1165 private_submodules_->beamformer->AnalyzeChunk( |
| 1126 *capture_buffer->split_data_f()); | 1166 *capture_buffer->split_data_f()); |
| 1127 // Discards all channels by the leftmost one. | 1167 // Discards all channels by the leftmost one. |
| 1128 capture_buffer->set_num_channels(1); | 1168 capture_buffer->set_num_channels(1); |
| 1129 } | 1169 } |
| 1130 | 1170 |
| 1131 if (private_submodules_->low_cut_filter) { | 1171 // TODO(peah): Move the AEC3 low-cut filter to this place. |
| 1172 if (private_submodules_->low_cut_filter && |
| 1173 !private_submodules_->echo_canceller3) { |
| 1132 private_submodules_->low_cut_filter->Process(capture_buffer); | 1174 private_submodules_->low_cut_filter->Process(capture_buffer); |
| 1133 } | 1175 } |
| 1134 RETURN_ON_ERR( | 1176 RETURN_ON_ERR( |
| 1135 public_submodules_->gain_control->AnalyzeCaptureAudio(capture_buffer)); | 1177 public_submodules_->gain_control->AnalyzeCaptureAudio(capture_buffer)); |
| 1136 public_submodules_->noise_suppression->AnalyzeCaptureAudio(capture_buffer); | 1178 public_submodules_->noise_suppression->AnalyzeCaptureAudio(capture_buffer); |
| 1137 | 1179 |
| 1138 // Ensure that the stream delay was set before the call to the | 1180 // Ensure that the stream delay was set before the call to the |
| 1139 // AEC ProcessCaptureAudio function. | 1181 // AEC ProcessCaptureAudio function. |
| 1140 if (public_submodules_->echo_cancellation->is_enabled() && | 1182 if (public_submodules_->echo_cancellation->is_enabled() && |
| 1141 !was_stream_delay_set()) { | 1183 !was_stream_delay_set()) { |
| 1142 return AudioProcessing::kStreamParameterNotSetError; | 1184 return AudioProcessing::kStreamParameterNotSetError; |
| 1143 } | 1185 } |
| 1144 | 1186 |
| 1187 if (private_submodules_->echo_canceller3) { |
| 1188 private_submodules_->echo_canceller3->ProcessCapture(capture_buffer, false); |
| 1189 } |
| 1190 |
| 1145 RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessCaptureAudio( | 1191 RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessCaptureAudio( |
| 1146 capture_buffer, stream_delay_ms())); | 1192 capture_buffer, stream_delay_ms())); |
| 1147 | 1193 |
| 1148 if (public_submodules_->echo_control_mobile->is_enabled() && | 1194 if (public_submodules_->echo_control_mobile->is_enabled() && |
| 1149 public_submodules_->noise_suppression->is_enabled()) { | 1195 public_submodules_->noise_suppression->is_enabled()) { |
| 1150 capture_buffer->CopyLowPassToReference(); | 1196 capture_buffer->CopyLowPassToReference(); |
| 1151 } | 1197 } |
| 1152 public_submodules_->noise_suppression->ProcessCaptureAudio(capture_buffer); | 1198 public_submodules_->noise_suppression->ProcessCaptureAudio(capture_buffer); |
| 1153 #if WEBRTC_INTELLIGIBILITY_ENHANCER | 1199 #if WEBRTC_INTELLIGIBILITY_ENHANCER |
| 1154 if (capture_nonlocked_.intelligibility_enabled) { | 1200 if (capture_nonlocked_.intelligibility_enabled) { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 } | 1420 } |
| 1375 | 1421 |
| 1376 #if WEBRTC_INTELLIGIBILITY_ENHANCER | 1422 #if WEBRTC_INTELLIGIBILITY_ENHANCER |
| 1377 if (capture_nonlocked_.intelligibility_enabled) { | 1423 if (capture_nonlocked_.intelligibility_enabled) { |
| 1378 public_submodules_->intelligibility_enhancer->ProcessRenderAudio( | 1424 public_submodules_->intelligibility_enhancer->ProcessRenderAudio( |
| 1379 render_buffer); | 1425 render_buffer); |
| 1380 } | 1426 } |
| 1381 #endif | 1427 #endif |
| 1382 | 1428 |
| 1383 QueueRenderAudio(render_buffer); | 1429 QueueRenderAudio(render_buffer); |
| 1430 // TODO(peah): Perform the queueing ínside QueueRenderAudiuo(). |
| 1431 if (private_submodules_->echo_canceller3) { |
| 1432 if (!private_submodules_->echo_canceller3->AnalyzeRender(render_buffer)) { |
| 1433 // TODO(peah): Lock and empty render queue, and try again. |
| 1434 } |
| 1435 } |
| 1384 | 1436 |
| 1385 if (submodule_states_.RenderMultiBandProcessingActive() && | 1437 if (submodule_states_.RenderMultiBandProcessingActive() && |
| 1386 SampleRateSupportsMultiBand( | 1438 SampleRateSupportsMultiBand( |
| 1387 formats_.render_processing_format.sample_rate_hz())) { | 1439 formats_.render_processing_format.sample_rate_hz())) { |
| 1388 render_buffer->MergeFrequencyBands(); | 1440 render_buffer->MergeFrequencyBands(); |
| 1389 } | 1441 } |
| 1390 | 1442 |
| 1391 return kNoError; | 1443 return kNoError; |
| 1392 } | 1444 } |
| 1393 | 1445 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1597 return submodule_states_.Update( | 1649 return submodule_states_.Update( |
| 1598 config_.high_pass_filter.enabled, | 1650 config_.high_pass_filter.enabled, |
| 1599 public_submodules_->echo_cancellation->is_enabled(), | 1651 public_submodules_->echo_cancellation->is_enabled(), |
| 1600 public_submodules_->echo_control_mobile->is_enabled(), | 1652 public_submodules_->echo_control_mobile->is_enabled(), |
| 1601 config_.residual_echo_detector.enabled, | 1653 config_.residual_echo_detector.enabled, |
| 1602 public_submodules_->noise_suppression->is_enabled(), | 1654 public_submodules_->noise_suppression->is_enabled(), |
| 1603 capture_nonlocked_.intelligibility_enabled, | 1655 capture_nonlocked_.intelligibility_enabled, |
| 1604 capture_nonlocked_.beamformer_enabled, | 1656 capture_nonlocked_.beamformer_enabled, |
| 1605 public_submodules_->gain_control->is_enabled(), | 1657 public_submodules_->gain_control->is_enabled(), |
| 1606 capture_nonlocked_.level_controller_enabled, | 1658 capture_nonlocked_.level_controller_enabled, |
| 1659 capture_nonlocked_.echo_canceller3_enabled, |
| 1607 public_submodules_->voice_detection->is_enabled(), | 1660 public_submodules_->voice_detection->is_enabled(), |
| 1608 public_submodules_->level_estimator->is_enabled(), | 1661 public_submodules_->level_estimator->is_enabled(), |
| 1609 capture_.transient_suppressor_enabled); | 1662 capture_.transient_suppressor_enabled); |
| 1610 } | 1663 } |
| 1611 | 1664 |
| 1612 | 1665 |
| 1613 void AudioProcessingImpl::InitializeTransient() { | 1666 void AudioProcessingImpl::InitializeTransient() { |
| 1614 if (capture_.transient_suppressor_enabled) { | 1667 if (capture_.transient_suppressor_enabled) { |
| 1615 if (!public_submodules_->transient_suppressor.get()) { | 1668 if (!public_submodules_->transient_suppressor.get()) { |
| 1616 public_submodules_->transient_suppressor.reset(new TransientSuppressor()); | 1669 public_submodules_->transient_suppressor.reset(new TransientSuppressor()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1645 } | 1698 } |
| 1646 | 1699 |
| 1647 void AudioProcessingImpl::InitializeLowCutFilter() { | 1700 void AudioProcessingImpl::InitializeLowCutFilter() { |
| 1648 if (config_.high_pass_filter.enabled) { | 1701 if (config_.high_pass_filter.enabled) { |
| 1649 private_submodules_->low_cut_filter.reset( | 1702 private_submodules_->low_cut_filter.reset( |
| 1650 new LowCutFilter(num_proc_channels(), proc_sample_rate_hz())); | 1703 new LowCutFilter(num_proc_channels(), proc_sample_rate_hz())); |
| 1651 } else { | 1704 } else { |
| 1652 private_submodules_->low_cut_filter.reset(); | 1705 private_submodules_->low_cut_filter.reset(); |
| 1653 } | 1706 } |
| 1654 } | 1707 } |
| 1708 void AudioProcessingImpl::InitializeEchoCanceller3() { |
| 1709 if (capture_nonlocked_.echo_canceller3_enabled) { |
| 1710 private_submodules_->echo_canceller3.reset( |
| 1711 new EchoCanceller3(proc_sample_rate_hz(), true)); |
| 1712 } else { |
| 1713 private_submodules_->echo_canceller3.reset(); |
| 1714 } |
| 1715 } |
| 1655 | 1716 |
| 1656 void AudioProcessingImpl::InitializeLevelController() { | 1717 void AudioProcessingImpl::InitializeLevelController() { |
| 1657 private_submodules_->level_controller->Initialize(proc_sample_rate_hz()); | 1718 private_submodules_->level_controller->Initialize(proc_sample_rate_hz()); |
| 1658 } | 1719 } |
| 1659 | 1720 |
| 1660 void AudioProcessingImpl::InitializeResidualEchoDetector() { | 1721 void AudioProcessingImpl::InitializeResidualEchoDetector() { |
| 1661 private_submodules_->residual_echo_detector->Initialize(); | 1722 private_submodules_->residual_echo_detector->Initialize(); |
| 1662 } | 1723 } |
| 1663 | 1724 |
| 1664 void AudioProcessingImpl::MaybeUpdateHistograms() { | 1725 void AudioProcessingImpl::MaybeUpdateHistograms() { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1850 std::string experiments_description = | 1911 std::string experiments_description = |
| 1851 public_submodules_->echo_cancellation->GetExperimentsDescription(); | 1912 public_submodules_->echo_cancellation->GetExperimentsDescription(); |
| 1852 // TODO(peah): Add semicolon-separated concatenations of experiment | 1913 // TODO(peah): Add semicolon-separated concatenations of experiment |
| 1853 // descriptions for other submodules. | 1914 // descriptions for other submodules. |
| 1854 if (capture_nonlocked_.level_controller_enabled) { | 1915 if (capture_nonlocked_.level_controller_enabled) { |
| 1855 experiments_description += "LevelController;"; | 1916 experiments_description += "LevelController;"; |
| 1856 } | 1917 } |
| 1857 if (constants_.agc_clipped_level_min != kClippedLevelMin) { | 1918 if (constants_.agc_clipped_level_min != kClippedLevelMin) { |
| 1858 experiments_description += "AgcClippingLevelExperiment;"; | 1919 experiments_description += "AgcClippingLevelExperiment;"; |
| 1859 } | 1920 } |
| 1921 if (capture_nonlocked_.echo_canceller3_enabled) { |
| 1922 experiments_description += "EchoCanceller3;"; |
| 1923 } |
| 1860 config.set_experiments_description(experiments_description); | 1924 config.set_experiments_description(experiments_description); |
| 1861 | 1925 |
| 1862 std::string serialized_config = config.SerializeAsString(); | 1926 std::string serialized_config = config.SerializeAsString(); |
| 1863 if (!forced && | 1927 if (!forced && |
| 1864 debug_dump_.capture.last_serialized_config == serialized_config) { | 1928 debug_dump_.capture.last_serialized_config == serialized_config) { |
| 1865 return kNoError; | 1929 return kNoError; |
| 1866 } | 1930 } |
| 1867 | 1931 |
| 1868 debug_dump_.capture.last_serialized_config = serialized_config; | 1932 debug_dump_.capture.last_serialized_config = serialized_config; |
| 1869 | 1933 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1895 capture_processing_format(kSampleRate16kHz), | 1959 capture_processing_format(kSampleRate16kHz), |
| 1896 split_rate(kSampleRate16kHz) {} | 1960 split_rate(kSampleRate16kHz) {} |
| 1897 | 1961 |
| 1898 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; | 1962 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; |
| 1899 | 1963 |
| 1900 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; | 1964 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; |
| 1901 | 1965 |
| 1902 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; | 1966 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; |
| 1903 | 1967 |
| 1904 } // namespace webrtc | 1968 } // namespace webrtc |
| OLD | NEW |