niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | 4065403 | 2012-01-30 20:51:15 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/audio_processing_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
peah | 103ac7e | 2017-04-12 05:40:55 -0700 | [diff] [blame] | 13 | #include <math.h> |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 14 | #include <algorithm> |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 15 | #include <string> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "common_audio/audio_converter.h" |
| 18 | #include "common_audio/channel_buffer.h" |
| 19 | #include "common_audio/include/audio_util.h" |
| 20 | #include "common_audio/signal_processing/include/signal_processing_library.h" |
| 21 | #include "modules/audio_processing/aec/aec_core.h" |
| 22 | #include "modules/audio_processing/aec3/echo_canceller3.h" |
| 23 | #include "modules/audio_processing/agc/agc_manager_direct.h" |
| 24 | #include "modules/audio_processing/agc2/gain_controller2.h" |
| 25 | #include "modules/audio_processing/audio_buffer.h" |
| 26 | #include "modules/audio_processing/beamformer/nonlinear_beamformer.h" |
| 27 | #include "modules/audio_processing/common.h" |
| 28 | #include "modules/audio_processing/echo_cancellation_impl.h" |
| 29 | #include "modules/audio_processing/echo_control_mobile_impl.h" |
| 30 | #include "modules/audio_processing/gain_control_for_experimental_agc.h" |
| 31 | #include "modules/audio_processing/gain_control_impl.h" |
| 32 | #include "rtc_base/checks.h" |
| 33 | #include "rtc_base/logging.h" |
| 34 | #include "rtc_base/platform_file.h" |
Niels Möller | 84255bb | 2017-10-06 13:43:23 +0200 | [diff] [blame] | 35 | #include "rtc_base/refcountedobject.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 36 | #include "rtc_base/trace_event.h" |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 37 | #if WEBRTC_INTELLIGIBILITY_ENHANCER |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 38 | #include "modules/audio_processing/intelligibility/intelligibility_enhancer.h" |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 39 | #endif |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 40 | #include "modules/audio_processing/level_controller/level_controller.h" |
| 41 | #include "modules/audio_processing/level_estimator_impl.h" |
| 42 | #include "modules/audio_processing/low_cut_filter.h" |
| 43 | #include "modules/audio_processing/noise_suppression_impl.h" |
| 44 | #include "modules/audio_processing/residual_echo_detector.h" |
| 45 | #include "modules/audio_processing/transient/transient_suppressor.h" |
| 46 | #include "modules/audio_processing/voice_detection_impl.h" |
| 47 | #include "modules/include/module_common_types.h" |
| 48 | #include "system_wrappers/include/file_wrapper.h" |
| 49 | #include "system_wrappers/include/metrics.h" |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 50 | |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 51 | // Check to verify that the define for the intelligibility enhancer is properly |
| 52 | // set. |
| 53 | #if !defined(WEBRTC_INTELLIGIBILITY_ENHANCER) || \ |
| 54 | (WEBRTC_INTELLIGIBILITY_ENHANCER != 0 && \ |
| 55 | WEBRTC_INTELLIGIBILITY_ENHANCER != 1) |
| 56 | #error "Set WEBRTC_INTELLIGIBILITY_ENHANCER to either 0 or 1" |
| 57 | #endif |
| 58 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 59 | #define RETURN_ON_ERR(expr) \ |
| 60 | do { \ |
| 61 | int err = (expr); \ |
| 62 | if (err != kNoError) { \ |
| 63 | return err; \ |
| 64 | } \ |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 65 | } while (0) |
| 66 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | namespace webrtc { |
aluebs | df6416a | 2016-03-16 18:26:35 -0700 | [diff] [blame] | 68 | |
kwiberg | d59d3bb | 2016-09-13 07:49:33 -0700 | [diff] [blame] | 69 | constexpr int AudioProcessing::kNativeSampleRatesHz[]; |
aluebs | df6416a | 2016-03-16 18:26:35 -0700 | [diff] [blame] | 70 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 71 | namespace { |
| 72 | |
| 73 | static bool LayoutHasKeyboard(AudioProcessing::ChannelLayout layout) { |
| 74 | switch (layout) { |
| 75 | case AudioProcessing::kMono: |
| 76 | case AudioProcessing::kStereo: |
| 77 | return false; |
| 78 | case AudioProcessing::kMonoAndKeyboard: |
| 79 | case AudioProcessing::kStereoAndKeyboard: |
| 80 | return true; |
| 81 | } |
| 82 | |
kwiberg | 9e2be5f | 2016-09-14 05:23:22 -0700 | [diff] [blame] | 83 | RTC_NOTREACHED(); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 84 | return false; |
| 85 | } |
aluebs | df6416a | 2016-03-16 18:26:35 -0700 | [diff] [blame] | 86 | |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 87 | bool SampleRateSupportsMultiBand(int sample_rate_hz) { |
aluebs | df6416a | 2016-03-16 18:26:35 -0700 | [diff] [blame] | 88 | return sample_rate_hz == AudioProcessing::kSampleRate32kHz || |
| 89 | sample_rate_hz == AudioProcessing::kSampleRate48kHz; |
| 90 | } |
| 91 | |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 92 | int FindNativeProcessRateToUse(int minimum_rate, bool band_splitting_required) { |
| 93 | #ifdef WEBRTC_ARCH_ARM_FAMILY |
kwiberg | d59d3bb | 2016-09-13 07:49:33 -0700 | [diff] [blame] | 94 | constexpr int kMaxSplittingNativeProcessRate = |
| 95 | AudioProcessing::kSampleRate32kHz; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 96 | #else |
kwiberg | d59d3bb | 2016-09-13 07:49:33 -0700 | [diff] [blame] | 97 | constexpr int kMaxSplittingNativeProcessRate = |
| 98 | AudioProcessing::kSampleRate48kHz; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 99 | #endif |
kwiberg | d59d3bb | 2016-09-13 07:49:33 -0700 | [diff] [blame] | 100 | static_assert( |
| 101 | kMaxSplittingNativeProcessRate <= AudioProcessing::kMaxNativeSampleRateHz, |
| 102 | ""); |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 103 | const int uppermost_native_rate = band_splitting_required |
| 104 | ? kMaxSplittingNativeProcessRate |
| 105 | : AudioProcessing::kSampleRate48kHz; |
| 106 | |
| 107 | for (auto rate : AudioProcessing::kNativeSampleRatesHz) { |
| 108 | if (rate >= uppermost_native_rate) { |
| 109 | return uppermost_native_rate; |
| 110 | } |
| 111 | if (rate >= minimum_rate) { |
aluebs | df6416a | 2016-03-16 18:26:35 -0700 | [diff] [blame] | 112 | return rate; |
| 113 | } |
| 114 | } |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 115 | RTC_NOTREACHED(); |
| 116 | return uppermost_native_rate; |
aluebs | df6416a | 2016-03-16 18:26:35 -0700 | [diff] [blame] | 117 | } |
| 118 | |
peah | 9e6a290 | 2017-05-15 07:19:21 -0700 | [diff] [blame] | 119 | // Maximum lengths that frame of samples being passed from the render side to |
| 120 | // the capture side can have (does not apply to AEC3). |
| 121 | static const size_t kMaxAllowedValuesOfSamplesPerBand = 160; |
| 122 | static const size_t kMaxAllowedValuesOfSamplesPerFrame = 480; |
| 123 | |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 124 | // Maximum number of frames to buffer in the render queue. |
| 125 | // TODO(peah): Decrease this once we properly handle hugely unbalanced |
| 126 | // reverse and forward call numbers. |
| 127 | static const size_t kMaxNumFramesToBuffer = 100; |
| 128 | |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 129 | class HighPassFilterImpl : public HighPassFilter { |
| 130 | public: |
| 131 | explicit HighPassFilterImpl(AudioProcessingImpl* apm) : apm_(apm) {} |
| 132 | ~HighPassFilterImpl() override = default; |
| 133 | |
| 134 | // HighPassFilter implementation. |
| 135 | int Enable(bool enable) override { |
| 136 | apm_->MutateConfig([enable](AudioProcessing::Config* config) { |
| 137 | config->high_pass_filter.enabled = enable; |
| 138 | }); |
| 139 | |
| 140 | return AudioProcessing::kNoError; |
| 141 | } |
| 142 | |
| 143 | bool is_enabled() const override { |
| 144 | return apm_->GetConfig().high_pass_filter.enabled; |
| 145 | } |
| 146 | |
| 147 | private: |
| 148 | AudioProcessingImpl* apm_; |
| 149 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(HighPassFilterImpl); |
| 150 | }; |
| 151 | |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 152 | webrtc::InternalAPMStreamsConfig ToStreamsConfig( |
| 153 | const ProcessingConfig& api_format) { |
| 154 | webrtc::InternalAPMStreamsConfig result; |
| 155 | result.input_sample_rate = api_format.input_stream().sample_rate_hz(); |
| 156 | result.input_num_channels = api_format.input_stream().num_channels(); |
| 157 | result.output_num_channels = api_format.output_stream().num_channels(); |
| 158 | result.render_input_num_channels = |
| 159 | api_format.reverse_input_stream().num_channels(); |
| 160 | result.render_input_sample_rate = |
| 161 | api_format.reverse_input_stream().sample_rate_hz(); |
| 162 | result.output_sample_rate = api_format.output_stream().sample_rate_hz(); |
| 163 | result.render_output_sample_rate = |
| 164 | api_format.reverse_output_stream().sample_rate_hz(); |
| 165 | result.render_output_num_channels = |
| 166 | api_format.reverse_output_stream().num_channels(); |
| 167 | return result; |
| 168 | } |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 169 | } // namespace |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 170 | |
| 171 | // Throughout webrtc, it's assumed that success is represented by zero. |
kwiberg@webrtc.org | 2ebfac5 | 2015-01-14 10:51:54 +0000 | [diff] [blame] | 172 | static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero"); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 173 | |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 174 | AudioProcessingImpl::ApmSubmoduleStates::ApmSubmoduleStates( |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 175 | bool capture_post_processor_enabled, |
| 176 | bool render_pre_processor_enabled) |
| 177 | : capture_post_processor_enabled_(capture_post_processor_enabled), |
| 178 | render_pre_processor_enabled_(render_pre_processor_enabled) {} |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 179 | |
| 180 | bool AudioProcessingImpl::ApmSubmoduleStates::Update( |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 181 | bool low_cut_filter_enabled, |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 182 | bool echo_canceller_enabled, |
| 183 | bool mobile_echo_controller_enabled, |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 184 | bool residual_echo_detector_enabled, |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 185 | bool noise_suppressor_enabled, |
| 186 | bool intelligibility_enhancer_enabled, |
| 187 | bool beamformer_enabled, |
| 188 | bool adaptive_gain_controller_enabled, |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 189 | bool gain_controller2_enabled, |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 190 | bool level_controller_enabled, |
Gustaf Ullberg | ce045ac | 2017-10-16 13:49:04 +0200 | [diff] [blame] | 191 | bool echo_controller_enabled, |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 192 | bool voice_activity_detector_enabled, |
| 193 | bool level_estimator_enabled, |
| 194 | bool transient_suppressor_enabled) { |
| 195 | bool changed = false; |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 196 | changed |= (low_cut_filter_enabled != low_cut_filter_enabled_); |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 197 | changed |= (echo_canceller_enabled != echo_canceller_enabled_); |
| 198 | changed |= |
| 199 | (mobile_echo_controller_enabled != mobile_echo_controller_enabled_); |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 200 | changed |= |
| 201 | (residual_echo_detector_enabled != residual_echo_detector_enabled_); |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 202 | changed |= (noise_suppressor_enabled != noise_suppressor_enabled_); |
| 203 | changed |= |
| 204 | (intelligibility_enhancer_enabled != intelligibility_enhancer_enabled_); |
| 205 | changed |= (beamformer_enabled != beamformer_enabled_); |
| 206 | changed |= |
| 207 | (adaptive_gain_controller_enabled != adaptive_gain_controller_enabled_); |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 208 | changed |= |
| 209 | (gain_controller2_enabled != gain_controller2_enabled_); |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 210 | changed |= (level_controller_enabled != level_controller_enabled_); |
Gustaf Ullberg | ce045ac | 2017-10-16 13:49:04 +0200 | [diff] [blame] | 211 | changed |= (echo_controller_enabled != echo_controller_enabled_); |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 212 | changed |= (level_estimator_enabled != level_estimator_enabled_); |
| 213 | changed |= |
| 214 | (voice_activity_detector_enabled != voice_activity_detector_enabled_); |
| 215 | changed |= (transient_suppressor_enabled != transient_suppressor_enabled_); |
| 216 | if (changed) { |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 217 | low_cut_filter_enabled_ = low_cut_filter_enabled; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 218 | echo_canceller_enabled_ = echo_canceller_enabled; |
| 219 | mobile_echo_controller_enabled_ = mobile_echo_controller_enabled; |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 220 | residual_echo_detector_enabled_ = residual_echo_detector_enabled; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 221 | noise_suppressor_enabled_ = noise_suppressor_enabled; |
| 222 | intelligibility_enhancer_enabled_ = intelligibility_enhancer_enabled; |
| 223 | beamformer_enabled_ = beamformer_enabled; |
| 224 | adaptive_gain_controller_enabled_ = adaptive_gain_controller_enabled; |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 225 | gain_controller2_enabled_ = gain_controller2_enabled; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 226 | level_controller_enabled_ = level_controller_enabled; |
Gustaf Ullberg | ce045ac | 2017-10-16 13:49:04 +0200 | [diff] [blame] | 227 | echo_controller_enabled_ = echo_controller_enabled; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 228 | level_estimator_enabled_ = level_estimator_enabled; |
| 229 | voice_activity_detector_enabled_ = voice_activity_detector_enabled; |
| 230 | transient_suppressor_enabled_ = transient_suppressor_enabled; |
| 231 | } |
| 232 | |
| 233 | changed |= first_update_; |
| 234 | first_update_ = false; |
| 235 | return changed; |
| 236 | } |
| 237 | |
| 238 | bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandSubModulesActive() |
| 239 | const { |
| 240 | #if WEBRTC_INTELLIGIBILITY_ENHANCER |
| 241 | return CaptureMultiBandProcessingActive() || |
peah | 5277584 | 2017-05-16 06:14:09 -0700 | [diff] [blame] | 242 | intelligibility_enhancer_enabled_ || voice_activity_detector_enabled_; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 243 | #else |
peah | 5277584 | 2017-05-16 06:14:09 -0700 | [diff] [blame] | 244 | return CaptureMultiBandProcessingActive() || voice_activity_detector_enabled_; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 245 | #endif |
| 246 | } |
| 247 | |
| 248 | bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandProcessingActive() |
| 249 | const { |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 250 | return low_cut_filter_enabled_ || echo_canceller_enabled_ || |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 251 | mobile_echo_controller_enabled_ || noise_suppressor_enabled_ || |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 252 | beamformer_enabled_ || adaptive_gain_controller_enabled_ || |
Gustaf Ullberg | ce045ac | 2017-10-16 13:49:04 +0200 | [diff] [blame] | 253 | echo_controller_enabled_; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 254 | } |
| 255 | |
peah | 23ac8b4 | 2017-05-23 05:33:56 -0700 | [diff] [blame] | 256 | bool AudioProcessingImpl::ApmSubmoduleStates::CaptureFullBandProcessingActive() |
| 257 | const { |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 258 | return level_controller_enabled_ || gain_controller2_enabled_ || |
| 259 | capture_post_processor_enabled_; |
peah | 23ac8b4 | 2017-05-23 05:33:56 -0700 | [diff] [blame] | 260 | } |
| 261 | |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 262 | bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandSubModulesActive() |
| 263 | const { |
| 264 | return RenderMultiBandProcessingActive() || echo_canceller_enabled_ || |
ivoc | 20270be | 2016-11-15 05:24:35 -0800 | [diff] [blame] | 265 | mobile_echo_controller_enabled_ || adaptive_gain_controller_enabled_ || |
Gustaf Ullberg | ce045ac | 2017-10-16 13:49:04 +0200 | [diff] [blame] | 266 | echo_controller_enabled_; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 269 | bool AudioProcessingImpl::ApmSubmoduleStates::RenderFullBandProcessingActive() |
| 270 | const { |
| 271 | return render_pre_processor_enabled_; |
| 272 | } |
| 273 | |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 274 | bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandProcessingActive() |
| 275 | const { |
| 276 | #if WEBRTC_INTELLIGIBILITY_ENHANCER |
| 277 | return intelligibility_enhancer_enabled_; |
| 278 | #else |
| 279 | return false; |
| 280 | #endif |
| 281 | } |
| 282 | |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 283 | struct AudioProcessingImpl::ApmPublicSubmodules { |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 284 | ApmPublicSubmodules() {} |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 285 | // Accessed externally of APM without any lock acquired. |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 286 | std::unique_ptr<EchoCancellationImpl> echo_cancellation; |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 287 | std::unique_ptr<EchoControlMobileImpl> echo_control_mobile; |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 288 | std::unique_ptr<GainControlImpl> gain_control; |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 289 | std::unique_ptr<LevelEstimatorImpl> level_estimator; |
| 290 | std::unique_ptr<NoiseSuppressionImpl> noise_suppression; |
| 291 | std::unique_ptr<VoiceDetectionImpl> voice_detection; |
| 292 | std::unique_ptr<GainControlForExperimentalAgc> |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 293 | gain_control_for_experimental_agc; |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 294 | |
| 295 | // Accessed internally from both render and capture. |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 296 | std::unique_ptr<TransientSuppressor> transient_suppressor; |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 297 | #if WEBRTC_INTELLIGIBILITY_ENHANCER |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 298 | std::unique_ptr<IntelligibilityEnhancer> intelligibility_enhancer; |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 299 | #endif |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | struct AudioProcessingImpl::ApmPrivateSubmodules { |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 303 | ApmPrivateSubmodules(NonlinearBeamformer* beamformer, |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 304 | std::unique_ptr<CustomProcessing> capture_post_processor, |
| 305 | std::unique_ptr<CustomProcessing> render_pre_processor) |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 306 | : beamformer(beamformer), |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 307 | capture_post_processor(std::move(capture_post_processor)), |
| 308 | render_pre_processor(std::move(render_pre_processor)) {} |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 309 | // Accessed internally from capture or during initialization |
Alejandro Luebs | f4022ff | 2016-07-01 17:19:09 -0700 | [diff] [blame] | 310 | std::unique_ptr<NonlinearBeamformer> beamformer; |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 311 | std::unique_ptr<AgcManagerDirect> agc_manager; |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 312 | std::unique_ptr<GainController2> gain_controller2; |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 313 | std::unique_ptr<LowCutFilter> low_cut_filter; |
peah | ca4cac7 | 2016-06-29 15:26:12 -0700 | [diff] [blame] | 314 | std::unique_ptr<LevelController> level_controller; |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 315 | std::unique_ptr<ResidualEchoDetector> residual_echo_detector; |
Gustaf Ullberg | 59ff0e2 | 2017-10-09 10:20:34 +0200 | [diff] [blame] | 316 | std::unique_ptr<EchoControl> echo_controller; |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 317 | std::unique_ptr<CustomProcessing> capture_post_processor; |
| 318 | std::unique_ptr<CustomProcessing> render_pre_processor; |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 319 | }; |
| 320 | |
Ivo Creusen | 5ec7e12 | 2017-12-22 11:35:59 +0100 | [diff] [blame^] | 321 | AudioProcessingBuilder::AudioProcessingBuilder() = default; |
| 322 | AudioProcessingBuilder::~AudioProcessingBuilder() = default; |
| 323 | |
| 324 | AudioProcessingBuilder& AudioProcessingBuilder::SetCapturePostProcessing( |
| 325 | std::unique_ptr<CustomProcessing> capture_post_processing) { |
| 326 | capture_post_processing_ = std::move(capture_post_processing); |
| 327 | return *this; |
| 328 | } |
| 329 | |
| 330 | AudioProcessingBuilder& AudioProcessingBuilder::SetRenderPreProcessing( |
| 331 | std::unique_ptr<CustomProcessing> render_pre_processing) { |
| 332 | render_pre_processing_ = std::move(render_pre_processing); |
| 333 | return *this; |
| 334 | } |
| 335 | |
| 336 | AudioProcessingBuilder& AudioProcessingBuilder::SetEchoControlFactory( |
| 337 | std::unique_ptr<EchoControlFactory> echo_control_factory) { |
| 338 | echo_control_factory_ = std::move(echo_control_factory); |
| 339 | return *this; |
| 340 | } |
| 341 | |
| 342 | AudioProcessingBuilder& AudioProcessingBuilder::SetNonlinearBeamformer( |
| 343 | std::unique_ptr<NonlinearBeamformer> nonlinear_beamformer) { |
| 344 | nonlinear_beamformer_ = std::move(nonlinear_beamformer); |
| 345 | return *this; |
| 346 | } |
| 347 | |
| 348 | AudioProcessing* AudioProcessingBuilder::Create() { |
| 349 | webrtc::Config config; |
| 350 | return Create(config); |
| 351 | } |
| 352 | |
| 353 | AudioProcessing* AudioProcessingBuilder::Create(const webrtc::Config& config) { |
| 354 | return AudioProcessing::Create(config, std::move(capture_post_processing_), |
| 355 | std::move(render_pre_processing_), |
| 356 | std::move(echo_control_factory_), |
| 357 | nonlinear_beamformer_.release()); |
| 358 | } |
| 359 | |
andrew@webrtc.org | e84978f | 2014-01-25 02:09:06 +0000 | [diff] [blame] | 360 | AudioProcessing* AudioProcessing::Create() { |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 361 | webrtc::Config config; |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 362 | return Create(config, nullptr, nullptr, nullptr, nullptr); |
andrew@webrtc.org | e84978f | 2014-01-25 02:09:06 +0000 | [diff] [blame] | 363 | } |
| 364 | |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 365 | AudioProcessing* AudioProcessing::Create(const webrtc::Config& config) { |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 366 | return Create(config, nullptr, nullptr, nullptr, nullptr); |
aluebs@webrtc.org | d82f55d | 2015-01-15 18:07:21 +0000 | [diff] [blame] | 367 | } |
| 368 | |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 369 | AudioProcessing* AudioProcessing::Create(const webrtc::Config& config, |
Alejandro Luebs | f4022ff | 2016-07-01 17:19:09 -0700 | [diff] [blame] | 370 | NonlinearBeamformer* beamformer) { |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 371 | return Create(config, nullptr, nullptr, nullptr, beamformer); |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | AudioProcessing* AudioProcessing::Create( |
| 375 | const webrtc::Config& config, |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 376 | std::unique_ptr<CustomProcessing> capture_post_processor, |
| 377 | std::unique_ptr<EchoControlFactory> echo_control_factory, |
| 378 | NonlinearBeamformer* beamformer) { |
| 379 | return Create(config, std::move(capture_post_processor), nullptr, |
| 380 | std::move(echo_control_factory), beamformer); |
| 381 | } |
| 382 | |
| 383 | AudioProcessing* AudioProcessing::Create( |
| 384 | const webrtc::Config& config, |
| 385 | std::unique_ptr<CustomProcessing> capture_post_processor, |
| 386 | std::unique_ptr<CustomProcessing> render_pre_processor, |
Gustaf Ullberg | 002ef28 | 2017-10-12 15:13:17 +0200 | [diff] [blame] | 387 | std::unique_ptr<EchoControlFactory> echo_control_factory, |
Gustaf Ullberg | d8579e0 | 2017-10-11 16:29:02 +0200 | [diff] [blame] | 388 | NonlinearBeamformer* beamformer) { |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 389 | AudioProcessingImpl* apm = new rtc::RefCountedObject<AudioProcessingImpl>( |
Gustaf Ullberg | 002ef28 | 2017-10-12 15:13:17 +0200 | [diff] [blame] | 390 | config, std::move(capture_post_processor), |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 391 | std::move(render_pre_processor), std::move(echo_control_factory), |
| 392 | beamformer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 393 | if (apm->Initialize() != kNoError) { |
| 394 | delete apm; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 395 | apm = nullptr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | return apm; |
| 399 | } |
| 400 | |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 401 | AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config) |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 402 | : AudioProcessingImpl(config, nullptr, nullptr, nullptr, nullptr) {} |
aluebs@webrtc.org | d82f55d | 2015-01-15 18:07:21 +0000 | [diff] [blame] | 403 | |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 404 | AudioProcessingImpl::AudioProcessingImpl( |
| 405 | const webrtc::Config& config, |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 406 | std::unique_ptr<CustomProcessing> capture_post_processor, |
| 407 | std::unique_ptr<CustomProcessing> render_pre_processor, |
Gustaf Ullberg | 002ef28 | 2017-10-12 15:13:17 +0200 | [diff] [blame] | 408 | std::unique_ptr<EchoControlFactory> echo_control_factory, |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 409 | NonlinearBeamformer* beamformer) |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 410 | : high_pass_filter_impl_(new HighPassFilterImpl(this)), |
Gustaf Ullberg | 002ef28 | 2017-10-12 15:13:17 +0200 | [diff] [blame] | 411 | echo_control_factory_(std::move(echo_control_factory)), |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 412 | submodule_states_(!!capture_post_processor, !!render_pre_processor), |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 413 | public_submodules_(new ApmPublicSubmodules()), |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 414 | private_submodules_( |
| 415 | new ApmPrivateSubmodules(beamformer, |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 416 | std::move(capture_post_processor), |
| 417 | std::move(render_pre_processor))), |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 418 | constants_(config.Get<ExperimentalAgc>().startup_min_volume, |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 419 | config.Get<ExperimentalAgc>().clipped_level_min, |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 420 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 421 | false), |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 422 | #else |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 423 | config.Get<ExperimentalAgc>().enabled), |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 424 | #endif |
andrew | 1c7075f | 2015-06-24 18:14:14 -0700 | [diff] [blame] | 425 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 426 | capture_(false, |
andrew | 1c7075f | 2015-06-24 18:14:14 -0700 | [diff] [blame] | 427 | #else |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 428 | capture_(config.Get<ExperimentalNs>().enabled, |
andrew | 1c7075f | 2015-06-24 18:14:14 -0700 | [diff] [blame] | 429 | #endif |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 430 | config.Get<Beamforming>().array_geometry, |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 431 | config.Get<Beamforming>().target_direction), |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 432 | capture_nonlocked_(config.Get<Beamforming>().enabled, |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 433 | config.Get<Intelligibility>().enabled) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 434 | { |
| 435 | rtc::CritScope cs_render(&crit_render_); |
| 436 | rtc::CritScope cs_capture(&crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 437 | |
Gustaf Ullberg | ce045ac | 2017-10-16 13:49:04 +0200 | [diff] [blame] | 438 | // Mark Echo Controller enabled if a factory is injected. |
| 439 | capture_nonlocked_.echo_controller_enabled = |
| 440 | static_cast<bool>(echo_control_factory_); |
| 441 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 442 | public_submodules_->echo_cancellation.reset( |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 443 | new EchoCancellationImpl(&crit_render_, &crit_capture_)); |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 444 | public_submodules_->echo_control_mobile.reset( |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame] | 445 | new EchoControlMobileImpl(&crit_render_, &crit_capture_)); |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 446 | public_submodules_->gain_control.reset( |
peah | b8fbb54 | 2016-03-15 02:28:08 -0700 | [diff] [blame] | 447 | new GainControlImpl(&crit_capture_, &crit_capture_)); |
solenberg | 949028f | 2015-12-15 11:39:38 -0800 | [diff] [blame] | 448 | public_submodules_->level_estimator.reset( |
| 449 | new LevelEstimatorImpl(&crit_capture_)); |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 450 | public_submodules_->noise_suppression.reset( |
| 451 | new NoiseSuppressionImpl(&crit_capture_)); |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 452 | public_submodules_->voice_detection.reset( |
| 453 | new VoiceDetectionImpl(&crit_capture_)); |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 454 | public_submodules_->gain_control_for_experimental_agc.reset( |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 455 | new GainControlForExperimentalAgc( |
| 456 | public_submodules_->gain_control.get(), &crit_capture_)); |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 457 | private_submodules_->residual_echo_detector.reset( |
| 458 | new ResidualEchoDetector()); |
peah | ca4cac7 | 2016-06-29 15:26:12 -0700 | [diff] [blame] | 459 | |
peah | c19f312 | 2016-10-07 14:54:10 -0700 | [diff] [blame] | 460 | // TODO(peah): Move this creation to happen only when the level controller |
| 461 | // is enabled. |
peah | ca4cac7 | 2016-06-29 15:26:12 -0700 | [diff] [blame] | 462 | private_submodules_->level_controller.reset(new LevelController()); |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 463 | |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 464 | // TODO(alessiob): Move the injected gain controller once injection is |
| 465 | // implemented. |
| 466 | private_submodules_->gain_controller2.reset(new GainController2()); |
| 467 | |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 468 | RTC_LOG(LS_INFO) << "Capture post processor activated: " |
| 469 | << !!private_submodules_->capture_post_processor; |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 470 | |
| 471 | RTC_LOG(LS_INFO) << "Render pre processor activated: " |
| 472 | << !!private_submodules_->render_pre_processor; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 473 | } |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 474 | |
andrew@webrtc.org | e84978f | 2014-01-25 02:09:06 +0000 | [diff] [blame] | 475 | SetExtraOptions(config); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | AudioProcessingImpl::~AudioProcessingImpl() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 479 | // Depends on gain_control_ and |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 480 | // public_submodules_->gain_control_for_experimental_agc. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 481 | private_submodules_->agc_manager.reset(); |
| 482 | // Depends on gain_control_. |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 483 | public_submodules_->gain_control_for_experimental_agc.reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 484 | } |
| 485 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 486 | int AudioProcessingImpl::Initialize() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 487 | // Run in a single-threaded manner during initialization. |
| 488 | rtc::CritScope cs_render(&crit_render_); |
| 489 | rtc::CritScope cs_capture(&crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 490 | return InitializeLocked(); |
| 491 | } |
| 492 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 493 | int AudioProcessingImpl::Initialize(int capture_input_sample_rate_hz, |
| 494 | int capture_output_sample_rate_hz, |
| 495 | int render_input_sample_rate_hz, |
| 496 | ChannelLayout capture_input_layout, |
| 497 | ChannelLayout capture_output_layout, |
| 498 | ChannelLayout render_input_layout) { |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 499 | const ProcessingConfig processing_config = { |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 500 | {{capture_input_sample_rate_hz, ChannelsFromLayout(capture_input_layout), |
| 501 | LayoutHasKeyboard(capture_input_layout)}, |
| 502 | {capture_output_sample_rate_hz, |
| 503 | ChannelsFromLayout(capture_output_layout), |
| 504 | LayoutHasKeyboard(capture_output_layout)}, |
| 505 | {render_input_sample_rate_hz, ChannelsFromLayout(render_input_layout), |
| 506 | LayoutHasKeyboard(render_input_layout)}, |
| 507 | {render_input_sample_rate_hz, ChannelsFromLayout(render_input_layout), |
| 508 | LayoutHasKeyboard(render_input_layout)}}}; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 509 | |
| 510 | return Initialize(processing_config); |
| 511 | } |
| 512 | |
| 513 | int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 514 | // Run in a single-threaded manner during initialization. |
| 515 | rtc::CritScope cs_render(&crit_render_); |
| 516 | rtc::CritScope cs_capture(&crit_capture_); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 517 | return InitializeLocked(processing_config); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 518 | } |
| 519 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 520 | int AudioProcessingImpl::MaybeInitializeRender( |
peah | 81b9bfe | 2015-11-27 02:47:28 -0800 | [diff] [blame] | 521 | const ProcessingConfig& processing_config) { |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 522 | return MaybeInitialize(processing_config, false); |
peah | 81b9bfe | 2015-11-27 02:47:28 -0800 | [diff] [blame] | 523 | } |
| 524 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 525 | int AudioProcessingImpl::MaybeInitializeCapture( |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 526 | const ProcessingConfig& processing_config, |
| 527 | bool force_initialization) { |
| 528 | return MaybeInitialize(processing_config, force_initialization); |
peah | 81b9bfe | 2015-11-27 02:47:28 -0800 | [diff] [blame] | 529 | } |
| 530 | |
peah | 192164e | 2015-11-17 02:16:45 -0800 | [diff] [blame] | 531 | // Calls InitializeLocked() if any of the audio parameters have changed from |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 532 | // their current values (needs to be called while holding the crit_render_lock). |
| 533 | int AudioProcessingImpl::MaybeInitialize( |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 534 | const ProcessingConfig& processing_config, |
| 535 | bool force_initialization) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 536 | // Called from both threads. Thread check is therefore not possible. |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 537 | if (processing_config == formats_.api_format && !force_initialization) { |
peah | 192164e | 2015-11-17 02:16:45 -0800 | [diff] [blame] | 538 | return kNoError; |
| 539 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 540 | |
| 541 | rtc::CritScope cs_capture(&crit_capture_); |
peah | 192164e | 2015-11-17 02:16:45 -0800 | [diff] [blame] | 542 | return InitializeLocked(processing_config); |
| 543 | } |
| 544 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 545 | int AudioProcessingImpl::InitializeLocked() { |
Per Ã…hgren | 4bdced5 | 2017-06-27 16:00:38 +0200 | [diff] [blame] | 546 | UpdateActiveSubmoduleStates(); |
| 547 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 548 | const int capture_audiobuffer_num_channels = |
| 549 | capture_nonlocked_.beamformer_enabled |
| 550 | ? formats_.api_format.input_stream().num_channels() |
| 551 | : formats_.api_format.output_stream().num_channels(); |
| 552 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 553 | const int render_audiobuffer_num_output_frames = |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 554 | formats_.api_format.reverse_output_stream().num_frames() == 0 |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 555 | ? formats_.render_processing_format.num_frames() |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 556 | : formats_.api_format.reverse_output_stream().num_frames(); |
| 557 | if (formats_.api_format.reverse_input_stream().num_channels() > 0) { |
| 558 | render_.render_audio.reset(new AudioBuffer( |
| 559 | formats_.api_format.reverse_input_stream().num_frames(), |
| 560 | formats_.api_format.reverse_input_stream().num_channels(), |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 561 | formats_.render_processing_format.num_frames(), |
| 562 | formats_.render_processing_format.num_channels(), |
| 563 | render_audiobuffer_num_output_frames)); |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 564 | if (formats_.api_format.reverse_input_stream() != |
| 565 | formats_.api_format.reverse_output_stream()) { |
kwiberg | c2b785d | 2016-02-24 05:22:32 -0800 | [diff] [blame] | 566 | render_.render_converter = AudioConverter::Create( |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 567 | formats_.api_format.reverse_input_stream().num_channels(), |
| 568 | formats_.api_format.reverse_input_stream().num_frames(), |
| 569 | formats_.api_format.reverse_output_stream().num_channels(), |
kwiberg | c2b785d | 2016-02-24 05:22:32 -0800 | [diff] [blame] | 570 | formats_.api_format.reverse_output_stream().num_frames()); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 571 | } else { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 572 | render_.render_converter.reset(nullptr); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 573 | } |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 574 | } else { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 575 | render_.render_audio.reset(nullptr); |
| 576 | render_.render_converter.reset(nullptr); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 577 | } |
peah | ce4d915 | 2017-05-19 01:28:05 -0700 | [diff] [blame] | 578 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 579 | capture_.capture_audio.reset( |
| 580 | new AudioBuffer(formats_.api_format.input_stream().num_frames(), |
| 581 | formats_.api_format.input_stream().num_channels(), |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 582 | capture_nonlocked_.capture_processing_format.num_frames(), |
| 583 | capture_audiobuffer_num_channels, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 584 | formats_.api_format.output_stream().num_frames())); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 585 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 586 | public_submodules_->echo_cancellation->Initialize( |
| 587 | proc_sample_rate_hz(), num_reverse_channels(), num_output_channels(), |
| 588 | num_proc_channels()); |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 589 | AllocateRenderQueue(); |
| 590 | |
ivoc | 3e9a537 | 2016-10-28 07:55:33 -0700 | [diff] [blame] | 591 | int success = public_submodules_->echo_cancellation->enable_metrics(true); |
| 592 | RTC_DCHECK_EQ(0, success); |
| 593 | success = public_submodules_->echo_cancellation->enable_delay_logging(true); |
| 594 | RTC_DCHECK_EQ(0, success); |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 595 | public_submodules_->echo_control_mobile->Initialize( |
| 596 | proc_split_sample_rate_hz(), num_reverse_channels(), |
| 597 | num_output_channels()); |
peah | 135259a | 2016-10-28 03:12:11 -0700 | [diff] [blame] | 598 | |
| 599 | public_submodules_->gain_control->Initialize(num_proc_channels(), |
| 600 | proc_sample_rate_hz()); |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 601 | if (constants_.use_experimental_agc) { |
| 602 | if (!private_submodules_->agc_manager.get()) { |
| 603 | private_submodules_->agc_manager.reset(new AgcManagerDirect( |
| 604 | public_submodules_->gain_control.get(), |
| 605 | public_submodules_->gain_control_for_experimental_agc.get(), |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 606 | constants_.agc_startup_min_volume, constants_.agc_clipped_level_min)); |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 607 | } |
| 608 | private_submodules_->agc_manager->Initialize(); |
| 609 | private_submodules_->agc_manager->SetCaptureMuted( |
| 610 | capture_.output_will_be_muted); |
peah | 135259a | 2016-10-28 03:12:11 -0700 | [diff] [blame] | 611 | public_submodules_->gain_control_for_experimental_agc->Initialize(); |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 612 | } |
Bjorn Volcker | adc46c4 | 2015-04-15 11:42:40 +0200 | [diff] [blame] | 613 | InitializeTransient(); |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 614 | InitializeBeamformer(); |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 615 | #if WEBRTC_INTELLIGIBILITY_ENHANCER |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 616 | InitializeIntelligibility(); |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 617 | #endif |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 618 | InitializeLowCutFilter(); |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 619 | public_submodules_->noise_suppression->Initialize(num_proc_channels(), |
| 620 | proc_sample_rate_hz()); |
| 621 | public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz()); |
| 622 | public_submodules_->level_estimator->Initialize(); |
peah | ca4cac7 | 2016-06-29 15:26:12 -0700 | [diff] [blame] | 623 | InitializeLevelController(); |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 624 | InitializeResidualEchoDetector(); |
Gustaf Ullberg | 8eb9c7d | 2017-10-14 08:28:46 +0200 | [diff] [blame] | 625 | InitializeEchoController(); |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 626 | InitializeGainController2(); |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 627 | InitializePostProcessor(); |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 628 | InitializePreProcessor(); |
solenberg | 70f9903 | 2015-12-08 11:07:32 -0800 | [diff] [blame] | 629 | |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 630 | if (aec_dump_) { |
| 631 | aec_dump_->WriteInitMessage(ToStreamsConfig(formats_.api_format)); |
| 632 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 633 | return kNoError; |
| 634 | } |
| 635 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 636 | int AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) { |
Per Ã…hgren | 4bdced5 | 2017-06-27 16:00:38 +0200 | [diff] [blame] | 637 | UpdateActiveSubmoduleStates(); |
| 638 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 639 | for (const auto& stream : config.streams) { |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 640 | if (stream.num_channels() > 0 && stream.sample_rate_hz() <= 0) { |
| 641 | return kBadSampleRateError; |
| 642 | } |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 643 | } |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 644 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 645 | const size_t num_in_channels = config.input_stream().num_channels(); |
| 646 | const size_t num_out_channels = config.output_stream().num_channels(); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 647 | |
| 648 | // Need at least one input channel. |
| 649 | // Need either one output channel or as many outputs as there are inputs. |
| 650 | if (num_in_channels == 0 || |
| 651 | !(num_out_channels == 1 || num_out_channels == num_in_channels)) { |
Michael Graczyk | c204754 | 2015-07-22 21:06:11 -0700 | [diff] [blame] | 652 | return kBadNumberChannelsError; |
| 653 | } |
| 654 | |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 655 | if (capture_nonlocked_.beamformer_enabled && |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 656 | num_in_channels != capture_.array_geometry.size()) { |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 657 | return kBadNumberChannelsError; |
| 658 | } |
| 659 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 660 | formats_.api_format = config; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 661 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 662 | int capture_processing_rate = FindNativeProcessRateToUse( |
peah | 423d236 | 2016-04-09 16:06:52 -0700 | [diff] [blame] | 663 | std::min(formats_.api_format.input_stream().sample_rate_hz(), |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 664 | formats_.api_format.output_stream().sample_rate_hz()), |
| 665 | submodule_states_.CaptureMultiBandSubModulesActive() || |
| 666 | submodule_states_.RenderMultiBandSubModulesActive()); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 667 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 668 | capture_nonlocked_.capture_processing_format = |
| 669 | StreamConfig(capture_processing_rate); |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 670 | |
peah | 2ce640f | 2017-04-07 03:57:48 -0700 | [diff] [blame] | 671 | int render_processing_rate; |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 672 | if (!capture_nonlocked_.echo_controller_enabled) { |
peah | 2ce640f | 2017-04-07 03:57:48 -0700 | [diff] [blame] | 673 | render_processing_rate = FindNativeProcessRateToUse( |
| 674 | std::min(formats_.api_format.reverse_input_stream().sample_rate_hz(), |
| 675 | formats_.api_format.reverse_output_stream().sample_rate_hz()), |
| 676 | submodule_states_.CaptureMultiBandSubModulesActive() || |
| 677 | submodule_states_.RenderMultiBandSubModulesActive()); |
| 678 | } else { |
| 679 | render_processing_rate = capture_processing_rate; |
| 680 | } |
| 681 | |
aluebs | eb3603b | 2016-04-20 15:27:58 -0700 | [diff] [blame] | 682 | // TODO(aluebs): Remove this restriction once we figure out why the 3-band |
| 683 | // splitting filter degrades the AEC performance. |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 684 | if (render_processing_rate > kSampleRate32kHz && |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 685 | !capture_nonlocked_.echo_controller_enabled) { |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 686 | render_processing_rate = submodule_states_.RenderMultiBandProcessingActive() |
| 687 | ? kSampleRate32kHz |
| 688 | : kSampleRate16kHz; |
aluebs | eb3603b | 2016-04-20 15:27:58 -0700 | [diff] [blame] | 689 | } |
peah | 2ce640f | 2017-04-07 03:57:48 -0700 | [diff] [blame] | 690 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 691 | // If the forward sample rate is 8 kHz, the render stream is also processed |
aluebs | eb3603b | 2016-04-20 15:27:58 -0700 | [diff] [blame] | 692 | // at this rate. |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 693 | if (capture_nonlocked_.capture_processing_format.sample_rate_hz() == |
| 694 | kSampleRate8kHz) { |
| 695 | render_processing_rate = kSampleRate8kHz; |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 696 | } else { |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 697 | render_processing_rate = |
| 698 | std::max(render_processing_rate, static_cast<int>(kSampleRate16kHz)); |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 699 | } |
| 700 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 701 | // Always downmix the render stream to mono for analysis. This has been |
andrew@webrtc.org | 30be827 | 2014-09-24 20:06:23 +0000 | [diff] [blame] | 702 | // demonstrated to work well for AEC in most practical scenarios. |
peah | ce4d915 | 2017-05-19 01:28:05 -0700 | [diff] [blame] | 703 | if (submodule_states_.RenderMultiBandSubModulesActive()) { |
| 704 | formats_.render_processing_format = StreamConfig(render_processing_rate, 1); |
| 705 | } else { |
| 706 | formats_.render_processing_format = StreamConfig( |
| 707 | formats_.api_format.reverse_input_stream().sample_rate_hz(), |
| 708 | formats_.api_format.reverse_input_stream().num_channels()); |
| 709 | } |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 710 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 711 | if (capture_nonlocked_.capture_processing_format.sample_rate_hz() == |
| 712 | kSampleRate32kHz || |
| 713 | capture_nonlocked_.capture_processing_format.sample_rate_hz() == |
| 714 | kSampleRate48kHz) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 715 | capture_nonlocked_.split_rate = kSampleRate16kHz; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 716 | } else { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 717 | capture_nonlocked_.split_rate = |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 718 | capture_nonlocked_.capture_processing_format.sample_rate_hz(); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | return InitializeLocked(); |
| 722 | } |
| 723 | |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 724 | void AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) { |
peah | c19f312 | 2016-10-07 14:54:10 -0700 | [diff] [blame] | 725 | config_ = config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 726 | |
peah | c19f312 | 2016-10-07 14:54:10 -0700 | [diff] [blame] | 727 | bool config_ok = LevelController::Validate(config_.level_controller); |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 728 | if (!config_ok) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 729 | RTC_LOG(LS_ERROR) << "AudioProcessing module config error" << std::endl |
| 730 | << "level_controller: " |
| 731 | << LevelController::ToString(config_.level_controller) |
| 732 | << std::endl |
| 733 | << "Reverting to default parameter set"; |
peah | c19f312 | 2016-10-07 14:54:10 -0700 | [diff] [blame] | 734 | config_.level_controller = AudioProcessing::Config::LevelController(); |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | // Run in a single-threaded manner when applying the settings. |
| 738 | rtc::CritScope cs_render(&crit_render_); |
| 739 | rtc::CritScope cs_capture(&crit_capture_); |
| 740 | |
peah | c19f312 | 2016-10-07 14:54:10 -0700 | [diff] [blame] | 741 | // TODO(peah): Replace the use of capture_nonlocked_.level_controller_enabled |
| 742 | // with the value in config_ everywhere in the code. |
| 743 | if (capture_nonlocked_.level_controller_enabled != |
| 744 | config_.level_controller.enabled) { |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 745 | capture_nonlocked_.level_controller_enabled = |
peah | c19f312 | 2016-10-07 14:54:10 -0700 | [diff] [blame] | 746 | config_.level_controller.enabled; |
| 747 | // TODO(peah): Remove the conditional initialization to always initialize |
| 748 | // the level controller regardless of whether it is enabled or not. |
| 749 | InitializeLevelController(); |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 750 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 751 | RTC_LOG(LS_INFO) << "Level controller activated: " |
| 752 | << capture_nonlocked_.level_controller_enabled; |
peah | c19f312 | 2016-10-07 14:54:10 -0700 | [diff] [blame] | 753 | |
| 754 | private_submodules_->level_controller->ApplyConfig(config_.level_controller); |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 755 | |
| 756 | InitializeLowCutFilter(); |
| 757 | |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 758 | RTC_LOG(LS_INFO) << "Highpass filter activated: " |
| 759 | << config_.high_pass_filter.enabled; |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 760 | |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 761 | // Deprecated way of activating AEC3. |
| 762 | // TODO(gustaf): Remove when possible. |
Gustaf Ullberg | 8eb9c7d | 2017-10-14 08:28:46 +0200 | [diff] [blame] | 763 | if (config.echo_canceller3.enabled && !echo_control_factory_) { |
Gustaf Ullberg | ce045ac | 2017-10-16 13:49:04 +0200 | [diff] [blame] | 764 | capture_nonlocked_.echo_controller_enabled = |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 765 | config_.echo_canceller3.enabled; |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 766 | echo_control_factory_ = |
| 767 | std::unique_ptr<EchoControlFactory>(new EchoCanceller3Factory()); |
Gustaf Ullberg | 8eb9c7d | 2017-10-14 08:28:46 +0200 | [diff] [blame] | 768 | InitializeEchoController(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 769 | RTC_LOG(LS_INFO) << "Echo canceller 3 activated: " |
| 770 | << capture_nonlocked_.echo_controller_enabled; |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 771 | } |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 772 | |
| 773 | config_ok = GainController2::Validate(config_.gain_controller2); |
| 774 | if (!config_ok) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 775 | RTC_LOG(LS_ERROR) << "AudioProcessing module config error" << std::endl |
| 776 | << "Gain Controller 2: " |
| 777 | << GainController2::ToString(config_.gain_controller2) |
| 778 | << std::endl |
| 779 | << "Reverting to default parameter set"; |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 780 | config_.gain_controller2 = AudioProcessing::Config::GainController2(); |
| 781 | } |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 782 | InitializeGainController2(); |
| 783 | private_submodules_->gain_controller2->ApplyConfig(config_.gain_controller2); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 784 | RTC_LOG(LS_INFO) << "Gain Controller 2 activated: " |
| 785 | << config_.gain_controller2.enabled; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | void AudioProcessingImpl::SetExtraOptions(const webrtc::Config& config) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 789 | // Run in a single-threaded manner when setting the extra options. |
| 790 | rtc::CritScope cs_render(&crit_render_); |
| 791 | rtc::CritScope cs_capture(&crit_capture_); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 792 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 793 | public_submodules_->echo_cancellation->SetExtraOptions(config); |
| 794 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 795 | if (capture_.transient_suppressor_enabled != |
| 796 | config.Get<ExperimentalNs>().enabled) { |
| 797 | capture_.transient_suppressor_enabled = |
| 798 | config.Get<ExperimentalNs>().enabled; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 799 | InitializeTransient(); |
| 800 | } |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 801 | |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 802 | #if WEBRTC_INTELLIGIBILITY_ENHANCER |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 803 | if (capture_nonlocked_.intelligibility_enabled != |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 804 | config.Get<Intelligibility>().enabled) { |
| 805 | capture_nonlocked_.intelligibility_enabled = |
| 806 | config.Get<Intelligibility>().enabled; |
| 807 | InitializeIntelligibility(); |
| 808 | } |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 809 | #endif |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 810 | |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 811 | #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 812 | if (capture_nonlocked_.beamformer_enabled != |
| 813 | config.Get<Beamforming>().enabled) { |
| 814 | capture_nonlocked_.beamformer_enabled = config.Get<Beamforming>().enabled; |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 815 | if (config.Get<Beamforming>().array_geometry.size() > 1) { |
| 816 | capture_.array_geometry = config.Get<Beamforming>().array_geometry; |
| 817 | } |
| 818 | capture_.target_direction = config.Get<Beamforming>().target_direction; |
| 819 | InitializeBeamformer(); |
| 820 | } |
| 821 | #endif // WEBRTC_ANDROID_PLATFORM_BUILD |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 822 | } |
| 823 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 824 | int AudioProcessingImpl::proc_sample_rate_hz() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 825 | // Used as callback from submodules, hence locking is not allowed. |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 826 | return capture_nonlocked_.capture_processing_format.sample_rate_hz(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 827 | } |
| 828 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 829 | int AudioProcessingImpl::proc_split_sample_rate_hz() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 830 | // Used as callback from submodules, hence locking is not allowed. |
| 831 | return capture_nonlocked_.split_rate; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 834 | size_t AudioProcessingImpl::num_reverse_channels() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 835 | // Used as callback from submodules, hence locking is not allowed. |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 836 | return formats_.render_processing_format.num_channels(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 837 | } |
| 838 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 839 | size_t AudioProcessingImpl::num_input_channels() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 840 | // Used as callback from submodules, hence locking is not allowed. |
| 841 | return formats_.api_format.input_stream().num_channels(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 842 | } |
| 843 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 844 | size_t AudioProcessingImpl::num_proc_channels() const { |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 845 | // Used as callback from submodules, hence locking is not allowed. |
peah | edddac5 | 2017-05-16 01:08:58 -0700 | [diff] [blame] | 846 | return (capture_nonlocked_.beamformer_enabled || |
Gustaf Ullberg | ce045ac | 2017-10-16 13:49:04 +0200 | [diff] [blame] | 847 | capture_nonlocked_.echo_controller_enabled) |
peah | edddac5 | 2017-05-16 01:08:58 -0700 | [diff] [blame] | 848 | ? 1 |
| 849 | : num_output_channels(); |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 850 | } |
| 851 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 852 | size_t AudioProcessingImpl::num_output_channels() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 853 | // Used as callback from submodules, hence locking is not allowed. |
| 854 | return formats_.api_format.output_stream().num_channels(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 855 | } |
| 856 | |
andrew@webrtc.org | 17342e5 | 2014-02-12 22:28:31 +0000 | [diff] [blame] | 857 | void AudioProcessingImpl::set_output_will_be_muted(bool muted) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 858 | rtc::CritScope cs(&crit_capture_); |
| 859 | capture_.output_will_be_muted = muted; |
| 860 | if (private_submodules_->agc_manager.get()) { |
| 861 | private_submodules_->agc_manager->SetCaptureMuted( |
| 862 | capture_.output_will_be_muted); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 863 | } |
andrew@webrtc.org | 17342e5 | 2014-02-12 22:28:31 +0000 | [diff] [blame] | 864 | } |
| 865 | |
andrew@webrtc.org | 17342e5 | 2014-02-12 22:28:31 +0000 | [diff] [blame] | 866 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 867 | int AudioProcessingImpl::ProcessStream(const float* const* src, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 868 | size_t samples_per_channel, |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 869 | int input_sample_rate_hz, |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 870 | ChannelLayout input_layout, |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 871 | int output_sample_rate_hz, |
| 872 | ChannelLayout output_layout, |
| 873 | float* const* dest) { |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 874 | TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_ChannelLayout"); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 875 | StreamConfig input_stream; |
| 876 | StreamConfig output_stream; |
| 877 | { |
| 878 | // Access the formats_.api_format.input_stream beneath the capture lock. |
| 879 | // The lock must be released as it is later required in the call |
| 880 | // to ProcessStream(,,,); |
| 881 | rtc::CritScope cs(&crit_capture_); |
| 882 | input_stream = formats_.api_format.input_stream(); |
| 883 | output_stream = formats_.api_format.output_stream(); |
| 884 | } |
| 885 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 886 | input_stream.set_sample_rate_hz(input_sample_rate_hz); |
| 887 | input_stream.set_num_channels(ChannelsFromLayout(input_layout)); |
| 888 | input_stream.set_has_keyboard(LayoutHasKeyboard(input_layout)); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 889 | output_stream.set_sample_rate_hz(output_sample_rate_hz); |
| 890 | output_stream.set_num_channels(ChannelsFromLayout(output_layout)); |
| 891 | output_stream.set_has_keyboard(LayoutHasKeyboard(output_layout)); |
| 892 | |
| 893 | if (samples_per_channel != input_stream.num_frames()) { |
| 894 | return kBadDataLengthError; |
| 895 | } |
| 896 | return ProcessStream(src, input_stream, output_stream, dest); |
| 897 | } |
| 898 | |
| 899 | int AudioProcessingImpl::ProcessStream(const float* const* src, |
| 900 | const StreamConfig& input_config, |
| 901 | const StreamConfig& output_config, |
| 902 | float* const* dest) { |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 903 | TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_StreamConfig"); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 904 | ProcessingConfig processing_config; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 905 | bool reinitialization_required = false; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 906 | { |
| 907 | // Acquire the capture lock in order to safely call the function |
| 908 | // that retrieves the render side data. This function accesses apm |
| 909 | // getters that need the capture lock held when being called. |
| 910 | rtc::CritScope cs_capture(&crit_capture_); |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 911 | EmptyQueuedRenderAudio(); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 912 | |
| 913 | if (!src || !dest) { |
| 914 | return kNullPointerError; |
| 915 | } |
| 916 | |
| 917 | processing_config = formats_.api_format; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 918 | reinitialization_required = UpdateActiveSubmoduleStates(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 919 | } |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 920 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 921 | processing_config.input_stream() = input_config; |
| 922 | processing_config.output_stream() = output_config; |
| 923 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 924 | { |
| 925 | // Do conditional reinitialization. |
| 926 | rtc::CritScope cs_render(&crit_render_); |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 927 | RETURN_ON_ERR( |
| 928 | MaybeInitializeCapture(processing_config, reinitialization_required)); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 929 | } |
| 930 | rtc::CritScope cs_capture(&crit_capture_); |
kwiberg | 9e2be5f | 2016-09-14 05:23:22 -0700 | [diff] [blame] | 931 | RTC_DCHECK_EQ(processing_config.input_stream().num_frames(), |
| 932 | formats_.api_format.input_stream().num_frames()); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 933 | |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 934 | if (aec_dump_) { |
| 935 | RecordUnprocessedCaptureStream(src); |
| 936 | } |
| 937 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 938 | capture_.capture_audio->CopyFrom(src, formats_.api_format.input_stream()); |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 939 | RETURN_ON_ERR(ProcessCaptureStreamLocked()); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 940 | capture_.capture_audio->CopyTo(formats_.api_format.output_stream(), dest); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 941 | |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 942 | if (aec_dump_) { |
| 943 | RecordProcessedCaptureStream(dest); |
| 944 | } |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 945 | return kNoError; |
| 946 | } |
| 947 | |
peah | 9e6a290 | 2017-05-15 07:19:21 -0700 | [diff] [blame] | 948 | void AudioProcessingImpl::QueueBandedRenderAudio(AudioBuffer* audio) { |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 949 | EchoCancellationImpl::PackRenderAudioBuffer(audio, num_output_channels(), |
| 950 | num_reverse_channels(), |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 951 | &aec_render_queue_buffer_); |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 952 | |
kwiberg | af476c7 | 2016-11-28 15:21:39 -0800 | [diff] [blame] | 953 | RTC_DCHECK_GE(160, audio->num_frames_per_band()); |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 954 | |
| 955 | // Insert the samples into the queue. |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 956 | if (!aec_render_signal_queue_->Insert(&aec_render_queue_buffer_)) { |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 957 | // The data queue is full and needs to be emptied. |
| 958 | EmptyQueuedRenderAudio(); |
| 959 | |
| 960 | // Retry the insert (should always work). |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 961 | bool result = aec_render_signal_queue_->Insert(&aec_render_queue_buffer_); |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 962 | RTC_DCHECK(result); |
| 963 | } |
| 964 | |
| 965 | EchoControlMobileImpl::PackRenderAudioBuffer(audio, num_output_channels(), |
| 966 | num_reverse_channels(), |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 967 | &aecm_render_queue_buffer_); |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 968 | |
| 969 | // Insert the samples into the queue. |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 970 | if (!aecm_render_signal_queue_->Insert(&aecm_render_queue_buffer_)) { |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 971 | // The data queue is full and needs to be emptied. |
| 972 | EmptyQueuedRenderAudio(); |
| 973 | |
| 974 | // Retry the insert (should always work). |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 975 | bool result = aecm_render_signal_queue_->Insert(&aecm_render_queue_buffer_); |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 976 | RTC_DCHECK(result); |
| 977 | } |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 978 | |
| 979 | if (!constants_.use_experimental_agc) { |
| 980 | GainControlImpl::PackRenderAudioBuffer(audio, &agc_render_queue_buffer_); |
| 981 | // Insert the samples into the queue. |
| 982 | if (!agc_render_signal_queue_->Insert(&agc_render_queue_buffer_)) { |
| 983 | // The data queue is full and needs to be emptied. |
| 984 | EmptyQueuedRenderAudio(); |
| 985 | |
| 986 | // Retry the insert (should always work). |
| 987 | bool result = agc_render_signal_queue_->Insert(&agc_render_queue_buffer_); |
| 988 | RTC_DCHECK(result); |
| 989 | } |
| 990 | } |
peah | 9e6a290 | 2017-05-15 07:19:21 -0700 | [diff] [blame] | 991 | } |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 992 | |
peah | 9e6a290 | 2017-05-15 07:19:21 -0700 | [diff] [blame] | 993 | void AudioProcessingImpl::QueueNonbandedRenderAudio(AudioBuffer* audio) { |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 994 | ResidualEchoDetector::PackRenderAudioBuffer(audio, &red_render_queue_buffer_); |
| 995 | |
| 996 | // Insert the samples into the queue. |
| 997 | if (!red_render_signal_queue_->Insert(&red_render_queue_buffer_)) { |
| 998 | // The data queue is full and needs to be emptied. |
| 999 | EmptyQueuedRenderAudio(); |
| 1000 | |
| 1001 | // Retry the insert (should always work). |
| 1002 | bool result = red_render_signal_queue_->Insert(&red_render_queue_buffer_); |
| 1003 | RTC_DCHECK(result); |
| 1004 | } |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | void AudioProcessingImpl::AllocateRenderQueue() { |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1008 | const size_t new_aec_render_queue_element_max_size = |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1009 | std::max(static_cast<size_t>(1), |
peah | 9e6a290 | 2017-05-15 07:19:21 -0700 | [diff] [blame] | 1010 | kMaxAllowedValuesOfSamplesPerBand * |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1011 | EchoCancellationImpl::NumCancellersRequired( |
| 1012 | num_output_channels(), num_reverse_channels())); |
| 1013 | |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1014 | const size_t new_aecm_render_queue_element_max_size = |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1015 | std::max(static_cast<size_t>(1), |
peah | 9e6a290 | 2017-05-15 07:19:21 -0700 | [diff] [blame] | 1016 | kMaxAllowedValuesOfSamplesPerBand * |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1017 | EchoControlMobileImpl::NumCancellersRequired( |
| 1018 | num_output_channels(), num_reverse_channels())); |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1019 | |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1020 | const size_t new_agc_render_queue_element_max_size = |
peah | 9e6a290 | 2017-05-15 07:19:21 -0700 | [diff] [blame] | 1021 | std::max(static_cast<size_t>(1), kMaxAllowedValuesOfSamplesPerBand); |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1022 | |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 1023 | const size_t new_red_render_queue_element_max_size = |
| 1024 | std::max(static_cast<size_t>(1), kMaxAllowedValuesOfSamplesPerFrame); |
| 1025 | |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1026 | // Reallocate the queues if the queue item sizes are too small to fit the |
| 1027 | // data to put in the queues. |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1028 | if (aec_render_queue_element_max_size_ < |
| 1029 | new_aec_render_queue_element_max_size) { |
| 1030 | aec_render_queue_element_max_size_ = new_aec_render_queue_element_max_size; |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1031 | |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1032 | std::vector<float> template_queue_element( |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1033 | aec_render_queue_element_max_size_); |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1034 | |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1035 | aec_render_signal_queue_.reset( |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1036 | new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>( |
| 1037 | kMaxNumFramesToBuffer, template_queue_element, |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1038 | RenderQueueItemVerifier<float>( |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1039 | aec_render_queue_element_max_size_))); |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1040 | |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1041 | aec_render_queue_buffer_.resize(aec_render_queue_element_max_size_); |
| 1042 | aec_capture_queue_buffer_.resize(aec_render_queue_element_max_size_); |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1043 | } else { |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1044 | aec_render_signal_queue_->Clear(); |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1047 | if (aecm_render_queue_element_max_size_ < |
| 1048 | new_aecm_render_queue_element_max_size) { |
| 1049 | aecm_render_queue_element_max_size_ = |
| 1050 | new_aecm_render_queue_element_max_size; |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1051 | |
| 1052 | std::vector<int16_t> template_queue_element( |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1053 | aecm_render_queue_element_max_size_); |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1054 | |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1055 | aecm_render_signal_queue_.reset( |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1056 | new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>( |
| 1057 | kMaxNumFramesToBuffer, template_queue_element, |
| 1058 | RenderQueueItemVerifier<int16_t>( |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1059 | aecm_render_queue_element_max_size_))); |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1060 | |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1061 | aecm_render_queue_buffer_.resize(aecm_render_queue_element_max_size_); |
| 1062 | aecm_capture_queue_buffer_.resize(aecm_render_queue_element_max_size_); |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1063 | } else { |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1064 | aecm_render_signal_queue_->Clear(); |
| 1065 | } |
| 1066 | |
| 1067 | if (agc_render_queue_element_max_size_ < |
| 1068 | new_agc_render_queue_element_max_size) { |
| 1069 | agc_render_queue_element_max_size_ = new_agc_render_queue_element_max_size; |
| 1070 | |
| 1071 | std::vector<int16_t> template_queue_element( |
| 1072 | agc_render_queue_element_max_size_); |
| 1073 | |
| 1074 | agc_render_signal_queue_.reset( |
| 1075 | new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>( |
| 1076 | kMaxNumFramesToBuffer, template_queue_element, |
| 1077 | RenderQueueItemVerifier<int16_t>( |
| 1078 | agc_render_queue_element_max_size_))); |
| 1079 | |
| 1080 | agc_render_queue_buffer_.resize(agc_render_queue_element_max_size_); |
| 1081 | agc_capture_queue_buffer_.resize(agc_render_queue_element_max_size_); |
| 1082 | } else { |
| 1083 | agc_render_signal_queue_->Clear(); |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1084 | } |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 1085 | |
| 1086 | if (red_render_queue_element_max_size_ < |
| 1087 | new_red_render_queue_element_max_size) { |
| 1088 | red_render_queue_element_max_size_ = new_red_render_queue_element_max_size; |
| 1089 | |
| 1090 | std::vector<float> template_queue_element( |
| 1091 | red_render_queue_element_max_size_); |
| 1092 | |
| 1093 | red_render_signal_queue_.reset( |
| 1094 | new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>( |
| 1095 | kMaxNumFramesToBuffer, template_queue_element, |
| 1096 | RenderQueueItemVerifier<float>( |
| 1097 | red_render_queue_element_max_size_))); |
| 1098 | |
| 1099 | red_render_queue_buffer_.resize(red_render_queue_element_max_size_); |
| 1100 | red_capture_queue_buffer_.resize(red_render_queue_element_max_size_); |
| 1101 | } else { |
| 1102 | red_render_signal_queue_->Clear(); |
| 1103 | } |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | void AudioProcessingImpl::EmptyQueuedRenderAudio() { |
| 1107 | rtc::CritScope cs_capture(&crit_capture_); |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1108 | while (aec_render_signal_queue_->Remove(&aec_capture_queue_buffer_)) { |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1109 | public_submodules_->echo_cancellation->ProcessRenderAudio( |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1110 | aec_capture_queue_buffer_); |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1113 | while (aecm_render_signal_queue_->Remove(&aecm_capture_queue_buffer_)) { |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 1114 | public_submodules_->echo_control_mobile->ProcessRenderAudio( |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 1115 | aecm_capture_queue_buffer_); |
| 1116 | } |
| 1117 | |
| 1118 | while (agc_render_signal_queue_->Remove(&agc_capture_queue_buffer_)) { |
| 1119 | public_submodules_->gain_control->ProcessRenderAudio( |
| 1120 | agc_capture_queue_buffer_); |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1121 | } |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 1122 | |
| 1123 | while (red_render_signal_queue_->Remove(&red_capture_queue_buffer_)) { |
| 1124 | private_submodules_->residual_echo_detector->AnalyzeRenderAudio( |
| 1125 | red_capture_queue_buffer_); |
| 1126 | } |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1129 | int AudioProcessingImpl::ProcessStream(AudioFrame* frame) { |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 1130 | TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_AudioFrame"); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1131 | { |
| 1132 | // Acquire the capture lock in order to safely call the function |
| 1133 | // that retrieves the render side data. This function accesses apm |
| 1134 | // getters that need the capture lock held when being called. |
| 1135 | // The lock needs to be released as |
| 1136 | // public_submodules_->echo_control_mobile->is_enabled() aquires this lock |
| 1137 | // as well. |
| 1138 | rtc::CritScope cs_capture(&crit_capture_); |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 1139 | EmptyQueuedRenderAudio(); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1140 | } |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 1141 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1142 | if (!frame) { |
| 1143 | return kNullPointerError; |
| 1144 | } |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 1145 | // Must be a native rate. |
| 1146 | if (frame->sample_rate_hz_ != kSampleRate8kHz && |
| 1147 | frame->sample_rate_hz_ != kSampleRate16kHz && |
aluebs@webrtc.org | 087da13 | 2014-11-17 23:01:23 +0000 | [diff] [blame] | 1148 | frame->sample_rate_hz_ != kSampleRate32kHz && |
| 1149 | frame->sample_rate_hz_ != kSampleRate48kHz) { |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 1150 | return kBadSampleRateError; |
| 1151 | } |
peah | 192164e | 2015-11-17 02:16:45 -0800 | [diff] [blame] | 1152 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1153 | ProcessingConfig processing_config; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1154 | bool reinitialization_required = false; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1155 | { |
| 1156 | // Aquire lock for the access of api_format. |
| 1157 | // The lock is released immediately due to the conditional |
| 1158 | // reinitialization. |
| 1159 | rtc::CritScope cs_capture(&crit_capture_); |
| 1160 | // TODO(ajm): The input and output rates and channels are currently |
| 1161 | // constrained to be identical in the int16 interface. |
| 1162 | processing_config = formats_.api_format; |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1163 | |
| 1164 | reinitialization_required = UpdateActiveSubmoduleStates(); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1165 | } |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1166 | processing_config.input_stream().set_sample_rate_hz(frame->sample_rate_hz_); |
| 1167 | processing_config.input_stream().set_num_channels(frame->num_channels_); |
| 1168 | processing_config.output_stream().set_sample_rate_hz(frame->sample_rate_hz_); |
| 1169 | processing_config.output_stream().set_num_channels(frame->num_channels_); |
| 1170 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1171 | { |
| 1172 | // Do conditional reinitialization. |
| 1173 | rtc::CritScope cs_render(&crit_render_); |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1174 | RETURN_ON_ERR( |
| 1175 | MaybeInitializeCapture(processing_config, reinitialization_required)); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1176 | } |
| 1177 | rtc::CritScope cs_capture(&crit_capture_); |
peah | 192164e | 2015-11-17 02:16:45 -0800 | [diff] [blame] | 1178 | if (frame->samples_per_channel_ != |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1179 | formats_.api_format.input_stream().num_frames()) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1180 | return kBadDataLengthError; |
| 1181 | } |
| 1182 | |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 1183 | if (aec_dump_) { |
| 1184 | RecordUnprocessedCaptureStream(*frame); |
| 1185 | } |
| 1186 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1187 | capture_.capture_audio->DeinterleaveFrom(frame); |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1188 | RETURN_ON_ERR(ProcessCaptureStreamLocked()); |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1189 | capture_.capture_audio->InterleaveTo( |
peah | 23ac8b4 | 2017-05-23 05:33:56 -0700 | [diff] [blame] | 1190 | frame, submodule_states_.CaptureMultiBandProcessingActive() || |
| 1191 | submodule_states_.CaptureFullBandProcessingActive()); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1192 | |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 1193 | if (aec_dump_) { |
| 1194 | RecordProcessedCaptureStream(*frame); |
| 1195 | } |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1196 | |
| 1197 | return kNoError; |
| 1198 | } |
| 1199 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1200 | int AudioProcessingImpl::ProcessCaptureStreamLocked() { |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 1201 | // Ensure that not both the AEC and AECM are active at the same time. |
| 1202 | // TODO(peah): Simplify once the public API Enable functions for these |
| 1203 | // are moved to APM. |
| 1204 | RTC_DCHECK(!(public_submodules_->echo_cancellation->is_enabled() && |
| 1205 | public_submodules_->echo_control_mobile->is_enabled())); |
| 1206 | |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1207 | MaybeUpdateHistograms(); |
| 1208 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1209 | AudioBuffer* capture_buffer = capture_.capture_audio.get(); // For brevity. |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1210 | |
peah | 1b08dc3 | 2016-12-20 13:45:58 -0800 | [diff] [blame] | 1211 | capture_input_rms_.Analyze(rtc::ArrayView<const int16_t>( |
henrik.lundin | 290d43a | 2016-11-29 08:09:09 -0800 | [diff] [blame] | 1212 | capture_buffer->channels_const()[0], |
| 1213 | capture_nonlocked_.capture_processing_format.num_frames())); |
peah | 1b08dc3 | 2016-12-20 13:45:58 -0800 | [diff] [blame] | 1214 | const bool log_rms = ++capture_rms_interval_counter_ >= 1000; |
| 1215 | if (log_rms) { |
| 1216 | capture_rms_interval_counter_ = 0; |
| 1217 | RmsLevel::Levels levels = capture_input_rms_.AverageAndPeak(); |
henrik.lundin | 45bb513 | 2016-12-06 04:28:04 -0800 | [diff] [blame] | 1218 | RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureInputLevelAverageRms", |
| 1219 | levels.average, 1, RmsLevel::kMinLevelDb, 64); |
| 1220 | RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureInputLevelPeakRms", |
| 1221 | levels.peak, 1, RmsLevel::kMinLevelDb, 64); |
henrik.lundin | 290d43a | 2016-11-29 08:09:09 -0800 | [diff] [blame] | 1222 | } |
| 1223 | |
Gustaf Ullberg | 59ff0e2 | 2017-10-09 10:20:34 +0200 | [diff] [blame] | 1224 | if (private_submodules_->echo_controller) { |
Per Ã…hgren | 9aed31c | 2017-06-29 20:23:27 +0200 | [diff] [blame] | 1225 | // TODO(peah): Reactivate analogue AGC gain detection once the analogue AGC |
| 1226 | // issues have been addressed. |
| 1227 | capture_.echo_path_gain_change = false; |
Gustaf Ullberg | 59ff0e2 | 2017-10-09 10:20:34 +0200 | [diff] [blame] | 1228 | private_submodules_->echo_controller->AnalyzeCapture(capture_buffer); |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 1229 | } |
| 1230 | |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 1231 | if (constants_.use_experimental_agc && |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1232 | public_submodules_->gain_control->is_enabled()) { |
| 1233 | private_submodules_->agc_manager->AnalyzePreProcess( |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1234 | capture_buffer->channels()[0], capture_buffer->num_channels(), |
| 1235 | capture_nonlocked_.capture_processing_format.num_frames()); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1238 | if (submodule_states_.CaptureMultiBandSubModulesActive() && |
| 1239 | SampleRateSupportsMultiBand( |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1240 | capture_nonlocked_.capture_processing_format.sample_rate_hz())) { |
| 1241 | capture_buffer->SplitIntoFrequencyBands(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
Gustaf Ullberg | 59ff0e2 | 2017-10-09 10:20:34 +0200 | [diff] [blame] | 1244 | if (private_submodules_->echo_controller) { |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 1245 | // Force down-mixing of the number of channels after the detection of |
| 1246 | // capture signal saturation. |
| 1247 | // TODO(peah): Look into ensuring that this kind of tampering with the |
| 1248 | // AudioBuffer functionality should not be needed. |
| 1249 | capture_buffer->set_num_channels(1); |
| 1250 | } |
| 1251 | |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 1252 | if (capture_nonlocked_.beamformer_enabled) { |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1253 | private_submodules_->beamformer->AnalyzeChunk( |
| 1254 | *capture_buffer->split_data_f()); |
Alejandro Luebs | f4022ff | 2016-07-01 17:19:09 -0700 | [diff] [blame] | 1255 | // Discards all channels by the leftmost one. |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1256 | capture_buffer->set_num_channels(1); |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 1257 | } |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 1258 | |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 1259 | // TODO(peah): Move the AEC3 low-cut filter to this place. |
| 1260 | if (private_submodules_->low_cut_filter && |
Gustaf Ullberg | 59ff0e2 | 2017-10-09 10:20:34 +0200 | [diff] [blame] | 1261 | !private_submodules_->echo_controller) { |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 1262 | private_submodules_->low_cut_filter->Process(capture_buffer); |
| 1263 | } |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1264 | RETURN_ON_ERR( |
| 1265 | public_submodules_->gain_control->AnalyzeCaptureAudio(capture_buffer)); |
| 1266 | public_submodules_->noise_suppression->AnalyzeCaptureAudio(capture_buffer); |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 1267 | |
| 1268 | // Ensure that the stream delay was set before the call to the |
| 1269 | // AEC ProcessCaptureAudio function. |
| 1270 | if (public_submodules_->echo_cancellation->is_enabled() && |
| 1271 | !was_stream_delay_set()) { |
| 1272 | return AudioProcessing::kStreamParameterNotSetError; |
| 1273 | } |
| 1274 | |
Gustaf Ullberg | 59ff0e2 | 2017-10-09 10:20:34 +0200 | [diff] [blame] | 1275 | if (private_submodules_->echo_controller) { |
| 1276 | private_submodules_->echo_controller->ProcessCapture( |
peah | 6799553 | 2017-04-10 14:12:41 -0700 | [diff] [blame] | 1277 | capture_buffer, capture_.echo_path_gain_change); |
peah | 61202ac | 2017-02-06 03:39:42 -0800 | [diff] [blame] | 1278 | } else { |
| 1279 | RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessCaptureAudio( |
| 1280 | capture_buffer, stream_delay_ms())); |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 1281 | } |
| 1282 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1283 | if (public_submodules_->echo_control_mobile->is_enabled() && |
| 1284 | public_submodules_->noise_suppression->is_enabled()) { |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1285 | capture_buffer->CopyLowPassToReference(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1286 | } |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1287 | public_submodules_->noise_suppression->ProcessCaptureAudio(capture_buffer); |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 1288 | #if WEBRTC_INTELLIGIBILITY_ENHANCER |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 1289 | if (capture_nonlocked_.intelligibility_enabled) { |
aluebs | c466bad | 2016-02-10 12:03:00 -0800 | [diff] [blame] | 1290 | RTC_DCHECK(public_submodules_->noise_suppression->is_enabled()); |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 1291 | int gain_db = public_submodules_->gain_control->is_enabled() ? |
| 1292 | public_submodules_->gain_control->compression_gain_db() : |
| 1293 | 0; |
Alejandro Luebs | 5041110 | 2016-06-30 15:35:41 -0700 | [diff] [blame] | 1294 | float gain = std::pow(10.f, gain_db / 20.f); |
| 1295 | gain *= capture_nonlocked_.level_controller_enabled ? |
| 1296 | private_submodules_->level_controller->GetLastGain() : |
| 1297 | 1.f; |
aluebs | c466bad | 2016-02-10 12:03:00 -0800 | [diff] [blame] | 1298 | public_submodules_->intelligibility_enhancer->SetCaptureNoiseEstimate( |
Alejandro Luebs | 5041110 | 2016-06-30 15:35:41 -0700 | [diff] [blame] | 1299 | public_submodules_->noise_suppression->NoiseEstimate(), gain); |
aluebs | c466bad | 2016-02-10 12:03:00 -0800 | [diff] [blame] | 1300 | } |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 1301 | #endif |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame] | 1302 | |
| 1303 | // Ensure that the stream delay was set before the call to the |
| 1304 | // AECM ProcessCaptureAudio function. |
| 1305 | if (public_submodules_->echo_control_mobile->is_enabled() && |
| 1306 | !was_stream_delay_set()) { |
| 1307 | return AudioProcessing::kStreamParameterNotSetError; |
| 1308 | } |
| 1309 | |
Gustaf Ullberg | 59ff0e2 | 2017-10-09 10:20:34 +0200 | [diff] [blame] | 1310 | if (!(private_submodules_->echo_controller || |
Per Ã…hgren | 46537a3 | 2017-06-07 10:08:10 +0200 | [diff] [blame] | 1311 | public_submodules_->echo_cancellation->is_enabled())) { |
| 1312 | RETURN_ON_ERR(public_submodules_->echo_control_mobile->ProcessCaptureAudio( |
| 1313 | capture_buffer, stream_delay_ms())); |
| 1314 | } |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 1315 | |
Alejandro Luebs | f4022ff | 2016-07-01 17:19:09 -0700 | [diff] [blame] | 1316 | if (capture_nonlocked_.beamformer_enabled) { |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1317 | private_submodules_->beamformer->PostFilter(capture_buffer->split_data_f()); |
Alejandro Luebs | f4022ff | 2016-07-01 17:19:09 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1320 | public_submodules_->voice_detection->ProcessCaptureAudio(capture_buffer); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1321 | |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 1322 | if (constants_.use_experimental_agc && |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1323 | public_submodules_->gain_control->is_enabled() && |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 1324 | (!capture_nonlocked_.beamformer_enabled || |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1325 | private_submodules_->beamformer->is_target_present())) { |
| 1326 | private_submodules_->agc_manager->Process( |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1327 | capture_buffer->split_bands_const(0)[kBand0To8kHz], |
| 1328 | capture_buffer->num_frames_per_band(), capture_nonlocked_.split_rate); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1329 | } |
peah | b8fbb54 | 2016-03-15 02:28:08 -0700 | [diff] [blame] | 1330 | RETURN_ON_ERR(public_submodules_->gain_control->ProcessCaptureAudio( |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1331 | capture_buffer, echo_cancellation()->stream_has_echo())); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1332 | |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1333 | if (submodule_states_.CaptureMultiBandProcessingActive() && |
| 1334 | SampleRateSupportsMultiBand( |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1335 | capture_nonlocked_.capture_processing_format.sample_rate_hz())) { |
| 1336 | capture_buffer->MergeFrequencyBands(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
peah | 9e6a290 | 2017-05-15 07:19:21 -0700 | [diff] [blame] | 1339 | if (config_.residual_echo_detector.enabled) { |
| 1340 | private_submodules_->residual_echo_detector->AnalyzeCaptureAudio( |
| 1341 | rtc::ArrayView<const float>(capture_buffer->channels_f()[0], |
| 1342 | capture_buffer->num_frames())); |
| 1343 | } |
| 1344 | |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1345 | // TODO(aluebs): Investigate if the transient suppression placement should be |
| 1346 | // before or after the AGC. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1347 | if (capture_.transient_suppressor_enabled) { |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1348 | float voice_probability = |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1349 | private_submodules_->agc_manager.get() |
| 1350 | ? private_submodules_->agc_manager->voice_probability() |
| 1351 | : 1.f; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1352 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1353 | public_submodules_->transient_suppressor->Suppress( |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1354 | capture_buffer->channels_f()[0], capture_buffer->num_frames(), |
| 1355 | capture_buffer->num_channels(), |
| 1356 | capture_buffer->split_bands_const_f(0)[kBand0To8kHz], |
| 1357 | capture_buffer->num_frames_per_band(), capture_buffer->keyboard_data(), |
| 1358 | capture_buffer->num_keyboard_frames(), voice_probability, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1359 | capture_.key_pressed); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 1362 | if (config_.gain_controller2.enabled) { |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 1363 | private_submodules_->gain_controller2->Process(capture_buffer); |
| 1364 | } |
| 1365 | |
peah | ca4cac7 | 2016-06-29 15:26:12 -0700 | [diff] [blame] | 1366 | if (capture_nonlocked_.level_controller_enabled) { |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1367 | private_submodules_->level_controller->Process(capture_buffer); |
peah | ca4cac7 | 2016-06-29 15:26:12 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 1370 | if (private_submodules_->capture_post_processor) { |
| 1371 | private_submodules_->capture_post_processor->Process(capture_buffer); |
| 1372 | } |
| 1373 | |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 1374 | // The level estimator operates on the recombined data. |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1375 | public_submodules_->level_estimator->ProcessStream(capture_buffer); |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 1376 | |
peah | 1b08dc3 | 2016-12-20 13:45:58 -0800 | [diff] [blame] | 1377 | capture_output_rms_.Analyze(rtc::ArrayView<const int16_t>( |
| 1378 | capture_buffer->channels_const()[0], |
| 1379 | capture_nonlocked_.capture_processing_format.num_frames())); |
| 1380 | if (log_rms) { |
| 1381 | RmsLevel::Levels levels = capture_output_rms_.AverageAndPeak(); |
| 1382 | RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureOutputLevelAverageRms", |
| 1383 | levels.average, 1, RmsLevel::kMinLevelDb, 64); |
| 1384 | RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureOutputLevelPeakRms", |
| 1385 | levels.peak, 1, RmsLevel::kMinLevelDb, 64); |
| 1386 | } |
| 1387 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1388 | capture_.was_stream_delay_set = false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1389 | return kNoError; |
| 1390 | } |
| 1391 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1392 | int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 1393 | size_t samples_per_channel, |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1394 | int sample_rate_hz, |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1395 | ChannelLayout layout) { |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 1396 | TRACE_EVENT0("webrtc", "AudioProcessing::AnalyzeReverseStream_ChannelLayout"); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1397 | rtc::CritScope cs(&crit_render_); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1398 | const StreamConfig reverse_config = { |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1399 | sample_rate_hz, ChannelsFromLayout(layout), LayoutHasKeyboard(layout), |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1400 | }; |
| 1401 | if (samples_per_channel != reverse_config.num_frames()) { |
| 1402 | return kBadDataLengthError; |
| 1403 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1404 | return AnalyzeReverseStreamLocked(data, reverse_config, reverse_config); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1407 | int AudioProcessingImpl::ProcessReverseStream(const float* const* src, |
| 1408 | const StreamConfig& input_config, |
| 1409 | const StreamConfig& output_config, |
| 1410 | float* const* dest) { |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 1411 | TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_StreamConfig"); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1412 | rtc::CritScope cs(&crit_render_); |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1413 | RETURN_ON_ERR(AnalyzeReverseStreamLocked(src, input_config, output_config)); |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 1414 | if (submodule_states_.RenderMultiBandProcessingActive() || |
| 1415 | submodule_states_.RenderFullBandProcessingActive()) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1416 | render_.render_audio->CopyTo(formats_.api_format.reverse_output_stream(), |
| 1417 | dest); |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1418 | } else if (formats_.api_format.reverse_input_stream() != |
| 1419 | formats_.api_format.reverse_output_stream()) { |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1420 | render_.render_converter->Convert(src, input_config.num_samples(), dest, |
| 1421 | output_config.num_samples()); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1422 | } else { |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1423 | CopyAudioIfNeeded(src, input_config.num_frames(), |
| 1424 | input_config.num_channels(), dest); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | return kNoError; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1430 | int AudioProcessingImpl::AnalyzeReverseStreamLocked( |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1431 | const float* const* src, |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1432 | const StreamConfig& input_config, |
| 1433 | const StreamConfig& output_config) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1434 | if (src == nullptr) { |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1435 | return kNullPointerError; |
| 1436 | } |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1437 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1438 | if (input_config.num_channels() == 0) { |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1439 | return kBadNumberChannelsError; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1440 | } |
| 1441 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1442 | ProcessingConfig processing_config = formats_.api_format; |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1443 | processing_config.reverse_input_stream() = input_config; |
| 1444 | processing_config.reverse_output_stream() = output_config; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1445 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1446 | RETURN_ON_ERR(MaybeInitializeRender(processing_config)); |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1447 | assert(input_config.num_frames() == |
| 1448 | formats_.api_format.reverse_input_stream().num_frames()); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1449 | |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 1450 | if (aec_dump_) { |
| 1451 | const size_t channel_size = |
| 1452 | formats_.api_format.reverse_input_stream().num_frames(); |
| 1453 | const size_t num_channels = |
| 1454 | formats_.api_format.reverse_input_stream().num_channels(); |
| 1455 | aec_dump_->WriteRenderStreamMessage( |
| 1456 | FloatAudioFrame(src, num_channels, channel_size)); |
| 1457 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1458 | render_.render_audio->CopyFrom(src, |
| 1459 | formats_.api_format.reverse_input_stream()); |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1460 | return ProcessRenderStreamLocked(); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) { |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 1464 | TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_AudioFrame"); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1465 | rtc::CritScope cs(&crit_render_); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1466 | if (frame == nullptr) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1467 | return kNullPointerError; |
| 1468 | } |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 1469 | // Must be a native rate. |
| 1470 | if (frame->sample_rate_hz_ != kSampleRate8kHz && |
| 1471 | frame->sample_rate_hz_ != kSampleRate16kHz && |
aluebs@webrtc.org | 087da13 | 2014-11-17 23:01:23 +0000 | [diff] [blame] | 1472 | frame->sample_rate_hz_ != kSampleRate32kHz && |
| 1473 | frame->sample_rate_hz_ != kSampleRate48kHz) { |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 1474 | return kBadSampleRateError; |
| 1475 | } |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 1476 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1477 | if (frame->num_channels_ <= 0) { |
| 1478 | return kBadNumberChannelsError; |
| 1479 | } |
| 1480 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1481 | ProcessingConfig processing_config = formats_.api_format; |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1482 | processing_config.reverse_input_stream().set_sample_rate_hz( |
| 1483 | frame->sample_rate_hz_); |
| 1484 | processing_config.reverse_input_stream().set_num_channels( |
| 1485 | frame->num_channels_); |
| 1486 | processing_config.reverse_output_stream().set_sample_rate_hz( |
| 1487 | frame->sample_rate_hz_); |
| 1488 | processing_config.reverse_output_stream().set_num_channels( |
| 1489 | frame->num_channels_); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1490 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1491 | RETURN_ON_ERR(MaybeInitializeRender(processing_config)); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1492 | if (frame->samples_per_channel_ != |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1493 | formats_.api_format.reverse_input_stream().num_frames()) { |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1494 | return kBadDataLengthError; |
| 1495 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1496 | |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 1497 | if (aec_dump_) { |
| 1498 | aec_dump_->WriteRenderStreamMessage(*frame); |
| 1499 | } |
| 1500 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1501 | render_.render_audio->DeinterleaveFrom(frame); |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1502 | RETURN_ON_ERR(ProcessRenderStreamLocked()); |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1503 | render_.render_audio->InterleaveTo( |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 1504 | frame, submodule_states_.RenderMultiBandProcessingActive() || |
| 1505 | submodule_states_.RenderFullBandProcessingActive()); |
aluebs | b031955 | 2016-03-17 20:39:53 -0700 | [diff] [blame] | 1506 | return kNoError; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1507 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1508 | |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1509 | int AudioProcessingImpl::ProcessRenderStreamLocked() { |
| 1510 | AudioBuffer* render_buffer = render_.render_audio.get(); // For brevity. |
peah | 9e6a290 | 2017-05-15 07:19:21 -0700 | [diff] [blame] | 1511 | |
| 1512 | QueueNonbandedRenderAudio(render_buffer); |
| 1513 | |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 1514 | if (private_submodules_->render_pre_processor) { |
| 1515 | private_submodules_->render_pre_processor->Process(render_buffer); |
| 1516 | } |
| 1517 | |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1518 | if (submodule_states_.RenderMultiBandSubModulesActive() && |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1519 | SampleRateSupportsMultiBand( |
| 1520 | formats_.render_processing_format.sample_rate_hz())) { |
| 1521 | render_buffer->SplitIntoFrequencyBands(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 1524 | #if WEBRTC_INTELLIGIBILITY_ENHANCER |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 1525 | if (capture_nonlocked_.intelligibility_enabled) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1526 | public_submodules_->intelligibility_enhancer->ProcessRenderAudio( |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 1527 | render_buffer); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1528 | } |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 1529 | #endif |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1530 | |
peah | ce4d915 | 2017-05-19 01:28:05 -0700 | [diff] [blame] | 1531 | if (submodule_states_.RenderMultiBandSubModulesActive()) { |
| 1532 | QueueBandedRenderAudio(render_buffer); |
| 1533 | } |
| 1534 | |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 1535 | // TODO(peah): Perform the queueing Ãnside QueueRenderAudiuo(). |
Gustaf Ullberg | 59ff0e2 | 2017-10-09 10:20:34 +0200 | [diff] [blame] | 1536 | if (private_submodules_->echo_controller) { |
| 1537 | private_submodules_->echo_controller->AnalyzeRender(render_buffer); |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 1538 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1539 | |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1540 | if (submodule_states_.RenderMultiBandProcessingActive() && |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1541 | SampleRateSupportsMultiBand( |
| 1542 | formats_.render_processing_format.sample_rate_hz())) { |
| 1543 | render_buffer->MergeFrequencyBands(); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1546 | return kNoError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | int AudioProcessingImpl::set_stream_delay_ms(int delay) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1550 | rtc::CritScope cs(&crit_capture_); |
andrew@webrtc.org | 5f23d64 | 2012-05-29 21:14:06 +0000 | [diff] [blame] | 1551 | Error retval = kNoError; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1552 | capture_.was_stream_delay_set = true; |
| 1553 | delay += capture_.delay_offset_ms; |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 1554 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1555 | if (delay < 0) { |
andrew@webrtc.org | 5f23d64 | 2012-05-29 21:14:06 +0000 | [diff] [blame] | 1556 | delay = 0; |
| 1557 | retval = kBadStreamParameterWarning; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | // TODO(ajm): the max is rather arbitrarily chosen; investigate. |
| 1561 | if (delay > 500) { |
andrew@webrtc.org | 5f23d64 | 2012-05-29 21:14:06 +0000 | [diff] [blame] | 1562 | delay = 500; |
| 1563 | retval = kBadStreamParameterWarning; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1566 | capture_nonlocked_.stream_delay_ms = delay; |
andrew@webrtc.org | 5f23d64 | 2012-05-29 21:14:06 +0000 | [diff] [blame] | 1567 | return retval; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | int AudioProcessingImpl::stream_delay_ms() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1571 | // Used as callback from submodules, hence locking is not allowed. |
| 1572 | return capture_nonlocked_.stream_delay_ms; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | bool AudioProcessingImpl::was_stream_delay_set() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1576 | // Used as callback from submodules, hence locking is not allowed. |
| 1577 | return capture_.was_stream_delay_set; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1580 | void AudioProcessingImpl::set_stream_key_pressed(bool key_pressed) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1581 | rtc::CritScope cs(&crit_capture_); |
| 1582 | capture_.key_pressed = key_pressed; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 1585 | void AudioProcessingImpl::set_delay_offset_ms(int offset) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1586 | rtc::CritScope cs(&crit_capture_); |
| 1587 | capture_.delay_offset_ms = offset; |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | int AudioProcessingImpl::delay_offset_ms() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1591 | rtc::CritScope cs(&crit_capture_); |
| 1592 | return capture_.delay_offset_ms; |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 1595 | void AudioProcessingImpl::AttachAecDump(std::unique_ptr<AecDump> aec_dump) { |
| 1596 | RTC_DCHECK(aec_dump); |
| 1597 | rtc::CritScope cs_render(&crit_render_); |
| 1598 | rtc::CritScope cs_capture(&crit_capture_); |
| 1599 | |
| 1600 | // The previously attached AecDump will be destroyed with the |
| 1601 | // 'aec_dump' parameter, which is after locks are released. |
| 1602 | aec_dump_.swap(aec_dump); |
| 1603 | WriteAecDumpConfigMessage(true); |
| 1604 | aec_dump_->WriteInitMessage(ToStreamsConfig(formats_.api_format)); |
| 1605 | } |
| 1606 | |
| 1607 | void AudioProcessingImpl::DetachAecDump() { |
| 1608 | // The d-tor of a task-queue based AecDump blocks until all pending |
| 1609 | // tasks are done. This construction avoids blocking while holding |
| 1610 | // the render and capture locks. |
| 1611 | std::unique_ptr<AecDump> aec_dump = nullptr; |
| 1612 | { |
| 1613 | rtc::CritScope cs_render(&crit_render_); |
| 1614 | rtc::CritScope cs_capture(&crit_capture_); |
| 1615 | aec_dump = std::move(aec_dump_); |
| 1616 | } |
| 1617 | } |
| 1618 | |
ivoc | 4e477a1 | 2017-01-15 08:29:46 -0800 | [diff] [blame] | 1619 | AudioProcessing::AudioProcessingStatistics::AudioProcessingStatistics() { |
| 1620 | residual_echo_return_loss.Set(-100.0f, -100.0f, -100.0f, -100.0f); |
| 1621 | echo_return_loss.Set(-100.0f, -100.0f, -100.0f, -100.0f); |
| 1622 | echo_return_loss_enhancement.Set(-100.0f, -100.0f, -100.0f, -100.0f); |
| 1623 | a_nlp.Set(-100.0f, -100.0f, -100.0f, -100.0f); |
| 1624 | } |
| 1625 | |
| 1626 | AudioProcessing::AudioProcessingStatistics::AudioProcessingStatistics( |
| 1627 | const AudioProcessingStatistics& other) = default; |
| 1628 | |
| 1629 | AudioProcessing::AudioProcessingStatistics::~AudioProcessingStatistics() = |
| 1630 | default; |
| 1631 | |
ivoc | 3e9a537 | 2016-10-28 07:55:33 -0700 | [diff] [blame] | 1632 | // TODO(ivoc): Remove this when GetStatistics() becomes pure virtual. |
| 1633 | AudioProcessing::AudioProcessingStatistics AudioProcessing::GetStatistics() |
| 1634 | const { |
| 1635 | return AudioProcessingStatistics(); |
| 1636 | } |
| 1637 | |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 1638 | // TODO(ivoc): Remove this when GetStatistics() becomes pure virtual. |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 1639 | AudioProcessingStats AudioProcessing::GetStatistics( |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 1640 | bool has_remote_tracks) const { |
| 1641 | return AudioProcessingStats(); |
| 1642 | } |
| 1643 | |
ivoc | 3e9a537 | 2016-10-28 07:55:33 -0700 | [diff] [blame] | 1644 | AudioProcessing::AudioProcessingStatistics AudioProcessingImpl::GetStatistics() |
| 1645 | const { |
| 1646 | AudioProcessingStatistics stats; |
| 1647 | EchoCancellation::Metrics metrics; |
Gustaf Ullberg | 09b9fae | 2017-11-24 13:42:29 +0100 | [diff] [blame] | 1648 | if (private_submodules_->echo_controller) { |
| 1649 | rtc::CritScope cs_capture(&crit_capture_); |
| 1650 | auto ec_metrics = private_submodules_->echo_controller->GetMetrics(); |
| 1651 | float erl = static_cast<float>(ec_metrics.echo_return_loss); |
| 1652 | float erle = static_cast<float>(ec_metrics.echo_return_loss_enhancement); |
| 1653 | // Instant value will also be used for min, max and average. |
| 1654 | stats.echo_return_loss.Set(erl, erl, erl, erl); |
| 1655 | stats.echo_return_loss_enhancement.Set(erle, erle, erle, erle); |
| 1656 | } else if (public_submodules_->echo_cancellation->GetMetrics(&metrics) == |
| 1657 | Error::kNoError) { |
ivoc | d0a151c | 2016-11-02 09:14:37 -0700 | [diff] [blame] | 1658 | stats.a_nlp.Set(metrics.a_nlp); |
| 1659 | stats.divergent_filter_fraction = metrics.divergent_filter_fraction; |
| 1660 | stats.echo_return_loss.Set(metrics.echo_return_loss); |
| 1661 | stats.echo_return_loss_enhancement.Set( |
| 1662 | metrics.echo_return_loss_enhancement); |
| 1663 | stats.residual_echo_return_loss.Set(metrics.residual_echo_return_loss); |
| 1664 | } |
ivoc | 9c192b2 | 2017-03-16 04:22:14 -0700 | [diff] [blame] | 1665 | { |
| 1666 | rtc::CritScope cs_capture(&crit_capture_); |
| 1667 | stats.residual_echo_likelihood = |
| 1668 | private_submodules_->residual_echo_detector->echo_likelihood(); |
| 1669 | stats.residual_echo_likelihood_recent_max = |
| 1670 | private_submodules_->residual_echo_detector |
| 1671 | ->echo_likelihood_recent_max(); |
| 1672 | } |
ivoc | 3e9a537 | 2016-10-28 07:55:33 -0700 | [diff] [blame] | 1673 | public_submodules_->echo_cancellation->GetDelayMetrics( |
| 1674 | &stats.delay_median, &stats.delay_standard_deviation, |
| 1675 | &stats.fraction_poor_delays); |
| 1676 | return stats; |
| 1677 | } |
| 1678 | |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 1679 | AudioProcessingStats AudioProcessingImpl::GetStatistics( |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 1680 | bool has_remote_tracks) const { |
| 1681 | AudioProcessingStats stats; |
| 1682 | if (has_remote_tracks) { |
| 1683 | EchoCancellation::Metrics metrics; |
Gustaf Ullberg | 332150d | 2017-11-22 14:17:39 +0100 | [diff] [blame] | 1684 | if (private_submodules_->echo_controller) { |
| 1685 | rtc::CritScope cs_capture(&crit_capture_); |
Gustaf Ullberg | 09b9fae | 2017-11-24 13:42:29 +0100 | [diff] [blame] | 1686 | auto ec_metrics = private_submodules_->echo_controller->GetMetrics(); |
| 1687 | stats.echo_return_loss = ec_metrics.echo_return_loss; |
Gustaf Ullberg | 332150d | 2017-11-22 14:17:39 +0100 | [diff] [blame] | 1688 | stats.echo_return_loss_enhancement = |
Gustaf Ullberg | 09b9fae | 2017-11-24 13:42:29 +0100 | [diff] [blame] | 1689 | ec_metrics.echo_return_loss_enhancement; |
Per Ã…hgren | 83c4a02 | 2017-11-27 12:07:09 +0100 | [diff] [blame] | 1690 | stats.delay_ms = ec_metrics.delay_ms; |
Gustaf Ullberg | 332150d | 2017-11-22 14:17:39 +0100 | [diff] [blame] | 1691 | } else if (public_submodules_->echo_cancellation->GetMetrics(&metrics) == |
| 1692 | Error::kNoError) { |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 1693 | if (metrics.divergent_filter_fraction != -1.0f) { |
| 1694 | stats.divergent_filter_fraction = |
| 1695 | rtc::Optional<double>(metrics.divergent_filter_fraction); |
| 1696 | } |
| 1697 | if (metrics.echo_return_loss.instant != -100) { |
| 1698 | stats.echo_return_loss = |
| 1699 | rtc::Optional<double>(metrics.echo_return_loss.instant); |
| 1700 | } |
| 1701 | if (metrics.echo_return_loss_enhancement.instant != -100) { |
| 1702 | stats.echo_return_loss_enhancement = |
| 1703 | rtc::Optional<double>(metrics.echo_return_loss_enhancement.instant); |
| 1704 | } |
| 1705 | } |
| 1706 | if (config_.residual_echo_detector.enabled) { |
| 1707 | rtc::CritScope cs_capture(&crit_capture_); |
| 1708 | stats.residual_echo_likelihood = rtc::Optional<double>( |
| 1709 | private_submodules_->residual_echo_detector->echo_likelihood()); |
| 1710 | stats.residual_echo_likelihood_recent_max = |
| 1711 | rtc::Optional<double>(private_submodules_->residual_echo_detector |
| 1712 | ->echo_likelihood_recent_max()); |
| 1713 | } |
| 1714 | int delay_median, delay_std; |
| 1715 | float fraction_poor_delays; |
| 1716 | if (public_submodules_->echo_cancellation->GetDelayMetrics( |
| 1717 | &delay_median, &delay_std, &fraction_poor_delays) == |
| 1718 | Error::kNoError) { |
| 1719 | if (delay_median >= 0) { |
| 1720 | stats.delay_median_ms = rtc::Optional<int32_t>(delay_median); |
| 1721 | } |
| 1722 | if (delay_std >= 0) { |
| 1723 | stats.delay_standard_deviation_ms = rtc::Optional<int32_t>(delay_std); |
| 1724 | } |
| 1725 | } |
| 1726 | } |
| 1727 | return stats; |
| 1728 | } |
| 1729 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1730 | EchoCancellation* AudioProcessingImpl::echo_cancellation() const { |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 1731 | return public_submodules_->echo_cancellation.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | EchoControlMobile* AudioProcessingImpl::echo_control_mobile() const { |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 1735 | return public_submodules_->echo_control_mobile.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | GainControl* AudioProcessingImpl::gain_control() const { |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 1739 | if (constants_.use_experimental_agc) { |
| 1740 | return public_submodules_->gain_control_for_experimental_agc.get(); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1741 | } |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 1742 | return public_submodules_->gain_control.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | HighPassFilter* AudioProcessingImpl::high_pass_filter() const { |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 1746 | return high_pass_filter_impl_.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | LevelEstimator* AudioProcessingImpl::level_estimator() const { |
solenberg | 949028f | 2015-12-15 11:39:38 -0800 | [diff] [blame] | 1750 | return public_submodules_->level_estimator.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | NoiseSuppression* AudioProcessingImpl::noise_suppression() const { |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 1754 | return public_submodules_->noise_suppression.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | VoiceDetection* AudioProcessingImpl::voice_detection() const { |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 1758 | return public_submodules_->voice_detection.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 1761 | void AudioProcessingImpl::MutateConfig( |
| 1762 | rtc::FunctionView<void(AudioProcessing::Config*)> mutator) { |
| 1763 | rtc::CritScope cs_render(&crit_render_); |
| 1764 | rtc::CritScope cs_capture(&crit_capture_); |
| 1765 | mutator(&config_); |
| 1766 | ApplyConfig(config_); |
| 1767 | } |
| 1768 | |
| 1769 | AudioProcessing::Config AudioProcessingImpl::GetConfig() const { |
| 1770 | rtc::CritScope cs_render(&crit_render_); |
| 1771 | rtc::CritScope cs_capture(&crit_capture_); |
| 1772 | return config_; |
| 1773 | } |
| 1774 | |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1775 | bool AudioProcessingImpl::UpdateActiveSubmoduleStates() { |
| 1776 | return submodule_states_.Update( |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 1777 | config_.high_pass_filter.enabled, |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1778 | public_submodules_->echo_cancellation->is_enabled(), |
| 1779 | public_submodules_->echo_control_mobile->is_enabled(), |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 1780 | config_.residual_echo_detector.enabled, |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1781 | public_submodules_->noise_suppression->is_enabled(), |
| 1782 | capture_nonlocked_.intelligibility_enabled, |
| 1783 | capture_nonlocked_.beamformer_enabled, |
| 1784 | public_submodules_->gain_control->is_enabled(), |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 1785 | config_.gain_controller2.enabled, |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1786 | capture_nonlocked_.level_controller_enabled, |
Gustaf Ullberg | ce045ac | 2017-10-16 13:49:04 +0200 | [diff] [blame] | 1787 | capture_nonlocked_.echo_controller_enabled, |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 1788 | public_submodules_->voice_detection->is_enabled(), |
| 1789 | public_submodules_->level_estimator->is_enabled(), |
| 1790 | capture_.transient_suppressor_enabled); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1793 | |
Bjorn Volcker | adc46c4 | 2015-04-15 11:42:40 +0200 | [diff] [blame] | 1794 | void AudioProcessingImpl::InitializeTransient() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1795 | if (capture_.transient_suppressor_enabled) { |
| 1796 | if (!public_submodules_->transient_suppressor.get()) { |
| 1797 | public_submodules_->transient_suppressor.reset(new TransientSuppressor()); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1798 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1799 | public_submodules_->transient_suppressor->Initialize( |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 1800 | capture_nonlocked_.capture_processing_format.sample_rate_hz(), |
| 1801 | capture_nonlocked_.split_rate, num_proc_channels()); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1802 | } |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1803 | } |
| 1804 | |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 1805 | void AudioProcessingImpl::InitializeBeamformer() { |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 1806 | if (capture_nonlocked_.beamformer_enabled) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1807 | if (!private_submodules_->beamformer) { |
| 1808 | private_submodules_->beamformer.reset(new NonlinearBeamformer( |
Alejandro Luebs | f4022ff | 2016-07-01 17:19:09 -0700 | [diff] [blame] | 1809 | capture_.array_geometry, 1u, capture_.target_direction)); |
aluebs@webrtc.org | d82f55d | 2015-01-15 18:07:21 +0000 | [diff] [blame] | 1810 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1811 | private_submodules_->beamformer->Initialize(kChunkSizeMs, |
| 1812 | capture_nonlocked_.split_rate); |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 1813 | } |
| 1814 | } |
| 1815 | |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1816 | void AudioProcessingImpl::InitializeIntelligibility() { |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 1817 | #if WEBRTC_INTELLIGIBILITY_ENHANCER |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 1818 | if (capture_nonlocked_.intelligibility_enabled) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1819 | public_submodules_->intelligibility_enhancer.reset( |
Alejandro Luebs | 18fcbcf | 2016-02-22 15:57:38 -0800 | [diff] [blame] | 1820 | new IntelligibilityEnhancer(capture_nonlocked_.split_rate, |
Alex Luebs | 57ae829 | 2016-03-09 16:24:34 +0100 | [diff] [blame] | 1821 | render_.render_audio->num_channels(), |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 1822 | render_.render_audio->num_bands(), |
Alex Luebs | 57ae829 | 2016-03-09 16:24:34 +0100 | [diff] [blame] | 1823 | NoiseSuppressionImpl::num_noise_bins())); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1824 | } |
peah | 1bcfce5 | 2016-08-26 07:16:04 -0700 | [diff] [blame] | 1825 | #endif |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 1828 | void AudioProcessingImpl::InitializeLowCutFilter() { |
| 1829 | if (config_.high_pass_filter.enabled) { |
| 1830 | private_submodules_->low_cut_filter.reset( |
| 1831 | new LowCutFilter(num_proc_channels(), proc_sample_rate_hz())); |
| 1832 | } else { |
| 1833 | private_submodules_->low_cut_filter.reset(); |
| 1834 | } |
| 1835 | } |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 1836 | |
Gustaf Ullberg | 8eb9c7d | 2017-10-14 08:28:46 +0200 | [diff] [blame] | 1837 | void AudioProcessingImpl::InitializeEchoController() { |
Gustaf Ullberg | 002ef28 | 2017-10-12 15:13:17 +0200 | [diff] [blame] | 1838 | if (echo_control_factory_) { |
| 1839 | private_submodules_->echo_controller = |
| 1840 | echo_control_factory_->Create(proc_sample_rate_hz()); |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 1841 | } else { |
Gustaf Ullberg | 59ff0e2 | 2017-10-09 10:20:34 +0200 | [diff] [blame] | 1842 | private_submodules_->echo_controller.reset(); |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 1843 | } |
| 1844 | } |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 1845 | |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 1846 | void AudioProcessingImpl::InitializeGainController2() { |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 1847 | if (config_.gain_controller2.enabled) { |
| 1848 | private_submodules_->gain_controller2->Initialize(proc_sample_rate_hz()); |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 1849 | } |
| 1850 | } |
| 1851 | |
peah | ca4cac7 | 2016-06-29 15:26:12 -0700 | [diff] [blame] | 1852 | void AudioProcessingImpl::InitializeLevelController() { |
| 1853 | private_submodules_->level_controller->Initialize(proc_sample_rate_hz()); |
| 1854 | } |
| 1855 | |
ivoc | 9f4a4a0 | 2016-10-28 05:39:16 -0700 | [diff] [blame] | 1856 | void AudioProcessingImpl::InitializeResidualEchoDetector() { |
| 1857 | private_submodules_->residual_echo_detector->Initialize(); |
| 1858 | } |
| 1859 | |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 1860 | void AudioProcessingImpl::InitializePostProcessor() { |
| 1861 | if (private_submodules_->capture_post_processor) { |
| 1862 | private_submodules_->capture_post_processor->Initialize( |
| 1863 | proc_sample_rate_hz(), num_proc_channels()); |
| 1864 | } |
| 1865 | } |
| 1866 | |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 1867 | void AudioProcessingImpl::InitializePreProcessor() { |
| 1868 | if (private_submodules_->render_pre_processor) { |
| 1869 | private_submodules_->render_pre_processor->Initialize( |
| 1870 | formats_.render_processing_format.sample_rate_hz(), |
| 1871 | formats_.render_processing_format.num_channels()); |
| 1872 | } |
| 1873 | } |
| 1874 | |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1875 | void AudioProcessingImpl::MaybeUpdateHistograms() { |
Bjorn Volcker | d92f267 | 2015-07-05 10:46:01 +0200 | [diff] [blame] | 1876 | static const int kMinDiffDelayMs = 60; |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1877 | |
| 1878 | if (echo_cancellation()->is_enabled()) { |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 1879 | // Activate delay_jumps_ counters if we know echo_cancellation is running. |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1880 | // If a stream has echo we know that the echo_cancellation is in process. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1881 | if (capture_.stream_delay_jumps == -1 && |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1882 | echo_cancellation()->stream_has_echo()) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1883 | capture_.stream_delay_jumps = 0; |
| 1884 | } |
| 1885 | if (capture_.aec_system_delay_jumps == -1 && |
| 1886 | echo_cancellation()->stream_has_echo()) { |
| 1887 | capture_.aec_system_delay_jumps = 0; |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1888 | } |
| 1889 | |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1890 | // Detect a jump in platform reported system delay and log the difference. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1891 | const int diff_stream_delay_ms = |
| 1892 | capture_nonlocked_.stream_delay_ms - capture_.last_stream_delay_ms; |
| 1893 | if (diff_stream_delay_ms > kMinDiffDelayMs && |
| 1894 | capture_.last_stream_delay_ms != 0) { |
asapersson | a2c58e2 | 2016-03-07 01:52:59 -0800 | [diff] [blame] | 1895 | RTC_HISTOGRAM_COUNTS("WebRTC.Audio.PlatformReportedStreamDelayJump", |
| 1896 | diff_stream_delay_ms, kMinDiffDelayMs, 1000, 100); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1897 | if (capture_.stream_delay_jumps == -1) { |
| 1898 | capture_.stream_delay_jumps = 0; // Activate counter if needed. |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1899 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1900 | capture_.stream_delay_jumps++; |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1901 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1902 | capture_.last_stream_delay_ms = capture_nonlocked_.stream_delay_ms; |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1903 | |
| 1904 | // Detect a jump in AEC system delay and log the difference. |
peah | 20028c4 | 2016-03-04 11:50:54 -0800 | [diff] [blame] | 1905 | const int samples_per_ms = |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1906 | rtc::CheckedDivExact(capture_nonlocked_.split_rate, 1000); |
peah | 20028c4 | 2016-03-04 11:50:54 -0800 | [diff] [blame] | 1907 | RTC_DCHECK_LT(0, samples_per_ms); |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1908 | const int aec_system_delay_ms = |
peah | 20028c4 | 2016-03-04 11:50:54 -0800 | [diff] [blame] | 1909 | public_submodules_->echo_cancellation->GetSystemDelayInSamples() / |
| 1910 | samples_per_ms; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1911 | const int diff_aec_system_delay_ms = |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1912 | aec_system_delay_ms - capture_.last_aec_system_delay_ms; |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1913 | if (diff_aec_system_delay_ms > kMinDiffDelayMs && |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1914 | capture_.last_aec_system_delay_ms != 0) { |
asapersson | a2c58e2 | 2016-03-07 01:52:59 -0800 | [diff] [blame] | 1915 | RTC_HISTOGRAM_COUNTS("WebRTC.Audio.AecSystemDelayJump", |
| 1916 | diff_aec_system_delay_ms, kMinDiffDelayMs, 1000, |
| 1917 | 100); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1918 | if (capture_.aec_system_delay_jumps == -1) { |
| 1919 | capture_.aec_system_delay_jumps = 0; // Activate counter if needed. |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1920 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1921 | capture_.aec_system_delay_jumps++; |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1922 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1923 | capture_.last_aec_system_delay_ms = aec_system_delay_ms; |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1924 | } |
| 1925 | } |
| 1926 | |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1927 | void AudioProcessingImpl::UpdateHistogramsOnCallEnd() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1928 | // Run in a single-threaded manner. |
| 1929 | rtc::CritScope cs_render(&crit_render_); |
| 1930 | rtc::CritScope cs_capture(&crit_capture_); |
| 1931 | |
| 1932 | if (capture_.stream_delay_jumps > -1) { |
asapersson | a2c58e2 | 2016-03-07 01:52:59 -0800 | [diff] [blame] | 1933 | RTC_HISTOGRAM_ENUMERATION( |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1934 | "WebRTC.Audio.NumOfPlatformReportedStreamDelayJumps", |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1935 | capture_.stream_delay_jumps, 51); |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1936 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1937 | capture_.stream_delay_jumps = -1; |
| 1938 | capture_.last_stream_delay_ms = 0; |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1939 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1940 | if (capture_.aec_system_delay_jumps > -1) { |
asapersson | a2c58e2 | 2016-03-07 01:52:59 -0800 | [diff] [blame] | 1941 | RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.NumOfAecSystemDelayJumps", |
| 1942 | capture_.aec_system_delay_jumps, 51); |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1943 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1944 | capture_.aec_system_delay_jumps = -1; |
| 1945 | capture_.last_aec_system_delay_ms = 0; |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1946 | } |
| 1947 | |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 1948 | void AudioProcessingImpl::WriteAecDumpConfigMessage(bool forced) { |
| 1949 | if (!aec_dump_) { |
| 1950 | return; |
| 1951 | } |
| 1952 | std::string experiments_description = |
| 1953 | public_submodules_->echo_cancellation->GetExperimentsDescription(); |
| 1954 | // TODO(peah): Add semicolon-separated concatenations of experiment |
| 1955 | // descriptions for other submodules. |
| 1956 | if (capture_nonlocked_.level_controller_enabled) { |
| 1957 | experiments_description += "LevelController;"; |
| 1958 | } |
| 1959 | if (constants_.agc_clipped_level_min != kClippedLevelMin) { |
| 1960 | experiments_description += "AgcClippingLevelExperiment;"; |
| 1961 | } |
Gustaf Ullberg | ce045ac | 2017-10-16 13:49:04 +0200 | [diff] [blame] | 1962 | if (capture_nonlocked_.echo_controller_enabled) { |
| 1963 | experiments_description += "EchoController;"; |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 1964 | } |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 1965 | if (config_.gain_controller2.enabled) { |
| 1966 | experiments_description += "GainController2;"; |
| 1967 | } |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 1968 | |
| 1969 | InternalAPMConfig apm_config; |
| 1970 | |
| 1971 | apm_config.aec_enabled = public_submodules_->echo_cancellation->is_enabled(); |
| 1972 | apm_config.aec_delay_agnostic_enabled = |
| 1973 | public_submodules_->echo_cancellation->is_delay_agnostic_enabled(); |
| 1974 | apm_config.aec_drift_compensation_enabled = |
| 1975 | public_submodules_->echo_cancellation->is_drift_compensation_enabled(); |
| 1976 | apm_config.aec_extended_filter_enabled = |
| 1977 | public_submodules_->echo_cancellation->is_extended_filter_enabled(); |
| 1978 | apm_config.aec_suppression_level = static_cast<int>( |
| 1979 | public_submodules_->echo_cancellation->suppression_level()); |
| 1980 | |
| 1981 | apm_config.aecm_enabled = |
| 1982 | public_submodules_->echo_control_mobile->is_enabled(); |
| 1983 | apm_config.aecm_comfort_noise_enabled = |
| 1984 | public_submodules_->echo_control_mobile->is_comfort_noise_enabled(); |
| 1985 | apm_config.aecm_routing_mode = |
| 1986 | static_cast<int>(public_submodules_->echo_control_mobile->routing_mode()); |
| 1987 | |
| 1988 | apm_config.agc_enabled = public_submodules_->gain_control->is_enabled(); |
| 1989 | apm_config.agc_mode = |
| 1990 | static_cast<int>(public_submodules_->gain_control->mode()); |
| 1991 | apm_config.agc_limiter_enabled = |
| 1992 | public_submodules_->gain_control->is_limiter_enabled(); |
| 1993 | apm_config.noise_robust_agc_enabled = constants_.use_experimental_agc; |
| 1994 | |
| 1995 | apm_config.hpf_enabled = config_.high_pass_filter.enabled; |
| 1996 | |
| 1997 | apm_config.ns_enabled = public_submodules_->noise_suppression->is_enabled(); |
| 1998 | apm_config.ns_level = |
| 1999 | static_cast<int>(public_submodules_->noise_suppression->level()); |
| 2000 | |
| 2001 | apm_config.transient_suppression_enabled = |
| 2002 | capture_.transient_suppressor_enabled; |
| 2003 | apm_config.intelligibility_enhancer_enabled = |
| 2004 | capture_nonlocked_.intelligibility_enabled; |
| 2005 | apm_config.experiments_description = experiments_description; |
| 2006 | |
| 2007 | if (!forced && apm_config == apm_config_for_aec_dump_) { |
| 2008 | return; |
| 2009 | } |
| 2010 | aec_dump_->WriteConfig(apm_config); |
| 2011 | apm_config_for_aec_dump_ = apm_config; |
| 2012 | } |
| 2013 | |
| 2014 | void AudioProcessingImpl::RecordUnprocessedCaptureStream( |
| 2015 | const float* const* src) { |
| 2016 | RTC_DCHECK(aec_dump_); |
| 2017 | WriteAecDumpConfigMessage(false); |
| 2018 | |
| 2019 | const size_t channel_size = formats_.api_format.input_stream().num_frames(); |
| 2020 | const size_t num_channels = formats_.api_format.input_stream().num_channels(); |
| 2021 | aec_dump_->AddCaptureStreamInput( |
| 2022 | FloatAudioFrame(src, num_channels, channel_size)); |
| 2023 | RecordAudioProcessingState(); |
| 2024 | } |
| 2025 | |
| 2026 | void AudioProcessingImpl::RecordUnprocessedCaptureStream( |
| 2027 | const AudioFrame& capture_frame) { |
| 2028 | RTC_DCHECK(aec_dump_); |
| 2029 | WriteAecDumpConfigMessage(false); |
| 2030 | |
| 2031 | aec_dump_->AddCaptureStreamInput(capture_frame); |
| 2032 | RecordAudioProcessingState(); |
| 2033 | } |
| 2034 | |
| 2035 | void AudioProcessingImpl::RecordProcessedCaptureStream( |
| 2036 | const float* const* processed_capture_stream) { |
| 2037 | RTC_DCHECK(aec_dump_); |
| 2038 | |
| 2039 | const size_t channel_size = formats_.api_format.output_stream().num_frames(); |
| 2040 | const size_t num_channels = |
| 2041 | formats_.api_format.output_stream().num_channels(); |
| 2042 | aec_dump_->AddCaptureStreamOutput( |
| 2043 | FloatAudioFrame(processed_capture_stream, num_channels, channel_size)); |
| 2044 | aec_dump_->WriteCaptureStreamMessage(); |
| 2045 | } |
| 2046 | |
| 2047 | void AudioProcessingImpl::RecordProcessedCaptureStream( |
| 2048 | const AudioFrame& processed_capture_frame) { |
| 2049 | RTC_DCHECK(aec_dump_); |
| 2050 | |
| 2051 | aec_dump_->AddCaptureStreamOutput(processed_capture_frame); |
| 2052 | aec_dump_->WriteCaptureStreamMessage(); |
| 2053 | } |
| 2054 | |
| 2055 | void AudioProcessingImpl::RecordAudioProcessingState() { |
| 2056 | RTC_DCHECK(aec_dump_); |
| 2057 | AecDump::AudioProcessingState audio_proc_state; |
| 2058 | audio_proc_state.delay = capture_nonlocked_.stream_delay_ms; |
| 2059 | audio_proc_state.drift = |
| 2060 | public_submodules_->echo_cancellation->stream_drift_samples(); |
| 2061 | audio_proc_state.level = gain_control()->stream_analog_level(); |
| 2062 | audio_proc_state.keypress = capture_.key_pressed; |
| 2063 | aec_dump_->AddAudioProcessingState(audio_proc_state); |
| 2064 | } |
| 2065 | |
kwiberg | 83ffe45 | 2016-08-29 14:46:07 -0700 | [diff] [blame] | 2066 | AudioProcessingImpl::ApmCaptureState::ApmCaptureState( |
| 2067 | bool transient_suppressor_enabled, |
| 2068 | const std::vector<Point>& array_geometry, |
| 2069 | SphericalPointf target_direction) |
| 2070 | : aec_system_delay_jumps(-1), |
| 2071 | delay_offset_ms(0), |
| 2072 | was_stream_delay_set(false), |
| 2073 | last_stream_delay_ms(0), |
| 2074 | last_aec_system_delay_ms(0), |
| 2075 | stream_delay_jumps(-1), |
| 2076 | output_will_be_muted(false), |
| 2077 | key_pressed(false), |
| 2078 | transient_suppressor_enabled(transient_suppressor_enabled), |
| 2079 | array_geometry(array_geometry), |
| 2080 | target_direction(target_direction), |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 2081 | capture_processing_format(kSampleRate16kHz), |
peah | 6799553 | 2017-04-10 14:12:41 -0700 | [diff] [blame] | 2082 | split_rate(kSampleRate16kHz), |
peah | 6799553 | 2017-04-10 14:12:41 -0700 | [diff] [blame] | 2083 | echo_path_gain_change(false) {} |
kwiberg | 83ffe45 | 2016-08-29 14:46:07 -0700 | [diff] [blame] | 2084 | |
| 2085 | AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; |
| 2086 | |
| 2087 | AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; |
| 2088 | |
| 2089 | AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; |
| 2090 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2091 | } // namespace webrtc |