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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 // Called from both threads. Thread check is therefore not possible. | 432 // Called from both threads. Thread check is therefore not possible. |
433 if (processing_config == formats_.api_format && !force_initialization) { | 433 if (processing_config == formats_.api_format && !force_initialization) { |
434 return kNoError; | 434 return kNoError; |
435 } | 435 } |
436 | 436 |
437 rtc::CritScope cs_capture(&crit_capture_); | 437 rtc::CritScope cs_capture(&crit_capture_); |
438 return InitializeLocked(processing_config); | 438 return InitializeLocked(processing_config); |
439 } | 439 } |
440 | 440 |
441 int AudioProcessingImpl::InitializeLocked() { | 441 int AudioProcessingImpl::InitializeLocked() { |
442 int capture_audiobuffer_num_channels; | 442 const int capture_audiobuffer_num_channels = |
443 if (private_submodules_->echo_canceller3) { | 443 capture_nonlocked_.beamformer_enabled |
444 // TODO(peah): Ensure that the echo canceller can operate on more than one | 444 ? formats_.api_format.input_stream().num_channels() |
445 // microphone channel. | 445 : formats_.api_format.output_stream().num_channels(); |
446 RTC_DCHECK(!capture_nonlocked_.beamformer_enabled); | 446 |
447 capture_audiobuffer_num_channels = 1; | |
448 } else { | |
449 capture_audiobuffer_num_channels = | |
450 capture_nonlocked_.beamformer_enabled | |
451 ? formats_.api_format.input_stream().num_channels() | |
452 : formats_.api_format.output_stream().num_channels(); | |
453 } | |
454 const int render_audiobuffer_num_output_frames = | 447 const int render_audiobuffer_num_output_frames = |
455 formats_.api_format.reverse_output_stream().num_frames() == 0 | 448 formats_.api_format.reverse_output_stream().num_frames() == 0 |
456 ? formats_.render_processing_format.num_frames() | 449 ? formats_.render_processing_format.num_frames() |
457 : formats_.api_format.reverse_output_stream().num_frames(); | 450 : formats_.api_format.reverse_output_stream().num_frames(); |
458 if (formats_.api_format.reverse_input_stream().num_channels() > 0) { | 451 if (formats_.api_format.reverse_input_stream().num_channels() > 0) { |
459 render_.render_audio.reset(new AudioBuffer( | 452 render_.render_audio.reset(new AudioBuffer( |
460 formats_.api_format.reverse_input_stream().num_frames(), | 453 formats_.api_format.reverse_input_stream().num_frames(), |
461 formats_.api_format.reverse_input_stream().num_channels(), | 454 formats_.api_format.reverse_input_stream().num_channels(), |
462 formats_.render_processing_format.num_frames(), | 455 formats_.render_processing_format.num_frames(), |
463 formats_.render_processing_format.num_channels(), | 456 formats_.render_processing_format.num_channels(), |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 capture_nonlocked_.capture_processing_format = | 562 capture_nonlocked_.capture_processing_format = |
570 StreamConfig(capture_processing_rate); | 563 StreamConfig(capture_processing_rate); |
571 | 564 |
572 int render_processing_rate = FindNativeProcessRateToUse( | 565 int render_processing_rate = FindNativeProcessRateToUse( |
573 std::min(formats_.api_format.reverse_input_stream().sample_rate_hz(), | 566 std::min(formats_.api_format.reverse_input_stream().sample_rate_hz(), |
574 formats_.api_format.reverse_output_stream().sample_rate_hz()), | 567 formats_.api_format.reverse_output_stream().sample_rate_hz()), |
575 submodule_states_.CaptureMultiBandSubModulesActive() || | 568 submodule_states_.CaptureMultiBandSubModulesActive() || |
576 submodule_states_.RenderMultiBandSubModulesActive()); | 569 submodule_states_.RenderMultiBandSubModulesActive()); |
577 // TODO(aluebs): Remove this restriction once we figure out why the 3-band | 570 // TODO(aluebs): Remove this restriction once we figure out why the 3-band |
578 // splitting filter degrades the AEC performance. | 571 // splitting filter degrades the AEC performance. |
579 // TODO(peah): Verify that the band splitting is needed for the AEC3. | 572 if (render_processing_rate > kSampleRate32kHz) { |
580 if (render_processing_rate > kSampleRate32kHz && | |
581 !capture_nonlocked_.echo_canceller3_enabled) { | |
582 render_processing_rate = submodule_states_.RenderMultiBandProcessingActive() | 573 render_processing_rate = submodule_states_.RenderMultiBandProcessingActive() |
583 ? kSampleRate32kHz | 574 ? kSampleRate32kHz |
584 : kSampleRate16kHz; | 575 : kSampleRate16kHz; |
585 } | 576 } |
586 // If the forward sample rate is 8 kHz, the render stream is also processed | 577 // If the forward sample rate is 8 kHz, the render stream is also processed |
587 // at this rate. | 578 // at this rate. |
588 if (capture_nonlocked_.capture_processing_format.sample_rate_hz() == | 579 if (capture_nonlocked_.capture_processing_format.sample_rate_hz() == |
589 kSampleRate8kHz) { | 580 kSampleRate8kHz) { |
590 render_processing_rate = kSampleRate8kHz; | 581 render_processing_rate = kSampleRate8kHz; |
591 } else { | 582 } else { |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 capture_buffer->channels()[0], capture_buffer->num_channels(), | 1146 capture_buffer->channels()[0], capture_buffer->num_channels(), |
1156 capture_nonlocked_.capture_processing_format.num_frames()); | 1147 capture_nonlocked_.capture_processing_format.num_frames()); |
1157 } | 1148 } |
1158 | 1149 |
1159 if (submodule_states_.CaptureMultiBandSubModulesActive() && | 1150 if (submodule_states_.CaptureMultiBandSubModulesActive() && |
1160 SampleRateSupportsMultiBand( | 1151 SampleRateSupportsMultiBand( |
1161 capture_nonlocked_.capture_processing_format.sample_rate_hz())) { | 1152 capture_nonlocked_.capture_processing_format.sample_rate_hz())) { |
1162 capture_buffer->SplitIntoFrequencyBands(); | 1153 capture_buffer->SplitIntoFrequencyBands(); |
1163 } | 1154 } |
1164 | 1155 |
| 1156 if (private_submodules_->echo_canceller3) { |
| 1157 // Force down-mixing of the number of channels after the detection of |
| 1158 // capture signal saturation. |
| 1159 // TODO(peah): Look into ensuring that this kind of tampering with the |
| 1160 // AudioBuffer functionality should not be needed. |
| 1161 capture_buffer->set_num_channels(1); |
| 1162 } |
| 1163 |
1165 if (capture_nonlocked_.beamformer_enabled) { | 1164 if (capture_nonlocked_.beamformer_enabled) { |
1166 private_submodules_->beamformer->AnalyzeChunk( | 1165 private_submodules_->beamformer->AnalyzeChunk( |
1167 *capture_buffer->split_data_f()); | 1166 *capture_buffer->split_data_f()); |
1168 // Discards all channels by the leftmost one. | 1167 // Discards all channels by the leftmost one. |
1169 capture_buffer->set_num_channels(1); | 1168 capture_buffer->set_num_channels(1); |
1170 } | 1169 } |
1171 | 1170 |
1172 // TODO(peah): Move the AEC3 low-cut filter to this place. | 1171 // TODO(peah): Move the AEC3 low-cut filter to this place. |
1173 if (private_submodules_->low_cut_filter && | 1172 if (private_submodules_->low_cut_filter && |
1174 !private_submodules_->echo_canceller3) { | 1173 !private_submodules_->echo_canceller3) { |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1986 capture_processing_format(kSampleRate16kHz), | 1985 capture_processing_format(kSampleRate16kHz), |
1987 split_rate(kSampleRate16kHz) {} | 1986 split_rate(kSampleRate16kHz) {} |
1988 | 1987 |
1989 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; | 1988 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; |
1990 | 1989 |
1991 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; | 1990 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; |
1992 | 1991 |
1993 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; | 1992 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; |
1994 | 1993 |
1995 } // namespace webrtc | 1994 } // namespace webrtc |
OLD | NEW |