| 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 #else | 219 #else |
| 220 config.Get<ExperimentalAgc>().enabled, | 220 config.Get<ExperimentalAgc>().enabled, |
| 221 #endif | 221 #endif |
| 222 config.Get<Intelligibility>().enabled), | 222 config.Get<Intelligibility>().enabled), |
| 223 | 223 |
| 224 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 224 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
| 225 capture_(false, | 225 capture_(false, |
| 226 #else | 226 #else |
| 227 capture_(config.Get<ExperimentalNs>().enabled, | 227 capture_(config.Get<ExperimentalNs>().enabled, |
| 228 #endif | 228 #endif |
| 229 config.Get<Beamforming>().enabled, | |
| 230 config.Get<Beamforming>().array_geometry, | 229 config.Get<Beamforming>().array_geometry, |
| 231 config.Get<Beamforming>().target_direction) | 230 config.Get<Beamforming>().target_direction), |
| 231 capture_nonlocked_(config.Get<Beamforming>().enabled) |
| 232 { | 232 { |
| 233 { | 233 { |
| 234 rtc::CritScope cs_render(&crit_render_); | 234 rtc::CritScope cs_render(&crit_render_); |
| 235 rtc::CritScope cs_capture(&crit_capture_); | 235 rtc::CritScope cs_capture(&crit_capture_); |
| 236 | 236 |
| 237 public_submodules_->echo_cancellation = | 237 public_submodules_->echo_cancellation = |
| 238 new EchoCancellationImpl(this, &crit_render_, &crit_capture_); | 238 new EchoCancellationImpl(this, &crit_render_, &crit_capture_); |
| 239 public_submodules_->echo_control_mobile = | 239 public_submodules_->echo_control_mobile = |
| 240 new EchoControlMobileImpl(this, &crit_render_, &crit_capture_); | 240 new EchoControlMobileImpl(this, &crit_render_, &crit_capture_); |
| 241 public_submodules_->gain_control = | 241 public_submodules_->gain_control = |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 if (processing_config == formats_.api_format) { | 338 if (processing_config == formats_.api_format) { |
| 339 return kNoError; | 339 return kNoError; |
| 340 } | 340 } |
| 341 | 341 |
| 342 rtc::CritScope cs_capture(&crit_capture_); | 342 rtc::CritScope cs_capture(&crit_capture_); |
| 343 return InitializeLocked(processing_config); | 343 return InitializeLocked(processing_config); |
| 344 } | 344 } |
| 345 | 345 |
| 346 int AudioProcessingImpl::InitializeLocked() { | 346 int AudioProcessingImpl::InitializeLocked() { |
| 347 const int fwd_audio_buffer_channels = | 347 const int fwd_audio_buffer_channels = |
| 348 capture_.beamformer_enabled | 348 capture_nonlocked_.beamformer_enabled |
| 349 ? formats_.api_format.input_stream().num_channels() | 349 ? formats_.api_format.input_stream().num_channels() |
| 350 : formats_.api_format.output_stream().num_channels(); | 350 : formats_.api_format.output_stream().num_channels(); |
| 351 const int rev_audio_buffer_out_num_frames = | 351 const int rev_audio_buffer_out_num_frames = |
| 352 formats_.api_format.reverse_output_stream().num_frames() == 0 | 352 formats_.api_format.reverse_output_stream().num_frames() == 0 |
| 353 ? formats_.rev_proc_format.num_frames() | 353 ? formats_.rev_proc_format.num_frames() |
| 354 : formats_.api_format.reverse_output_stream().num_frames(); | 354 : formats_.api_format.reverse_output_stream().num_frames(); |
| 355 if (formats_.api_format.reverse_input_stream().num_channels() > 0) { | 355 if (formats_.api_format.reverse_input_stream().num_channels() > 0) { |
| 356 render_.render_audio.reset(new AudioBuffer( | 356 render_.render_audio.reset(new AudioBuffer( |
| 357 formats_.api_format.reverse_input_stream().num_frames(), | 357 formats_.api_format.reverse_input_stream().num_frames(), |
| 358 formats_.api_format.reverse_input_stream().num_channels(), | 358 formats_.api_format.reverse_input_stream().num_channels(), |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 const int num_in_channels = config.input_stream().num_channels(); | 421 const int num_in_channels = config.input_stream().num_channels(); |
| 422 const int num_out_channels = config.output_stream().num_channels(); | 422 const int num_out_channels = config.output_stream().num_channels(); |
| 423 | 423 |
| 424 // Need at least one input channel. | 424 // Need at least one input channel. |
| 425 // Need either one output channel or as many outputs as there are inputs. | 425 // Need either one output channel or as many outputs as there are inputs. |
| 426 if (num_in_channels == 0 || | 426 if (num_in_channels == 0 || |
| 427 !(num_out_channels == 1 || num_out_channels == num_in_channels)) { | 427 !(num_out_channels == 1 || num_out_channels == num_in_channels)) { |
| 428 return kBadNumberChannelsError; | 428 return kBadNumberChannelsError; |
| 429 } | 429 } |
| 430 | 430 |
| 431 if (capture_.beamformer_enabled && | 431 if (capture_nonlocked_.beamformer_enabled && |
| 432 (static_cast<size_t>(num_in_channels) != capture_.array_geometry.size() || | 432 static_cast<size_t>(num_in_channels) != capture_.array_geometry.size()) { |
| 433 num_out_channels > 1)) { | |
| 434 return kBadNumberChannelsError; | 433 return kBadNumberChannelsError; |
| 435 } | 434 } |
| 436 | 435 |
| 437 formats_.api_format = config; | 436 formats_.api_format = config; |
| 438 | 437 |
| 439 // We process at the closest native rate >= min(input rate, output rate)... | 438 // We process at the closest native rate >= min(input rate, output rate)... |
| 440 const int min_proc_rate = | 439 const int min_proc_rate = |
| 441 std::min(formats_.api_format.input_stream().sample_rate_hz(), | 440 std::min(formats_.api_format.input_stream().sample_rate_hz(), |
| 442 formats_.api_format.output_stream().sample_rate_hz()); | 441 formats_.api_format.output_stream().sample_rate_hz()); |
| 443 int fwd_proc_rate; | 442 int fwd_proc_rate; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 } | 492 } |
| 494 | 493 |
| 495 if (capture_.transient_suppressor_enabled != | 494 if (capture_.transient_suppressor_enabled != |
| 496 config.Get<ExperimentalNs>().enabled) { | 495 config.Get<ExperimentalNs>().enabled) { |
| 497 capture_.transient_suppressor_enabled = | 496 capture_.transient_suppressor_enabled = |
| 498 config.Get<ExperimentalNs>().enabled; | 497 config.Get<ExperimentalNs>().enabled; |
| 499 InitializeTransient(); | 498 InitializeTransient(); |
| 500 } | 499 } |
| 501 | 500 |
| 502 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 501 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
| 503 if (capture_.beamformer_enabled != config.Get<Beamforming>().enabled) { | 502 if (capture_nonlocked_.beamformer_enabled != |
| 504 capture_.beamformer_enabled = config.Get<Beamforming>().enabled; | 503 config.Get<Beamforming>().enabled) { |
| 504 capture_nonlocked_.beamformer_enabled = config.Get<Beamforming>().enabled; |
| 505 if (config.Get<Beamforming>().array_geometry.size() > 1) { | 505 if (config.Get<Beamforming>().array_geometry.size() > 1) { |
| 506 capture_.array_geometry = config.Get<Beamforming>().array_geometry; | 506 capture_.array_geometry = config.Get<Beamforming>().array_geometry; |
| 507 } | 507 } |
| 508 capture_.target_direction = config.Get<Beamforming>().target_direction; | 508 capture_.target_direction = config.Get<Beamforming>().target_direction; |
| 509 InitializeBeamformer(); | 509 InitializeBeamformer(); |
| 510 } | 510 } |
| 511 #endif // WEBRTC_ANDROID_PLATFORM_BUILD | 511 #endif // WEBRTC_ANDROID_PLATFORM_BUILD |
| 512 } | 512 } |
| 513 | 513 |
| 514 int AudioProcessingImpl::input_sample_rate_hz() const { | 514 int AudioProcessingImpl::input_sample_rate_hz() const { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 530 int AudioProcessingImpl::num_reverse_channels() const { | 530 int AudioProcessingImpl::num_reverse_channels() const { |
| 531 // Used as callback from submodules, hence locking is not allowed. | 531 // Used as callback from submodules, hence locking is not allowed. |
| 532 return formats_.rev_proc_format.num_channels(); | 532 return formats_.rev_proc_format.num_channels(); |
| 533 } | 533 } |
| 534 | 534 |
| 535 int AudioProcessingImpl::num_input_channels() const { | 535 int AudioProcessingImpl::num_input_channels() const { |
| 536 // Used as callback from submodules, hence locking is not allowed. | 536 // Used as callback from submodules, hence locking is not allowed. |
| 537 return formats_.api_format.input_stream().num_channels(); | 537 return formats_.api_format.input_stream().num_channels(); |
| 538 } | 538 } |
| 539 | 539 |
| 540 int AudioProcessingImpl::num_proc_channels() const { |
| 541 // Used as callback from submodules, hence locking is not allowed. |
| 542 return capture_nonlocked_.beamformer_enabled ? 1 : num_output_channels(); |
| 543 } |
| 544 |
| 540 int AudioProcessingImpl::num_output_channels() const { | 545 int AudioProcessingImpl::num_output_channels() const { |
| 541 // Used as callback from submodules, hence locking is not allowed. | 546 // Used as callback from submodules, hence locking is not allowed. |
| 542 return formats_.api_format.output_stream().num_channels(); | 547 return formats_.api_format.output_stream().num_channels(); |
| 543 } | 548 } |
| 544 | 549 |
| 545 void AudioProcessingImpl::set_output_will_be_muted(bool muted) { | 550 void AudioProcessingImpl::set_output_will_be_muted(bool muted) { |
| 546 rtc::CritScope cs(&crit_capture_); | 551 rtc::CritScope cs(&crit_capture_); |
| 547 capture_.output_will_be_muted = muted; | 552 capture_.output_will_be_muted = muted; |
| 548 if (private_submodules_->agc_manager.get()) { | 553 if (private_submodules_->agc_manager.get()) { |
| 549 private_submodules_->agc_manager->SetCaptureMuted( | 554 private_submodules_->agc_manager->SetCaptureMuted( |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 if (analysis_needed(data_processed)) { | 769 if (analysis_needed(data_processed)) { |
| 765 ca->SplitIntoFrequencyBands(); | 770 ca->SplitIntoFrequencyBands(); |
| 766 } | 771 } |
| 767 | 772 |
| 768 if (constants_.intelligibility_enabled) { | 773 if (constants_.intelligibility_enabled) { |
| 769 public_submodules_->intelligibility_enhancer->AnalyzeCaptureAudio( | 774 public_submodules_->intelligibility_enhancer->AnalyzeCaptureAudio( |
| 770 ca->split_channels_f(kBand0To8kHz), capture_nonlocked_.split_rate, | 775 ca->split_channels_f(kBand0To8kHz), capture_nonlocked_.split_rate, |
| 771 ca->num_channels()); | 776 ca->num_channels()); |
| 772 } | 777 } |
| 773 | 778 |
| 774 if (capture_.beamformer_enabled) { | 779 if (capture_nonlocked_.beamformer_enabled) { |
| 775 private_submodules_->beamformer->ProcessChunk(*ca->split_data_f(), | 780 private_submodules_->beamformer->ProcessChunk(*ca->split_data_f(), |
| 776 ca->split_data_f()); | 781 ca->split_data_f()); |
| 777 ca->set_num_channels(1); | 782 ca->set_num_channels(1); |
| 778 } | 783 } |
| 779 | 784 |
| 780 public_submodules_->high_pass_filter->ProcessCaptureAudio(ca); | 785 public_submodules_->high_pass_filter->ProcessCaptureAudio(ca); |
| 781 RETURN_ON_ERR(public_submodules_->gain_control->AnalyzeCaptureAudio(ca)); | 786 RETURN_ON_ERR(public_submodules_->gain_control->AnalyzeCaptureAudio(ca)); |
| 782 public_submodules_->noise_suppression->AnalyzeCaptureAudio(ca); | 787 public_submodules_->noise_suppression->AnalyzeCaptureAudio(ca); |
| 783 RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessCaptureAudio(ca)); | 788 RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessCaptureAudio(ca)); |
| 784 | 789 |
| 785 if (public_submodules_->echo_control_mobile->is_enabled() && | 790 if (public_submodules_->echo_control_mobile->is_enabled() && |
| 786 public_submodules_->noise_suppression->is_enabled()) { | 791 public_submodules_->noise_suppression->is_enabled()) { |
| 787 ca->CopyLowPassToReference(); | 792 ca->CopyLowPassToReference(); |
| 788 } | 793 } |
| 789 public_submodules_->noise_suppression->ProcessCaptureAudio(ca); | 794 public_submodules_->noise_suppression->ProcessCaptureAudio(ca); |
| 790 RETURN_ON_ERR( | 795 RETURN_ON_ERR( |
| 791 public_submodules_->echo_control_mobile->ProcessCaptureAudio(ca)); | 796 public_submodules_->echo_control_mobile->ProcessCaptureAudio(ca)); |
| 792 public_submodules_->voice_detection->ProcessCaptureAudio(ca); | 797 public_submodules_->voice_detection->ProcessCaptureAudio(ca); |
| 793 | 798 |
| 794 if (constants_.use_new_agc && | 799 if (constants_.use_new_agc && |
| 795 public_submodules_->gain_control->is_enabled() && | 800 public_submodules_->gain_control->is_enabled() && |
| 796 (!capture_.beamformer_enabled || | 801 (!capture_nonlocked_.beamformer_enabled || |
| 797 private_submodules_->beamformer->is_target_present())) { | 802 private_submodules_->beamformer->is_target_present())) { |
| 798 private_submodules_->agc_manager->Process( | 803 private_submodules_->agc_manager->Process( |
| 799 ca->split_bands_const(0)[kBand0To8kHz], ca->num_frames_per_band(), | 804 ca->split_bands_const(0)[kBand0To8kHz], ca->num_frames_per_band(), |
| 800 capture_nonlocked_.split_rate); | 805 capture_nonlocked_.split_rate); |
| 801 } | 806 } |
| 802 RETURN_ON_ERR(public_submodules_->gain_control->ProcessCaptureAudio(ca)); | 807 RETURN_ON_ERR(public_submodules_->gain_control->ProcessCaptureAudio(ca)); |
| 803 | 808 |
| 804 if (synthesis_needed(data_processed)) { | 809 if (synthesis_needed(data_processed)) { |
| 805 ca->MergeFrequencyBands(); | 810 ca->MergeFrequencyBands(); |
| 806 } | 811 } |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 return public_submodules_->noise_suppression.get(); | 1181 return public_submodules_->noise_suppression.get(); |
| 1177 } | 1182 } |
| 1178 | 1183 |
| 1179 VoiceDetection* AudioProcessingImpl::voice_detection() const { | 1184 VoiceDetection* AudioProcessingImpl::voice_detection() const { |
| 1180 // Adding a lock here has no effect as it allows any access to the submodule | 1185 // Adding a lock here has no effect as it allows any access to the submodule |
| 1181 // from the returned pointer. | 1186 // from the returned pointer. |
| 1182 return public_submodules_->voice_detection.get(); | 1187 return public_submodules_->voice_detection.get(); |
| 1183 } | 1188 } |
| 1184 | 1189 |
| 1185 bool AudioProcessingImpl::is_data_processed() const { | 1190 bool AudioProcessingImpl::is_data_processed() const { |
| 1186 if (capture_.beamformer_enabled) { | 1191 if (capture_nonlocked_.beamformer_enabled) { |
| 1187 return true; | 1192 return true; |
| 1188 } | 1193 } |
| 1189 | 1194 |
| 1190 int enabled_count = 0; | 1195 int enabled_count = 0; |
| 1191 for (auto item : private_submodules_->component_list) { | 1196 for (auto item : private_submodules_->component_list) { |
| 1192 if (item->is_component_enabled()) { | 1197 if (item->is_component_enabled()) { |
| 1193 enabled_count++; | 1198 enabled_count++; |
| 1194 } | 1199 } |
| 1195 } | 1200 } |
| 1196 if (public_submodules_->high_pass_filter->is_enabled()) { | 1201 if (public_submodules_->high_pass_filter->is_enabled()) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1286 } | 1291 } |
| 1287 | 1292 |
| 1288 void AudioProcessingImpl::InitializeTransient() { | 1293 void AudioProcessingImpl::InitializeTransient() { |
| 1289 if (capture_.transient_suppressor_enabled) { | 1294 if (capture_.transient_suppressor_enabled) { |
| 1290 if (!public_submodules_->transient_suppressor.get()) { | 1295 if (!public_submodules_->transient_suppressor.get()) { |
| 1291 public_submodules_->transient_suppressor.reset(new TransientSuppressor()); | 1296 public_submodules_->transient_suppressor.reset(new TransientSuppressor()); |
| 1292 } | 1297 } |
| 1293 public_submodules_->transient_suppressor->Initialize( | 1298 public_submodules_->transient_suppressor->Initialize( |
| 1294 capture_nonlocked_.fwd_proc_format.sample_rate_hz(), | 1299 capture_nonlocked_.fwd_proc_format.sample_rate_hz(), |
| 1295 capture_nonlocked_.split_rate, | 1300 capture_nonlocked_.split_rate, |
| 1296 formats_.api_format.output_stream().num_channels()); | 1301 num_proc_channels()); |
| 1297 } | 1302 } |
| 1298 } | 1303 } |
| 1299 | 1304 |
| 1300 void AudioProcessingImpl::InitializeBeamformer() { | 1305 void AudioProcessingImpl::InitializeBeamformer() { |
| 1301 if (capture_.beamformer_enabled) { | 1306 if (capture_nonlocked_.beamformer_enabled) { |
| 1302 if (!private_submodules_->beamformer) { | 1307 if (!private_submodules_->beamformer) { |
| 1303 private_submodules_->beamformer.reset(new NonlinearBeamformer( | 1308 private_submodules_->beamformer.reset(new NonlinearBeamformer( |
| 1304 capture_.array_geometry, capture_.target_direction)); | 1309 capture_.array_geometry, capture_.target_direction)); |
| 1305 } | 1310 } |
| 1306 private_submodules_->beamformer->Initialize(kChunkSizeMs, | 1311 private_submodules_->beamformer->Initialize(kChunkSizeMs, |
| 1307 capture_nonlocked_.split_rate); | 1312 capture_nonlocked_.split_rate); |
| 1308 } | 1313 } |
| 1309 } | 1314 } |
| 1310 | 1315 |
| 1311 void AudioProcessingImpl::InitializeIntelligibility() { | 1316 void AudioProcessingImpl::InitializeIntelligibility() { |
| 1312 if (constants_.intelligibility_enabled) { | 1317 if (constants_.intelligibility_enabled) { |
| 1313 IntelligibilityEnhancer::Config config; | 1318 IntelligibilityEnhancer::Config config; |
| 1314 config.sample_rate_hz = capture_nonlocked_.split_rate; | 1319 config.sample_rate_hz = capture_nonlocked_.split_rate; |
| 1315 config.num_capture_channels = capture_.capture_audio->num_channels(); | 1320 config.num_capture_channels = capture_.capture_audio->num_channels(); |
| 1316 config.num_render_channels = render_.render_audio->num_channels(); | 1321 config.num_render_channels = render_.render_audio->num_channels(); |
| 1317 public_submodules_->intelligibility_enhancer.reset( | 1322 public_submodules_->intelligibility_enhancer.reset( |
| 1318 new IntelligibilityEnhancer(config)); | 1323 new IntelligibilityEnhancer(config)); |
| 1319 } | 1324 } |
| 1320 } | 1325 } |
| 1321 | 1326 |
| 1322 void AudioProcessingImpl::InitializeHighPassFilter() { | 1327 void AudioProcessingImpl::InitializeHighPassFilter() { |
| 1323 public_submodules_->high_pass_filter->Initialize(num_output_channels(), | 1328 public_submodules_->high_pass_filter->Initialize(num_proc_channels(), |
| 1324 proc_sample_rate_hz()); | 1329 proc_sample_rate_hz()); |
| 1325 } | 1330 } |
| 1326 | 1331 |
| 1327 void AudioProcessingImpl::InitializeNoiseSuppression() { | 1332 void AudioProcessingImpl::InitializeNoiseSuppression() { |
| 1328 public_submodules_->noise_suppression->Initialize(num_output_channels(), | 1333 public_submodules_->noise_suppression->Initialize(num_proc_channels(), |
| 1329 proc_sample_rate_hz()); | 1334 proc_sample_rate_hz()); |
| 1330 } | 1335 } |
| 1331 | 1336 |
| 1332 void AudioProcessingImpl::InitializeLevelEstimator() { | 1337 void AudioProcessingImpl::InitializeLevelEstimator() { |
| 1333 public_submodules_->level_estimator->Initialize(); | 1338 public_submodules_->level_estimator->Initialize(); |
| 1334 } | 1339 } |
| 1335 | 1340 |
| 1336 void AudioProcessingImpl::InitializeVoiceDetection() { | 1341 void AudioProcessingImpl::InitializeVoiceDetection() { |
| 1337 public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz()); | 1342 public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz()); |
| 1338 } | 1343 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1515 debug_dump_.capture.event_msg->set_type(audioproc::Event::CONFIG); | 1520 debug_dump_.capture.event_msg->set_type(audioproc::Event::CONFIG); |
| 1516 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config); | 1521 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config); |
| 1517 | 1522 |
| 1518 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 1523 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
| 1519 &crit_debug_, &debug_dump_.capture)); | 1524 &crit_debug_, &debug_dump_.capture)); |
| 1520 return kNoError; | 1525 return kNoError; |
| 1521 } | 1526 } |
| 1522 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1527 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1523 | 1528 |
| 1524 } // namespace webrtc | 1529 } // namespace webrtc |
| OLD | NEW |