| 1 |
/* |
| 2 |
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 |
* |
| 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 |
| 6 |
* tree. An additional intellectual property rights grant can be found |
| 7 |
* in the file PATENTS. All contributing project authors may |
| 8 |
* be found in the AUTHORS file in the root of the source tree. |
| 9 |
*/ |
| 10 |
#include "modules/audio_processing/aec3/echo_canceller3.h" |
| 11 |
|
| 12 |
#include <algorithm> |
| 13 |
#include <utility> |
| 14 |
|
| 15 |
#include "modules/audio_processing/aec3/aec3_common.h" |
| 16 |
#include "modules/audio_processing/high_pass_filter.h" |
| 17 |
#include "modules/audio_processing/logging/apm_data_dumper.h" |
| 18 |
#include "rtc_base/atomic_ops.h" |
| 19 |
#include "rtc_base/experiments/field_trial_parser.h" |
| 20 |
#include "rtc_base/logging.h" |
| 21 |
#include "system_wrappers/include/field_trial.h" |
| 22 |
|
| 23 |
namespace webrtc { |
| 24 |
|
| 25 |
namespace { |
| 26 |
|
| 27 |
enum class EchoCanceller3ApiCall { kCapture, kRender }; |
| 28 |
|
| 29 |
bool DetectSaturation(rtc::ArrayView<const float> y) { |
| 30 |
for (auto y_k : y) { |
| 31 |
if (y_k >= 32700.0f || y_k <= -32700.0f) { |
| 32 |
return true; |
| 33 |
} |
| 34 |
} |
| 35 |
return false; |
| 36 |
} |
| 37 |
|
| 38 |
// Retrieves a value from a field trial if it is available. If no value is |
| 39 |
// present, the default value is returned. If the retrieved value is beyond the |
| 40 |
// specified limits, the default value is returned instead. |
| 41 |
void RetrieveFieldTrialValue(const char* trial_name, |
| 42 |
float min, |
| 43 |
float max, |
| 44 |
float* value_to_update) { |
| 45 |
const std::string field_trial_str = field_trial::FindFullName(trial_name); |
| 46 |
|
| 47 |
FieldTrialParameter<double> field_trial_param(/*key=*/"", *value_to_update); |
| 48 |
|
| 49 |
ParseFieldTrial({&field_trial_param}, field_trial_str); |
| 50 |
float field_trial_value = static_cast<float>(field_trial_param.Get()); |
| 51 |
|
| 52 |
if (field_trial_value >= min && field_trial_value <= max) { |
| 53 |
*value_to_update = field_trial_value; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
void RetrieveFieldTrialValue(const char* trial_name, |
| 58 |
int min, |
| 59 |
int max, |
| 60 |
int* value_to_update) { |
| 61 |
const std::string field_trial_str = field_trial::FindFullName(trial_name); |
| 62 |
|
| 63 |
FieldTrialParameter<int> field_trial_param(/*key=*/"", *value_to_update); |
| 64 |
|
| 65 |
ParseFieldTrial({&field_trial_param}, field_trial_str); |
| 66 |
float field_trial_value = field_trial_param.Get(); |
| 67 |
|
| 68 |
if (field_trial_value >= min && field_trial_value <= max) { |
| 69 |
*value_to_update = field_trial_value; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
void FillSubFrameView( |
| 74 |
AudioBuffer* frame, |
| 75 |
size_t sub_frame_index, |
| 76 |
std::vector<std::vector<rtc::ArrayView<float>>>* sub_frame_view) { |
| 77 |
RTC_DCHECK_GE(1, sub_frame_index); |
| 78 |
RTC_DCHECK_LE(0, sub_frame_index); |
| 79 |
RTC_DCHECK_EQ(frame->num_bands(), sub_frame_view->size()); |
| 80 |
RTC_DCHECK_EQ(frame->num_channels(), (*sub_frame_view)[0].size()); |
| 81 |
for (size_t band = 0; band < sub_frame_view->size(); ++band) { |
| 82 |
for (size_t channel = 0; channel < (*sub_frame_view)[0].size(); ++channel) { |
| 83 |
(*sub_frame_view)[band][channel] = rtc::ArrayView<float>( |
| 84 |
&frame->split_bands(channel)[band][sub_frame_index * kSubFrameLength], |
| 85 |
kSubFrameLength); |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
void FillSubFrameView( |
| 91 |
std::vector<std::vector<std::vector<float>>>* frame, |
| 92 |
size_t sub_frame_index, |
| 93 |
std::vector<std::vector<rtc::ArrayView<float>>>* sub_frame_view) { |
| 94 |
RTC_DCHECK_GE(1, sub_frame_index); |
| 95 |
RTC_DCHECK_EQ(frame->size(), sub_frame_view->size()); |
| 96 |
RTC_DCHECK_EQ((*frame)[0].size(), (*sub_frame_view)[0].size()); |
| 97 |
for (size_t band = 0; band < frame->size(); ++band) { |
| 98 |
for (size_t channel = 0; channel < (*frame)[band].size(); ++channel) { |
| 99 |
(*sub_frame_view)[band][channel] = rtc::ArrayView<float>( |
| 100 |
&(*frame)[band][channel][sub_frame_index * kSubFrameLength], |
| 101 |
kSubFrameLength); |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
void ProcessCaptureFrameContent( |
| 107 |
AudioBuffer* linear_output, |
| 108 |
AudioBuffer* capture, |
| 109 |
bool level_change, |
| 110 |
bool saturated_microphone_signal, |
| 111 |
size_t sub_frame_index, |
| 112 |
FrameBlocker* capture_blocker, |
| 113 |
BlockFramer* linear_output_framer, |
| 114 |
BlockFramer* output_framer, |
| 115 |
BlockProcessor* block_processor, |
| 116 |
std::vector<std::vector<std::vector<float>>>* linear_output_block, |
| 117 |
std::vector<std::vector<rtc::ArrayView<float>>>* |
| 118 |
linear_output_sub_frame_view, |
| 119 |
std::vector<std::vector<std::vector<float>>>* capture_block, |
| 120 |
std::vector<std::vector<rtc::ArrayView<float>>>* capture_sub_frame_view) { |
| 121 |
FillSubFrameView(capture, sub_frame_index, capture_sub_frame_view); |
| 122 |
|
| 123 |
if (linear_output) { |
| 124 |
RTC_DCHECK(linear_output_framer); |
| 125 |
RTC_DCHECK(linear_output_block); |
| 126 |
RTC_DCHECK(linear_output_sub_frame_view); |
| 127 |
FillSubFrameView(linear_output, sub_frame_index, |
| 128 |
linear_output_sub_frame_view); |
| 129 |
} |
| 130 |
|
| 131 |
capture_blocker->InsertSubFrameAndExtractBlock(*capture_sub_frame_view, |
| 132 |
capture_block); |
| 133 |
block_processor->ProcessCapture(level_change, saturated_microphone_signal, |
| 134 |
linear_output_block, capture_block); |
| 135 |
output_framer->InsertBlockAndExtractSubFrame(*capture_block, |
| 136 |
capture_sub_frame_view); |
| 137 |
|
| 138 |
if (linear_output) { |
| 139 |
RTC_DCHECK(linear_output_framer); |
| 140 |
linear_output_framer->InsertBlockAndExtractSubFrame( |
| 141 |
*linear_output_block, linear_output_sub_frame_view); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
void ProcessRemainingCaptureFrameContent( |
| 146 |
bool level_change, |
| 147 |
bool saturated_microphone_signal, |
| 148 |
FrameBlocker* capture_blocker, |
| 149 |
BlockFramer* linear_output_framer, |
| 150 |
BlockFramer* output_framer, |
| 151 |
BlockProcessor* block_processor, |
| 152 |
std::vector<std::vector<std::vector<float>>>* linear_output_block, |
| 153 |
std::vector<std::vector<std::vector<float>>>* block) { |
| 154 |
if (!capture_blocker->IsBlockAvailable()) { |
| 155 |
return; |
| 156 |
} |
| 157 |
|
| 158 |
capture_blocker->ExtractBlock(block); |
| 159 |
block_processor->ProcessCapture(level_change, saturated_microphone_signal, |
| 160 |
linear_output_block, block); |
| 161 |
output_framer->InsertBlock(*block); |
| 162 |
|
| 163 |
if (linear_output_framer) { |
| 164 |
RTC_DCHECK(linear_output_block); |
| 165 |
linear_output_framer->InsertBlock(*linear_output_block); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
void BufferRenderFrameContent( |
| 170 |
std::vector<std::vector<std::vector<float>>>* render_frame, |
| 171 |
size_t sub_frame_index, |
| 172 |
FrameBlocker* render_blocker, |
| 173 |
BlockProcessor* block_processor, |
| 174 |
std::vector<std::vector<std::vector<float>>>* block, |
| 175 |
std::vector<std::vector<rtc::ArrayView<float>>>* sub_frame_view) { |
| 176 |
FillSubFrameView(render_frame, sub_frame_index, sub_frame_view); |
| 177 |
render_blocker->InsertSubFrameAndExtractBlock(*sub_frame_view, block); |
| 178 |
block_processor->BufferRender(*block); |
| 179 |
} |
| 180 |
|
| 181 |
void BufferRemainingRenderFrameContent( |
| 182 |
FrameBlocker* render_blocker, |
| 183 |
BlockProcessor* block_processor, |
| 184 |
std::vector<std::vector<std::vector<float>>>* block) { |
| 185 |
if (!render_blocker->IsBlockAvailable()) { |
| 186 |
return; |
| 187 |
} |
| 188 |
render_blocker->ExtractBlock(block); |
| 189 |
block_processor->BufferRender(*block); |
| 190 |
} |
| 191 |
|
| 192 |
void CopyBufferIntoFrame(const AudioBuffer& buffer, |
| 193 |
size_t num_bands, |
| 194 |
size_t num_channels, |
| 195 |
std::vector<std::vector<std::vector<float>>>* frame) { |
| 196 |
RTC_DCHECK_EQ(num_bands, frame->size()); |
| 197 |
RTC_DCHECK_EQ(num_channels, (*frame)[0].size()); |
| 198 |
RTC_DCHECK_EQ(AudioBuffer::kSplitBandSize, (*frame)[0][0].size()); |
| 199 |
for (size_t band = 0; band < num_bands; ++band) { |
| 200 |
for (size_t channel = 0; channel < num_channels; ++channel) { |
| 201 |
rtc::ArrayView<const float> buffer_view( |
| 202 |
&buffer.split_bands_const(channel)[band][0], |
| 203 |
AudioBuffer::kSplitBandSize); |
| 204 |
std::copy(buffer_view.begin(), buffer_view.end(), |
| 205 |
(*frame)[band][channel].begin()); |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
} // namespace |
| 211 |
|
| 212 |
// TODO(webrtc:5298): Move this to a separate file. |
| 213 |
EchoCanceller3Config AdjustConfig(const EchoCanceller3Config& config) { |
| 214 |
EchoCanceller3Config adjusted_cfg = config; |
| 215 |
|
| 216 |
if (field_trial::IsEnabled("WebRTC-Aec3AntiHowlingMinimizationKillSwitch")) { |
| 217 |
adjusted_cfg.suppressor.high_bands_suppression |
| 218 |
.anti_howling_activation_threshold = 25.f; |
| 219 |
adjusted_cfg.suppressor.high_bands_suppression.anti_howling_gain = 0.01f; |
| 220 |
} |
| 221 |
|
| 222 |
if (field_trial::IsEnabled("WebRTC-Aec3UseShortConfigChangeDuration")) { |
| 223 |
adjusted_cfg.filter.config_change_duration_blocks = 10; |
| 224 |
} |
| 225 |
|
| 226 |
if (field_trial::IsEnabled("WebRTC-Aec3UseZeroInitialStateDuration")) { |
| 227 |
adjusted_cfg.filter.initial_state_seconds = 0.f; |
| 228 |
} else if (field_trial::IsEnabled( |
| 229 |
"WebRTC-Aec3UseDot1SecondsInitialStateDuration")) { |
| 230 |
adjusted_cfg.filter.initial_state_seconds = .1f; |
| 231 |
} else if (field_trial::IsEnabled( |
| 232 |
"WebRTC-Aec3UseDot2SecondsInitialStateDuration")) { |
| 233 |
adjusted_cfg.filter.initial_state_seconds = .2f; |
| 234 |
} else if (field_trial::IsEnabled( |
| 235 |
"WebRTC-Aec3UseDot3SecondsInitialStateDuration")) { |
| 236 |
adjusted_cfg.filter.initial_state_seconds = .3f; |
| 237 |
} else if (field_trial::IsEnabled( |
| 238 |
"WebRTC-Aec3UseDot6SecondsInitialStateDuration")) { |
| 239 |
adjusted_cfg.filter.initial_state_seconds = .6f; |
| 240 |
} else if (field_trial::IsEnabled( |
| 241 |
"WebRTC-Aec3UseDot9SecondsInitialStateDuration")) { |
| 242 |
adjusted_cfg.filter.initial_state_seconds = .9f; |
| 243 |
} else if (field_trial::IsEnabled( |
| 244 |
"WebRTC-Aec3Use1Dot2SecondsInitialStateDuration")) { |
| 245 |
adjusted_cfg.filter.initial_state_seconds = 1.2f; |
| 246 |
} else if (field_trial::IsEnabled( |
| 247 |
"WebRTC-Aec3Use1Dot6SecondsInitialStateDuration")) { |
| 248 |
adjusted_cfg.filter.initial_state_seconds = 1.6f; |
| 249 |
} else if (field_trial::IsEnabled( |
| 250 |
"WebRTC-Aec3Use2Dot0SecondsInitialStateDuration")) { |
| 251 |
adjusted_cfg.filter.initial_state_seconds = 2.0f; |
| 252 |
} |
| 253 |
|
| 254 |
if (field_trial::IsEnabled("WebRTC-Aec3HighPassFilterEchoReference")) { |
| 255 |
adjusted_cfg.filter.high_pass_filter_echo_reference = true; |
| 256 |
} |
| 257 |
|
| 258 |
if (field_trial::IsEnabled("WebRTC-Aec3EchoSaturationDetectionKillSwitch")) { |
| 259 |
adjusted_cfg.ep_strength.echo_can_saturate = false; |
| 260 |
} |
| 261 |
|
| 262 |
if (field_trial::IsEnabled("WebRTC-Aec3UseDot2ReverbDefaultLen")) { |
| 263 |
adjusted_cfg.ep_strength.default_len = 0.2f; |
| 264 |
} else if (field_trial::IsEnabled("WebRTC-Aec3UseDot3ReverbDefaultLen")) { |
| 265 |
adjusted_cfg.ep_strength.default_len = 0.3f; |
| 266 |
} else if (field_trial::IsEnabled("WebRTC-Aec3UseDot4ReverbDefaultLen")) { |
| 267 |
adjusted_cfg.ep_strength.default_len = 0.4f; |
| 268 |
} else if (field_trial::IsEnabled("WebRTC-Aec3UseDot5ReverbDefaultLen")) { |
| 269 |
adjusted_cfg.ep_strength.default_len = 0.5f; |
| 270 |
} else if (field_trial::IsEnabled("WebRTC-Aec3UseDot6ReverbDefaultLen")) { |
| 271 |
adjusted_cfg.ep_strength.default_len = 0.6f; |
| 272 |
} else if (field_trial::IsEnabled("WebRTC-Aec3UseDot7ReverbDefaultLen")) { |
| 273 |
adjusted_cfg.ep_strength.default_len = 0.7f; |
| 274 |
} else if (field_trial::IsEnabled("WebRTC-Aec3UseDot8ReverbDefaultLen")) { |
| 275 |
adjusted_cfg.ep_strength.default_len = 0.8f; |
| 276 |
} |
| 277 |
|
| 278 |
if (field_trial::IsEnabled("WebRTC-Aec3ShortHeadroomKillSwitch")) { |
| 279 |
// Two blocks headroom. |
| 280 |
adjusted_cfg.delay.delay_headroom_samples = kBlockSize * 2; |
| 281 |
} |
| 282 |
|
| 283 |
if (field_trial::IsEnabled("WebRTC-Aec3ClampInstQualityToZeroKillSwitch")) { |
| 284 |
adjusted_cfg.erle.clamp_quality_estimate_to_zero = false; |
| 285 |
} |
| 286 |
|
| 287 |
if (field_trial::IsEnabled("WebRTC-Aec3ClampInstQualityToOneKillSwitch")) { |
| 288 |
adjusted_cfg.erle.clamp_quality_estimate_to_one = false; |
| 289 |
} |
| 290 |
|
| 291 |
if (field_trial::IsEnabled("WebRTC-Aec3OnsetDetectionKillSwitch")) { |
| 292 |
adjusted_cfg.erle.onset_detection = false; |
| 293 |
} |
| 294 |
|
| 295 |
if (field_trial::IsEnabled( |
| 296 |
"WebRTC-Aec3EnforceRenderDelayEstimationDownmixing")) { |
| 297 |
adjusted_cfg.delay.render_alignment_mixing.downmix = true; |
| 298 |
adjusted_cfg.delay.render_alignment_mixing.adaptive_selection = false; |
| 299 |
} |
| 300 |
|
| 301 |
if (field_trial::IsEnabled( |
| 302 |
"WebRTC-Aec3EnforceCaptureDelayEstimationDownmixing")) { |
| 303 |
adjusted_cfg.delay.capture_alignment_mixing.downmix = true; |
| 304 |
adjusted_cfg.delay.capture_alignment_mixing.adaptive_selection = false; |
| 305 |
} |
| 306 |
|
| 307 |
if (field_trial::IsEnabled( |
| 308 |
"WebRTC-Aec3EnforceCaptureDelayEstimationLeftRightPrioritization")) { |
| 309 |
adjusted_cfg.delay.capture_alignment_mixing.prefer_first_two_channels = |
| 310 |
true; |
| 311 |
} |
| 312 |
|
| 313 |
if (field_trial::IsEnabled( |
| 314 |
"WebRTC-" |
| 315 |
"Aec3RenderDelayEstimationLeftRightPrioritizationKillSwitch")) { |
| 316 |
adjusted_cfg.delay.capture_alignment_mixing.prefer_first_two_channels = |
| 317 |
false; |
| 318 |
} |
| 319 |
|
| 320 |
if (field_trial::IsEnabled("WebRTC-Aec3SensitiveDominantNearendActivation")) { |
| 321 |
adjusted_cfg.suppressor.dominant_nearend_detection.enr_threshold = 0.5f; |
| 322 |
} else if (field_trial::IsEnabled( |
| 323 |
"WebRTC-Aec3VerySensitiveDominantNearendActivation")) { |
| 324 |
adjusted_cfg.suppressor.dominant_nearend_detection.enr_threshold = 0.75f; |
| 325 |
} |
| 326 |
|
| 327 |
if (field_trial::IsEnabled("WebRTC-Aec3TransparentAntiHowlingGain")) { |
| 328 |
adjusted_cfg.suppressor.high_bands_suppression.anti_howling_gain = 1.f; |
| 329 |
} |
| 330 |
|
| 331 |
if (field_trial::IsEnabled( |
| 332 |
"WebRTC-Aec3EnforceMoreTransparentNormalSuppressorTuning")) { |
| 333 |
adjusted_cfg.suppressor.normal_tuning.mask_lf.enr_transparent = 0.4f; |
| 334 |
adjusted_cfg.suppressor.normal_tuning.mask_lf.enr_suppress = 0.5f; |
| 335 |
} |
| 336 |
|
| 337 |
if (field_trial::IsEnabled( |
| 338 |
"WebRTC-Aec3EnforceMoreTransparentNearendSuppressorTuning")) { |
| 339 |
adjusted_cfg.suppressor.nearend_tuning.mask_lf.enr_transparent = 1.29f; |
| 340 |
adjusted_cfg.suppressor.nearend_tuning.mask_lf.enr_suppress = 1.3f; |
| 341 |
} |
| 342 |
|
| 343 |
if (field_trial::IsEnabled( |
| 344 |
"WebRTC-Aec3EnforceMoreTransparentNormalSuppressorHfTuning")) { |
| 345 |
adjusted_cfg.suppressor.normal_tuning.mask_hf.enr_transparent = 0.3f; |
| 346 |
adjusted_cfg.suppressor.normal_tuning.mask_hf.enr_suppress = 0.4f; |
| 347 |
} |
| 348 |
|
| 349 |
if (field_trial::IsEnabled( |
| 350 |
"WebRTC-Aec3EnforceMoreTransparentNearendSuppressorHfTuning")) { |
| 351 |
adjusted_cfg.suppressor.nearend_tuning.mask_hf.enr_transparent = 1.09f; |
| 352 |
adjusted_cfg.suppressor.nearend_tuning.mask_hf.enr_suppress = 1.1f; |
| 353 |
} |
| 354 |
|
| 355 |
if (field_trial::IsEnabled( |
| 356 |
"WebRTC-Aec3EnforceRapidlyAdjustingNormalSuppressorTunings")) { |
| 357 |
adjusted_cfg.suppressor.normal_tuning.max_inc_factor = 2.5f; |
| 358 |
} |
| 359 |
|
| 360 |
if (field_trial::IsEnabled( |
| 361 |
"WebRTC-Aec3EnforceRapidlyAdjustingNearendSuppressorTunings")) { |
| 362 |
adjusted_cfg.suppressor.nearend_tuning.max_inc_factor = 2.5f; |
| 363 |
} |
| 364 |
|
| 365 |
if (field_trial::IsEnabled( |
| 366 |
"WebRTC-Aec3EnforceSlowlyAdjustingNormalSuppressorTunings")) { |
| 367 |
adjusted_cfg.suppressor.normal_tuning.max_dec_factor_lf = .2f; |
| 368 |
} |
| 369 |
|
| 370 |
if (field_trial::IsEnabled( |
| 371 |
"WebRTC-Aec3EnforceSlowlyAdjustingNearendSuppressorTunings")) { |
| 372 |
adjusted_cfg.suppressor.nearend_tuning.max_dec_factor_lf = .2f; |
| 373 |
} |
| 374 |
|
| 375 |
if (field_trial::IsEnabled("WebRTC-Aec3EnforceConservativeHfSuppression")) { |
| 376 |
adjusted_cfg.suppressor.conservative_hf_suppression = true; |
| 377 |
} |
| 378 |
|
| 379 |
if (field_trial::IsEnabled("WebRTC-Aec3EnforceStationarityProperties")) { |
| 380 |
adjusted_cfg.echo_audibility.use_stationarity_properties = true; |
| 381 |
} |
| 382 |
|
| 383 |
if (field_trial::IsEnabled( |
| 384 |
"WebRTC-Aec3EnforceStationarityPropertiesAtInit")) { |
| 385 |
adjusted_cfg.echo_audibility.use_stationarity_properties_at_init = true; |
| 386 |
} |
| 387 |
|
| 388 |
if (field_trial::IsEnabled("WebRTC-Aec3EnforceLowActiveRenderLimit")) { |
| 389 |
adjusted_cfg.render_levels.active_render_limit = 50.f; |
| 390 |
} else if (field_trial::IsEnabled( |
| 391 |
"WebRTC-Aec3EnforceVeryLowActiveRenderLimit")) { |
| 392 |
adjusted_cfg.render_levels.active_render_limit = 30.f; |
| 393 |
} |
| 394 |
|
| 395 |
if (field_trial::IsEnabled("WebRTC-Aec3NonlinearModeReverbKillSwitch")) { |
| 396 |
adjusted_cfg.echo_model.model_reverb_in_nonlinear_mode = false; |
| 397 |
} |
| 398 |
|
| 399 |
// Field-trial based override for the whole suppressor tuning. |
| 400 |
const std::string suppressor_tuning_override_trial_name = |
| 401 |
field_trial::FindFullName("WebRTC-Aec3SuppressorTuningOverride"); |
| 402 |
|
| 403 |
FieldTrialParameter<double> nearend_tuning_mask_lf_enr_transparent( |
| 404 |
"nearend_tuning_mask_lf_enr_transparent", |
| 405 |
adjusted_cfg.suppressor.nearend_tuning.mask_lf.enr_transparent); |
| 406 |
FieldTrialParameter<double> nearend_tuning_mask_lf_enr_suppress( |
| 407 |
"nearend_tuning_mask_lf_enr_suppress", |
| 408 |
adjusted_cfg.suppressor.nearend_tuning.mask_lf.enr_suppress); |
| 409 |
FieldTrialParameter<double> nearend_tuning_mask_hf_enr_transparent( |
| 410 |
"nearend_tuning_mask_hf_enr_transparent", |
| 411 |
adjusted_cfg.suppressor.nearend_tuning.mask_hf.enr_transparent); |
| 412 |
FieldTrialParameter<double> nearend_tuning_mask_hf_enr_suppress( |
| 413 |
"nearend_tuning_mask_hf_enr_suppress", |
| 414 |
adjusted_cfg.suppressor.nearend_tuning.mask_hf.enr_suppress); |
| 415 |
FieldTrialParameter<double> nearend_tuning_max_inc_factor( |
| 416 |
"nearend_tuning_max_inc_factor", |
| 417 |
adjusted_cfg.suppressor.nearend_tuning.max_inc_factor); |
| 418 |
FieldTrialParameter<double> nearend_tuning_max_dec_factor_lf( |
| 419 |
"nearend_tuning_max_dec_factor_lf", |
| 420 |
adjusted_cfg.suppressor.nearend_tuning.max_dec_factor_lf); |
| 421 |
FieldTrialParameter<double> normal_tuning_mask_lf_enr_transparent( |
| 422 |
"normal_tuning_mask_lf_enr_transparent", |
| 423 |
adjusted_cfg.suppressor.normal_tuning.mask_lf.enr_transparent); |
| 424 |
FieldTrialParameter<double> normal_tuning_mask_lf_enr_suppress( |
| 425 |
"normal_tuning_mask_lf_enr_suppress", |
| 426 |
adjusted_cfg.suppressor.normal_tuning.mask_lf.enr_suppress); |
| 427 |
FieldTrialParameter<double> normal_tuning_mask_hf_enr_transparent( |
| 428 |
"normal_tuning_mask_hf_enr_transparent", |
| 429 |
adjusted_cfg.suppressor.normal_tuning.mask_hf.enr_transparent); |
| 430 |
FieldTrialParameter<double> normal_tuning_mask_hf_enr_suppress( |
| 431 |
"normal_tuning_mask_hf_enr_suppress", |
| 432 |
adjusted_cfg.suppressor.normal_tuning.mask_hf.enr_suppress); |
| 433 |
FieldTrialParameter<double> normal_tuning_max_inc_factor( |
| 434 |
"normal_tuning_max_inc_factor", |
| 435 |
adjusted_cfg.suppressor.normal_tuning.max_inc_factor); |
| 436 |
FieldTrialParameter<double> normal_tuning_max_dec_factor_lf( |
| 437 |
"normal_tuning_max_dec_factor_lf", |
| 438 |
adjusted_cfg.suppressor.normal_tuning.max_dec_factor_lf); |
| 439 |
FieldTrialParameter<double> dominant_nearend_detection_enr_threshold( |
| 440 |
"dominant_nearend_detection_enr_threshold", |
| 441 |
adjusted_cfg.suppressor.dominant_nearend_detection.enr_threshold); |
| 442 |
FieldTrialParameter<double> dominant_nearend_detection_enr_exit_threshold( |
| 443 |
"dominant_nearend_detection_enr_exit_threshold", |
| 444 |
adjusted_cfg.suppressor.dominant_nearend_detection.enr_exit_threshold); |
| 445 |
FieldTrialParameter<double> dominant_nearend_detection_snr_threshold( |
| 446 |
"dominant_nearend_detection_snr_threshold", |
| 447 |
adjusted_cfg.suppressor.dominant_nearend_detection.snr_threshold); |
| 448 |
FieldTrialParameter<int> dominant_nearend_detection_hold_duration( |
| 449 |
"dominant_nearend_detection_hold_duration", |
| 450 |
adjusted_cfg.suppressor.dominant_nearend_detection.hold_duration); |
| 451 |
FieldTrialParameter<int> dominant_nearend_detection_trigger_threshold( |
| 452 |
"dominant_nearend_detection_trigger_threshold", |
| 453 |
adjusted_cfg.suppressor.dominant_nearend_detection.trigger_threshold); |
| 454 |
FieldTrialParameter<double> ep_strength_default_len( |
| 455 |
"ep_strength_default_len", adjusted_cfg.ep_strength.default_len); |
| 456 |
|
| 457 |
ParseFieldTrial( |
| 458 |
{&nearend_tuning_mask_lf_enr_transparent, |
| 459 |
&nearend_tuning_mask_lf_enr_suppress, |
| 460 |
&nearend_tuning_mask_hf_enr_transparent, |
| 461 |
&nearend_tuning_mask_hf_enr_suppress, &nearend_tuning_max_inc_factor, |
| 462 |
&nearend_tuning_max_dec_factor_lf, |
| 463 |
&normal_tuning_mask_lf_enr_transparent, |
| 464 |
&normal_tuning_mask_lf_enr_suppress, |
| 465 |
&normal_tuning_mask_hf_enr_transparent, |
| 466 |
&normal_tuning_mask_hf_enr_suppress, &normal_tuning_max_inc_factor, |
| 467 |
&normal_tuning_max_dec_factor_lf, |
| 468 |
&dominant_nearend_detection_enr_threshold, |
| 469 |
&dominant_nearend_detection_enr_exit_threshold, |
| 470 |
&dominant_nearend_detection_snr_threshold, |
| 471 |
&dominant_nearend_detection_hold_duration, |
| 472 |
&dominant_nearend_detection_trigger_threshold, &ep_strength_default_len}, |
| 473 |
suppressor_tuning_override_trial_name); |
| 474 |
|
| 475 |
adjusted_cfg.suppressor.nearend_tuning.mask_lf.enr_transparent = |
| 476 |
static_cast<float>(nearend_tuning_mask_lf_enr_transparent.Get()); |
| 477 |
adjusted_cfg.suppressor.nearend_tuning.mask_lf.enr_suppress = |
| 478 |
static_cast<float>(nearend_tuning_mask_lf_enr_suppress.Get()); |
| 479 |
adjusted_cfg.suppressor.nearend_tuning.mask_hf.enr_transparent = |
| 480 |
static_cast<float>(nearend_tuning_mask_hf_enr_transparent.Get()); |
| 481 |
adjusted_cfg.suppressor.nearend_tuning.mask_hf.enr_suppress = |
| 482 |
static_cast<float>(nearend_tuning_mask_hf_enr_suppress.Get()); |
| 483 |
adjusted_cfg.suppressor.nearend_tuning.max_inc_factor = |
| 484 |
static_cast<float>(nearend_tuning_max_inc_factor.Get()); |
| 485 |
adjusted_cfg.suppressor.nearend_tuning.max_dec_factor_lf = |
| 486 |
static_cast<float>(nearend_tuning_max_dec_factor_lf.Get()); |
| 487 |
adjusted_cfg.suppressor.normal_tuning.mask_lf.enr_transparent = |
| 488 |
static_cast<float>(normal_tuning_mask_lf_enr_transparent.Get()); |
| 489 |
adjusted_cfg.suppressor.normal_tuning.mask_lf.enr_suppress = |
| 490 |
static_cast<float>(normal_tuning_mask_lf_enr_suppress.Get()); |
| 491 |
adjusted_cfg.suppressor.normal_tuning.mask_hf.enr_transparent = |
| 492 |
static_cast<float>(normal_tuning_mask_hf_enr_transparent.Get()); |
| 493 |
adjusted_cfg.suppressor.normal_tuning.mask_hf.enr_suppress = |
| 494 |
static_cast<float>(normal_tuning_mask_hf_enr_suppress.Get()); |
| 495 |
adjusted_cfg.suppressor.normal_tuning.max_inc_factor = |
| 496 |
static_cast<float>(normal_tuning_max_inc_factor.Get()); |
| 497 |
adjusted_cfg.suppressor.normal_tuning.max_dec_factor_lf = |
| 498 |
static_cast<float>(normal_tuning_max_dec_factor_lf.Get()); |
| 499 |
adjusted_cfg.suppressor.dominant_nearend_detection.enr_threshold = |
| 500 |
static_cast<float>(dominant_nearend_detection_enr_threshold.Get()); |
| 501 |
adjusted_cfg.suppressor.dominant_nearend_detection.enr_exit_threshold = |
| 502 |
static_cast<float>(dominant_nearend_detection_enr_exit_threshold.Get()); |
| 503 |
adjusted_cfg.suppressor.dominant_nearend_detection.snr_threshold = |
| 504 |
static_cast<float>(dominant_nearend_detection_snr_threshold.Get()); |
| 505 |
adjusted_cfg.suppressor.dominant_nearend_detection.hold_duration = |
| 506 |
dominant_nearend_detection_hold_duration.Get(); |
| 507 |
adjusted_cfg.suppressor.dominant_nearend_detection.trigger_threshold = |
| 508 |
dominant_nearend_detection_trigger_threshold.Get(); |
| 509 |
adjusted_cfg.ep_strength.default_len = |
| 510 |
static_cast<float>(ep_strength_default_len.Get()); |
| 511 |
|
| 512 |
// Field trial-based overrides of individual suppressor parameters. |
| 513 |
RetrieveFieldTrialValue( |
| 514 |
"WebRTC-Aec3SuppressorNearendLfMaskTransparentOverride", 0.f, 10.f, |
| 515 |
&adjusted_cfg.suppressor.nearend_tuning.mask_lf.enr_transparent); |
| 516 |
RetrieveFieldTrialValue( |
| 517 |
"WebRTC-Aec3SuppressorNearendLfMaskSuppressOverride", 0.f, 10.f, |
| 518 |
&adjusted_cfg.suppressor.nearend_tuning.mask_lf.enr_suppress); |
| 519 |
RetrieveFieldTrialValue( |
| 520 |
"WebRTC-Aec3SuppressorNearendHfMaskTransparentOverride", 0.f, 10.f, |
| 521 |
&adjusted_cfg.suppressor.nearend_tuning.mask_hf.enr_transparent); |
| 522 |
RetrieveFieldTrialValue( |
| 523 |
"WebRTC-Aec3SuppressorNearendHfMaskSuppressOverride", 0.f, 10.f, |
| 524 |
&adjusted_cfg.suppressor.nearend_tuning.mask_hf.enr_suppress); |
| 525 |
RetrieveFieldTrialValue( |
| 526 |
"WebRTC-Aec3SuppressorNearendMaxIncFactorOverride", 0.f, 10.f, |
| 527 |
&adjusted_cfg.suppressor.nearend_tuning.max_inc_factor); |
| 528 |
RetrieveFieldTrialValue( |
| 529 |
"WebRTC-Aec3SuppressorNearendMaxDecFactorLfOverride", 0.f, 10.f, |
| 530 |
&adjusted_cfg.suppressor.nearend_tuning.max_dec_factor_lf); |
| 531 |
|
| 532 |
RetrieveFieldTrialValue( |
| 533 |
"WebRTC-Aec3SuppressorNormalLfMaskTransparentOverride", 0.f, 10.f, |
| 534 |
&adjusted_cfg.suppressor.normal_tuning.mask_lf.enr_transparent); |
| 535 |
RetrieveFieldTrialValue( |
| 536 |
"WebRTC-Aec3SuppressorNormalLfMaskSuppressOverride", 0.f, 10.f, |
| 537 |
&adjusted_cfg.suppressor.normal_tuning.mask_lf.enr_suppress); |
| 538 |
RetrieveFieldTrialValue( |
| 539 |
"WebRTC-Aec3SuppressorNormalHfMaskTransparentOverride", 0.f, 10.f, |
| 540 |
&adjusted_cfg.suppressor.normal_tuning.mask_hf.enr_transparent); |
| 541 |
RetrieveFieldTrialValue( |
| 542 |
"WebRTC-Aec3SuppressorNormalHfMaskSuppressOverride", 0.f, 10.f, |
| 543 |
&adjusted_cfg.suppressor.normal_tuning.mask_hf.enr_suppress); |
| 544 |
RetrieveFieldTrialValue( |
| 545 |
"WebRTC-Aec3SuppressorNormalMaxIncFactorOverride", 0.f, 10.f, |
| 546 |
&adjusted_cfg.suppressor.normal_tuning.max_inc_factor); |
| 547 |
RetrieveFieldTrialValue( |
| 548 |
"WebRTC-Aec3SuppressorNormalMaxDecFactorLfOverride", 0.f, 10.f, |
| 549 |
&adjusted_cfg.suppressor.normal_tuning.max_dec_factor_lf); |
| 550 |
|
| 551 |
RetrieveFieldTrialValue( |
| 552 |
"WebRTC-Aec3SuppressorDominantNearendEnrThresholdOverride", 0.f, 100.f, |
| 553 |
&adjusted_cfg.suppressor.dominant_nearend_detection.enr_threshold); |
| 554 |
RetrieveFieldTrialValue( |
| 555 |
"WebRTC-Aec3SuppressorDominantNearendEnrExitThresholdOverride", 0.f, |
| 556 |
100.f, |
| 557 |
&adjusted_cfg.suppressor.dominant_nearend_detection.enr_exit_threshold); |
| 558 |
RetrieveFieldTrialValue( |
| 559 |
"WebRTC-Aec3SuppressorDominantNearendSnrThresholdOverride", 0.f, 100.f, |
| 560 |
&adjusted_cfg.suppressor.dominant_nearend_detection.snr_threshold); |
| 561 |
RetrieveFieldTrialValue( |
| 562 |
"WebRTC-Aec3SuppressorDominantNearendHoldDurationOverride", 0, 1000, |
| 563 |
&adjusted_cfg.suppressor.dominant_nearend_detection.hold_duration); |
| 564 |
RetrieveFieldTrialValue( |
| 565 |
"WebRTC-Aec3SuppressorDominantNearendTriggerThresholdOverride", 0, 1000, |
| 566 |
&adjusted_cfg.suppressor.dominant_nearend_detection.trigger_threshold); |
| 567 |
|
| 568 |
RetrieveFieldTrialValue( |
| 569 |
"WebRTC-Aec3SuppressorAntiHowlingGainOverride", 0.f, 10.f, |
| 570 |
&adjusted_cfg.suppressor.high_bands_suppression.anti_howling_gain); |
| 571 |
|
| 572 |
RetrieveFieldTrialValue("WebRTC-Aec3SuppressorEpStrengthDefaultLenOverride", |
| 573 |
-1.f, 1.f, &adjusted_cfg.ep_strength.default_len); |
| 574 |
|
| 575 |
return adjusted_cfg; |
| 576 |
} |
| 577 |
|
| 578 |
class EchoCanceller3::RenderWriter { |
| 579 |
public: |
| 580 |
RenderWriter(ApmDataDumper* data_dumper, |
| 581 |
const EchoCanceller3Config& config, |
| 582 |
SwapQueue<std::vector<std::vector<std::vector<float>>>, |
| 583 |
Aec3RenderQueueItemVerifier>* render_transfer_queue, |
| 584 |
size_t num_bands, |
| 585 |
size_t num_channels); |
| 586 |
|
| 587 |
RenderWriter() = delete; |
| 588 |
RenderWriter(const RenderWriter&) = delete; |
| 589 |
RenderWriter& operator=(const RenderWriter&) = delete; |
| 590 |
|
| 591 |
~RenderWriter(); |
| 592 |
void Insert(const AudioBuffer& input); |
| 593 |
|
| 594 |
private: |
| 595 |
ApmDataDumper* data_dumper_; |
| 596 |
const size_t num_bands_; |
| 597 |
const size_t num_channels_; |
| 598 |
std::unique_ptr<HighPassFilter> high_pass_filter_; |
| 599 |
std::vector<std::vector<std::vector<float>>> render_queue_input_frame_; |
| 600 |
SwapQueue<std::vector<std::vector<std::vector<float>>>, |
| 601 |
Aec3RenderQueueItemVerifier>* render_transfer_queue_; |
| 602 |
}; |
| 603 |
|
| 604 |
EchoCanceller3::RenderWriter::RenderWriter( |
| 605 |
ApmDataDumper* data_dumper, |
| 606 |
const EchoCanceller3Config& config, |
| 607 |
SwapQueue<std::vector<std::vector<std::vector<float>>>, |
| 608 |
Aec3RenderQueueItemVerifier>* render_transfer_queue, |
| 609 |
size_t num_bands, |
| 610 |
size_t num_channels) |
| 611 |
: data_dumper_(data_dumper), |
| 612 |
num_bands_(num_bands), |
| 613 |
num_channels_(num_channels), |
| 614 |
render_queue_input_frame_( |
| 615 |
num_bands_, |
| 616 |
std::vector<std::vector<float>>( |
| 617 |
num_channels_, |
| 618 |
std::vector<float>(AudioBuffer::kSplitBandSize, 0.f))), |
| 619 |
render_transfer_queue_(render_transfer_queue) { |
| 620 |
RTC_DCHECK(data_dumper); |
| 621 |
if (config.filter.high_pass_filter_echo_reference) { |
| 622 |
high_pass_filter_ = std::make_unique<HighPassFilter>(16000, num_channels); |
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
EchoCanceller3::RenderWriter::~RenderWriter() = default; |
| 627 |
|
| 628 |
void EchoCanceller3::RenderWriter::Insert(const AudioBuffer& input) { |
| 629 |
RTC_DCHECK_EQ(AudioBuffer::kSplitBandSize, input.num_frames_per_band()); |
| 630 |
RTC_DCHECK_EQ(num_bands_, input.num_bands()); |
| 631 |
RTC_DCHECK_EQ(num_channels_, input.num_channels()); |
| 632 |
|
| 633 |
// TODO(bugs.webrtc.org/8759) Temporary work-around. |
| 634 |
if (num_bands_ != input.num_bands()) |
| 635 |
return; |
| 636 |
|
| 637 |
data_dumper_->DumpWav("aec3_render_input", AudioBuffer::kSplitBandSize, |
| 638 |
&input.split_bands_const(0)[0][0], 16000, 1); |
| 639 |
|
| 640 |
CopyBufferIntoFrame(input, num_bands_, num_channels_, |
| 641 |
&render_queue_input_frame_); |
| 642 |
if (high_pass_filter_) { |
| 643 |
high_pass_filter_->Process(&render_queue_input_frame_[0]); |
| 644 |
} |
| 645 |
|
| 646 |
static_cast<void>(render_transfer_queue_->Insert(&render_queue_input_frame_)); |
| 647 |
} |
| 648 |
|
| 649 |
int EchoCanceller3::instance_count_ = 0; |
| 650 |
|
| 651 |
EchoCanceller3::EchoCanceller3(const EchoCanceller3Config& config, |
| 652 |
int sample_rate_hz, |
| 653 |
size_t num_render_channels, |
| 654 |
size_t num_capture_channels) |
| 655 |
: EchoCanceller3(AdjustConfig(config), |
| 656 |
sample_rate_hz, |
| 657 |
num_render_channels, |
| 658 |
num_capture_channels, |
| 659 |
std::unique_ptr<BlockProcessor>( |
| 660 |
BlockProcessor::Create(AdjustConfig(config), |
| 661 |
sample_rate_hz, |
| 662 |
num_render_channels, |
| 663 |
num_capture_channels))) {} |
| 664 |
EchoCanceller3::EchoCanceller3(const EchoCanceller3Config& config, |
| 665 |
int sample_rate_hz, |
| 666 |
size_t num_render_channels, |
| 667 |
size_t num_capture_channels, |
| 668 |
std::unique_ptr<BlockProcessor> block_processor) |
| 669 |
: data_dumper_( |
| 670 |
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))), |
| 671 |
config_(config), |
| 672 |
sample_rate_hz_(sample_rate_hz), |
| 673 |
num_bands_(NumBandsForRate(sample_rate_hz_)), |
| 674 |
num_render_channels_(num_render_channels), |
| 675 |
num_capture_channels_(num_capture_channels), |
| 676 |
output_framer_(num_bands_, num_capture_channels_), |
| 677 |
capture_blocker_(num_bands_, num_capture_channels_), |
| 678 |
render_blocker_(num_bands_, num_render_channels_), |
| 679 |
render_transfer_queue_( |
| 680 |
kRenderTransferQueueSizeFrames, |
| 681 |
std::vector<std::vector<std::vector<float>>>( |
| 682 |
num_bands_, |
| 683 |
std::vector<std::vector<float>>( |
| 684 |
num_render_channels_, |
| 685 |
std::vector<float>(AudioBuffer::kSplitBandSize, 0.f))), |
| 686 |
Aec3RenderQueueItemVerifier(num_bands_, |
| 687 |
num_render_channels_, |
| 688 |
AudioBuffer::kSplitBandSize)), |
| 689 |
block_processor_(std::move(block_processor)), |
| 690 |
render_queue_output_frame_( |
| 691 |
num_bands_, |
| 692 |
std::vector<std::vector<float>>( |
| 693 |
num_render_channels_, |
| 694 |
std::vector<float>(AudioBuffer::kSplitBandSize, 0.f))), |
| 695 |
render_block_( |
| 696 |
num_bands_, |
| 697 |
std::vector<std::vector<float>>(num_render_channels_, |
| 698 |
std::vector<float>(kBlockSize, 0.f))), |
| 699 |
capture_block_( |
| 700 |
num_bands_, |
| 701 |
std::vector<std::vector<float>>(num_capture_channels_, |
| 702 |
std::vector<float>(kBlockSize, 0.f))), |
| 703 |
render_sub_frame_view_( |
| 704 |
num_bands_, |
| 705 |
std::vector<rtc::ArrayView<float>>(num_render_channels_)), |
| 706 |
capture_sub_frame_view_( |
| 707 |
num_bands_, |
| 708 |
std::vector<rtc::ArrayView<float>>(num_capture_channels_)) { |
| 709 |
RTC_DCHECK(ValidFullBandRate(sample_rate_hz_)); |
| 710 |
|
| 711 |
if (config_.delay.fixed_capture_delay_samples > 0) { |
| 712 |
block_delay_buffer_.reset(new BlockDelayBuffer( |
| 713 |
num_capture_channels_, num_bands_, AudioBuffer::kSplitBandSize, |
| 714 |
config_.delay.fixed_capture_delay_samples)); |
| 715 |
} |
| 716 |
|
| 717 |
render_writer_.reset(new RenderWriter(data_dumper_.get(), config_, |
| 718 |
&render_transfer_queue_, num_bands_, |
| 719 |
num_render_channels_)); |
| 720 |
|
| 721 |
RTC_DCHECK_EQ(num_bands_, std::max(sample_rate_hz_, 16000) / 16000); |
| 722 |
RTC_DCHECK_GE(kMaxNumBands, num_bands_); |
| 723 |
|
| 724 |
if (config_.filter.export_linear_aec_output) { |
| 725 |
linear_output_framer_.reset(new BlockFramer(1, num_capture_channels_)); |
| 726 |
linear_output_block_ = |
| 727 |
std::make_unique<std::vector<std::vector<std::vector<float>>>>( |
| 728 |
1, std::vector<std::vector<float>>( |
| 729 |
num_capture_channels_, std::vector<float>(kBlockSize, 0.f))); |
| 730 |
linear_output_sub_frame_view_ = |
| 731 |
std::vector<std::vector<rtc::ArrayView<float>>>( |
| 732 |
1, std::vector<rtc::ArrayView<float>>(num_capture_channels_)); |
| 733 |
} |
| 734 |
} |
| 735 |
|
| 736 |
EchoCanceller3::~EchoCanceller3() = default; |
| 737 |
|
| 738 |
void EchoCanceller3::AnalyzeRender(const AudioBuffer& render) { |
| 739 |
RTC_DCHECK_RUNS_SERIALIZED(&render_race_checker_); |
| 740 |
|
| 741 |
RTC_DCHECK_EQ(render.num_channels(), num_render_channels_); |
| 742 |
data_dumper_->DumpRaw("aec3_call_order", |
| 743 |
static_cast<int>(EchoCanceller3ApiCall::kRender)); |
| 744 |
|
| 745 |
return render_writer_->Insert(render); |
| 746 |
} |
| 747 |
|
| 748 |
void EchoCanceller3::AnalyzeCapture(const AudioBuffer& capture) { |
| 749 |
RTC_DCHECK_RUNS_SERIALIZED(&capture_race_checker_); |
| 750 |
data_dumper_->DumpWav("aec3_capture_analyze_input", capture.num_frames(), |
| 751 |
capture.channels_const()[0], sample_rate_hz_, 1); |
| 752 |
saturated_microphone_signal_ = false; |
| 753 |
for (size_t channel = 0; channel < capture.num_channels(); ++channel) { |
| 754 |
saturated_microphone_signal_ |= |
| 755 |
DetectSaturation(rtc::ArrayView<const float>( |
| 756 |
capture.channels_const()[channel], capture.num_frames())); |
| 757 |
if (saturated_microphone_signal_) { |
| 758 |
break; |
| 759 |
} |
| 760 |
} |
| 761 |
} |
| 762 |
|
| 763 |
void EchoCanceller3::ProcessCapture(AudioBuffer* capture, bool level_change) { |
| 764 |
ProcessCapture(capture, nullptr, level_change); |
| 765 |
} |
| 766 |
|
| 767 |
void EchoCanceller3::ProcessCapture(AudioBuffer* capture, |
| 768 |
AudioBuffer* linear_output, |
| 769 |
bool level_change) { |
| 770 |
RTC_DCHECK_RUNS_SERIALIZED(&capture_race_checker_); |
| 771 |
RTC_DCHECK(capture); |
| 772 |
RTC_DCHECK_EQ(num_bands_, capture->num_bands()); |
| 773 |
RTC_DCHECK_EQ(AudioBuffer::kSplitBandSize, capture->num_frames_per_band()); |
| 774 |
RTC_DCHECK_EQ(capture->num_channels(), num_capture_channels_); |
| 775 |
data_dumper_->DumpRaw("aec3_call_order", |
| 776 |
static_cast<int>(EchoCanceller3ApiCall::kCapture)); |
| 777 |
|
| 778 |
if (linear_output && !linear_output_framer_) { |
| 779 |
RTC_LOG(LS_ERROR) << "Trying to retrieve the linear AEC output without " |
| 780 |
"properly configuring AEC3."; |
| 781 |
RTC_NOTREACHED(); |
| 782 |
} |
| 783 |
|
| 784 |
// Report capture call in the metrics and periodically update API call |
| 785 |
// metrics. |
| 786 |
api_call_metrics_.ReportCaptureCall(); |
| 787 |
|
| 788 |
// Optionally delay the capture signal. |
| 789 |
if (config_.delay.fixed_capture_delay_samples > 0) { |
| 790 |
RTC_DCHECK(block_delay_buffer_); |
| 791 |
block_delay_buffer_->DelaySignal(capture); |
| 792 |
} |
| 793 |
|
| 794 |
rtc::ArrayView<float> capture_lower_band = rtc::ArrayView<float>( |
| 795 |
&capture->split_bands(0)[0][0], AudioBuffer::kSplitBandSize); |
| 796 |
|
| 797 |
data_dumper_->DumpWav("aec3_capture_input", capture_lower_band, 16000, 1); |
| 798 |
|
| 799 |
EmptyRenderQueue(); |
| 800 |
|
| 801 |
ProcessCaptureFrameContent(linear_output, capture, level_change, |
| 802 |
saturated_microphone_signal_, 0, &capture_blocker_, |
| 803 |
linear_output_framer_.get(), &output_framer_, |
| 804 |
block_processor_.get(), linear_output_block_.get(), |
| 805 |
&linear_output_sub_frame_view_, &capture_block_, |
| 806 |
&capture_sub_frame_view_); |
| 807 |
|
| 808 |
ProcessCaptureFrameContent(linear_output, capture, level_change, |
| 809 |
saturated_microphone_signal_, 1, &capture_blocker_, |
| 810 |
linear_output_framer_.get(), &output_framer_, |
| 811 |
block_processor_.get(), linear_output_block_.get(), |
| 812 |
&linear_output_sub_frame_view_, &capture_block_, |
| 813 |
&capture_sub_frame_view_); |
| 814 |
|
| 815 |
ProcessRemainingCaptureFrameContent( |
| 816 |
level_change, saturated_microphone_signal_, &capture_blocker_, |
| 817 |
linear_output_framer_.get(), &output_framer_, block_processor_.get(), |
| 818 |
linear_output_block_.get(), &capture_block_); |
| 819 |
|
| 820 |
data_dumper_->DumpWav("aec3_capture_output", AudioBuffer::kSplitBandSize, |
| 821 |
&capture->split_bands(0)[0][0], 16000, 1); |
| 822 |
} |
| 823 |
|
| 824 |
EchoControl::Metrics EchoCanceller3::GetMetrics() const { |
| 825 |
RTC_DCHECK_RUNS_SERIALIZED(&capture_race_checker_); |
| 826 |
Metrics metrics; |
| 827 |
block_processor_->GetMetrics(&metrics); |
| 828 |
return metrics; |
| 829 |
} |
| 830 |
|
| 831 |
void EchoCanceller3::SetAudioBufferDelay(int delay_ms) { |
| 832 |
RTC_DCHECK_RUNS_SERIALIZED(&capture_race_checker_); |
| 833 |
block_processor_->SetAudioBufferDelay(delay_ms); |
| 834 |
} |
| 835 |
|
| 836 |
void EchoCanceller3::SetCaptureOutputUsage(bool capture_output_used) { |
| 837 |
RTC_DCHECK_RUNS_SERIALIZED(&capture_race_checker_); |
| 838 |
block_processor_->SetCaptureOutputUsage(capture_output_used); |
| 839 |
} |
| 840 |
|
| 841 |
bool EchoCanceller3::ActiveProcessing() const { |
| 842 |
return true; |
| 843 |
} |
| 844 |
|
| 845 |
EchoCanceller3Config EchoCanceller3::CreateDefaultConfig( |
| 846 |
size_t num_render_channels, |
| 847 |
size_t num_capture_channels) { |
| 848 |
EchoCanceller3Config cfg; |
| 849 |
if (num_render_channels > 1) { |
| 850 |
// Use shorter and more rapidly adapting coarse filter to compensate for |
| 851 |
// thge increased number of total filter parameters to adapt. |
| 852 |
cfg.filter.coarse.length_blocks = 11; |
| 853 |
cfg.filter.coarse.rate = 0.95f; |
| 854 |
cfg.filter.coarse_initial.length_blocks = 11; |
| 855 |
cfg.filter.coarse_initial.rate = 0.95f; |
| 856 |
|
| 857 |
// Use more concervative suppressor behavior for non-nearend speech. |
| 858 |
cfg.suppressor.normal_tuning.max_dec_factor_lf = 0.35f; |
| 859 |
cfg.suppressor.normal_tuning.max_inc_factor = 1.5f; |
| 860 |
} |
| 861 |
return cfg; |
| 862 |
} |
| 863 |
|
| 864 |
void EchoCanceller3::EmptyRenderQueue() { |
| 865 |
RTC_DCHECK_RUNS_SERIALIZED(&capture_race_checker_); |
| 866 |
bool frame_to_buffer = |
| 867 |
render_transfer_queue_.Remove(&render_queue_output_frame_); |
| 868 |
while (frame_to_buffer) { |
| 869 |
// Report render call in the metrics. |
| 870 |
api_call_metrics_.ReportRenderCall(); |
| 871 |
|
| 872 |
BufferRenderFrameContent(&render_queue_output_frame_, 0, &render_blocker_, |
| 873 |
block_processor_.get(), &render_block_, |
| 874 |
&render_sub_frame_view_); |
| 875 |
|
| 876 |
BufferRenderFrameContent(&render_queue_output_frame_, 1, &render_blocker_, |
| 877 |
block_processor_.get(), &render_block_, |
| 878 |
&render_sub_frame_view_); |
| 879 |
|
| 880 |
BufferRemainingRenderFrameContent(&render_blocker_, block_processor_.get(), |
| 881 |
&render_block_); |
| 882 |
|
| 883 |
frame_to_buffer = |
| 884 |
render_transfer_queue_.Remove(&render_queue_output_frame_); |
| 885 |
} |
| 886 |
} |
| 887 |
} // namespace webrtc |