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