niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
bjornv@webrtc.org | 21a2fc9 | 2013-02-15 17:01:03 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/audio_processing/echo_cancellation_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
bjornv@webrtc.org | 21a2fc9 | 2013-02-15 17:01:03 +0000 | [diff] [blame] | 13 | #include <assert.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | #include <string.h> |
| 15 | |
andrew@webrtc.org | 1760a17 | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 16 | extern "C" { |
| 17 | #include "webrtc/modules/audio_processing/aec/aec_core.h" |
| 18 | } |
| 19 | #include "webrtc/modules/audio_processing/aec/include/echo_cancellation.h" |
bjornv@webrtc.org | 21a2fc9 | 2013-02-15 17:01:03 +0000 | [diff] [blame] | 20 | #include "webrtc/modules/audio_processing/audio_buffer.h" |
bjornv@webrtc.org | 21a2fc9 | 2013-02-15 17:01:03 +0000 | [diff] [blame] | 21 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | namespace webrtc { |
| 24 | |
| 25 | typedef void Handle; |
| 26 | |
| 27 | namespace { |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 28 | int16_t MapSetting(EchoCancellation::SuppressionLevel level) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | switch (level) { |
| 30 | case EchoCancellation::kLowSuppression: |
| 31 | return kAecNlpConservative; |
| 32 | case EchoCancellation::kModerateSuppression: |
| 33 | return kAecNlpModerate; |
| 34 | case EchoCancellation::kHighSuppression: |
| 35 | return kAecNlpAggressive; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | } |
andrew@webrtc.org | 648af74 | 2012-02-08 01:57:29 +0000 | [diff] [blame] | 37 | assert(false); |
mflodman@webrtc.org | 657b2a4 | 2012-02-06 11:06:01 +0000 | [diff] [blame] | 38 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | } |
| 40 | |
andrew@webrtc.org | 648af74 | 2012-02-08 01:57:29 +0000 | [diff] [blame] | 41 | AudioProcessing::Error MapError(int err) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | switch (err) { |
| 43 | case AEC_UNSUPPORTED_FUNCTION_ERROR: |
| 44 | return AudioProcessing::kUnsupportedFunctionError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | case AEC_BAD_PARAMETER_ERROR: |
| 46 | return AudioProcessing::kBadParameterError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | case AEC_BAD_PARAMETER_WARNING: |
| 48 | return AudioProcessing::kBadStreamParameterWarning; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | default: |
| 50 | // AEC_UNSPECIFIED_ERROR |
| 51 | // AEC_UNINITIALIZED_ERROR |
| 52 | // AEC_NULL_POINTER_ERROR |
| 53 | return AudioProcessing::kUnspecifiedError; |
| 54 | } |
| 55 | } |
| 56 | } // namespace |
| 57 | |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 58 | EchoCancellationImpl::EchoCancellationImpl(const AudioProcessing* apm, |
| 59 | CriticalSectionWrapper* crit) |
| 60 | : ProcessingComponent(), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | apm_(apm), |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 62 | crit_(crit), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | drift_compensation_enabled_(false), |
| 64 | metrics_enabled_(false), |
| 65 | suppression_level_(kModerateSuppression), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | stream_drift_samples_(0), |
| 67 | was_stream_drift_set_(false), |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 68 | stream_has_echo_(false), |
andrew@webrtc.org | 1760a17 | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 69 | delay_logging_enabled_(false), |
bjornv@webrtc.org | e9d3760 | 2014-04-23 13:20:07 +0000 | [diff] [blame] | 70 | delay_correction_enabled_(false), |
| 71 | reported_delay_enabled_(true) {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
| 73 | EchoCancellationImpl::~EchoCancellationImpl() {} |
| 74 | |
| 75 | int EchoCancellationImpl::ProcessRenderAudio(const AudioBuffer* audio) { |
| 76 | if (!is_component_enabled()) { |
| 77 | return apm_->kNoError; |
| 78 | } |
| 79 | |
| 80 | assert(audio->samples_per_split_channel() <= 160); |
| 81 | assert(audio->num_channels() == apm_->num_reverse_channels()); |
| 82 | |
| 83 | int err = apm_->kNoError; |
| 84 | |
| 85 | // The ordering convention must be followed to pass to the correct AEC. |
| 86 | size_t handle_index = 0; |
| 87 | for (int i = 0; i < apm_->num_output_channels(); i++) { |
| 88 | for (int j = 0; j < audio->num_channels(); j++) { |
| 89 | Handle* my_handle = static_cast<Handle*>(handle(handle_index)); |
| 90 | err = WebRtcAec_BufferFarend( |
| 91 | my_handle, |
aluebs@webrtc.org | c5ebbd9 | 2014-12-10 19:30:57 +0000 | [diff] [blame] | 92 | audio->split_bands_const_f(j)[kBand0To8kHz], |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 93 | static_cast<int16_t>(audio->samples_per_split_channel())); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | |
| 95 | if (err != apm_->kNoError) { |
| 96 | return GetHandleError(my_handle); // TODO(ajm): warning possible? |
| 97 | } |
| 98 | |
| 99 | handle_index++; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | return apm_->kNoError; |
| 104 | } |
| 105 | |
| 106 | int EchoCancellationImpl::ProcessCaptureAudio(AudioBuffer* audio) { |
| 107 | if (!is_component_enabled()) { |
| 108 | return apm_->kNoError; |
| 109 | } |
| 110 | |
| 111 | if (!apm_->was_stream_delay_set()) { |
| 112 | return apm_->kStreamParameterNotSetError; |
| 113 | } |
| 114 | |
| 115 | if (drift_compensation_enabled_ && !was_stream_drift_set_) { |
| 116 | return apm_->kStreamParameterNotSetError; |
| 117 | } |
| 118 | |
| 119 | assert(audio->samples_per_split_channel() <= 160); |
| 120 | assert(audio->num_channels() == apm_->num_output_channels()); |
| 121 | |
| 122 | int err = apm_->kNoError; |
| 123 | |
| 124 | // The ordering convention must be followed to pass to the correct AEC. |
| 125 | size_t handle_index = 0; |
| 126 | stream_has_echo_ = false; |
| 127 | for (int i = 0; i < audio->num_channels(); i++) { |
| 128 | for (int j = 0; j < apm_->num_reverse_channels(); j++) { |
| 129 | Handle* my_handle = handle(handle_index); |
| 130 | err = WebRtcAec_Process( |
| 131 | my_handle, |
aluebs@webrtc.org | c78d81a | 2015-01-21 19:10:55 +0000 | [diff] [blame] | 132 | audio->split_bands_const_f(i), |
| 133 | audio->num_bands(), |
| 134 | audio->split_bands_f(i), |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 135 | static_cast<int16_t>(audio->samples_per_split_channel()), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 136 | apm_->stream_delay_ms(), |
| 137 | stream_drift_samples_); |
| 138 | |
| 139 | if (err != apm_->kNoError) { |
| 140 | err = GetHandleError(my_handle); |
| 141 | // TODO(ajm): Figure out how to return warnings properly. |
| 142 | if (err != apm_->kBadStreamParameterWarning) { |
| 143 | return err; |
| 144 | } |
| 145 | } |
| 146 | |
bjornv@webrtc.org | 21a2fc9 | 2013-02-15 17:01:03 +0000 | [diff] [blame] | 147 | int status = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 148 | err = WebRtcAec_get_echo_status(my_handle, &status); |
| 149 | if (err != apm_->kNoError) { |
| 150 | return GetHandleError(my_handle); |
| 151 | } |
| 152 | |
| 153 | if (status == 1) { |
| 154 | stream_has_echo_ = true; |
| 155 | } |
| 156 | |
| 157 | handle_index++; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | was_stream_drift_set_ = false; |
| 162 | return apm_->kNoError; |
| 163 | } |
| 164 | |
| 165 | int EchoCancellationImpl::Enable(bool enable) { |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 166 | CriticalSectionScoped crit_scoped(crit_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 167 | // Ensure AEC and AECM are not both enabled. |
| 168 | if (enable && apm_->echo_control_mobile()->is_enabled()) { |
| 169 | return apm_->kBadParameterError; |
| 170 | } |
| 171 | |
| 172 | return EnableComponent(enable); |
| 173 | } |
| 174 | |
| 175 | bool EchoCancellationImpl::is_enabled() const { |
| 176 | return is_component_enabled(); |
| 177 | } |
| 178 | |
| 179 | int EchoCancellationImpl::set_suppression_level(SuppressionLevel level) { |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 180 | CriticalSectionScoped crit_scoped(crit_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 181 | if (MapSetting(level) == -1) { |
| 182 | return apm_->kBadParameterError; |
| 183 | } |
| 184 | |
| 185 | suppression_level_ = level; |
| 186 | return Configure(); |
| 187 | } |
| 188 | |
| 189 | EchoCancellation::SuppressionLevel EchoCancellationImpl::suppression_level() |
| 190 | const { |
| 191 | return suppression_level_; |
| 192 | } |
| 193 | |
| 194 | int EchoCancellationImpl::enable_drift_compensation(bool enable) { |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 195 | CriticalSectionScoped crit_scoped(crit_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 196 | drift_compensation_enabled_ = enable; |
| 197 | return Configure(); |
| 198 | } |
| 199 | |
| 200 | bool EchoCancellationImpl::is_drift_compensation_enabled() const { |
| 201 | return drift_compensation_enabled_; |
| 202 | } |
| 203 | |
andrew@webrtc.org | 6be1e93 | 2013-03-01 18:47:28 +0000 | [diff] [blame] | 204 | void EchoCancellationImpl::set_stream_drift_samples(int drift) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 205 | was_stream_drift_set_ = true; |
| 206 | stream_drift_samples_ = drift; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | int EchoCancellationImpl::stream_drift_samples() const { |
| 210 | return stream_drift_samples_; |
| 211 | } |
| 212 | |
| 213 | int EchoCancellationImpl::enable_metrics(bool enable) { |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 214 | CriticalSectionScoped crit_scoped(crit_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 215 | metrics_enabled_ = enable; |
| 216 | return Configure(); |
| 217 | } |
| 218 | |
| 219 | bool EchoCancellationImpl::are_metrics_enabled() const { |
| 220 | return metrics_enabled_; |
| 221 | } |
| 222 | |
| 223 | // TODO(ajm): we currently just use the metrics from the first AEC. Think more |
| 224 | // aboue the best way to extend this to multi-channel. |
| 225 | int EchoCancellationImpl::GetMetrics(Metrics* metrics) { |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 226 | CriticalSectionScoped crit_scoped(crit_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 227 | if (metrics == NULL) { |
| 228 | return apm_->kNullPointerError; |
| 229 | } |
| 230 | |
| 231 | if (!is_component_enabled() || !metrics_enabled_) { |
| 232 | return apm_->kNotEnabledError; |
| 233 | } |
| 234 | |
| 235 | AecMetrics my_metrics; |
| 236 | memset(&my_metrics, 0, sizeof(my_metrics)); |
| 237 | memset(metrics, 0, sizeof(Metrics)); |
| 238 | |
| 239 | Handle* my_handle = static_cast<Handle*>(handle(0)); |
| 240 | int err = WebRtcAec_GetMetrics(my_handle, &my_metrics); |
| 241 | if (err != apm_->kNoError) { |
| 242 | return GetHandleError(my_handle); |
| 243 | } |
| 244 | |
| 245 | metrics->residual_echo_return_loss.instant = my_metrics.rerl.instant; |
| 246 | metrics->residual_echo_return_loss.average = my_metrics.rerl.average; |
| 247 | metrics->residual_echo_return_loss.maximum = my_metrics.rerl.max; |
| 248 | metrics->residual_echo_return_loss.minimum = my_metrics.rerl.min; |
| 249 | |
| 250 | metrics->echo_return_loss.instant = my_metrics.erl.instant; |
| 251 | metrics->echo_return_loss.average = my_metrics.erl.average; |
| 252 | metrics->echo_return_loss.maximum = my_metrics.erl.max; |
| 253 | metrics->echo_return_loss.minimum = my_metrics.erl.min; |
| 254 | |
| 255 | metrics->echo_return_loss_enhancement.instant = my_metrics.erle.instant; |
| 256 | metrics->echo_return_loss_enhancement.average = my_metrics.erle.average; |
| 257 | metrics->echo_return_loss_enhancement.maximum = my_metrics.erle.max; |
| 258 | metrics->echo_return_loss_enhancement.minimum = my_metrics.erle.min; |
| 259 | |
| 260 | metrics->a_nlp.instant = my_metrics.aNlp.instant; |
| 261 | metrics->a_nlp.average = my_metrics.aNlp.average; |
| 262 | metrics->a_nlp.maximum = my_metrics.aNlp.max; |
| 263 | metrics->a_nlp.minimum = my_metrics.aNlp.min; |
| 264 | |
| 265 | return apm_->kNoError; |
| 266 | } |
| 267 | |
| 268 | bool EchoCancellationImpl::stream_has_echo() const { |
| 269 | return stream_has_echo_; |
| 270 | } |
| 271 | |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 272 | int EchoCancellationImpl::enable_delay_logging(bool enable) { |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 273 | CriticalSectionScoped crit_scoped(crit_); |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 274 | delay_logging_enabled_ = enable; |
| 275 | return Configure(); |
| 276 | } |
| 277 | |
| 278 | bool EchoCancellationImpl::is_delay_logging_enabled() const { |
| 279 | return delay_logging_enabled_; |
| 280 | } |
| 281 | |
| 282 | // TODO(bjornv): How should we handle the multi-channel case? |
| 283 | int EchoCancellationImpl::GetDelayMetrics(int* median, int* std) { |
bjornv@webrtc.org | b1786db | 2015-02-03 06:06:26 +0000 | [diff] [blame^] | 284 | float fraction_poor_delays = 0; |
| 285 | return GetDelayMetrics(median, std, &fraction_poor_delays); |
| 286 | } |
| 287 | |
| 288 | int EchoCancellationImpl::GetDelayMetrics(int* median, int* std, |
| 289 | float* fraction_poor_delays) { |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 290 | CriticalSectionScoped crit_scoped(crit_); |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 291 | if (median == NULL) { |
| 292 | return apm_->kNullPointerError; |
| 293 | } |
| 294 | if (std == NULL) { |
| 295 | return apm_->kNullPointerError; |
| 296 | } |
| 297 | |
| 298 | if (!is_component_enabled() || !delay_logging_enabled_) { |
| 299 | return apm_->kNotEnabledError; |
| 300 | } |
| 301 | |
| 302 | Handle* my_handle = static_cast<Handle*>(handle(0)); |
bjornv@webrtc.org | b1786db | 2015-02-03 06:06:26 +0000 | [diff] [blame^] | 303 | if (WebRtcAec_GetDelayMetrics(my_handle, median, std, fraction_poor_delays) != |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 304 | apm_->kNoError) { |
| 305 | return GetHandleError(my_handle); |
| 306 | } |
| 307 | |
| 308 | return apm_->kNoError; |
| 309 | } |
| 310 | |
bjornv@webrtc.org | 91d11b3 | 2013-03-05 16:53:09 +0000 | [diff] [blame] | 311 | struct AecCore* EchoCancellationImpl::aec_core() const { |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 312 | CriticalSectionScoped crit_scoped(crit_); |
bjornv@webrtc.org | 91d11b3 | 2013-03-05 16:53:09 +0000 | [diff] [blame] | 313 | if (!is_component_enabled()) { |
| 314 | return NULL; |
| 315 | } |
| 316 | Handle* my_handle = static_cast<Handle*>(handle(0)); |
| 317 | return WebRtcAec_aec_core(my_handle); |
| 318 | } |
| 319 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 320 | int EchoCancellationImpl::Initialize() { |
| 321 | int err = ProcessingComponent::Initialize(); |
| 322 | if (err != apm_->kNoError || !is_component_enabled()) { |
| 323 | return err; |
| 324 | } |
| 325 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 326 | return apm_->kNoError; |
| 327 | } |
| 328 | |
andrew@webrtc.org | 1760a17 | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 329 | void EchoCancellationImpl::SetExtraOptions(const Config& config) { |
| 330 | delay_correction_enabled_ = config.Get<DelayCorrection>().enabled; |
bjornv@webrtc.org | 3f83072 | 2014-06-11 04:48:11 +0000 | [diff] [blame] | 331 | reported_delay_enabled_ = config.Get<ReportedDelay>().enabled; |
andrew@webrtc.org | 1760a17 | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 332 | Configure(); |
| 333 | } |
| 334 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 335 | void* EchoCancellationImpl::CreateHandle() const { |
| 336 | Handle* handle = NULL; |
| 337 | if (WebRtcAec_Create(&handle) != apm_->kNoError) { |
| 338 | handle = NULL; |
| 339 | } else { |
| 340 | assert(handle != NULL); |
| 341 | } |
| 342 | |
| 343 | return handle; |
| 344 | } |
| 345 | |
bjornv@webrtc.org | 5964fe0 | 2014-04-22 06:52:28 +0000 | [diff] [blame] | 346 | void EchoCancellationImpl::DestroyHandle(void* handle) const { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 347 | assert(handle != NULL); |
bjornv@webrtc.org | 5964fe0 | 2014-04-22 06:52:28 +0000 | [diff] [blame] | 348 | WebRtcAec_Free(static_cast<Handle*>(handle)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | int EchoCancellationImpl::InitializeHandle(void* handle) const { |
| 352 | assert(handle != NULL); |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 353 | // TODO(ajm): Drift compensation is disabled in practice. If restored, it |
| 354 | // should be managed internally and not depend on the hardware sample rate. |
| 355 | // For now, just hardcode a 48 kHz value. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 356 | return WebRtcAec_Init(static_cast<Handle*>(handle), |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 357 | apm_->proc_sample_rate_hz(), |
| 358 | 48000); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | int EchoCancellationImpl::ConfigureHandle(void* handle) const { |
| 362 | assert(handle != NULL); |
| 363 | AecConfig config; |
| 364 | config.metricsMode = metrics_enabled_; |
| 365 | config.nlpMode = MapSetting(suppression_level_); |
| 366 | config.skewMode = drift_compensation_enabled_; |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 367 | config.delay_logging = delay_logging_enabled_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 368 | |
andrew@webrtc.org | 1760a17 | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 369 | WebRtcAec_enable_delay_correction(WebRtcAec_aec_core( |
| 370 | static_cast<Handle*>(handle)), delay_correction_enabled_ ? 1 : 0); |
bjornv@webrtc.org | e9d3760 | 2014-04-23 13:20:07 +0000 | [diff] [blame] | 371 | WebRtcAec_enable_reported_delay(WebRtcAec_aec_core( |
| 372 | static_cast<Handle*>(handle)), reported_delay_enabled_ ? 1 : 0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 373 | return WebRtcAec_set_config(static_cast<Handle*>(handle), config); |
| 374 | } |
| 375 | |
| 376 | int EchoCancellationImpl::num_handles_required() const { |
| 377 | return apm_->num_output_channels() * |
| 378 | apm_->num_reverse_channels(); |
| 379 | } |
| 380 | |
| 381 | int EchoCancellationImpl::GetHandleError(void* handle) const { |
| 382 | assert(handle != NULL); |
| 383 | return MapError(WebRtcAec_get_error_code(static_cast<Handle*>(handle))); |
| 384 | } |
| 385 | } // namespace webrtc |