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 13 matching lines...) Expand all Loading... |
24 #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h" | 24 #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h" |
25 #include "webrtc/modules/audio_processing/audio_buffer.h" | 25 #include "webrtc/modules/audio_processing/audio_buffer.h" |
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_controller/level_controller.h" |
34 #include "webrtc/modules/audio_processing/level_estimator_impl.h" | 35 #include "webrtc/modules/audio_processing/level_estimator_impl.h" |
35 #include "webrtc/modules/audio_processing/noise_suppression_impl.h" | 36 #include "webrtc/modules/audio_processing/noise_suppression_impl.h" |
36 #include "webrtc/modules/audio_processing/transient/transient_suppressor.h" | 37 #include "webrtc/modules/audio_processing/transient/transient_suppressor.h" |
37 #include "webrtc/modules/audio_processing/voice_detection_impl.h" | 38 #include "webrtc/modules/audio_processing/voice_detection_impl.h" |
38 #include "webrtc/modules/include/module_common_types.h" | 39 #include "webrtc/modules/include/module_common_types.h" |
39 #include "webrtc/system_wrappers/include/file_wrapper.h" | 40 #include "webrtc/system_wrappers/include/file_wrapper.h" |
40 #include "webrtc/system_wrappers/include/logging.h" | 41 #include "webrtc/system_wrappers/include/logging.h" |
41 #include "webrtc/system_wrappers/include/metrics.h" | 42 #include "webrtc/system_wrappers/include/metrics.h" |
42 | 43 |
43 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 44 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 std::unique_ptr<TransientSuppressor> transient_suppressor; | 126 std::unique_ptr<TransientSuppressor> transient_suppressor; |
126 std::unique_ptr<IntelligibilityEnhancer> intelligibility_enhancer; | 127 std::unique_ptr<IntelligibilityEnhancer> intelligibility_enhancer; |
127 }; | 128 }; |
128 | 129 |
129 struct AudioProcessingImpl::ApmPrivateSubmodules { | 130 struct AudioProcessingImpl::ApmPrivateSubmodules { |
130 explicit ApmPrivateSubmodules(Beamformer<float>* beamformer) | 131 explicit ApmPrivateSubmodules(Beamformer<float>* beamformer) |
131 : beamformer(beamformer) {} | 132 : beamformer(beamformer) {} |
132 // Accessed internally from capture or during initialization | 133 // Accessed internally from capture or during initialization |
133 std::unique_ptr<Beamformer<float>> beamformer; | 134 std::unique_ptr<Beamformer<float>> beamformer; |
134 std::unique_ptr<AgcManagerDirect> agc_manager; | 135 std::unique_ptr<AgcManagerDirect> agc_manager; |
| 136 std::unique_ptr<LevelController> level_controller; |
135 }; | 137 }; |
136 | 138 |
137 AudioProcessing* AudioProcessing::Create() { | 139 AudioProcessing* AudioProcessing::Create() { |
138 Config config; | 140 Config config; |
139 return Create(config, nullptr); | 141 return Create(config, nullptr); |
140 } | 142 } |
141 | 143 |
142 AudioProcessing* AudioProcessing::Create(const Config& config) { | 144 AudioProcessing* AudioProcessing::Create(const Config& config) { |
143 return Create(config, nullptr); | 145 return Create(config, nullptr); |
144 } | 146 } |
(...skipping 23 matching lines...) Expand all Loading... |
168 config.Get<ExperimentalAgc>().enabled), | 170 config.Get<ExperimentalAgc>().enabled), |
169 #endif | 171 #endif |
170 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 172 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
171 capture_(false, | 173 capture_(false, |
172 #else | 174 #else |
173 capture_(config.Get<ExperimentalNs>().enabled, | 175 capture_(config.Get<ExperimentalNs>().enabled, |
174 #endif | 176 #endif |
175 config.Get<Beamforming>().array_geometry, | 177 config.Get<Beamforming>().array_geometry, |
176 config.Get<Beamforming>().target_direction), | 178 config.Get<Beamforming>().target_direction), |
177 capture_nonlocked_(config.Get<Beamforming>().enabled, | 179 capture_nonlocked_(config.Get<Beamforming>().enabled, |
178 config.Get<Intelligibility>().enabled) | 180 config.Get<Intelligibility>().enabled, |
179 { | 181 config.Get<LevelControl>().enabled) { |
180 { | 182 { |
181 rtc::CritScope cs_render(&crit_render_); | 183 rtc::CritScope cs_render(&crit_render_); |
182 rtc::CritScope cs_capture(&crit_capture_); | 184 rtc::CritScope cs_capture(&crit_capture_); |
183 | 185 |
184 public_submodules_->echo_cancellation.reset( | 186 public_submodules_->echo_cancellation.reset( |
185 new EchoCancellationImpl(&crit_render_, &crit_capture_)); | 187 new EchoCancellationImpl(&crit_render_, &crit_capture_)); |
186 public_submodules_->echo_control_mobile.reset( | 188 public_submodules_->echo_control_mobile.reset( |
187 new EchoControlMobileImpl(&crit_render_, &crit_capture_)); | 189 new EchoControlMobileImpl(&crit_render_, &crit_capture_)); |
188 public_submodules_->gain_control.reset( | 190 public_submodules_->gain_control.reset( |
189 new GainControlImpl(&crit_capture_, &crit_capture_)); | 191 new GainControlImpl(&crit_capture_, &crit_capture_)); |
190 public_submodules_->high_pass_filter.reset( | 192 public_submodules_->high_pass_filter.reset( |
191 new HighPassFilterImpl(&crit_capture_)); | 193 new HighPassFilterImpl(&crit_capture_)); |
192 public_submodules_->level_estimator.reset( | 194 public_submodules_->level_estimator.reset( |
193 new LevelEstimatorImpl(&crit_capture_)); | 195 new LevelEstimatorImpl(&crit_capture_)); |
194 public_submodules_->noise_suppression.reset( | 196 public_submodules_->noise_suppression.reset( |
195 new NoiseSuppressionImpl(&crit_capture_)); | 197 new NoiseSuppressionImpl(&crit_capture_)); |
196 public_submodules_->voice_detection.reset( | 198 public_submodules_->voice_detection.reset( |
197 new VoiceDetectionImpl(&crit_capture_)); | 199 new VoiceDetectionImpl(&crit_capture_)); |
198 public_submodules_->gain_control_for_experimental_agc.reset( | 200 public_submodules_->gain_control_for_experimental_agc.reset( |
199 new GainControlForExperimentalAgc( | 201 new GainControlForExperimentalAgc( |
200 public_submodules_->gain_control.get(), &crit_capture_)); | 202 public_submodules_->gain_control.get(), &crit_capture_)); |
| 203 |
| 204 private_submodules_->level_controller.reset(new LevelController()); |
201 } | 205 } |
202 | 206 |
203 SetExtraOptions(config); | 207 SetExtraOptions(config); |
204 } | 208 } |
205 | 209 |
206 AudioProcessingImpl::~AudioProcessingImpl() { | 210 AudioProcessingImpl::~AudioProcessingImpl() { |
207 // Depends on gain_control_ and | 211 // Depends on gain_control_ and |
208 // public_submodules_->gain_control_for_experimental_agc. | 212 // public_submodules_->gain_control_for_experimental_agc. |
209 private_submodules_->agc_manager.reset(); | 213 private_submodules_->agc_manager.reset(); |
210 // Depends on gain_control_. | 214 // Depends on gain_control_. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 InitializeEchoCanceller(); | 319 InitializeEchoCanceller(); |
316 InitializeEchoControlMobile(); | 320 InitializeEchoControlMobile(); |
317 InitializeExperimentalAgc(); | 321 InitializeExperimentalAgc(); |
318 InitializeTransient(); | 322 InitializeTransient(); |
319 InitializeBeamformer(); | 323 InitializeBeamformer(); |
320 InitializeIntelligibility(); | 324 InitializeIntelligibility(); |
321 InitializeHighPassFilter(); | 325 InitializeHighPassFilter(); |
322 InitializeNoiseSuppression(); | 326 InitializeNoiseSuppression(); |
323 InitializeLevelEstimator(); | 327 InitializeLevelEstimator(); |
324 InitializeVoiceDetection(); | 328 InitializeVoiceDetection(); |
| 329 InitializeLevelController(); |
325 | 330 |
326 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 331 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
327 if (debug_dump_.debug_file->is_open()) { | 332 if (debug_dump_.debug_file->is_open()) { |
328 int err = WriteInitMessage(); | 333 int err = WriteInitMessage(); |
329 if (err != kNoError) { | 334 if (err != kNoError) { |
330 return err; | 335 return err; |
331 } | 336 } |
332 } | 337 } |
333 #endif | 338 #endif |
334 | 339 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 406 |
402 public_submodules_->echo_cancellation->SetExtraOptions(config); | 407 public_submodules_->echo_cancellation->SetExtraOptions(config); |
403 | 408 |
404 if (capture_.transient_suppressor_enabled != | 409 if (capture_.transient_suppressor_enabled != |
405 config.Get<ExperimentalNs>().enabled) { | 410 config.Get<ExperimentalNs>().enabled) { |
406 capture_.transient_suppressor_enabled = | 411 capture_.transient_suppressor_enabled = |
407 config.Get<ExperimentalNs>().enabled; | 412 config.Get<ExperimentalNs>().enabled; |
408 InitializeTransient(); | 413 InitializeTransient(); |
409 } | 414 } |
410 | 415 |
| 416 if (capture_nonlocked_.level_controller_enabled != |
| 417 config.Get<LevelControl>().enabled) { |
| 418 capture_nonlocked_.level_controller_enabled = |
| 419 config.Get<LevelControl>().enabled; |
| 420 LOG(LS_INFO) << "Level controller activated: " |
| 421 << config.Get<LevelControl>().enabled; |
| 422 |
| 423 // TODO(peah): Remove the explicit deactivation once |
| 424 // the upcoming changes for the level controller tuning |
| 425 // are landed. |
| 426 capture_nonlocked_.level_controller_enabled = false; |
| 427 InitializeLevelController(); |
| 428 } |
| 429 |
411 if(capture_nonlocked_.intelligibility_enabled != | 430 if(capture_nonlocked_.intelligibility_enabled != |
412 config.Get<Intelligibility>().enabled) { | 431 config.Get<Intelligibility>().enabled) { |
413 capture_nonlocked_.intelligibility_enabled = | 432 capture_nonlocked_.intelligibility_enabled = |
414 config.Get<Intelligibility>().enabled; | 433 config.Get<Intelligibility>().enabled; |
415 InitializeIntelligibility(); | 434 InitializeIntelligibility(); |
416 } | 435 } |
417 | 436 |
418 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 437 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
419 if (capture_nonlocked_.beamformer_enabled != | 438 if (capture_nonlocked_.beamformer_enabled != |
420 config.Get<Beamforming>().enabled) { | 439 config.Get<Beamforming>().enabled) { |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 ? private_submodules_->agc_manager->voice_probability() | 771 ? private_submodules_->agc_manager->voice_probability() |
753 : 1.f; | 772 : 1.f; |
754 | 773 |
755 public_submodules_->transient_suppressor->Suppress( | 774 public_submodules_->transient_suppressor->Suppress( |
756 ca->channels_f()[0], ca->num_frames(), ca->num_channels(), | 775 ca->channels_f()[0], ca->num_frames(), ca->num_channels(), |
757 ca->split_bands_const_f(0)[kBand0To8kHz], ca->num_frames_per_band(), | 776 ca->split_bands_const_f(0)[kBand0To8kHz], ca->num_frames_per_band(), |
758 ca->keyboard_data(), ca->num_keyboard_frames(), voice_probability, | 777 ca->keyboard_data(), ca->num_keyboard_frames(), voice_probability, |
759 capture_.key_pressed); | 778 capture_.key_pressed); |
760 } | 779 } |
761 | 780 |
| 781 if (capture_nonlocked_.level_controller_enabled) { |
| 782 private_submodules_->level_controller->Process(ca); |
| 783 } |
| 784 |
762 // The level estimator operates on the recombined data. | 785 // The level estimator operates on the recombined data. |
763 public_submodules_->level_estimator->ProcessStream(ca); | 786 public_submodules_->level_estimator->ProcessStream(ca); |
764 | 787 |
765 capture_.was_stream_delay_set = false; | 788 capture_.was_stream_delay_set = false; |
766 return kNoError; | 789 return kNoError; |
767 } | 790 } |
768 | 791 |
769 int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data, | 792 int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data, |
770 size_t samples_per_channel, | 793 size_t samples_per_channel, |
771 int rev_sample_rate_hz, | 794 int rev_sample_rate_hz, |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 } | 1134 } |
1112 | 1135 |
1113 // The capture data is otherwise unchanged. | 1136 // The capture data is otherwise unchanged. |
1114 return false; | 1137 return false; |
1115 } | 1138 } |
1116 | 1139 |
1117 bool AudioProcessingImpl::output_copy_needed() const { | 1140 bool AudioProcessingImpl::output_copy_needed() const { |
1118 // Check if we've upmixed or downmixed the audio. | 1141 // Check if we've upmixed or downmixed the audio. |
1119 return ((formats_.api_format.output_stream().num_channels() != | 1142 return ((formats_.api_format.output_stream().num_channels() != |
1120 formats_.api_format.input_stream().num_channels()) || | 1143 formats_.api_format.input_stream().num_channels()) || |
1121 is_fwd_processed() || capture_.transient_suppressor_enabled); | 1144 is_fwd_processed() || capture_.transient_suppressor_enabled || |
| 1145 capture_nonlocked_.level_controller_enabled); |
1122 } | 1146 } |
1123 | 1147 |
1124 bool AudioProcessingImpl::fwd_synthesis_needed() const { | 1148 bool AudioProcessingImpl::fwd_synthesis_needed() const { |
1125 return (is_fwd_processed() && | 1149 return (is_fwd_processed() && |
1126 is_multi_band(capture_nonlocked_.fwd_proc_format.sample_rate_hz())); | 1150 is_multi_band(capture_nonlocked_.fwd_proc_format.sample_rate_hz())); |
1127 } | 1151 } |
1128 | 1152 |
1129 bool AudioProcessingImpl::fwd_analysis_needed() const { | 1153 bool AudioProcessingImpl::fwd_analysis_needed() const { |
1130 if (!is_fwd_processed() && | 1154 if (!is_fwd_processed() && |
1131 !public_submodules_->voice_detection->is_enabled() && | 1155 !public_submodules_->voice_detection->is_enabled() && |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 public_submodules_->echo_control_mobile->Initialize( | 1264 public_submodules_->echo_control_mobile->Initialize( |
1241 proc_split_sample_rate_hz(), | 1265 proc_split_sample_rate_hz(), |
1242 num_reverse_channels(), | 1266 num_reverse_channels(), |
1243 num_output_channels()); | 1267 num_output_channels()); |
1244 } | 1268 } |
1245 | 1269 |
1246 void AudioProcessingImpl::InitializeLevelEstimator() { | 1270 void AudioProcessingImpl::InitializeLevelEstimator() { |
1247 public_submodules_->level_estimator->Initialize(); | 1271 public_submodules_->level_estimator->Initialize(); |
1248 } | 1272 } |
1249 | 1273 |
| 1274 void AudioProcessingImpl::InitializeLevelController() { |
| 1275 private_submodules_->level_controller->Initialize(proc_sample_rate_hz()); |
| 1276 } |
| 1277 |
1250 void AudioProcessingImpl::InitializeVoiceDetection() { | 1278 void AudioProcessingImpl::InitializeVoiceDetection() { |
1251 public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz()); | 1279 public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz()); |
1252 } | 1280 } |
1253 | 1281 |
1254 void AudioProcessingImpl::MaybeUpdateHistograms() { | 1282 void AudioProcessingImpl::MaybeUpdateHistograms() { |
1255 static const int kMinDiffDelayMs = 60; | 1283 static const int kMinDiffDelayMs = 60; |
1256 | 1284 |
1257 if (echo_cancellation()->is_enabled()) { | 1285 if (echo_cancellation()->is_enabled()) { |
1258 // Activate delay_jumps_ counters if we know echo_cancellation is runnning. | 1286 // Activate delay_jumps_ counters if we know echo_cancellation is runnning. |
1259 // If a stream has echo we know that the echo_cancellation is in process. | 1287 // If a stream has echo we know that the echo_cancellation is in process. |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 | 1462 |
1435 config.set_transient_suppression_enabled( | 1463 config.set_transient_suppression_enabled( |
1436 capture_.transient_suppressor_enabled); | 1464 capture_.transient_suppressor_enabled); |
1437 config.set_intelligibility_enhancer_enabled( | 1465 config.set_intelligibility_enhancer_enabled( |
1438 capture_nonlocked_.intelligibility_enabled); | 1466 capture_nonlocked_.intelligibility_enabled); |
1439 | 1467 |
1440 std::string experiments_description = | 1468 std::string experiments_description = |
1441 public_submodules_->echo_cancellation->GetExperimentsDescription(); | 1469 public_submodules_->echo_cancellation->GetExperimentsDescription(); |
1442 // TODO(peah): Add semicolon-separated concatenations of experiment | 1470 // TODO(peah): Add semicolon-separated concatenations of experiment |
1443 // descriptions for other submodules. | 1471 // descriptions for other submodules. |
| 1472 if (capture_nonlocked_.level_controller_enabled) { |
| 1473 experiments_description += "LevelController;"; |
| 1474 } |
1444 config.set_experiments_description(experiments_description); | 1475 config.set_experiments_description(experiments_description); |
1445 | 1476 |
1446 std::string serialized_config = config.SerializeAsString(); | 1477 std::string serialized_config = config.SerializeAsString(); |
1447 if (!forced && | 1478 if (!forced && |
1448 debug_dump_.capture.last_serialized_config == serialized_config) { | 1479 debug_dump_.capture.last_serialized_config == serialized_config) { |
1449 return kNoError; | 1480 return kNoError; |
1450 } | 1481 } |
1451 | 1482 |
1452 debug_dump_.capture.last_serialized_config = serialized_config; | 1483 debug_dump_.capture.last_serialized_config = serialized_config; |
1453 | 1484 |
1454 debug_dump_.capture.event_msg->set_type(audioproc::Event::CONFIG); | 1485 debug_dump_.capture.event_msg->set_type(audioproc::Event::CONFIG); |
1455 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config); | 1486 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config); |
1456 | 1487 |
1457 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 1488 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
1458 &debug_dump_.num_bytes_left_for_log_, | 1489 &debug_dump_.num_bytes_left_for_log_, |
1459 &crit_debug_, &debug_dump_.capture)); | 1490 &crit_debug_, &debug_dump_.capture)); |
1460 return kNoError; | 1491 return kNoError; |
1461 } | 1492 } |
1462 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1493 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
1463 | 1494 |
1464 } // namespace webrtc | 1495 } // namespace webrtc |
OLD | NEW |