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 | |
andrew@webrtc.org | 78693fe | 2013-03-01 16:36:19 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/audio_processing/audio_processing_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 13 | #include <assert.h> |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 14 | #include <algorithm> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 16 | #include "webrtc/base/checks.h" |
xians@webrtc.org | e46bc77 | 2014-10-10 08:36:56 +0000 | [diff] [blame] | 17 | #include "webrtc/base/platform_file.h" |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 18 | #include "webrtc/base/trace_event.h" |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 19 | #include "webrtc/common_audio/audio_converter.h" |
Michael Graczyk | dfa3605 | 2015-03-25 16:37:27 -0700 | [diff] [blame] | 20 | #include "webrtc/common_audio/channel_buffer.h" |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 21 | #include "webrtc/common_audio/include/audio_util.h" |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 22 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 23 | #include "webrtc/modules/audio_processing/aec/aec_core.h" |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 24 | #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h" |
andrew@webrtc.org | 78693fe | 2013-03-01 16:36:19 +0000 | [diff] [blame] | 25 | #include "webrtc/modules/audio_processing/audio_buffer.h" |
mgraczyk@chromium.org | 0f663de | 2015-03-13 00:13:32 +0000 | [diff] [blame] | 26 | #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 27 | #include "webrtc/modules/audio_processing/common.h" |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 28 | #include "webrtc/modules/audio_processing/echo_cancellation_impl.h" |
andrew@webrtc.org | 78693fe | 2013-03-01 16:36:19 +0000 | [diff] [blame] | 29 | #include "webrtc/modules/audio_processing/echo_control_mobile_impl.h" |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 30 | #include "webrtc/modules/audio_processing/gain_control_for_experimental_agc.h" |
andrew@webrtc.org | 78693fe | 2013-03-01 16:36:19 +0000 | [diff] [blame] | 31 | #include "webrtc/modules/audio_processing/gain_control_impl.h" |
| 32 | #include "webrtc/modules/audio_processing/high_pass_filter_impl.h" |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 33 | #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.h" |
andrew@webrtc.org | 78693fe | 2013-03-01 16:36:19 +0000 | [diff] [blame] | 34 | #include "webrtc/modules/audio_processing/level_estimator_impl.h" |
| 35 | #include "webrtc/modules/audio_processing/noise_suppression_impl.h" |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 36 | #include "webrtc/modules/audio_processing/transient/transient_suppressor.h" |
andrew@webrtc.org | 78693fe | 2013-03-01 16:36:19 +0000 | [diff] [blame] | 37 | #include "webrtc/modules/audio_processing/voice_detection_impl.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 38 | #include "webrtc/modules/include/module_common_types.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 39 | #include "webrtc/system_wrappers/include/file_wrapper.h" |
| 40 | #include "webrtc/system_wrappers/include/logging.h" |
| 41 | #include "webrtc/system_wrappers/include/metrics.h" |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 42 | |
| 43 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 44 | // Files generated at build-time by the protobuf compiler. |
leozwang@webrtc.org | a373634 | 2012-03-16 21:36:00 +0000 | [diff] [blame] | 45 | #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
leozwang@webrtc.org | 534e495 | 2012-10-22 21:21:52 +0000 | [diff] [blame] | 46 | #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h" |
leozwang@google.com | ce9bfbb | 2011-08-03 23:34:31 +0000 | [diff] [blame] | 47 | #else |
kjellander | 78ddd73 | 2016-02-09 08:13:06 -0800 | [diff] [blame] | 48 | #include "webrtc/modules/audio_processing/debug.pb.h" |
leozwang@google.com | ce9bfbb | 2011-08-03 23:34:31 +0000 | [diff] [blame] | 49 | #endif |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 50 | #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 52 | #define RETURN_ON_ERR(expr) \ |
| 53 | do { \ |
| 54 | int err = (expr); \ |
| 55 | if (err != kNoError) { \ |
| 56 | return err; \ |
| 57 | } \ |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 58 | } while (0) |
| 59 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | namespace webrtc { |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 61 | namespace { |
| 62 | |
| 63 | static bool LayoutHasKeyboard(AudioProcessing::ChannelLayout layout) { |
| 64 | switch (layout) { |
| 65 | case AudioProcessing::kMono: |
| 66 | case AudioProcessing::kStereo: |
| 67 | return false; |
| 68 | case AudioProcessing::kMonoAndKeyboard: |
| 69 | case AudioProcessing::kStereoAndKeyboard: |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | assert(false); |
| 74 | return false; |
| 75 | } |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 76 | } // namespace |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 77 | |
| 78 | // Throughout webrtc, it's assumed that success is represented by zero. |
kwiberg@webrtc.org | 2ebfac5 | 2015-01-14 10:51:54 +0000 | [diff] [blame] | 79 | static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero"); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 80 | |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 81 | struct AudioProcessingImpl::ApmPublicSubmodules { |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 82 | ApmPublicSubmodules() {} |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 83 | // Accessed externally of APM without any lock acquired. |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 84 | std::unique_ptr<EchoCancellationImpl> echo_cancellation; |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 85 | std::unique_ptr<EchoControlMobileImpl> echo_control_mobile; |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 86 | std::unique_ptr<GainControlImpl> gain_control; |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 87 | std::unique_ptr<HighPassFilterImpl> high_pass_filter; |
| 88 | std::unique_ptr<LevelEstimatorImpl> level_estimator; |
| 89 | std::unique_ptr<NoiseSuppressionImpl> noise_suppression; |
| 90 | std::unique_ptr<VoiceDetectionImpl> voice_detection; |
| 91 | std::unique_ptr<GainControlForExperimentalAgc> |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 92 | gain_control_for_experimental_agc; |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 93 | |
| 94 | // Accessed internally from both render and capture. |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 95 | std::unique_ptr<TransientSuppressor> transient_suppressor; |
| 96 | std::unique_ptr<IntelligibilityEnhancer> intelligibility_enhancer; |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | struct AudioProcessingImpl::ApmPrivateSubmodules { |
| 100 | explicit ApmPrivateSubmodules(Beamformer<float>* beamformer) |
| 101 | : beamformer(beamformer) {} |
| 102 | // Accessed internally from capture or during initialization |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 103 | std::unique_ptr<Beamformer<float>> beamformer; |
| 104 | std::unique_ptr<AgcManagerDirect> agc_manager; |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
Alejandro Luebs | cdfe20b | 2015-09-23 12:49:12 -0700 | [diff] [blame] | 107 | const int AudioProcessing::kNativeSampleRatesHz[] = { |
| 108 | AudioProcessing::kSampleRate8kHz, |
| 109 | AudioProcessing::kSampleRate16kHz, |
aluebs | 4c279b8 | 2016-03-08 01:48:17 -0800 | [diff] [blame] | 110 | #ifdef WEBRTC_ARCH_ARM_FAMILY |
| 111 | AudioProcessing::kSampleRate32kHz}; |
| 112 | #else |
Alejandro Luebs | cdfe20b | 2015-09-23 12:49:12 -0700 | [diff] [blame] | 113 | AudioProcessing::kSampleRate32kHz, |
| 114 | AudioProcessing::kSampleRate48kHz}; |
aluebs | 4c279b8 | 2016-03-08 01:48:17 -0800 | [diff] [blame] | 115 | #endif // WEBRTC_ARCH_ARM_FAMILY |
Alejandro Luebs | cdfe20b | 2015-09-23 12:49:12 -0700 | [diff] [blame] | 116 | const size_t AudioProcessing::kNumNativeSampleRates = |
| 117 | arraysize(AudioProcessing::kNativeSampleRatesHz); |
| 118 | const int AudioProcessing::kMaxNativeSampleRateHz = AudioProcessing:: |
| 119 | kNativeSampleRatesHz[AudioProcessing::kNumNativeSampleRates - 1]; |
perkj | dfc2870 | 2016-03-09 16:23:23 -0800 | [diff] [blame] | 120 | const int AudioProcessing::kMaxAECMSampleRateHz = kSampleRate16kHz; |
Alejandro Luebs | cdfe20b | 2015-09-23 12:49:12 -0700 | [diff] [blame] | 121 | |
andrew@webrtc.org | e84978f | 2014-01-25 02:09:06 +0000 | [diff] [blame] | 122 | AudioProcessing* AudioProcessing::Create() { |
| 123 | Config config; |
aluebs@webrtc.org | d82f55d | 2015-01-15 18:07:21 +0000 | [diff] [blame] | 124 | return Create(config, nullptr); |
andrew@webrtc.org | e84978f | 2014-01-25 02:09:06 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | AudioProcessing* AudioProcessing::Create(const Config& config) { |
aluebs@webrtc.org | d82f55d | 2015-01-15 18:07:21 +0000 | [diff] [blame] | 128 | return Create(config, nullptr); |
| 129 | } |
| 130 | |
| 131 | AudioProcessing* AudioProcessing::Create(const Config& config, |
Michael Graczyk | dfa3605 | 2015-03-25 16:37:27 -0700 | [diff] [blame] | 132 | Beamformer<float>* beamformer) { |
aluebs@webrtc.org | d82f55d | 2015-01-15 18:07:21 +0000 | [diff] [blame] | 133 | AudioProcessingImpl* apm = new AudioProcessingImpl(config, beamformer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 134 | if (apm->Initialize() != kNoError) { |
| 135 | delete apm; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 136 | apm = nullptr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | return apm; |
| 140 | } |
| 141 | |
andrew@webrtc.org | e84978f | 2014-01-25 02:09:06 +0000 | [diff] [blame] | 142 | AudioProcessingImpl::AudioProcessingImpl(const Config& config) |
aluebs@webrtc.org | d82f55d | 2015-01-15 18:07:21 +0000 | [diff] [blame] | 143 | : AudioProcessingImpl(config, nullptr) {} |
| 144 | |
| 145 | AudioProcessingImpl::AudioProcessingImpl(const Config& config, |
Michael Graczyk | dfa3605 | 2015-03-25 16:37:27 -0700 | [diff] [blame] | 146 | Beamformer<float>* beamformer) |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 147 | : public_submodules_(new ApmPublicSubmodules()), |
| 148 | private_submodules_(new ApmPrivateSubmodules(beamformer)), |
| 149 | constants_(config.Get<ExperimentalAgc>().startup_min_volume, |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 150 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 151 | false, |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 152 | #else |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 153 | config.Get<ExperimentalAgc>().enabled, |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 154 | #endif |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 155 | config.Get<Intelligibility>().enabled), |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 156 | |
andrew | 1c7075f | 2015-06-24 18:14:14 -0700 | [diff] [blame] | 157 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 158 | capture_(false, |
andrew | 1c7075f | 2015-06-24 18:14:14 -0700 | [diff] [blame] | 159 | #else |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 160 | capture_(config.Get<ExperimentalNs>().enabled, |
andrew | 1c7075f | 2015-06-24 18:14:14 -0700 | [diff] [blame] | 161 | #endif |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 162 | config.Get<Beamforming>().array_geometry, |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 163 | config.Get<Beamforming>().target_direction), |
| 164 | capture_nonlocked_(config.Get<Beamforming>().enabled) |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 165 | { |
| 166 | { |
| 167 | rtc::CritScope cs_render(&crit_render_); |
| 168 | rtc::CritScope cs_capture(&crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 170 | public_submodules_->echo_cancellation.reset( |
| 171 | new EchoCancellationImpl(this, &crit_render_, &crit_capture_)); |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 172 | public_submodules_->echo_control_mobile.reset( |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame^] | 173 | new EchoControlMobileImpl(&crit_render_, &crit_capture_)); |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 174 | public_submodules_->gain_control.reset( |
peah | b8fbb54 | 2016-03-15 02:28:08 -0700 | [diff] [blame] | 175 | new GainControlImpl(&crit_capture_, &crit_capture_)); |
solenberg | 70f9903 | 2015-12-08 11:07:32 -0800 | [diff] [blame] | 176 | public_submodules_->high_pass_filter.reset( |
| 177 | new HighPassFilterImpl(&crit_capture_)); |
solenberg | 949028f | 2015-12-15 11:39:38 -0800 | [diff] [blame] | 178 | public_submodules_->level_estimator.reset( |
| 179 | new LevelEstimatorImpl(&crit_capture_)); |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 180 | public_submodules_->noise_suppression.reset( |
| 181 | new NoiseSuppressionImpl(&crit_capture_)); |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 182 | public_submodules_->voice_detection.reset( |
| 183 | new VoiceDetectionImpl(&crit_capture_)); |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 184 | public_submodules_->gain_control_for_experimental_agc.reset( |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 185 | new GainControlForExperimentalAgc( |
| 186 | public_submodules_->gain_control.get(), &crit_capture_)); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 187 | } |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 188 | |
andrew@webrtc.org | e84978f | 2014-01-25 02:09:06 +0000 | [diff] [blame] | 189 | SetExtraOptions(config); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | AudioProcessingImpl::~AudioProcessingImpl() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 193 | // Depends on gain_control_ and |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 194 | // public_submodules_->gain_control_for_experimental_agc. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 195 | private_submodules_->agc_manager.reset(); |
| 196 | // Depends on gain_control_. |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 197 | public_submodules_->gain_control_for_experimental_agc.reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 198 | |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 199 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 200 | if (debug_dump_.debug_file->Open()) { |
| 201 | debug_dump_.debug_file->CloseFile(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 202 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 203 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 204 | } |
| 205 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 206 | int AudioProcessingImpl::Initialize() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 207 | // Run in a single-threaded manner during initialization. |
| 208 | rtc::CritScope cs_render(&crit_render_); |
| 209 | rtc::CritScope cs_capture(&crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 210 | return InitializeLocked(); |
| 211 | } |
| 212 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 213 | int AudioProcessingImpl::Initialize(int input_sample_rate_hz, |
| 214 | int output_sample_rate_hz, |
| 215 | int reverse_sample_rate_hz, |
| 216 | ChannelLayout input_layout, |
| 217 | ChannelLayout output_layout, |
| 218 | ChannelLayout reverse_layout) { |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 219 | const ProcessingConfig processing_config = { |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 220 | {{input_sample_rate_hz, |
| 221 | ChannelsFromLayout(input_layout), |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 222 | LayoutHasKeyboard(input_layout)}, |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 223 | {output_sample_rate_hz, |
| 224 | ChannelsFromLayout(output_layout), |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 225 | LayoutHasKeyboard(output_layout)}, |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 226 | {reverse_sample_rate_hz, |
| 227 | ChannelsFromLayout(reverse_layout), |
| 228 | LayoutHasKeyboard(reverse_layout)}, |
| 229 | {reverse_sample_rate_hz, |
| 230 | ChannelsFromLayout(reverse_layout), |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 231 | LayoutHasKeyboard(reverse_layout)}}}; |
| 232 | |
| 233 | return Initialize(processing_config); |
| 234 | } |
| 235 | |
| 236 | int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 237 | // Run in a single-threaded manner during initialization. |
| 238 | rtc::CritScope cs_render(&crit_render_); |
| 239 | rtc::CritScope cs_capture(&crit_capture_); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 240 | return InitializeLocked(processing_config); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 241 | } |
| 242 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 243 | int AudioProcessingImpl::MaybeInitializeRender( |
peah | 81b9bfe | 2015-11-27 02:47:28 -0800 | [diff] [blame] | 244 | const ProcessingConfig& processing_config) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 245 | return MaybeInitialize(processing_config); |
peah | 81b9bfe | 2015-11-27 02:47:28 -0800 | [diff] [blame] | 246 | } |
| 247 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 248 | int AudioProcessingImpl::MaybeInitializeCapture( |
peah | 81b9bfe | 2015-11-27 02:47:28 -0800 | [diff] [blame] | 249 | const ProcessingConfig& processing_config) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 250 | return MaybeInitialize(processing_config); |
peah | 81b9bfe | 2015-11-27 02:47:28 -0800 | [diff] [blame] | 251 | } |
| 252 | |
peah | 192164e | 2015-11-17 02:16:45 -0800 | [diff] [blame] | 253 | // Calls InitializeLocked() if any of the audio parameters have changed from |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 254 | // their current values (needs to be called while holding the crit_render_lock). |
| 255 | int AudioProcessingImpl::MaybeInitialize( |
peah | 192164e | 2015-11-17 02:16:45 -0800 | [diff] [blame] | 256 | const ProcessingConfig& processing_config) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 257 | // Called from both threads. Thread check is therefore not possible. |
| 258 | if (processing_config == formats_.api_format) { |
peah | 192164e | 2015-11-17 02:16:45 -0800 | [diff] [blame] | 259 | return kNoError; |
| 260 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 261 | |
| 262 | rtc::CritScope cs_capture(&crit_capture_); |
peah | 192164e | 2015-11-17 02:16:45 -0800 | [diff] [blame] | 263 | return InitializeLocked(processing_config); |
| 264 | } |
| 265 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 266 | int AudioProcessingImpl::InitializeLocked() { |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 267 | const int fwd_audio_buffer_channels = |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 268 | capture_nonlocked_.beamformer_enabled |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 269 | ? formats_.api_format.input_stream().num_channels() |
| 270 | : formats_.api_format.output_stream().num_channels(); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 271 | const int rev_audio_buffer_out_num_frames = |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 272 | formats_.api_format.reverse_output_stream().num_frames() == 0 |
| 273 | ? formats_.rev_proc_format.num_frames() |
| 274 | : formats_.api_format.reverse_output_stream().num_frames(); |
| 275 | if (formats_.api_format.reverse_input_stream().num_channels() > 0) { |
| 276 | render_.render_audio.reset(new AudioBuffer( |
| 277 | formats_.api_format.reverse_input_stream().num_frames(), |
| 278 | formats_.api_format.reverse_input_stream().num_channels(), |
| 279 | formats_.rev_proc_format.num_frames(), |
| 280 | formats_.rev_proc_format.num_channels(), |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 281 | rev_audio_buffer_out_num_frames)); |
| 282 | if (rev_conversion_needed()) { |
kwiberg | c2b785d | 2016-02-24 05:22:32 -0800 | [diff] [blame] | 283 | render_.render_converter = AudioConverter::Create( |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 284 | formats_.api_format.reverse_input_stream().num_channels(), |
| 285 | formats_.api_format.reverse_input_stream().num_frames(), |
| 286 | formats_.api_format.reverse_output_stream().num_channels(), |
kwiberg | c2b785d | 2016-02-24 05:22:32 -0800 | [diff] [blame] | 287 | formats_.api_format.reverse_output_stream().num_frames()); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 288 | } else { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 289 | render_.render_converter.reset(nullptr); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 290 | } |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 291 | } else { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 292 | render_.render_audio.reset(nullptr); |
| 293 | render_.render_converter.reset(nullptr); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 294 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 295 | capture_.capture_audio.reset( |
| 296 | new AudioBuffer(formats_.api_format.input_stream().num_frames(), |
| 297 | formats_.api_format.input_stream().num_channels(), |
| 298 | capture_nonlocked_.fwd_proc_format.num_frames(), |
| 299 | fwd_audio_buffer_channels, |
| 300 | formats_.api_format.output_stream().num_frames())); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 301 | |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 302 | InitializeGainController(); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 303 | InitializeEchoCanceller(); |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 304 | InitializeEchoControlMobile(); |
Bjorn Volcker | adc46c4 | 2015-04-15 11:42:40 +0200 | [diff] [blame] | 305 | InitializeExperimentalAgc(); |
Bjorn Volcker | adc46c4 | 2015-04-15 11:42:40 +0200 | [diff] [blame] | 306 | InitializeTransient(); |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 307 | InitializeBeamformer(); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 308 | InitializeIntelligibility(); |
solenberg | 70f9903 | 2015-12-08 11:07:32 -0800 | [diff] [blame] | 309 | InitializeHighPassFilter(); |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 310 | InitializeNoiseSuppression(); |
solenberg | 949028f | 2015-12-15 11:39:38 -0800 | [diff] [blame] | 311 | InitializeLevelEstimator(); |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 312 | InitializeVoiceDetection(); |
solenberg | 70f9903 | 2015-12-08 11:07:32 -0800 | [diff] [blame] | 313 | |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 314 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 315 | if (debug_dump_.debug_file->Open()) { |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 316 | int err = WriteInitMessage(); |
| 317 | if (err != kNoError) { |
| 318 | return err; |
| 319 | } |
| 320 | } |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 321 | #endif |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 322 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 323 | return kNoError; |
| 324 | } |
| 325 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 326 | int AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) { |
| 327 | for (const auto& stream : config.streams) { |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 328 | if (stream.num_channels() > 0 && stream.sample_rate_hz() <= 0) { |
| 329 | return kBadSampleRateError; |
| 330 | } |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 331 | } |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 332 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 333 | const size_t num_in_channels = config.input_stream().num_channels(); |
| 334 | const size_t num_out_channels = config.output_stream().num_channels(); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 335 | |
| 336 | // Need at least one input channel. |
| 337 | // Need either one output channel or as many outputs as there are inputs. |
| 338 | if (num_in_channels == 0 || |
| 339 | !(num_out_channels == 1 || num_out_channels == num_in_channels)) { |
Michael Graczyk | c204754 | 2015-07-22 21:06:11 -0700 | [diff] [blame] | 340 | return kBadNumberChannelsError; |
| 341 | } |
| 342 | |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 343 | if (capture_nonlocked_.beamformer_enabled && |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 344 | num_in_channels != capture_.array_geometry.size()) { |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 345 | return kBadNumberChannelsError; |
| 346 | } |
| 347 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 348 | formats_.api_format = config; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 349 | |
perkj | dfc2870 | 2016-03-09 16:23:23 -0800 | [diff] [blame] | 350 | // We process at the closest native rate >= min(input rate, output rate)... |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 351 | const int min_proc_rate = |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 352 | std::min(formats_.api_format.input_stream().sample_rate_hz(), |
| 353 | formats_.api_format.output_stream().sample_rate_hz()); |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 354 | int fwd_proc_rate; |
Alejandro Luebs | cdfe20b | 2015-09-23 12:49:12 -0700 | [diff] [blame] | 355 | for (size_t i = 0; i < kNumNativeSampleRates; ++i) { |
| 356 | fwd_proc_rate = kNativeSampleRatesHz[i]; |
| 357 | if (fwd_proc_rate >= min_proc_rate) { |
| 358 | break; |
| 359 | } |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 360 | } |
perkj | dfc2870 | 2016-03-09 16:23:23 -0800 | [diff] [blame] | 361 | // ...with one exception. |
| 362 | if (public_submodules_->echo_control_mobile->is_enabled() && |
| 363 | min_proc_rate > kMaxAECMSampleRateHz) { |
| 364 | fwd_proc_rate = kMaxAECMSampleRateHz; |
| 365 | } |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 366 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 367 | capture_nonlocked_.fwd_proc_format = StreamConfig(fwd_proc_rate); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 368 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 369 | // We normally process the reverse stream at 16 kHz. Unless... |
| 370 | int rev_proc_rate = kSampleRate16kHz; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 371 | if (capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate8kHz) { |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 372 | // ...the forward stream is at 8 kHz. |
| 373 | rev_proc_rate = kSampleRate8kHz; |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 374 | } else { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 375 | if (formats_.api_format.reverse_input_stream().sample_rate_hz() == |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 376 | kSampleRate32kHz) { |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 377 | // ...or the input is at 32 kHz, in which case we use the splitting |
| 378 | // filter rather than the resampler. |
| 379 | rev_proc_rate = kSampleRate32kHz; |
| 380 | } |
| 381 | } |
| 382 | |
andrew@webrtc.org | 30be827 | 2014-09-24 20:06:23 +0000 | [diff] [blame] | 383 | // Always downmix the reverse stream to mono for analysis. This has been |
| 384 | // demonstrated to work well for AEC in most practical scenarios. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 385 | formats_.rev_proc_format = StreamConfig(rev_proc_rate, 1); |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 386 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 387 | if (capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate32kHz || |
| 388 | capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate48kHz) { |
| 389 | capture_nonlocked_.split_rate = kSampleRate16kHz; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 390 | } else { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 391 | capture_nonlocked_.split_rate = |
| 392 | capture_nonlocked_.fwd_proc_format.sample_rate_hz(); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | return InitializeLocked(); |
| 396 | } |
| 397 | |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 398 | void AudioProcessingImpl::SetExtraOptions(const Config& config) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 399 | // Run in a single-threaded manner when setting the extra options. |
| 400 | rtc::CritScope cs_render(&crit_render_); |
| 401 | rtc::CritScope cs_capture(&crit_capture_); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 402 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 403 | public_submodules_->echo_cancellation->SetExtraOptions(config); |
| 404 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 405 | if (capture_.transient_suppressor_enabled != |
| 406 | config.Get<ExperimentalNs>().enabled) { |
| 407 | capture_.transient_suppressor_enabled = |
| 408 | config.Get<ExperimentalNs>().enabled; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 409 | InitializeTransient(); |
| 410 | } |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 411 | |
| 412 | #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 413 | if (capture_nonlocked_.beamformer_enabled != |
| 414 | config.Get<Beamforming>().enabled) { |
| 415 | capture_nonlocked_.beamformer_enabled = config.Get<Beamforming>().enabled; |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 416 | if (config.Get<Beamforming>().array_geometry.size() > 1) { |
| 417 | capture_.array_geometry = config.Get<Beamforming>().array_geometry; |
| 418 | } |
| 419 | capture_.target_direction = config.Get<Beamforming>().target_direction; |
| 420 | InitializeBeamformer(); |
| 421 | } |
| 422 | #endif // WEBRTC_ANDROID_PLATFORM_BUILD |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 423 | } |
| 424 | |
peah | 66085be | 2015-12-16 02:02:20 -0800 | [diff] [blame] | 425 | int AudioProcessingImpl::input_sample_rate_hz() const { |
| 426 | // Accessed from outside APM, hence a lock is needed. |
| 427 | rtc::CritScope cs(&crit_capture_); |
| 428 | return formats_.api_format.input_stream().sample_rate_hz(); |
| 429 | } |
| 430 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 431 | int AudioProcessingImpl::proc_sample_rate_hz() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 432 | // Used as callback from submodules, hence locking is not allowed. |
| 433 | return capture_nonlocked_.fwd_proc_format.sample_rate_hz(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 434 | } |
| 435 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 436 | int AudioProcessingImpl::proc_split_sample_rate_hz() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 437 | // Used as callback from submodules, hence locking is not allowed. |
| 438 | return capture_nonlocked_.split_rate; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 441 | size_t AudioProcessingImpl::num_reverse_channels() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 442 | // Used as callback from submodules, hence locking is not allowed. |
| 443 | return formats_.rev_proc_format.num_channels(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 446 | size_t AudioProcessingImpl::num_input_channels() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 447 | // Used as callback from submodules, hence locking is not allowed. |
| 448 | return formats_.api_format.input_stream().num_channels(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 451 | size_t AudioProcessingImpl::num_proc_channels() const { |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 452 | // Used as callback from submodules, hence locking is not allowed. |
| 453 | return capture_nonlocked_.beamformer_enabled ? 1 : num_output_channels(); |
| 454 | } |
| 455 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 456 | size_t AudioProcessingImpl::num_output_channels() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 457 | // Used as callback from submodules, hence locking is not allowed. |
| 458 | return formats_.api_format.output_stream().num_channels(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 459 | } |
| 460 | |
andrew@webrtc.org | 17342e5 | 2014-02-12 22:28:31 +0000 | [diff] [blame] | 461 | void AudioProcessingImpl::set_output_will_be_muted(bool muted) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 462 | rtc::CritScope cs(&crit_capture_); |
| 463 | capture_.output_will_be_muted = muted; |
| 464 | if (private_submodules_->agc_manager.get()) { |
| 465 | private_submodules_->agc_manager->SetCaptureMuted( |
| 466 | capture_.output_will_be_muted); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 467 | } |
andrew@webrtc.org | 17342e5 | 2014-02-12 22:28:31 +0000 | [diff] [blame] | 468 | } |
| 469 | |
andrew@webrtc.org | 17342e5 | 2014-02-12 22:28:31 +0000 | [diff] [blame] | 470 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 471 | int AudioProcessingImpl::ProcessStream(const float* const* src, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 472 | size_t samples_per_channel, |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 473 | int input_sample_rate_hz, |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 474 | ChannelLayout input_layout, |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 475 | int output_sample_rate_hz, |
| 476 | ChannelLayout output_layout, |
| 477 | float* const* dest) { |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 478 | TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_ChannelLayout"); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 479 | StreamConfig input_stream; |
| 480 | StreamConfig output_stream; |
| 481 | { |
| 482 | // Access the formats_.api_format.input_stream beneath the capture lock. |
| 483 | // The lock must be released as it is later required in the call |
| 484 | // to ProcessStream(,,,); |
| 485 | rtc::CritScope cs(&crit_capture_); |
| 486 | input_stream = formats_.api_format.input_stream(); |
| 487 | output_stream = formats_.api_format.output_stream(); |
| 488 | } |
| 489 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 490 | input_stream.set_sample_rate_hz(input_sample_rate_hz); |
| 491 | input_stream.set_num_channels(ChannelsFromLayout(input_layout)); |
| 492 | input_stream.set_has_keyboard(LayoutHasKeyboard(input_layout)); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 493 | output_stream.set_sample_rate_hz(output_sample_rate_hz); |
| 494 | output_stream.set_num_channels(ChannelsFromLayout(output_layout)); |
| 495 | output_stream.set_has_keyboard(LayoutHasKeyboard(output_layout)); |
| 496 | |
| 497 | if (samples_per_channel != input_stream.num_frames()) { |
| 498 | return kBadDataLengthError; |
| 499 | } |
| 500 | return ProcessStream(src, input_stream, output_stream, dest); |
| 501 | } |
| 502 | |
| 503 | int AudioProcessingImpl::ProcessStream(const float* const* src, |
| 504 | const StreamConfig& input_config, |
| 505 | const StreamConfig& output_config, |
| 506 | float* const* dest) { |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 507 | TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_StreamConfig"); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 508 | ProcessingConfig processing_config; |
| 509 | { |
| 510 | // Acquire the capture lock in order to safely call the function |
| 511 | // that retrieves the render side data. This function accesses apm |
| 512 | // getters that need the capture lock held when being called. |
| 513 | rtc::CritScope cs_capture(&crit_capture_); |
| 514 | public_submodules_->echo_cancellation->ReadQueuedRenderData(); |
| 515 | public_submodules_->echo_control_mobile->ReadQueuedRenderData(); |
| 516 | public_submodules_->gain_control->ReadQueuedRenderData(); |
| 517 | |
| 518 | if (!src || !dest) { |
| 519 | return kNullPointerError; |
| 520 | } |
| 521 | |
| 522 | processing_config = formats_.api_format; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 523 | } |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 524 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 525 | processing_config.input_stream() = input_config; |
| 526 | processing_config.output_stream() = output_config; |
| 527 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 528 | { |
| 529 | // Do conditional reinitialization. |
| 530 | rtc::CritScope cs_render(&crit_render_); |
| 531 | RETURN_ON_ERR(MaybeInitializeCapture(processing_config)); |
| 532 | } |
| 533 | rtc::CritScope cs_capture(&crit_capture_); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 534 | assert(processing_config.input_stream().num_frames() == |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 535 | formats_.api_format.input_stream().num_frames()); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 536 | |
| 537 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 538 | if (debug_dump_.debug_file->Open()) { |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 539 | RETURN_ON_ERR(WriteConfigMessage(false)); |
| 540 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 541 | debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); |
| 542 | audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
aluebs@webrtc.org | 59a1b1b | 2014-08-28 10:43:09 +0000 | [diff] [blame] | 543 | const size_t channel_size = |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 544 | sizeof(float) * formats_.api_format.input_stream().num_frames(); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 545 | for (size_t i = 0; i < formats_.api_format.input_stream().num_channels(); |
| 546 | ++i) |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 547 | msg->add_input_channel(src[i], channel_size); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 548 | } |
| 549 | #endif |
| 550 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 551 | capture_.capture_audio->CopyFrom(src, formats_.api_format.input_stream()); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 552 | RETURN_ON_ERR(ProcessStreamLocked()); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 553 | capture_.capture_audio->CopyTo(formats_.api_format.output_stream(), dest); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 554 | |
| 555 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 556 | if (debug_dump_.debug_file->Open()) { |
| 557 | audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
aluebs@webrtc.org | 59a1b1b | 2014-08-28 10:43:09 +0000 | [diff] [blame] | 558 | const size_t channel_size = |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 559 | sizeof(float) * formats_.api_format.output_stream().num_frames(); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 560 | for (size_t i = 0; i < formats_.api_format.output_stream().num_channels(); |
| 561 | ++i) |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 562 | msg->add_output_channel(dest[i], channel_size); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 563 | RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 564 | &debug_dump_.num_bytes_left_for_log_, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 565 | &crit_debug_, &debug_dump_.capture)); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 566 | } |
| 567 | #endif |
| 568 | |
| 569 | return kNoError; |
| 570 | } |
| 571 | |
| 572 | int AudioProcessingImpl::ProcessStream(AudioFrame* frame) { |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 573 | TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_AudioFrame"); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 574 | { |
| 575 | // Acquire the capture lock in order to safely call the function |
| 576 | // that retrieves the render side data. This function accesses apm |
| 577 | // getters that need the capture lock held when being called. |
| 578 | // The lock needs to be released as |
| 579 | // public_submodules_->echo_control_mobile->is_enabled() aquires this lock |
| 580 | // as well. |
| 581 | rtc::CritScope cs_capture(&crit_capture_); |
| 582 | public_submodules_->echo_cancellation->ReadQueuedRenderData(); |
| 583 | public_submodules_->echo_control_mobile->ReadQueuedRenderData(); |
| 584 | public_submodules_->gain_control->ReadQueuedRenderData(); |
| 585 | } |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 586 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 587 | if (!frame) { |
| 588 | return kNullPointerError; |
| 589 | } |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 590 | // Must be a native rate. |
| 591 | if (frame->sample_rate_hz_ != kSampleRate8kHz && |
| 592 | frame->sample_rate_hz_ != kSampleRate16kHz && |
aluebs@webrtc.org | 087da13 | 2014-11-17 23:01:23 +0000 | [diff] [blame] | 593 | frame->sample_rate_hz_ != kSampleRate32kHz && |
| 594 | frame->sample_rate_hz_ != kSampleRate48kHz) { |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 595 | return kBadSampleRateError; |
| 596 | } |
peah | 192164e | 2015-11-17 02:16:45 -0800 | [diff] [blame] | 597 | |
perkj | dfc2870 | 2016-03-09 16:23:23 -0800 | [diff] [blame] | 598 | if (public_submodules_->echo_control_mobile->is_enabled() && |
| 599 | frame->sample_rate_hz_ > kMaxAECMSampleRateHz) { |
| 600 | LOG(LS_ERROR) << "AECM only supports 16 or 8 kHz sample rates"; |
| 601 | return kUnsupportedComponentError; |
| 602 | } |
| 603 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 604 | ProcessingConfig processing_config; |
| 605 | { |
| 606 | // Aquire lock for the access of api_format. |
| 607 | // The lock is released immediately due to the conditional |
| 608 | // reinitialization. |
| 609 | rtc::CritScope cs_capture(&crit_capture_); |
| 610 | // TODO(ajm): The input and output rates and channels are currently |
| 611 | // constrained to be identical in the int16 interface. |
| 612 | processing_config = formats_.api_format; |
| 613 | } |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 614 | processing_config.input_stream().set_sample_rate_hz(frame->sample_rate_hz_); |
| 615 | processing_config.input_stream().set_num_channels(frame->num_channels_); |
| 616 | processing_config.output_stream().set_sample_rate_hz(frame->sample_rate_hz_); |
| 617 | processing_config.output_stream().set_num_channels(frame->num_channels_); |
| 618 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 619 | { |
| 620 | // Do conditional reinitialization. |
| 621 | rtc::CritScope cs_render(&crit_render_); |
| 622 | RETURN_ON_ERR(MaybeInitializeCapture(processing_config)); |
| 623 | } |
| 624 | rtc::CritScope cs_capture(&crit_capture_); |
peah | 192164e | 2015-11-17 02:16:45 -0800 | [diff] [blame] | 625 | if (frame->samples_per_channel_ != |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 626 | formats_.api_format.input_stream().num_frames()) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 627 | return kBadDataLengthError; |
| 628 | } |
| 629 | |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 630 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 631 | if (debug_dump_.debug_file->Open()) { |
| 632 | debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); |
| 633 | audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 634 | const size_t data_size = |
| 635 | sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 636 | msg->set_input_data(frame->data_, data_size); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 637 | } |
| 638 | #endif |
| 639 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 640 | capture_.capture_audio->DeinterleaveFrom(frame); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 641 | RETURN_ON_ERR(ProcessStreamLocked()); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 642 | capture_.capture_audio->InterleaveTo(frame, |
| 643 | output_copy_needed(is_data_processed())); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 644 | |
| 645 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 646 | if (debug_dump_.debug_file->Open()) { |
| 647 | audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 648 | const size_t data_size = |
| 649 | sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 650 | msg->set_output_data(frame->data_, data_size); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 651 | RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 652 | &debug_dump_.num_bytes_left_for_log_, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 653 | &crit_debug_, &debug_dump_.capture)); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 654 | } |
| 655 | #endif |
| 656 | |
| 657 | return kNoError; |
| 658 | } |
| 659 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 660 | int AudioProcessingImpl::ProcessStreamLocked() { |
| 661 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 662 | if (debug_dump_.debug_file->Open()) { |
| 663 | audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
| 664 | msg->set_delay(capture_nonlocked_.stream_delay_ms); |
| 665 | msg->set_drift( |
| 666 | public_submodules_->echo_cancellation->stream_drift_samples()); |
bjornv@webrtc.org | 63da1dd | 2015-02-06 19:44:21 +0000 | [diff] [blame] | 667 | msg->set_level(gain_control()->stream_analog_level()); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 668 | msg->set_keypress(capture_.key_pressed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 669 | } |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 670 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 671 | |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 672 | MaybeUpdateHistograms(); |
| 673 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 674 | AudioBuffer* ca = capture_.capture_audio.get(); // For brevity. |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 675 | |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 676 | if (constants_.use_experimental_agc && |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 677 | public_submodules_->gain_control->is_enabled()) { |
| 678 | private_submodules_->agc_manager->AnalyzePreProcess( |
| 679 | ca->channels()[0], ca->num_channels(), |
| 680 | capture_nonlocked_.fwd_proc_format.num_frames()); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 681 | } |
| 682 | |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 683 | bool data_processed = is_data_processed(); |
| 684 | if (analysis_needed(data_processed)) { |
aluebs@webrtc.org | be05c74 | 2014-11-14 22:18:10 +0000 | [diff] [blame] | 685 | ca->SplitIntoFrequencyBands(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 686 | } |
| 687 | |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 688 | if (capture_nonlocked_.beamformer_enabled) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 689 | private_submodules_->beamformer->ProcessChunk(*ca->split_data_f(), |
| 690 | ca->split_data_f()); |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 691 | ca->set_num_channels(1); |
| 692 | } |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 693 | |
solenberg | 70f9903 | 2015-12-08 11:07:32 -0800 | [diff] [blame] | 694 | public_submodules_->high_pass_filter->ProcessCaptureAudio(ca); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 695 | RETURN_ON_ERR(public_submodules_->gain_control->AnalyzeCaptureAudio(ca)); |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 696 | public_submodules_->noise_suppression->AnalyzeCaptureAudio(ca); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 697 | RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessCaptureAudio(ca)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 698 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 699 | if (public_submodules_->echo_control_mobile->is_enabled() && |
| 700 | public_submodules_->noise_suppression->is_enabled()) { |
andrew@webrtc.org | 103657b | 2014-04-24 18:28:56 +0000 | [diff] [blame] | 701 | ca->CopyLowPassToReference(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 702 | } |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 703 | public_submodules_->noise_suppression->ProcessCaptureAudio(ca); |
aluebs | c466bad | 2016-02-10 12:03:00 -0800 | [diff] [blame] | 704 | if (constants_.intelligibility_enabled) { |
| 705 | RTC_DCHECK(public_submodules_->noise_suppression->is_enabled()); |
| 706 | public_submodules_->intelligibility_enhancer->SetCaptureNoiseEstimate( |
| 707 | public_submodules_->noise_suppression->NoiseEstimate()); |
| 708 | } |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame^] | 709 | |
| 710 | // Ensure that the stream delay was set before the call to the |
| 711 | // AECM ProcessCaptureAudio function. |
| 712 | if (public_submodules_->echo_control_mobile->is_enabled() && |
| 713 | !was_stream_delay_set()) { |
| 714 | return AudioProcessing::kStreamParameterNotSetError; |
| 715 | } |
| 716 | |
| 717 | RETURN_ON_ERR(public_submodules_->echo_control_mobile->ProcessCaptureAudio( |
| 718 | ca, stream_delay_ms())); |
| 719 | |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 720 | public_submodules_->voice_detection->ProcessCaptureAudio(ca); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 721 | |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 722 | if (constants_.use_experimental_agc && |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 723 | public_submodules_->gain_control->is_enabled() && |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 724 | (!capture_nonlocked_.beamformer_enabled || |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 725 | private_submodules_->beamformer->is_target_present())) { |
| 726 | private_submodules_->agc_manager->Process( |
| 727 | ca->split_bands_const(0)[kBand0To8kHz], ca->num_frames_per_band(), |
| 728 | capture_nonlocked_.split_rate); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 729 | } |
peah | b8fbb54 | 2016-03-15 02:28:08 -0700 | [diff] [blame] | 730 | RETURN_ON_ERR(public_submodules_->gain_control->ProcessCaptureAudio( |
| 731 | ca, echo_cancellation()->stream_has_echo())); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 732 | |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 733 | if (synthesis_needed(data_processed)) { |
aluebs@webrtc.org | be05c74 | 2014-11-14 22:18:10 +0000 | [diff] [blame] | 734 | ca->MergeFrequencyBands(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 735 | } |
| 736 | |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 737 | // TODO(aluebs): Investigate if the transient suppression placement should be |
| 738 | // before or after the AGC. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 739 | if (capture_.transient_suppressor_enabled) { |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 740 | float voice_probability = |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 741 | private_submodules_->agc_manager.get() |
| 742 | ? private_submodules_->agc_manager->voice_probability() |
| 743 | : 1.f; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 744 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 745 | public_submodules_->transient_suppressor->Suppress( |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 746 | ca->channels_f()[0], ca->num_frames(), ca->num_channels(), |
| 747 | ca->split_bands_const_f(0)[kBand0To8kHz], ca->num_frames_per_band(), |
| 748 | ca->keyboard_data(), ca->num_keyboard_frames(), voice_probability, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 749 | capture_.key_pressed); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 750 | } |
| 751 | |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 752 | // The level estimator operates on the recombined data. |
solenberg | 949028f | 2015-12-15 11:39:38 -0800 | [diff] [blame] | 753 | public_submodules_->level_estimator->ProcessStream(ca); |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 754 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 755 | capture_.was_stream_delay_set = false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 756 | return kNoError; |
| 757 | } |
| 758 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 759 | int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 760 | size_t samples_per_channel, |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 761 | int rev_sample_rate_hz, |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 762 | ChannelLayout layout) { |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 763 | TRACE_EVENT0("webrtc", "AudioProcessing::AnalyzeReverseStream_ChannelLayout"); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 764 | rtc::CritScope cs(&crit_render_); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 765 | const StreamConfig reverse_config = { |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 766 | rev_sample_rate_hz, ChannelsFromLayout(layout), LayoutHasKeyboard(layout), |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 767 | }; |
| 768 | if (samples_per_channel != reverse_config.num_frames()) { |
| 769 | return kBadDataLengthError; |
| 770 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 771 | return AnalyzeReverseStreamLocked(data, reverse_config, reverse_config); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | int AudioProcessingImpl::ProcessReverseStream( |
| 775 | const float* const* src, |
| 776 | const StreamConfig& reverse_input_config, |
| 777 | const StreamConfig& reverse_output_config, |
| 778 | float* const* dest) { |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 779 | TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_StreamConfig"); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 780 | rtc::CritScope cs(&crit_render_); |
| 781 | RETURN_ON_ERR(AnalyzeReverseStreamLocked(src, reverse_input_config, |
| 782 | reverse_output_config)); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 783 | if (is_rev_processed()) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 784 | render_.render_audio->CopyTo(formats_.api_format.reverse_output_stream(), |
| 785 | dest); |
peah | 81b9bfe | 2015-11-27 02:47:28 -0800 | [diff] [blame] | 786 | } else if (render_check_rev_conversion_needed()) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 787 | render_.render_converter->Convert(src, reverse_input_config.num_samples(), |
| 788 | dest, |
| 789 | reverse_output_config.num_samples()); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 790 | } else { |
| 791 | CopyAudioIfNeeded(src, reverse_input_config.num_frames(), |
| 792 | reverse_input_config.num_channels(), dest); |
| 793 | } |
| 794 | |
| 795 | return kNoError; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 796 | } |
| 797 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 798 | int AudioProcessingImpl::AnalyzeReverseStreamLocked( |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 799 | const float* const* src, |
| 800 | const StreamConfig& reverse_input_config, |
| 801 | const StreamConfig& reverse_output_config) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 802 | if (src == nullptr) { |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 803 | return kNullPointerError; |
| 804 | } |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 805 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 806 | if (reverse_input_config.num_channels() == 0) { |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 807 | return kBadNumberChannelsError; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 808 | } |
| 809 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 810 | ProcessingConfig processing_config = formats_.api_format; |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 811 | processing_config.reverse_input_stream() = reverse_input_config; |
| 812 | processing_config.reverse_output_stream() = reverse_output_config; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 813 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 814 | RETURN_ON_ERR(MaybeInitializeRender(processing_config)); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 815 | assert(reverse_input_config.num_frames() == |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 816 | formats_.api_format.reverse_input_stream().num_frames()); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 817 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 818 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 819 | if (debug_dump_.debug_file->Open()) { |
| 820 | debug_dump_.render.event_msg->set_type(audioproc::Event::REVERSE_STREAM); |
| 821 | audioproc::ReverseStream* msg = |
| 822 | debug_dump_.render.event_msg->mutable_reverse_stream(); |
aluebs@webrtc.org | 59a1b1b | 2014-08-28 10:43:09 +0000 | [diff] [blame] | 823 | const size_t channel_size = |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 824 | sizeof(float) * formats_.api_format.reverse_input_stream().num_frames(); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 825 | for (size_t i = 0; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 826 | i < formats_.api_format.reverse_input_stream().num_channels(); ++i) |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 827 | msg->add_channel(src[i], channel_size); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 828 | RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 829 | &debug_dump_.num_bytes_left_for_log_, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 830 | &crit_debug_, &debug_dump_.render)); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 831 | } |
| 832 | #endif |
| 833 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 834 | render_.render_audio->CopyFrom(src, |
| 835 | formats_.api_format.reverse_input_stream()); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 836 | return ProcessReverseStreamLocked(); |
| 837 | } |
| 838 | |
| 839 | int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) { |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 840 | TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_AudioFrame"); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 841 | RETURN_ON_ERR(AnalyzeReverseStream(frame)); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 842 | rtc::CritScope cs(&crit_render_); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 843 | if (is_rev_processed()) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 844 | render_.render_audio->InterleaveTo(frame, true); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | return kNoError; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 848 | } |
| 849 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 850 | int AudioProcessingImpl::AnalyzeReverseStream(AudioFrame* frame) { |
peah | 369f828 | 2015-12-17 06:42:29 -0800 | [diff] [blame] | 851 | TRACE_EVENT0("webrtc", "AudioProcessing::AnalyzeReverseStream_AudioFrame"); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 852 | rtc::CritScope cs(&crit_render_); |
| 853 | if (frame == nullptr) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 854 | return kNullPointerError; |
| 855 | } |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 856 | // Must be a native rate. |
| 857 | if (frame->sample_rate_hz_ != kSampleRate8kHz && |
| 858 | frame->sample_rate_hz_ != kSampleRate16kHz && |
aluebs@webrtc.org | 087da13 | 2014-11-17 23:01:23 +0000 | [diff] [blame] | 859 | frame->sample_rate_hz_ != kSampleRate32kHz && |
| 860 | frame->sample_rate_hz_ != kSampleRate48kHz) { |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 861 | return kBadSampleRateError; |
| 862 | } |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 863 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 864 | if (frame->num_channels_ <= 0) { |
| 865 | return kBadNumberChannelsError; |
| 866 | } |
| 867 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 868 | ProcessingConfig processing_config = formats_.api_format; |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 869 | processing_config.reverse_input_stream().set_sample_rate_hz( |
| 870 | frame->sample_rate_hz_); |
| 871 | processing_config.reverse_input_stream().set_num_channels( |
| 872 | frame->num_channels_); |
| 873 | processing_config.reverse_output_stream().set_sample_rate_hz( |
| 874 | frame->sample_rate_hz_); |
| 875 | processing_config.reverse_output_stream().set_num_channels( |
| 876 | frame->num_channels_); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 877 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 878 | RETURN_ON_ERR(MaybeInitializeRender(processing_config)); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 879 | if (frame->samples_per_channel_ != |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 880 | formats_.api_format.reverse_input_stream().num_frames()) { |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 881 | return kBadDataLengthError; |
| 882 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 883 | |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 884 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 885 | if (debug_dump_.debug_file->Open()) { |
| 886 | debug_dump_.render.event_msg->set_type(audioproc::Event::REVERSE_STREAM); |
| 887 | audioproc::ReverseStream* msg = |
| 888 | debug_dump_.render.event_msg->mutable_reverse_stream(); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 889 | const size_t data_size = |
| 890 | sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 891 | msg->set_data(frame->data_, data_size); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 892 | RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 893 | &debug_dump_.num_bytes_left_for_log_, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 894 | &crit_debug_, &debug_dump_.render)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 895 | } |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 896 | #endif |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 897 | render_.render_audio->DeinterleaveFrom(frame); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 898 | return ProcessReverseStreamLocked(); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 899 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 900 | |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 901 | int AudioProcessingImpl::ProcessReverseStreamLocked() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 902 | AudioBuffer* ra = render_.render_audio.get(); // For brevity. |
| 903 | if (formats_.rev_proc_format.sample_rate_hz() == kSampleRate32kHz) { |
aluebs@webrtc.org | be05c74 | 2014-11-14 22:18:10 +0000 | [diff] [blame] | 904 | ra->SplitIntoFrequencyBands(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 905 | } |
| 906 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 907 | if (constants_.intelligibility_enabled) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 908 | public_submodules_->intelligibility_enhancer->ProcessRenderAudio( |
| 909 | ra->split_channels_f(kBand0To8kHz), capture_nonlocked_.split_rate, |
| 910 | ra->num_channels()); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 911 | } |
| 912 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 913 | RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessRenderAudio(ra)); |
| 914 | RETURN_ON_ERR( |
| 915 | public_submodules_->echo_control_mobile->ProcessRenderAudio(ra)); |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 916 | if (!constants_.use_experimental_agc) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 917 | RETURN_ON_ERR(public_submodules_->gain_control->ProcessRenderAudio(ra)); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 918 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 919 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 920 | if (formats_.rev_proc_format.sample_rate_hz() == kSampleRate32kHz && |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 921 | is_rev_processed()) { |
| 922 | ra->MergeFrequencyBands(); |
| 923 | } |
| 924 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 925 | return kNoError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | int AudioProcessingImpl::set_stream_delay_ms(int delay) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 929 | rtc::CritScope cs(&crit_capture_); |
andrew@webrtc.org | 5f23d64 | 2012-05-29 21:14:06 +0000 | [diff] [blame] | 930 | Error retval = kNoError; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 931 | capture_.was_stream_delay_set = true; |
| 932 | delay += capture_.delay_offset_ms; |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 933 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 934 | if (delay < 0) { |
andrew@webrtc.org | 5f23d64 | 2012-05-29 21:14:06 +0000 | [diff] [blame] | 935 | delay = 0; |
| 936 | retval = kBadStreamParameterWarning; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | // TODO(ajm): the max is rather arbitrarily chosen; investigate. |
| 940 | if (delay > 500) { |
andrew@webrtc.org | 5f23d64 | 2012-05-29 21:14:06 +0000 | [diff] [blame] | 941 | delay = 500; |
| 942 | retval = kBadStreamParameterWarning; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 943 | } |
| 944 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 945 | capture_nonlocked_.stream_delay_ms = delay; |
andrew@webrtc.org | 5f23d64 | 2012-05-29 21:14:06 +0000 | [diff] [blame] | 946 | return retval; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | int AudioProcessingImpl::stream_delay_ms() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 950 | // Used as callback from submodules, hence locking is not allowed. |
| 951 | return capture_nonlocked_.stream_delay_ms; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | bool AudioProcessingImpl::was_stream_delay_set() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 955 | // Used as callback from submodules, hence locking is not allowed. |
| 956 | return capture_.was_stream_delay_set; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 957 | } |
| 958 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 959 | void AudioProcessingImpl::set_stream_key_pressed(bool key_pressed) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 960 | rtc::CritScope cs(&crit_capture_); |
| 961 | capture_.key_pressed = key_pressed; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 962 | } |
| 963 | |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 964 | void AudioProcessingImpl::set_delay_offset_ms(int offset) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 965 | rtc::CritScope cs(&crit_capture_); |
| 966 | capture_.delay_offset_ms = offset; |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | int AudioProcessingImpl::delay_offset_ms() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 970 | rtc::CritScope cs(&crit_capture_); |
| 971 | return capture_.delay_offset_ms; |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 972 | } |
| 973 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 974 | int AudioProcessingImpl::StartDebugRecording( |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 975 | const char filename[AudioProcessing::kMaxFilenameSize], |
| 976 | int64_t max_log_size_bytes) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 977 | // Run in a single-threaded manner. |
| 978 | rtc::CritScope cs_render(&crit_render_); |
| 979 | rtc::CritScope cs_capture(&crit_capture_); |
André Susano Pinto | 664cdaf | 2015-05-20 11:11:07 +0200 | [diff] [blame] | 980 | static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, ""); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 981 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 982 | if (filename == nullptr) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 983 | return kNullPointerError; |
| 984 | } |
| 985 | |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 986 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 987 | debug_dump_.num_bytes_left_for_log_ = max_log_size_bytes; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 988 | // Stop any ongoing recording. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 989 | if (debug_dump_.debug_file->Open()) { |
| 990 | if (debug_dump_.debug_file->CloseFile() == -1) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 991 | return kFileError; |
| 992 | } |
| 993 | } |
| 994 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 995 | if (debug_dump_.debug_file->OpenFile(filename, false) == -1) { |
| 996 | debug_dump_.debug_file->CloseFile(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 997 | return kFileError; |
| 998 | } |
| 999 | |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1000 | RETURN_ON_ERR(WriteConfigMessage(true)); |
| 1001 | RETURN_ON_ERR(WriteInitMessage()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1002 | return kNoError; |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 1003 | #else |
| 1004 | return kUnsupportedFunctionError; |
| 1005 | #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 1008 | int AudioProcessingImpl::StartDebugRecording(FILE* handle, |
| 1009 | int64_t max_log_size_bytes) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1010 | // Run in a single-threaded manner. |
| 1011 | rtc::CritScope cs_render(&crit_render_); |
| 1012 | rtc::CritScope cs_capture(&crit_capture_); |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 1013 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1014 | if (handle == nullptr) { |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 1015 | return kNullPointerError; |
| 1016 | } |
| 1017 | |
| 1018 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 1019 | debug_dump_.num_bytes_left_for_log_ = max_log_size_bytes; |
| 1020 | |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 1021 | // Stop any ongoing recording. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1022 | if (debug_dump_.debug_file->Open()) { |
| 1023 | if (debug_dump_.debug_file->CloseFile() == -1) { |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 1024 | return kFileError; |
| 1025 | } |
| 1026 | } |
| 1027 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1028 | if (debug_dump_.debug_file->OpenFromFileHandle(handle, true, false) == -1) { |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 1029 | return kFileError; |
| 1030 | } |
| 1031 | |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1032 | RETURN_ON_ERR(WriteConfigMessage(true)); |
| 1033 | RETURN_ON_ERR(WriteInitMessage()); |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 1034 | return kNoError; |
| 1035 | #else |
| 1036 | return kUnsupportedFunctionError; |
| 1037 | #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1038 | } |
| 1039 | |
xians@webrtc.org | e46bc77 | 2014-10-10 08:36:56 +0000 | [diff] [blame] | 1040 | int AudioProcessingImpl::StartDebugRecordingForPlatformFile( |
| 1041 | rtc::PlatformFile handle) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1042 | // Run in a single-threaded manner. |
| 1043 | rtc::CritScope cs_render(&crit_render_); |
| 1044 | rtc::CritScope cs_capture(&crit_capture_); |
xians@webrtc.org | e46bc77 | 2014-10-10 08:36:56 +0000 | [diff] [blame] | 1045 | FILE* stream = rtc::FdopenPlatformFileForWriting(handle); |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 1046 | return StartDebugRecording(stream, -1); |
xians@webrtc.org | e46bc77 | 2014-10-10 08:36:56 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1049 | int AudioProcessingImpl::StopDebugRecording() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1050 | // Run in a single-threaded manner. |
| 1051 | rtc::CritScope cs_render(&crit_render_); |
| 1052 | rtc::CritScope cs_capture(&crit_capture_); |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 1053 | |
| 1054 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1055 | // We just return if recording hasn't started. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1056 | if (debug_dump_.debug_file->Open()) { |
| 1057 | if (debug_dump_.debug_file->CloseFile() == -1) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1058 | return kFileError; |
| 1059 | } |
| 1060 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1061 | return kNoError; |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 1062 | #else |
| 1063 | return kUnsupportedFunctionError; |
| 1064 | #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | EchoCancellation* AudioProcessingImpl::echo_cancellation() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1068 | // Adding a lock here has no effect as it allows any access to the submodule |
| 1069 | // from the returned pointer. |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 1070 | return public_submodules_->echo_cancellation.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | EchoControlMobile* AudioProcessingImpl::echo_control_mobile() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1074 | // Adding a lock here has no effect as it allows any access to the submodule |
| 1075 | // from the returned pointer. |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 1076 | return public_submodules_->echo_control_mobile.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | GainControl* AudioProcessingImpl::gain_control() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1080 | // Adding a lock here has no effect as it allows any access to the submodule |
| 1081 | // from the returned pointer. |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 1082 | if (constants_.use_experimental_agc) { |
| 1083 | return public_submodules_->gain_control_for_experimental_agc.get(); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1084 | } |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 1085 | return public_submodules_->gain_control.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | HighPassFilter* AudioProcessingImpl::high_pass_filter() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1089 | // Adding a lock here has no effect as it allows any access to the submodule |
| 1090 | // from the returned pointer. |
solenberg | 70f9903 | 2015-12-08 11:07:32 -0800 | [diff] [blame] | 1091 | return public_submodules_->high_pass_filter.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | LevelEstimator* AudioProcessingImpl::level_estimator() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1095 | // Adding a lock here has no effect as it allows any access to the submodule |
| 1096 | // from the returned pointer. |
solenberg | 949028f | 2015-12-15 11:39:38 -0800 | [diff] [blame] | 1097 | return public_submodules_->level_estimator.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | NoiseSuppression* AudioProcessingImpl::noise_suppression() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1101 | // Adding a lock here has no effect as it allows any access to the submodule |
| 1102 | // from the returned pointer. |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 1103 | return public_submodules_->noise_suppression.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | VoiceDetection* AudioProcessingImpl::voice_detection() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1107 | // Adding a lock here has no effect as it allows any access to the submodule |
| 1108 | // from the returned pointer. |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 1109 | return public_submodules_->voice_detection.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 1112 | bool AudioProcessingImpl::is_data_processed() const { |
peah | 253d8fa | 2016-02-22 02:00:09 -0800 | [diff] [blame] | 1113 | // The beamformer, noise suppressor and highpass filter |
| 1114 | // modify the data. |
| 1115 | if (capture_nonlocked_.beamformer_enabled || |
| 1116 | public_submodules_->high_pass_filter->is_enabled() || |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 1117 | public_submodules_->noise_suppression->is_enabled() || |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 1118 | public_submodules_->echo_cancellation->is_enabled() || |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 1119 | public_submodules_->echo_control_mobile->is_enabled() || |
| 1120 | public_submodules_->gain_control->is_enabled()) { |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 1121 | return true; |
| 1122 | } |
| 1123 | |
peah | 253d8fa | 2016-02-22 02:00:09 -0800 | [diff] [blame] | 1124 | // The capture data is otherwise unchanged. |
| 1125 | return false; |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1128 | bool AudioProcessingImpl::output_copy_needed(bool is_data_processed) const { |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 1129 | // Check if we've upmixed or downmixed the audio. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1130 | return ((formats_.api_format.output_stream().num_channels() != |
| 1131 | formats_.api_format.input_stream().num_channels()) || |
| 1132 | is_data_processed || capture_.transient_suppressor_enabled); |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 1135 | bool AudioProcessingImpl::synthesis_needed(bool is_data_processed) const { |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1136 | return (is_data_processed && |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1137 | (capture_nonlocked_.fwd_proc_format.sample_rate_hz() == |
| 1138 | kSampleRate32kHz || |
| 1139 | capture_nonlocked_.fwd_proc_format.sample_rate_hz() == |
| 1140 | kSampleRate48kHz)); |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | bool AudioProcessingImpl::analysis_needed(bool is_data_processed) const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1144 | if (!is_data_processed && |
| 1145 | !public_submodules_->voice_detection->is_enabled() && |
| 1146 | !capture_.transient_suppressor_enabled) { |
| 1147 | // Only public_submodules_->level_estimator is enabled. |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 1148 | return false; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1149 | } else if (capture_nonlocked_.fwd_proc_format.sample_rate_hz() == |
| 1150 | kSampleRate32kHz || |
| 1151 | capture_nonlocked_.fwd_proc_format.sample_rate_hz() == |
| 1152 | kSampleRate48kHz) { |
| 1153 | // Something besides public_submodules_->level_estimator is enabled, and we |
| 1154 | // have super-wb. |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 1155 | return true; |
| 1156 | } |
| 1157 | return false; |
| 1158 | } |
| 1159 | |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1160 | bool AudioProcessingImpl::is_rev_processed() const { |
Alejandro Luebs | 18fcbcf | 2016-02-22 15:57:38 -0800 | [diff] [blame] | 1161 | return constants_.intelligibility_enabled; |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
peah | 81b9bfe | 2015-11-27 02:47:28 -0800 | [diff] [blame] | 1164 | bool AudioProcessingImpl::render_check_rev_conversion_needed() const { |
| 1165 | return rev_conversion_needed(); |
| 1166 | } |
| 1167 | |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1168 | bool AudioProcessingImpl::rev_conversion_needed() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1169 | return (formats_.api_format.reverse_input_stream() != |
| 1170 | formats_.api_format.reverse_output_stream()); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Bjorn Volcker | adc46c4 | 2015-04-15 11:42:40 +0200 | [diff] [blame] | 1173 | void AudioProcessingImpl::InitializeExperimentalAgc() { |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 1174 | if (constants_.use_experimental_agc) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1175 | if (!private_submodules_->agc_manager.get()) { |
| 1176 | private_submodules_->agc_manager.reset(new AgcManagerDirect( |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 1177 | public_submodules_->gain_control.get(), |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 1178 | public_submodules_->gain_control_for_experimental_agc.get(), |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1179 | constants_.agc_startup_min_volume)); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1180 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1181 | private_submodules_->agc_manager->Initialize(); |
| 1182 | private_submodules_->agc_manager->SetCaptureMuted( |
| 1183 | capture_.output_will_be_muted); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1184 | } |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
Bjorn Volcker | adc46c4 | 2015-04-15 11:42:40 +0200 | [diff] [blame] | 1187 | void AudioProcessingImpl::InitializeTransient() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1188 | if (capture_.transient_suppressor_enabled) { |
| 1189 | if (!public_submodules_->transient_suppressor.get()) { |
| 1190 | public_submodules_->transient_suppressor.reset(new TransientSuppressor()); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1191 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1192 | public_submodules_->transient_suppressor->Initialize( |
| 1193 | capture_nonlocked_.fwd_proc_format.sample_rate_hz(), |
| 1194 | capture_nonlocked_.split_rate, |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 1195 | num_proc_channels()); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1196 | } |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 1199 | void AudioProcessingImpl::InitializeBeamformer() { |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 1200 | if (capture_nonlocked_.beamformer_enabled) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1201 | if (!private_submodules_->beamformer) { |
| 1202 | private_submodules_->beamformer.reset(new NonlinearBeamformer( |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 1203 | capture_.array_geometry, capture_.target_direction)); |
aluebs@webrtc.org | d82f55d | 2015-01-15 18:07:21 +0000 | [diff] [blame] | 1204 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1205 | private_submodules_->beamformer->Initialize(kChunkSizeMs, |
| 1206 | capture_nonlocked_.split_rate); |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 1207 | } |
| 1208 | } |
| 1209 | |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1210 | void AudioProcessingImpl::InitializeIntelligibility() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1211 | if (constants_.intelligibility_enabled) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1212 | public_submodules_->intelligibility_enhancer.reset( |
Alejandro Luebs | 18fcbcf | 2016-02-22 15:57:38 -0800 | [diff] [blame] | 1213 | new IntelligibilityEnhancer(capture_nonlocked_.split_rate, |
Alex Luebs | 57ae829 | 2016-03-09 16:24:34 +0100 | [diff] [blame] | 1214 | render_.render_audio->num_channels(), |
| 1215 | NoiseSuppressionImpl::num_noise_bins())); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 1216 | } |
| 1217 | } |
| 1218 | |
solenberg | 70f9903 | 2015-12-08 11:07:32 -0800 | [diff] [blame] | 1219 | void AudioProcessingImpl::InitializeHighPassFilter() { |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 1220 | public_submodules_->high_pass_filter->Initialize(num_proc_channels(), |
solenberg | 70f9903 | 2015-12-08 11:07:32 -0800 | [diff] [blame] | 1221 | proc_sample_rate_hz()); |
| 1222 | } |
| 1223 | |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 1224 | void AudioProcessingImpl::InitializeNoiseSuppression() { |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 1225 | public_submodules_->noise_suppression->Initialize(num_proc_channels(), |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 1226 | proc_sample_rate_hz()); |
| 1227 | } |
| 1228 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 1229 | void AudioProcessingImpl::InitializeEchoCanceller() { |
| 1230 | public_submodules_->echo_cancellation->Initialize(); |
| 1231 | } |
| 1232 | |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 1233 | void AudioProcessingImpl::InitializeGainController() { |
peah | b8fbb54 | 2016-03-15 02:28:08 -0700 | [diff] [blame] | 1234 | public_submodules_->gain_control->Initialize(num_proc_channels(), |
| 1235 | proc_sample_rate_hz()); |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 1236 | } |
| 1237 | |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 1238 | void AudioProcessingImpl::InitializeEchoControlMobile() { |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame^] | 1239 | public_submodules_->echo_control_mobile->Initialize( |
| 1240 | proc_sample_rate_hz(), num_reverse_channels(), num_output_channels()); |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 1241 | } |
| 1242 | |
solenberg | 949028f | 2015-12-15 11:39:38 -0800 | [diff] [blame] | 1243 | void AudioProcessingImpl::InitializeLevelEstimator() { |
| 1244 | public_submodules_->level_estimator->Initialize(); |
| 1245 | } |
| 1246 | |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 1247 | void AudioProcessingImpl::InitializeVoiceDetection() { |
| 1248 | public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz()); |
| 1249 | } |
| 1250 | |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1251 | void AudioProcessingImpl::MaybeUpdateHistograms() { |
Bjorn Volcker | d92f267 | 2015-07-05 10:46:01 +0200 | [diff] [blame] | 1252 | static const int kMinDiffDelayMs = 60; |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1253 | |
| 1254 | if (echo_cancellation()->is_enabled()) { |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1255 | // Activate delay_jumps_ counters if we know echo_cancellation is runnning. |
| 1256 | // 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] | 1257 | if (capture_.stream_delay_jumps == -1 && |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1258 | echo_cancellation()->stream_has_echo()) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1259 | capture_.stream_delay_jumps = 0; |
| 1260 | } |
| 1261 | if (capture_.aec_system_delay_jumps == -1 && |
| 1262 | echo_cancellation()->stream_has_echo()) { |
| 1263 | capture_.aec_system_delay_jumps = 0; |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1264 | } |
| 1265 | |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1266 | // Detect a jump in platform reported system delay and log the difference. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1267 | const int diff_stream_delay_ms = |
| 1268 | capture_nonlocked_.stream_delay_ms - capture_.last_stream_delay_ms; |
| 1269 | if (diff_stream_delay_ms > kMinDiffDelayMs && |
| 1270 | capture_.last_stream_delay_ms != 0) { |
asapersson | a2c58e2 | 2016-03-07 01:52:59 -0800 | [diff] [blame] | 1271 | RTC_HISTOGRAM_COUNTS("WebRTC.Audio.PlatformReportedStreamDelayJump", |
| 1272 | diff_stream_delay_ms, kMinDiffDelayMs, 1000, 100); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1273 | if (capture_.stream_delay_jumps == -1) { |
| 1274 | capture_.stream_delay_jumps = 0; // Activate counter if needed. |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1275 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1276 | capture_.stream_delay_jumps++; |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1277 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1278 | capture_.last_stream_delay_ms = capture_nonlocked_.stream_delay_ms; |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1279 | |
| 1280 | // Detect a jump in AEC system delay and log the difference. |
peah | 20028c4 | 2016-03-04 11:50:54 -0800 | [diff] [blame] | 1281 | const int samples_per_ms = |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1282 | rtc::CheckedDivExact(capture_nonlocked_.split_rate, 1000); |
peah | 20028c4 | 2016-03-04 11:50:54 -0800 | [diff] [blame] | 1283 | RTC_DCHECK_LT(0, samples_per_ms); |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1284 | const int aec_system_delay_ms = |
peah | 20028c4 | 2016-03-04 11:50:54 -0800 | [diff] [blame] | 1285 | public_submodules_->echo_cancellation->GetSystemDelayInSamples() / |
| 1286 | samples_per_ms; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1287 | const int diff_aec_system_delay_ms = |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1288 | aec_system_delay_ms - capture_.last_aec_system_delay_ms; |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1289 | if (diff_aec_system_delay_ms > kMinDiffDelayMs && |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1290 | capture_.last_aec_system_delay_ms != 0) { |
asapersson | a2c58e2 | 2016-03-07 01:52:59 -0800 | [diff] [blame] | 1291 | RTC_HISTOGRAM_COUNTS("WebRTC.Audio.AecSystemDelayJump", |
| 1292 | diff_aec_system_delay_ms, kMinDiffDelayMs, 1000, |
| 1293 | 100); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1294 | if (capture_.aec_system_delay_jumps == -1) { |
| 1295 | capture_.aec_system_delay_jumps = 0; // Activate counter if needed. |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1296 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1297 | capture_.aec_system_delay_jumps++; |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1298 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1299 | capture_.last_aec_system_delay_ms = aec_system_delay_ms; |
Bjorn Volcker | 1ca324f | 2015-06-29 14:57:29 +0200 | [diff] [blame] | 1300 | } |
| 1301 | } |
| 1302 | |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1303 | void AudioProcessingImpl::UpdateHistogramsOnCallEnd() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1304 | // Run in a single-threaded manner. |
| 1305 | rtc::CritScope cs_render(&crit_render_); |
| 1306 | rtc::CritScope cs_capture(&crit_capture_); |
| 1307 | |
| 1308 | if (capture_.stream_delay_jumps > -1) { |
asapersson | a2c58e2 | 2016-03-07 01:52:59 -0800 | [diff] [blame] | 1309 | RTC_HISTOGRAM_ENUMERATION( |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1310 | "WebRTC.Audio.NumOfPlatformReportedStreamDelayJumps", |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1311 | capture_.stream_delay_jumps, 51); |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1312 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1313 | capture_.stream_delay_jumps = -1; |
| 1314 | capture_.last_stream_delay_ms = 0; |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1315 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1316 | if (capture_.aec_system_delay_jumps > -1) { |
asapersson | a2c58e2 | 2016-03-07 01:52:59 -0800 | [diff] [blame] | 1317 | RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.NumOfAecSystemDelayJumps", |
| 1318 | capture_.aec_system_delay_jumps, 51); |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1319 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1320 | capture_.aec_system_delay_jumps = -1; |
| 1321 | capture_.last_aec_system_delay_ms = 0; |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 1322 | } |
| 1323 | |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 1324 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1325 | int AudioProcessingImpl::WriteMessageToDebugFile( |
| 1326 | FileWrapper* debug_file, |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 1327 | int64_t* filesize_limit_bytes, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1328 | rtc::CriticalSection* crit_debug, |
| 1329 | ApmDebugDumpThreadState* debug_state) { |
| 1330 | int32_t size = debug_state->event_msg->ByteSize(); |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 1331 | if (size <= 0) { |
| 1332 | return kUnspecifiedError; |
| 1333 | } |
andrew@webrtc.org | 621df67 | 2013-10-22 10:27:23 +0000 | [diff] [blame] | 1334 | #if defined(WEBRTC_ARCH_BIG_ENDIAN) |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 1335 | // TODO(ajm): Use little-endian "on the wire". For the moment, we can be |
| 1336 | // pretty safe in assuming little-endian. |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 1337 | #endif |
| 1338 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1339 | if (!debug_state->event_msg->SerializeToString(&debug_state->event_str)) { |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 1340 | return kUnspecifiedError; |
| 1341 | } |
| 1342 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1343 | { |
| 1344 | // Ensure atomic writes of the message. |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 1345 | rtc::CritScope cs_debug(crit_debug); |
| 1346 | |
| 1347 | RTC_DCHECK(debug_file->Open()); |
| 1348 | // Update the byte counter. |
| 1349 | if (*filesize_limit_bytes >= 0) { |
| 1350 | *filesize_limit_bytes -= |
| 1351 | (sizeof(int32_t) + debug_state->event_str.length()); |
| 1352 | if (*filesize_limit_bytes < 0) { |
| 1353 | // Not enough bytes are left to write this message, so stop logging. |
| 1354 | debug_file->CloseFile(); |
| 1355 | return kNoError; |
| 1356 | } |
| 1357 | } |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1358 | // Write message preceded by its size. |
| 1359 | if (!debug_file->Write(&size, sizeof(int32_t))) { |
| 1360 | return kFileError; |
| 1361 | } |
| 1362 | if (!debug_file->Write(debug_state->event_str.data(), |
| 1363 | debug_state->event_str.length())) { |
| 1364 | return kFileError; |
| 1365 | } |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1368 | debug_state->event_msg->Clear(); |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 1369 | |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 1370 | return kNoError; |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | int AudioProcessingImpl::WriteInitMessage() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1374 | debug_dump_.capture.event_msg->set_type(audioproc::Event::INIT); |
| 1375 | audioproc::Init* msg = debug_dump_.capture.event_msg->mutable_init(); |
| 1376 | msg->set_sample_rate(formats_.api_format.input_stream().sample_rate_hz()); |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 1377 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 1378 | msg->set_num_input_channels(static_cast<google::protobuf::int32>( |
| 1379 | formats_.api_format.input_stream().num_channels())); |
| 1380 | msg->set_num_output_channels(static_cast<google::protobuf::int32>( |
| 1381 | formats_.api_format.output_stream().num_channels())); |
| 1382 | msg->set_num_reverse_channels(static_cast<google::protobuf::int32>( |
| 1383 | formats_.api_format.reverse_input_stream().num_channels())); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1384 | msg->set_reverse_sample_rate( |
| 1385 | formats_.api_format.reverse_input_stream().sample_rate_hz()); |
| 1386 | msg->set_output_sample_rate( |
| 1387 | formats_.api_format.output_stream().sample_rate_hz()); |
| 1388 | // TODO(ekmeyerson): Add reverse output fields to |
| 1389 | // debug_dump_.capture.event_msg. |
| 1390 | |
| 1391 | RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 1392 | &debug_dump_.num_bytes_left_for_log_, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1393 | &crit_debug_, &debug_dump_.capture)); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1394 | return kNoError; |
| 1395 | } |
| 1396 | |
| 1397 | int AudioProcessingImpl::WriteConfigMessage(bool forced) { |
| 1398 | audioproc::Config config; |
| 1399 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1400 | config.set_aec_enabled(public_submodules_->echo_cancellation->is_enabled()); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1401 | config.set_aec_delay_agnostic_enabled( |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1402 | public_submodules_->echo_cancellation->is_delay_agnostic_enabled()); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1403 | config.set_aec_drift_compensation_enabled( |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1404 | public_submodules_->echo_cancellation->is_drift_compensation_enabled()); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1405 | config.set_aec_extended_filter_enabled( |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1406 | public_submodules_->echo_cancellation->is_extended_filter_enabled()); |
| 1407 | config.set_aec_suppression_level(static_cast<int>( |
| 1408 | public_submodules_->echo_cancellation->suppression_level())); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1409 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1410 | config.set_aecm_enabled( |
| 1411 | public_submodules_->echo_control_mobile->is_enabled()); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1412 | config.set_aecm_comfort_noise_enabled( |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1413 | public_submodules_->echo_control_mobile->is_comfort_noise_enabled()); |
| 1414 | config.set_aecm_routing_mode(static_cast<int>( |
| 1415 | public_submodules_->echo_control_mobile->routing_mode())); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1416 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1417 | config.set_agc_enabled(public_submodules_->gain_control->is_enabled()); |
| 1418 | config.set_agc_mode( |
| 1419 | static_cast<int>(public_submodules_->gain_control->mode())); |
| 1420 | config.set_agc_limiter_enabled( |
| 1421 | public_submodules_->gain_control->is_limiter_enabled()); |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 1422 | config.set_noise_robust_agc_enabled(constants_.use_experimental_agc); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1423 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1424 | config.set_hpf_enabled(public_submodules_->high_pass_filter->is_enabled()); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1425 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1426 | config.set_ns_enabled(public_submodules_->noise_suppression->is_enabled()); |
| 1427 | config.set_ns_level( |
| 1428 | static_cast<int>(public_submodules_->noise_suppression->level())); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1429 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1430 | config.set_transient_suppression_enabled( |
| 1431 | capture_.transient_suppressor_enabled); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1432 | |
| 1433 | std::string serialized_config = config.SerializeAsString(); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1434 | if (!forced && |
| 1435 | debug_dump_.capture.last_serialized_config == serialized_config) { |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1436 | return kNoError; |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1439 | debug_dump_.capture.last_serialized_config = serialized_config; |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1440 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1441 | debug_dump_.capture.event_msg->set_type(audioproc::Event::CONFIG); |
| 1442 | debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 1443 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1444 | RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 1445 | &debug_dump_.num_bytes_left_for_log_, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 1446 | &crit_debug_, &debug_dump_.capture)); |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 1447 | return kNoError; |
| 1448 | } |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 1449 | #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 1450 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1451 | } // namespace webrtc |