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 15 matching lines...) Expand all Loading... |
26 #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" | 26 #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" |
27 #include "webrtc/modules/audio_processing/common.h" | 27 #include "webrtc/modules/audio_processing/common.h" |
28 #include "webrtc/modules/audio_processing/echo_cancellation_impl.h" | 28 #include "webrtc/modules/audio_processing/echo_cancellation_impl.h" |
29 #include "webrtc/modules/audio_processing/echo_control_mobile_impl.h" | 29 #include "webrtc/modules/audio_processing/echo_control_mobile_impl.h" |
30 #include "webrtc/modules/audio_processing/gain_control_for_experimental_agc.h" | 30 #include "webrtc/modules/audio_processing/gain_control_for_experimental_agc.h" |
31 #include "webrtc/modules/audio_processing/gain_control_impl.h" | 31 #include "webrtc/modules/audio_processing/gain_control_impl.h" |
32 #include "webrtc/modules/audio_processing/high_pass_filter_impl.h" | 32 #include "webrtc/modules/audio_processing/high_pass_filter_impl.h" |
33 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc
er.h" | 33 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc
er.h" |
34 #include "webrtc/modules/audio_processing/level_estimator_impl.h" | 34 #include "webrtc/modules/audio_processing/level_estimator_impl.h" |
35 #include "webrtc/modules/audio_processing/noise_suppression_impl.h" | 35 #include "webrtc/modules/audio_processing/noise_suppression_impl.h" |
36 #include "webrtc/modules/audio_processing/processing_component.h" | |
37 #include "webrtc/modules/audio_processing/transient/transient_suppressor.h" | 36 #include "webrtc/modules/audio_processing/transient/transient_suppressor.h" |
38 #include "webrtc/modules/audio_processing/voice_detection_impl.h" | 37 #include "webrtc/modules/audio_processing/voice_detection_impl.h" |
39 #include "webrtc/modules/include/module_common_types.h" | 38 #include "webrtc/modules/include/module_common_types.h" |
40 #include "webrtc/system_wrappers/include/file_wrapper.h" | 39 #include "webrtc/system_wrappers/include/file_wrapper.h" |
41 #include "webrtc/system_wrappers/include/logging.h" | 40 #include "webrtc/system_wrappers/include/logging.h" |
42 #include "webrtc/system_wrappers/include/metrics.h" | 41 #include "webrtc/system_wrappers/include/metrics.h" |
43 | 42 |
44 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 43 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
45 // Files generated at build-time by the protobuf compiler. | 44 // Files generated at build-time by the protobuf compiler. |
46 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 45 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 93 |
95 // Accessed internally from both render and capture. | 94 // Accessed internally from both render and capture. |
96 std::unique_ptr<TransientSuppressor> transient_suppressor; | 95 std::unique_ptr<TransientSuppressor> transient_suppressor; |
97 std::unique_ptr<IntelligibilityEnhancer> intelligibility_enhancer; | 96 std::unique_ptr<IntelligibilityEnhancer> intelligibility_enhancer; |
98 }; | 97 }; |
99 | 98 |
100 struct AudioProcessingImpl::ApmPrivateSubmodules { | 99 struct AudioProcessingImpl::ApmPrivateSubmodules { |
101 explicit ApmPrivateSubmodules(Beamformer<float>* beamformer) | 100 explicit ApmPrivateSubmodules(Beamformer<float>* beamformer) |
102 : beamformer(beamformer) {} | 101 : beamformer(beamformer) {} |
103 // Accessed internally from capture or during initialization | 102 // Accessed internally from capture or during initialization |
104 std::list<ProcessingComponent*> component_list; | |
105 std::unique_ptr<Beamformer<float>> beamformer; | 103 std::unique_ptr<Beamformer<float>> beamformer; |
106 std::unique_ptr<AgcManagerDirect> agc_manager; | 104 std::unique_ptr<AgcManagerDirect> agc_manager; |
107 }; | 105 }; |
108 | 106 |
109 const int AudioProcessing::kNativeSampleRatesHz[] = { | 107 const int AudioProcessing::kNativeSampleRatesHz[] = { |
110 AudioProcessing::kSampleRate8kHz, | 108 AudioProcessing::kSampleRate8kHz, |
111 AudioProcessing::kSampleRate16kHz, | 109 AudioProcessing::kSampleRate16kHz, |
112 #ifdef WEBRTC_ARCH_ARM_FAMILY | 110 #ifdef WEBRTC_ARCH_ARM_FAMILY |
113 AudioProcessing::kSampleRate32kHz}; | 111 AudioProcessing::kSampleRate32kHz}; |
114 #else | 112 #else |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 188 |
191 SetExtraOptions(config); | 189 SetExtraOptions(config); |
192 } | 190 } |
193 | 191 |
194 AudioProcessingImpl::~AudioProcessingImpl() { | 192 AudioProcessingImpl::~AudioProcessingImpl() { |
195 // Depends on gain_control_ and | 193 // Depends on gain_control_ and |
196 // public_submodules_->gain_control_for_experimental_agc. | 194 // public_submodules_->gain_control_for_experimental_agc. |
197 private_submodules_->agc_manager.reset(); | 195 private_submodules_->agc_manager.reset(); |
198 // Depends on gain_control_. | 196 // Depends on gain_control_. |
199 public_submodules_->gain_control_for_experimental_agc.reset(); | 197 public_submodules_->gain_control_for_experimental_agc.reset(); |
200 while (!private_submodules_->component_list.empty()) { | |
201 ProcessingComponent* component = | |
202 private_submodules_->component_list.front(); | |
203 component->Destroy(); | |
204 delete component; | |
205 private_submodules_->component_list.pop_front(); | |
206 } | |
207 | 198 |
208 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 199 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
209 if (debug_dump_.debug_file->Open()) { | 200 if (debug_dump_.debug_file->Open()) { |
210 debug_dump_.debug_file->CloseFile(); | 201 debug_dump_.debug_file->CloseFile(); |
211 } | 202 } |
212 #endif | 203 #endif |
213 } | 204 } |
214 | 205 |
215 int AudioProcessingImpl::Initialize() { | 206 int AudioProcessingImpl::Initialize() { |
216 // Run in a single-threaded manner during initialization. | 207 // Run in a single-threaded manner during initialization. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 render_.render_audio.reset(nullptr); | 292 render_.render_audio.reset(nullptr); |
302 render_.render_converter.reset(nullptr); | 293 render_.render_converter.reset(nullptr); |
303 } | 294 } |
304 capture_.capture_audio.reset( | 295 capture_.capture_audio.reset( |
305 new AudioBuffer(formats_.api_format.input_stream().num_frames(), | 296 new AudioBuffer(formats_.api_format.input_stream().num_frames(), |
306 formats_.api_format.input_stream().num_channels(), | 297 formats_.api_format.input_stream().num_channels(), |
307 capture_nonlocked_.fwd_proc_format.num_frames(), | 298 capture_nonlocked_.fwd_proc_format.num_frames(), |
308 fwd_audio_buffer_channels, | 299 fwd_audio_buffer_channels, |
309 formats_.api_format.output_stream().num_frames())); | 300 formats_.api_format.output_stream().num_frames())); |
310 | 301 |
311 // Initialize all components. | |
312 for (auto item : private_submodules_->component_list) { | |
313 int err = item->Initialize(); | |
314 if (err != kNoError) { | |
315 return err; | |
316 } | |
317 } | |
318 | |
319 InitializeGainController(); | 302 InitializeGainController(); |
320 InitializeEchoCanceller(); | 303 InitializeEchoCanceller(); |
321 InitializeEchoControlMobile(); | 304 InitializeEchoControlMobile(); |
322 InitializeExperimentalAgc(); | 305 InitializeExperimentalAgc(); |
323 InitializeTransient(); | 306 InitializeTransient(); |
324 InitializeBeamformer(); | 307 InitializeBeamformer(); |
325 InitializeIntelligibility(); | 308 InitializeIntelligibility(); |
326 InitializeHighPassFilter(); | 309 InitializeHighPassFilter(); |
327 InitializeNoiseSuppression(); | 310 InitializeNoiseSuppression(); |
328 InitializeLevelEstimator(); | 311 InitializeLevelEstimator(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 capture_nonlocked_.fwd_proc_format.sample_rate_hz(); | 392 capture_nonlocked_.fwd_proc_format.sample_rate_hz(); |
410 } | 393 } |
411 | 394 |
412 return InitializeLocked(); | 395 return InitializeLocked(); |
413 } | 396 } |
414 | 397 |
415 void AudioProcessingImpl::SetExtraOptions(const Config& config) { | 398 void AudioProcessingImpl::SetExtraOptions(const Config& config) { |
416 // Run in a single-threaded manner when setting the extra options. | 399 // Run in a single-threaded manner when setting the extra options. |
417 rtc::CritScope cs_render(&crit_render_); | 400 rtc::CritScope cs_render(&crit_render_); |
418 rtc::CritScope cs_capture(&crit_capture_); | 401 rtc::CritScope cs_capture(&crit_capture_); |
419 for (auto item : private_submodules_->component_list) { | |
420 item->SetExtraOptions(config); | |
421 } | |
422 | 402 |
423 public_submodules_->echo_cancellation->SetExtraOptions(config); | 403 public_submodules_->echo_cancellation->SetExtraOptions(config); |
424 | 404 |
425 if (capture_.transient_suppressor_enabled != | 405 if (capture_.transient_suppressor_enabled != |
426 config.Get<ExperimentalNs>().enabled) { | 406 config.Get<ExperimentalNs>().enabled) { |
427 capture_.transient_suppressor_enabled = | 407 capture_.transient_suppressor_enabled = |
428 config.Get<ExperimentalNs>().enabled; | 408 config.Get<ExperimentalNs>().enabled; |
429 InitializeTransient(); | 409 InitializeTransient(); |
430 } | 410 } |
431 | 411 |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 // modify the data. | 1104 // modify the data. |
1125 if (capture_nonlocked_.beamformer_enabled || | 1105 if (capture_nonlocked_.beamformer_enabled || |
1126 public_submodules_->high_pass_filter->is_enabled() || | 1106 public_submodules_->high_pass_filter->is_enabled() || |
1127 public_submodules_->noise_suppression->is_enabled() || | 1107 public_submodules_->noise_suppression->is_enabled() || |
1128 public_submodules_->echo_cancellation->is_enabled() || | 1108 public_submodules_->echo_cancellation->is_enabled() || |
1129 public_submodules_->echo_control_mobile->is_enabled() || | 1109 public_submodules_->echo_control_mobile->is_enabled() || |
1130 public_submodules_->gain_control->is_enabled()) { | 1110 public_submodules_->gain_control->is_enabled()) { |
1131 return true; | 1111 return true; |
1132 } | 1112 } |
1133 | 1113 |
1134 // All of the private submodules modify the data. | |
1135 for (auto item : private_submodules_->component_list) { | |
1136 if (item->is_component_enabled()) { | |
1137 return true; | |
1138 } | |
1139 } | |
1140 | |
1141 // The capture data is otherwise unchanged. | 1114 // The capture data is otherwise unchanged. |
1142 return false; | 1115 return false; |
1143 } | 1116 } |
1144 | 1117 |
1145 bool AudioProcessingImpl::output_copy_needed(bool is_data_processed) const { | 1118 bool AudioProcessingImpl::output_copy_needed(bool is_data_processed) const { |
1146 // Check if we've upmixed or downmixed the audio. | 1119 // Check if we've upmixed or downmixed the audio. |
1147 return ((formats_.api_format.output_stream().num_channels() != | 1120 return ((formats_.api_format.output_stream().num_channels() != |
1148 formats_.api_format.input_stream().num_channels()) || | 1121 formats_.api_format.input_stream().num_channels()) || |
1149 is_data_processed || capture_.transient_suppressor_enabled); | 1122 is_data_processed || capture_.transient_suppressor_enabled); |
1150 } | 1123 } |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config); | 1430 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config); |
1458 | 1431 |
1459 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 1432 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
1460 &debug_dump_.num_bytes_left_for_log_, | 1433 &debug_dump_.num_bytes_left_for_log_, |
1461 &crit_debug_, &debug_dump_.capture)); | 1434 &crit_debug_, &debug_dump_.capture)); |
1462 return kNoError; | 1435 return kNoError; |
1463 } | 1436 } |
1464 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1437 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
1465 | 1438 |
1466 } // namespace webrtc | 1439 } // namespace webrtc |
OLD | NEW |