| 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 |
| 11 #include <math.h> | 11 #include <math.h> |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 #ifdef WEBRTC_ANDROID | 14 #ifdef WEBRTC_ANDROID |
| 15 #include <sys/stat.h> | 15 #include <sys/stat.h> |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 #include <algorithm> | 18 #include <algorithm> |
| 19 | 19 |
| 20 #include "webrtc/base/format_macros.h" |
| 20 #include "webrtc/base/scoped_ptr.h" | 21 #include "webrtc/base/scoped_ptr.h" |
| 21 #include "webrtc/common.h" | 22 #include "webrtc/common.h" |
| 22 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 23 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 23 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" | 24 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" |
| 24 #include "webrtc/modules/audio_processing/test/test_utils.h" | 25 #include "webrtc/modules/audio_processing/test/test_utils.h" |
| 25 #include "webrtc/modules/include/module_common_types.h" | 26 #include "webrtc/modules/include/module_common_types.h" |
| 26 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" | 27 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" |
| 27 #include "webrtc/system_wrappers/include/tick_util.h" | 28 #include "webrtc/system_wrappers/include/tick_util.h" |
| 28 #include "webrtc/test/testsupport/fileutils.h" | 29 #include "webrtc/test/testsupport/fileutils.h" |
| 29 #include "webrtc/test/testsupport/perf_test.h" | 30 #include "webrtc/test/testsupport/perf_test.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 const char* far_filename = NULL; | 153 const char* far_filename = NULL; |
| 153 const char* near_filename = NULL; | 154 const char* near_filename = NULL; |
| 154 std::string out_filename; | 155 std::string out_filename; |
| 155 const char* vad_out_filename = NULL; | 156 const char* vad_out_filename = NULL; |
| 156 const char* ns_prob_filename = NULL; | 157 const char* ns_prob_filename = NULL; |
| 157 const char* aecm_echo_path_in_filename = NULL; | 158 const char* aecm_echo_path_in_filename = NULL; |
| 158 const char* aecm_echo_path_out_filename = NULL; | 159 const char* aecm_echo_path_out_filename = NULL; |
| 159 | 160 |
| 160 int32_t sample_rate_hz = 16000; | 161 int32_t sample_rate_hz = 16000; |
| 161 | 162 |
| 162 int num_capture_input_channels = 1; | 163 size_t num_capture_input_channels = 1; |
| 163 int num_capture_output_channels = 1; | 164 size_t num_capture_output_channels = 1; |
| 164 int num_render_channels = 1; | 165 size_t num_render_channels = 1; |
| 165 | 166 |
| 166 int samples_per_channel = sample_rate_hz / 100; | 167 int samples_per_channel = sample_rate_hz / 100; |
| 167 | 168 |
| 168 bool simulating = false; | 169 bool simulating = false; |
| 169 bool perf_testing = false; | 170 bool perf_testing = false; |
| 170 bool verbose = true; | 171 bool verbose = true; |
| 171 bool progress = true; | 172 bool progress = true; |
| 172 bool raw_output = false; | 173 bool raw_output = false; |
| 173 int extra_delay_ms = 0; | 174 int extra_delay_ms = 0; |
| 174 int override_delay_ms = 0; | 175 int override_delay_ms = 0; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 200 | 201 |
| 201 } else if (strcmp(argv[i], "-fs") == 0) { | 202 } else if (strcmp(argv[i], "-fs") == 0) { |
| 202 i++; | 203 i++; |
| 203 ASSERT_LT(i, argc) << "Specify sample rate after -fs"; | 204 ASSERT_LT(i, argc) << "Specify sample rate after -fs"; |
| 204 ASSERT_EQ(1, sscanf(argv[i], "%d", &sample_rate_hz)); | 205 ASSERT_EQ(1, sscanf(argv[i], "%d", &sample_rate_hz)); |
| 205 samples_per_channel = sample_rate_hz / 100; | 206 samples_per_channel = sample_rate_hz / 100; |
| 206 | 207 |
| 207 } else if (strcmp(argv[i], "-ch") == 0) { | 208 } else if (strcmp(argv[i], "-ch") == 0) { |
| 208 i++; | 209 i++; |
| 209 ASSERT_LT(i + 1, argc) << "Specify number of channels after -ch"; | 210 ASSERT_LT(i + 1, argc) << "Specify number of channels after -ch"; |
| 210 ASSERT_EQ(1, sscanf(argv[i], "%d", &num_capture_input_channels)); | 211 ASSERT_EQ(1, sscanf(argv[i], "%" PRIuS, &num_capture_input_channels)); |
| 211 i++; | 212 i++; |
| 212 ASSERT_EQ(1, sscanf(argv[i], "%d", &num_capture_output_channels)); | 213 ASSERT_EQ(1, sscanf(argv[i], "%" PRIuS, &num_capture_output_channels)); |
| 213 | 214 |
| 214 } else if (strcmp(argv[i], "-rch") == 0) { | 215 } else if (strcmp(argv[i], "-rch") == 0) { |
| 215 i++; | 216 i++; |
| 216 ASSERT_LT(i, argc) << "Specify number of channels after -rch"; | 217 ASSERT_LT(i, argc) << "Specify number of channels after -rch"; |
| 217 ASSERT_EQ(1, sscanf(argv[i], "%d", &num_render_channels)); | 218 ASSERT_EQ(1, sscanf(argv[i], "%" PRIuS, &num_render_channels)); |
| 218 | 219 |
| 219 } else if (strcmp(argv[i], "-aec") == 0) { | 220 } else if (strcmp(argv[i], "-aec") == 0) { |
| 220 ASSERT_EQ(apm->kNoError, apm->echo_cancellation()->Enable(true)); | 221 ASSERT_EQ(apm->kNoError, apm->echo_cancellation()->Enable(true)); |
| 221 ASSERT_EQ(apm->kNoError, | 222 ASSERT_EQ(apm->kNoError, |
| 222 apm->echo_cancellation()->enable_metrics(true)); | 223 apm->echo_cancellation()->enable_metrics(true)); |
| 223 ASSERT_EQ(apm->kNoError, | 224 ASSERT_EQ(apm->kNoError, |
| 224 apm->echo_cancellation()->enable_delay_logging(true)); | 225 apm->echo_cancellation()->enable_delay_logging(true)); |
| 225 | 226 |
| 226 } else if (strcmp(argv[i], "--drift_compensation") == 0) { | 227 } else if (strcmp(argv[i], "--drift_compensation") == 0) { |
| 227 ASSERT_EQ(apm->kNoError, apm->echo_cancellation()->Enable(true)); | 228 ASSERT_EQ(apm->kNoError, apm->echo_cancellation()->Enable(true)); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 } | 441 } |
| 441 } | 442 } |
| 442 apm->SetExtraOptions(config); | 443 apm->SetExtraOptions(config); |
| 443 | 444 |
| 444 // If we're reading a protobuf file, ensure a simulation hasn't also | 445 // If we're reading a protobuf file, ensure a simulation hasn't also |
| 445 // been requested (which makes no sense...) | 446 // been requested (which makes no sense...) |
| 446 ASSERT_FALSE(pb_filename && simulating); | 447 ASSERT_FALSE(pb_filename && simulating); |
| 447 | 448 |
| 448 if (verbose) { | 449 if (verbose) { |
| 449 printf("Sample rate: %d Hz\n", sample_rate_hz); | 450 printf("Sample rate: %d Hz\n", sample_rate_hz); |
| 450 printf("Primary channels: %d (in), %d (out)\n", | 451 printf("Primary channels: %" PRIuS " (in), %" PRIuS " (out)\n", |
| 451 num_capture_input_channels, | 452 num_capture_input_channels, |
| 452 num_capture_output_channels); | 453 num_capture_output_channels); |
| 453 printf("Reverse channels: %d \n", num_render_channels); | 454 printf("Reverse channels: %" PRIuS "\n", num_render_channels); |
| 454 } | 455 } |
| 455 | 456 |
| 456 const std::string out_path = webrtc::test::OutputPath(); | 457 const std::string out_path = webrtc::test::OutputPath(); |
| 457 const char far_file_default[] = "apm_far.pcm"; | 458 const char far_file_default[] = "apm_far.pcm"; |
| 458 const char near_file_default[] = "apm_near.pcm"; | 459 const char near_file_default[] = "apm_near.pcm"; |
| 459 const char event_filename[] = "apm_event.dat"; | 460 const char event_filename[] = "apm_event.dat"; |
| 460 const char delay_filename[] = "apm_delay.dat"; | 461 const char delay_filename[] = "apm_delay.dat"; |
| 461 const char drift_filename[] = "apm_drift.dat"; | 462 const char drift_filename[] = "apm_drift.dat"; |
| 462 const std::string vad_file_default = out_path + "vad_out.dat"; | 463 const std::string vad_file_default = out_path + "vad_out.dat"; |
| 463 const std::string ns_prob_file_default = out_path + "ns_prob.dat"; | 464 const std::string ns_prob_file_default = out_path + "ns_prob.dat"; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 ASSERT_TRUE(msg.has_num_output_channels()); | 595 ASSERT_TRUE(msg.has_num_output_channels()); |
| 595 ASSERT_TRUE(msg.has_num_reverse_channels()); | 596 ASSERT_TRUE(msg.has_num_reverse_channels()); |
| 596 int reverse_sample_rate = msg.sample_rate(); | 597 int reverse_sample_rate = msg.sample_rate(); |
| 597 if (msg.has_reverse_sample_rate()) { | 598 if (msg.has_reverse_sample_rate()) { |
| 598 reverse_sample_rate = msg.reverse_sample_rate(); | 599 reverse_sample_rate = msg.reverse_sample_rate(); |
| 599 } | 600 } |
| 600 output_sample_rate = msg.sample_rate(); | 601 output_sample_rate = msg.sample_rate(); |
| 601 if (msg.has_output_sample_rate()) { | 602 if (msg.has_output_sample_rate()) { |
| 602 output_sample_rate = msg.output_sample_rate(); | 603 output_sample_rate = msg.output_sample_rate(); |
| 603 } | 604 } |
| 604 output_layout = LayoutFromChannels(msg.num_output_channels()); | 605 output_layout = |
| 605 ASSERT_EQ(kNoErr, apm->Initialize( | 606 LayoutFromChannels(static_cast<size_t>(msg.num_output_channels())); |
| 606 msg.sample_rate(), | 607 ASSERT_EQ(kNoErr, |
| 607 output_sample_rate, | 608 apm->Initialize( |
| 608 reverse_sample_rate, | 609 msg.sample_rate(), |
| 609 LayoutFromChannels(msg.num_input_channels()), | 610 output_sample_rate, |
| 610 output_layout, | 611 reverse_sample_rate, |
| 611 LayoutFromChannels(msg.num_reverse_channels()))); | 612 LayoutFromChannels( |
| 613 static_cast<size_t>(msg.num_input_channels())), |
| 614 output_layout, |
| 615 LayoutFromChannels( |
| 616 static_cast<size_t>(msg.num_reverse_channels())))); |
| 612 | 617 |
| 613 samples_per_channel = msg.sample_rate() / 100; | 618 samples_per_channel = msg.sample_rate() / 100; |
| 614 far_frame.sample_rate_hz_ = reverse_sample_rate; | 619 far_frame.sample_rate_hz_ = reverse_sample_rate; |
| 615 far_frame.samples_per_channel_ = reverse_sample_rate / 100; | 620 far_frame.samples_per_channel_ = reverse_sample_rate / 100; |
| 616 far_frame.num_channels_ = msg.num_reverse_channels(); | 621 far_frame.num_channels_ = msg.num_reverse_channels(); |
| 617 near_frame.sample_rate_hz_ = msg.sample_rate(); | 622 near_frame.sample_rate_hz_ = msg.sample_rate(); |
| 618 near_frame.samples_per_channel_ = samples_per_channel; | 623 near_frame.samples_per_channel_ = samples_per_channel; |
| 619 near_frame.num_channels_ = msg.num_input_channels(); | 624 near_frame.num_channels_ = msg.num_input_channels(); |
| 620 reverse_cb.reset(new ChannelBuffer<float>( | 625 reverse_cb.reset(new ChannelBuffer<float>( |
| 621 far_frame.samples_per_channel_, | 626 far_frame.samples_per_channel_, |
| 622 msg.num_reverse_channels())); | 627 msg.num_reverse_channels())); |
| 623 primary_cb.reset(new ChannelBuffer<float>(samples_per_channel, | 628 primary_cb.reset(new ChannelBuffer<float>(samples_per_channel, |
| 624 msg.num_input_channels())); | 629 msg.num_input_channels())); |
| 625 | 630 |
| 626 if (verbose) { | 631 if (verbose) { |
| 627 printf("Init at frame: %d (primary), %d (reverse)\n", | 632 printf("Init at frame: %d (primary), %d (reverse)\n", |
| 628 primary_count, reverse_count); | 633 primary_count, reverse_count); |
| 629 printf(" Primary rates: %d Hz (in), %d Hz (out)\n", | 634 printf(" Primary rates: %d Hz (in), %d Hz (out)\n", |
| 630 msg.sample_rate(), output_sample_rate); | 635 msg.sample_rate(), output_sample_rate); |
| 631 printf(" Primary channels: %d (in), %d (out)\n", | 636 printf(" Primary channels: %d (in), %d (out)\n", |
| 632 msg.num_input_channels(), | 637 msg.num_input_channels(), |
| 633 msg.num_output_channels()); | 638 msg.num_output_channels()); |
| 634 printf(" Reverse rate: %d\n", reverse_sample_rate); | 639 printf(" Reverse rate: %d\n", reverse_sample_rate); |
| 635 printf(" Reverse channels: %d\n", msg.num_reverse_channels()); | 640 printf(" Reverse channels: %d\n", msg.num_reverse_channels()); |
| 636 } | 641 } |
| 637 | 642 |
| 638 if (!raw_output) { | 643 if (!raw_output) { |
| 639 // The WAV file needs to be reset every time, because it can't change | 644 // The WAV file needs to be reset every time, because it can't change |
| 640 // its sample rate or number of channels. | 645 // its sample rate or number of channels. |
| 641 output_wav_file.reset(new WavWriter(out_filename + ".wav", | 646 output_wav_file.reset(new WavWriter( |
| 642 output_sample_rate, | 647 out_filename + ".wav", output_sample_rate, |
| 643 msg.num_output_channels())); | 648 static_cast<size_t>(msg.num_output_channels()))); |
| 644 } | 649 } |
| 645 | 650 |
| 646 } else if (event_msg.type() == Event::REVERSE_STREAM) { | 651 } else if (event_msg.type() == Event::REVERSE_STREAM) { |
| 647 ASSERT_TRUE(event_msg.has_reverse_stream()); | 652 ASSERT_TRUE(event_msg.has_reverse_stream()); |
| 648 ReverseStream msg = event_msg.reverse_stream(); | 653 ReverseStream msg = event_msg.reverse_stream(); |
| 649 reverse_count++; | 654 reverse_count++; |
| 650 | 655 |
| 651 ASSERT_TRUE(msg.has_data() ^ (msg.channel_size() > 0)); | 656 ASSERT_TRUE(msg.has_data() ^ (msg.channel_size() > 0)); |
| 652 if (msg.has_data()) { | 657 if (msg.has_data()) { |
| 653 ASSERT_EQ(sizeof(int16_t) * far_frame.samples_per_channel_ * | 658 ASSERT_EQ(sizeof(int16_t) * far_frame.samples_per_channel_ * |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 } // namespace | 1146 } // namespace |
| 1142 } // namespace webrtc | 1147 } // namespace webrtc |
| 1143 | 1148 |
| 1144 int main(int argc, char* argv[]) { | 1149 int main(int argc, char* argv[]) { |
| 1145 webrtc::void_main(argc, argv); | 1150 webrtc::void_main(argc, argv); |
| 1146 | 1151 |
| 1147 // Optional, but removes memory leak noise from Valgrind. | 1152 // Optional, but removes memory leak noise from Valgrind. |
| 1148 google::protobuf::ShutdownProtobufLibrary(); | 1153 google::protobuf::ShutdownProtobufLibrary(); |
| 1149 return 0; | 1154 return 0; |
| 1150 } | 1155 } |
| OLD | NEW |