Skip to content

Commit 8271d04

Browse files
peahCommit bot
peah
authored and
Commit bot
committed
This CL introduces the new functionality for setting
the APM parameters to the high-pass filter. The introduction will be done in three steps: 1) This CL which introduces the new scheme and changes the code in webrtcvoiceengine.cc to use it. 2) Introduce the scheme into upstream code. 3) Remove the HighPassFilter interface in APM. BUG=webrtc::6220, webrtc::6296, webrtc::6297, webrtc::6181, webrtc::5298 Review-Url: https://codereview.webrtc.org/2415403002 Cr-Commit-Position: refs/heads/master@{#15197}
1 parent 30a12fb commit 8271d04

17 files changed

+191
-172
lines changed

webrtc/media/engine/webrtcvoiceengine.cc

+4-8
Original file line numberDiff line numberDiff line change
@@ -825,14 +825,6 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) {
825825
}
826826
}
827827

828-
if (options.highpass_filter) {
829-
LOG(LS_INFO) << "High pass filter enabled? " << *options.highpass_filter;
830-
if (voep->EnableHighPassFilter(*options.highpass_filter) == -1) {
831-
LOG_RTCERR1(SetHighpassFilterStatus, *options.highpass_filter);
832-
return false;
833-
}
834-
}
835-
836828
if (options.stereo_swapping) {
837829
LOG(LS_INFO) << "Stereo swapping enabled? " << *options.stereo_swapping;
838830
voep->EnableStereoChannelSwapping(*options.stereo_swapping);
@@ -920,6 +912,10 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) {
920912
}
921913
}
922914

915+
if (options.highpass_filter) {
916+
apm_config_.high_pass_filter.enabled = *options.highpass_filter;
917+
}
918+
923919
apm()->SetExtraOptions(config);
924920
apm()->ApplyConfig(apm_config_);
925921

webrtc/media/engine/webrtcvoiceengine.h

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ class WebRtcVoiceEngine final : public webrtc::TraceCallback {
8989
// Stops AEC dump.
9090
void StopAecDump();
9191

92+
const webrtc::AudioProcessing::Config& GetApmConfigForTest() const {
93+
return apm_config_;
94+
}
95+
9296
private:
9397
// Every option that is "set" will be applied. Every option not "set" will be
9498
// ignored. This allows us to selectively turn on and off different options

webrtc/media/engine/webrtcvoiceengine_unittest.cc

+9-12
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,10 @@ class WebRtcVoiceEngineTestFake : public testing::Test {
571571
}
572572
}
573573

574+
bool IsHighPassFilterEnabled() {
575+
return engine_->GetApmConfigForTest().high_pass_filter.enabled;
576+
}
577+
574578
protected:
575579
StrictMock<webrtc::test::MockAudioDeviceModule> adm_;
576580
StrictMock<webrtc::test::MockAudioProcessing> apm_;
@@ -2793,15 +2797,13 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
27932797
webrtc::AgcConfig agc_config;
27942798
bool ns_enabled;
27952799
webrtc::NsModes ns_mode;
2796-
bool highpass_filter_enabled;
27972800
bool stereo_swapping_enabled;
27982801
bool typing_detection_enabled;
27992802
voe_.GetEcStatus(ec_enabled, ec_mode);
28002803
voe_.GetAecmMode(aecm_mode, cng_enabled);
28012804
voe_.GetAgcStatus(agc_enabled, agc_mode);
28022805
voe_.GetAgcConfig(agc_config);
28032806
voe_.GetNsStatus(ns_enabled, ns_mode);
2804-
highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
28052807
stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
28062808
voe_.GetTypingDetectionStatus(typing_detection_enabled);
28072809
EXPECT_TRUE(ec_enabled);
@@ -2810,7 +2812,7 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
28102812
EXPECT_TRUE(agc_enabled);
28112813
EXPECT_EQ(0, agc_config.targetLeveldBOv);
28122814
EXPECT_TRUE(ns_enabled);
2813-
EXPECT_TRUE(highpass_filter_enabled);
2815+
EXPECT_TRUE(IsHighPassFilterEnabled());
28142816
EXPECT_FALSE(stereo_swapping_enabled);
28152817
EXPECT_TRUE(typing_detection_enabled);
28162818
EXPECT_EQ(ec_mode, webrtc::kEcConference);
@@ -2826,7 +2828,6 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
28262828
voe_.GetAgcStatus(agc_enabled, agc_mode);
28272829
voe_.GetAgcConfig(agc_config);
28282830
voe_.GetNsStatus(ns_enabled, ns_mode);
2829-
highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
28302831
stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
28312832
voe_.GetTypingDetectionStatus(typing_detection_enabled);
28322833
EXPECT_TRUE(ec_enabled);
@@ -2835,7 +2836,7 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
28352836
EXPECT_TRUE(agc_enabled);
28362837
EXPECT_EQ(0, agc_config.targetLeveldBOv);
28372838
EXPECT_TRUE(ns_enabled);
2838-
EXPECT_TRUE(highpass_filter_enabled);
2839+
EXPECT_TRUE(IsHighPassFilterEnabled());
28392840
EXPECT_FALSE(stereo_swapping_enabled);
28402841
EXPECT_TRUE(typing_detection_enabled);
28412842
EXPECT_EQ(ec_mode, webrtc::kEcConference);
@@ -2858,15 +2859,14 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
28582859
voe_.GetAgcStatus(agc_enabled, agc_mode);
28592860
voe_.GetAgcConfig(agc_config);
28602861
voe_.GetNsStatus(ns_enabled, ns_mode);
2861-
highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
28622862
stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
28632863
voe_.GetTypingDetectionStatus(typing_detection_enabled);
28642864
EXPECT_TRUE(ec_enabled);
28652865
EXPECT_TRUE(voe_.ec_metrics_enabled());
28662866
EXPECT_TRUE(agc_enabled);
28672867
EXPECT_EQ(0, agc_config.targetLeveldBOv);
28682868
EXPECT_TRUE(ns_enabled);
2869-
EXPECT_TRUE(highpass_filter_enabled);
2869+
EXPECT_TRUE(IsHighPassFilterEnabled());
28702870
EXPECT_FALSE(stereo_swapping_enabled);
28712871
EXPECT_TRUE(typing_detection_enabled);
28722872
EXPECT_EQ(ec_mode, webrtc::kEcConference);
@@ -2919,11 +2919,10 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
29192919
send_parameters_.options.stereo_swapping = rtc::Optional<bool>(true);
29202920
SetSendParameters(send_parameters_);
29212921
voe_.GetNsStatus(ns_enabled, ns_mode);
2922-
highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
29232922
stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
29242923
voe_.GetTypingDetectionStatus(typing_detection_enabled);
29252924
EXPECT_FALSE(ns_enabled);
2926-
EXPECT_FALSE(highpass_filter_enabled);
2925+
EXPECT_FALSE(IsHighPassFilterEnabled());
29272926
EXPECT_FALSE(typing_detection_enabled);
29282927
EXPECT_TRUE(stereo_swapping_enabled);
29292928

@@ -2946,20 +2945,18 @@ TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) {
29462945
webrtc::AgcModes agc_mode;
29472946
bool ns_enabled;
29482947
webrtc::NsModes ns_mode;
2949-
bool highpass_filter_enabled;
29502948
bool stereo_swapping_enabled;
29512949
bool typing_detection_enabled;
29522950

29532951
voe_.GetEcStatus(ec_enabled, ec_mode);
29542952
voe_.GetAgcStatus(agc_enabled, agc_mode);
29552953
voe_.GetNsStatus(ns_enabled, ns_mode);
2956-
highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
29572954
stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
29582955
voe_.GetTypingDetectionStatus(typing_detection_enabled);
29592956
EXPECT_TRUE(ec_enabled);
29602957
EXPECT_TRUE(agc_enabled);
29612958
EXPECT_TRUE(ns_enabled);
2962-
EXPECT_TRUE(highpass_filter_enabled);
2959+
EXPECT_TRUE(IsHighPassFilterEnabled());
29632960
EXPECT_TRUE(typing_detection_enabled);
29642961
EXPECT_FALSE(stereo_swapping_enabled);
29652962
}

webrtc/modules/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,9 @@ if (rtc_include_tests) {
600600
"audio_processing/echo_detector/mean_variance_estimator_unittest.cc",
601601
"audio_processing/echo_detector/normalized_covariance_estimator_unittest.cc",
602602
"audio_processing/gain_control_unittest.cc",
603-
"audio_processing/high_pass_filter_unittest.cc",
604603
"audio_processing/level_controller/level_controller_unittest.cc",
605604
"audio_processing/level_estimator_unittest.cc",
605+
"audio_processing/low_cut_filter_unittest.cc",
606606
"audio_processing/noise_suppression_unittest.cc",
607607
"audio_processing/residual_echo_detector_unittest.cc",
608608
"audio_processing/test/bitexactness_tools.cc",

webrtc/modules/audio_processing/BUILD.gn

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ rtc_static_library("audio_processing") {
7171
"gain_control_for_experimental_agc.h",
7272
"gain_control_impl.cc",
7373
"gain_control_impl.h",
74-
"high_pass_filter_impl.cc",
75-
"high_pass_filter_impl.h",
7674
"include/audio_processing.cc",
7775
"include/audio_processing.h",
7876
"include/config.cc",
@@ -102,6 +100,8 @@ rtc_static_library("audio_processing") {
102100
"level_estimator_impl.h",
103101
"logging/apm_data_dumper.cc",
104102
"logging/apm_data_dumper.h",
103+
"low_cut_filter.cc",
104+
"low_cut_filter.h",
105105
"noise_suppression_impl.cc",
106106
"noise_suppression_impl.h",
107107
"render_queue_item_verifier.h",

webrtc/modules/audio_processing/audio_processing_impl.cc

+66-15
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
#include "webrtc/modules/audio_processing/echo_control_mobile_impl.h"
2929
#include "webrtc/modules/audio_processing/gain_control_for_experimental_agc.h"
3030
#include "webrtc/modules/audio_processing/gain_control_impl.h"
31-
#include "webrtc/modules/audio_processing/high_pass_filter_impl.h"
3231
#if WEBRTC_INTELLIGIBILITY_ENHANCER
3332
#include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.h"
3433
#endif
3534
#include "webrtc/modules/audio_processing/level_controller/level_controller.h"
3635
#include "webrtc/modules/audio_processing/level_estimator_impl.h"
36+
#include "webrtc/modules/audio_processing/low_cut_filter.h"
3737
#include "webrtc/modules/audio_processing/noise_suppression_impl.h"
3838
#include "webrtc/modules/audio_processing/residual_echo_detector.h"
3939
#include "webrtc/modules/audio_processing/transient/transient_suppressor.h"
@@ -127,6 +127,29 @@ static const size_t kMaxAllowedValuesOfSamplesPerFrame = 160;
127127
// reverse and forward call numbers.
128128
static const size_t kMaxNumFramesToBuffer = 100;
129129

130+
class HighPassFilterImpl : public HighPassFilter {
131+
public:
132+
explicit HighPassFilterImpl(AudioProcessingImpl* apm) : apm_(apm) {}
133+
~HighPassFilterImpl() override = default;
134+
135+
// HighPassFilter implementation.
136+
int Enable(bool enable) override {
137+
apm_->MutateConfig([enable](AudioProcessing::Config* config) {
138+
config->high_pass_filter.enabled = enable;
139+
});
140+
141+
return AudioProcessing::kNoError;
142+
}
143+
144+
bool is_enabled() const override {
145+
return apm_->GetConfig().high_pass_filter.enabled;
146+
}
147+
148+
private:
149+
AudioProcessingImpl* apm_;
150+
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(HighPassFilterImpl);
151+
};
152+
130153
} // namespace
131154

132155
// Throughout webrtc, it's assumed that success is represented by zero.
@@ -135,7 +158,7 @@ static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero");
135158
AudioProcessingImpl::ApmSubmoduleStates::ApmSubmoduleStates() {}
136159

137160
bool AudioProcessingImpl::ApmSubmoduleStates::Update(
138-
bool high_pass_filter_enabled,
161+
bool low_cut_filter_enabled,
139162
bool echo_canceller_enabled,
140163
bool mobile_echo_controller_enabled,
141164
bool residual_echo_detector_enabled,
@@ -148,7 +171,7 @@ bool AudioProcessingImpl::ApmSubmoduleStates::Update(
148171
bool level_estimator_enabled,
149172
bool transient_suppressor_enabled) {
150173
bool changed = false;
151-
changed |= (high_pass_filter_enabled != high_pass_filter_enabled_);
174+
changed |= (low_cut_filter_enabled != low_cut_filter_enabled_);
152175
changed |= (echo_canceller_enabled != echo_canceller_enabled_);
153176
changed |=
154177
(mobile_echo_controller_enabled != mobile_echo_controller_enabled_);
@@ -166,7 +189,7 @@ bool AudioProcessingImpl::ApmSubmoduleStates::Update(
166189
(voice_activity_detector_enabled != voice_activity_detector_enabled_);
167190
changed |= (transient_suppressor_enabled != transient_suppressor_enabled_);
168191
if (changed) {
169-
high_pass_filter_enabled_ = high_pass_filter_enabled;
192+
low_cut_filter_enabled_ = low_cut_filter_enabled;
170193
echo_canceller_enabled_ = echo_canceller_enabled;
171194
mobile_echo_controller_enabled_ = mobile_echo_controller_enabled;
172195
residual_echo_detector_enabled_ = residual_echo_detector_enabled;
@@ -199,7 +222,7 @@ bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandSubModulesActive()
199222

200223
bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandProcessingActive()
201224
const {
202-
return high_pass_filter_enabled_ || echo_canceller_enabled_ ||
225+
return low_cut_filter_enabled_ || echo_canceller_enabled_ ||
203226
mobile_echo_controller_enabled_ || noise_suppressor_enabled_ ||
204227
beamformer_enabled_ || adaptive_gain_controller_enabled_;
205228
}
@@ -226,7 +249,6 @@ struct AudioProcessingImpl::ApmPublicSubmodules {
226249
std::unique_ptr<EchoCancellationImpl> echo_cancellation;
227250
std::unique_ptr<EchoControlMobileImpl> echo_control_mobile;
228251
std::unique_ptr<GainControlImpl> gain_control;
229-
std::unique_ptr<HighPassFilterImpl> high_pass_filter;
230252
std::unique_ptr<LevelEstimatorImpl> level_estimator;
231253
std::unique_ptr<NoiseSuppressionImpl> noise_suppression;
232254
std::unique_ptr<VoiceDetectionImpl> voice_detection;
@@ -246,6 +268,7 @@ struct AudioProcessingImpl::ApmPrivateSubmodules {
246268
// Accessed internally from capture or during initialization
247269
std::unique_ptr<NonlinearBeamformer> beamformer;
248270
std::unique_ptr<AgcManagerDirect> agc_manager;
271+
std::unique_ptr<LowCutFilter> low_cut_filter;
249272
std::unique_ptr<LevelController> level_controller;
250273
std::unique_ptr<ResidualEchoDetector> residual_echo_detector;
251274
};
@@ -275,7 +298,8 @@ AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config)
275298

276299
AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config,
277300
NonlinearBeamformer* beamformer)
278-
: public_submodules_(new ApmPublicSubmodules()),
301+
: high_pass_filter_impl_(new HighPassFilterImpl(this)),
302+
public_submodules_(new ApmPublicSubmodules()),
279303
private_submodules_(new ApmPrivateSubmodules(beamformer)),
280304
constants_(config.Get<ExperimentalAgc>().startup_min_volume,
281305
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
@@ -302,8 +326,6 @@ AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config,
302326
new EchoControlMobileImpl(&crit_render_, &crit_capture_));
303327
public_submodules_->gain_control.reset(
304328
new GainControlImpl(&crit_capture_, &crit_capture_));
305-
public_submodules_->high_pass_filter.reset(
306-
new HighPassFilterImpl(&crit_capture_));
307329
public_submodules_->level_estimator.reset(
308330
new LevelEstimatorImpl(&crit_capture_));
309331
public_submodules_->noise_suppression.reset(
@@ -478,8 +500,7 @@ int AudioProcessingImpl::InitializeLocked() {
478500
#if WEBRTC_INTELLIGIBILITY_ENHANCER
479501
InitializeIntelligibility();
480502
#endif
481-
public_submodules_->high_pass_filter->Initialize(num_proc_channels(),
482-
proc_sample_rate_hz());
503+
InitializeLowCutFilter();
483504
public_submodules_->noise_suppression->Initialize(num_proc_channels(),
484505
proc_sample_rate_hz());
485506
public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz());
@@ -602,6 +623,11 @@ void AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) {
602623
<< capture_nonlocked_.level_controller_enabled;
603624

604625
private_submodules_->level_controller->ApplyConfig(config_.level_controller);
626+
627+
InitializeLowCutFilter();
628+
629+
LOG(LS_INFO) << "Highpass filter activated: "
630+
<< config_.high_pass_filter.enabled;
605631
}
606632

607633
void AudioProcessingImpl::SetExtraOptions(const webrtc::Config& config) {
@@ -1089,7 +1115,9 @@ int AudioProcessingImpl::ProcessCaptureStreamLocked() {
10891115
capture_buffer->set_num_channels(1);
10901116
}
10911117

1092-
public_submodules_->high_pass_filter->ProcessCaptureAudio(capture_buffer);
1118+
if (private_submodules_->low_cut_filter) {
1119+
private_submodules_->low_cut_filter->Process(capture_buffer);
1120+
}
10931121
RETURN_ON_ERR(
10941122
public_submodules_->gain_control->AnalyzeCaptureAudio(capture_buffer));
10951123
public_submodules_->noise_suppression->AnalyzeCaptureAudio(capture_buffer);
@@ -1523,7 +1551,7 @@ GainControl* AudioProcessingImpl::gain_control() const {
15231551
}
15241552

15251553
HighPassFilter* AudioProcessingImpl::high_pass_filter() const {
1526-
return public_submodules_->high_pass_filter.get();
1554+
return high_pass_filter_impl_.get();
15271555
}
15281556

15291557
LevelEstimator* AudioProcessingImpl::level_estimator() const {
@@ -1538,9 +1566,23 @@ VoiceDetection* AudioProcessingImpl::voice_detection() const {
15381566
return public_submodules_->voice_detection.get();
15391567
}
15401568

1569+
void AudioProcessingImpl::MutateConfig(
1570+
rtc::FunctionView<void(AudioProcessing::Config*)> mutator) {
1571+
rtc::CritScope cs_render(&crit_render_);
1572+
rtc::CritScope cs_capture(&crit_capture_);
1573+
mutator(&config_);
1574+
ApplyConfig(config_);
1575+
}
1576+
1577+
AudioProcessing::Config AudioProcessingImpl::GetConfig() const {
1578+
rtc::CritScope cs_render(&crit_render_);
1579+
rtc::CritScope cs_capture(&crit_capture_);
1580+
return config_;
1581+
}
1582+
15411583
bool AudioProcessingImpl::UpdateActiveSubmoduleStates() {
15421584
return submodule_states_.Update(
1543-
public_submodules_->high_pass_filter->is_enabled(),
1585+
config_.high_pass_filter.enabled,
15441586
public_submodules_->echo_cancellation->is_enabled(),
15451587
public_submodules_->echo_control_mobile->is_enabled(),
15461588
config_.residual_echo_detector.enabled,
@@ -1589,6 +1631,15 @@ void AudioProcessingImpl::InitializeIntelligibility() {
15891631
#endif
15901632
}
15911633

1634+
void AudioProcessingImpl::InitializeLowCutFilter() {
1635+
if (config_.high_pass_filter.enabled) {
1636+
private_submodules_->low_cut_filter.reset(
1637+
new LowCutFilter(num_proc_channels(), proc_sample_rate_hz()));
1638+
} else {
1639+
private_submodules_->low_cut_filter.reset();
1640+
}
1641+
}
1642+
15921643
void AudioProcessingImpl::InitializeLevelController() {
15931644
private_submodules_->level_controller->Initialize(proc_sample_rate_hz());
15941645
}
@@ -1772,7 +1823,7 @@ int AudioProcessingImpl::WriteConfigMessage(bool forced) {
17721823
public_submodules_->gain_control->is_limiter_enabled());
17731824
config.set_noise_robust_agc_enabled(constants_.use_experimental_agc);
17741825

1775-
config.set_hpf_enabled(public_submodules_->high_pass_filter->is_enabled());
1826+
config.set_hpf_enabled(config_.high_pass_filter.enabled);
17761827

17771828
config.set_ns_enabled(public_submodules_->noise_suppression->is_enabled());
17781829
config.set_ns_level(

0 commit comments

Comments
 (0)