Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Side by Side Diff: webrtc/modules/audio_processing/audio_processing_impl.cc

Issue 1563493005: Make Beamforming dynamically settable for Android platform builds (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Re-add num_out_channels > 1 restriction Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/audio_processing/audio_processing_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 207 }
208 208
209 AudioProcessingImpl::AudioProcessingImpl(const Config& config) 209 AudioProcessingImpl::AudioProcessingImpl(const Config& config)
210 : AudioProcessingImpl(config, nullptr) {} 210 : AudioProcessingImpl(config, nullptr) {}
211 211
212 AudioProcessingImpl::AudioProcessingImpl(const Config& config, 212 AudioProcessingImpl::AudioProcessingImpl(const Config& config,
213 Beamformer<float>* beamformer) 213 Beamformer<float>* beamformer)
214 : public_submodules_(new ApmPublicSubmodules()), 214 : public_submodules_(new ApmPublicSubmodules()),
215 private_submodules_(new ApmPrivateSubmodules(beamformer)), 215 private_submodules_(new ApmPrivateSubmodules(beamformer)),
216 constants_(config.Get<ExperimentalAgc>().startup_min_volume, 216 constants_(config.Get<ExperimentalAgc>().startup_min_volume,
217 config.Get<Beamforming>().array_geometry,
218 config.Get<Beamforming>().target_direction,
219 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) 217 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
220 false, 218 false,
221 #else 219 #else
222 config.Get<ExperimentalAgc>().enabled, 220 config.Get<ExperimentalAgc>().enabled,
223 #endif 221 #endif
224 config.Get<Intelligibility>().enabled, 222 config.Get<Intelligibility>().enabled),
225 config.Get<Beamforming>().enabled),
226 223
227 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) 224 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
228 capture_(false) 225 capture_(false,
229 #else 226 #else
230 capture_(config.Get<ExperimentalNs>().enabled) 227 capture_(config.Get<ExperimentalNs>().enabled,
231 #endif 228 #endif
229 config.Get<Beamforming>().enabled,
230 config.Get<Beamforming>().array_geometry,
231 config.Get<Beamforming>().target_direction)
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
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 constants_.beamformer_enabled 348 capture_.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
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 (constants_.beamformer_enabled && (static_cast<size_t>(num_in_channels) != 431 if (capture_.beamformer_enabled &&
432 constants_.array_geometry.size() || 432 (static_cast<size_t>(num_in_channels) != capture_.array_geometry.size() ||
433 num_out_channels > 1)) { 433 num_out_channels > 1)) {
434 return kBadNumberChannelsError; 434 return kBadNumberChannelsError;
435 } 435 }
436 436
437 formats_.api_format = config; 437 formats_.api_format = config;
438 438
439 // We process at the closest native rate >= min(input rate, output rate)... 439 // We process at the closest native rate >= min(input rate, output rate)...
440 const int min_proc_rate = 440 const int min_proc_rate =
441 std::min(formats_.api_format.input_stream().sample_rate_hz(), 441 std::min(formats_.api_format.input_stream().sample_rate_hz(),
442 formats_.api_format.output_stream().sample_rate_hz()); 442 formats_.api_format.output_stream().sample_rate_hz());
443 int fwd_proc_rate; 443 int fwd_proc_rate;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 for (auto item : private_submodules_->component_list) { 491 for (auto item : private_submodules_->component_list) {
492 item->SetExtraOptions(config); 492 item->SetExtraOptions(config);
493 } 493 }
494 494
495 if (capture_.transient_suppressor_enabled != 495 if (capture_.transient_suppressor_enabled !=
496 config.Get<ExperimentalNs>().enabled) { 496 config.Get<ExperimentalNs>().enabled) {
497 capture_.transient_suppressor_enabled = 497 capture_.transient_suppressor_enabled =
498 config.Get<ExperimentalNs>().enabled; 498 config.Get<ExperimentalNs>().enabled;
499 InitializeTransient(); 499 InitializeTransient();
500 } 500 }
501
502 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
503 if (capture_.beamformer_enabled != config.Get<Beamforming>().enabled) {
504 capture_.beamformer_enabled = config.Get<Beamforming>().enabled;
505 if (config.Get<Beamforming>().array_geometry.size() > 1) {
506 capture_.array_geometry = config.Get<Beamforming>().array_geometry;
507 }
508 capture_.target_direction = config.Get<Beamforming>().target_direction;
509 InitializeBeamformer();
510 }
511 #endif // WEBRTC_ANDROID_PLATFORM_BUILD
501 } 512 }
502 513
503 int AudioProcessingImpl::input_sample_rate_hz() const { 514 int AudioProcessingImpl::input_sample_rate_hz() const {
504 // Accessed from outside APM, hence a lock is needed. 515 // Accessed from outside APM, hence a lock is needed.
505 rtc::CritScope cs(&crit_capture_); 516 rtc::CritScope cs(&crit_capture_);
506 return formats_.api_format.input_stream().sample_rate_hz(); 517 return formats_.api_format.input_stream().sample_rate_hz();
507 } 518 }
508 519
509 int AudioProcessingImpl::proc_sample_rate_hz() const { 520 int AudioProcessingImpl::proc_sample_rate_hz() const {
510 // Used as callback from submodules, hence locking is not allowed. 521 // Used as callback from submodules, hence locking is not allowed.
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 if (analysis_needed(data_processed)) { 764 if (analysis_needed(data_processed)) {
754 ca->SplitIntoFrequencyBands(); 765 ca->SplitIntoFrequencyBands();
755 } 766 }
756 767
757 if (constants_.intelligibility_enabled) { 768 if (constants_.intelligibility_enabled) {
758 public_submodules_->intelligibility_enhancer->AnalyzeCaptureAudio( 769 public_submodules_->intelligibility_enhancer->AnalyzeCaptureAudio(
759 ca->split_channels_f(kBand0To8kHz), capture_nonlocked_.split_rate, 770 ca->split_channels_f(kBand0To8kHz), capture_nonlocked_.split_rate,
760 ca->num_channels()); 771 ca->num_channels());
761 } 772 }
762 773
763 if (constants_.beamformer_enabled) { 774 if (capture_.beamformer_enabled) {
764 private_submodules_->beamformer->ProcessChunk(*ca->split_data_f(), 775 private_submodules_->beamformer->ProcessChunk(*ca->split_data_f(),
765 ca->split_data_f()); 776 ca->split_data_f());
766 ca->set_num_channels(1); 777 ca->set_num_channels(1);
767 } 778 }
768 779
769 public_submodules_->high_pass_filter->ProcessCaptureAudio(ca); 780 public_submodules_->high_pass_filter->ProcessCaptureAudio(ca);
770 RETURN_ON_ERR(public_submodules_->gain_control->AnalyzeCaptureAudio(ca)); 781 RETURN_ON_ERR(public_submodules_->gain_control->AnalyzeCaptureAudio(ca));
771 public_submodules_->noise_suppression->AnalyzeCaptureAudio(ca); 782 public_submodules_->noise_suppression->AnalyzeCaptureAudio(ca);
772 RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessCaptureAudio(ca)); 783 RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessCaptureAudio(ca));
773 784
774 if (public_submodules_->echo_control_mobile->is_enabled() && 785 if (public_submodules_->echo_control_mobile->is_enabled() &&
775 public_submodules_->noise_suppression->is_enabled()) { 786 public_submodules_->noise_suppression->is_enabled()) {
776 ca->CopyLowPassToReference(); 787 ca->CopyLowPassToReference();
777 } 788 }
778 public_submodules_->noise_suppression->ProcessCaptureAudio(ca); 789 public_submodules_->noise_suppression->ProcessCaptureAudio(ca);
779 RETURN_ON_ERR( 790 RETURN_ON_ERR(
780 public_submodules_->echo_control_mobile->ProcessCaptureAudio(ca)); 791 public_submodules_->echo_control_mobile->ProcessCaptureAudio(ca));
781 public_submodules_->voice_detection->ProcessCaptureAudio(ca); 792 public_submodules_->voice_detection->ProcessCaptureAudio(ca);
782 793
783 if (constants_.use_new_agc && 794 if (constants_.use_new_agc &&
784 public_submodules_->gain_control->is_enabled() && 795 public_submodules_->gain_control->is_enabled() &&
785 (!constants_.beamformer_enabled || 796 (!capture_.beamformer_enabled ||
786 private_submodules_->beamformer->is_target_present())) { 797 private_submodules_->beamformer->is_target_present())) {
787 private_submodules_->agc_manager->Process( 798 private_submodules_->agc_manager->Process(
788 ca->split_bands_const(0)[kBand0To8kHz], ca->num_frames_per_band(), 799 ca->split_bands_const(0)[kBand0To8kHz], ca->num_frames_per_band(),
789 capture_nonlocked_.split_rate); 800 capture_nonlocked_.split_rate);
790 } 801 }
791 RETURN_ON_ERR(public_submodules_->gain_control->ProcessCaptureAudio(ca)); 802 RETURN_ON_ERR(public_submodules_->gain_control->ProcessCaptureAudio(ca));
792 803
793 if (synthesis_needed(data_processed)) { 804 if (synthesis_needed(data_processed)) {
794 ca->MergeFrequencyBands(); 805 ca->MergeFrequencyBands();
795 } 806 }
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 return public_submodules_->noise_suppression.get(); 1176 return public_submodules_->noise_suppression.get();
1166 } 1177 }
1167 1178
1168 VoiceDetection* AudioProcessingImpl::voice_detection() const { 1179 VoiceDetection* AudioProcessingImpl::voice_detection() const {
1169 // Adding a lock here has no effect as it allows any access to the submodule 1180 // Adding a lock here has no effect as it allows any access to the submodule
1170 // from the returned pointer. 1181 // from the returned pointer.
1171 return public_submodules_->voice_detection.get(); 1182 return public_submodules_->voice_detection.get();
1172 } 1183 }
1173 1184
1174 bool AudioProcessingImpl::is_data_processed() const { 1185 bool AudioProcessingImpl::is_data_processed() const {
1175 if (constants_.beamformer_enabled) { 1186 if (capture_.beamformer_enabled) {
1176 return true; 1187 return true;
1177 } 1188 }
1178 1189
1179 int enabled_count = 0; 1190 int enabled_count = 0;
1180 for (auto item : private_submodules_->component_list) { 1191 for (auto item : private_submodules_->component_list) {
1181 if (item->is_component_enabled()) { 1192 if (item->is_component_enabled()) {
1182 enabled_count++; 1193 enabled_count++;
1183 } 1194 }
1184 } 1195 }
1185 if (public_submodules_->high_pass_filter->is_enabled()) { 1196 if (public_submodules_->high_pass_filter->is_enabled()) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 public_submodules_->transient_suppressor.reset(new TransientSuppressor()); 1291 public_submodules_->transient_suppressor.reset(new TransientSuppressor());
1281 } 1292 }
1282 public_submodules_->transient_suppressor->Initialize( 1293 public_submodules_->transient_suppressor->Initialize(
1283 capture_nonlocked_.fwd_proc_format.sample_rate_hz(), 1294 capture_nonlocked_.fwd_proc_format.sample_rate_hz(),
1284 capture_nonlocked_.split_rate, 1295 capture_nonlocked_.split_rate,
1285 formats_.api_format.output_stream().num_channels()); 1296 formats_.api_format.output_stream().num_channels());
1286 } 1297 }
1287 } 1298 }
1288 1299
1289 void AudioProcessingImpl::InitializeBeamformer() { 1300 void AudioProcessingImpl::InitializeBeamformer() {
1290 if (constants_.beamformer_enabled) { 1301 if (capture_.beamformer_enabled) {
1291 if (!private_submodules_->beamformer) { 1302 if (!private_submodules_->beamformer) {
1292 private_submodules_->beamformer.reset(new NonlinearBeamformer( 1303 private_submodules_->beamformer.reset(new NonlinearBeamformer(
1293 constants_.array_geometry, constants_.target_direction)); 1304 capture_.array_geometry, capture_.target_direction));
1294 } 1305 }
1295 private_submodules_->beamformer->Initialize(kChunkSizeMs, 1306 private_submodules_->beamformer->Initialize(kChunkSizeMs,
1296 capture_nonlocked_.split_rate); 1307 capture_nonlocked_.split_rate);
1297 } 1308 }
1298 } 1309 }
1299 1310
1300 void AudioProcessingImpl::InitializeIntelligibility() { 1311 void AudioProcessingImpl::InitializeIntelligibility() {
1301 if (constants_.intelligibility_enabled) { 1312 if (constants_.intelligibility_enabled) {
1302 IntelligibilityEnhancer::Config config; 1313 IntelligibilityEnhancer::Config config;
1303 config.sample_rate_hz = capture_nonlocked_.split_rate; 1314 config.sample_rate_hz = capture_nonlocked_.split_rate;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 debug_dump_.capture.event_msg->set_type(audioproc::Event::CONFIG); 1515 debug_dump_.capture.event_msg->set_type(audioproc::Event::CONFIG);
1505 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config); 1516 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config);
1506 1517
1507 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), 1518 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
1508 &crit_debug_, &debug_dump_.capture)); 1519 &crit_debug_, &debug_dump_.capture));
1509 return kNoError; 1520 return kNoError;
1510 } 1521 }
1511 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 1522 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1512 1523
1513 } // namespace webrtc 1524 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/audio_processing_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698