Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: webrtc/modules/audio_processing/audio_processing_impl.cc

Issue 2848593002: AGC2 as a new APM sub-module operating with hard-coded gain. (Closed)
Patch Set: mock and iface removed, mv agc2 gain_controller2 Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <math.h> 13 #include <math.h>
14 #include <algorithm> 14 #include <algorithm>
15 15
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/base/logging.h" 17 #include "webrtc/base/logging.h"
18 #include "webrtc/base/platform_file.h" 18 #include "webrtc/base/platform_file.h"
19 #include "webrtc/base/trace_event.h" 19 #include "webrtc/base/trace_event.h"
20 #include "webrtc/common_audio/audio_converter.h" 20 #include "webrtc/common_audio/audio_converter.h"
21 #include "webrtc/common_audio/channel_buffer.h" 21 #include "webrtc/common_audio/channel_buffer.h"
22 #include "webrtc/common_audio/include/audio_util.h" 22 #include "webrtc/common_audio/include/audio_util.h"
23 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" 23 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h"
24 #include "webrtc/modules/audio_processing/aec/aec_core.h" 24 #include "webrtc/modules/audio_processing/aec/aec_core.h"
25 #include "webrtc/modules/audio_processing/aec3/echo_canceller3.h" 25 #include "webrtc/modules/audio_processing/aec3/echo_canceller3.h"
26 #include "webrtc/modules/audio_processing/agc2/gain_controller2.h"
26 #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h" 27 #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h"
27 #include "webrtc/modules/audio_processing/audio_buffer.h" 28 #include "webrtc/modules/audio_processing/audio_buffer.h"
28 #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" 29 #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h"
29 #include "webrtc/modules/audio_processing/common.h" 30 #include "webrtc/modules/audio_processing/common.h"
30 #include "webrtc/modules/audio_processing/echo_cancellation_impl.h" 31 #include "webrtc/modules/audio_processing/echo_cancellation_impl.h"
31 #include "webrtc/modules/audio_processing/echo_control_mobile_impl.h" 32 #include "webrtc/modules/audio_processing/echo_control_mobile_impl.h"
32 #include "webrtc/modules/audio_processing/gain_control_for_experimental_agc.h" 33 #include "webrtc/modules/audio_processing/gain_control_for_experimental_agc.h"
33 #include "webrtc/modules/audio_processing/gain_control_impl.h" 34 #include "webrtc/modules/audio_processing/gain_control_impl.h"
34 #if WEBRTC_INTELLIGIBILITY_ENHANCER 35 #if WEBRTC_INTELLIGIBILITY_ENHANCER
35 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc er.h" 36 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc er.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 162
162 bool AudioProcessingImpl::ApmSubmoduleStates::Update( 163 bool AudioProcessingImpl::ApmSubmoduleStates::Update(
163 bool low_cut_filter_enabled, 164 bool low_cut_filter_enabled,
164 bool echo_canceller_enabled, 165 bool echo_canceller_enabled,
165 bool mobile_echo_controller_enabled, 166 bool mobile_echo_controller_enabled,
166 bool residual_echo_detector_enabled, 167 bool residual_echo_detector_enabled,
167 bool noise_suppressor_enabled, 168 bool noise_suppressor_enabled,
168 bool intelligibility_enhancer_enabled, 169 bool intelligibility_enhancer_enabled,
169 bool beamformer_enabled, 170 bool beamformer_enabled,
170 bool adaptive_gain_controller_enabled, 171 bool adaptive_gain_controller_enabled,
172 bool adaptive_gain_controller2_enabled,
171 bool level_controller_enabled, 173 bool level_controller_enabled,
172 bool echo_canceller3_enabled, 174 bool echo_canceller3_enabled,
173 bool voice_activity_detector_enabled, 175 bool voice_activity_detector_enabled,
174 bool level_estimator_enabled, 176 bool level_estimator_enabled,
175 bool transient_suppressor_enabled) { 177 bool transient_suppressor_enabled) {
176 bool changed = false; 178 bool changed = false;
177 changed |= (low_cut_filter_enabled != low_cut_filter_enabled_); 179 changed |= (low_cut_filter_enabled != low_cut_filter_enabled_);
178 changed |= (echo_canceller_enabled != echo_canceller_enabled_); 180 changed |= (echo_canceller_enabled != echo_canceller_enabled_);
179 changed |= 181 changed |=
180 (mobile_echo_controller_enabled != mobile_echo_controller_enabled_); 182 (mobile_echo_controller_enabled != mobile_echo_controller_enabled_);
181 changed |= 183 changed |=
182 (residual_echo_detector_enabled != residual_echo_detector_enabled_); 184 (residual_echo_detector_enabled != residual_echo_detector_enabled_);
183 changed |= (noise_suppressor_enabled != noise_suppressor_enabled_); 185 changed |= (noise_suppressor_enabled != noise_suppressor_enabled_);
184 changed |= 186 changed |=
185 (intelligibility_enhancer_enabled != intelligibility_enhancer_enabled_); 187 (intelligibility_enhancer_enabled != intelligibility_enhancer_enabled_);
186 changed |= (beamformer_enabled != beamformer_enabled_); 188 changed |= (beamformer_enabled != beamformer_enabled_);
187 changed |= 189 changed |=
188 (adaptive_gain_controller_enabled != adaptive_gain_controller_enabled_); 190 (adaptive_gain_controller_enabled != adaptive_gain_controller_enabled_);
191 changed |=
192 (adaptive_gain_controller2_enabled != adaptive_gain_controller2_enabled_);
189 changed |= (level_controller_enabled != level_controller_enabled_); 193 changed |= (level_controller_enabled != level_controller_enabled_);
190 changed |= (echo_canceller3_enabled != echo_canceller3_enabled_); 194 changed |= (echo_canceller3_enabled != echo_canceller3_enabled_);
191 changed |= (level_estimator_enabled != level_estimator_enabled_); 195 changed |= (level_estimator_enabled != level_estimator_enabled_);
192 changed |= 196 changed |=
193 (voice_activity_detector_enabled != voice_activity_detector_enabled_); 197 (voice_activity_detector_enabled != voice_activity_detector_enabled_);
194 changed |= (transient_suppressor_enabled != transient_suppressor_enabled_); 198 changed |= (transient_suppressor_enabled != transient_suppressor_enabled_);
195 if (changed) { 199 if (changed) {
196 low_cut_filter_enabled_ = low_cut_filter_enabled; 200 low_cut_filter_enabled_ = low_cut_filter_enabled;
197 echo_canceller_enabled_ = echo_canceller_enabled; 201 echo_canceller_enabled_ = echo_canceller_enabled;
198 mobile_echo_controller_enabled_ = mobile_echo_controller_enabled; 202 mobile_echo_controller_enabled_ = mobile_echo_controller_enabled;
199 residual_echo_detector_enabled_ = residual_echo_detector_enabled; 203 residual_echo_detector_enabled_ = residual_echo_detector_enabled;
200 noise_suppressor_enabled_ = noise_suppressor_enabled; 204 noise_suppressor_enabled_ = noise_suppressor_enabled;
201 intelligibility_enhancer_enabled_ = intelligibility_enhancer_enabled; 205 intelligibility_enhancer_enabled_ = intelligibility_enhancer_enabled;
202 beamformer_enabled_ = beamformer_enabled; 206 beamformer_enabled_ = beamformer_enabled;
203 adaptive_gain_controller_enabled_ = adaptive_gain_controller_enabled; 207 adaptive_gain_controller_enabled_ = adaptive_gain_controller_enabled;
208 adaptive_gain_controller2_enabled_ = adaptive_gain_controller2_enabled;
204 level_controller_enabled_ = level_controller_enabled; 209 level_controller_enabled_ = level_controller_enabled;
205 echo_canceller3_enabled_ = echo_canceller3_enabled; 210 echo_canceller3_enabled_ = echo_canceller3_enabled;
206 level_estimator_enabled_ = level_estimator_enabled; 211 level_estimator_enabled_ = level_estimator_enabled;
207 voice_activity_detector_enabled_ = voice_activity_detector_enabled; 212 voice_activity_detector_enabled_ = voice_activity_detector_enabled;
208 transient_suppressor_enabled_ = transient_suppressor_enabled; 213 transient_suppressor_enabled_ = transient_suppressor_enabled;
209 } 214 }
210 215
211 changed |= first_update_; 216 changed |= first_update_;
212 first_update_ = false; 217 first_update_ = false;
213 return changed; 218 return changed;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 std::unique_ptr<IntelligibilityEnhancer> intelligibility_enhancer; 272 std::unique_ptr<IntelligibilityEnhancer> intelligibility_enhancer;
268 #endif 273 #endif
269 }; 274 };
270 275
271 struct AudioProcessingImpl::ApmPrivateSubmodules { 276 struct AudioProcessingImpl::ApmPrivateSubmodules {
272 explicit ApmPrivateSubmodules(NonlinearBeamformer* beamformer) 277 explicit ApmPrivateSubmodules(NonlinearBeamformer* beamformer)
273 : beamformer(beamformer) {} 278 : beamformer(beamformer) {}
274 // Accessed internally from capture or during initialization 279 // Accessed internally from capture or during initialization
275 std::unique_ptr<NonlinearBeamformer> beamformer; 280 std::unique_ptr<NonlinearBeamformer> beamformer;
276 std::unique_ptr<AgcManagerDirect> agc_manager; 281 std::unique_ptr<AgcManagerDirect> agc_manager;
282 std::unique_ptr<GainController2> gain_controller2;
277 std::unique_ptr<LowCutFilter> low_cut_filter; 283 std::unique_ptr<LowCutFilter> low_cut_filter;
278 std::unique_ptr<LevelController> level_controller; 284 std::unique_ptr<LevelController> level_controller;
279 std::unique_ptr<ResidualEchoDetector> residual_echo_detector; 285 std::unique_ptr<ResidualEchoDetector> residual_echo_detector;
280 std::unique_ptr<EchoCanceller3> echo_canceller3; 286 std::unique_ptr<EchoCanceller3> echo_canceller3;
281 }; 287 };
282 288
283 AudioProcessing* AudioProcessing::Create() { 289 AudioProcessing* AudioProcessing::Create() {
284 webrtc::Config config; 290 webrtc::Config config;
285 return Create(config, nullptr); 291 return Create(config, nullptr);
286 } 292 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 new LevelEstimatorImpl(&crit_capture_)); 344 new LevelEstimatorImpl(&crit_capture_));
339 public_submodules_->noise_suppression.reset( 345 public_submodules_->noise_suppression.reset(
340 new NoiseSuppressionImpl(&crit_capture_)); 346 new NoiseSuppressionImpl(&crit_capture_));
341 public_submodules_->voice_detection.reset( 347 public_submodules_->voice_detection.reset(
342 new VoiceDetectionImpl(&crit_capture_)); 348 new VoiceDetectionImpl(&crit_capture_));
343 public_submodules_->gain_control_for_experimental_agc.reset( 349 public_submodules_->gain_control_for_experimental_agc.reset(
344 new GainControlForExperimentalAgc( 350 new GainControlForExperimentalAgc(
345 public_submodules_->gain_control.get(), &crit_capture_)); 351 public_submodules_->gain_control.get(), &crit_capture_));
346 private_submodules_->residual_echo_detector.reset( 352 private_submodules_->residual_echo_detector.reset(
347 new ResidualEchoDetector()); 353 new ResidualEchoDetector());
354 private_submodules_->gain_controller2.reset(new GainController2());
348 355
349 // TODO(peah): Move this creation to happen only when the level controller 356 // TODO(peah): Move this creation to happen only when the level controller
350 // is enabled. 357 // is enabled.
351 private_submodules_->level_controller.reset(new LevelController()); 358 private_submodules_->level_controller.reset(new LevelController());
352 } 359 }
353 360
354 SetExtraOptions(config); 361 SetExtraOptions(config);
355 } 362 }
356 363
357 AudioProcessingImpl::~AudioProcessingImpl() { 364 AudioProcessingImpl::~AudioProcessingImpl() {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 InitializeIntelligibility(); 517 InitializeIntelligibility();
511 #endif 518 #endif
512 InitializeLowCutFilter(); 519 InitializeLowCutFilter();
513 public_submodules_->noise_suppression->Initialize(num_proc_channels(), 520 public_submodules_->noise_suppression->Initialize(num_proc_channels(),
514 proc_sample_rate_hz()); 521 proc_sample_rate_hz());
515 public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz()); 522 public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz());
516 public_submodules_->level_estimator->Initialize(); 523 public_submodules_->level_estimator->Initialize();
517 InitializeLevelController(); 524 InitializeLevelController();
518 InitializeResidualEchoDetector(); 525 InitializeResidualEchoDetector();
519 InitializeEchoCanceller3(); 526 InitializeEchoCanceller3();
527 InitializeGainController2();
520 528
521 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 529 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
522 if (debug_dump_.debug_file->is_open()) { 530 if (debug_dump_.debug_file->is_open()) {
523 int err = WriteInitMessage(); 531 int err = WriteInitMessage();
524 if (err != kNoError) { 532 if (err != kNoError) {
525 return err; 533 return err;
526 } 534 }
527 } 535 }
528 #endif 536 #endif
529 537
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 } 666 }
659 667
660 if (config.echo_canceller3.enabled != 668 if (config.echo_canceller3.enabled !=
661 capture_nonlocked_.echo_canceller3_enabled) { 669 capture_nonlocked_.echo_canceller3_enabled) {
662 capture_nonlocked_.echo_canceller3_enabled = 670 capture_nonlocked_.echo_canceller3_enabled =
663 config_.echo_canceller3.enabled; 671 config_.echo_canceller3.enabled;
664 InitializeEchoCanceller3(); 672 InitializeEchoCanceller3();
665 LOG(LS_INFO) << "Echo canceller 3 activated: " 673 LOG(LS_INFO) << "Echo canceller 3 activated: "
666 << capture_nonlocked_.echo_canceller3_enabled; 674 << capture_nonlocked_.echo_canceller3_enabled;
667 } 675 }
676
677 config_ok = GainController2::Validate(config_.gain_controller2);
678 if (!config_ok) {
679 LOG(LS_ERROR) << "AudioProcessing module config error" << std::endl
680 << "gain_controller2: "
peah-webrtc 2017/05/05 20:44:11 What about also adding a LOG(LS_INFO) about that t
AleBzk 2017/05/16 12:38:43 Done.
681 << GainController2::ToString(config_.gain_controller2)
682 << std::endl
683 << "Reverting to default parameter set";
684 config_.gain_controller2 = AudioProcessing::Config::GainController2();
685 }
668 } 686 }
669 687
670 void AudioProcessingImpl::SetExtraOptions(const webrtc::Config& config) { 688 void AudioProcessingImpl::SetExtraOptions(const webrtc::Config& config) {
671 // Run in a single-threaded manner when setting the extra options. 689 // Run in a single-threaded manner when setting the extra options.
672 rtc::CritScope cs_render(&crit_render_); 690 rtc::CritScope cs_render(&crit_render_);
673 rtc::CritScope cs_capture(&crit_capture_); 691 rtc::CritScope cs_capture(&crit_capture_);
674 692
675 public_submodules_->echo_cancellation->SetExtraOptions(config); 693 public_submodules_->echo_cancellation->SetExtraOptions(config);
676 694
677 if (capture_.transient_suppressor_enabled != 695 if (capture_.transient_suppressor_enabled !=
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 bool AudioProcessingImpl::UpdateActiveSubmoduleStates() { 1708 bool AudioProcessingImpl::UpdateActiveSubmoduleStates() {
1691 return submodule_states_.Update( 1709 return submodule_states_.Update(
1692 config_.high_pass_filter.enabled, 1710 config_.high_pass_filter.enabled,
1693 public_submodules_->echo_cancellation->is_enabled(), 1711 public_submodules_->echo_cancellation->is_enabled(),
1694 public_submodules_->echo_control_mobile->is_enabled(), 1712 public_submodules_->echo_control_mobile->is_enabled(),
1695 config_.residual_echo_detector.enabled, 1713 config_.residual_echo_detector.enabled,
1696 public_submodules_->noise_suppression->is_enabled(), 1714 public_submodules_->noise_suppression->is_enabled(),
1697 capture_nonlocked_.intelligibility_enabled, 1715 capture_nonlocked_.intelligibility_enabled,
1698 capture_nonlocked_.beamformer_enabled, 1716 capture_nonlocked_.beamformer_enabled,
1699 public_submodules_->gain_control->is_enabled(), 1717 public_submodules_->gain_control->is_enabled(),
1718 capture_nonlocked_.adaptive_gain_controller2_enabled,
1700 capture_nonlocked_.level_controller_enabled, 1719 capture_nonlocked_.level_controller_enabled,
1701 capture_nonlocked_.echo_canceller3_enabled, 1720 capture_nonlocked_.echo_canceller3_enabled,
1702 public_submodules_->voice_detection->is_enabled(), 1721 public_submodules_->voice_detection->is_enabled(),
1703 public_submodules_->level_estimator->is_enabled(), 1722 public_submodules_->level_estimator->is_enabled(),
1704 capture_.transient_suppressor_enabled); 1723 capture_.transient_suppressor_enabled);
1705 } 1724 }
1706 1725
1707 1726
1708 void AudioProcessingImpl::InitializeTransient() { 1727 void AudioProcessingImpl::InitializeTransient() {
1709 if (capture_.transient_suppressor_enabled) { 1728 if (capture_.transient_suppressor_enabled) {
(...skipping 30 matching lines...) Expand all
1740 } 1759 }
1741 1760
1742 void AudioProcessingImpl::InitializeLowCutFilter() { 1761 void AudioProcessingImpl::InitializeLowCutFilter() {
1743 if (config_.high_pass_filter.enabled) { 1762 if (config_.high_pass_filter.enabled) {
1744 private_submodules_->low_cut_filter.reset( 1763 private_submodules_->low_cut_filter.reset(
1745 new LowCutFilter(num_proc_channels(), proc_sample_rate_hz())); 1764 new LowCutFilter(num_proc_channels(), proc_sample_rate_hz()));
1746 } else { 1765 } else {
1747 private_submodules_->low_cut_filter.reset(); 1766 private_submodules_->low_cut_filter.reset();
1748 } 1767 }
1749 } 1768 }
1769
1750 void AudioProcessingImpl::InitializeEchoCanceller3() { 1770 void AudioProcessingImpl::InitializeEchoCanceller3() {
1751 if (capture_nonlocked_.echo_canceller3_enabled) { 1771 if (capture_nonlocked_.echo_canceller3_enabled) {
1752 private_submodules_->echo_canceller3.reset( 1772 private_submodules_->echo_canceller3.reset(
1753 new EchoCanceller3(proc_sample_rate_hz(), true)); 1773 new EchoCanceller3(proc_sample_rate_hz(), true));
1754 } else { 1774 } else {
1755 private_submodules_->echo_canceller3.reset(); 1775 private_submodules_->echo_canceller3.reset();
1756 } 1776 }
1757 } 1777 }
1758 1778
1779 void AudioProcessingImpl::InitializeGainController2() {
1780 if (capture_nonlocked_.adaptive_gain_controller2_enabled) {
1781 private_submodules_->gain_controller2.reset(new GainController2());
1782 } else {
1783 private_submodules_->gain_controller2.reset();
1784 }
1785 }
1786
1759 void AudioProcessingImpl::InitializeLevelController() { 1787 void AudioProcessingImpl::InitializeLevelController() {
1760 private_submodules_->level_controller->Initialize(proc_sample_rate_hz()); 1788 private_submodules_->level_controller->Initialize(proc_sample_rate_hz());
1761 } 1789 }
1762 1790
1763 void AudioProcessingImpl::InitializeResidualEchoDetector() { 1791 void AudioProcessingImpl::InitializeResidualEchoDetector() {
1764 private_submodules_->residual_echo_detector->Initialize(); 1792 private_submodules_->residual_echo_detector->Initialize();
1765 } 1793 }
1766 1794
1767 void AudioProcessingImpl::MaybeUpdateHistograms() { 1795 void AudioProcessingImpl::MaybeUpdateHistograms() {
1768 static const int kMinDiffDelayMs = 60; 1796 static const int kMinDiffDelayMs = 60;
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
2003 previous_agc_level(0), 2031 previous_agc_level(0),
2004 echo_path_gain_change(false) {} 2032 echo_path_gain_change(false) {}
2005 2033
2006 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; 2034 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default;
2007 2035
2008 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; 2036 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default;
2009 2037
2010 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; 2038 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default;
2011 2039
2012 } // namespace webrtc 2040 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698