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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 #endif | 323 #endif |
324 } | 324 } |
325 | 325 |
326 int AudioProcessingImpl::Initialize() { | 326 int AudioProcessingImpl::Initialize() { |
327 // Run in a single-threaded manner during initialization. | 327 // Run in a single-threaded manner during initialization. |
328 rtc::CritScope cs_render(&crit_render_); | 328 rtc::CritScope cs_render(&crit_render_); |
329 rtc::CritScope cs_capture(&crit_capture_); | 329 rtc::CritScope cs_capture(&crit_capture_); |
330 return InitializeLocked(); | 330 return InitializeLocked(); |
331 } | 331 } |
332 | 332 |
333 int AudioProcessingImpl::Initialize(int input_sample_rate_hz, | 333 int AudioProcessingImpl::Initialize(int capture_input_sample_rate_hz, |
334 int output_sample_rate_hz, | 334 int capture_output_sample_rate_hz, |
335 int reverse_sample_rate_hz, | 335 int render_input_sample_rate_hz, |
336 ChannelLayout input_layout, | 336 ChannelLayout capture_input_layout, |
337 ChannelLayout output_layout, | 337 ChannelLayout capture_output_layout, |
338 ChannelLayout reverse_layout) { | 338 ChannelLayout render_input_layout) { |
339 const ProcessingConfig processing_config = { | 339 const ProcessingConfig processing_config = { |
340 {{input_sample_rate_hz, | 340 {{capture_input_sample_rate_hz, ChannelsFromLayout(capture_input_layout), |
341 ChannelsFromLayout(input_layout), | 341 LayoutHasKeyboard(capture_input_layout)}, |
342 LayoutHasKeyboard(input_layout)}, | 342 {capture_output_sample_rate_hz, |
343 {output_sample_rate_hz, | 343 ChannelsFromLayout(capture_output_layout), |
344 ChannelsFromLayout(output_layout), | 344 LayoutHasKeyboard(capture_output_layout)}, |
345 LayoutHasKeyboard(output_layout)}, | 345 {render_input_sample_rate_hz, ChannelsFromLayout(render_input_layout), |
346 {reverse_sample_rate_hz, | 346 LayoutHasKeyboard(render_input_layout)}, |
347 ChannelsFromLayout(reverse_layout), | 347 {render_input_sample_rate_hz, ChannelsFromLayout(render_input_layout), |
348 LayoutHasKeyboard(reverse_layout)}, | 348 LayoutHasKeyboard(render_input_layout)}}}; |
349 {reverse_sample_rate_hz, | |
350 ChannelsFromLayout(reverse_layout), | |
351 LayoutHasKeyboard(reverse_layout)}}}; | |
352 | 349 |
353 return Initialize(processing_config); | 350 return Initialize(processing_config); |
354 } | 351 } |
355 | 352 |
356 int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) { | 353 int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) { |
357 // Run in a single-threaded manner during initialization. | 354 // Run in a single-threaded manner during initialization. |
358 rtc::CritScope cs_render(&crit_render_); | 355 rtc::CritScope cs_render(&crit_render_); |
359 rtc::CritScope cs_capture(&crit_capture_); | 356 rtc::CritScope cs_capture(&crit_capture_); |
360 return InitializeLocked(processing_config); | 357 return InitializeLocked(processing_config); |
361 } | 358 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 // Called from both threads. Thread check is therefore not possible. | 390 // Called from both threads. Thread check is therefore not possible. |
394 if (processing_config == formats_.api_format && !force_initialization) { | 391 if (processing_config == formats_.api_format && !force_initialization) { |
395 return kNoError; | 392 return kNoError; |
396 } | 393 } |
397 | 394 |
398 rtc::CritScope cs_capture(&crit_capture_); | 395 rtc::CritScope cs_capture(&crit_capture_); |
399 return InitializeLocked(processing_config); | 396 return InitializeLocked(processing_config); |
400 } | 397 } |
401 | 398 |
402 int AudioProcessingImpl::InitializeLocked() { | 399 int AudioProcessingImpl::InitializeLocked() { |
403 const int fwd_audio_buffer_channels = | 400 const int capture_audiobuffer_num_channels = |
404 capture_nonlocked_.beamformer_enabled | 401 capture_nonlocked_.beamformer_enabled |
405 ? formats_.api_format.input_stream().num_channels() | 402 ? formats_.api_format.input_stream().num_channels() |
406 : formats_.api_format.output_stream().num_channels(); | 403 : formats_.api_format.output_stream().num_channels(); |
407 const int rev_audio_buffer_out_num_frames = | 404 const int render_audiobuffer_num_output_frames = |
408 formats_.api_format.reverse_output_stream().num_frames() == 0 | 405 formats_.api_format.reverse_output_stream().num_frames() == 0 |
409 ? formats_.rev_proc_format.num_frames() | 406 ? formats_.render_processing_format.num_frames() |
410 : formats_.api_format.reverse_output_stream().num_frames(); | 407 : formats_.api_format.reverse_output_stream().num_frames(); |
411 if (formats_.api_format.reverse_input_stream().num_channels() > 0) { | 408 if (formats_.api_format.reverse_input_stream().num_channels() > 0) { |
412 render_.render_audio.reset(new AudioBuffer( | 409 render_.render_audio.reset(new AudioBuffer( |
413 formats_.api_format.reverse_input_stream().num_frames(), | 410 formats_.api_format.reverse_input_stream().num_frames(), |
414 formats_.api_format.reverse_input_stream().num_channels(), | 411 formats_.api_format.reverse_input_stream().num_channels(), |
415 formats_.rev_proc_format.num_frames(), | 412 formats_.render_processing_format.num_frames(), |
416 formats_.rev_proc_format.num_channels(), | 413 formats_.render_processing_format.num_channels(), |
417 rev_audio_buffer_out_num_frames)); | 414 render_audiobuffer_num_output_frames)); |
418 if (formats_.api_format.reverse_input_stream() != | 415 if (formats_.api_format.reverse_input_stream() != |
419 formats_.api_format.reverse_output_stream()) { | 416 formats_.api_format.reverse_output_stream()) { |
420 render_.render_converter = AudioConverter::Create( | 417 render_.render_converter = AudioConverter::Create( |
421 formats_.api_format.reverse_input_stream().num_channels(), | 418 formats_.api_format.reverse_input_stream().num_channels(), |
422 formats_.api_format.reverse_input_stream().num_frames(), | 419 formats_.api_format.reverse_input_stream().num_frames(), |
423 formats_.api_format.reverse_output_stream().num_channels(), | 420 formats_.api_format.reverse_output_stream().num_channels(), |
424 formats_.api_format.reverse_output_stream().num_frames()); | 421 formats_.api_format.reverse_output_stream().num_frames()); |
425 } else { | 422 } else { |
426 render_.render_converter.reset(nullptr); | 423 render_.render_converter.reset(nullptr); |
427 } | 424 } |
428 } else { | 425 } else { |
429 render_.render_audio.reset(nullptr); | 426 render_.render_audio.reset(nullptr); |
430 render_.render_converter.reset(nullptr); | 427 render_.render_converter.reset(nullptr); |
431 } | 428 } |
432 capture_.capture_audio.reset( | 429 capture_.capture_audio.reset( |
433 new AudioBuffer(formats_.api_format.input_stream().num_frames(), | 430 new AudioBuffer(formats_.api_format.input_stream().num_frames(), |
434 formats_.api_format.input_stream().num_channels(), | 431 formats_.api_format.input_stream().num_channels(), |
435 capture_nonlocked_.fwd_proc_format.num_frames(), | 432 capture_nonlocked_.capture_processing_format.num_frames(), |
436 fwd_audio_buffer_channels, | 433 capture_audiobuffer_num_channels, |
437 formats_.api_format.output_stream().num_frames())); | 434 formats_.api_format.output_stream().num_frames())); |
438 | 435 |
439 InitializeGainController(); | 436 public_submodules_->gain_control->Initialize(num_proc_channels(), |
440 InitializeEchoCanceller(); | 437 proc_sample_rate_hz()); |
441 InitializeEchoControlMobile(); | 438 public_submodules_->echo_cancellation->Initialize( |
442 InitializeExperimentalAgc(); | 439 proc_sample_rate_hz(), num_reverse_channels(), num_output_channels(), |
440 num_proc_channels()); | |
441 | |
the sun
2016/09/14 09:40:32
dd
peah-webrtc
2016/09/16 08:26:27
Done.
| |
442 public_submodules_->echo_control_mobile->Initialize( | |
443 proc_split_sample_rate_hz(), num_reverse_channels(), | |
444 num_output_channels()); | |
445 if (constants_.use_experimental_agc) { | |
446 if (!private_submodules_->agc_manager.get()) { | |
447 private_submodules_->agc_manager.reset(new AgcManagerDirect( | |
448 public_submodules_->gain_control.get(), | |
449 public_submodules_->gain_control_for_experimental_agc.get(), | |
450 constants_.agc_startup_min_volume)); | |
451 } | |
452 private_submodules_->agc_manager->Initialize(); | |
453 private_submodules_->agc_manager->SetCaptureMuted( | |
454 capture_.output_will_be_muted); | |
455 } | |
443 InitializeTransient(); | 456 InitializeTransient(); |
444 InitializeBeamformer(); | 457 InitializeBeamformer(); |
445 #if WEBRTC_INTELLIGIBILITY_ENHANCER | 458 #if WEBRTC_INTELLIGIBILITY_ENHANCER |
446 InitializeIntelligibility(); | 459 InitializeIntelligibility(); |
447 #endif | 460 #endif |
448 InitializeHighPassFilter(); | 461 public_submodules_->high_pass_filter->Initialize(num_proc_channels(), |
449 InitializeNoiseSuppression(); | 462 proc_sample_rate_hz()); |
450 InitializeLevelEstimator(); | 463 public_submodules_->noise_suppression->Initialize(num_proc_channels(), |
451 InitializeVoiceDetection(); | 464 proc_sample_rate_hz()); |
452 InitializeLevelController(); | 465 InitializeLevelController(); |
453 | 466 |
the sun
2016/09/14 09:40:32
dd
peah-webrtc
2016/09/16 08:26:27
Done.
| |
467 public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz()); | |
468 private_submodules_->level_controller->Initialize(proc_sample_rate_hz()); | |
the sun
2016/09/14 09:40:32
why did you change the order of vd and lc?
peah-webrtc
2016/09/16 08:26:27
Sorry, my error. What was even worse was that the
| |
469 | |
454 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 470 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
455 if (debug_dump_.debug_file->is_open()) { | 471 if (debug_dump_.debug_file->is_open()) { |
456 int err = WriteInitMessage(); | 472 int err = WriteInitMessage(); |
457 if (err != kNoError) { | 473 if (err != kNoError) { |
458 return err; | 474 return err; |
459 } | 475 } |
460 } | 476 } |
461 #endif | 477 #endif |
462 | 478 |
463 return kNoError; | 479 return kNoError; |
(...skipping 16 matching lines...) Expand all Loading... | |
480 return kBadNumberChannelsError; | 496 return kBadNumberChannelsError; |
481 } | 497 } |
482 | 498 |
483 if (capture_nonlocked_.beamformer_enabled && | 499 if (capture_nonlocked_.beamformer_enabled && |
484 num_in_channels != capture_.array_geometry.size()) { | 500 num_in_channels != capture_.array_geometry.size()) { |
485 return kBadNumberChannelsError; | 501 return kBadNumberChannelsError; |
486 } | 502 } |
487 | 503 |
488 formats_.api_format = config; | 504 formats_.api_format = config; |
489 | 505 |
490 int fwd_proc_rate = FindNativeProcessRateToUse( | 506 int capture_processing_rate = FindNativeProcessRateToUse( |
491 std::min(formats_.api_format.input_stream().sample_rate_hz(), | 507 std::min(formats_.api_format.input_stream().sample_rate_hz(), |
492 formats_.api_format.output_stream().sample_rate_hz()), | 508 formats_.api_format.output_stream().sample_rate_hz()), |
493 submodule_states_.CaptureMultiBandSubModulesActive() || | 509 submodule_states_.CaptureMultiBandSubModulesActive() || |
494 submodule_states_.RenderMultiBandSubModulesActive()); | 510 submodule_states_.RenderMultiBandSubModulesActive()); |
495 | 511 |
496 capture_nonlocked_.fwd_proc_format = StreamConfig(fwd_proc_rate); | 512 capture_nonlocked_.capture_processing_format = |
513 StreamConfig(capture_processing_rate); | |
497 | 514 |
498 int rev_proc_rate = FindNativeProcessRateToUse( | 515 int render_processing_rate = FindNativeProcessRateToUse( |
499 std::min(formats_.api_format.reverse_input_stream().sample_rate_hz(), | 516 std::min(formats_.api_format.reverse_input_stream().sample_rate_hz(), |
500 formats_.api_format.reverse_output_stream().sample_rate_hz()), | 517 formats_.api_format.reverse_output_stream().sample_rate_hz()), |
501 submodule_states_.CaptureMultiBandSubModulesActive() || | 518 submodule_states_.CaptureMultiBandSubModulesActive() || |
502 submodule_states_.RenderMultiBandSubModulesActive()); | 519 submodule_states_.RenderMultiBandSubModulesActive()); |
503 // TODO(aluebs): Remove this restriction once we figure out why the 3-band | 520 // TODO(aluebs): Remove this restriction once we figure out why the 3-band |
504 // splitting filter degrades the AEC performance. | 521 // splitting filter degrades the AEC performance. |
505 if (rev_proc_rate > kSampleRate32kHz) { | 522 if (render_processing_rate > kSampleRate32kHz) { |
506 rev_proc_rate = submodule_states_.RenderMultiBandProcessingActive() | 523 render_processing_rate = submodule_states_.RenderMultiBandProcessingActive() |
507 ? kSampleRate32kHz | 524 ? kSampleRate32kHz |
508 : kSampleRate16kHz; | 525 : kSampleRate16kHz; |
509 } | 526 } |
510 // If the forward sample rate is 8 kHz, the reverse stream is also processed | 527 // If the forward sample rate is 8 kHz, the render stream is also processed |
511 // at this rate. | 528 // at this rate. |
512 if (capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate8kHz) { | 529 if (capture_nonlocked_.capture_processing_format.sample_rate_hz() == |
513 rev_proc_rate = kSampleRate8kHz; | 530 kSampleRate8kHz) { |
531 render_processing_rate = kSampleRate8kHz; | |
514 } else { | 532 } else { |
515 rev_proc_rate = std::max(rev_proc_rate, static_cast<int>(kSampleRate16kHz)); | 533 render_processing_rate = |
534 std::max(render_processing_rate, static_cast<int>(kSampleRate16kHz)); | |
516 } | 535 } |
517 | 536 |
518 // Always downmix the reverse stream to mono for analysis. This has been | 537 // Always downmix the render stream to mono for analysis. This has been |
519 // demonstrated to work well for AEC in most practical scenarios. | 538 // demonstrated to work well for AEC in most practical scenarios. |
520 formats_.rev_proc_format = StreamConfig(rev_proc_rate, 1); | 539 formats_.render_processing_format = StreamConfig(render_processing_rate, 1); |
521 | 540 |
522 if (capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate32kHz || | 541 if (capture_nonlocked_.capture_processing_format.sample_rate_hz() == |
523 capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate48kHz) { | 542 kSampleRate32kHz || |
543 capture_nonlocked_.capture_processing_format.sample_rate_hz() == | |
544 kSampleRate48kHz) { | |
524 capture_nonlocked_.split_rate = kSampleRate16kHz; | 545 capture_nonlocked_.split_rate = kSampleRate16kHz; |
525 } else { | 546 } else { |
526 capture_nonlocked_.split_rate = | 547 capture_nonlocked_.split_rate = |
527 capture_nonlocked_.fwd_proc_format.sample_rate_hz(); | 548 capture_nonlocked_.capture_processing_format.sample_rate_hz(); |
528 } | 549 } |
529 | 550 |
530 return InitializeLocked(); | 551 return InitializeLocked(); |
531 } | 552 } |
532 | 553 |
533 void AudioProcessingImpl::SetExtraOptions(const Config& config) { | 554 void AudioProcessingImpl::SetExtraOptions(const Config& config) { |
534 // Run in a single-threaded manner when setting the extra options. | 555 // Run in a single-threaded manner when setting the extra options. |
535 rtc::CritScope cs_render(&crit_render_); | 556 rtc::CritScope cs_render(&crit_render_); |
536 rtc::CritScope cs_capture(&crit_capture_); | 557 rtc::CritScope cs_capture(&crit_capture_); |
537 | 558 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 capture_.array_geometry = config.Get<Beamforming>().array_geometry; | 592 capture_.array_geometry = config.Get<Beamforming>().array_geometry; |
572 } | 593 } |
573 capture_.target_direction = config.Get<Beamforming>().target_direction; | 594 capture_.target_direction = config.Get<Beamforming>().target_direction; |
574 InitializeBeamformer(); | 595 InitializeBeamformer(); |
575 } | 596 } |
576 #endif // WEBRTC_ANDROID_PLATFORM_BUILD | 597 #endif // WEBRTC_ANDROID_PLATFORM_BUILD |
577 } | 598 } |
578 | 599 |
579 int AudioProcessingImpl::proc_sample_rate_hz() const { | 600 int AudioProcessingImpl::proc_sample_rate_hz() const { |
580 // Used as callback from submodules, hence locking is not allowed. | 601 // Used as callback from submodules, hence locking is not allowed. |
581 return capture_nonlocked_.fwd_proc_format.sample_rate_hz(); | 602 return capture_nonlocked_.capture_processing_format.sample_rate_hz(); |
582 } | 603 } |
583 | 604 |
584 int AudioProcessingImpl::proc_split_sample_rate_hz() const { | 605 int AudioProcessingImpl::proc_split_sample_rate_hz() const { |
585 // Used as callback from submodules, hence locking is not allowed. | 606 // Used as callback from submodules, hence locking is not allowed. |
586 return capture_nonlocked_.split_rate; | 607 return capture_nonlocked_.split_rate; |
587 } | 608 } |
588 | 609 |
589 size_t AudioProcessingImpl::num_reverse_channels() const { | 610 size_t AudioProcessingImpl::num_reverse_channels() const { |
590 // Used as callback from submodules, hence locking is not allowed. | 611 // Used as callback from submodules, hence locking is not allowed. |
591 return formats_.rev_proc_format.num_channels(); | 612 return formats_.render_processing_format.num_channels(); |
592 } | 613 } |
593 | 614 |
594 size_t AudioProcessingImpl::num_input_channels() const { | 615 size_t AudioProcessingImpl::num_input_channels() const { |
595 // Used as callback from submodules, hence locking is not allowed. | 616 // Used as callback from submodules, hence locking is not allowed. |
596 return formats_.api_format.input_stream().num_channels(); | 617 return formats_.api_format.input_stream().num_channels(); |
597 } | 618 } |
598 | 619 |
599 size_t AudioProcessingImpl::num_proc_channels() const { | 620 size_t AudioProcessingImpl::num_proc_channels() const { |
600 // Used as callback from submodules, hence locking is not allowed. | 621 // Used as callback from submodules, hence locking is not allowed. |
601 return capture_nonlocked_.beamformer_enabled ? 1 : num_output_channels(); | 622 return capture_nonlocked_.beamformer_enabled ? 1 : num_output_channels(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
693 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); | 714 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
694 const size_t channel_size = | 715 const size_t channel_size = |
695 sizeof(float) * formats_.api_format.input_stream().num_frames(); | 716 sizeof(float) * formats_.api_format.input_stream().num_frames(); |
696 for (size_t i = 0; i < formats_.api_format.input_stream().num_channels(); | 717 for (size_t i = 0; i < formats_.api_format.input_stream().num_channels(); |
697 ++i) | 718 ++i) |
698 msg->add_input_channel(src[i], channel_size); | 719 msg->add_input_channel(src[i], channel_size); |
699 } | 720 } |
700 #endif | 721 #endif |
701 | 722 |
702 capture_.capture_audio->CopyFrom(src, formats_.api_format.input_stream()); | 723 capture_.capture_audio->CopyFrom(src, formats_.api_format.input_stream()); |
703 RETURN_ON_ERR(ProcessStreamLocked()); | 724 RETURN_ON_ERR(ProcessCaptureStreamLocked()); |
704 capture_.capture_audio->CopyTo(formats_.api_format.output_stream(), dest); | 725 capture_.capture_audio->CopyTo(formats_.api_format.output_stream(), dest); |
705 | 726 |
706 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 727 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
707 if (debug_dump_.debug_file->is_open()) { | 728 if (debug_dump_.debug_file->is_open()) { |
708 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); | 729 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
709 const size_t channel_size = | 730 const size_t channel_size = |
710 sizeof(float) * formats_.api_format.output_stream().num_frames(); | 731 sizeof(float) * formats_.api_format.output_stream().num_frames(); |
711 for (size_t i = 0; i < formats_.api_format.output_stream().num_channels(); | 732 for (size_t i = 0; i < formats_.api_format.output_stream().num_channels(); |
712 ++i) | 733 ++i) |
713 msg->add_output_channel(dest[i], channel_size); | 734 msg->add_output_channel(dest[i], channel_size); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
782 | 803 |
783 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); | 804 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); |
784 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); | 805 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
785 const size_t data_size = | 806 const size_t data_size = |
786 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; | 807 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
787 msg->set_input_data(frame->data_, data_size); | 808 msg->set_input_data(frame->data_, data_size); |
788 } | 809 } |
789 #endif | 810 #endif |
790 | 811 |
791 capture_.capture_audio->DeinterleaveFrom(frame); | 812 capture_.capture_audio->DeinterleaveFrom(frame); |
792 RETURN_ON_ERR(ProcessStreamLocked()); | 813 RETURN_ON_ERR(ProcessCaptureStreamLocked()); |
793 capture_.capture_audio->InterleaveTo( | 814 capture_.capture_audio->InterleaveTo( |
794 frame, submodule_states_.CaptureMultiBandProcessingActive()); | 815 frame, submodule_states_.CaptureMultiBandProcessingActive()); |
795 | 816 |
796 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 817 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
797 if (debug_dump_.debug_file->is_open()) { | 818 if (debug_dump_.debug_file->is_open()) { |
798 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); | 819 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
799 const size_t data_size = | 820 const size_t data_size = |
800 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; | 821 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
801 msg->set_output_data(frame->data_, data_size); | 822 msg->set_output_data(frame->data_, data_size); |
802 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 823 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
803 &debug_dump_.num_bytes_left_for_log_, | 824 &debug_dump_.num_bytes_left_for_log_, |
804 &crit_debug_, &debug_dump_.capture)); | 825 &crit_debug_, &debug_dump_.capture)); |
805 } | 826 } |
806 #endif | 827 #endif |
807 | 828 |
808 return kNoError; | 829 return kNoError; |
809 } | 830 } |
810 | 831 |
811 int AudioProcessingImpl::ProcessStreamLocked() { | 832 int AudioProcessingImpl::ProcessCaptureStreamLocked() { |
812 // Ensure that not both the AEC and AECM are active at the same time. | 833 // Ensure that not both the AEC and AECM are active at the same time. |
813 // TODO(peah): Simplify once the public API Enable functions for these | 834 // TODO(peah): Simplify once the public API Enable functions for these |
814 // are moved to APM. | 835 // are moved to APM. |
815 RTC_DCHECK(!(public_submodules_->echo_cancellation->is_enabled() && | 836 RTC_DCHECK(!(public_submodules_->echo_cancellation->is_enabled() && |
816 public_submodules_->echo_control_mobile->is_enabled())); | 837 public_submodules_->echo_control_mobile->is_enabled())); |
817 | 838 |
818 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 839 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
819 if (debug_dump_.debug_file->is_open()) { | 840 if (debug_dump_.debug_file->is_open()) { |
820 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); | 841 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
821 msg->set_delay(capture_nonlocked_.stream_delay_ms); | 842 msg->set_delay(capture_nonlocked_.stream_delay_ms); |
822 msg->set_drift( | 843 msg->set_drift( |
823 public_submodules_->echo_cancellation->stream_drift_samples()); | 844 public_submodules_->echo_cancellation->stream_drift_samples()); |
824 msg->set_level(gain_control()->stream_analog_level()); | 845 msg->set_level(gain_control()->stream_analog_level()); |
825 msg->set_keypress(capture_.key_pressed); | 846 msg->set_keypress(capture_.key_pressed); |
826 } | 847 } |
827 #endif | 848 #endif |
828 | 849 |
829 MaybeUpdateHistograms(); | 850 MaybeUpdateHistograms(); |
830 | 851 |
831 AudioBuffer* ca = capture_.capture_audio.get(); // For brevity. | 852 AudioBuffer* capture_buffer = capture_.capture_audio.get(); // For brevity. |
832 | 853 |
833 if (constants_.use_experimental_agc && | 854 if (constants_.use_experimental_agc && |
834 public_submodules_->gain_control->is_enabled()) { | 855 public_submodules_->gain_control->is_enabled()) { |
835 private_submodules_->agc_manager->AnalyzePreProcess( | 856 private_submodules_->agc_manager->AnalyzePreProcess( |
836 ca->channels()[0], ca->num_channels(), | 857 capture_buffer->channels()[0], capture_buffer->num_channels(), |
837 capture_nonlocked_.fwd_proc_format.num_frames()); | 858 capture_nonlocked_.capture_processing_format.num_frames()); |
838 } | 859 } |
839 | 860 |
840 if (submodule_states_.CaptureMultiBandSubModulesActive() && | 861 if (submodule_states_.CaptureMultiBandSubModulesActive() && |
841 SampleRateSupportsMultiBand( | 862 SampleRateSupportsMultiBand( |
842 capture_nonlocked_.fwd_proc_format.sample_rate_hz())) { | 863 capture_nonlocked_.capture_processing_format.sample_rate_hz())) { |
843 ca->SplitIntoFrequencyBands(); | 864 capture_buffer->SplitIntoFrequencyBands(); |
844 } | 865 } |
845 | 866 |
846 if (capture_nonlocked_.beamformer_enabled) { | 867 if (capture_nonlocked_.beamformer_enabled) { |
847 private_submodules_->beamformer->AnalyzeChunk(*ca->split_data_f()); | 868 private_submodules_->beamformer->AnalyzeChunk( |
869 *capture_buffer->split_data_f()); | |
848 // Discards all channels by the leftmost one. | 870 // Discards all channels by the leftmost one. |
849 ca->set_num_channels(1); | 871 capture_buffer->set_num_channels(1); |
850 } | 872 } |
851 | 873 |
852 public_submodules_->high_pass_filter->ProcessCaptureAudio(ca); | 874 public_submodules_->high_pass_filter->ProcessCaptureAudio(capture_buffer); |
853 RETURN_ON_ERR(public_submodules_->gain_control->AnalyzeCaptureAudio(ca)); | 875 RETURN_ON_ERR( |
854 public_submodules_->noise_suppression->AnalyzeCaptureAudio(ca); | 876 public_submodules_->gain_control->AnalyzeCaptureAudio(capture_buffer)); |
877 public_submodules_->noise_suppression->AnalyzeCaptureAudio(capture_buffer); | |
855 | 878 |
856 // Ensure that the stream delay was set before the call to the | 879 // Ensure that the stream delay was set before the call to the |
857 // AEC ProcessCaptureAudio function. | 880 // AEC ProcessCaptureAudio function. |
858 if (public_submodules_->echo_cancellation->is_enabled() && | 881 if (public_submodules_->echo_cancellation->is_enabled() && |
859 !was_stream_delay_set()) { | 882 !was_stream_delay_set()) { |
860 return AudioProcessing::kStreamParameterNotSetError; | 883 return AudioProcessing::kStreamParameterNotSetError; |
861 } | 884 } |
862 | 885 |
863 RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessCaptureAudio( | 886 RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessCaptureAudio( |
864 ca, stream_delay_ms())); | 887 capture_buffer, stream_delay_ms())); |
865 | 888 |
866 if (public_submodules_->echo_control_mobile->is_enabled() && | 889 if (public_submodules_->echo_control_mobile->is_enabled() && |
867 public_submodules_->noise_suppression->is_enabled()) { | 890 public_submodules_->noise_suppression->is_enabled()) { |
868 ca->CopyLowPassToReference(); | 891 capture_buffer->CopyLowPassToReference(); |
869 } | 892 } |
870 public_submodules_->noise_suppression->ProcessCaptureAudio(ca); | 893 public_submodules_->noise_suppression->ProcessCaptureAudio(capture_buffer); |
871 #if WEBRTC_INTELLIGIBILITY_ENHANCER | 894 #if WEBRTC_INTELLIGIBILITY_ENHANCER |
872 if (capture_nonlocked_.intelligibility_enabled) { | 895 if (capture_nonlocked_.intelligibility_enabled) { |
873 RTC_DCHECK(public_submodules_->noise_suppression->is_enabled()); | 896 RTC_DCHECK(public_submodules_->noise_suppression->is_enabled()); |
874 int gain_db = public_submodules_->gain_control->is_enabled() ? | 897 int gain_db = public_submodules_->gain_control->is_enabled() ? |
875 public_submodules_->gain_control->compression_gain_db() : | 898 public_submodules_->gain_control->compression_gain_db() : |
876 0; | 899 0; |
877 float gain = std::pow(10.f, gain_db / 20.f); | 900 float gain = std::pow(10.f, gain_db / 20.f); |
878 gain *= capture_nonlocked_.level_controller_enabled ? | 901 gain *= capture_nonlocked_.level_controller_enabled ? |
879 private_submodules_->level_controller->GetLastGain() : | 902 private_submodules_->level_controller->GetLastGain() : |
880 1.f; | 903 1.f; |
881 public_submodules_->intelligibility_enhancer->SetCaptureNoiseEstimate( | 904 public_submodules_->intelligibility_enhancer->SetCaptureNoiseEstimate( |
882 public_submodules_->noise_suppression->NoiseEstimate(), gain); | 905 public_submodules_->noise_suppression->NoiseEstimate(), gain); |
883 } | 906 } |
884 #endif | 907 #endif |
885 | 908 |
886 // Ensure that the stream delay was set before the call to the | 909 // Ensure that the stream delay was set before the call to the |
887 // AECM ProcessCaptureAudio function. | 910 // AECM ProcessCaptureAudio function. |
888 if (public_submodules_->echo_control_mobile->is_enabled() && | 911 if (public_submodules_->echo_control_mobile->is_enabled() && |
889 !was_stream_delay_set()) { | 912 !was_stream_delay_set()) { |
890 return AudioProcessing::kStreamParameterNotSetError; | 913 return AudioProcessing::kStreamParameterNotSetError; |
891 } | 914 } |
892 | 915 |
893 RETURN_ON_ERR(public_submodules_->echo_control_mobile->ProcessCaptureAudio( | 916 RETURN_ON_ERR(public_submodules_->echo_control_mobile->ProcessCaptureAudio( |
894 ca, stream_delay_ms())); | 917 capture_buffer, stream_delay_ms())); |
895 | 918 |
896 if (capture_nonlocked_.beamformer_enabled) { | 919 if (capture_nonlocked_.beamformer_enabled) { |
897 private_submodules_->beamformer->PostFilter(ca->split_data_f()); | 920 private_submodules_->beamformer->PostFilter(capture_buffer->split_data_f()); |
898 } | 921 } |
899 | 922 |
900 public_submodules_->voice_detection->ProcessCaptureAudio(ca); | 923 public_submodules_->voice_detection->ProcessCaptureAudio(capture_buffer); |
901 | 924 |
902 if (constants_.use_experimental_agc && | 925 if (constants_.use_experimental_agc && |
903 public_submodules_->gain_control->is_enabled() && | 926 public_submodules_->gain_control->is_enabled() && |
904 (!capture_nonlocked_.beamformer_enabled || | 927 (!capture_nonlocked_.beamformer_enabled || |
905 private_submodules_->beamformer->is_target_present())) { | 928 private_submodules_->beamformer->is_target_present())) { |
906 private_submodules_->agc_manager->Process( | 929 private_submodules_->agc_manager->Process( |
907 ca->split_bands_const(0)[kBand0To8kHz], ca->num_frames_per_band(), | 930 capture_buffer->split_bands_const(0)[kBand0To8kHz], |
908 capture_nonlocked_.split_rate); | 931 capture_buffer->num_frames_per_band(), capture_nonlocked_.split_rate); |
909 } | 932 } |
910 RETURN_ON_ERR(public_submodules_->gain_control->ProcessCaptureAudio( | 933 RETURN_ON_ERR(public_submodules_->gain_control->ProcessCaptureAudio( |
911 ca, echo_cancellation()->stream_has_echo())); | 934 capture_buffer, echo_cancellation()->stream_has_echo())); |
912 | 935 |
913 if (submodule_states_.CaptureMultiBandProcessingActive() && | 936 if (submodule_states_.CaptureMultiBandProcessingActive() && |
914 SampleRateSupportsMultiBand( | 937 SampleRateSupportsMultiBand( |
915 capture_nonlocked_.fwd_proc_format.sample_rate_hz())) { | 938 capture_nonlocked_.capture_processing_format.sample_rate_hz())) { |
916 ca->MergeFrequencyBands(); | 939 capture_buffer->MergeFrequencyBands(); |
917 } | 940 } |
918 | 941 |
919 // TODO(aluebs): Investigate if the transient suppression placement should be | 942 // TODO(aluebs): Investigate if the transient suppression placement should be |
920 // before or after the AGC. | 943 // before or after the AGC. |
921 if (capture_.transient_suppressor_enabled) { | 944 if (capture_.transient_suppressor_enabled) { |
922 float voice_probability = | 945 float voice_probability = |
923 private_submodules_->agc_manager.get() | 946 private_submodules_->agc_manager.get() |
924 ? private_submodules_->agc_manager->voice_probability() | 947 ? private_submodules_->agc_manager->voice_probability() |
925 : 1.f; | 948 : 1.f; |
926 | 949 |
927 public_submodules_->transient_suppressor->Suppress( | 950 public_submodules_->transient_suppressor->Suppress( |
928 ca->channels_f()[0], ca->num_frames(), ca->num_channels(), | 951 capture_buffer->channels_f()[0], capture_buffer->num_frames(), |
929 ca->split_bands_const_f(0)[kBand0To8kHz], ca->num_frames_per_band(), | 952 capture_buffer->num_channels(), |
930 ca->keyboard_data(), ca->num_keyboard_frames(), voice_probability, | 953 capture_buffer->split_bands_const_f(0)[kBand0To8kHz], |
954 capture_buffer->num_frames_per_band(), capture_buffer->keyboard_data(), | |
955 capture_buffer->num_keyboard_frames(), voice_probability, | |
931 capture_.key_pressed); | 956 capture_.key_pressed); |
932 } | 957 } |
933 | 958 |
934 if (capture_nonlocked_.level_controller_enabled) { | 959 if (capture_nonlocked_.level_controller_enabled) { |
935 private_submodules_->level_controller->Process(ca); | 960 private_submodules_->level_controller->Process(capture_buffer); |
936 } | 961 } |
937 | 962 |
938 // The level estimator operates on the recombined data. | 963 // The level estimator operates on the recombined data. |
939 public_submodules_->level_estimator->ProcessStream(ca); | 964 public_submodules_->level_estimator->ProcessStream(capture_buffer); |
940 | 965 |
941 capture_.was_stream_delay_set = false; | 966 capture_.was_stream_delay_set = false; |
942 return kNoError; | 967 return kNoError; |
943 } | 968 } |
944 | 969 |
945 int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data, | 970 int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data, |
946 size_t samples_per_channel, | 971 size_t samples_per_channel, |
947 int rev_sample_rate_hz, | 972 int sample_rate_hz, |
948 ChannelLayout layout) { | 973 ChannelLayout layout) { |
949 TRACE_EVENT0("webrtc", "AudioProcessing::AnalyzeReverseStream_ChannelLayout"); | 974 TRACE_EVENT0("webrtc", "AudioProcessing::AnalyzeReverseStream_ChannelLayout"); |
950 rtc::CritScope cs(&crit_render_); | 975 rtc::CritScope cs(&crit_render_); |
951 const StreamConfig reverse_config = { | 976 const StreamConfig reverse_config = { |
952 rev_sample_rate_hz, ChannelsFromLayout(layout), LayoutHasKeyboard(layout), | 977 sample_rate_hz, ChannelsFromLayout(layout), LayoutHasKeyboard(layout), |
953 }; | 978 }; |
954 if (samples_per_channel != reverse_config.num_frames()) { | 979 if (samples_per_channel != reverse_config.num_frames()) { |
955 return kBadDataLengthError; | 980 return kBadDataLengthError; |
956 } | 981 } |
957 return AnalyzeReverseStreamLocked(data, reverse_config, reverse_config); | 982 return AnalyzeReverseStreamLocked(data, reverse_config, reverse_config); |
958 } | 983 } |
959 | 984 |
960 int AudioProcessingImpl::ProcessReverseStream( | 985 int AudioProcessingImpl::ProcessReverseStream(const float* const* src, |
961 const float* const* src, | 986 const StreamConfig& input_config, |
962 const StreamConfig& reverse_input_config, | 987 const StreamConfig& output_config, |
963 const StreamConfig& reverse_output_config, | 988 float* const* dest) { |
964 float* const* dest) { | |
965 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_StreamConfig"); | 989 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_StreamConfig"); |
966 rtc::CritScope cs(&crit_render_); | 990 rtc::CritScope cs(&crit_render_); |
967 RETURN_ON_ERR(AnalyzeReverseStreamLocked(src, reverse_input_config, | 991 RETURN_ON_ERR(AnalyzeReverseStreamLocked(src, input_config, output_config)); |
968 reverse_output_config)); | |
969 if (submodule_states_.RenderMultiBandProcessingActive()) { | 992 if (submodule_states_.RenderMultiBandProcessingActive()) { |
970 render_.render_audio->CopyTo(formats_.api_format.reverse_output_stream(), | 993 render_.render_audio->CopyTo(formats_.api_format.reverse_output_stream(), |
971 dest); | 994 dest); |
972 } else if (formats_.api_format.reverse_input_stream() != | 995 } else if (formats_.api_format.reverse_input_stream() != |
973 formats_.api_format.reverse_output_stream()) { | 996 formats_.api_format.reverse_output_stream()) { |
974 render_.render_converter->Convert(src, reverse_input_config.num_samples(), | 997 render_.render_converter->Convert(src, input_config.num_samples(), dest, |
975 dest, | 998 output_config.num_samples()); |
976 reverse_output_config.num_samples()); | |
977 } else { | 999 } else { |
978 CopyAudioIfNeeded(src, reverse_input_config.num_frames(), | 1000 CopyAudioIfNeeded(src, input_config.num_frames(), |
979 reverse_input_config.num_channels(), dest); | 1001 input_config.num_channels(), dest); |
980 } | 1002 } |
981 | 1003 |
982 return kNoError; | 1004 return kNoError; |
983 } | 1005 } |
984 | 1006 |
985 int AudioProcessingImpl::AnalyzeReverseStreamLocked( | 1007 int AudioProcessingImpl::AnalyzeReverseStreamLocked( |
986 const float* const* src, | 1008 const float* const* src, |
987 const StreamConfig& reverse_input_config, | 1009 const StreamConfig& input_config, |
988 const StreamConfig& reverse_output_config) { | 1010 const StreamConfig& output_config) { |
989 if (src == nullptr) { | 1011 if (src == nullptr) { |
990 return kNullPointerError; | 1012 return kNullPointerError; |
991 } | 1013 } |
992 | 1014 |
993 if (reverse_input_config.num_channels() == 0) { | 1015 if (input_config.num_channels() == 0) { |
994 return kBadNumberChannelsError; | 1016 return kBadNumberChannelsError; |
995 } | 1017 } |
996 | 1018 |
997 ProcessingConfig processing_config = formats_.api_format; | 1019 ProcessingConfig processing_config = formats_.api_format; |
998 processing_config.reverse_input_stream() = reverse_input_config; | 1020 processing_config.reverse_input_stream() = input_config; |
999 processing_config.reverse_output_stream() = reverse_output_config; | 1021 processing_config.reverse_output_stream() = output_config; |
1000 | 1022 |
1001 RETURN_ON_ERR(MaybeInitializeRender(processing_config)); | 1023 RETURN_ON_ERR(MaybeInitializeRender(processing_config)); |
1002 assert(reverse_input_config.num_frames() == | 1024 assert(input_config.num_frames() == |
1003 formats_.api_format.reverse_input_stream().num_frames()); | 1025 formats_.api_format.reverse_input_stream().num_frames()); |
1004 | 1026 |
1005 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 1027 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
1006 if (debug_dump_.debug_file->is_open()) { | 1028 if (debug_dump_.debug_file->is_open()) { |
1007 debug_dump_.render.event_msg->set_type(audioproc::Event::REVERSE_STREAM); | 1029 debug_dump_.render.event_msg->set_type(audioproc::Event::REVERSE_STREAM); |
1008 audioproc::ReverseStream* msg = | 1030 audioproc::ReverseStream* msg = |
1009 debug_dump_.render.event_msg->mutable_reverse_stream(); | 1031 debug_dump_.render.event_msg->mutable_reverse_stream(); |
1010 const size_t channel_size = | 1032 const size_t channel_size = |
1011 sizeof(float) * formats_.api_format.reverse_input_stream().num_frames(); | 1033 sizeof(float) * formats_.api_format.reverse_input_stream().num_frames(); |
1012 for (size_t i = 0; | 1034 for (size_t i = 0; |
1013 i < formats_.api_format.reverse_input_stream().num_channels(); ++i) | 1035 i < formats_.api_format.reverse_input_stream().num_channels(); ++i) |
1014 msg->add_channel(src[i], channel_size); | 1036 msg->add_channel(src[i], channel_size); |
1015 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 1037 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
1016 &debug_dump_.num_bytes_left_for_log_, | 1038 &debug_dump_.num_bytes_left_for_log_, |
1017 &crit_debug_, &debug_dump_.render)); | 1039 &crit_debug_, &debug_dump_.render)); |
1018 } | 1040 } |
1019 #endif | 1041 #endif |
1020 | 1042 |
1021 render_.render_audio->CopyFrom(src, | 1043 render_.render_audio->CopyFrom(src, |
1022 formats_.api_format.reverse_input_stream()); | 1044 formats_.api_format.reverse_input_stream()); |
1023 return ProcessReverseStreamLocked(); | 1045 return ProcessRenderStreamLocked(); |
1024 } | 1046 } |
1025 | 1047 |
1026 int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) { | 1048 int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) { |
1027 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_AudioFrame"); | 1049 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_AudioFrame"); |
1028 rtc::CritScope cs(&crit_render_); | 1050 rtc::CritScope cs(&crit_render_); |
1029 if (frame == nullptr) { | 1051 if (frame == nullptr) { |
1030 return kNullPointerError; | 1052 return kNullPointerError; |
1031 } | 1053 } |
1032 // Must be a native rate. | 1054 // Must be a native rate. |
1033 if (frame->sample_rate_hz_ != kSampleRate8kHz && | 1055 if (frame->sample_rate_hz_ != kSampleRate8kHz && |
(...skipping 30 matching lines...) Expand all Loading... | |
1064 debug_dump_.render.event_msg->mutable_reverse_stream(); | 1086 debug_dump_.render.event_msg->mutable_reverse_stream(); |
1065 const size_t data_size = | 1087 const size_t data_size = |
1066 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; | 1088 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
1067 msg->set_data(frame->data_, data_size); | 1089 msg->set_data(frame->data_, data_size); |
1068 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 1090 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
1069 &debug_dump_.num_bytes_left_for_log_, | 1091 &debug_dump_.num_bytes_left_for_log_, |
1070 &crit_debug_, &debug_dump_.render)); | 1092 &crit_debug_, &debug_dump_.render)); |
1071 } | 1093 } |
1072 #endif | 1094 #endif |
1073 render_.render_audio->DeinterleaveFrom(frame); | 1095 render_.render_audio->DeinterleaveFrom(frame); |
1074 RETURN_ON_ERR(ProcessReverseStreamLocked()); | 1096 RETURN_ON_ERR(ProcessRenderStreamLocked()); |
1075 render_.render_audio->InterleaveTo( | 1097 render_.render_audio->InterleaveTo( |
1076 frame, submodule_states_.RenderMultiBandProcessingActive()); | 1098 frame, submodule_states_.RenderMultiBandProcessingActive()); |
1077 return kNoError; | 1099 return kNoError; |
1078 } | 1100 } |
1079 | 1101 |
1080 int AudioProcessingImpl::ProcessReverseStreamLocked() { | 1102 int AudioProcessingImpl::ProcessRenderStreamLocked() { |
1081 AudioBuffer* ra = render_.render_audio.get(); // For brevity. | 1103 AudioBuffer* render_buffer = render_.render_audio.get(); // For brevity. |
1082 if (submodule_states_.RenderMultiBandSubModulesActive() && | 1104 if (submodule_states_.RenderMultiBandSubModulesActive() && |
1083 SampleRateSupportsMultiBand(formats_.rev_proc_format.sample_rate_hz())) { | 1105 SampleRateSupportsMultiBand( |
1084 ra->SplitIntoFrequencyBands(); | 1106 formats_.render_processing_format.sample_rate_hz())) { |
1107 render_buffer->SplitIntoFrequencyBands(); | |
1085 } | 1108 } |
1086 | 1109 |
1087 #if WEBRTC_INTELLIGIBILITY_ENHANCER | 1110 #if WEBRTC_INTELLIGIBILITY_ENHANCER |
1088 if (capture_nonlocked_.intelligibility_enabled) { | 1111 if (capture_nonlocked_.intelligibility_enabled) { |
1089 public_submodules_->intelligibility_enhancer->ProcessRenderAudio( | 1112 public_submodules_->intelligibility_enhancer->ProcessRenderAudio( |
1090 ra->split_channels_f(kBand0To8kHz), capture_nonlocked_.split_rate, | 1113 render_buffer->split_channels_f(kBand0To8kHz), |
1091 ra->num_channels()); | 1114 capture_nonlocked_.split_rate, render_buffer->num_channels()); |
1092 } | 1115 } |
1093 #endif | 1116 #endif |
1094 | 1117 |
1095 RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessRenderAudio(ra)); | |
1096 RETURN_ON_ERR( | 1118 RETURN_ON_ERR( |
1097 public_submodules_->echo_control_mobile->ProcessRenderAudio(ra)); | 1119 public_submodules_->echo_cancellation->ProcessRenderAudio(render_buffer)); |
1120 RETURN_ON_ERR(public_submodules_->echo_control_mobile->ProcessRenderAudio( | |
1121 render_buffer)); | |
1098 if (!constants_.use_experimental_agc) { | 1122 if (!constants_.use_experimental_agc) { |
1099 RETURN_ON_ERR(public_submodules_->gain_control->ProcessRenderAudio(ra)); | 1123 RETURN_ON_ERR( |
1124 public_submodules_->gain_control->ProcessRenderAudio(render_buffer)); | |
1100 } | 1125 } |
1101 | 1126 |
1102 if (submodule_states_.RenderMultiBandProcessingActive() && | 1127 if (submodule_states_.RenderMultiBandProcessingActive() && |
1103 SampleRateSupportsMultiBand(formats_.rev_proc_format.sample_rate_hz())) { | 1128 SampleRateSupportsMultiBand( |
1104 ra->MergeFrequencyBands(); | 1129 formats_.render_processing_format.sample_rate_hz())) { |
1130 render_buffer->MergeFrequencyBands(); | |
1105 } | 1131 } |
1106 | 1132 |
1107 return kNoError; | 1133 return kNoError; |
1108 } | 1134 } |
1109 | 1135 |
1110 int AudioProcessingImpl::set_stream_delay_ms(int delay) { | 1136 int AudioProcessingImpl::set_stream_delay_ms(int delay) { |
1111 rtc::CritScope cs(&crit_capture_); | 1137 rtc::CritScope cs(&crit_capture_); |
1112 Error retval = kNoError; | 1138 Error retval = kNoError; |
1113 capture_.was_stream_delay_set = true; | 1139 capture_.was_stream_delay_set = true; |
1114 delay += capture_.delay_offset_ms; | 1140 delay += capture_.delay_offset_ms; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1272 public_submodules_->noise_suppression->is_enabled(), | 1298 public_submodules_->noise_suppression->is_enabled(), |
1273 capture_nonlocked_.intelligibility_enabled, | 1299 capture_nonlocked_.intelligibility_enabled, |
1274 capture_nonlocked_.beamformer_enabled, | 1300 capture_nonlocked_.beamformer_enabled, |
1275 public_submodules_->gain_control->is_enabled(), | 1301 public_submodules_->gain_control->is_enabled(), |
1276 capture_nonlocked_.level_controller_enabled, | 1302 capture_nonlocked_.level_controller_enabled, |
1277 public_submodules_->voice_detection->is_enabled(), | 1303 public_submodules_->voice_detection->is_enabled(), |
1278 public_submodules_->level_estimator->is_enabled(), | 1304 public_submodules_->level_estimator->is_enabled(), |
1279 capture_.transient_suppressor_enabled); | 1305 capture_.transient_suppressor_enabled); |
1280 } | 1306 } |
1281 | 1307 |
1282 void AudioProcessingImpl::InitializeExperimentalAgc() { | |
1283 if (constants_.use_experimental_agc) { | |
1284 if (!private_submodules_->agc_manager.get()) { | |
1285 private_submodules_->agc_manager.reset(new AgcManagerDirect( | |
1286 public_submodules_->gain_control.get(), | |
1287 public_submodules_->gain_control_for_experimental_agc.get(), | |
1288 constants_.agc_startup_min_volume)); | |
1289 } | |
1290 private_submodules_->agc_manager->Initialize(); | |
1291 private_submodules_->agc_manager->SetCaptureMuted( | |
1292 capture_.output_will_be_muted); | |
1293 } | |
1294 } | |
1295 | 1308 |
1296 void AudioProcessingImpl::InitializeTransient() { | 1309 void AudioProcessingImpl::InitializeTransient() { |
1297 if (capture_.transient_suppressor_enabled) { | 1310 if (capture_.transient_suppressor_enabled) { |
1298 if (!public_submodules_->transient_suppressor.get()) { | 1311 if (!public_submodules_->transient_suppressor.get()) { |
1299 public_submodules_->transient_suppressor.reset(new TransientSuppressor()); | 1312 public_submodules_->transient_suppressor.reset(new TransientSuppressor()); |
1300 } | 1313 } |
1301 public_submodules_->transient_suppressor->Initialize( | 1314 public_submodules_->transient_suppressor->Initialize( |
1302 capture_nonlocked_.fwd_proc_format.sample_rate_hz(), | 1315 capture_nonlocked_.capture_processing_format.sample_rate_hz(), |
1303 capture_nonlocked_.split_rate, | 1316 capture_nonlocked_.split_rate, num_proc_channels()); |
1304 num_proc_channels()); | |
1305 } | 1317 } |
1306 } | 1318 } |
1307 | 1319 |
1308 void AudioProcessingImpl::InitializeBeamformer() { | 1320 void AudioProcessingImpl::InitializeBeamformer() { |
1309 if (capture_nonlocked_.beamformer_enabled) { | 1321 if (capture_nonlocked_.beamformer_enabled) { |
1310 if (!private_submodules_->beamformer) { | 1322 if (!private_submodules_->beamformer) { |
1311 private_submodules_->beamformer.reset(new NonlinearBeamformer( | 1323 private_submodules_->beamformer.reset(new NonlinearBeamformer( |
1312 capture_.array_geometry, 1u, capture_.target_direction)); | 1324 capture_.array_geometry, 1u, capture_.target_direction)); |
1313 } | 1325 } |
1314 private_submodules_->beamformer->Initialize(kChunkSizeMs, | 1326 private_submodules_->beamformer->Initialize(kChunkSizeMs, |
1315 capture_nonlocked_.split_rate); | 1327 capture_nonlocked_.split_rate); |
1316 } | 1328 } |
1317 } | 1329 } |
1318 | 1330 |
1319 void AudioProcessingImpl::InitializeIntelligibility() { | 1331 void AudioProcessingImpl::InitializeIntelligibility() { |
1320 #if WEBRTC_INTELLIGIBILITY_ENHANCER | 1332 #if WEBRTC_INTELLIGIBILITY_ENHANCER |
1321 if (capture_nonlocked_.intelligibility_enabled) { | 1333 if (capture_nonlocked_.intelligibility_enabled) { |
1322 public_submodules_->intelligibility_enhancer.reset( | 1334 public_submodules_->intelligibility_enhancer.reset( |
1323 new IntelligibilityEnhancer(capture_nonlocked_.split_rate, | 1335 new IntelligibilityEnhancer(capture_nonlocked_.split_rate, |
1324 render_.render_audio->num_channels(), | 1336 render_.render_audio->num_channels(), |
1325 NoiseSuppressionImpl::num_noise_bins())); | 1337 NoiseSuppressionImpl::num_noise_bins())); |
1326 } | 1338 } |
1327 #endif | 1339 #endif |
1328 } | 1340 } |
1329 | 1341 |
1330 void AudioProcessingImpl::InitializeHighPassFilter() { | |
1331 public_submodules_->high_pass_filter->Initialize(num_proc_channels(), | |
1332 proc_sample_rate_hz()); | |
1333 } | |
1334 | |
1335 void AudioProcessingImpl::InitializeNoiseSuppression() { | |
1336 public_submodules_->noise_suppression->Initialize(num_proc_channels(), | |
1337 proc_sample_rate_hz()); | |
1338 } | |
1339 | |
1340 void AudioProcessingImpl::InitializeEchoCanceller() { | |
1341 public_submodules_->echo_cancellation->Initialize( | |
1342 proc_sample_rate_hz(), num_reverse_channels(), num_output_channels(), | |
1343 num_proc_channels()); | |
1344 } | |
1345 | |
1346 void AudioProcessingImpl::InitializeGainController() { | |
1347 public_submodules_->gain_control->Initialize(num_proc_channels(), | |
1348 proc_sample_rate_hz()); | |
1349 } | |
1350 | |
1351 void AudioProcessingImpl::InitializeEchoControlMobile() { | |
1352 public_submodules_->echo_control_mobile->Initialize( | |
1353 proc_split_sample_rate_hz(), | |
1354 num_reverse_channels(), | |
1355 num_output_channels()); | |
1356 } | |
1357 | |
1358 void AudioProcessingImpl::InitializeLevelEstimator() { | |
1359 public_submodules_->level_estimator->Initialize(); | |
1360 } | |
1361 | |
1362 void AudioProcessingImpl::InitializeLevelController() { | 1342 void AudioProcessingImpl::InitializeLevelController() { |
1363 private_submodules_->level_controller->Initialize(proc_sample_rate_hz()); | 1343 private_submodules_->level_controller->Initialize(proc_sample_rate_hz()); |
1364 } | 1344 } |
1365 | 1345 |
1366 void AudioProcessingImpl::InitializeVoiceDetection() { | 1346 |
1367 public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz()); | 1347 |
1368 } | 1348 |
1369 | 1349 |
1370 void AudioProcessingImpl::MaybeUpdateHistograms() { | 1350 void AudioProcessingImpl::MaybeUpdateHistograms() { |
1371 static const int kMinDiffDelayMs = 60; | 1351 static const int kMinDiffDelayMs = 60; |
1372 | 1352 |
1373 if (echo_cancellation()->is_enabled()) { | 1353 if (echo_cancellation()->is_enabled()) { |
1374 // Activate delay_jumps_ counters if we know echo_cancellation is runnning. | 1354 // Activate delay_jumps_ counters if we know echo_cancellation is runnning. |
1375 // If a stream has echo we know that the echo_cancellation is in process. | 1355 // If a stream has echo we know that the echo_cancellation is in process. |
1376 if (capture_.stream_delay_jumps == -1 && | 1356 if (capture_.stream_delay_jumps == -1 && |
1377 echo_cancellation()->stream_has_echo()) { | 1357 echo_cancellation()->stream_has_echo()) { |
1378 capture_.stream_delay_jumps = 0; | 1358 capture_.stream_delay_jumps = 0; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1588 delay_offset_ms(0), | 1568 delay_offset_ms(0), |
1589 was_stream_delay_set(false), | 1569 was_stream_delay_set(false), |
1590 last_stream_delay_ms(0), | 1570 last_stream_delay_ms(0), |
1591 last_aec_system_delay_ms(0), | 1571 last_aec_system_delay_ms(0), |
1592 stream_delay_jumps(-1), | 1572 stream_delay_jumps(-1), |
1593 output_will_be_muted(false), | 1573 output_will_be_muted(false), |
1594 key_pressed(false), | 1574 key_pressed(false), |
1595 transient_suppressor_enabled(transient_suppressor_enabled), | 1575 transient_suppressor_enabled(transient_suppressor_enabled), |
1596 array_geometry(array_geometry), | 1576 array_geometry(array_geometry), |
1597 target_direction(target_direction), | 1577 target_direction(target_direction), |
1598 fwd_proc_format(kSampleRate16kHz), | 1578 capture_processing_format(kSampleRate16kHz), |
1599 split_rate(kSampleRate16kHz) {} | 1579 split_rate(kSampleRate16kHz) {} |
1600 | 1580 |
1601 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; | 1581 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; |
1602 | 1582 |
1603 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; | 1583 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; |
1604 | 1584 |
1605 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; | 1585 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; |
1606 | 1586 |
1607 } // namespace webrtc | 1587 } // namespace webrtc |
OLD | NEW |