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 24 matching lines...) Expand all Loading... | |
35 #include "webrtc/modules/audio_processing/noise_suppression_impl.h" | 35 #include "webrtc/modules/audio_processing/noise_suppression_impl.h" |
36 #include "webrtc/modules/audio_processing/processing_component.h" | 36 #include "webrtc/modules/audio_processing/processing_component.h" |
37 #include "webrtc/modules/audio_processing/transient/transient_suppressor.h" | 37 #include "webrtc/modules/audio_processing/transient/transient_suppressor.h" |
38 #include "webrtc/modules/audio_processing/voice_detection_impl.h" | 38 #include "webrtc/modules/audio_processing/voice_detection_impl.h" |
39 #include "webrtc/modules/interface/module_common_types.h" | 39 #include "webrtc/modules/interface/module_common_types.h" |
40 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 40 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
41 #include "webrtc/system_wrappers/interface/file_wrapper.h" | 41 #include "webrtc/system_wrappers/interface/file_wrapper.h" |
42 #include "webrtc/system_wrappers/interface/logging.h" | 42 #include "webrtc/system_wrappers/interface/logging.h" |
43 #include "webrtc/system_wrappers/interface/metrics.h" | 43 #include "webrtc/system_wrappers/interface/metrics.h" |
44 | 44 |
45 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | |
Andrew MacDonald
2015/10/01 06:33:28
Why was this removed?
minyue-webrtc
2015/10/01 20:18:26
This is moved to .h since audioproc::Config is nee
| |
46 // Files generated at build-time by the protobuf compiler. | |
47 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | |
48 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h" | |
49 #else | |
50 #include "webrtc/audio_processing/debug.pb.h" | |
51 #endif | |
52 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | |
53 | |
54 #define RETURN_ON_ERR(expr) \ | 45 #define RETURN_ON_ERR(expr) \ |
55 do { \ | 46 do { \ |
56 int err = (expr); \ | 47 int err = (expr); \ |
57 if (err != kNoError) { \ | 48 if (err != kNoError) { \ |
58 return err; \ | 49 return err; \ |
59 } \ | 50 } \ |
60 } while (0) | 51 } while (0) |
61 | 52 |
53 #define UPDATE_CONFIG(field_name, new_value) \ | |
54 { \ | |
55 const auto value = new_value; \ | |
56 if (!config_->has_##field_name() || config_->field_name() != value) { \ | |
57 config_->set_##field_name(value); \ | |
58 changed = true; \ | |
59 } \ | |
60 } | |
61 | |
62 namespace webrtc { | 62 namespace webrtc { |
63 namespace { | 63 namespace { |
64 | 64 |
65 static bool LayoutHasKeyboard(AudioProcessing::ChannelLayout layout) { | 65 static bool LayoutHasKeyboard(AudioProcessing::ChannelLayout layout) { |
66 switch (layout) { | 66 switch (layout) { |
67 case AudioProcessing::kMono: | 67 case AudioProcessing::kMono: |
68 case AudioProcessing::kStereo: | 68 case AudioProcessing::kStereo: |
69 return false; | 69 return false; |
70 case AudioProcessing::kMonoAndKeyboard: | 70 case AudioProcessing::kMonoAndKeyboard: |
71 case AudioProcessing::kStereoAndKeyboard: | 71 case AudioProcessing::kStereoAndKeyboard: |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 echo_control_mobile_(NULL), | 187 echo_control_mobile_(NULL), |
188 gain_control_(NULL), | 188 gain_control_(NULL), |
189 high_pass_filter_(NULL), | 189 high_pass_filter_(NULL), |
190 level_estimator_(NULL), | 190 level_estimator_(NULL), |
191 noise_suppression_(NULL), | 191 noise_suppression_(NULL), |
192 voice_detection_(NULL), | 192 voice_detection_(NULL), |
193 crit_(CriticalSectionWrapper::CreateCriticalSection()), | 193 crit_(CriticalSectionWrapper::CreateCriticalSection()), |
194 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 194 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
195 debug_file_(FileWrapper::Create()), | 195 debug_file_(FileWrapper::Create()), |
196 event_msg_(new audioproc::Event()), | 196 event_msg_(new audioproc::Event()), |
197 config_(new audioproc::Config()), | |
197 #endif | 198 #endif |
198 api_format_({{{kSampleRate16kHz, 1, false}, | 199 api_format_({{{kSampleRate16kHz, 1, false}, |
199 {kSampleRate16kHz, 1, false}, | 200 {kSampleRate16kHz, 1, false}, |
200 {kSampleRate16kHz, 1, false}, | 201 {kSampleRate16kHz, 1, false}, |
201 {kSampleRate16kHz, 1, false}}}), | 202 {kSampleRate16kHz, 1, false}}}), |
202 fwd_proc_format_(kSampleRate16kHz), | 203 fwd_proc_format_(kSampleRate16kHz), |
203 rev_proc_format_(kSampleRate16kHz, 1), | 204 rev_proc_format_(kSampleRate16kHz, 1), |
204 split_rate_(kSampleRate16kHz), | 205 split_rate_(kSampleRate16kHz), |
205 stream_delay_ms_(0), | 206 stream_delay_ms_(0), |
206 delay_offset_ms_(0), | 207 delay_offset_ms_(0), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 | 244 |
244 noise_suppression_ = new NoiseSuppressionImpl(this, crit_); | 245 noise_suppression_ = new NoiseSuppressionImpl(this, crit_); |
245 component_list_.push_back(noise_suppression_); | 246 component_list_.push_back(noise_suppression_); |
246 | 247 |
247 voice_detection_ = new VoiceDetectionImpl(this, crit_); | 248 voice_detection_ = new VoiceDetectionImpl(this, crit_); |
248 component_list_.push_back(voice_detection_); | 249 component_list_.push_back(voice_detection_); |
249 | 250 |
250 gain_control_for_new_agc_.reset(new GainControlForNewAgc(gain_control_)); | 251 gain_control_for_new_agc_.reset(new GainControlForNewAgc(gain_control_)); |
251 | 252 |
252 SetExtraOptions(config); | 253 SetExtraOptions(config); |
254 | |
255 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | |
256 UpdateCurrentConfig(); | |
257 #endif | |
253 } | 258 } |
254 | 259 |
255 AudioProcessingImpl::~AudioProcessingImpl() { | 260 AudioProcessingImpl::~AudioProcessingImpl() { |
256 { | 261 { |
257 CriticalSectionScoped crit_scoped(crit_); | 262 CriticalSectionScoped crit_scoped(crit_); |
258 // Depends on gain_control_ and gain_control_for_new_agc_. | 263 // Depends on gain_control_ and gain_control_for_new_agc_. |
259 agc_manager_.reset(); | 264 agc_manager_.reset(); |
260 // Depends on gain_control_. | 265 // Depends on gain_control_. |
261 gain_control_for_new_agc_.reset(); | 266 gain_control_for_new_agc_.reset(); |
262 while (!component_list_.empty()) { | 267 while (!component_list_.empty()) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 return kBadNumberChannelsError; | 409 return kBadNumberChannelsError; |
405 } | 410 } |
406 | 411 |
407 api_format_ = config; | 412 api_format_ = config; |
408 | 413 |
409 // We process at the closest native rate >= min(input rate, output rate)... | 414 // We process at the closest native rate >= min(input rate, output rate)... |
410 const int min_proc_rate = | 415 const int min_proc_rate = |
411 std::min(api_format_.input_stream().sample_rate_hz(), | 416 std::min(api_format_.input_stream().sample_rate_hz(), |
412 api_format_.output_stream().sample_rate_hz()); | 417 api_format_.output_stream().sample_rate_hz()); |
413 int fwd_proc_rate; | 418 int fwd_proc_rate; |
414 for (size_t i = 0; i < kNumNativeSampleRates; ++i) { | 419 for (size_t i = 0; i < kNumNativeSampleRates; ++i) { |
minyue-webrtc
2015/09/26 16:26:44
oh, this must come from rebasing. Sorry, I worked
| |
415 fwd_proc_rate = kNativeSampleRatesHz[i]; | 420 fwd_proc_rate = kNativeSampleRatesHz[i]; |
416 if (fwd_proc_rate >= min_proc_rate) { | 421 if (fwd_proc_rate >= min_proc_rate) { |
417 break; | 422 break; |
418 } | 423 } |
419 } | 424 } |
420 // ...with one exception. | 425 // ...with one exception. |
421 if (echo_control_mobile_->is_enabled() && | 426 if (echo_control_mobile_->is_enabled() && |
minyue-webrtc
2015/09/26 16:26:44
rebase
| |
422 min_proc_rate > kMaxAECMSampleRateHz) { | 427 min_proc_rate > kMaxAECMSampleRateHz) { |
423 fwd_proc_rate = kMaxAECMSampleRateHz; | 428 fwd_proc_rate = kMaxAECMSampleRateHz; |
424 } | 429 } |
425 | 430 |
426 fwd_proc_format_ = StreamConfig(fwd_proc_rate); | 431 fwd_proc_format_ = StreamConfig(fwd_proc_rate); |
427 | 432 |
428 // We normally process the reverse stream at 16 kHz. Unless... | 433 // We normally process the reverse stream at 16 kHz. Unless... |
429 int rev_proc_rate = kSampleRate16kHz; | 434 int rev_proc_rate = kSampleRate16kHz; |
430 if (fwd_proc_format_.sample_rate_hz() == kSampleRate8kHz) { | 435 if (fwd_proc_format_.sample_rate_hz() == kSampleRate8kHz) { |
431 // ...the forward stream is at 8 kHz. | 436 // ...the forward stream is at 8 kHz. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 | 558 |
554 ProcessingConfig processing_config = api_format_; | 559 ProcessingConfig processing_config = api_format_; |
555 processing_config.input_stream() = input_config; | 560 processing_config.input_stream() = input_config; |
556 processing_config.output_stream() = output_config; | 561 processing_config.output_stream() = output_config; |
557 | 562 |
558 RETURN_ON_ERR(MaybeInitializeLocked(processing_config)); | 563 RETURN_ON_ERR(MaybeInitializeLocked(processing_config)); |
559 assert(processing_config.input_stream().num_frames() == | 564 assert(processing_config.input_stream().num_frames() == |
560 api_format_.input_stream().num_frames()); | 565 api_format_.input_stream().num_frames()); |
561 | 566 |
562 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 567 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
568 if (debug_file_->Open() && UpdateCurrentConfig()) { | |
569 RETURN_ON_ERR(WriteConfigMessage()); | |
570 } | |
571 #endif | |
Andrew MacDonald
2015/10/01 06:33:28
Combine these #ifdef blocks.
minyue-webrtc
2015/10/01 20:18:26
Done.
| |
572 | |
573 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | |
563 if (debug_file_->Open()) { | 574 if (debug_file_->Open()) { |
564 event_msg_->set_type(audioproc::Event::STREAM); | 575 event_msg_->set_type(audioproc::Event::STREAM); |
565 audioproc::Stream* msg = event_msg_->mutable_stream(); | 576 audioproc::Stream* msg = event_msg_->mutable_stream(); |
566 const size_t channel_size = | 577 const size_t channel_size = |
567 sizeof(float) * api_format_.input_stream().num_frames(); | 578 sizeof(float) * api_format_.input_stream().num_frames(); |
568 for (int i = 0; i < api_format_.input_stream().num_channels(); ++i) | 579 for (int i = 0; i < api_format_.input_stream().num_channels(); ++i) |
569 msg->add_input_channel(src[i], channel_size); | 580 msg->add_input_channel(src[i], channel_size); |
570 } | 581 } |
571 #endif | 582 #endif |
572 | 583 |
(...skipping 21 matching lines...) Expand all Loading... | |
594 return kNullPointerError; | 605 return kNullPointerError; |
595 } | 606 } |
596 // Must be a native rate. | 607 // Must be a native rate. |
597 if (frame->sample_rate_hz_ != kSampleRate8kHz && | 608 if (frame->sample_rate_hz_ != kSampleRate8kHz && |
598 frame->sample_rate_hz_ != kSampleRate16kHz && | 609 frame->sample_rate_hz_ != kSampleRate16kHz && |
599 frame->sample_rate_hz_ != kSampleRate32kHz && | 610 frame->sample_rate_hz_ != kSampleRate32kHz && |
600 frame->sample_rate_hz_ != kSampleRate48kHz) { | 611 frame->sample_rate_hz_ != kSampleRate48kHz) { |
601 return kBadSampleRateError; | 612 return kBadSampleRateError; |
602 } | 613 } |
603 if (echo_control_mobile_->is_enabled() && | 614 if (echo_control_mobile_->is_enabled() && |
604 frame->sample_rate_hz_ > kMaxAECMSampleRateHz) { | 615 frame->sample_rate_hz_ > kMaxAECMSampleRateHz) { |
minyue-webrtc
2015/09/26 16:26:44
rebase
| |
605 LOG(LS_ERROR) << "AECM only supports 16 or 8 kHz sample rates"; | 616 LOG(LS_ERROR) << "AECM only supports 16 or 8 kHz sample rates"; |
606 return kUnsupportedComponentError; | 617 return kUnsupportedComponentError; |
607 } | 618 } |
608 | 619 |
609 // TODO(ajm): The input and output rates and channels are currently | 620 // TODO(ajm): The input and output rates and channels are currently |
610 // constrained to be identical in the int16 interface. | 621 // constrained to be identical in the int16 interface. |
611 ProcessingConfig processing_config = api_format_; | 622 ProcessingConfig processing_config = api_format_; |
612 processing_config.input_stream().set_sample_rate_hz(frame->sample_rate_hz_); | 623 processing_config.input_stream().set_sample_rate_hz(frame->sample_rate_hz_); |
613 processing_config.input_stream().set_num_channels(frame->num_channels_); | 624 processing_config.input_stream().set_num_channels(frame->num_channels_); |
614 processing_config.output_stream().set_sample_rate_hz(frame->sample_rate_hz_); | 625 processing_config.output_stream().set_sample_rate_hz(frame->sample_rate_hz_); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
939 if (debug_file_->CloseFile() == -1) { | 950 if (debug_file_->CloseFile() == -1) { |
940 return kFileError; | 951 return kFileError; |
941 } | 952 } |
942 } | 953 } |
943 | 954 |
944 if (debug_file_->OpenFile(filename, false) == -1) { | 955 if (debug_file_->OpenFile(filename, false) == -1) { |
945 debug_file_->CloseFile(); | 956 debug_file_->CloseFile(); |
946 return kFileError; | 957 return kFileError; |
947 } | 958 } |
948 | 959 |
949 int err = WriteInitMessage(); | 960 UpdateCurrentConfig(); |
961 int err = WriteConfigMessage(); | |
950 if (err != kNoError) { | 962 if (err != kNoError) { |
951 return err; | 963 return err; |
952 } | 964 } |
965 | |
966 err = WriteInitMessage(); | |
967 if (err != kNoError) { | |
968 return err; | |
969 } | |
953 return kNoError; | 970 return kNoError; |
954 #else | 971 #else |
955 return kUnsupportedFunctionError; | 972 return kUnsupportedFunctionError; |
956 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 973 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
957 } | 974 } |
958 | 975 |
959 int AudioProcessingImpl::StartDebugRecording(FILE* handle) { | 976 int AudioProcessingImpl::StartDebugRecording(FILE* handle) { |
960 CriticalSectionScoped crit_scoped(crit_); | 977 CriticalSectionScoped crit_scoped(crit_); |
961 | 978 |
962 if (handle == NULL) { | 979 if (handle == NULL) { |
963 return kNullPointerError; | 980 return kNullPointerError; |
964 } | 981 } |
965 | 982 |
966 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 983 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
967 // Stop any ongoing recording. | 984 // Stop any ongoing recording. |
968 if (debug_file_->Open()) { | 985 if (debug_file_->Open()) { |
969 if (debug_file_->CloseFile() == -1) { | 986 if (debug_file_->CloseFile() == -1) { |
970 return kFileError; | 987 return kFileError; |
971 } | 988 } |
972 } | 989 } |
973 | 990 |
974 if (debug_file_->OpenFromFileHandle(handle, true, false) == -1) { | 991 if (debug_file_->OpenFromFileHandle(handle, true, false) == -1) { |
975 return kFileError; | 992 return kFileError; |
976 } | 993 } |
977 | 994 |
978 int err = WriteInitMessage(); | 995 UpdateCurrentConfig(); |
996 int err = WriteConfigMessage(); | |
979 if (err != kNoError) { | 997 if (err != kNoError) { |
980 return err; | 998 return err; |
981 } | 999 } |
1000 | |
1001 err = WriteInitMessage(); | |
1002 if (err != kNoError) { | |
1003 return err; | |
1004 } | |
982 return kNoError; | 1005 return kNoError; |
983 #else | 1006 #else |
984 return kUnsupportedFunctionError; | 1007 return kUnsupportedFunctionError; |
985 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1008 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
986 } | 1009 } |
987 | 1010 |
988 int AudioProcessingImpl::StartDebugRecordingForPlatformFile( | 1011 int AudioProcessingImpl::StartDebugRecordingForPlatformFile( |
989 rtc::PlatformFile handle) { | 1012 rtc::PlatformFile handle) { |
990 FILE* stream = rtc::FdopenPlatformFileForWriting(handle); | 1013 FILE* stream = rtc::FdopenPlatformFileForWriting(handle); |
991 return StartDebugRecording(stream); | 1014 return StartDebugRecording(stream); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1248 msg->set_output_sample_rate(api_format_.output_stream().sample_rate_hz()); | 1271 msg->set_output_sample_rate(api_format_.output_stream().sample_rate_hz()); |
1249 // TODO(ekmeyerson): Add reverse output fields to event_msg_. | 1272 // TODO(ekmeyerson): Add reverse output fields to event_msg_. |
1250 | 1273 |
1251 int err = WriteMessageToDebugFile(); | 1274 int err = WriteMessageToDebugFile(); |
1252 if (err != kNoError) { | 1275 if (err != kNoError) { |
1253 return err; | 1276 return err; |
1254 } | 1277 } |
1255 | 1278 |
1256 return kNoError; | 1279 return kNoError; |
1257 } | 1280 } |
1281 | |
1282 bool AudioProcessingImpl::UpdateCurrentConfig() { | |
Andrew MacDonald
2015/10/01 06:33:28
I wonder if rather than checking every individual
minyue-webrtc
2015/10/01 20:18:26
I did a similar trial (not a string compare, but a
Andrew MacDonald
2015/10/02 02:15:19
I wouldn't worry about that, as it would only be u
minyue-webrtc
2015/10/02 05:29:01
I still have some questions on this. Do you mean
Andrew MacDonald
2015/10/02 06:07:39
To be clear, I mean this:
https://codereview.webrt
| |
1283 bool changed = false; | |
1284 | |
1285 // Acoustic echo canceler. | |
1286 UPDATE_CONFIG(aec_enabled, echo_cancellation_->is_enabled()); | |
peah-webrtc
2015/09/30 13:13:54
Sorry, missed to send this before, had a draft tha
minyue-webrtc
2015/09/30 18:44:52
I would like to use function but it does not seem
peah-webrtc
2015/10/01 05:31:31
I'd use a function instead with more parameters.
Andrew MacDonald
2015/10/01 06:33:28
Agree with Per, I probably would not use a macro f
kwiberg-webrtc
2015/10/01 08:26:22
A good compromise might be to implement almost all
minyue-webrtc
2015/10/01 20:18:26
It is rather complicated to use inline function, s
| |
1287 UPDATE_CONFIG(aec_delay_agnostic, | |
1288 echo_cancellation_->is_delay_agnostic_enabled()); | |
1289 UPDATE_CONFIG(aec_drift_compensation, | |
1290 echo_cancellation_->is_drift_compensation_enabled()); | |
1291 UPDATE_CONFIG(aec_extended_filter, | |
1292 echo_cancellation_->is_extended_filter_enabled()); | |
1293 UPDATE_CONFIG(aec_suppression_level, | |
1294 static_cast<int>(echo_cancellation_->suppression_level())); | |
1295 // Mobile AEC. | |
1296 UPDATE_CONFIG(aecm_enabled, echo_control_mobile_->is_enabled()); | |
1297 UPDATE_CONFIG(aecm_comfort_noise, | |
1298 echo_control_mobile_->is_comfort_noise_enabled()); | |
1299 UPDATE_CONFIG(aecm_routing_mode, | |
1300 static_cast<int>(echo_control_mobile_->routing_mode())); | |
1301 // Automatic gain controller. | |
1302 UPDATE_CONFIG(agc_enabled, gain_control_->is_enabled()); | |
1303 UPDATE_CONFIG(agc_experiment, use_new_agc_); | |
1304 UPDATE_CONFIG(agc_mode, static_cast<int>(gain_control_->mode())); | |
1305 UPDATE_CONFIG(agc_limiter, gain_control_->is_limiter_enabled()); | |
1306 // High pass filter. | |
1307 UPDATE_CONFIG(hpf_enabled, high_pass_filter_->is_enabled()); | |
1308 // Noise suppression. | |
1309 UPDATE_CONFIG(ns_enabled, noise_suppression_->is_enabled()); | |
1310 UPDATE_CONFIG(ns_experiment, transient_suppressor_enabled_); | |
1311 UPDATE_CONFIG(ns_level, static_cast<int>(noise_suppression_->level())); | |
1312 | |
1313 return changed; | |
1314 } | |
1315 | |
1316 int AudioProcessingImpl::WriteConfigMessage() { | |
1317 event_msg_->set_type(audioproc::Event::CONFIG); | |
1318 event_msg_->mutable_config()->CopyFrom(*config_); | |
1319 | |
1320 int err = WriteMessageToDebugFile(); | |
1321 if (err != kNoError) { | |
1322 return err; | |
1323 } | |
1324 | |
1325 return kNoError; | |
1326 } | |
1258 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1327 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
1259 | 1328 |
1260 } // namespace webrtc | 1329 } // namespace webrtc |
OLD | NEW |