Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 AudioProcessing::kSampleRate16kHz, | 75 AudioProcessing::kSampleRate16kHz, |
| 76 AudioProcessing::kSampleRate32kHz, | 76 AudioProcessing::kSampleRate32kHz, |
| 77 AudioProcessing::kSampleRate48kHz}; | 77 AudioProcessing::kSampleRate48kHz}; |
| 78 const size_t AudioProcessing::kNumNativeSampleRates = | 78 const size_t AudioProcessing::kNumNativeSampleRates = |
| 79 arraysize(AudioProcessing::kNativeSampleRatesHz); | 79 arraysize(AudioProcessing::kNativeSampleRatesHz); |
| 80 const int AudioProcessing::kMaxNativeSampleRateHz = AudioProcessing:: | 80 const int AudioProcessing::kMaxNativeSampleRateHz = AudioProcessing:: |
| 81 kNativeSampleRatesHz[AudioProcessing::kNumNativeSampleRates - 1]; | 81 kNativeSampleRatesHz[AudioProcessing::kNumNativeSampleRates - 1]; |
| 82 | 82 |
| 83 namespace { | 83 namespace { |
| 84 | 84 |
| 85 const int kInternalNativeRates[] = {AudioProcessing::kSampleRate8kHz, | |
| 86 AudioProcessing::kSampleRate16kHz, | |
| 87 #ifdef WEBRTC_ARCH_ARM_FAMILY | |
| 88 AudioProcessing::kSampleRate32kHz}; | |
| 89 #else | |
| 90 AudioProcessing::kSampleRate32kHz, | |
| 91 AudioProcessing::kSampleRate48kHz}; | |
| 92 #endif // WEBRTC_ARCH_ARM_FAMILY | |
| 93 | |
| 94 static bool LayoutHasKeyboard(AudioProcessing::ChannelLayout layout) { | 85 static bool LayoutHasKeyboard(AudioProcessing::ChannelLayout layout) { |
| 95 switch (layout) { | 86 switch (layout) { |
| 96 case AudioProcessing::kMono: | 87 case AudioProcessing::kMono: |
| 97 case AudioProcessing::kStereo: | 88 case AudioProcessing::kStereo: |
| 98 return false; | 89 return false; |
| 99 case AudioProcessing::kMonoAndKeyboard: | 90 case AudioProcessing::kMonoAndKeyboard: |
| 100 case AudioProcessing::kStereoAndKeyboard: | 91 case AudioProcessing::kStereoAndKeyboard: |
| 101 return true; | 92 return true; |
| 102 } | 93 } |
| 103 | 94 |
| 104 assert(false); | 95 assert(false); |
| 105 return false; | 96 return false; |
| 106 } | 97 } |
| 107 | 98 |
| 108 bool is_multi_band(int sample_rate_hz) { | 99 bool SampleRateSupportsMultiBand(int sample_rate_hz) { |
| 109 return sample_rate_hz == AudioProcessing::kSampleRate32kHz || | 100 return sample_rate_hz == AudioProcessing::kSampleRate32kHz || |
| 110 sample_rate_hz == AudioProcessing::kSampleRate48kHz; | 101 sample_rate_hz == AudioProcessing::kSampleRate48kHz; |
| 111 } | 102 } |
| 112 | 103 |
| 113 int ClosestHigherNativeRate(int min_proc_rate) { | 104 int NativeProcessRateToUse(int minimum_rate, bool band_splitting_required) { |
| 114 for (int rate : kInternalNativeRates) { | 105 #ifdef WEBRTC_ARCH_ARM_FAMILY |
| 115 if (rate >= min_proc_rate) { | 106 const size_t kMaxSplittingNativeProcessRateIndex = 2; |
| 107 #else | |
| 108 const size_t kMaxSplittingNativeProcessRateIndex = 3; | |
| 109 #endif | |
| 110 RTC_DCHECK_LT(kMaxSplittingNativeProcessRateIndex, | |
|
hlundin-webrtc
2016/09/06 10:41:32
You should be able to use a static_assert instead.
peah-webrtc
2016/09/07 06:28:11
Great suggestion but I ran into some problems. See
hlundin-webrtc
2016/09/07 21:36:05
Weird. I thought it'd work if you used constexpr i
peah-webrtc
2016/09/08 08:44:03
Acknowledged.
| |
| 111 AudioProcessing::kNumNativeSampleRates); | |
| 112 size_t uppermost_native_rate_index = | |
| 113 (band_splitting_required ? kMaxSplittingNativeProcessRateIndex : 3); | |
| 114 | |
| 115 for (size_t k = 0; k <= uppermost_native_rate_index; ++k) { | |
|
hlundin-webrtc
2016/09/06 10:41:32
Consider this alternative implementation of the fu
peah-webrtc
2016/09/07 06:28:11
This is a much nicer variant! Thanks!!!
I could n
kwiberg-webrtc
2016/09/08 08:17:27
What problems did you encounter? It feels like thi
peah-webrtc
2016/09/08 08:44:03
There are not that many constexpr's to add. I trie
| |
| 116 int rate = AudioProcessing::kNativeSampleRatesHz[k]; | |
| 117 if (rate >= minimum_rate) { | |
| 116 return rate; | 118 return rate; |
| 117 } | 119 } |
| 118 } | 120 } |
| 119 return kInternalNativeRates[arraysize(kInternalNativeRates) - 1]; | 121 return AudioProcessing::kNativeSampleRatesHz[uppermost_native_rate_index]; |
| 120 } | 122 } |
| 121 | 123 |
| 122 } // namespace | 124 } // namespace |
| 123 | 125 |
| 124 // Throughout webrtc, it's assumed that success is represented by zero. | 126 // Throughout webrtc, it's assumed that success is represented by zero. |
| 125 static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero"); | 127 static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero"); |
| 126 | 128 |
| 129 class AudioProcessingImpl::ApmSubmoduleStates { | |
| 130 public: | |
| 131 ApmSubmoduleStates(){}; | |
| 132 // Updates the submodule state and returns true if it has changed. | |
| 133 bool Update(bool hpf_enabled, | |
| 134 bool aec_enabled, | |
| 135 bool aecm_enabled, | |
| 136 bool ns_enabled, | |
| 137 bool ie_enabled, | |
| 138 bool bf_enabled, | |
| 139 bool agc_enabled, | |
| 140 bool lc_enabled, | |
| 141 bool vad_enabled, | |
| 142 bool le_enabled, | |
| 143 bool ts_enabled) { | |
|
the sun
2016/09/02 20:11:34
What's "ts"? (I could look it up, but I pretend to
peah-webrtc
2016/09/07 06:28:11
ts is the transient suppressor.
The abbreviation
| |
| 144 bool changed = false; | |
| 145 changed |= (hpf_enabled != hpf_enabled_); | |
| 146 changed |= (aec_enabled != aec_enabled_); | |
| 147 changed |= (aecm_enabled != aecm_enabled_); | |
| 148 changed |= (ns_enabled != ns_enabled_); | |
| 149 changed |= (ie_enabled != ie_enabled_); | |
| 150 changed |= (bf_enabled != bf_enabled_); | |
| 151 changed |= (agc_enabled != agc_enabled_); | |
| 152 changed |= (lc_enabled != lc_enabled_); | |
| 153 changed |= (le_enabled != le_enabled_); | |
| 154 changed |= (vad_enabled != vad_enabled_); | |
| 155 changed |= (ts_enabled != ts_enabled_); | |
| 156 if (changed) { | |
| 157 hpf_enabled_ = hpf_enabled; | |
| 158 aec_enabled_ = aec_enabled; | |
| 159 aecm_enabled_ = aecm_enabled; | |
| 160 ns_enabled_ = ns_enabled; | |
| 161 ie_enabled_ = ie_enabled; | |
| 162 bf_enabled_ = bf_enabled; | |
| 163 agc_enabled_ = agc_enabled; | |
| 164 lc_enabled_ = lc_enabled; | |
| 165 le_enabled_ = le_enabled; | |
| 166 vad_enabled_ = vad_enabled; | |
| 167 ts_enabled_ = ts_enabled; | |
| 168 } | |
| 169 | |
| 170 changed |= first_update_; | |
| 171 first_update_ = false; | |
| 172 return changed; | |
| 173 } | |
| 174 | |
| 175 bool CaptureMultiBandModulesActive() const { | |
| 176 return CaptureMultiBandEffectsActive() || ie_enabled_ || vad_enabled_; | |
| 177 } | |
| 178 | |
| 179 bool CaptureMultiBandEffectsActive() const { | |
| 180 return (hpf_enabled_ || aec_enabled_ || aecm_enabled_ || ns_enabled_ || | |
|
hlundin-webrtc
2016/09/06 10:41:32
You can drop the () here too.
peah-webrtc
2016/09/07 06:28:11
Done.
| |
| 181 bf_enabled_ || agc_enabled_); | |
| 182 } | |
| 183 | |
| 184 bool RenderMultiBandModulesActive() const { | |
| 185 return RenderMultiBandEffectsActive() || aec_enabled_ || aecm_enabled_ || | |
| 186 agc_enabled_; | |
| 187 } | |
| 188 | |
| 189 bool RenderMultiBandEffectsActive() const { return ie_enabled_; } | |
| 190 | |
| 191 private: | |
| 192 bool hpf_enabled_ = false; | |
| 193 bool aec_enabled_ = false; | |
| 194 bool aecm_enabled_ = false; | |
| 195 bool ns_enabled_ = false; | |
| 196 bool ie_enabled_ = false; | |
| 197 bool bf_enabled_ = false; | |
| 198 bool agc_enabled_ = false; | |
| 199 bool lc_enabled_ = false; | |
| 200 bool le_enabled_ = false; | |
| 201 bool vad_enabled_ = false; | |
| 202 bool ts_enabled_ = false; | |
| 203 bool first_update_ = true; | |
| 204 }; | |
| 205 | |
| 127 struct AudioProcessingImpl::ApmPublicSubmodules { | 206 struct AudioProcessingImpl::ApmPublicSubmodules { |
| 128 ApmPublicSubmodules() {} | 207 ApmPublicSubmodules() {} |
| 129 // Accessed externally of APM without any lock acquired. | 208 // Accessed externally of APM without any lock acquired. |
| 130 std::unique_ptr<EchoCancellationImpl> echo_cancellation; | 209 std::unique_ptr<EchoCancellationImpl> echo_cancellation; |
| 131 std::unique_ptr<EchoControlMobileImpl> echo_control_mobile; | 210 std::unique_ptr<EchoControlMobileImpl> echo_control_mobile; |
| 132 std::unique_ptr<GainControlImpl> gain_control; | 211 std::unique_ptr<GainControlImpl> gain_control; |
| 133 std::unique_ptr<HighPassFilterImpl> high_pass_filter; | 212 std::unique_ptr<HighPassFilterImpl> high_pass_filter; |
| 134 std::unique_ptr<LevelEstimatorImpl> level_estimator; | 213 std::unique_ptr<LevelEstimatorImpl> level_estimator; |
| 135 std::unique_ptr<NoiseSuppressionImpl> noise_suppression; | 214 std::unique_ptr<NoiseSuppressionImpl> noise_suppression; |
| 136 std::unique_ptr<VoiceDetectionImpl> voice_detection; | 215 std::unique_ptr<VoiceDetectionImpl> voice_detection; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 } | 250 } |
| 172 | 251 |
| 173 return apm; | 252 return apm; |
| 174 } | 253 } |
| 175 | 254 |
| 176 AudioProcessingImpl::AudioProcessingImpl(const Config& config) | 255 AudioProcessingImpl::AudioProcessingImpl(const Config& config) |
| 177 : AudioProcessingImpl(config, nullptr) {} | 256 : AudioProcessingImpl(config, nullptr) {} |
| 178 | 257 |
| 179 AudioProcessingImpl::AudioProcessingImpl(const Config& config, | 258 AudioProcessingImpl::AudioProcessingImpl(const Config& config, |
| 180 NonlinearBeamformer* beamformer) | 259 NonlinearBeamformer* beamformer) |
| 181 : public_submodules_(new ApmPublicSubmodules()), | 260 : submodule_states_(new ApmSubmoduleStates()), |
| 261 public_submodules_(new ApmPublicSubmodules()), | |
| 182 private_submodules_(new ApmPrivateSubmodules(beamformer)), | 262 private_submodules_(new ApmPrivateSubmodules(beamformer)), |
| 183 constants_(config.Get<ExperimentalAgc>().startup_min_volume, | 263 constants_(config.Get<ExperimentalAgc>().startup_min_volume, |
| 184 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 264 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
| 185 false), | 265 false), |
| 186 #else | 266 #else |
| 187 config.Get<ExperimentalAgc>().enabled), | 267 config.Get<ExperimentalAgc>().enabled), |
| 188 #endif | 268 #endif |
| 189 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 269 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
| 190 capture_(false, | 270 capture_(false, |
| 191 #else | 271 #else |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 | 348 |
| 269 int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) { | 349 int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) { |
| 270 // Run in a single-threaded manner during initialization. | 350 // Run in a single-threaded manner during initialization. |
| 271 rtc::CritScope cs_render(&crit_render_); | 351 rtc::CritScope cs_render(&crit_render_); |
| 272 rtc::CritScope cs_capture(&crit_capture_); | 352 rtc::CritScope cs_capture(&crit_capture_); |
| 273 return InitializeLocked(processing_config); | 353 return InitializeLocked(processing_config); |
| 274 } | 354 } |
| 275 | 355 |
| 276 int AudioProcessingImpl::MaybeInitializeRender( | 356 int AudioProcessingImpl::MaybeInitializeRender( |
| 277 const ProcessingConfig& processing_config) { | 357 const ProcessingConfig& processing_config) { |
| 278 return MaybeInitialize(processing_config); | 358 return MaybeInitialize(processing_config, false); |
| 279 } | 359 } |
| 280 | 360 |
| 281 int AudioProcessingImpl::MaybeInitializeCapture( | 361 int AudioProcessingImpl::MaybeInitializeCapture( |
| 282 const ProcessingConfig& processing_config) { | 362 const ProcessingConfig& processing_config, |
| 283 return MaybeInitialize(processing_config); | 363 bool force_initialization) { |
| 364 return MaybeInitialize(processing_config, force_initialization); | |
| 284 } | 365 } |
| 285 | 366 |
| 286 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 367 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 287 | 368 |
| 288 AudioProcessingImpl::ApmDebugDumpThreadState::ApmDebugDumpThreadState() | 369 AudioProcessingImpl::ApmDebugDumpThreadState::ApmDebugDumpThreadState() |
| 289 : event_msg(new audioproc::Event()) {} | 370 : event_msg(new audioproc::Event()) {} |
| 290 | 371 |
| 291 AudioProcessingImpl::ApmDebugDumpThreadState::~ApmDebugDumpThreadState() {} | 372 AudioProcessingImpl::ApmDebugDumpThreadState::~ApmDebugDumpThreadState() {} |
| 292 | 373 |
| 293 AudioProcessingImpl::ApmDebugDumpState::ApmDebugDumpState() | 374 AudioProcessingImpl::ApmDebugDumpState::ApmDebugDumpState() |
| 294 : debug_file(FileWrapper::Create()) {} | 375 : debug_file(FileWrapper::Create()) {} |
| 295 | 376 |
| 296 AudioProcessingImpl::ApmDebugDumpState::~ApmDebugDumpState() {} | 377 AudioProcessingImpl::ApmDebugDumpState::~ApmDebugDumpState() {} |
| 297 | 378 |
| 298 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 379 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 299 | 380 |
| 300 // Calls InitializeLocked() if any of the audio parameters have changed from | 381 // Calls InitializeLocked() if any of the audio parameters have changed from |
| 301 // their current values (needs to be called while holding the crit_render_lock). | 382 // their current values (needs to be called while holding the crit_render_lock). |
| 302 int AudioProcessingImpl::MaybeInitialize( | 383 int AudioProcessingImpl::MaybeInitialize( |
| 303 const ProcessingConfig& processing_config) { | 384 const ProcessingConfig& processing_config, |
| 385 bool force_initialization) { | |
| 304 // Called from both threads. Thread check is therefore not possible. | 386 // Called from both threads. Thread check is therefore not possible. |
| 305 if (processing_config == formats_.api_format) { | 387 if (processing_config == formats_.api_format && !force_initialization) { |
| 306 return kNoError; | 388 return kNoError; |
| 307 } | 389 } |
| 308 | 390 |
| 309 rtc::CritScope cs_capture(&crit_capture_); | 391 rtc::CritScope cs_capture(&crit_capture_); |
| 310 return InitializeLocked(processing_config); | 392 return InitializeLocked(processing_config); |
| 311 } | 393 } |
| 312 | 394 |
| 313 int AudioProcessingImpl::InitializeLocked() { | 395 int AudioProcessingImpl::InitializeLocked() { |
| 314 const int fwd_audio_buffer_channels = | 396 const int fwd_audio_buffer_channels = |
| 315 capture_nonlocked_.beamformer_enabled | 397 capture_nonlocked_.beamformer_enabled |
| 316 ? formats_.api_format.input_stream().num_channels() | 398 ? formats_.api_format.input_stream().num_channels() |
| 317 : formats_.api_format.output_stream().num_channels(); | 399 : formats_.api_format.output_stream().num_channels(); |
| 318 const int rev_audio_buffer_out_num_frames = | 400 const int rev_audio_buffer_out_num_frames = |
| 319 formats_.api_format.reverse_output_stream().num_frames() == 0 | 401 formats_.api_format.reverse_output_stream().num_frames() == 0 |
| 320 ? formats_.rev_proc_format.num_frames() | 402 ? formats_.rev_proc_format.num_frames() |
| 321 : formats_.api_format.reverse_output_stream().num_frames(); | 403 : formats_.api_format.reverse_output_stream().num_frames(); |
| 322 if (formats_.api_format.reverse_input_stream().num_channels() > 0) { | 404 if (formats_.api_format.reverse_input_stream().num_channels() > 0) { |
| 323 render_.render_audio.reset(new AudioBuffer( | 405 render_.render_audio.reset(new AudioBuffer( |
| 324 formats_.api_format.reverse_input_stream().num_frames(), | 406 formats_.api_format.reverse_input_stream().num_frames(), |
| 325 formats_.api_format.reverse_input_stream().num_channels(), | 407 formats_.api_format.reverse_input_stream().num_channels(), |
| 326 formats_.rev_proc_format.num_frames(), | 408 formats_.rev_proc_format.num_frames(), |
| 327 formats_.rev_proc_format.num_channels(), | 409 formats_.rev_proc_format.num_channels(), |
| 328 rev_audio_buffer_out_num_frames)); | 410 rev_audio_buffer_out_num_frames)); |
| 329 if (rev_conversion_needed()) { | 411 if (formats_.api_format.reverse_input_stream() != |
| 412 formats_.api_format.reverse_output_stream()) { | |
| 330 render_.render_converter = AudioConverter::Create( | 413 render_.render_converter = AudioConverter::Create( |
| 331 formats_.api_format.reverse_input_stream().num_channels(), | 414 formats_.api_format.reverse_input_stream().num_channels(), |
| 332 formats_.api_format.reverse_input_stream().num_frames(), | 415 formats_.api_format.reverse_input_stream().num_frames(), |
| 333 formats_.api_format.reverse_output_stream().num_channels(), | 416 formats_.api_format.reverse_output_stream().num_channels(), |
| 334 formats_.api_format.reverse_output_stream().num_frames()); | 417 formats_.api_format.reverse_output_stream().num_frames()); |
| 335 } else { | 418 } else { |
| 336 render_.render_converter.reset(nullptr); | 419 render_.render_converter.reset(nullptr); |
| 337 } | 420 } |
| 338 } else { | 421 } else { |
| 339 render_.render_audio.reset(nullptr); | 422 render_.render_audio.reset(nullptr); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 return kBadNumberChannelsError; | 473 return kBadNumberChannelsError; |
| 391 } | 474 } |
| 392 | 475 |
| 393 if (capture_nonlocked_.beamformer_enabled && | 476 if (capture_nonlocked_.beamformer_enabled && |
| 394 num_in_channels != capture_.array_geometry.size()) { | 477 num_in_channels != capture_.array_geometry.size()) { |
| 395 return kBadNumberChannelsError; | 478 return kBadNumberChannelsError; |
| 396 } | 479 } |
| 397 | 480 |
| 398 formats_.api_format = config; | 481 formats_.api_format = config; |
| 399 | 482 |
| 400 capture_nonlocked_.fwd_proc_format = StreamConfig(ClosestHigherNativeRate( | 483 int fwd_proc_rate = NativeProcessRateToUse( |
| 401 std::min(formats_.api_format.input_stream().sample_rate_hz(), | 484 std::min(formats_.api_format.input_stream().sample_rate_hz(), |
| 402 formats_.api_format.output_stream().sample_rate_hz()))); | 485 formats_.api_format.output_stream().sample_rate_hz()), |
| 486 submodule_states_->CaptureMultiBandModulesActive() || | |
| 487 submodule_states_->RenderMultiBandModulesActive()); | |
| 403 | 488 |
| 404 int rev_proc_rate = ClosestHigherNativeRate(std::min( | 489 capture_nonlocked_.fwd_proc_format = StreamConfig(fwd_proc_rate); |
| 405 formats_.api_format.reverse_input_stream().sample_rate_hz(), | 490 |
| 406 formats_.api_format.reverse_output_stream().sample_rate_hz())); | 491 int rev_proc_rate = NativeProcessRateToUse( |
| 492 std::min(formats_.api_format.reverse_input_stream().sample_rate_hz(), | |
| 493 formats_.api_format.reverse_output_stream().sample_rate_hz()), | |
| 494 submodule_states_->CaptureMultiBandModulesActive() || | |
| 495 submodule_states_->RenderMultiBandModulesActive()); | |
| 407 // TODO(aluebs): Remove this restriction once we figure out why the 3-band | 496 // TODO(aluebs): Remove this restriction once we figure out why the 3-band |
| 408 // splitting filter degrades the AEC performance. | 497 // splitting filter degrades the AEC performance. |
| 409 if (rev_proc_rate > kSampleRate32kHz) { | 498 if (rev_proc_rate > kSampleRate32kHz) { |
| 410 rev_proc_rate = is_rev_processed() ? kSampleRate32kHz : kSampleRate16kHz; | 499 rev_proc_rate = submodule_states_->RenderMultiBandEffectsActive() |
| 500 ? kSampleRate32kHz | |
| 501 : kSampleRate16kHz; | |
| 411 } | 502 } |
| 412 // If the forward sample rate is 8 kHz, the reverse stream is also processed | 503 // If the forward sample rate is 8 kHz, the reverse stream is also processed |
| 413 // at this rate. | 504 // at this rate. |
| 414 if (capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate8kHz) { | 505 if (capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate8kHz) { |
| 415 rev_proc_rate = kSampleRate8kHz; | 506 rev_proc_rate = kSampleRate8kHz; |
| 416 } else { | 507 } else { |
| 417 rev_proc_rate = std::max(rev_proc_rate, static_cast<int>(kSampleRate16kHz)); | 508 rev_proc_rate = std::max(rev_proc_rate, static_cast<int>(kSampleRate16kHz)); |
| 418 } | 509 } |
| 419 | 510 |
| 420 // Always downmix the reverse stream to mono for analysis. This has been | 511 // Always downmix the reverse stream to mono for analysis. This has been |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 } | 640 } |
| 550 return ProcessStream(src, input_stream, output_stream, dest); | 641 return ProcessStream(src, input_stream, output_stream, dest); |
| 551 } | 642 } |
| 552 | 643 |
| 553 int AudioProcessingImpl::ProcessStream(const float* const* src, | 644 int AudioProcessingImpl::ProcessStream(const float* const* src, |
| 554 const StreamConfig& input_config, | 645 const StreamConfig& input_config, |
| 555 const StreamConfig& output_config, | 646 const StreamConfig& output_config, |
| 556 float* const* dest) { | 647 float* const* dest) { |
| 557 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_StreamConfig"); | 648 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_StreamConfig"); |
| 558 ProcessingConfig processing_config; | 649 ProcessingConfig processing_config; |
| 650 bool reeinitialization_required; | |
|
hlundin-webrtc
2016/09/06 10:41:32
Typo: reeinit... -> reinit...
peah-webrtc
2016/09/07 06:28:11
Done.
| |
| 559 { | 651 { |
| 560 // Acquire the capture lock in order to safely call the function | 652 // Acquire the capture lock in order to safely call the function |
| 561 // that retrieves the render side data. This function accesses apm | 653 // that retrieves the render side data. This function accesses apm |
| 562 // getters that need the capture lock held when being called. | 654 // getters that need the capture lock held when being called. |
| 563 rtc::CritScope cs_capture(&crit_capture_); | 655 rtc::CritScope cs_capture(&crit_capture_); |
| 564 public_submodules_->echo_cancellation->ReadQueuedRenderData(); | 656 public_submodules_->echo_cancellation->ReadQueuedRenderData(); |
| 565 public_submodules_->echo_control_mobile->ReadQueuedRenderData(); | 657 public_submodules_->echo_control_mobile->ReadQueuedRenderData(); |
| 566 public_submodules_->gain_control->ReadQueuedRenderData(); | 658 public_submodules_->gain_control->ReadQueuedRenderData(); |
| 567 | 659 |
| 568 if (!src || !dest) { | 660 if (!src || !dest) { |
| 569 return kNullPointerError; | 661 return kNullPointerError; |
| 570 } | 662 } |
| 571 | 663 |
| 572 processing_config = formats_.api_format; | 664 processing_config = formats_.api_format; |
| 665 reeinitialization_required = UpdateActiveSubmoduleStates(); | |
| 573 } | 666 } |
| 574 | 667 |
| 575 processing_config.input_stream() = input_config; | 668 processing_config.input_stream() = input_config; |
| 576 processing_config.output_stream() = output_config; | 669 processing_config.output_stream() = output_config; |
| 577 | 670 |
| 578 { | 671 { |
| 579 // Do conditional reinitialization. | 672 // Do conditional reinitialization. |
| 580 rtc::CritScope cs_render(&crit_render_); | 673 rtc::CritScope cs_render(&crit_render_); |
| 581 RETURN_ON_ERR(MaybeInitializeCapture(processing_config)); | 674 RETURN_ON_ERR( |
| 675 MaybeInitializeCapture(processing_config, reeinitialization_required)); | |
| 582 } | 676 } |
| 583 rtc::CritScope cs_capture(&crit_capture_); | 677 rtc::CritScope cs_capture(&crit_capture_); |
| 584 assert(processing_config.input_stream().num_frames() == | 678 assert(processing_config.input_stream().num_frames() == |
| 585 formats_.api_format.input_stream().num_frames()); | 679 formats_.api_format.input_stream().num_frames()); |
| 586 | 680 |
| 587 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 681 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 588 if (debug_dump_.debug_file->is_open()) { | 682 if (debug_dump_.debug_file->is_open()) { |
| 589 RETURN_ON_ERR(WriteConfigMessage(false)); | 683 RETURN_ON_ERR(WriteConfigMessage(false)); |
| 590 | 684 |
| 591 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); | 685 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 } | 733 } |
| 640 // Must be a native rate. | 734 // Must be a native rate. |
| 641 if (frame->sample_rate_hz_ != kSampleRate8kHz && | 735 if (frame->sample_rate_hz_ != kSampleRate8kHz && |
| 642 frame->sample_rate_hz_ != kSampleRate16kHz && | 736 frame->sample_rate_hz_ != kSampleRate16kHz && |
| 643 frame->sample_rate_hz_ != kSampleRate32kHz && | 737 frame->sample_rate_hz_ != kSampleRate32kHz && |
| 644 frame->sample_rate_hz_ != kSampleRate48kHz) { | 738 frame->sample_rate_hz_ != kSampleRate48kHz) { |
| 645 return kBadSampleRateError; | 739 return kBadSampleRateError; |
| 646 } | 740 } |
| 647 | 741 |
| 648 ProcessingConfig processing_config; | 742 ProcessingConfig processing_config; |
| 743 bool reeinitialization_required; | |
|
hlundin-webrtc
2016/09/06 10:41:32
Same typo.
peah-webrtc
2016/09/07 06:28:11
Done.
| |
| 649 { | 744 { |
| 650 // Aquire lock for the access of api_format. | 745 // Aquire lock for the access of api_format. |
| 651 // The lock is released immediately due to the conditional | 746 // The lock is released immediately due to the conditional |
| 652 // reinitialization. | 747 // reinitialization. |
| 653 rtc::CritScope cs_capture(&crit_capture_); | 748 rtc::CritScope cs_capture(&crit_capture_); |
| 654 // TODO(ajm): The input and output rates and channels are currently | 749 // TODO(ajm): The input and output rates and channels are currently |
| 655 // constrained to be identical in the int16 interface. | 750 // constrained to be identical in the int16 interface. |
| 656 processing_config = formats_.api_format; | 751 processing_config = formats_.api_format; |
| 752 | |
| 753 reeinitialization_required = UpdateActiveSubmoduleStates(); | |
| 657 } | 754 } |
| 658 processing_config.input_stream().set_sample_rate_hz(frame->sample_rate_hz_); | 755 processing_config.input_stream().set_sample_rate_hz(frame->sample_rate_hz_); |
| 659 processing_config.input_stream().set_num_channels(frame->num_channels_); | 756 processing_config.input_stream().set_num_channels(frame->num_channels_); |
| 660 processing_config.output_stream().set_sample_rate_hz(frame->sample_rate_hz_); | 757 processing_config.output_stream().set_sample_rate_hz(frame->sample_rate_hz_); |
| 661 processing_config.output_stream().set_num_channels(frame->num_channels_); | 758 processing_config.output_stream().set_num_channels(frame->num_channels_); |
| 662 | 759 |
| 663 { | 760 { |
| 664 // Do conditional reinitialization. | 761 // Do conditional reinitialization. |
| 665 rtc::CritScope cs_render(&crit_render_); | 762 rtc::CritScope cs_render(&crit_render_); |
| 666 RETURN_ON_ERR(MaybeInitializeCapture(processing_config)); | 763 RETURN_ON_ERR( |
| 764 MaybeInitializeCapture(processing_config, reeinitialization_required)); | |
| 667 } | 765 } |
| 668 rtc::CritScope cs_capture(&crit_capture_); | 766 rtc::CritScope cs_capture(&crit_capture_); |
| 669 if (frame->samples_per_channel_ != | 767 if (frame->samples_per_channel_ != |
| 670 formats_.api_format.input_stream().num_frames()) { | 768 formats_.api_format.input_stream().num_frames()) { |
| 671 return kBadDataLengthError; | 769 return kBadDataLengthError; |
| 672 } | 770 } |
| 673 | 771 |
| 674 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 772 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 675 if (debug_dump_.debug_file->is_open()) { | 773 if (debug_dump_.debug_file->is_open()) { |
| 676 RETURN_ON_ERR(WriteConfigMessage(false)); | 774 RETURN_ON_ERR(WriteConfigMessage(false)); |
| 677 | 775 |
| 678 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); | 776 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); |
| 679 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); | 777 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
| 680 const size_t data_size = | 778 const size_t data_size = |
| 681 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; | 779 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
| 682 msg->set_input_data(frame->data_, data_size); | 780 msg->set_input_data(frame->data_, data_size); |
| 683 } | 781 } |
| 684 #endif | 782 #endif |
| 685 | 783 |
| 686 capture_.capture_audio->DeinterleaveFrom(frame); | 784 capture_.capture_audio->DeinterleaveFrom(frame); |
| 687 RETURN_ON_ERR(ProcessStreamLocked()); | 785 RETURN_ON_ERR(ProcessStreamLocked()); |
| 688 capture_.capture_audio->InterleaveTo(frame, output_copy_needed()); | 786 capture_.capture_audio->InterleaveTo(frame, true); |
| 689 | 787 |
| 690 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 788 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 691 if (debug_dump_.debug_file->is_open()) { | 789 if (debug_dump_.debug_file->is_open()) { |
| 692 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); | 790 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
| 693 const size_t data_size = | 791 const size_t data_size = |
| 694 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; | 792 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
| 695 msg->set_output_data(frame->data_, data_size); | 793 msg->set_output_data(frame->data_, data_size); |
| 696 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 794 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
| 697 &debug_dump_.num_bytes_left_for_log_, | 795 &debug_dump_.num_bytes_left_for_log_, |
| 698 &crit_debug_, &debug_dump_.capture)); | 796 &crit_debug_, &debug_dump_.capture)); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 724 | 822 |
| 725 AudioBuffer* ca = capture_.capture_audio.get(); // For brevity. | 823 AudioBuffer* ca = capture_.capture_audio.get(); // For brevity. |
| 726 | 824 |
| 727 if (constants_.use_experimental_agc && | 825 if (constants_.use_experimental_agc && |
| 728 public_submodules_->gain_control->is_enabled()) { | 826 public_submodules_->gain_control->is_enabled()) { |
| 729 private_submodules_->agc_manager->AnalyzePreProcess( | 827 private_submodules_->agc_manager->AnalyzePreProcess( |
| 730 ca->channels()[0], ca->num_channels(), | 828 ca->channels()[0], ca->num_channels(), |
| 731 capture_nonlocked_.fwd_proc_format.num_frames()); | 829 capture_nonlocked_.fwd_proc_format.num_frames()); |
| 732 } | 830 } |
| 733 | 831 |
| 734 if (fwd_analysis_needed()) { | 832 if (submodule_states_->CaptureMultiBandModulesActive() && |
| 833 SampleRateSupportsMultiBand( | |
| 834 capture_nonlocked_.fwd_proc_format.sample_rate_hz())) { | |
| 735 ca->SplitIntoFrequencyBands(); | 835 ca->SplitIntoFrequencyBands(); |
| 736 } | 836 } |
| 737 | 837 |
| 738 if (capture_nonlocked_.beamformer_enabled) { | 838 if (capture_nonlocked_.beamformer_enabled) { |
| 739 private_submodules_->beamformer->AnalyzeChunk(*ca->split_data_f()); | 839 private_submodules_->beamformer->AnalyzeChunk(*ca->split_data_f()); |
| 740 // Discards all channels by the leftmost one. | 840 // Discards all channels by the leftmost one. |
| 741 ca->set_num_channels(1); | 841 ca->set_num_channels(1); |
| 742 } | 842 } |
| 743 | 843 |
| 744 public_submodules_->high_pass_filter->ProcessCaptureAudio(ca); | 844 public_submodules_->high_pass_filter->ProcessCaptureAudio(ca); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 public_submodules_->gain_control->is_enabled() && | 895 public_submodules_->gain_control->is_enabled() && |
| 796 (!capture_nonlocked_.beamformer_enabled || | 896 (!capture_nonlocked_.beamformer_enabled || |
| 797 private_submodules_->beamformer->is_target_present())) { | 897 private_submodules_->beamformer->is_target_present())) { |
| 798 private_submodules_->agc_manager->Process( | 898 private_submodules_->agc_manager->Process( |
| 799 ca->split_bands_const(0)[kBand0To8kHz], ca->num_frames_per_band(), | 899 ca->split_bands_const(0)[kBand0To8kHz], ca->num_frames_per_band(), |
| 800 capture_nonlocked_.split_rate); | 900 capture_nonlocked_.split_rate); |
| 801 } | 901 } |
| 802 RETURN_ON_ERR(public_submodules_->gain_control->ProcessCaptureAudio( | 902 RETURN_ON_ERR(public_submodules_->gain_control->ProcessCaptureAudio( |
| 803 ca, echo_cancellation()->stream_has_echo())); | 903 ca, echo_cancellation()->stream_has_echo())); |
| 804 | 904 |
| 805 if (fwd_synthesis_needed()) { | 905 if (submodule_states_->CaptureMultiBandEffectsActive() && |
| 906 SampleRateSupportsMultiBand( | |
| 907 capture_nonlocked_.fwd_proc_format.sample_rate_hz())) { | |
| 806 ca->MergeFrequencyBands(); | 908 ca->MergeFrequencyBands(); |
| 807 } | 909 } |
| 808 | 910 |
| 809 // TODO(aluebs): Investigate if the transient suppression placement should be | 911 // TODO(aluebs): Investigate if the transient suppression placement should be |
| 810 // before or after the AGC. | 912 // before or after the AGC. |
| 811 if (capture_.transient_suppressor_enabled) { | 913 if (capture_.transient_suppressor_enabled) { |
| 812 float voice_probability = | 914 float voice_probability = |
| 813 private_submodules_->agc_manager.get() | 915 private_submodules_->agc_manager.get() |
| 814 ? private_submodules_->agc_manager->voice_probability() | 916 ? private_submodules_->agc_manager->voice_probability() |
| 815 : 1.f; | 917 : 1.f; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 849 | 951 |
| 850 int AudioProcessingImpl::ProcessReverseStream( | 952 int AudioProcessingImpl::ProcessReverseStream( |
| 851 const float* const* src, | 953 const float* const* src, |
| 852 const StreamConfig& reverse_input_config, | 954 const StreamConfig& reverse_input_config, |
| 853 const StreamConfig& reverse_output_config, | 955 const StreamConfig& reverse_output_config, |
| 854 float* const* dest) { | 956 float* const* dest) { |
| 855 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_StreamConfig"); | 957 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_StreamConfig"); |
| 856 rtc::CritScope cs(&crit_render_); | 958 rtc::CritScope cs(&crit_render_); |
| 857 RETURN_ON_ERR(AnalyzeReverseStreamLocked(src, reverse_input_config, | 959 RETURN_ON_ERR(AnalyzeReverseStreamLocked(src, reverse_input_config, |
| 858 reverse_output_config)); | 960 reverse_output_config)); |
| 859 if (is_rev_processed()) { | 961 if (submodule_states_->RenderMultiBandEffectsActive()) { |
| 860 render_.render_audio->CopyTo(formats_.api_format.reverse_output_stream(), | 962 render_.render_audio->CopyTo(formats_.api_format.reverse_output_stream(), |
| 861 dest); | 963 dest); |
| 862 } else if (render_check_rev_conversion_needed()) { | 964 } else if (formats_.api_format.reverse_input_stream() != |
| 965 formats_.api_format.reverse_output_stream()) { | |
| 863 render_.render_converter->Convert(src, reverse_input_config.num_samples(), | 966 render_.render_converter->Convert(src, reverse_input_config.num_samples(), |
| 864 dest, | 967 dest, |
| 865 reverse_output_config.num_samples()); | 968 reverse_output_config.num_samples()); |
| 866 } else { | 969 } else { |
| 867 CopyAudioIfNeeded(src, reverse_input_config.num_frames(), | 970 CopyAudioIfNeeded(src, reverse_input_config.num_frames(), |
| 868 reverse_input_config.num_channels(), dest); | 971 reverse_input_config.num_channels(), dest); |
| 869 } | 972 } |
| 870 | 973 |
| 871 return kNoError; | 974 return kNoError; |
| 872 } | 975 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 954 const size_t data_size = | 1057 const size_t data_size = |
| 955 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; | 1058 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
| 956 msg->set_data(frame->data_, data_size); | 1059 msg->set_data(frame->data_, data_size); |
| 957 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 1060 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
| 958 &debug_dump_.num_bytes_left_for_log_, | 1061 &debug_dump_.num_bytes_left_for_log_, |
| 959 &crit_debug_, &debug_dump_.render)); | 1062 &crit_debug_, &debug_dump_.render)); |
| 960 } | 1063 } |
| 961 #endif | 1064 #endif |
| 962 render_.render_audio->DeinterleaveFrom(frame); | 1065 render_.render_audio->DeinterleaveFrom(frame); |
| 963 RETURN_ON_ERR(ProcessReverseStreamLocked()); | 1066 RETURN_ON_ERR(ProcessReverseStreamLocked()); |
| 964 if (is_rev_processed()) { | 1067 render_.render_audio->InterleaveTo(frame, true); |
| 965 render_.render_audio->InterleaveTo(frame, true); | |
| 966 } | |
| 967 return kNoError; | 1068 return kNoError; |
| 968 } | 1069 } |
| 969 | 1070 |
| 970 int AudioProcessingImpl::ProcessReverseStreamLocked() { | 1071 int AudioProcessingImpl::ProcessReverseStreamLocked() { |
| 971 AudioBuffer* ra = render_.render_audio.get(); // For brevity. | 1072 AudioBuffer* ra = render_.render_audio.get(); // For brevity. |
| 972 if (rev_analysis_needed()) { | 1073 if (submodule_states_->RenderMultiBandModulesActive() && |
| 1074 SampleRateSupportsMultiBand(formats_.rev_proc_format.sample_rate_hz())) { | |
| 973 ra->SplitIntoFrequencyBands(); | 1075 ra->SplitIntoFrequencyBands(); |
| 974 } | 1076 } |
| 975 | 1077 |
| 976 #if WEBRTC_INTELLIGIBILITY_ENHANCER | 1078 #if WEBRTC_INTELLIGIBILITY_ENHANCER |
| 977 if (capture_nonlocked_.intelligibility_enabled) { | 1079 if (capture_nonlocked_.intelligibility_enabled) { |
| 978 public_submodules_->intelligibility_enhancer->ProcessRenderAudio( | 1080 public_submodules_->intelligibility_enhancer->ProcessRenderAudio( |
| 979 ra->split_channels_f(kBand0To8kHz), capture_nonlocked_.split_rate, | 1081 ra->split_channels_f(kBand0To8kHz), capture_nonlocked_.split_rate, |
| 980 ra->num_channels()); | 1082 ra->num_channels()); |
| 981 } | 1083 } |
| 982 #endif | 1084 #endif |
| 983 | 1085 |
| 984 RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessRenderAudio(ra)); | 1086 RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessRenderAudio(ra)); |
| 985 RETURN_ON_ERR( | 1087 RETURN_ON_ERR( |
| 986 public_submodules_->echo_control_mobile->ProcessRenderAudio(ra)); | 1088 public_submodules_->echo_control_mobile->ProcessRenderAudio(ra)); |
| 987 if (!constants_.use_experimental_agc) { | 1089 if (!constants_.use_experimental_agc) { |
| 988 RETURN_ON_ERR(public_submodules_->gain_control->ProcessRenderAudio(ra)); | 1090 RETURN_ON_ERR(public_submodules_->gain_control->ProcessRenderAudio(ra)); |
| 989 } | 1091 } |
| 990 | 1092 |
| 991 if (rev_synthesis_needed()) { | 1093 if (submodule_states_->RenderMultiBandEffectsActive() && |
| 1094 SampleRateSupportsMultiBand(formats_.rev_proc_format.sample_rate_hz())) { | |
| 992 ra->MergeFrequencyBands(); | 1095 ra->MergeFrequencyBands(); |
| 993 } | 1096 } |
| 994 | 1097 |
| 995 return kNoError; | 1098 return kNoError; |
| 996 } | 1099 } |
| 997 | 1100 |
| 998 int AudioProcessingImpl::set_stream_delay_ms(int delay) { | 1101 int AudioProcessingImpl::set_stream_delay_ms(int delay) { |
| 999 rtc::CritScope cs(&crit_capture_); | 1102 rtc::CritScope cs(&crit_capture_); |
| 1000 Error retval = kNoError; | 1103 Error retval = kNoError; |
| 1001 capture_.was_stream_delay_set = true; | 1104 capture_.was_stream_delay_set = true; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1115 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 1218 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1116 // We just return if recording hasn't started. | 1219 // We just return if recording hasn't started. |
| 1117 debug_dump_.debug_file->CloseFile(); | 1220 debug_dump_.debug_file->CloseFile(); |
| 1118 return kNoError; | 1221 return kNoError; |
| 1119 #else | 1222 #else |
| 1120 return kUnsupportedFunctionError; | 1223 return kUnsupportedFunctionError; |
| 1121 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1224 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1122 } | 1225 } |
| 1123 | 1226 |
| 1124 EchoCancellation* AudioProcessingImpl::echo_cancellation() const { | 1227 EchoCancellation* AudioProcessingImpl::echo_cancellation() const { |
| 1125 // Adding a lock here has no effect as it allows any access to the submodule | |
| 1126 // from the returned pointer. | |
| 1127 return public_submodules_->echo_cancellation.get(); | 1228 return public_submodules_->echo_cancellation.get(); |
| 1128 } | 1229 } |
| 1129 | 1230 |
| 1130 EchoControlMobile* AudioProcessingImpl::echo_control_mobile() const { | 1231 EchoControlMobile* AudioProcessingImpl::echo_control_mobile() const { |
| 1131 // Adding a lock here has no effect as it allows any access to the submodule | |
| 1132 // from the returned pointer. | |
| 1133 return public_submodules_->echo_control_mobile.get(); | 1232 return public_submodules_->echo_control_mobile.get(); |
| 1134 } | 1233 } |
| 1135 | 1234 |
| 1136 GainControl* AudioProcessingImpl::gain_control() const { | 1235 GainControl* AudioProcessingImpl::gain_control() const { |
| 1137 // Adding a lock here has no effect as it allows any access to the submodule | |
| 1138 // from the returned pointer. | |
| 1139 if (constants_.use_experimental_agc) { | 1236 if (constants_.use_experimental_agc) { |
| 1140 return public_submodules_->gain_control_for_experimental_agc.get(); | 1237 return public_submodules_->gain_control_for_experimental_agc.get(); |
| 1141 } | 1238 } |
| 1142 return public_submodules_->gain_control.get(); | 1239 return public_submodules_->gain_control.get(); |
| 1143 } | 1240 } |
| 1144 | 1241 |
| 1145 HighPassFilter* AudioProcessingImpl::high_pass_filter() const { | 1242 HighPassFilter* AudioProcessingImpl::high_pass_filter() const { |
| 1146 // Adding a lock here has no effect as it allows any access to the submodule | |
| 1147 // from the returned pointer. | |
| 1148 return public_submodules_->high_pass_filter.get(); | 1243 return public_submodules_->high_pass_filter.get(); |
| 1149 } | 1244 } |
| 1150 | 1245 |
| 1151 LevelEstimator* AudioProcessingImpl::level_estimator() const { | 1246 LevelEstimator* AudioProcessingImpl::level_estimator() const { |
| 1152 // Adding a lock here has no effect as it allows any access to the submodule | |
| 1153 // from the returned pointer. | |
| 1154 return public_submodules_->level_estimator.get(); | 1247 return public_submodules_->level_estimator.get(); |
| 1155 } | 1248 } |
| 1156 | 1249 |
| 1157 NoiseSuppression* AudioProcessingImpl::noise_suppression() const { | 1250 NoiseSuppression* AudioProcessingImpl::noise_suppression() const { |
| 1158 // Adding a lock here has no effect as it allows any access to the submodule | |
| 1159 // from the returned pointer. | |
| 1160 return public_submodules_->noise_suppression.get(); | 1251 return public_submodules_->noise_suppression.get(); |
| 1161 } | 1252 } |
| 1162 | 1253 |
| 1163 VoiceDetection* AudioProcessingImpl::voice_detection() const { | 1254 VoiceDetection* AudioProcessingImpl::voice_detection() const { |
| 1164 // Adding a lock here has no effect as it allows any access to the submodule | |
| 1165 // from the returned pointer. | |
| 1166 return public_submodules_->voice_detection.get(); | 1255 return public_submodules_->voice_detection.get(); |
| 1167 } | 1256 } |
| 1168 | 1257 |
| 1169 bool AudioProcessingImpl::is_fwd_processed() const { | 1258 bool AudioProcessingImpl::UpdateActiveSubmoduleStates() { |
| 1170 // The beamformer, noise suppressor and highpass filter | 1259 return submodule_states_->Update( |
| 1171 // modify the data. | 1260 public_submodules_->high_pass_filter->is_enabled(), |
| 1172 if (capture_nonlocked_.beamformer_enabled || | 1261 public_submodules_->echo_cancellation->is_enabled(), |
| 1173 public_submodules_->high_pass_filter->is_enabled() || | 1262 public_submodules_->echo_control_mobile->is_enabled(), |
| 1174 public_submodules_->noise_suppression->is_enabled() || | 1263 public_submodules_->noise_suppression->is_enabled(), |
| 1175 public_submodules_->echo_cancellation->is_enabled() || | 1264 capture_nonlocked_.intelligibility_enabled, |
| 1176 public_submodules_->echo_control_mobile->is_enabled() || | 1265 capture_nonlocked_.beamformer_enabled, |
| 1177 public_submodules_->gain_control->is_enabled()) { | 1266 public_submodules_->gain_control->is_enabled(), |
| 1178 return true; | 1267 capture_nonlocked_.level_controller_enabled, |
| 1179 } | 1268 public_submodules_->voice_detection->is_enabled(), |
| 1180 | 1269 public_submodules_->level_estimator->is_enabled(), |
| 1181 // The capture data is otherwise unchanged. | 1270 capture_.transient_suppressor_enabled); |
| 1182 return false; | |
| 1183 } | |
| 1184 | |
| 1185 bool AudioProcessingImpl::output_copy_needed() const { | |
| 1186 // Check if we've upmixed or downmixed the audio. | |
| 1187 return ((formats_.api_format.output_stream().num_channels() != | |
| 1188 formats_.api_format.input_stream().num_channels()) || | |
| 1189 is_fwd_processed() || capture_.transient_suppressor_enabled || | |
| 1190 capture_nonlocked_.level_controller_enabled); | |
| 1191 } | |
| 1192 | |
| 1193 bool AudioProcessingImpl::fwd_synthesis_needed() const { | |
| 1194 return (is_fwd_processed() && | |
| 1195 is_multi_band(capture_nonlocked_.fwd_proc_format.sample_rate_hz())); | |
| 1196 } | |
| 1197 | |
| 1198 bool AudioProcessingImpl::fwd_analysis_needed() const { | |
| 1199 if (!is_fwd_processed() && | |
| 1200 !public_submodules_->voice_detection->is_enabled() && | |
| 1201 !capture_.transient_suppressor_enabled) { | |
| 1202 // Only public_submodules_->level_estimator is enabled. | |
| 1203 return false; | |
| 1204 } else if (is_multi_band( | |
| 1205 capture_nonlocked_.fwd_proc_format.sample_rate_hz())) { | |
| 1206 // Something besides public_submodules_->level_estimator is enabled, and we | |
| 1207 // have super-wb. | |
| 1208 return true; | |
| 1209 } | |
| 1210 return false; | |
| 1211 } | |
| 1212 | |
| 1213 bool AudioProcessingImpl::is_rev_processed() const { | |
| 1214 #if WEBRTC_INTELLIGIBILITY_ENHANCER | |
| 1215 return capture_nonlocked_.intelligibility_enabled; | |
| 1216 #else | |
| 1217 return false; | |
| 1218 #endif | |
| 1219 } | |
| 1220 | |
| 1221 bool AudioProcessingImpl::rev_synthesis_needed() const { | |
| 1222 return (is_rev_processed() && | |
| 1223 is_multi_band(formats_.rev_proc_format.sample_rate_hz())); | |
| 1224 } | |
| 1225 | |
| 1226 bool AudioProcessingImpl::rev_analysis_needed() const { | |
| 1227 return is_multi_band(formats_.rev_proc_format.sample_rate_hz()) && | |
| 1228 (is_rev_processed() || | |
| 1229 public_submodules_->echo_cancellation | |
| 1230 ->is_enabled_render_side_query() || | |
| 1231 public_submodules_->echo_control_mobile | |
| 1232 ->is_enabled_render_side_query() || | |
| 1233 public_submodules_->gain_control->is_enabled_render_side_query()); | |
| 1234 } | |
| 1235 | |
| 1236 bool AudioProcessingImpl::render_check_rev_conversion_needed() const { | |
| 1237 return rev_conversion_needed(); | |
| 1238 } | |
| 1239 | |
| 1240 bool AudioProcessingImpl::rev_conversion_needed() const { | |
| 1241 return (formats_.api_format.reverse_input_stream() != | |
| 1242 formats_.api_format.reverse_output_stream()); | |
| 1243 } | 1271 } |
| 1244 | 1272 |
| 1245 void AudioProcessingImpl::InitializeExperimentalAgc() { | 1273 void AudioProcessingImpl::InitializeExperimentalAgc() { |
| 1246 if (constants_.use_experimental_agc) { | 1274 if (constants_.use_experimental_agc) { |
| 1247 if (!private_submodules_->agc_manager.get()) { | 1275 if (!private_submodules_->agc_manager.get()) { |
| 1248 private_submodules_->agc_manager.reset(new AgcManagerDirect( | 1276 private_submodules_->agc_manager.reset(new AgcManagerDirect( |
| 1249 public_submodules_->gain_control.get(), | 1277 public_submodules_->gain_control.get(), |
| 1250 public_submodules_->gain_control_for_experimental_agc.get(), | 1278 public_submodules_->gain_control_for_experimental_agc.get(), |
| 1251 constants_.agc_startup_min_volume)); | 1279 constants_.agc_startup_min_volume)); |
| 1252 } | 1280 } |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1561 fwd_proc_format(kSampleRate16kHz), | 1589 fwd_proc_format(kSampleRate16kHz), |
| 1562 split_rate(kSampleRate16kHz) {} | 1590 split_rate(kSampleRate16kHz) {} |
| 1563 | 1591 |
| 1564 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; | 1592 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; |
| 1565 | 1593 |
| 1566 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; | 1594 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; |
| 1567 | 1595 |
| 1568 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; | 1596 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; |
| 1569 | 1597 |
| 1570 } // namespace webrtc | 1598 } // namespace webrtc |
| OLD | NEW |