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

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

Issue 2995043002: AGC2 dummy module: fixed gain param, APM integration, audioproc_f adaptation (Closed)
Patch Set: UT fix Created 3 years, 4 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
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "webrtc/system_wrappers/include/file_wrapper.h" 47 #include "webrtc/system_wrappers/include/file_wrapper.h"
48 #include "webrtc/system_wrappers/include/metrics.h" 48 #include "webrtc/system_wrappers/include/metrics.h"
49 49
50 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 50 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
51 // Files generated at build-time by the protobuf compiler. 51 // Files generated at build-time by the protobuf compiler.
52 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD 52 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
53 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h" 53 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h"
54 #else 54 #else
55 #include "webrtc/modules/audio_processing/debug.pb.h" 55 #include "webrtc/modules/audio_processing/debug.pb.h"
56 #endif 56 #endif
57 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 57 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
AleBzk 2017/09/14 09:21:56 This comes from a merge. Please double-check all t
58 58
59 // Check to verify that the define for the intelligibility enhancer is properly 59 // Check to verify that the define for the intelligibility enhancer is properly
60 // set. 60 // set.
61 #if !defined(WEBRTC_INTELLIGIBILITY_ENHANCER) || \ 61 #if !defined(WEBRTC_INTELLIGIBILITY_ENHANCER) || \
62 (WEBRTC_INTELLIGIBILITY_ENHANCER != 0 && \ 62 (WEBRTC_INTELLIGIBILITY_ENHANCER != 0 && \
63 WEBRTC_INTELLIGIBILITY_ENHANCER != 1) 63 WEBRTC_INTELLIGIBILITY_ENHANCER != 1)
64 #error "Set WEBRTC_INTELLIGIBILITY_ENHANCER to either 0 or 1" 64 #error "Set WEBRTC_INTELLIGIBILITY_ENHANCER to either 0 or 1"
65 #endif 65 #endif
66 66
67 #define RETURN_ON_ERR(expr) \ 67 #define RETURN_ON_ERR(expr) \
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandProcessingActive() 252 bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandProcessingActive()
253 const { 253 const {
254 return low_cut_filter_enabled_ || echo_canceller_enabled_ || 254 return low_cut_filter_enabled_ || echo_canceller_enabled_ ||
255 mobile_echo_controller_enabled_ || noise_suppressor_enabled_ || 255 mobile_echo_controller_enabled_ || noise_suppressor_enabled_ ||
256 beamformer_enabled_ || adaptive_gain_controller_enabled_ || 256 beamformer_enabled_ || adaptive_gain_controller_enabled_ ||
257 echo_canceller3_enabled_; 257 echo_canceller3_enabled_;
258 } 258 }
259 259
260 bool AudioProcessingImpl::ApmSubmoduleStates::CaptureFullBandProcessingActive() 260 bool AudioProcessingImpl::ApmSubmoduleStates::CaptureFullBandProcessingActive()
261 const { 261 const {
262 return level_controller_enabled_; 262 return level_controller_enabled_ && gain_controller2_enabled_;
aleloi 2017/08/15 14:34:03 I've forgotten how the APM monster works again. Wh
263 } 263 }
264 264
265 bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandSubModulesActive() 265 bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandSubModulesActive()
266 const { 266 const {
267 return RenderMultiBandProcessingActive() || echo_canceller_enabled_ || 267 return RenderMultiBandProcessingActive() || echo_canceller_enabled_ ||
268 mobile_echo_controller_enabled_ || adaptive_gain_controller_enabled_ || 268 mobile_echo_controller_enabled_ || adaptive_gain_controller_enabled_ ||
269 echo_canceller3_enabled_; 269 echo_canceller3_enabled_;
270 } 270 }
271 271
272 bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandProcessingActive() 272 bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandProcessingActive()
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 704
705 if (config.echo_canceller3.enabled != 705 if (config.echo_canceller3.enabled !=
706 capture_nonlocked_.echo_canceller3_enabled) { 706 capture_nonlocked_.echo_canceller3_enabled) {
707 capture_nonlocked_.echo_canceller3_enabled = 707 capture_nonlocked_.echo_canceller3_enabled =
708 config_.echo_canceller3.enabled; 708 config_.echo_canceller3.enabled;
709 InitializeEchoCanceller3(); 709 InitializeEchoCanceller3();
710 LOG(LS_INFO) << "Echo canceller 3 activated: " 710 LOG(LS_INFO) << "Echo canceller 3 activated: "
711 << capture_nonlocked_.echo_canceller3_enabled; 711 << capture_nonlocked_.echo_canceller3_enabled;
712 } 712 }
713 713
714 config_ok = GainController2::Validate(config_.gain_controller2); 714 if (!GainController2::Validate(config_.gain_controller2)) {
715 if (!config_ok) {
716 LOG(LS_ERROR) << "AudioProcessing module config error" << std::endl 715 LOG(LS_ERROR) << "AudioProcessing module config error" << std::endl
717 << "gain_controller2: " 716 << "Gain Controller 2: "
718 << GainController2::ToString(config_.gain_controller2) 717 << GainController2::ToString(config_.gain_controller2)
719 << std::endl 718 << std::endl
720 << "Reverting to default parameter set"; 719 << "Reverting to default parameter set";
721 config_.gain_controller2 = AudioProcessing::Config::GainController2(); 720 config_.gain_controller2 = AudioProcessing::Config::GainController2();
722 } 721 }
723 722 InitializeGainController2();
724 if (config.gain_controller2.enabled != 723 LOG(LS_INFO) << "Gain Controller 2 activated: "
725 capture_nonlocked_.gain_controller2_enabled) { 724 << config_.gain_controller2.enabled;
726 capture_nonlocked_.gain_controller2_enabled =
727 config_.gain_controller2.enabled;
728 InitializeGainController2();
729 LOG(LS_INFO) << "Gain controller 2 activated: "
730 << capture_nonlocked_.gain_controller2_enabled;
731 }
732 } 725 }
733 726
734 void AudioProcessingImpl::SetExtraOptions(const webrtc::Config& config) { 727 void AudioProcessingImpl::SetExtraOptions(const webrtc::Config& config) {
735 // Run in a single-threaded manner when setting the extra options. 728 // Run in a single-threaded manner when setting the extra options.
736 rtc::CritScope cs_render(&crit_render_); 729 rtc::CritScope cs_render(&crit_render_);
737 rtc::CritScope cs_capture(&crit_capture_); 730 rtc::CritScope cs_capture(&crit_capture_);
738 731
739 public_submodules_->echo_cancellation->SetExtraOptions(config); 732 public_submodules_->echo_cancellation->SetExtraOptions(config);
740 733
741 if (capture_.transient_suppressor_enabled != 734 if (capture_.transient_suppressor_enabled !=
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 1352
1360 public_submodules_->transient_suppressor->Suppress( 1353 public_submodules_->transient_suppressor->Suppress(
1361 capture_buffer->channels_f()[0], capture_buffer->num_frames(), 1354 capture_buffer->channels_f()[0], capture_buffer->num_frames(),
1362 capture_buffer->num_channels(), 1355 capture_buffer->num_channels(),
1363 capture_buffer->split_bands_const_f(0)[kBand0To8kHz], 1356 capture_buffer->split_bands_const_f(0)[kBand0To8kHz],
1364 capture_buffer->num_frames_per_band(), capture_buffer->keyboard_data(), 1357 capture_buffer->num_frames_per_band(), capture_buffer->keyboard_data(),
1365 capture_buffer->num_keyboard_frames(), voice_probability, 1358 capture_buffer->num_keyboard_frames(), voice_probability,
1366 capture_.key_pressed); 1359 capture_.key_pressed);
1367 } 1360 }
1368 1361
1369 if (capture_nonlocked_.gain_controller2_enabled) { 1362 if (config_.gain_controller2.enabled) {
1370 private_submodules_->gain_controller2->Process(capture_buffer); 1363 private_submodules_->gain_controller2->Process(capture_buffer);
1371 } 1364 }
1372 1365
1373 if (capture_nonlocked_.level_controller_enabled) { 1366 if (capture_nonlocked_.level_controller_enabled) {
1374 private_submodules_->level_controller->Process(capture_buffer); 1367 private_submodules_->level_controller->Process(capture_buffer);
1375 } 1368 }
1376 1369
1377 // The level estimator operates on the recombined data. 1370 // The level estimator operates on the recombined data.
1378 public_submodules_->level_estimator->ProcessStream(capture_buffer); 1371 public_submodules_->level_estimator->ProcessStream(capture_buffer);
1379 1372
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 bool AudioProcessingImpl::UpdateActiveSubmoduleStates() { 1813 bool AudioProcessingImpl::UpdateActiveSubmoduleStates() {
1821 return submodule_states_.Update( 1814 return submodule_states_.Update(
1822 config_.high_pass_filter.enabled, 1815 config_.high_pass_filter.enabled,
1823 public_submodules_->echo_cancellation->is_enabled(), 1816 public_submodules_->echo_cancellation->is_enabled(),
1824 public_submodules_->echo_control_mobile->is_enabled(), 1817 public_submodules_->echo_control_mobile->is_enabled(),
1825 config_.residual_echo_detector.enabled, 1818 config_.residual_echo_detector.enabled,
1826 public_submodules_->noise_suppression->is_enabled(), 1819 public_submodules_->noise_suppression->is_enabled(),
1827 capture_nonlocked_.intelligibility_enabled, 1820 capture_nonlocked_.intelligibility_enabled,
1828 capture_nonlocked_.beamformer_enabled, 1821 capture_nonlocked_.beamformer_enabled,
1829 public_submodules_->gain_control->is_enabled(), 1822 public_submodules_->gain_control->is_enabled(),
1830 capture_nonlocked_.gain_controller2_enabled, 1823 config_.gain_controller2.enabled,
1831 capture_nonlocked_.level_controller_enabled, 1824 capture_nonlocked_.level_controller_enabled,
1832 capture_nonlocked_.echo_canceller3_enabled, 1825 capture_nonlocked_.echo_canceller3_enabled,
1833 public_submodules_->voice_detection->is_enabled(), 1826 public_submodules_->voice_detection->is_enabled(),
1834 public_submodules_->level_estimator->is_enabled(), 1827 public_submodules_->level_estimator->is_enabled(),
1835 capture_.transient_suppressor_enabled); 1828 capture_.transient_suppressor_enabled);
1836 } 1829 }
1837 1830
1838 1831
1839 void AudioProcessingImpl::InitializeTransient() { 1832 void AudioProcessingImpl::InitializeTransient() {
1840 if (capture_.transient_suppressor_enabled) { 1833 if (capture_.transient_suppressor_enabled) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1882 void AudioProcessingImpl::InitializeEchoCanceller3() { 1875 void AudioProcessingImpl::InitializeEchoCanceller3() {
1883 if (capture_nonlocked_.echo_canceller3_enabled) { 1876 if (capture_nonlocked_.echo_canceller3_enabled) {
1884 private_submodules_->echo_canceller3.reset(new EchoCanceller3( 1877 private_submodules_->echo_canceller3.reset(new EchoCanceller3(
1885 config_.echo_canceller3, proc_sample_rate_hz(), true)); 1878 config_.echo_canceller3, proc_sample_rate_hz(), true));
1886 } else { 1879 } else {
1887 private_submodules_->echo_canceller3.reset(); 1880 private_submodules_->echo_canceller3.reset();
1888 } 1881 }
1889 } 1882 }
1890 1883
1891 void AudioProcessingImpl::InitializeGainController2() { 1884 void AudioProcessingImpl::InitializeGainController2() {
1892 if (capture_nonlocked_.gain_controller2_enabled) { 1885 if (config_.gain_controller2.enabled) {
1886 // TODO(alessiob): If GainController2 was already enabled and the fixed gain
1887 // to apply hasn't changed do not re-initialize.
1893 private_submodules_->gain_controller2.reset( 1888 private_submodules_->gain_controller2.reset(
1894 new GainController2(proc_sample_rate_hz())); 1889 new GainController2(config_.gain_controller2.fixed_gain_db));
1890 private_submodules_->gain_controller2->Initialize(proc_sample_rate_hz());
aleloi 2017/08/15 14:34:03 proc_sample_rate_hz() is the right rate, right? So
AleBzk 2017/09/14 09:21:56 Thanks for your concern. Yes, I double-checked, it
1895 } else { 1891 } else {
1896 private_submodules_->gain_controller2.reset(); 1892 private_submodules_->gain_controller2.reset();
1897 } 1893 }
1898 } 1894 }
1899 1895
1900 void AudioProcessingImpl::InitializeLevelController() { 1896 void AudioProcessingImpl::InitializeLevelController() {
1901 private_submodules_->level_controller->Initialize(proc_sample_rate_hz()); 1897 private_submodules_->level_controller->Initialize(proc_sample_rate_hz());
1902 } 1898 }
1903 1899
1904 void AudioProcessingImpl::InitializeResidualEchoDetector() { 1900 void AudioProcessingImpl::InitializeResidualEchoDetector() {
1905 private_submodules_->residual_echo_detector->Initialize(); 1901 private_submodules_->residual_echo_detector->Initialize();
1906 } 1902 }
1907 1903
1908 void AudioProcessingImpl::MaybeUpdateHistograms() { 1904 void AudioProcessingImpl::MaybeUpdateHistograms() {
1909 static const int kMinDiffDelayMs = 60; 1905 static const int kMinDiffDelayMs = 60;
1910 1906
1911 if (echo_cancellation()->is_enabled()) { 1907 if (echo_cancellation()->is_enabled()) {
1912 // Activate delay_jumps_ counters if we know echo_cancellation is runnning. 1908 // Activate delay_jumps_ counters if we know echo_cancellation is runnning.
AleBzk 2017/09/14 09:21:56 Typo.
1913 // If a stream has echo we know that the echo_cancellation is in process. 1909 // If a stream has echo we know that the echo_cancellation is in process.
1914 if (capture_.stream_delay_jumps == -1 && 1910 if (capture_.stream_delay_jumps == -1 &&
1915 echo_cancellation()->stream_has_echo()) { 1911 echo_cancellation()->stream_has_echo()) {
1916 capture_.stream_delay_jumps = 0; 1912 capture_.stream_delay_jumps = 0;
1917 } 1913 }
1918 if (capture_.aec_system_delay_jumps == -1 && 1914 if (capture_.aec_system_delay_jumps == -1 &&
1919 echo_cancellation()->stream_has_echo()) { 1915 echo_cancellation()->stream_has_echo()) {
1920 capture_.aec_system_delay_jumps = 0; 1916 capture_.aec_system_delay_jumps = 0;
1921 } 1917 }
1922 1918
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1988 // descriptions for other submodules. 1984 // descriptions for other submodules.
1989 if (capture_nonlocked_.level_controller_enabled) { 1985 if (capture_nonlocked_.level_controller_enabled) {
1990 experiments_description += "LevelController;"; 1986 experiments_description += "LevelController;";
1991 } 1987 }
1992 if (constants_.agc_clipped_level_min != kClippedLevelMin) { 1988 if (constants_.agc_clipped_level_min != kClippedLevelMin) {
1993 experiments_description += "AgcClippingLevelExperiment;"; 1989 experiments_description += "AgcClippingLevelExperiment;";
1994 } 1990 }
1995 if (capture_nonlocked_.echo_canceller3_enabled) { 1991 if (capture_nonlocked_.echo_canceller3_enabled) {
1996 experiments_description += "EchoCanceller3;"; 1992 experiments_description += "EchoCanceller3;";
1997 } 1993 }
1994 if (config_.gain_controller2.enabled) {
1995 experiments_description += "GainController2;";
1996 }
1998 1997
1999 InternalAPMConfig apm_config; 1998 InternalAPMConfig apm_config;
2000 1999
2001 apm_config.aec_enabled = public_submodules_->echo_cancellation->is_enabled(); 2000 apm_config.aec_enabled = public_submodules_->echo_cancellation->is_enabled();
2002 apm_config.aec_delay_agnostic_enabled = 2001 apm_config.aec_delay_agnostic_enabled =
2003 public_submodules_->echo_cancellation->is_delay_agnostic_enabled(); 2002 public_submodules_->echo_cancellation->is_delay_agnostic_enabled();
2004 apm_config.aec_drift_compensation_enabled = 2003 apm_config.aec_drift_compensation_enabled =
2005 public_submodules_->echo_cancellation->is_drift_compensation_enabled(); 2004 public_submodules_->echo_cancellation->is_drift_compensation_enabled();
2006 apm_config.aec_extended_filter_enabled = 2005 apm_config.aec_extended_filter_enabled =
2007 public_submodules_->echo_cancellation->is_extended_filter_enabled(); 2006 public_submodules_->echo_cancellation->is_extended_filter_enabled();
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
2258 split_rate(kSampleRate16kHz), 2257 split_rate(kSampleRate16kHz),
2259 echo_path_gain_change(false) {} 2258 echo_path_gain_change(false) {}
2260 2259
2261 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; 2260 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default;
2262 2261
2263 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; 2262 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default;
2264 2263
2265 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; 2264 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default;
2266 2265
2267 } // namespace webrtc 2266 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698