blob: 961d9a47b0d6a97477a544f3dd75ec3321a3fe7f [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.org40654032012-01-30 20:51:15 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
andrew@webrtc.org78693fe2013-03-01 16:36:19 +000011#include "webrtc/modules/audio_processing/audio_processing_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
peah103ac7e2017-04-12 05:40:55 -070013#include <math.h>
Michael Graczyk86c6d332015-07-23 11:41:39 -070014#include <algorithm>
niklase@google.com470e71d2011-07-07 08:21:25 +000015
Bjorn Volcker1ca324f2015-06-29 14:57:29 +020016#include "webrtc/base/checks.h"
nisse368f5cf2017-04-05 05:00:33 -070017#include "webrtc/base/logging.h"
xians@webrtc.orge46bc772014-10-10 08:36:56 +000018#include "webrtc/base/platform_file.h"
peah369f8282015-12-17 06:42:29 -080019#include "webrtc/base/trace_event.h"
ekmeyerson60d9b332015-08-14 10:35:55 -070020#include "webrtc/common_audio/audio_converter.h"
Michael Graczykdfa36052015-03-25 16:37:27 -070021#include "webrtc/common_audio/channel_buffer.h"
ekmeyerson60d9b332015-08-14 10:35:55 -070022#include "webrtc/common_audio/include/audio_util.h"
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000023#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
Bjorn Volcker1ca324f2015-06-29 14:57:29 +020024#include "webrtc/modules/audio_processing/aec/aec_core.h"
peahe0eae3c2016-12-14 01:16:23 -080025#include "webrtc/modules/audio_processing/aec3/echo_canceller3.h"
pbos@webrtc.org788acd12014-12-15 09:41:24 +000026#include "webrtc/modules/audio_processing/agc/agc_manager_direct.h"
andrew@webrtc.org78693fe2013-03-01 16:36:19 +000027#include "webrtc/modules/audio_processing/audio_buffer.h"
mgraczyk@chromium.org0f663de2015-03-13 00:13:32 +000028#include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h"
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000029#include "webrtc/modules/audio_processing/common.h"
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000030#include "webrtc/modules/audio_processing/echo_cancellation_impl.h"
andrew@webrtc.org78693fe2013-03-01 16:36:19 +000031#include "webrtc/modules/audio_processing/echo_control_mobile_impl.h"
peahbe615622016-02-13 16:40:47 -080032#include "webrtc/modules/audio_processing/gain_control_for_experimental_agc.h"
andrew@webrtc.org78693fe2013-03-01 16:36:19 +000033#include "webrtc/modules/audio_processing/gain_control_impl.h"
peah1bcfce52016-08-26 07:16:04 -070034#if WEBRTC_INTELLIGIBILITY_ENHANCER
ekmeyerson60d9b332015-08-14 10:35:55 -070035#include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.h"
peah1bcfce52016-08-26 07:16:04 -070036#endif
peahca4cac72016-06-29 15:26:12 -070037#include "webrtc/modules/audio_processing/level_controller/level_controller.h"
andrew@webrtc.org78693fe2013-03-01 16:36:19 +000038#include "webrtc/modules/audio_processing/level_estimator_impl.h"
peah8271d042016-11-22 07:24:52 -080039#include "webrtc/modules/audio_processing/low_cut_filter.h"
andrew@webrtc.org78693fe2013-03-01 16:36:19 +000040#include "webrtc/modules/audio_processing/noise_suppression_impl.h"
ivoc9f4a4a02016-10-28 05:39:16 -070041#include "webrtc/modules/audio_processing/residual_echo_detector.h"
aluebs@webrtc.orgae643ce2014-12-19 19:57:34 +000042#include "webrtc/modules/audio_processing/transient/transient_suppressor.h"
andrew@webrtc.org78693fe2013-03-01 16:36:19 +000043#include "webrtc/modules/audio_processing/voice_detection_impl.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010044#include "webrtc/modules/include/module_common_types.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010045#include "webrtc/system_wrappers/include/file_wrapper.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010046#include "webrtc/system_wrappers/include/metrics.h"
andrew@webrtc.org7bf26462011-12-03 00:03:31 +000047
48#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
49// Files generated at build-time by the protobuf compiler.
leozwang@webrtc.orga3736342012-03-16 21:36:00 +000050#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
leozwang@webrtc.org534e4952012-10-22 21:21:52 +000051#include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h"
leozwang@google.comce9bfbb2011-08-03 23:34:31 +000052#else
kjellander78ddd732016-02-09 08:13:06 -080053#include "webrtc/modules/audio_processing/debug.pb.h"
leozwang@google.comce9bfbb2011-08-03 23:34:31 +000054#endif
andrew@webrtc.org7bf26462011-12-03 00:03:31 +000055#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
niklase@google.com470e71d2011-07-07 08:21:25 +000056
peah1bcfce52016-08-26 07:16:04 -070057// Check to verify that the define for the intelligibility enhancer is properly
58// set.
59#if !defined(WEBRTC_INTELLIGIBILITY_ENHANCER) || \
60 (WEBRTC_INTELLIGIBILITY_ENHANCER != 0 && \
61 WEBRTC_INTELLIGIBILITY_ENHANCER != 1)
62#error "Set WEBRTC_INTELLIGIBILITY_ENHANCER to either 0 or 1"
63#endif
64
Michael Graczyk86c6d332015-07-23 11:41:39 -070065#define RETURN_ON_ERR(expr) \
66 do { \
67 int err = (expr); \
68 if (err != kNoError) { \
69 return err; \
70 } \
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000071 } while (0)
72
niklase@google.com470e71d2011-07-07 08:21:25 +000073namespace webrtc {
aluebsdf6416a2016-03-16 18:26:35 -070074
kwibergd59d3bb2016-09-13 07:49:33 -070075constexpr int AudioProcessing::kNativeSampleRatesHz[];
aluebsdf6416a2016-03-16 18:26:35 -070076
Michael Graczyk86c6d332015-07-23 11:41:39 -070077namespace {
78
79static bool LayoutHasKeyboard(AudioProcessing::ChannelLayout layout) {
80 switch (layout) {
81 case AudioProcessing::kMono:
82 case AudioProcessing::kStereo:
83 return false;
84 case AudioProcessing::kMonoAndKeyboard:
85 case AudioProcessing::kStereoAndKeyboard:
86 return true;
87 }
88
kwiberg9e2be5f2016-09-14 05:23:22 -070089 RTC_NOTREACHED();
Michael Graczyk86c6d332015-07-23 11:41:39 -070090 return false;
91}
aluebsdf6416a2016-03-16 18:26:35 -070092
peah2ace3f92016-09-10 04:42:27 -070093bool SampleRateSupportsMultiBand(int sample_rate_hz) {
aluebsdf6416a2016-03-16 18:26:35 -070094 return sample_rate_hz == AudioProcessing::kSampleRate32kHz ||
95 sample_rate_hz == AudioProcessing::kSampleRate48kHz;
96}
97
peah2ace3f92016-09-10 04:42:27 -070098int FindNativeProcessRateToUse(int minimum_rate, bool band_splitting_required) {
99#ifdef WEBRTC_ARCH_ARM_FAMILY
kwibergd59d3bb2016-09-13 07:49:33 -0700100 constexpr int kMaxSplittingNativeProcessRate =
101 AudioProcessing::kSampleRate32kHz;
peah2ace3f92016-09-10 04:42:27 -0700102#else
kwibergd59d3bb2016-09-13 07:49:33 -0700103 constexpr int kMaxSplittingNativeProcessRate =
104 AudioProcessing::kSampleRate48kHz;
peah2ace3f92016-09-10 04:42:27 -0700105#endif
kwibergd59d3bb2016-09-13 07:49:33 -0700106 static_assert(
107 kMaxSplittingNativeProcessRate <= AudioProcessing::kMaxNativeSampleRateHz,
108 "");
peah2ace3f92016-09-10 04:42:27 -0700109 const int uppermost_native_rate = band_splitting_required
110 ? kMaxSplittingNativeProcessRate
111 : AudioProcessing::kSampleRate48kHz;
112
113 for (auto rate : AudioProcessing::kNativeSampleRatesHz) {
114 if (rate >= uppermost_native_rate) {
115 return uppermost_native_rate;
116 }
117 if (rate >= minimum_rate) {
aluebsdf6416a2016-03-16 18:26:35 -0700118 return rate;
119 }
120 }
peah2ace3f92016-09-10 04:42:27 -0700121 RTC_NOTREACHED();
122 return uppermost_native_rate;
aluebsdf6416a2016-03-16 18:26:35 -0700123}
124
peah9e6a2902017-05-15 07:19:21 -0700125// Maximum lengths that frame of samples being passed from the render side to
126// the capture side can have (does not apply to AEC3).
127static const size_t kMaxAllowedValuesOfSamplesPerBand = 160;
128static const size_t kMaxAllowedValuesOfSamplesPerFrame = 480;
129
peah764e3642016-10-22 05:04:30 -0700130// Maximum number of frames to buffer in the render queue.
131// TODO(peah): Decrease this once we properly handle hugely unbalanced
132// reverse and forward call numbers.
133static const size_t kMaxNumFramesToBuffer = 100;
134
peah8271d042016-11-22 07:24:52 -0800135class HighPassFilterImpl : public HighPassFilter {
136 public:
137 explicit HighPassFilterImpl(AudioProcessingImpl* apm) : apm_(apm) {}
138 ~HighPassFilterImpl() override = default;
139
140 // HighPassFilter implementation.
141 int Enable(bool enable) override {
142 apm_->MutateConfig([enable](AudioProcessing::Config* config) {
143 config->high_pass_filter.enabled = enable;
144 });
145
146 return AudioProcessing::kNoError;
147 }
148
149 bool is_enabled() const override {
150 return apm_->GetConfig().high_pass_filter.enabled;
151 }
152
153 private:
154 AudioProcessingImpl* apm_;
155 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(HighPassFilterImpl);
156};
157
Michael Graczyk86c6d332015-07-23 11:41:39 -0700158} // namespace
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000159
160// Throughout webrtc, it's assumed that success is represented by zero.
kwiberg@webrtc.org2ebfac52015-01-14 10:51:54 +0000161static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero");
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000162
peah2ace3f92016-09-10 04:42:27 -0700163AudioProcessingImpl::ApmSubmoduleStates::ApmSubmoduleStates() {}
164
165bool AudioProcessingImpl::ApmSubmoduleStates::Update(
peah8271d042016-11-22 07:24:52 -0800166 bool low_cut_filter_enabled,
peah2ace3f92016-09-10 04:42:27 -0700167 bool echo_canceller_enabled,
168 bool mobile_echo_controller_enabled,
ivoc9f4a4a02016-10-28 05:39:16 -0700169 bool residual_echo_detector_enabled,
peah2ace3f92016-09-10 04:42:27 -0700170 bool noise_suppressor_enabled,
171 bool intelligibility_enhancer_enabled,
172 bool beamformer_enabled,
173 bool adaptive_gain_controller_enabled,
174 bool level_controller_enabled,
peahe0eae3c2016-12-14 01:16:23 -0800175 bool echo_canceller3_enabled,
peah2ace3f92016-09-10 04:42:27 -0700176 bool voice_activity_detector_enabled,
177 bool level_estimator_enabled,
178 bool transient_suppressor_enabled) {
179 bool changed = false;
peah8271d042016-11-22 07:24:52 -0800180 changed |= (low_cut_filter_enabled != low_cut_filter_enabled_);
peah2ace3f92016-09-10 04:42:27 -0700181 changed |= (echo_canceller_enabled != echo_canceller_enabled_);
182 changed |=
183 (mobile_echo_controller_enabled != mobile_echo_controller_enabled_);
ivoc9f4a4a02016-10-28 05:39:16 -0700184 changed |=
185 (residual_echo_detector_enabled != residual_echo_detector_enabled_);
peah2ace3f92016-09-10 04:42:27 -0700186 changed |= (noise_suppressor_enabled != noise_suppressor_enabled_);
187 changed |=
188 (intelligibility_enhancer_enabled != intelligibility_enhancer_enabled_);
189 changed |= (beamformer_enabled != beamformer_enabled_);
190 changed |=
191 (adaptive_gain_controller_enabled != adaptive_gain_controller_enabled_);
192 changed |= (level_controller_enabled != level_controller_enabled_);
peahe0eae3c2016-12-14 01:16:23 -0800193 changed |= (echo_canceller3_enabled != echo_canceller3_enabled_);
peah2ace3f92016-09-10 04:42:27 -0700194 changed |= (level_estimator_enabled != level_estimator_enabled_);
195 changed |=
196 (voice_activity_detector_enabled != voice_activity_detector_enabled_);
197 changed |= (transient_suppressor_enabled != transient_suppressor_enabled_);
198 if (changed) {
peah8271d042016-11-22 07:24:52 -0800199 low_cut_filter_enabled_ = low_cut_filter_enabled;
peah2ace3f92016-09-10 04:42:27 -0700200 echo_canceller_enabled_ = echo_canceller_enabled;
201 mobile_echo_controller_enabled_ = mobile_echo_controller_enabled;
ivoc9f4a4a02016-10-28 05:39:16 -0700202 residual_echo_detector_enabled_ = residual_echo_detector_enabled;
peah2ace3f92016-09-10 04:42:27 -0700203 noise_suppressor_enabled_ = noise_suppressor_enabled;
204 intelligibility_enhancer_enabled_ = intelligibility_enhancer_enabled;
205 beamformer_enabled_ = beamformer_enabled;
206 adaptive_gain_controller_enabled_ = adaptive_gain_controller_enabled;
207 level_controller_enabled_ = level_controller_enabled;
peahe0eae3c2016-12-14 01:16:23 -0800208 echo_canceller3_enabled_ = echo_canceller3_enabled;
peah2ace3f92016-09-10 04:42:27 -0700209 level_estimator_enabled_ = level_estimator_enabled;
210 voice_activity_detector_enabled_ = voice_activity_detector_enabled;
211 transient_suppressor_enabled_ = transient_suppressor_enabled;
212 }
213
214 changed |= first_update_;
215 first_update_ = false;
216 return changed;
217}
218
219bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandSubModulesActive()
220 const {
221#if WEBRTC_INTELLIGIBILITY_ENHANCER
222 return CaptureMultiBandProcessingActive() ||
peah52775842017-05-16 06:14:09 -0700223 intelligibility_enhancer_enabled_ || voice_activity_detector_enabled_;
peah2ace3f92016-09-10 04:42:27 -0700224#else
peah52775842017-05-16 06:14:09 -0700225 return CaptureMultiBandProcessingActive() || voice_activity_detector_enabled_;
peah2ace3f92016-09-10 04:42:27 -0700226#endif
227}
228
229bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandProcessingActive()
230 const {
peah8271d042016-11-22 07:24:52 -0800231 return low_cut_filter_enabled_ || echo_canceller_enabled_ ||
peah2ace3f92016-09-10 04:42:27 -0700232 mobile_echo_controller_enabled_ || noise_suppressor_enabled_ ||
peahe0eae3c2016-12-14 01:16:23 -0800233 beamformer_enabled_ || adaptive_gain_controller_enabled_ ||
234 echo_canceller3_enabled_;
peah2ace3f92016-09-10 04:42:27 -0700235}
236
237bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandSubModulesActive()
238 const {
239 return RenderMultiBandProcessingActive() || echo_canceller_enabled_ ||
ivoc20270be2016-11-15 05:24:35 -0800240 mobile_echo_controller_enabled_ || adaptive_gain_controller_enabled_ ||
peah52775842017-05-16 06:14:09 -0700241 echo_canceller3_enabled_;
peah2ace3f92016-09-10 04:42:27 -0700242}
243
244bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandProcessingActive()
245 const {
246#if WEBRTC_INTELLIGIBILITY_ENHANCER
247 return intelligibility_enhancer_enabled_;
248#else
249 return false;
250#endif
251}
252
solenberg5e465c32015-12-08 13:22:33 -0800253struct AudioProcessingImpl::ApmPublicSubmodules {
peahbfa97112016-03-10 21:09:04 -0800254 ApmPublicSubmodules() {}
solenberg5e465c32015-12-08 13:22:33 -0800255 // Accessed externally of APM without any lock acquired.
peahb624d8c2016-03-05 03:01:14 -0800256 std::unique_ptr<EchoCancellationImpl> echo_cancellation;
peahbb9edbd2016-03-10 12:54:25 -0800257 std::unique_ptr<EchoControlMobileImpl> echo_control_mobile;
peahbfa97112016-03-10 21:09:04 -0800258 std::unique_ptr<GainControlImpl> gain_control;
kwiberg88788ad2016-02-19 07:04:49 -0800259 std::unique_ptr<LevelEstimatorImpl> level_estimator;
260 std::unique_ptr<NoiseSuppressionImpl> noise_suppression;
261 std::unique_ptr<VoiceDetectionImpl> voice_detection;
262 std::unique_ptr<GainControlForExperimentalAgc>
peahbe615622016-02-13 16:40:47 -0800263 gain_control_for_experimental_agc;
solenberg5e465c32015-12-08 13:22:33 -0800264
265 // Accessed internally from both render and capture.
kwiberg88788ad2016-02-19 07:04:49 -0800266 std::unique_ptr<TransientSuppressor> transient_suppressor;
peah1bcfce52016-08-26 07:16:04 -0700267#if WEBRTC_INTELLIGIBILITY_ENHANCER
kwiberg88788ad2016-02-19 07:04:49 -0800268 std::unique_ptr<IntelligibilityEnhancer> intelligibility_enhancer;
peah1bcfce52016-08-26 07:16:04 -0700269#endif
solenberg5e465c32015-12-08 13:22:33 -0800270};
271
272struct AudioProcessingImpl::ApmPrivateSubmodules {
Alejandro Luebsf4022ff2016-07-01 17:19:09 -0700273 explicit ApmPrivateSubmodules(NonlinearBeamformer* beamformer)
solenberg5e465c32015-12-08 13:22:33 -0800274 : beamformer(beamformer) {}
275 // Accessed internally from capture or during initialization
Alejandro Luebsf4022ff2016-07-01 17:19:09 -0700276 std::unique_ptr<NonlinearBeamformer> beamformer;
kwiberg88788ad2016-02-19 07:04:49 -0800277 std::unique_ptr<AgcManagerDirect> agc_manager;
peah8271d042016-11-22 07:24:52 -0800278 std::unique_ptr<LowCutFilter> low_cut_filter;
peahca4cac72016-06-29 15:26:12 -0700279 std::unique_ptr<LevelController> level_controller;
ivoc9f4a4a02016-10-28 05:39:16 -0700280 std::unique_ptr<ResidualEchoDetector> residual_echo_detector;
peahe0eae3c2016-12-14 01:16:23 -0800281 std::unique_ptr<EchoCanceller3> echo_canceller3;
solenberg5e465c32015-12-08 13:22:33 -0800282};
283
andrew@webrtc.orge84978f2014-01-25 02:09:06 +0000284AudioProcessing* AudioProcessing::Create() {
peah88ac8532016-09-12 16:47:25 -0700285 webrtc::Config config;
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +0000286 return Create(config, nullptr);
andrew@webrtc.orge84978f2014-01-25 02:09:06 +0000287}
288
peah88ac8532016-09-12 16:47:25 -0700289AudioProcessing* AudioProcessing::Create(const webrtc::Config& config) {
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +0000290 return Create(config, nullptr);
291}
292
peah88ac8532016-09-12 16:47:25 -0700293AudioProcessing* AudioProcessing::Create(const webrtc::Config& config,
Alejandro Luebsf4022ff2016-07-01 17:19:09 -0700294 NonlinearBeamformer* beamformer) {
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +0000295 AudioProcessingImpl* apm = new AudioProcessingImpl(config, beamformer);
niklase@google.com470e71d2011-07-07 08:21:25 +0000296 if (apm->Initialize() != kNoError) {
297 delete apm;
peahdf3efa82015-11-28 12:35:15 -0800298 apm = nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000299 }
300
301 return apm;
302}
303
peah88ac8532016-09-12 16:47:25 -0700304AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config)
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +0000305 : AudioProcessingImpl(config, nullptr) {}
306
peah88ac8532016-09-12 16:47:25 -0700307AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config,
Alejandro Luebsf4022ff2016-07-01 17:19:09 -0700308 NonlinearBeamformer* beamformer)
peah8271d042016-11-22 07:24:52 -0800309 : high_pass_filter_impl_(new HighPassFilterImpl(this)),
310 public_submodules_(new ApmPublicSubmodules()),
peahdf3efa82015-11-28 12:35:15 -0800311 private_submodules_(new ApmPrivateSubmodules(beamformer)),
312 constants_(config.Get<ExperimentalAgc>().startup_min_volume,
henrik.lundinbd681b92016-12-05 09:08:42 -0800313 config.Get<ExperimentalAgc>().clipped_level_min,
pbos@webrtc.org788acd12014-12-15 09:41:24 +0000314#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700315 false),
pbos@webrtc.org788acd12014-12-15 09:41:24 +0000316#else
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700317 config.Get<ExperimentalAgc>().enabled),
pbos@webrtc.org788acd12014-12-15 09:41:24 +0000318#endif
andrew1c7075f2015-06-24 18:14:14 -0700319#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
aluebs2a346882016-01-11 18:04:30 -0800320 capture_(false,
andrew1c7075f2015-06-24 18:14:14 -0700321#else
aluebs2a346882016-01-11 18:04:30 -0800322 capture_(config.Get<ExperimentalNs>().enabled,
andrew1c7075f2015-06-24 18:14:14 -0700323#endif
aluebs2a346882016-01-11 18:04:30 -0800324 config.Get<Beamforming>().array_geometry,
aluebsb2328d12016-01-11 20:32:29 -0800325 config.Get<Beamforming>().target_direction),
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700326 capture_nonlocked_(config.Get<Beamforming>().enabled,
peah88ac8532016-09-12 16:47:25 -0700327 config.Get<Intelligibility>().enabled) {
peahdf3efa82015-11-28 12:35:15 -0800328 {
329 rtc::CritScope cs_render(&crit_render_);
330 rtc::CritScope cs_capture(&crit_capture_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000331
peahb624d8c2016-03-05 03:01:14 -0800332 public_submodules_->echo_cancellation.reset(
peahb58a1582016-03-15 09:34:24 -0700333 new EchoCancellationImpl(&crit_render_, &crit_capture_));
peahbb9edbd2016-03-10 12:54:25 -0800334 public_submodules_->echo_control_mobile.reset(
peah253534d2016-03-15 04:32:28 -0700335 new EchoControlMobileImpl(&crit_render_, &crit_capture_));
peahbfa97112016-03-10 21:09:04 -0800336 public_submodules_->gain_control.reset(
peahb8fbb542016-03-15 02:28:08 -0700337 new GainControlImpl(&crit_capture_, &crit_capture_));
solenberg949028f2015-12-15 11:39:38 -0800338 public_submodules_->level_estimator.reset(
339 new LevelEstimatorImpl(&crit_capture_));
solenberg5e465c32015-12-08 13:22:33 -0800340 public_submodules_->noise_suppression.reset(
341 new NoiseSuppressionImpl(&crit_capture_));
solenberga29386c2015-12-16 03:31:12 -0800342 public_submodules_->voice_detection.reset(
343 new VoiceDetectionImpl(&crit_capture_));
peahbe615622016-02-13 16:40:47 -0800344 public_submodules_->gain_control_for_experimental_agc.reset(
peahbfa97112016-03-10 21:09:04 -0800345 new GainControlForExperimentalAgc(
346 public_submodules_->gain_control.get(), &crit_capture_));
ivoc9f4a4a02016-10-28 05:39:16 -0700347 private_submodules_->residual_echo_detector.reset(
348 new ResidualEchoDetector());
peahca4cac72016-06-29 15:26:12 -0700349
peahc19f3122016-10-07 14:54:10 -0700350 // TODO(peah): Move this creation to happen only when the level controller
351 // is enabled.
peahca4cac72016-06-29 15:26:12 -0700352 private_submodules_->level_controller.reset(new LevelController());
peahdf3efa82015-11-28 12:35:15 -0800353 }
pbos@webrtc.org788acd12014-12-15 09:41:24 +0000354
andrew@webrtc.orge84978f2014-01-25 02:09:06 +0000355 SetExtraOptions(config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000356}
357
358AudioProcessingImpl::~AudioProcessingImpl() {
peahdf3efa82015-11-28 12:35:15 -0800359 // Depends on gain_control_ and
peahbe615622016-02-13 16:40:47 -0800360 // public_submodules_->gain_control_for_experimental_agc.
peahdf3efa82015-11-28 12:35:15 -0800361 private_submodules_->agc_manager.reset();
362 // Depends on gain_control_.
peahbe615622016-02-13 16:40:47 -0800363 public_submodules_->gain_control_for_experimental_agc.reset();
niklase@google.com470e71d2011-07-07 08:21:25 +0000364
andrew@webrtc.org7bf26462011-12-03 00:03:31 +0000365#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
tommia6219cc2016-06-15 10:30:14 -0700366 debug_dump_.debug_file->CloseFile();
peahdf3efa82015-11-28 12:35:15 -0800367#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000368}
369
niklase@google.com470e71d2011-07-07 08:21:25 +0000370int AudioProcessingImpl::Initialize() {
peahdf3efa82015-11-28 12:35:15 -0800371 // Run in a single-threaded manner during initialization.
372 rtc::CritScope cs_render(&crit_render_);
373 rtc::CritScope cs_capture(&crit_capture_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000374 return InitializeLocked();
375}
376
peahde65ddc2016-09-16 15:02:15 -0700377int AudioProcessingImpl::Initialize(int capture_input_sample_rate_hz,
378 int capture_output_sample_rate_hz,
379 int render_input_sample_rate_hz,
380 ChannelLayout capture_input_layout,
381 ChannelLayout capture_output_layout,
382 ChannelLayout render_input_layout) {
Michael Graczyk86c6d332015-07-23 11:41:39 -0700383 const ProcessingConfig processing_config = {
peahde65ddc2016-09-16 15:02:15 -0700384 {{capture_input_sample_rate_hz, ChannelsFromLayout(capture_input_layout),
385 LayoutHasKeyboard(capture_input_layout)},
386 {capture_output_sample_rate_hz,
387 ChannelsFromLayout(capture_output_layout),
388 LayoutHasKeyboard(capture_output_layout)},
389 {render_input_sample_rate_hz, ChannelsFromLayout(render_input_layout),
390 LayoutHasKeyboard(render_input_layout)},
391 {render_input_sample_rate_hz, ChannelsFromLayout(render_input_layout),
392 LayoutHasKeyboard(render_input_layout)}}};
Michael Graczyk86c6d332015-07-23 11:41:39 -0700393
394 return Initialize(processing_config);
395}
396
397int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) {
peahdf3efa82015-11-28 12:35:15 -0800398 // Run in a single-threaded manner during initialization.
399 rtc::CritScope cs_render(&crit_render_);
400 rtc::CritScope cs_capture(&crit_capture_);
Michael Graczyk86c6d332015-07-23 11:41:39 -0700401 return InitializeLocked(processing_config);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000402}
403
peahdf3efa82015-11-28 12:35:15 -0800404int AudioProcessingImpl::MaybeInitializeRender(
peah81b9bfe2015-11-27 02:47:28 -0800405 const ProcessingConfig& processing_config) {
peah2ace3f92016-09-10 04:42:27 -0700406 return MaybeInitialize(processing_config, false);
peah81b9bfe2015-11-27 02:47:28 -0800407}
408
peahdf3efa82015-11-28 12:35:15 -0800409int AudioProcessingImpl::MaybeInitializeCapture(
peah2ace3f92016-09-10 04:42:27 -0700410 const ProcessingConfig& processing_config,
411 bool force_initialization) {
412 return MaybeInitialize(processing_config, force_initialization);
peah81b9bfe2015-11-27 02:47:28 -0800413}
414
kwiberg83ffe452016-08-29 14:46:07 -0700415#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
416
417AudioProcessingImpl::ApmDebugDumpThreadState::ApmDebugDumpThreadState()
418 : event_msg(new audioproc::Event()) {}
419
420AudioProcessingImpl::ApmDebugDumpThreadState::~ApmDebugDumpThreadState() {}
421
422AudioProcessingImpl::ApmDebugDumpState::ApmDebugDumpState()
423 : debug_file(FileWrapper::Create()) {}
424
425AudioProcessingImpl::ApmDebugDumpState::~ApmDebugDumpState() {}
426
427#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
428
peah192164e2015-11-17 02:16:45 -0800429// Calls InitializeLocked() if any of the audio parameters have changed from
peahdf3efa82015-11-28 12:35:15 -0800430// their current values (needs to be called while holding the crit_render_lock).
431int AudioProcessingImpl::MaybeInitialize(
peah2ace3f92016-09-10 04:42:27 -0700432 const ProcessingConfig& processing_config,
433 bool force_initialization) {
peahdf3efa82015-11-28 12:35:15 -0800434 // Called from both threads. Thread check is therefore not possible.
peah2ace3f92016-09-10 04:42:27 -0700435 if (processing_config == formats_.api_format && !force_initialization) {
peah192164e2015-11-17 02:16:45 -0800436 return kNoError;
437 }
peahdf3efa82015-11-28 12:35:15 -0800438
439 rtc::CritScope cs_capture(&crit_capture_);
peah192164e2015-11-17 02:16:45 -0800440 return InitializeLocked(processing_config);
441}
442
niklase@google.com470e71d2011-07-07 08:21:25 +0000443int AudioProcessingImpl::InitializeLocked() {
peah522d71b2017-02-23 05:16:26 -0800444 const int capture_audiobuffer_num_channels =
445 capture_nonlocked_.beamformer_enabled
446 ? formats_.api_format.input_stream().num_channels()
447 : formats_.api_format.output_stream().num_channels();
448
peahde65ddc2016-09-16 15:02:15 -0700449 const int render_audiobuffer_num_output_frames =
peahdf3efa82015-11-28 12:35:15 -0800450 formats_.api_format.reverse_output_stream().num_frames() == 0
peahde65ddc2016-09-16 15:02:15 -0700451 ? formats_.render_processing_format.num_frames()
peahdf3efa82015-11-28 12:35:15 -0800452 : formats_.api_format.reverse_output_stream().num_frames();
453 if (formats_.api_format.reverse_input_stream().num_channels() > 0) {
454 render_.render_audio.reset(new AudioBuffer(
455 formats_.api_format.reverse_input_stream().num_frames(),
456 formats_.api_format.reverse_input_stream().num_channels(),
peahde65ddc2016-09-16 15:02:15 -0700457 formats_.render_processing_format.num_frames(),
458 formats_.render_processing_format.num_channels(),
459 render_audiobuffer_num_output_frames));
peah2ace3f92016-09-10 04:42:27 -0700460 if (formats_.api_format.reverse_input_stream() !=
461 formats_.api_format.reverse_output_stream()) {
kwibergc2b785d2016-02-24 05:22:32 -0800462 render_.render_converter = AudioConverter::Create(
peahdf3efa82015-11-28 12:35:15 -0800463 formats_.api_format.reverse_input_stream().num_channels(),
464 formats_.api_format.reverse_input_stream().num_frames(),
465 formats_.api_format.reverse_output_stream().num_channels(),
kwibergc2b785d2016-02-24 05:22:32 -0800466 formats_.api_format.reverse_output_stream().num_frames());
ekmeyerson60d9b332015-08-14 10:35:55 -0700467 } else {
peahdf3efa82015-11-28 12:35:15 -0800468 render_.render_converter.reset(nullptr);
ekmeyerson60d9b332015-08-14 10:35:55 -0700469 }
Michael Graczyk86c6d332015-07-23 11:41:39 -0700470 } else {
peahdf3efa82015-11-28 12:35:15 -0800471 render_.render_audio.reset(nullptr);
472 render_.render_converter.reset(nullptr);
Michael Graczyk86c6d332015-07-23 11:41:39 -0700473 }
peahce4d9152017-05-19 01:28:05 -0700474
peahdf3efa82015-11-28 12:35:15 -0800475 capture_.capture_audio.reset(
476 new AudioBuffer(formats_.api_format.input_stream().num_frames(),
477 formats_.api_format.input_stream().num_channels(),
peahde65ddc2016-09-16 15:02:15 -0700478 capture_nonlocked_.capture_processing_format.num_frames(),
479 capture_audiobuffer_num_channels,
peahdf3efa82015-11-28 12:35:15 -0800480 formats_.api_format.output_stream().num_frames()));
niklase@google.com470e71d2011-07-07 08:21:25 +0000481
peahde65ddc2016-09-16 15:02:15 -0700482 public_submodules_->echo_cancellation->Initialize(
483 proc_sample_rate_hz(), num_reverse_channels(), num_output_channels(),
484 num_proc_channels());
peah764e3642016-10-22 05:04:30 -0700485 AllocateRenderQueue();
486
ivoc3e9a5372016-10-28 07:55:33 -0700487 int success = public_submodules_->echo_cancellation->enable_metrics(true);
488 RTC_DCHECK_EQ(0, success);
489 success = public_submodules_->echo_cancellation->enable_delay_logging(true);
490 RTC_DCHECK_EQ(0, success);
peahde65ddc2016-09-16 15:02:15 -0700491 public_submodules_->echo_control_mobile->Initialize(
492 proc_split_sample_rate_hz(), num_reverse_channels(),
493 num_output_channels());
peah135259a2016-10-28 03:12:11 -0700494
495 public_submodules_->gain_control->Initialize(num_proc_channels(),
496 proc_sample_rate_hz());
peahde65ddc2016-09-16 15:02:15 -0700497 if (constants_.use_experimental_agc) {
498 if (!private_submodules_->agc_manager.get()) {
499 private_submodules_->agc_manager.reset(new AgcManagerDirect(
500 public_submodules_->gain_control.get(),
501 public_submodules_->gain_control_for_experimental_agc.get(),
henrik.lundinbd681b92016-12-05 09:08:42 -0800502 constants_.agc_startup_min_volume, constants_.agc_clipped_level_min));
peahde65ddc2016-09-16 15:02:15 -0700503 }
504 private_submodules_->agc_manager->Initialize();
505 private_submodules_->agc_manager->SetCaptureMuted(
506 capture_.output_will_be_muted);
peah135259a2016-10-28 03:12:11 -0700507 public_submodules_->gain_control_for_experimental_agc->Initialize();
peahde65ddc2016-09-16 15:02:15 -0700508 }
Bjorn Volckeradc46c42015-04-15 11:42:40 +0200509 InitializeTransient();
aluebs@webrtc.orgae643ce2014-12-19 19:57:34 +0000510 InitializeBeamformer();
peah1bcfce52016-08-26 07:16:04 -0700511#if WEBRTC_INTELLIGIBILITY_ENHANCER
ekmeyerson60d9b332015-08-14 10:35:55 -0700512 InitializeIntelligibility();
peah1bcfce52016-08-26 07:16:04 -0700513#endif
peah8271d042016-11-22 07:24:52 -0800514 InitializeLowCutFilter();
peahde65ddc2016-09-16 15:02:15 -0700515 public_submodules_->noise_suppression->Initialize(num_proc_channels(),
516 proc_sample_rate_hz());
517 public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz());
518 public_submodules_->level_estimator->Initialize();
peahca4cac72016-06-29 15:26:12 -0700519 InitializeLevelController();
ivoc9f4a4a02016-10-28 05:39:16 -0700520 InitializeResidualEchoDetector();
peahe0eae3c2016-12-14 01:16:23 -0800521 InitializeEchoCanceller3();
solenberg70f99032015-12-08 11:07:32 -0800522
andrew@webrtc.org7bf26462011-12-03 00:03:31 +0000523#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
tommia6219cc2016-06-15 10:30:14 -0700524 if (debug_dump_.debug_file->is_open()) {
ajm@google.com808e0e02011-08-03 21:08:51 +0000525 int err = WriteInitMessage();
526 if (err != kNoError) {
527 return err;
528 }
529 }
andrew@webrtc.org7bf26462011-12-03 00:03:31 +0000530#endif
ajm@google.com808e0e02011-08-03 21:08:51 +0000531
niklase@google.com470e71d2011-07-07 08:21:25 +0000532 return kNoError;
533}
534
Michael Graczyk86c6d332015-07-23 11:41:39 -0700535int AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) {
536 for (const auto& stream : config.streams) {
Michael Graczyk86c6d332015-07-23 11:41:39 -0700537 if (stream.num_channels() > 0 && stream.sample_rate_hz() <= 0) {
538 return kBadSampleRateError;
539 }
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000540 }
Michael Graczyk86c6d332015-07-23 11:41:39 -0700541
Peter Kasting69558702016-01-12 16:26:35 -0800542 const size_t num_in_channels = config.input_stream().num_channels();
543 const size_t num_out_channels = config.output_stream().num_channels();
Michael Graczyk86c6d332015-07-23 11:41:39 -0700544
545 // Need at least one input channel.
546 // Need either one output channel or as many outputs as there are inputs.
547 if (num_in_channels == 0 ||
548 !(num_out_channels == 1 || num_out_channels == num_in_channels)) {
Michael Graczykc2047542015-07-22 21:06:11 -0700549 return kBadNumberChannelsError;
550 }
551
aluebsb2328d12016-01-11 20:32:29 -0800552 if (capture_nonlocked_.beamformer_enabled &&
Peter Kasting69558702016-01-12 16:26:35 -0800553 num_in_channels != capture_.array_geometry.size()) {
Michael Graczyk86c6d332015-07-23 11:41:39 -0700554 return kBadNumberChannelsError;
555 }
556
peahdf3efa82015-11-28 12:35:15 -0800557 formats_.api_format = config;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000558
peahde65ddc2016-09-16 15:02:15 -0700559 int capture_processing_rate = FindNativeProcessRateToUse(
peah423d2362016-04-09 16:06:52 -0700560 std::min(formats_.api_format.input_stream().sample_rate_hz(),
peah2ace3f92016-09-10 04:42:27 -0700561 formats_.api_format.output_stream().sample_rate_hz()),
562 submodule_states_.CaptureMultiBandSubModulesActive() ||
563 submodule_states_.RenderMultiBandSubModulesActive());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000564
peahde65ddc2016-09-16 15:02:15 -0700565 capture_nonlocked_.capture_processing_format =
566 StreamConfig(capture_processing_rate);
peah2ace3f92016-09-10 04:42:27 -0700567
peah2ce640f2017-04-07 03:57:48 -0700568 int render_processing_rate;
569 if (!config_.echo_canceller3.enabled) {
570 render_processing_rate = FindNativeProcessRateToUse(
571 std::min(formats_.api_format.reverse_input_stream().sample_rate_hz(),
572 formats_.api_format.reverse_output_stream().sample_rate_hz()),
573 submodule_states_.CaptureMultiBandSubModulesActive() ||
574 submodule_states_.RenderMultiBandSubModulesActive());
575 } else {
576 render_processing_rate = capture_processing_rate;
577 }
578
aluebseb3603b2016-04-20 15:27:58 -0700579 // TODO(aluebs): Remove this restriction once we figure out why the 3-band
580 // splitting filter degrades the AEC performance.
peahcf02cf12017-04-05 14:18:07 -0700581 if (render_processing_rate > kSampleRate32kHz &&
582 !config_.echo_canceller3.enabled) {
peahde65ddc2016-09-16 15:02:15 -0700583 render_processing_rate = submodule_states_.RenderMultiBandProcessingActive()
584 ? kSampleRate32kHz
585 : kSampleRate16kHz;
aluebseb3603b2016-04-20 15:27:58 -0700586 }
peah2ce640f2017-04-07 03:57:48 -0700587
peahde65ddc2016-09-16 15:02:15 -0700588 // If the forward sample rate is 8 kHz, the render stream is also processed
aluebseb3603b2016-04-20 15:27:58 -0700589 // at this rate.
peahde65ddc2016-09-16 15:02:15 -0700590 if (capture_nonlocked_.capture_processing_format.sample_rate_hz() ==
591 kSampleRate8kHz) {
592 render_processing_rate = kSampleRate8kHz;
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000593 } else {
peahde65ddc2016-09-16 15:02:15 -0700594 render_processing_rate =
595 std::max(render_processing_rate, static_cast<int>(kSampleRate16kHz));
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000596 }
597
peahde65ddc2016-09-16 15:02:15 -0700598 // Always downmix the render stream to mono for analysis. This has been
andrew@webrtc.org30be8272014-09-24 20:06:23 +0000599 // demonstrated to work well for AEC in most practical scenarios.
peahce4d9152017-05-19 01:28:05 -0700600 if (submodule_states_.RenderMultiBandSubModulesActive()) {
601 formats_.render_processing_format = StreamConfig(render_processing_rate, 1);
602 } else {
603 formats_.render_processing_format = StreamConfig(
604 formats_.api_format.reverse_input_stream().sample_rate_hz(),
605 formats_.api_format.reverse_input_stream().num_channels());
606 }
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000607
peahde65ddc2016-09-16 15:02:15 -0700608 if (capture_nonlocked_.capture_processing_format.sample_rate_hz() ==
609 kSampleRate32kHz ||
610 capture_nonlocked_.capture_processing_format.sample_rate_hz() ==
611 kSampleRate48kHz) {
peahdf3efa82015-11-28 12:35:15 -0800612 capture_nonlocked_.split_rate = kSampleRate16kHz;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000613 } else {
peahdf3efa82015-11-28 12:35:15 -0800614 capture_nonlocked_.split_rate =
peahde65ddc2016-09-16 15:02:15 -0700615 capture_nonlocked_.capture_processing_format.sample_rate_hz();
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000616 }
617
618 return InitializeLocked();
619}
620
peah88ac8532016-09-12 16:47:25 -0700621void AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) {
peahc19f3122016-10-07 14:54:10 -0700622 config_ = config;
peah88ac8532016-09-12 16:47:25 -0700623
peahc19f3122016-10-07 14:54:10 -0700624 bool config_ok = LevelController::Validate(config_.level_controller);
peah88ac8532016-09-12 16:47:25 -0700625 if (!config_ok) {
626 LOG(LS_ERROR) << "AudioProcessing module config error" << std::endl
627 << "level_controller: "
peahc19f3122016-10-07 14:54:10 -0700628 << LevelController::ToString(config_.level_controller)
peah88ac8532016-09-12 16:47:25 -0700629 << std::endl
630 << "Reverting to default parameter set";
peahc19f3122016-10-07 14:54:10 -0700631 config_.level_controller = AudioProcessing::Config::LevelController();
peah88ac8532016-09-12 16:47:25 -0700632 }
633
634 // Run in a single-threaded manner when applying the settings.
635 rtc::CritScope cs_render(&crit_render_);
636 rtc::CritScope cs_capture(&crit_capture_);
637
peahc19f3122016-10-07 14:54:10 -0700638 // TODO(peah): Replace the use of capture_nonlocked_.level_controller_enabled
639 // with the value in config_ everywhere in the code.
640 if (capture_nonlocked_.level_controller_enabled !=
641 config_.level_controller.enabled) {
peah88ac8532016-09-12 16:47:25 -0700642 capture_nonlocked_.level_controller_enabled =
peahc19f3122016-10-07 14:54:10 -0700643 config_.level_controller.enabled;
644 // TODO(peah): Remove the conditional initialization to always initialize
645 // the level controller regardless of whether it is enabled or not.
646 InitializeLevelController();
peah88ac8532016-09-12 16:47:25 -0700647 }
peahc19f3122016-10-07 14:54:10 -0700648 LOG(LS_INFO) << "Level controller activated: "
649 << capture_nonlocked_.level_controller_enabled;
650
651 private_submodules_->level_controller->ApplyConfig(config_.level_controller);
peah8271d042016-11-22 07:24:52 -0800652
653 InitializeLowCutFilter();
654
655 LOG(LS_INFO) << "Highpass filter activated: "
656 << config_.high_pass_filter.enabled;
peahe0eae3c2016-12-14 01:16:23 -0800657
658 config_ok = EchoCanceller3::Validate(config_.echo_canceller3);
659 if (!config_ok) {
660 LOG(LS_ERROR) << "AudioProcessing module config error" << std::endl
661 << "echo canceller 3: "
662 << EchoCanceller3::ToString(config_.echo_canceller3)
663 << std::endl
664 << "Reverting to default parameter set";
665 config_.echo_canceller3 = AudioProcessing::Config::EchoCanceller3();
666 }
667
668 if (config.echo_canceller3.enabled !=
669 capture_nonlocked_.echo_canceller3_enabled) {
670 capture_nonlocked_.echo_canceller3_enabled =
671 config_.echo_canceller3.enabled;
672 InitializeEchoCanceller3();
673 LOG(LS_INFO) << "Echo canceller 3 activated: "
674 << capture_nonlocked_.echo_canceller3_enabled;
675 }
peah88ac8532016-09-12 16:47:25 -0700676}
677
678void AudioProcessingImpl::SetExtraOptions(const webrtc::Config& config) {
peahdf3efa82015-11-28 12:35:15 -0800679 // Run in a single-threaded manner when setting the extra options.
680 rtc::CritScope cs_render(&crit_render_);
681 rtc::CritScope cs_capture(&crit_capture_);
pbos@webrtc.org788acd12014-12-15 09:41:24 +0000682
peahb624d8c2016-03-05 03:01:14 -0800683 public_submodules_->echo_cancellation->SetExtraOptions(config);
684
peahdf3efa82015-11-28 12:35:15 -0800685 if (capture_.transient_suppressor_enabled !=
686 config.Get<ExperimentalNs>().enabled) {
687 capture_.transient_suppressor_enabled =
688 config.Get<ExperimentalNs>().enabled;
pbos@webrtc.org788acd12014-12-15 09:41:24 +0000689 InitializeTransient();
690 }
aluebs2a346882016-01-11 18:04:30 -0800691
peah1bcfce52016-08-26 07:16:04 -0700692#if WEBRTC_INTELLIGIBILITY_ENHANCER
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700693 if(capture_nonlocked_.intelligibility_enabled !=
694 config.Get<Intelligibility>().enabled) {
695 capture_nonlocked_.intelligibility_enabled =
696 config.Get<Intelligibility>().enabled;
697 InitializeIntelligibility();
698 }
peah1bcfce52016-08-26 07:16:04 -0700699#endif
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700700
aluebs2a346882016-01-11 18:04:30 -0800701#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
aluebsb2328d12016-01-11 20:32:29 -0800702 if (capture_nonlocked_.beamformer_enabled !=
703 config.Get<Beamforming>().enabled) {
704 capture_nonlocked_.beamformer_enabled = config.Get<Beamforming>().enabled;
aluebs2a346882016-01-11 18:04:30 -0800705 if (config.Get<Beamforming>().array_geometry.size() > 1) {
706 capture_.array_geometry = config.Get<Beamforming>().array_geometry;
707 }
708 capture_.target_direction = config.Get<Beamforming>().target_direction;
709 InitializeBeamformer();
710 }
711#endif // WEBRTC_ANDROID_PLATFORM_BUILD
andrew@webrtc.org61e596f2013-07-25 18:28:29 +0000712}
713
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000714int AudioProcessingImpl::proc_sample_rate_hz() const {
peahdf3efa82015-11-28 12:35:15 -0800715 // Used as callback from submodules, hence locking is not allowed.
peahde65ddc2016-09-16 15:02:15 -0700716 return capture_nonlocked_.capture_processing_format.sample_rate_hz();
niklase@google.com470e71d2011-07-07 08:21:25 +0000717}
718
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000719int AudioProcessingImpl::proc_split_sample_rate_hz() const {
peahdf3efa82015-11-28 12:35:15 -0800720 // Used as callback from submodules, hence locking is not allowed.
721 return capture_nonlocked_.split_rate;
niklase@google.com470e71d2011-07-07 08:21:25 +0000722}
723
Peter Kasting69558702016-01-12 16:26:35 -0800724size_t AudioProcessingImpl::num_reverse_channels() const {
peahdf3efa82015-11-28 12:35:15 -0800725 // Used as callback from submodules, hence locking is not allowed.
peahde65ddc2016-09-16 15:02:15 -0700726 return formats_.render_processing_format.num_channels();
niklase@google.com470e71d2011-07-07 08:21:25 +0000727}
728
Peter Kasting69558702016-01-12 16:26:35 -0800729size_t AudioProcessingImpl::num_input_channels() const {
peahdf3efa82015-11-28 12:35:15 -0800730 // Used as callback from submodules, hence locking is not allowed.
731 return formats_.api_format.input_stream().num_channels();
niklase@google.com470e71d2011-07-07 08:21:25 +0000732}
733
Peter Kasting69558702016-01-12 16:26:35 -0800734size_t AudioProcessingImpl::num_proc_channels() const {
aluebsb2328d12016-01-11 20:32:29 -0800735 // Used as callback from submodules, hence locking is not allowed.
peahedddac52017-05-16 01:08:58 -0700736 return (capture_nonlocked_.beamformer_enabled ||
737 capture_nonlocked_.echo_canceller3_enabled)
738 ? 1
739 : num_output_channels();
aluebsb2328d12016-01-11 20:32:29 -0800740}
741
Peter Kasting69558702016-01-12 16:26:35 -0800742size_t AudioProcessingImpl::num_output_channels() const {
peahdf3efa82015-11-28 12:35:15 -0800743 // Used as callback from submodules, hence locking is not allowed.
744 return formats_.api_format.output_stream().num_channels();
niklase@google.com470e71d2011-07-07 08:21:25 +0000745}
746
andrew@webrtc.org17342e52014-02-12 22:28:31 +0000747void AudioProcessingImpl::set_output_will_be_muted(bool muted) {
peahdf3efa82015-11-28 12:35:15 -0800748 rtc::CritScope cs(&crit_capture_);
749 capture_.output_will_be_muted = muted;
750 if (private_submodules_->agc_manager.get()) {
751 private_submodules_->agc_manager->SetCaptureMuted(
752 capture_.output_will_be_muted);
pbos@webrtc.org788acd12014-12-15 09:41:24 +0000753 }
andrew@webrtc.org17342e52014-02-12 22:28:31 +0000754}
755
andrew@webrtc.org17342e52014-02-12 22:28:31 +0000756
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000757int AudioProcessingImpl::ProcessStream(const float* const* src,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700758 size_t samples_per_channel,
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000759 int input_sample_rate_hz,
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000760 ChannelLayout input_layout,
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000761 int output_sample_rate_hz,
762 ChannelLayout output_layout,
763 float* const* dest) {
peah369f8282015-12-17 06:42:29 -0800764 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_ChannelLayout");
peahdf3efa82015-11-28 12:35:15 -0800765 StreamConfig input_stream;
766 StreamConfig output_stream;
767 {
768 // Access the formats_.api_format.input_stream beneath the capture lock.
769 // The lock must be released as it is later required in the call
770 // to ProcessStream(,,,);
771 rtc::CritScope cs(&crit_capture_);
772 input_stream = formats_.api_format.input_stream();
773 output_stream = formats_.api_format.output_stream();
774 }
775
Michael Graczyk86c6d332015-07-23 11:41:39 -0700776 input_stream.set_sample_rate_hz(input_sample_rate_hz);
777 input_stream.set_num_channels(ChannelsFromLayout(input_layout));
778 input_stream.set_has_keyboard(LayoutHasKeyboard(input_layout));
Michael Graczyk86c6d332015-07-23 11:41:39 -0700779 output_stream.set_sample_rate_hz(output_sample_rate_hz);
780 output_stream.set_num_channels(ChannelsFromLayout(output_layout));
781 output_stream.set_has_keyboard(LayoutHasKeyboard(output_layout));
782
783 if (samples_per_channel != input_stream.num_frames()) {
784 return kBadDataLengthError;
785 }
786 return ProcessStream(src, input_stream, output_stream, dest);
787}
788
789int AudioProcessingImpl::ProcessStream(const float* const* src,
790 const StreamConfig& input_config,
791 const StreamConfig& output_config,
792 float* const* dest) {
peah369f8282015-12-17 06:42:29 -0800793 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_StreamConfig");
peahdf3efa82015-11-28 12:35:15 -0800794 ProcessingConfig processing_config;
peah2ace3f92016-09-10 04:42:27 -0700795 bool reinitialization_required = false;
peahdf3efa82015-11-28 12:35:15 -0800796 {
797 // Acquire the capture lock in order to safely call the function
798 // that retrieves the render side data. This function accesses apm
799 // getters that need the capture lock held when being called.
800 rtc::CritScope cs_capture(&crit_capture_);
peah764e3642016-10-22 05:04:30 -0700801 EmptyQueuedRenderAudio();
peahdf3efa82015-11-28 12:35:15 -0800802
803 if (!src || !dest) {
804 return kNullPointerError;
805 }
806
807 processing_config = formats_.api_format;
peah2ace3f92016-09-10 04:42:27 -0700808 reinitialization_required = UpdateActiveSubmoduleStates();
niklase@google.com470e71d2011-07-07 08:21:25 +0000809 }
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000810
Michael Graczyk86c6d332015-07-23 11:41:39 -0700811 processing_config.input_stream() = input_config;
812 processing_config.output_stream() = output_config;
813
peahdf3efa82015-11-28 12:35:15 -0800814 {
815 // Do conditional reinitialization.
816 rtc::CritScope cs_render(&crit_render_);
peah2ace3f92016-09-10 04:42:27 -0700817 RETURN_ON_ERR(
818 MaybeInitializeCapture(processing_config, reinitialization_required));
peahdf3efa82015-11-28 12:35:15 -0800819 }
820 rtc::CritScope cs_capture(&crit_capture_);
kwiberg9e2be5f2016-09-14 05:23:22 -0700821 RTC_DCHECK_EQ(processing_config.input_stream().num_frames(),
822 formats_.api_format.input_stream().num_frames());
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000823
824#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
tommia6219cc2016-06-15 10:30:14 -0700825 if (debug_dump_.debug_file->is_open()) {
Minyue13b96ba2015-10-03 00:39:14 +0200826 RETURN_ON_ERR(WriteConfigMessage(false));
827
peahdf3efa82015-11-28 12:35:15 -0800828 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM);
829 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
aluebs@webrtc.org59a1b1b2014-08-28 10:43:09 +0000830 const size_t channel_size =
peahdf3efa82015-11-28 12:35:15 -0800831 sizeof(float) * formats_.api_format.input_stream().num_frames();
Peter Kasting69558702016-01-12 16:26:35 -0800832 for (size_t i = 0; i < formats_.api_format.input_stream().num_channels();
833 ++i)
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000834 msg->add_input_channel(src[i], channel_size);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000835 }
836#endif
837
peahdf3efa82015-11-28 12:35:15 -0800838 capture_.capture_audio->CopyFrom(src, formats_.api_format.input_stream());
peahde65ddc2016-09-16 15:02:15 -0700839 RETURN_ON_ERR(ProcessCaptureStreamLocked());
peahdf3efa82015-11-28 12:35:15 -0800840 capture_.capture_audio->CopyTo(formats_.api_format.output_stream(), dest);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000841
842#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
tommia6219cc2016-06-15 10:30:14 -0700843 if (debug_dump_.debug_file->is_open()) {
peahdf3efa82015-11-28 12:35:15 -0800844 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
aluebs@webrtc.org59a1b1b2014-08-28 10:43:09 +0000845 const size_t channel_size =
peahdf3efa82015-11-28 12:35:15 -0800846 sizeof(float) * formats_.api_format.output_stream().num_frames();
Peter Kasting69558702016-01-12 16:26:35 -0800847 for (size_t i = 0; i < formats_.api_format.output_stream().num_channels();
848 ++i)
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000849 msg->add_output_channel(dest[i], channel_size);
peahdf3efa82015-11-28 12:35:15 -0800850 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
ivocd66b44d2016-01-15 03:06:36 -0800851 &debug_dump_.num_bytes_left_for_log_,
peahdf3efa82015-11-28 12:35:15 -0800852 &crit_debug_, &debug_dump_.capture));
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000853 }
854#endif
855
856 return kNoError;
857}
858
peah9e6a2902017-05-15 07:19:21 -0700859void AudioProcessingImpl::QueueBandedRenderAudio(AudioBuffer* audio) {
peah764e3642016-10-22 05:04:30 -0700860 EchoCancellationImpl::PackRenderAudioBuffer(audio, num_output_channels(),
861 num_reverse_channels(),
peah701d6282016-10-25 05:42:20 -0700862 &aec_render_queue_buffer_);
peah764e3642016-10-22 05:04:30 -0700863
kwibergaf476c72016-11-28 15:21:39 -0800864 RTC_DCHECK_GE(160, audio->num_frames_per_band());
peah764e3642016-10-22 05:04:30 -0700865
866 // Insert the samples into the queue.
peah701d6282016-10-25 05:42:20 -0700867 if (!aec_render_signal_queue_->Insert(&aec_render_queue_buffer_)) {
peah764e3642016-10-22 05:04:30 -0700868 // The data queue is full and needs to be emptied.
869 EmptyQueuedRenderAudio();
870
871 // Retry the insert (should always work).
peah701d6282016-10-25 05:42:20 -0700872 bool result = aec_render_signal_queue_->Insert(&aec_render_queue_buffer_);
peaha0624602016-10-25 04:45:24 -0700873 RTC_DCHECK(result);
874 }
875
876 EchoControlMobileImpl::PackRenderAudioBuffer(audio, num_output_channels(),
877 num_reverse_channels(),
peah701d6282016-10-25 05:42:20 -0700878 &aecm_render_queue_buffer_);
peaha0624602016-10-25 04:45:24 -0700879
880 // Insert the samples into the queue.
peah701d6282016-10-25 05:42:20 -0700881 if (!aecm_render_signal_queue_->Insert(&aecm_render_queue_buffer_)) {
peaha0624602016-10-25 04:45:24 -0700882 // The data queue is full and needs to be emptied.
883 EmptyQueuedRenderAudio();
884
885 // Retry the insert (should always work).
peah701d6282016-10-25 05:42:20 -0700886 bool result = aecm_render_signal_queue_->Insert(&aecm_render_queue_buffer_);
peah764e3642016-10-22 05:04:30 -0700887 RTC_DCHECK(result);
888 }
peah701d6282016-10-25 05:42:20 -0700889
890 if (!constants_.use_experimental_agc) {
891 GainControlImpl::PackRenderAudioBuffer(audio, &agc_render_queue_buffer_);
892 // Insert the samples into the queue.
893 if (!agc_render_signal_queue_->Insert(&agc_render_queue_buffer_)) {
894 // The data queue is full and needs to be emptied.
895 EmptyQueuedRenderAudio();
896
897 // Retry the insert (should always work).
898 bool result = agc_render_signal_queue_->Insert(&agc_render_queue_buffer_);
899 RTC_DCHECK(result);
900 }
901 }
peah9e6a2902017-05-15 07:19:21 -0700902}
ivoc9f4a4a02016-10-28 05:39:16 -0700903
peah9e6a2902017-05-15 07:19:21 -0700904void AudioProcessingImpl::QueueNonbandedRenderAudio(AudioBuffer* audio) {
ivoc9f4a4a02016-10-28 05:39:16 -0700905 ResidualEchoDetector::PackRenderAudioBuffer(audio, &red_render_queue_buffer_);
906
907 // Insert the samples into the queue.
908 if (!red_render_signal_queue_->Insert(&red_render_queue_buffer_)) {
909 // The data queue is full and needs to be emptied.
910 EmptyQueuedRenderAudio();
911
912 // Retry the insert (should always work).
913 bool result = red_render_signal_queue_->Insert(&red_render_queue_buffer_);
914 RTC_DCHECK(result);
915 }
peah764e3642016-10-22 05:04:30 -0700916}
917
918void AudioProcessingImpl::AllocateRenderQueue() {
peah701d6282016-10-25 05:42:20 -0700919 const size_t new_aec_render_queue_element_max_size =
peah764e3642016-10-22 05:04:30 -0700920 std::max(static_cast<size_t>(1),
peah9e6a2902017-05-15 07:19:21 -0700921 kMaxAllowedValuesOfSamplesPerBand *
peah764e3642016-10-22 05:04:30 -0700922 EchoCancellationImpl::NumCancellersRequired(
923 num_output_channels(), num_reverse_channels()));
924
peah701d6282016-10-25 05:42:20 -0700925 const size_t new_aecm_render_queue_element_max_size =
peaha0624602016-10-25 04:45:24 -0700926 std::max(static_cast<size_t>(1),
peah9e6a2902017-05-15 07:19:21 -0700927 kMaxAllowedValuesOfSamplesPerBand *
peaha0624602016-10-25 04:45:24 -0700928 EchoControlMobileImpl::NumCancellersRequired(
929 num_output_channels(), num_reverse_channels()));
peah764e3642016-10-22 05:04:30 -0700930
peah701d6282016-10-25 05:42:20 -0700931 const size_t new_agc_render_queue_element_max_size =
peah9e6a2902017-05-15 07:19:21 -0700932 std::max(static_cast<size_t>(1), kMaxAllowedValuesOfSamplesPerBand);
peah701d6282016-10-25 05:42:20 -0700933
ivoc9f4a4a02016-10-28 05:39:16 -0700934 const size_t new_red_render_queue_element_max_size =
935 std::max(static_cast<size_t>(1), kMaxAllowedValuesOfSamplesPerFrame);
936
peaha0624602016-10-25 04:45:24 -0700937 // Reallocate the queues if the queue item sizes are too small to fit the
938 // data to put in the queues.
peah701d6282016-10-25 05:42:20 -0700939 if (aec_render_queue_element_max_size_ <
940 new_aec_render_queue_element_max_size) {
941 aec_render_queue_element_max_size_ = new_aec_render_queue_element_max_size;
peah764e3642016-10-22 05:04:30 -0700942
peaha0624602016-10-25 04:45:24 -0700943 std::vector<float> template_queue_element(
peah701d6282016-10-25 05:42:20 -0700944 aec_render_queue_element_max_size_);
peaha0624602016-10-25 04:45:24 -0700945
peah701d6282016-10-25 05:42:20 -0700946 aec_render_signal_queue_.reset(
peah764e3642016-10-22 05:04:30 -0700947 new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>(
948 kMaxNumFramesToBuffer, template_queue_element,
peaha0624602016-10-25 04:45:24 -0700949 RenderQueueItemVerifier<float>(
peah701d6282016-10-25 05:42:20 -0700950 aec_render_queue_element_max_size_)));
peah764e3642016-10-22 05:04:30 -0700951
peah701d6282016-10-25 05:42:20 -0700952 aec_render_queue_buffer_.resize(aec_render_queue_element_max_size_);
953 aec_capture_queue_buffer_.resize(aec_render_queue_element_max_size_);
peah764e3642016-10-22 05:04:30 -0700954 } else {
peah701d6282016-10-25 05:42:20 -0700955 aec_render_signal_queue_->Clear();
peaha0624602016-10-25 04:45:24 -0700956 }
957
peah701d6282016-10-25 05:42:20 -0700958 if (aecm_render_queue_element_max_size_ <
959 new_aecm_render_queue_element_max_size) {
960 aecm_render_queue_element_max_size_ =
961 new_aecm_render_queue_element_max_size;
peaha0624602016-10-25 04:45:24 -0700962
963 std::vector<int16_t> template_queue_element(
peah701d6282016-10-25 05:42:20 -0700964 aecm_render_queue_element_max_size_);
peaha0624602016-10-25 04:45:24 -0700965
peah701d6282016-10-25 05:42:20 -0700966 aecm_render_signal_queue_.reset(
peaha0624602016-10-25 04:45:24 -0700967 new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>(
968 kMaxNumFramesToBuffer, template_queue_element,
969 RenderQueueItemVerifier<int16_t>(
peah701d6282016-10-25 05:42:20 -0700970 aecm_render_queue_element_max_size_)));
peaha0624602016-10-25 04:45:24 -0700971
peah701d6282016-10-25 05:42:20 -0700972 aecm_render_queue_buffer_.resize(aecm_render_queue_element_max_size_);
973 aecm_capture_queue_buffer_.resize(aecm_render_queue_element_max_size_);
peaha0624602016-10-25 04:45:24 -0700974 } else {
peah701d6282016-10-25 05:42:20 -0700975 aecm_render_signal_queue_->Clear();
976 }
977
978 if (agc_render_queue_element_max_size_ <
979 new_agc_render_queue_element_max_size) {
980 agc_render_queue_element_max_size_ = new_agc_render_queue_element_max_size;
981
982 std::vector<int16_t> template_queue_element(
983 agc_render_queue_element_max_size_);
984
985 agc_render_signal_queue_.reset(
986 new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>(
987 kMaxNumFramesToBuffer, template_queue_element,
988 RenderQueueItemVerifier<int16_t>(
989 agc_render_queue_element_max_size_)));
990
991 agc_render_queue_buffer_.resize(agc_render_queue_element_max_size_);
992 agc_capture_queue_buffer_.resize(agc_render_queue_element_max_size_);
993 } else {
994 agc_render_signal_queue_->Clear();
peah764e3642016-10-22 05:04:30 -0700995 }
ivoc9f4a4a02016-10-28 05:39:16 -0700996
997 if (red_render_queue_element_max_size_ <
998 new_red_render_queue_element_max_size) {
999 red_render_queue_element_max_size_ = new_red_render_queue_element_max_size;
1000
1001 std::vector<float> template_queue_element(
1002 red_render_queue_element_max_size_);
1003
1004 red_render_signal_queue_.reset(
1005 new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>(
1006 kMaxNumFramesToBuffer, template_queue_element,
1007 RenderQueueItemVerifier<float>(
1008 red_render_queue_element_max_size_)));
1009
1010 red_render_queue_buffer_.resize(red_render_queue_element_max_size_);
1011 red_capture_queue_buffer_.resize(red_render_queue_element_max_size_);
1012 } else {
1013 red_render_signal_queue_->Clear();
1014 }
peah764e3642016-10-22 05:04:30 -07001015}
1016
1017void AudioProcessingImpl::EmptyQueuedRenderAudio() {
1018 rtc::CritScope cs_capture(&crit_capture_);
peah701d6282016-10-25 05:42:20 -07001019 while (aec_render_signal_queue_->Remove(&aec_capture_queue_buffer_)) {
peah764e3642016-10-22 05:04:30 -07001020 public_submodules_->echo_cancellation->ProcessRenderAudio(
peah701d6282016-10-25 05:42:20 -07001021 aec_capture_queue_buffer_);
peaha0624602016-10-25 04:45:24 -07001022 }
1023
peah701d6282016-10-25 05:42:20 -07001024 while (aecm_render_signal_queue_->Remove(&aecm_capture_queue_buffer_)) {
peaha0624602016-10-25 04:45:24 -07001025 public_submodules_->echo_control_mobile->ProcessRenderAudio(
peah701d6282016-10-25 05:42:20 -07001026 aecm_capture_queue_buffer_);
1027 }
1028
1029 while (agc_render_signal_queue_->Remove(&agc_capture_queue_buffer_)) {
1030 public_submodules_->gain_control->ProcessRenderAudio(
1031 agc_capture_queue_buffer_);
peah764e3642016-10-22 05:04:30 -07001032 }
ivoc9f4a4a02016-10-28 05:39:16 -07001033
1034 while (red_render_signal_queue_->Remove(&red_capture_queue_buffer_)) {
1035 private_submodules_->residual_echo_detector->AnalyzeRenderAudio(
1036 red_capture_queue_buffer_);
1037 }
peah764e3642016-10-22 05:04:30 -07001038}
1039
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001040int AudioProcessingImpl::ProcessStream(AudioFrame* frame) {
peah369f8282015-12-17 06:42:29 -08001041 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_AudioFrame");
peahdf3efa82015-11-28 12:35:15 -08001042 {
1043 // Acquire the capture lock in order to safely call the function
1044 // that retrieves the render side data. This function accesses apm
1045 // getters that need the capture lock held when being called.
1046 // The lock needs to be released as
1047 // public_submodules_->echo_control_mobile->is_enabled() aquires this lock
1048 // as well.
1049 rtc::CritScope cs_capture(&crit_capture_);
peah764e3642016-10-22 05:04:30 -07001050 EmptyQueuedRenderAudio();
peahdf3efa82015-11-28 12:35:15 -08001051 }
peahfa6228e2015-11-16 16:27:42 -08001052
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001053 if (!frame) {
1054 return kNullPointerError;
1055 }
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001056 // Must be a native rate.
1057 if (frame->sample_rate_hz_ != kSampleRate8kHz &&
1058 frame->sample_rate_hz_ != kSampleRate16kHz &&
aluebs@webrtc.org087da132014-11-17 23:01:23 +00001059 frame->sample_rate_hz_ != kSampleRate32kHz &&
1060 frame->sample_rate_hz_ != kSampleRate48kHz) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001061 return kBadSampleRateError;
1062 }
peah192164e2015-11-17 02:16:45 -08001063
peahdf3efa82015-11-28 12:35:15 -08001064 ProcessingConfig processing_config;
peah2ace3f92016-09-10 04:42:27 -07001065 bool reinitialization_required = false;
peahdf3efa82015-11-28 12:35:15 -08001066 {
1067 // Aquire lock for the access of api_format.
1068 // The lock is released immediately due to the conditional
1069 // reinitialization.
1070 rtc::CritScope cs_capture(&crit_capture_);
1071 // TODO(ajm): The input and output rates and channels are currently
1072 // constrained to be identical in the int16 interface.
1073 processing_config = formats_.api_format;
peah2ace3f92016-09-10 04:42:27 -07001074
1075 reinitialization_required = UpdateActiveSubmoduleStates();
peahdf3efa82015-11-28 12:35:15 -08001076 }
Michael Graczyk86c6d332015-07-23 11:41:39 -07001077 processing_config.input_stream().set_sample_rate_hz(frame->sample_rate_hz_);
1078 processing_config.input_stream().set_num_channels(frame->num_channels_);
1079 processing_config.output_stream().set_sample_rate_hz(frame->sample_rate_hz_);
1080 processing_config.output_stream().set_num_channels(frame->num_channels_);
1081
peahdf3efa82015-11-28 12:35:15 -08001082 {
1083 // Do conditional reinitialization.
1084 rtc::CritScope cs_render(&crit_render_);
peah2ace3f92016-09-10 04:42:27 -07001085 RETURN_ON_ERR(
1086 MaybeInitializeCapture(processing_config, reinitialization_required));
peahdf3efa82015-11-28 12:35:15 -08001087 }
1088 rtc::CritScope cs_capture(&crit_capture_);
peah192164e2015-11-17 02:16:45 -08001089 if (frame->samples_per_channel_ !=
peahdf3efa82015-11-28 12:35:15 -08001090 formats_.api_format.input_stream().num_frames()) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001091 return kBadDataLengthError;
1092 }
1093
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001094#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
tommia6219cc2016-06-15 10:30:14 -07001095 if (debug_dump_.debug_file->is_open()) {
peah644fa962016-08-18 06:48:33 -07001096 RETURN_ON_ERR(WriteConfigMessage(false));
1097
peahdf3efa82015-11-28 12:35:15 -08001098 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM);
1099 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
Michael Graczyk86c6d332015-07-23 11:41:39 -07001100 const size_t data_size =
1101 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_;
andrew@webrtc.org63a50982012-05-02 23:56:37 +00001102 msg->set_input_data(frame->data_, data_size);
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001103 }
1104#endif
1105
peahdf3efa82015-11-28 12:35:15 -08001106 capture_.capture_audio->DeinterleaveFrom(frame);
peahde65ddc2016-09-16 15:02:15 -07001107 RETURN_ON_ERR(ProcessCaptureStreamLocked());
peah2ace3f92016-09-10 04:42:27 -07001108 capture_.capture_audio->InterleaveTo(
1109 frame, submodule_states_.CaptureMultiBandProcessingActive());
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001110
1111#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
tommia6219cc2016-06-15 10:30:14 -07001112 if (debug_dump_.debug_file->is_open()) {
peahdf3efa82015-11-28 12:35:15 -08001113 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
Michael Graczyk86c6d332015-07-23 11:41:39 -07001114 const size_t data_size =
1115 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_;
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001116 msg->set_output_data(frame->data_, data_size);
peahdf3efa82015-11-28 12:35:15 -08001117 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
ivocd66b44d2016-01-15 03:06:36 -08001118 &debug_dump_.num_bytes_left_for_log_,
peahdf3efa82015-11-28 12:35:15 -08001119 &crit_debug_, &debug_dump_.capture));
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001120 }
1121#endif
1122
1123 return kNoError;
1124}
1125
peahde65ddc2016-09-16 15:02:15 -07001126int AudioProcessingImpl::ProcessCaptureStreamLocked() {
peahb58a1582016-03-15 09:34:24 -07001127 // Ensure that not both the AEC and AECM are active at the same time.
1128 // TODO(peah): Simplify once the public API Enable functions for these
1129 // are moved to APM.
1130 RTC_DCHECK(!(public_submodules_->echo_cancellation->is_enabled() &&
1131 public_submodules_->echo_control_mobile->is_enabled()));
1132
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001133#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
tommia6219cc2016-06-15 10:30:14 -07001134 if (debug_dump_.debug_file->is_open()) {
peahdf3efa82015-11-28 12:35:15 -08001135 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
1136 msg->set_delay(capture_nonlocked_.stream_delay_ms);
1137 msg->set_drift(
1138 public_submodules_->echo_cancellation->stream_drift_samples());
bjornv@webrtc.org63da1dd2015-02-06 19:44:21 +00001139 msg->set_level(gain_control()->stream_analog_level());
peahdf3efa82015-11-28 12:35:15 -08001140 msg->set_keypress(capture_.key_pressed);
niklase@google.com470e71d2011-07-07 08:21:25 +00001141 }
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001142#endif
niklase@google.com470e71d2011-07-07 08:21:25 +00001143
Bjorn Volcker1ca324f2015-06-29 14:57:29 +02001144 MaybeUpdateHistograms();
1145
peahde65ddc2016-09-16 15:02:15 -07001146 AudioBuffer* capture_buffer = capture_.capture_audio.get(); // For brevity.
ekmeyerson60d9b332015-08-14 10:35:55 -07001147
peah1b08dc32016-12-20 13:45:58 -08001148 capture_input_rms_.Analyze(rtc::ArrayView<const int16_t>(
henrik.lundin290d43a2016-11-29 08:09:09 -08001149 capture_buffer->channels_const()[0],
1150 capture_nonlocked_.capture_processing_format.num_frames()));
peah1b08dc32016-12-20 13:45:58 -08001151 const bool log_rms = ++capture_rms_interval_counter_ >= 1000;
1152 if (log_rms) {
1153 capture_rms_interval_counter_ = 0;
1154 RmsLevel::Levels levels = capture_input_rms_.AverageAndPeak();
henrik.lundin45bb5132016-12-06 04:28:04 -08001155 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureInputLevelAverageRms",
1156 levels.average, 1, RmsLevel::kMinLevelDb, 64);
1157 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureInputLevelPeakRms",
1158 levels.peak, 1, RmsLevel::kMinLevelDb, 64);
henrik.lundin290d43a2016-11-29 08:09:09 -08001159 }
1160
peahe0eae3c2016-12-14 01:16:23 -08001161 if (private_submodules_->echo_canceller3) {
peah67995532017-04-10 14:12:41 -07001162 const int new_agc_level = gain_control()->stream_analog_level();
1163 capture_.echo_path_gain_change =
peah103ac7e2017-04-12 05:40:55 -07001164 abs(capture_.previous_agc_level - new_agc_level) > 5;
peah67995532017-04-10 14:12:41 -07001165 capture_.previous_agc_level = new_agc_level;
peahe0eae3c2016-12-14 01:16:23 -08001166 private_submodules_->echo_canceller3->AnalyzeCapture(capture_buffer);
1167 }
1168
peahbe615622016-02-13 16:40:47 -08001169 if (constants_.use_experimental_agc &&
peahdf3efa82015-11-28 12:35:15 -08001170 public_submodules_->gain_control->is_enabled()) {
1171 private_submodules_->agc_manager->AnalyzePreProcess(
peahde65ddc2016-09-16 15:02:15 -07001172 capture_buffer->channels()[0], capture_buffer->num_channels(),
1173 capture_nonlocked_.capture_processing_format.num_frames());
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001174 }
1175
peah2ace3f92016-09-10 04:42:27 -07001176 if (submodule_states_.CaptureMultiBandSubModulesActive() &&
1177 SampleRateSupportsMultiBand(
peahde65ddc2016-09-16 15:02:15 -07001178 capture_nonlocked_.capture_processing_format.sample_rate_hz())) {
1179 capture_buffer->SplitIntoFrequencyBands();
niklase@google.com470e71d2011-07-07 08:21:25 +00001180 }
1181
peah522d71b2017-02-23 05:16:26 -08001182 if (private_submodules_->echo_canceller3) {
1183 // Force down-mixing of the number of channels after the detection of
1184 // capture signal saturation.
1185 // TODO(peah): Look into ensuring that this kind of tampering with the
1186 // AudioBuffer functionality should not be needed.
1187 capture_buffer->set_num_channels(1);
1188 }
1189
aluebsb2328d12016-01-11 20:32:29 -08001190 if (capture_nonlocked_.beamformer_enabled) {
peahde65ddc2016-09-16 15:02:15 -07001191 private_submodules_->beamformer->AnalyzeChunk(
1192 *capture_buffer->split_data_f());
Alejandro Luebsf4022ff2016-07-01 17:19:09 -07001193 // Discards all channels by the leftmost one.
peahde65ddc2016-09-16 15:02:15 -07001194 capture_buffer->set_num_channels(1);
aluebs@webrtc.orgae643ce2014-12-19 19:57:34 +00001195 }
aluebs@webrtc.orgae643ce2014-12-19 19:57:34 +00001196
peahe0eae3c2016-12-14 01:16:23 -08001197 // TODO(peah): Move the AEC3 low-cut filter to this place.
1198 if (private_submodules_->low_cut_filter &&
1199 !private_submodules_->echo_canceller3) {
peah8271d042016-11-22 07:24:52 -08001200 private_submodules_->low_cut_filter->Process(capture_buffer);
1201 }
peahde65ddc2016-09-16 15:02:15 -07001202 RETURN_ON_ERR(
1203 public_submodules_->gain_control->AnalyzeCaptureAudio(capture_buffer));
1204 public_submodules_->noise_suppression->AnalyzeCaptureAudio(capture_buffer);
peahb58a1582016-03-15 09:34:24 -07001205
1206 // Ensure that the stream delay was set before the call to the
1207 // AEC ProcessCaptureAudio function.
1208 if (public_submodules_->echo_cancellation->is_enabled() &&
1209 !was_stream_delay_set()) {
1210 return AudioProcessing::kStreamParameterNotSetError;
1211 }
1212
peahe0eae3c2016-12-14 01:16:23 -08001213 if (private_submodules_->echo_canceller3) {
peah67995532017-04-10 14:12:41 -07001214 private_submodules_->echo_canceller3->ProcessCapture(
1215 capture_buffer, capture_.echo_path_gain_change);
peah61202ac2017-02-06 03:39:42 -08001216 } else {
1217 RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessCaptureAudio(
1218 capture_buffer, stream_delay_ms()));
peahe0eae3c2016-12-14 01:16:23 -08001219 }
1220
peahdf3efa82015-11-28 12:35:15 -08001221 if (public_submodules_->echo_control_mobile->is_enabled() &&
1222 public_submodules_->noise_suppression->is_enabled()) {
peahde65ddc2016-09-16 15:02:15 -07001223 capture_buffer->CopyLowPassToReference();
niklase@google.com470e71d2011-07-07 08:21:25 +00001224 }
peahde65ddc2016-09-16 15:02:15 -07001225 public_submodules_->noise_suppression->ProcessCaptureAudio(capture_buffer);
peah1bcfce52016-08-26 07:16:04 -07001226#if WEBRTC_INTELLIGIBILITY_ENHANCER
Alejandro Luebsc9b0c262016-05-16 15:32:38 -07001227 if (capture_nonlocked_.intelligibility_enabled) {
aluebsc466bad2016-02-10 12:03:00 -08001228 RTC_DCHECK(public_submodules_->noise_suppression->is_enabled());
Alejandro Luebsc9b0c262016-05-16 15:32:38 -07001229 int gain_db = public_submodules_->gain_control->is_enabled() ?
1230 public_submodules_->gain_control->compression_gain_db() :
1231 0;
Alejandro Luebs50411102016-06-30 15:35:41 -07001232 float gain = std::pow(10.f, gain_db / 20.f);
1233 gain *= capture_nonlocked_.level_controller_enabled ?
1234 private_submodules_->level_controller->GetLastGain() :
1235 1.f;
aluebsc466bad2016-02-10 12:03:00 -08001236 public_submodules_->intelligibility_enhancer->SetCaptureNoiseEstimate(
Alejandro Luebs50411102016-06-30 15:35:41 -07001237 public_submodules_->noise_suppression->NoiseEstimate(), gain);
aluebsc466bad2016-02-10 12:03:00 -08001238 }
peah1bcfce52016-08-26 07:16:04 -07001239#endif
peah253534d2016-03-15 04:32:28 -07001240
1241 // Ensure that the stream delay was set before the call to the
1242 // AECM ProcessCaptureAudio function.
1243 if (public_submodules_->echo_control_mobile->is_enabled() &&
1244 !was_stream_delay_set()) {
1245 return AudioProcessing::kStreamParameterNotSetError;
1246 }
1247
1248 RETURN_ON_ERR(public_submodules_->echo_control_mobile->ProcessCaptureAudio(
peahde65ddc2016-09-16 15:02:15 -07001249 capture_buffer, stream_delay_ms()));
peah253534d2016-03-15 04:32:28 -07001250
ivoc9f4a4a02016-10-28 05:39:16 -07001251
Alejandro Luebsf4022ff2016-07-01 17:19:09 -07001252 if (capture_nonlocked_.beamformer_enabled) {
peahde65ddc2016-09-16 15:02:15 -07001253 private_submodules_->beamformer->PostFilter(capture_buffer->split_data_f());
Alejandro Luebsf4022ff2016-07-01 17:19:09 -07001254 }
1255
peahde65ddc2016-09-16 15:02:15 -07001256 public_submodules_->voice_detection->ProcessCaptureAudio(capture_buffer);
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001257
peahbe615622016-02-13 16:40:47 -08001258 if (constants_.use_experimental_agc &&
peahdf3efa82015-11-28 12:35:15 -08001259 public_submodules_->gain_control->is_enabled() &&
aluebsb2328d12016-01-11 20:32:29 -08001260 (!capture_nonlocked_.beamformer_enabled ||
peahdf3efa82015-11-28 12:35:15 -08001261 private_submodules_->beamformer->is_target_present())) {
1262 private_submodules_->agc_manager->Process(
peahde65ddc2016-09-16 15:02:15 -07001263 capture_buffer->split_bands_const(0)[kBand0To8kHz],
1264 capture_buffer->num_frames_per_band(), capture_nonlocked_.split_rate);
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001265 }
peahb8fbb542016-03-15 02:28:08 -07001266 RETURN_ON_ERR(public_submodules_->gain_control->ProcessCaptureAudio(
peahde65ddc2016-09-16 15:02:15 -07001267 capture_buffer, echo_cancellation()->stream_has_echo()));
niklase@google.com470e71d2011-07-07 08:21:25 +00001268
peah2ace3f92016-09-10 04:42:27 -07001269 if (submodule_states_.CaptureMultiBandProcessingActive() &&
1270 SampleRateSupportsMultiBand(
peahde65ddc2016-09-16 15:02:15 -07001271 capture_nonlocked_.capture_processing_format.sample_rate_hz())) {
1272 capture_buffer->MergeFrequencyBands();
niklase@google.com470e71d2011-07-07 08:21:25 +00001273 }
1274
peah9e6a2902017-05-15 07:19:21 -07001275 if (config_.residual_echo_detector.enabled) {
1276 private_submodules_->residual_echo_detector->AnalyzeCaptureAudio(
1277 rtc::ArrayView<const float>(capture_buffer->channels_f()[0],
1278 capture_buffer->num_frames()));
1279 }
1280
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001281 // TODO(aluebs): Investigate if the transient suppression placement should be
1282 // before or after the AGC.
peahdf3efa82015-11-28 12:35:15 -08001283 if (capture_.transient_suppressor_enabled) {
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001284 float voice_probability =
peahdf3efa82015-11-28 12:35:15 -08001285 private_submodules_->agc_manager.get()
1286 ? private_submodules_->agc_manager->voice_probability()
1287 : 1.f;
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001288
peahdf3efa82015-11-28 12:35:15 -08001289 public_submodules_->transient_suppressor->Suppress(
peahde65ddc2016-09-16 15:02:15 -07001290 capture_buffer->channels_f()[0], capture_buffer->num_frames(),
1291 capture_buffer->num_channels(),
1292 capture_buffer->split_bands_const_f(0)[kBand0To8kHz],
1293 capture_buffer->num_frames_per_band(), capture_buffer->keyboard_data(),
1294 capture_buffer->num_keyboard_frames(), voice_probability,
peahdf3efa82015-11-28 12:35:15 -08001295 capture_.key_pressed);
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001296 }
1297
peahca4cac72016-06-29 15:26:12 -07001298 if (capture_nonlocked_.level_controller_enabled) {
peahde65ddc2016-09-16 15:02:15 -07001299 private_submodules_->level_controller->Process(capture_buffer);
peahca4cac72016-06-29 15:26:12 -07001300 }
1301
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001302 // The level estimator operates on the recombined data.
peahde65ddc2016-09-16 15:02:15 -07001303 public_submodules_->level_estimator->ProcessStream(capture_buffer);
ajm@google.com808e0e02011-08-03 21:08:51 +00001304
peah1b08dc32016-12-20 13:45:58 -08001305 capture_output_rms_.Analyze(rtc::ArrayView<const int16_t>(
1306 capture_buffer->channels_const()[0],
1307 capture_nonlocked_.capture_processing_format.num_frames()));
1308 if (log_rms) {
1309 RmsLevel::Levels levels = capture_output_rms_.AverageAndPeak();
1310 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureOutputLevelAverageRms",
1311 levels.average, 1, RmsLevel::kMinLevelDb, 64);
1312 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureOutputLevelPeakRms",
1313 levels.peak, 1, RmsLevel::kMinLevelDb, 64);
1314 }
1315
peahdf3efa82015-11-28 12:35:15 -08001316 capture_.was_stream_delay_set = false;
niklase@google.com470e71d2011-07-07 08:21:25 +00001317 return kNoError;
1318}
1319
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001320int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data,
Peter Kastingdce40cf2015-08-24 14:52:23 -07001321 size_t samples_per_channel,
peahde65ddc2016-09-16 15:02:15 -07001322 int sample_rate_hz,
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001323 ChannelLayout layout) {
peah369f8282015-12-17 06:42:29 -08001324 TRACE_EVENT0("webrtc", "AudioProcessing::AnalyzeReverseStream_ChannelLayout");
peahdf3efa82015-11-28 12:35:15 -08001325 rtc::CritScope cs(&crit_render_);
Michael Graczyk86c6d332015-07-23 11:41:39 -07001326 const StreamConfig reverse_config = {
peahde65ddc2016-09-16 15:02:15 -07001327 sample_rate_hz, ChannelsFromLayout(layout), LayoutHasKeyboard(layout),
Michael Graczyk86c6d332015-07-23 11:41:39 -07001328 };
1329 if (samples_per_channel != reverse_config.num_frames()) {
1330 return kBadDataLengthError;
1331 }
peahdf3efa82015-11-28 12:35:15 -08001332 return AnalyzeReverseStreamLocked(data, reverse_config, reverse_config);
ekmeyerson60d9b332015-08-14 10:35:55 -07001333}
1334
peahde65ddc2016-09-16 15:02:15 -07001335int AudioProcessingImpl::ProcessReverseStream(const float* const* src,
1336 const StreamConfig& input_config,
1337 const StreamConfig& output_config,
1338 float* const* dest) {
peah369f8282015-12-17 06:42:29 -08001339 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_StreamConfig");
peahdf3efa82015-11-28 12:35:15 -08001340 rtc::CritScope cs(&crit_render_);
peahde65ddc2016-09-16 15:02:15 -07001341 RETURN_ON_ERR(AnalyzeReverseStreamLocked(src, input_config, output_config));
peah2ace3f92016-09-10 04:42:27 -07001342 if (submodule_states_.RenderMultiBandProcessingActive()) {
peahdf3efa82015-11-28 12:35:15 -08001343 render_.render_audio->CopyTo(formats_.api_format.reverse_output_stream(),
1344 dest);
peah2ace3f92016-09-10 04:42:27 -07001345 } else if (formats_.api_format.reverse_input_stream() !=
1346 formats_.api_format.reverse_output_stream()) {
peahde65ddc2016-09-16 15:02:15 -07001347 render_.render_converter->Convert(src, input_config.num_samples(), dest,
1348 output_config.num_samples());
ekmeyerson60d9b332015-08-14 10:35:55 -07001349 } else {
peahde65ddc2016-09-16 15:02:15 -07001350 CopyAudioIfNeeded(src, input_config.num_frames(),
1351 input_config.num_channels(), dest);
ekmeyerson60d9b332015-08-14 10:35:55 -07001352 }
1353
1354 return kNoError;
Michael Graczyk86c6d332015-07-23 11:41:39 -07001355}
1356
peahdf3efa82015-11-28 12:35:15 -08001357int AudioProcessingImpl::AnalyzeReverseStreamLocked(
ekmeyerson60d9b332015-08-14 10:35:55 -07001358 const float* const* src,
peahde65ddc2016-09-16 15:02:15 -07001359 const StreamConfig& input_config,
1360 const StreamConfig& output_config) {
peahdf3efa82015-11-28 12:35:15 -08001361 if (src == nullptr) {
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001362 return kNullPointerError;
1363 }
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001364
peahde65ddc2016-09-16 15:02:15 -07001365 if (input_config.num_channels() == 0) {
Michael Graczyk86c6d332015-07-23 11:41:39 -07001366 return kBadNumberChannelsError;
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001367 }
1368
peahdf3efa82015-11-28 12:35:15 -08001369 ProcessingConfig processing_config = formats_.api_format;
peahde65ddc2016-09-16 15:02:15 -07001370 processing_config.reverse_input_stream() = input_config;
1371 processing_config.reverse_output_stream() = output_config;
Michael Graczyk86c6d332015-07-23 11:41:39 -07001372
peahdf3efa82015-11-28 12:35:15 -08001373 RETURN_ON_ERR(MaybeInitializeRender(processing_config));
peahde65ddc2016-09-16 15:02:15 -07001374 assert(input_config.num_frames() ==
1375 formats_.api_format.reverse_input_stream().num_frames());
Michael Graczyk86c6d332015-07-23 11:41:39 -07001376
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001377#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
tommia6219cc2016-06-15 10:30:14 -07001378 if (debug_dump_.debug_file->is_open()) {
peahdf3efa82015-11-28 12:35:15 -08001379 debug_dump_.render.event_msg->set_type(audioproc::Event::REVERSE_STREAM);
1380 audioproc::ReverseStream* msg =
1381 debug_dump_.render.event_msg->mutable_reverse_stream();
aluebs@webrtc.org59a1b1b2014-08-28 10:43:09 +00001382 const size_t channel_size =
peahdf3efa82015-11-28 12:35:15 -08001383 sizeof(float) * formats_.api_format.reverse_input_stream().num_frames();
Peter Kasting69558702016-01-12 16:26:35 -08001384 for (size_t i = 0;
peahdf3efa82015-11-28 12:35:15 -08001385 i < formats_.api_format.reverse_input_stream().num_channels(); ++i)
ekmeyerson60d9b332015-08-14 10:35:55 -07001386 msg->add_channel(src[i], channel_size);
peahdf3efa82015-11-28 12:35:15 -08001387 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
ivocd66b44d2016-01-15 03:06:36 -08001388 &debug_dump_.num_bytes_left_for_log_,
peahdf3efa82015-11-28 12:35:15 -08001389 &crit_debug_, &debug_dump_.render));
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001390 }
1391#endif
1392
peahdf3efa82015-11-28 12:35:15 -08001393 render_.render_audio->CopyFrom(src,
1394 formats_.api_format.reverse_input_stream());
peahde65ddc2016-09-16 15:02:15 -07001395 return ProcessRenderStreamLocked();
ekmeyerson60d9b332015-08-14 10:35:55 -07001396}
1397
1398int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) {
peah369f8282015-12-17 06:42:29 -08001399 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_AudioFrame");
peahdf3efa82015-11-28 12:35:15 -08001400 rtc::CritScope cs(&crit_render_);
peahdf3efa82015-11-28 12:35:15 -08001401 if (frame == nullptr) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001402 return kNullPointerError;
1403 }
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001404 // Must be a native rate.
1405 if (frame->sample_rate_hz_ != kSampleRate8kHz &&
1406 frame->sample_rate_hz_ != kSampleRate16kHz &&
aluebs@webrtc.org087da132014-11-17 23:01:23 +00001407 frame->sample_rate_hz_ != kSampleRate32kHz &&
1408 frame->sample_rate_hz_ != kSampleRate48kHz) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001409 return kBadSampleRateError;
1410 }
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001411
Michael Graczyk86c6d332015-07-23 11:41:39 -07001412 if (frame->num_channels_ <= 0) {
1413 return kBadNumberChannelsError;
1414 }
1415
peahdf3efa82015-11-28 12:35:15 -08001416 ProcessingConfig processing_config = formats_.api_format;
ekmeyerson60d9b332015-08-14 10:35:55 -07001417 processing_config.reverse_input_stream().set_sample_rate_hz(
1418 frame->sample_rate_hz_);
1419 processing_config.reverse_input_stream().set_num_channels(
1420 frame->num_channels_);
1421 processing_config.reverse_output_stream().set_sample_rate_hz(
1422 frame->sample_rate_hz_);
1423 processing_config.reverse_output_stream().set_num_channels(
1424 frame->num_channels_);
Michael Graczyk86c6d332015-07-23 11:41:39 -07001425
peahdf3efa82015-11-28 12:35:15 -08001426 RETURN_ON_ERR(MaybeInitializeRender(processing_config));
Michael Graczyk86c6d332015-07-23 11:41:39 -07001427 if (frame->samples_per_channel_ !=
peahdf3efa82015-11-28 12:35:15 -08001428 formats_.api_format.reverse_input_stream().num_frames()) {
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001429 return kBadDataLengthError;
1430 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001431
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001432#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
tommia6219cc2016-06-15 10:30:14 -07001433 if (debug_dump_.debug_file->is_open()) {
peahdf3efa82015-11-28 12:35:15 -08001434 debug_dump_.render.event_msg->set_type(audioproc::Event::REVERSE_STREAM);
1435 audioproc::ReverseStream* msg =
1436 debug_dump_.render.event_msg->mutable_reverse_stream();
Michael Graczyk86c6d332015-07-23 11:41:39 -07001437 const size_t data_size =
1438 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_;
andrew@webrtc.org63a50982012-05-02 23:56:37 +00001439 msg->set_data(frame->data_, data_size);
peahdf3efa82015-11-28 12:35:15 -08001440 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
ivocd66b44d2016-01-15 03:06:36 -08001441 &debug_dump_.num_bytes_left_for_log_,
peahdf3efa82015-11-28 12:35:15 -08001442 &crit_debug_, &debug_dump_.render));
niklase@google.com470e71d2011-07-07 08:21:25 +00001443 }
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001444#endif
peahdf3efa82015-11-28 12:35:15 -08001445 render_.render_audio->DeinterleaveFrom(frame);
peahde65ddc2016-09-16 15:02:15 -07001446 RETURN_ON_ERR(ProcessRenderStreamLocked());
peah2ace3f92016-09-10 04:42:27 -07001447 render_.render_audio->InterleaveTo(
1448 frame, submodule_states_.RenderMultiBandProcessingActive());
aluebsb0319552016-03-17 20:39:53 -07001449 return kNoError;
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001450}
niklase@google.com470e71d2011-07-07 08:21:25 +00001451
peahde65ddc2016-09-16 15:02:15 -07001452int AudioProcessingImpl::ProcessRenderStreamLocked() {
1453 AudioBuffer* render_buffer = render_.render_audio.get(); // For brevity.
peah9e6a2902017-05-15 07:19:21 -07001454
1455 QueueNonbandedRenderAudio(render_buffer);
1456
peah2ace3f92016-09-10 04:42:27 -07001457 if (submodule_states_.RenderMultiBandSubModulesActive() &&
peahde65ddc2016-09-16 15:02:15 -07001458 SampleRateSupportsMultiBand(
1459 formats_.render_processing_format.sample_rate_hz())) {
1460 render_buffer->SplitIntoFrequencyBands();
niklase@google.com470e71d2011-07-07 08:21:25 +00001461 }
1462
peah1bcfce52016-08-26 07:16:04 -07001463#if WEBRTC_INTELLIGIBILITY_ENHANCER
Alejandro Luebsc9b0c262016-05-16 15:32:38 -07001464 if (capture_nonlocked_.intelligibility_enabled) {
peahdf3efa82015-11-28 12:35:15 -08001465 public_submodules_->intelligibility_enhancer->ProcessRenderAudio(
Alejandro Luebsef009252016-09-20 14:51:56 -07001466 render_buffer);
ekmeyerson60d9b332015-08-14 10:35:55 -07001467 }
peah1bcfce52016-08-26 07:16:04 -07001468#endif
ekmeyerson60d9b332015-08-14 10:35:55 -07001469
peahce4d9152017-05-19 01:28:05 -07001470 if (submodule_states_.RenderMultiBandSubModulesActive()) {
1471 QueueBandedRenderAudio(render_buffer);
1472 }
1473
peahe0eae3c2016-12-14 01:16:23 -08001474 // TODO(peah): Perform the queueing ínside QueueRenderAudiuo().
1475 if (private_submodules_->echo_canceller3) {
peahcf02cf12017-04-05 14:18:07 -07001476 private_submodules_->echo_canceller3->AnalyzeRender(render_buffer);
peahe0eae3c2016-12-14 01:16:23 -08001477 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001478
peah2ace3f92016-09-10 04:42:27 -07001479 if (submodule_states_.RenderMultiBandProcessingActive() &&
peahde65ddc2016-09-16 15:02:15 -07001480 SampleRateSupportsMultiBand(
1481 formats_.render_processing_format.sample_rate_hz())) {
1482 render_buffer->MergeFrequencyBands();
ekmeyerson60d9b332015-08-14 10:35:55 -07001483 }
1484
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001485 return kNoError;
niklase@google.com470e71d2011-07-07 08:21:25 +00001486}
1487
1488int AudioProcessingImpl::set_stream_delay_ms(int delay) {
peahdf3efa82015-11-28 12:35:15 -08001489 rtc::CritScope cs(&crit_capture_);
andrew@webrtc.org5f23d642012-05-29 21:14:06 +00001490 Error retval = kNoError;
peahdf3efa82015-11-28 12:35:15 -08001491 capture_.was_stream_delay_set = true;
1492 delay += capture_.delay_offset_ms;
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +00001493
niklase@google.com470e71d2011-07-07 08:21:25 +00001494 if (delay < 0) {
andrew@webrtc.org5f23d642012-05-29 21:14:06 +00001495 delay = 0;
1496 retval = kBadStreamParameterWarning;
niklase@google.com470e71d2011-07-07 08:21:25 +00001497 }
1498
1499 // TODO(ajm): the max is rather arbitrarily chosen; investigate.
1500 if (delay > 500) {
andrew@webrtc.org5f23d642012-05-29 21:14:06 +00001501 delay = 500;
1502 retval = kBadStreamParameterWarning;
niklase@google.com470e71d2011-07-07 08:21:25 +00001503 }
1504
peahdf3efa82015-11-28 12:35:15 -08001505 capture_nonlocked_.stream_delay_ms = delay;
andrew@webrtc.org5f23d642012-05-29 21:14:06 +00001506 return retval;
niklase@google.com470e71d2011-07-07 08:21:25 +00001507}
1508
1509int AudioProcessingImpl::stream_delay_ms() const {
peahdf3efa82015-11-28 12:35:15 -08001510 // Used as callback from submodules, hence locking is not allowed.
1511 return capture_nonlocked_.stream_delay_ms;
niklase@google.com470e71d2011-07-07 08:21:25 +00001512}
1513
1514bool AudioProcessingImpl::was_stream_delay_set() const {
peahdf3efa82015-11-28 12:35:15 -08001515 // Used as callback from submodules, hence locking is not allowed.
1516 return capture_.was_stream_delay_set;
niklase@google.com470e71d2011-07-07 08:21:25 +00001517}
1518
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001519void AudioProcessingImpl::set_stream_key_pressed(bool key_pressed) {
peahdf3efa82015-11-28 12:35:15 -08001520 rtc::CritScope cs(&crit_capture_);
1521 capture_.key_pressed = key_pressed;
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001522}
1523
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +00001524void AudioProcessingImpl::set_delay_offset_ms(int offset) {
peahdf3efa82015-11-28 12:35:15 -08001525 rtc::CritScope cs(&crit_capture_);
1526 capture_.delay_offset_ms = offset;
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +00001527}
1528
1529int AudioProcessingImpl::delay_offset_ms() const {
peahdf3efa82015-11-28 12:35:15 -08001530 rtc::CritScope cs(&crit_capture_);
1531 return capture_.delay_offset_ms;
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +00001532}
1533
niklase@google.com470e71d2011-07-07 08:21:25 +00001534int AudioProcessingImpl::StartDebugRecording(
ivocd66b44d2016-01-15 03:06:36 -08001535 const char filename[AudioProcessing::kMaxFilenameSize],
1536 int64_t max_log_size_bytes) {
peahdf3efa82015-11-28 12:35:15 -08001537 // Run in a single-threaded manner.
1538 rtc::CritScope cs_render(&crit_render_);
1539 rtc::CritScope cs_capture(&crit_capture_);
André Susano Pinto664cdaf2015-05-20 11:11:07 +02001540 static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, "");
niklase@google.com470e71d2011-07-07 08:21:25 +00001541
peahdf3efa82015-11-28 12:35:15 -08001542 if (filename == nullptr) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001543 return kNullPointerError;
1544 }
1545
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001546#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
ivocd66b44d2016-01-15 03:06:36 -08001547 debug_dump_.num_bytes_left_for_log_ = max_log_size_bytes;
niklase@google.com470e71d2011-07-07 08:21:25 +00001548 // Stop any ongoing recording.
tommia6219cc2016-06-15 10:30:14 -07001549 debug_dump_.debug_file->CloseFile();
niklase@google.com470e71d2011-07-07 08:21:25 +00001550
tommia6219cc2016-06-15 10:30:14 -07001551 if (!debug_dump_.debug_file->OpenFile(filename, false)) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001552 return kFileError;
1553 }
1554
Minyue13b96ba2015-10-03 00:39:14 +02001555 RETURN_ON_ERR(WriteConfigMessage(true));
1556 RETURN_ON_ERR(WriteInitMessage());
niklase@google.com470e71d2011-07-07 08:21:25 +00001557 return kNoError;
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001558#else
1559 return kUnsupportedFunctionError;
1560#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
niklase@google.com470e71d2011-07-07 08:21:25 +00001561}
1562
ivocd66b44d2016-01-15 03:06:36 -08001563int AudioProcessingImpl::StartDebugRecording(FILE* handle,
1564 int64_t max_log_size_bytes) {
peahdf3efa82015-11-28 12:35:15 -08001565 // Run in a single-threaded manner.
1566 rtc::CritScope cs_render(&crit_render_);
1567 rtc::CritScope cs_capture(&crit_capture_);
henrikg@webrtc.org863b5362013-12-06 16:05:17 +00001568
peahdf3efa82015-11-28 12:35:15 -08001569 if (handle == nullptr) {
henrikg@webrtc.org863b5362013-12-06 16:05:17 +00001570 return kNullPointerError;
1571 }
1572
1573#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
ivocd66b44d2016-01-15 03:06:36 -08001574 debug_dump_.num_bytes_left_for_log_ = max_log_size_bytes;
1575
henrikg@webrtc.org863b5362013-12-06 16:05:17 +00001576 // Stop any ongoing recording.
tommia6219cc2016-06-15 10:30:14 -07001577 debug_dump_.debug_file->CloseFile();
henrikg@webrtc.org863b5362013-12-06 16:05:17 +00001578
tommia6219cc2016-06-15 10:30:14 -07001579 if (!debug_dump_.debug_file->OpenFromFileHandle(handle)) {
henrikg@webrtc.org863b5362013-12-06 16:05:17 +00001580 return kFileError;
1581 }
1582
Minyue13b96ba2015-10-03 00:39:14 +02001583 RETURN_ON_ERR(WriteConfigMessage(true));
1584 RETURN_ON_ERR(WriteInitMessage());
henrikg@webrtc.org863b5362013-12-06 16:05:17 +00001585 return kNoError;
1586#else
1587 return kUnsupportedFunctionError;
1588#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1589}
1590
peah73a28ee2016-10-12 03:01:49 -07001591int AudioProcessingImpl::StartDebugRecording(FILE* handle) {
1592 return StartDebugRecording(handle, -1);
1593}
1594
xians@webrtc.orge46bc772014-10-10 08:36:56 +00001595int AudioProcessingImpl::StartDebugRecordingForPlatformFile(
1596 rtc::PlatformFile handle) {
peahdf3efa82015-11-28 12:35:15 -08001597 // Run in a single-threaded manner.
1598 rtc::CritScope cs_render(&crit_render_);
1599 rtc::CritScope cs_capture(&crit_capture_);
xians@webrtc.orge46bc772014-10-10 08:36:56 +00001600 FILE* stream = rtc::FdopenPlatformFileForWriting(handle);
ivocd66b44d2016-01-15 03:06:36 -08001601 return StartDebugRecording(stream, -1);
xians@webrtc.orge46bc772014-10-10 08:36:56 +00001602}
1603
niklase@google.com470e71d2011-07-07 08:21:25 +00001604int AudioProcessingImpl::StopDebugRecording() {
peahdf3efa82015-11-28 12:35:15 -08001605 // Run in a single-threaded manner.
1606 rtc::CritScope cs_render(&crit_render_);
1607 rtc::CritScope cs_capture(&crit_capture_);
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001608
1609#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
niklase@google.com470e71d2011-07-07 08:21:25 +00001610 // We just return if recording hasn't started.
tommia6219cc2016-06-15 10:30:14 -07001611 debug_dump_.debug_file->CloseFile();
niklase@google.com470e71d2011-07-07 08:21:25 +00001612 return kNoError;
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001613#else
1614 return kUnsupportedFunctionError;
1615#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
niklase@google.com470e71d2011-07-07 08:21:25 +00001616}
1617
ivoc4e477a12017-01-15 08:29:46 -08001618AudioProcessing::AudioProcessingStatistics::AudioProcessingStatistics() {
1619 residual_echo_return_loss.Set(-100.0f, -100.0f, -100.0f, -100.0f);
1620 echo_return_loss.Set(-100.0f, -100.0f, -100.0f, -100.0f);
1621 echo_return_loss_enhancement.Set(-100.0f, -100.0f, -100.0f, -100.0f);
1622 a_nlp.Set(-100.0f, -100.0f, -100.0f, -100.0f);
1623}
1624
1625AudioProcessing::AudioProcessingStatistics::AudioProcessingStatistics(
1626 const AudioProcessingStatistics& other) = default;
1627
1628AudioProcessing::AudioProcessingStatistics::~AudioProcessingStatistics() =
1629 default;
1630
ivoc3e9a5372016-10-28 07:55:33 -07001631// TODO(ivoc): Remove this when GetStatistics() becomes pure virtual.
1632AudioProcessing::AudioProcessingStatistics AudioProcessing::GetStatistics()
1633 const {
1634 return AudioProcessingStatistics();
1635}
1636
1637AudioProcessing::AudioProcessingStatistics AudioProcessingImpl::GetStatistics()
1638 const {
1639 AudioProcessingStatistics stats;
1640 EchoCancellation::Metrics metrics;
ivocd0a151c2016-11-02 09:14:37 -07001641 int success = public_submodules_->echo_cancellation->GetMetrics(&metrics);
1642 if (success == Error::kNoError) {
1643 stats.a_nlp.Set(metrics.a_nlp);
1644 stats.divergent_filter_fraction = metrics.divergent_filter_fraction;
1645 stats.echo_return_loss.Set(metrics.echo_return_loss);
1646 stats.echo_return_loss_enhancement.Set(
1647 metrics.echo_return_loss_enhancement);
1648 stats.residual_echo_return_loss.Set(metrics.residual_echo_return_loss);
1649 }
ivoc9c192b22017-03-16 04:22:14 -07001650 {
1651 rtc::CritScope cs_capture(&crit_capture_);
1652 stats.residual_echo_likelihood =
1653 private_submodules_->residual_echo_detector->echo_likelihood();
1654 stats.residual_echo_likelihood_recent_max =
1655 private_submodules_->residual_echo_detector
1656 ->echo_likelihood_recent_max();
1657 }
ivoc3e9a5372016-10-28 07:55:33 -07001658 public_submodules_->echo_cancellation->GetDelayMetrics(
1659 &stats.delay_median, &stats.delay_standard_deviation,
1660 &stats.fraction_poor_delays);
1661 return stats;
1662}
1663
niklase@google.com470e71d2011-07-07 08:21:25 +00001664EchoCancellation* AudioProcessingImpl::echo_cancellation() const {
peahb624d8c2016-03-05 03:01:14 -08001665 return public_submodules_->echo_cancellation.get();
niklase@google.com470e71d2011-07-07 08:21:25 +00001666}
1667
1668EchoControlMobile* AudioProcessingImpl::echo_control_mobile() const {
peahbb9edbd2016-03-10 12:54:25 -08001669 return public_submodules_->echo_control_mobile.get();
niklase@google.com470e71d2011-07-07 08:21:25 +00001670}
1671
1672GainControl* AudioProcessingImpl::gain_control() const {
peahbe615622016-02-13 16:40:47 -08001673 if (constants_.use_experimental_agc) {
1674 return public_submodules_->gain_control_for_experimental_agc.get();
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001675 }
peahbfa97112016-03-10 21:09:04 -08001676 return public_submodules_->gain_control.get();
niklase@google.com470e71d2011-07-07 08:21:25 +00001677}
1678
1679HighPassFilter* AudioProcessingImpl::high_pass_filter() const {
peah8271d042016-11-22 07:24:52 -08001680 return high_pass_filter_impl_.get();
niklase@google.com470e71d2011-07-07 08:21:25 +00001681}
1682
1683LevelEstimator* AudioProcessingImpl::level_estimator() const {
solenberg949028f2015-12-15 11:39:38 -08001684 return public_submodules_->level_estimator.get();
niklase@google.com470e71d2011-07-07 08:21:25 +00001685}
1686
1687NoiseSuppression* AudioProcessingImpl::noise_suppression() const {
solenberg5e465c32015-12-08 13:22:33 -08001688 return public_submodules_->noise_suppression.get();
niklase@google.com470e71d2011-07-07 08:21:25 +00001689}
1690
1691VoiceDetection* AudioProcessingImpl::voice_detection() const {
solenberga29386c2015-12-16 03:31:12 -08001692 return public_submodules_->voice_detection.get();
niklase@google.com470e71d2011-07-07 08:21:25 +00001693}
1694
peah8271d042016-11-22 07:24:52 -08001695void AudioProcessingImpl::MutateConfig(
1696 rtc::FunctionView<void(AudioProcessing::Config*)> mutator) {
1697 rtc::CritScope cs_render(&crit_render_);
1698 rtc::CritScope cs_capture(&crit_capture_);
1699 mutator(&config_);
1700 ApplyConfig(config_);
1701}
1702
1703AudioProcessing::Config AudioProcessingImpl::GetConfig() const {
1704 rtc::CritScope cs_render(&crit_render_);
1705 rtc::CritScope cs_capture(&crit_capture_);
1706 return config_;
1707}
1708
peah2ace3f92016-09-10 04:42:27 -07001709bool AudioProcessingImpl::UpdateActiveSubmoduleStates() {
1710 return submodule_states_.Update(
peah8271d042016-11-22 07:24:52 -08001711 config_.high_pass_filter.enabled,
peah2ace3f92016-09-10 04:42:27 -07001712 public_submodules_->echo_cancellation->is_enabled(),
1713 public_submodules_->echo_control_mobile->is_enabled(),
ivoc9f4a4a02016-10-28 05:39:16 -07001714 config_.residual_echo_detector.enabled,
peah2ace3f92016-09-10 04:42:27 -07001715 public_submodules_->noise_suppression->is_enabled(),
1716 capture_nonlocked_.intelligibility_enabled,
1717 capture_nonlocked_.beamformer_enabled,
1718 public_submodules_->gain_control->is_enabled(),
1719 capture_nonlocked_.level_controller_enabled,
peahe0eae3c2016-12-14 01:16:23 -08001720 capture_nonlocked_.echo_canceller3_enabled,
peah2ace3f92016-09-10 04:42:27 -07001721 public_submodules_->voice_detection->is_enabled(),
1722 public_submodules_->level_estimator->is_enabled(),
1723 capture_.transient_suppressor_enabled);
ekmeyerson60d9b332015-08-14 10:35:55 -07001724}
1725
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001726
Bjorn Volckeradc46c42015-04-15 11:42:40 +02001727void AudioProcessingImpl::InitializeTransient() {
peahdf3efa82015-11-28 12:35:15 -08001728 if (capture_.transient_suppressor_enabled) {
1729 if (!public_submodules_->transient_suppressor.get()) {
1730 public_submodules_->transient_suppressor.reset(new TransientSuppressor());
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001731 }
peahdf3efa82015-11-28 12:35:15 -08001732 public_submodules_->transient_suppressor->Initialize(
peahde65ddc2016-09-16 15:02:15 -07001733 capture_nonlocked_.capture_processing_format.sample_rate_hz(),
1734 capture_nonlocked_.split_rate, num_proc_channels());
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001735 }
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001736}
1737
aluebs@webrtc.orgae643ce2014-12-19 19:57:34 +00001738void AudioProcessingImpl::InitializeBeamformer() {
aluebsb2328d12016-01-11 20:32:29 -08001739 if (capture_nonlocked_.beamformer_enabled) {
peahdf3efa82015-11-28 12:35:15 -08001740 if (!private_submodules_->beamformer) {
1741 private_submodules_->beamformer.reset(new NonlinearBeamformer(
Alejandro Luebsf4022ff2016-07-01 17:19:09 -07001742 capture_.array_geometry, 1u, capture_.target_direction));
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +00001743 }
peahdf3efa82015-11-28 12:35:15 -08001744 private_submodules_->beamformer->Initialize(kChunkSizeMs,
1745 capture_nonlocked_.split_rate);
aluebs@webrtc.orgae643ce2014-12-19 19:57:34 +00001746 }
1747}
1748
ekmeyerson60d9b332015-08-14 10:35:55 -07001749void AudioProcessingImpl::InitializeIntelligibility() {
peah1bcfce52016-08-26 07:16:04 -07001750#if WEBRTC_INTELLIGIBILITY_ENHANCER
Alejandro Luebsc9b0c262016-05-16 15:32:38 -07001751 if (capture_nonlocked_.intelligibility_enabled) {
peahdf3efa82015-11-28 12:35:15 -08001752 public_submodules_->intelligibility_enhancer.reset(
Alejandro Luebs18fcbcf2016-02-22 15:57:38 -08001753 new IntelligibilityEnhancer(capture_nonlocked_.split_rate,
Alex Luebs57ae8292016-03-09 16:24:34 +01001754 render_.render_audio->num_channels(),
Alejandro Luebsef009252016-09-20 14:51:56 -07001755 render_.render_audio->num_bands(),
Alex Luebs57ae8292016-03-09 16:24:34 +01001756 NoiseSuppressionImpl::num_noise_bins()));
ekmeyerson60d9b332015-08-14 10:35:55 -07001757 }
peah1bcfce52016-08-26 07:16:04 -07001758#endif
ekmeyerson60d9b332015-08-14 10:35:55 -07001759}
1760
peah8271d042016-11-22 07:24:52 -08001761void AudioProcessingImpl::InitializeLowCutFilter() {
1762 if (config_.high_pass_filter.enabled) {
1763 private_submodules_->low_cut_filter.reset(
1764 new LowCutFilter(num_proc_channels(), proc_sample_rate_hz()));
1765 } else {
1766 private_submodules_->low_cut_filter.reset();
1767 }
1768}
peahe0eae3c2016-12-14 01:16:23 -08001769void AudioProcessingImpl::InitializeEchoCanceller3() {
1770 if (capture_nonlocked_.echo_canceller3_enabled) {
1771 private_submodules_->echo_canceller3.reset(
1772 new EchoCanceller3(proc_sample_rate_hz(), true));
1773 } else {
1774 private_submodules_->echo_canceller3.reset();
1775 }
1776}
peah8271d042016-11-22 07:24:52 -08001777
peahca4cac72016-06-29 15:26:12 -07001778void AudioProcessingImpl::InitializeLevelController() {
1779 private_submodules_->level_controller->Initialize(proc_sample_rate_hz());
1780}
1781
ivoc9f4a4a02016-10-28 05:39:16 -07001782void AudioProcessingImpl::InitializeResidualEchoDetector() {
1783 private_submodules_->residual_echo_detector->Initialize();
1784}
1785
Bjorn Volcker1ca324f2015-06-29 14:57:29 +02001786void AudioProcessingImpl::MaybeUpdateHistograms() {
Bjorn Volckerd92f2672015-07-05 10:46:01 +02001787 static const int kMinDiffDelayMs = 60;
Bjorn Volcker1ca324f2015-06-29 14:57:29 +02001788
1789 if (echo_cancellation()->is_enabled()) {
Bjorn Volcker4e7aa432015-07-07 11:50:05 +02001790 // Activate delay_jumps_ counters if we know echo_cancellation is runnning.
1791 // If a stream has echo we know that the echo_cancellation is in process.
peahdf3efa82015-11-28 12:35:15 -08001792 if (capture_.stream_delay_jumps == -1 &&
Bjorn Volcker4e7aa432015-07-07 11:50:05 +02001793 echo_cancellation()->stream_has_echo()) {
peahdf3efa82015-11-28 12:35:15 -08001794 capture_.stream_delay_jumps = 0;
1795 }
1796 if (capture_.aec_system_delay_jumps == -1 &&
1797 echo_cancellation()->stream_has_echo()) {
1798 capture_.aec_system_delay_jumps = 0;
Bjorn Volcker4e7aa432015-07-07 11:50:05 +02001799 }
1800
Bjorn Volcker1ca324f2015-06-29 14:57:29 +02001801 // Detect a jump in platform reported system delay and log the difference.
peahdf3efa82015-11-28 12:35:15 -08001802 const int diff_stream_delay_ms =
1803 capture_nonlocked_.stream_delay_ms - capture_.last_stream_delay_ms;
1804 if (diff_stream_delay_ms > kMinDiffDelayMs &&
1805 capture_.last_stream_delay_ms != 0) {
asaperssona2c58e22016-03-07 01:52:59 -08001806 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.PlatformReportedStreamDelayJump",
1807 diff_stream_delay_ms, kMinDiffDelayMs, 1000, 100);
peahdf3efa82015-11-28 12:35:15 -08001808 if (capture_.stream_delay_jumps == -1) {
1809 capture_.stream_delay_jumps = 0; // Activate counter if needed.
Bjorn Volcker4e7aa432015-07-07 11:50:05 +02001810 }
peahdf3efa82015-11-28 12:35:15 -08001811 capture_.stream_delay_jumps++;
Bjorn Volcker1ca324f2015-06-29 14:57:29 +02001812 }
peahdf3efa82015-11-28 12:35:15 -08001813 capture_.last_stream_delay_ms = capture_nonlocked_.stream_delay_ms;
Bjorn Volcker1ca324f2015-06-29 14:57:29 +02001814
1815 // Detect a jump in AEC system delay and log the difference.
peah20028c42016-03-04 11:50:54 -08001816 const int samples_per_ms =
peahdf3efa82015-11-28 12:35:15 -08001817 rtc::CheckedDivExact(capture_nonlocked_.split_rate, 1000);
peah20028c42016-03-04 11:50:54 -08001818 RTC_DCHECK_LT(0, samples_per_ms);
Bjorn Volcker1ca324f2015-06-29 14:57:29 +02001819 const int aec_system_delay_ms =
peah20028c42016-03-04 11:50:54 -08001820 public_submodules_->echo_cancellation->GetSystemDelayInSamples() /
1821 samples_per_ms;
Michael Graczyk86c6d332015-07-23 11:41:39 -07001822 const int diff_aec_system_delay_ms =
peahdf3efa82015-11-28 12:35:15 -08001823 aec_system_delay_ms - capture_.last_aec_system_delay_ms;
Bjorn Volcker1ca324f2015-06-29 14:57:29 +02001824 if (diff_aec_system_delay_ms > kMinDiffDelayMs &&
peahdf3efa82015-11-28 12:35:15 -08001825 capture_.last_aec_system_delay_ms != 0) {
asaperssona2c58e22016-03-07 01:52:59 -08001826 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.AecSystemDelayJump",
1827 diff_aec_system_delay_ms, kMinDiffDelayMs, 1000,
1828 100);
peahdf3efa82015-11-28 12:35:15 -08001829 if (capture_.aec_system_delay_jumps == -1) {
1830 capture_.aec_system_delay_jumps = 0; // Activate counter if needed.
Bjorn Volcker4e7aa432015-07-07 11:50:05 +02001831 }
peahdf3efa82015-11-28 12:35:15 -08001832 capture_.aec_system_delay_jumps++;
Bjorn Volcker1ca324f2015-06-29 14:57:29 +02001833 }
peahdf3efa82015-11-28 12:35:15 -08001834 capture_.last_aec_system_delay_ms = aec_system_delay_ms;
Bjorn Volcker1ca324f2015-06-29 14:57:29 +02001835 }
1836}
1837
Bjorn Volcker4e7aa432015-07-07 11:50:05 +02001838void AudioProcessingImpl::UpdateHistogramsOnCallEnd() {
peahdf3efa82015-11-28 12:35:15 -08001839 // Run in a single-threaded manner.
1840 rtc::CritScope cs_render(&crit_render_);
1841 rtc::CritScope cs_capture(&crit_capture_);
1842
1843 if (capture_.stream_delay_jumps > -1) {
asaperssona2c58e22016-03-07 01:52:59 -08001844 RTC_HISTOGRAM_ENUMERATION(
Bjorn Volcker4e7aa432015-07-07 11:50:05 +02001845 "WebRTC.Audio.NumOfPlatformReportedStreamDelayJumps",
peahdf3efa82015-11-28 12:35:15 -08001846 capture_.stream_delay_jumps, 51);
Bjorn Volcker4e7aa432015-07-07 11:50:05 +02001847 }
peahdf3efa82015-11-28 12:35:15 -08001848 capture_.stream_delay_jumps = -1;
1849 capture_.last_stream_delay_ms = 0;
Bjorn Volcker4e7aa432015-07-07 11:50:05 +02001850
peahdf3efa82015-11-28 12:35:15 -08001851 if (capture_.aec_system_delay_jumps > -1) {
asaperssona2c58e22016-03-07 01:52:59 -08001852 RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.NumOfAecSystemDelayJumps",
1853 capture_.aec_system_delay_jumps, 51);
Bjorn Volcker4e7aa432015-07-07 11:50:05 +02001854 }
peahdf3efa82015-11-28 12:35:15 -08001855 capture_.aec_system_delay_jumps = -1;
1856 capture_.last_aec_system_delay_ms = 0;
Bjorn Volcker4e7aa432015-07-07 11:50:05 +02001857}
1858
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001859#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
peahdf3efa82015-11-28 12:35:15 -08001860int AudioProcessingImpl::WriteMessageToDebugFile(
1861 FileWrapper* debug_file,
ivocd66b44d2016-01-15 03:06:36 -08001862 int64_t* filesize_limit_bytes,
peahdf3efa82015-11-28 12:35:15 -08001863 rtc::CriticalSection* crit_debug,
1864 ApmDebugDumpThreadState* debug_state) {
1865 int32_t size = debug_state->event_msg->ByteSize();
ajm@google.com808e0e02011-08-03 21:08:51 +00001866 if (size <= 0) {
1867 return kUnspecifiedError;
1868 }
andrew@webrtc.org621df672013-10-22 10:27:23 +00001869#if defined(WEBRTC_ARCH_BIG_ENDIAN)
Michael Graczyk86c6d332015-07-23 11:41:39 -07001870// TODO(ajm): Use little-endian "on the wire". For the moment, we can be
1871// pretty safe in assuming little-endian.
ajm@google.com808e0e02011-08-03 21:08:51 +00001872#endif
1873
peahdf3efa82015-11-28 12:35:15 -08001874 if (!debug_state->event_msg->SerializeToString(&debug_state->event_str)) {
ajm@google.com808e0e02011-08-03 21:08:51 +00001875 return kUnspecifiedError;
1876 }
1877
peahdf3efa82015-11-28 12:35:15 -08001878 {
1879 // Ensure atomic writes of the message.
ivocd66b44d2016-01-15 03:06:36 -08001880 rtc::CritScope cs_debug(crit_debug);
1881
tommia6219cc2016-06-15 10:30:14 -07001882 RTC_DCHECK(debug_file->is_open());
ivocd66b44d2016-01-15 03:06:36 -08001883 // Update the byte counter.
1884 if (*filesize_limit_bytes >= 0) {
1885 *filesize_limit_bytes -=
1886 (sizeof(int32_t) + debug_state->event_str.length());
1887 if (*filesize_limit_bytes < 0) {
1888 // Not enough bytes are left to write this message, so stop logging.
1889 debug_file->CloseFile();
1890 return kNoError;
1891 }
1892 }
peahdf3efa82015-11-28 12:35:15 -08001893 // Write message preceded by its size.
1894 if (!debug_file->Write(&size, sizeof(int32_t))) {
1895 return kFileError;
1896 }
1897 if (!debug_file->Write(debug_state->event_str.data(),
1898 debug_state->event_str.length())) {
1899 return kFileError;
1900 }
ajm@google.com808e0e02011-08-03 21:08:51 +00001901 }
1902
peahdf3efa82015-11-28 12:35:15 -08001903 debug_state->event_msg->Clear();
ajm@google.com808e0e02011-08-03 21:08:51 +00001904
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001905 return kNoError;
ajm@google.com808e0e02011-08-03 21:08:51 +00001906}
1907
1908int AudioProcessingImpl::WriteInitMessage() {
peahdf3efa82015-11-28 12:35:15 -08001909 debug_dump_.capture.event_msg->set_type(audioproc::Event::INIT);
1910 audioproc::Init* msg = debug_dump_.capture.event_msg->mutable_init();
1911 msg->set_sample_rate(formats_.api_format.input_stream().sample_rate_hz());
ajm@google.com808e0e02011-08-03 21:08:51 +00001912
mbonadei7c2c8432017-04-07 00:59:12 -07001913 msg->set_num_input_channels(static_cast<int32_t>(
Peter Kasting69558702016-01-12 16:26:35 -08001914 formats_.api_format.input_stream().num_channels()));
mbonadei7c2c8432017-04-07 00:59:12 -07001915 msg->set_num_output_channels(static_cast<int32_t>(
Peter Kasting69558702016-01-12 16:26:35 -08001916 formats_.api_format.output_stream().num_channels()));
mbonadei7c2c8432017-04-07 00:59:12 -07001917 msg->set_num_reverse_channels(static_cast<int32_t>(
Peter Kasting69558702016-01-12 16:26:35 -08001918 formats_.api_format.reverse_input_stream().num_channels()));
peahdf3efa82015-11-28 12:35:15 -08001919 msg->set_reverse_sample_rate(
1920 formats_.api_format.reverse_input_stream().sample_rate_hz());
1921 msg->set_output_sample_rate(
1922 formats_.api_format.output_stream().sample_rate_hz());
peahc7bdf8a2016-04-11 07:05:53 -07001923 msg->set_reverse_output_sample_rate(
1924 formats_.api_format.reverse_output_stream().sample_rate_hz());
1925 msg->set_num_reverse_output_channels(
1926 formats_.api_format.reverse_output_stream().num_channels());
peahdf3efa82015-11-28 12:35:15 -08001927
1928 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
ivocd66b44d2016-01-15 03:06:36 -08001929 &debug_dump_.num_bytes_left_for_log_,
peahdf3efa82015-11-28 12:35:15 -08001930 &crit_debug_, &debug_dump_.capture));
Minyue13b96ba2015-10-03 00:39:14 +02001931 return kNoError;
1932}
1933
1934int AudioProcessingImpl::WriteConfigMessage(bool forced) {
1935 audioproc::Config config;
1936
peahdf3efa82015-11-28 12:35:15 -08001937 config.set_aec_enabled(public_submodules_->echo_cancellation->is_enabled());
Minyue13b96ba2015-10-03 00:39:14 +02001938 config.set_aec_delay_agnostic_enabled(
peahdf3efa82015-11-28 12:35:15 -08001939 public_submodules_->echo_cancellation->is_delay_agnostic_enabled());
Minyue13b96ba2015-10-03 00:39:14 +02001940 config.set_aec_drift_compensation_enabled(
peahdf3efa82015-11-28 12:35:15 -08001941 public_submodules_->echo_cancellation->is_drift_compensation_enabled());
Minyue13b96ba2015-10-03 00:39:14 +02001942 config.set_aec_extended_filter_enabled(
peahdf3efa82015-11-28 12:35:15 -08001943 public_submodules_->echo_cancellation->is_extended_filter_enabled());
1944 config.set_aec_suppression_level(static_cast<int>(
1945 public_submodules_->echo_cancellation->suppression_level()));
Minyue13b96ba2015-10-03 00:39:14 +02001946
peahdf3efa82015-11-28 12:35:15 -08001947 config.set_aecm_enabled(
1948 public_submodules_->echo_control_mobile->is_enabled());
Minyue13b96ba2015-10-03 00:39:14 +02001949 config.set_aecm_comfort_noise_enabled(
peahdf3efa82015-11-28 12:35:15 -08001950 public_submodules_->echo_control_mobile->is_comfort_noise_enabled());
1951 config.set_aecm_routing_mode(static_cast<int>(
1952 public_submodules_->echo_control_mobile->routing_mode()));
Minyue13b96ba2015-10-03 00:39:14 +02001953
peahdf3efa82015-11-28 12:35:15 -08001954 config.set_agc_enabled(public_submodules_->gain_control->is_enabled());
1955 config.set_agc_mode(
1956 static_cast<int>(public_submodules_->gain_control->mode()));
1957 config.set_agc_limiter_enabled(
1958 public_submodules_->gain_control->is_limiter_enabled());
peahbe615622016-02-13 16:40:47 -08001959 config.set_noise_robust_agc_enabled(constants_.use_experimental_agc);
Minyue13b96ba2015-10-03 00:39:14 +02001960
peah8271d042016-11-22 07:24:52 -08001961 config.set_hpf_enabled(config_.high_pass_filter.enabled);
Minyue13b96ba2015-10-03 00:39:14 +02001962
peahdf3efa82015-11-28 12:35:15 -08001963 config.set_ns_enabled(public_submodules_->noise_suppression->is_enabled());
1964 config.set_ns_level(
1965 static_cast<int>(public_submodules_->noise_suppression->level()));
Minyue13b96ba2015-10-03 00:39:14 +02001966
peahdf3efa82015-11-28 12:35:15 -08001967 config.set_transient_suppression_enabled(
1968 capture_.transient_suppressor_enabled);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -07001969 config.set_intelligibility_enhancer_enabled(
1970 capture_nonlocked_.intelligibility_enabled);
Minyue13b96ba2015-10-03 00:39:14 +02001971
peah7789fe72016-04-15 01:19:44 -07001972 std::string experiments_description =
1973 public_submodules_->echo_cancellation->GetExperimentsDescription();
1974 // TODO(peah): Add semicolon-separated concatenations of experiment
1975 // descriptions for other submodules.
peahca4cac72016-06-29 15:26:12 -07001976 if (capture_nonlocked_.level_controller_enabled) {
1977 experiments_description += "LevelController;";
1978 }
henrik.lundinbd681b92016-12-05 09:08:42 -08001979 if (constants_.agc_clipped_level_min != kClippedLevelMin) {
1980 experiments_description += "AgcClippingLevelExperiment;";
1981 }
peahe0eae3c2016-12-14 01:16:23 -08001982 if (capture_nonlocked_.echo_canceller3_enabled) {
1983 experiments_description += "EchoCanceller3;";
1984 }
peah7789fe72016-04-15 01:19:44 -07001985 config.set_experiments_description(experiments_description);
1986
mbonadei7c2c8432017-04-07 00:59:12 -07001987 ProtoString serialized_config = config.SerializeAsString();
peahdf3efa82015-11-28 12:35:15 -08001988 if (!forced &&
1989 debug_dump_.capture.last_serialized_config == serialized_config) {
Minyue13b96ba2015-10-03 00:39:14 +02001990 return kNoError;
ajm@google.com808e0e02011-08-03 21:08:51 +00001991 }
1992
peahdf3efa82015-11-28 12:35:15 -08001993 debug_dump_.capture.last_serialized_config = serialized_config;
Minyue13b96ba2015-10-03 00:39:14 +02001994
peahdf3efa82015-11-28 12:35:15 -08001995 debug_dump_.capture.event_msg->set_type(audioproc::Event::CONFIG);
1996 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config);
Minyue13b96ba2015-10-03 00:39:14 +02001997
peahdf3efa82015-11-28 12:35:15 -08001998 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
ivocd66b44d2016-01-15 03:06:36 -08001999 &debug_dump_.num_bytes_left_for_log_,
peahdf3efa82015-11-28 12:35:15 -08002000 &crit_debug_, &debug_dump_.capture));
ajm@google.com808e0e02011-08-03 21:08:51 +00002001 return kNoError;
2002}
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00002003#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002004
kwiberg83ffe452016-08-29 14:46:07 -07002005AudioProcessingImpl::ApmCaptureState::ApmCaptureState(
2006 bool transient_suppressor_enabled,
2007 const std::vector<Point>& array_geometry,
2008 SphericalPointf target_direction)
2009 : aec_system_delay_jumps(-1),
2010 delay_offset_ms(0),
2011 was_stream_delay_set(false),
2012 last_stream_delay_ms(0),
2013 last_aec_system_delay_ms(0),
2014 stream_delay_jumps(-1),
2015 output_will_be_muted(false),
2016 key_pressed(false),
2017 transient_suppressor_enabled(transient_suppressor_enabled),
2018 array_geometry(array_geometry),
2019 target_direction(target_direction),
peahde65ddc2016-09-16 15:02:15 -07002020 capture_processing_format(kSampleRate16kHz),
peah67995532017-04-10 14:12:41 -07002021 split_rate(kSampleRate16kHz),
2022 previous_agc_level(0),
2023 echo_path_gain_change(false) {}
kwiberg83ffe452016-08-29 14:46:07 -07002024
2025AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default;
2026
2027AudioProcessingImpl::ApmRenderState::ApmRenderState() = default;
2028
2029AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default;
2030
niklase@google.com470e71d2011-07-07 08:21:25 +00002031} // namespace webrtc