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

Side by Side Diff: webrtc/modules/audio_processing/test/audio_processing_unittest.cc

Issue 1226093007: Allow more than 2 input channels in AudioProcessing. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix docs Created 5 years, 5 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
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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 void Init(AudioProcessing* ap); 347 void Init(AudioProcessing* ap);
348 void EnableAllComponents(); 348 void EnableAllComponents();
349 bool ReadFrame(FILE* file, AudioFrame* frame); 349 bool ReadFrame(FILE* file, AudioFrame* frame);
350 bool ReadFrame(FILE* file, AudioFrame* frame, ChannelBuffer<float>* cb); 350 bool ReadFrame(FILE* file, AudioFrame* frame, ChannelBuffer<float>* cb);
351 void ReadFrameWithRewind(FILE* file, AudioFrame* frame); 351 void ReadFrameWithRewind(FILE* file, AudioFrame* frame);
352 void ReadFrameWithRewind(FILE* file, AudioFrame* frame, 352 void ReadFrameWithRewind(FILE* file, AudioFrame* frame,
353 ChannelBuffer<float>* cb); 353 ChannelBuffer<float>* cb);
354 void ProcessWithDefaultStreamParameters(AudioFrame* frame); 354 void ProcessWithDefaultStreamParameters(AudioFrame* frame);
355 void ProcessDelayVerificationTest(int delay_ms, int system_delay_ms, 355 void ProcessDelayVerificationTest(int delay_ms, int system_delay_ms,
356 int delay_min, int delay_max); 356 int delay_min, int delay_max);
357 void TestChangingChannels(int num_channels, 357 void TestChangingChannelsInt16Interface(
358 AudioProcessing::Error expected_return); 358 int num_channels,
359 AudioProcessing::Error expected_return);
360 void TestChangingForwardChannels(int num_in_channels,
361 int num_out_channels,
362 AudioProcessing::Error expected_return);
363 void TestChangingReverseChannels(int num_rev_channels,
364 AudioProcessing::Error expected_return);
359 void RunQuantizedVolumeDoesNotGetStuckTest(int sample_rate); 365 void RunQuantizedVolumeDoesNotGetStuckTest(int sample_rate);
360 void RunManualVolumeChangeIsPossibleTest(int sample_rate); 366 void RunManualVolumeChangeIsPossibleTest(int sample_rate);
361 void StreamParametersTest(Format format); 367 void StreamParametersTest(Format format);
362 int ProcessStreamChooser(Format format); 368 int ProcessStreamChooser(Format format);
363 int AnalyzeReverseStreamChooser(Format format); 369 int AnalyzeReverseStreamChooser(Format format);
364 void ProcessDebugDump(const std::string& in_filename, 370 void ProcessDebugDump(const std::string& in_filename,
365 const std::string& out_filename, 371 const std::string& out_filename,
366 Format format); 372 Format format);
367 void VerifyDebugDumpTest(Format format); 373 void VerifyDebugDumpTest(Format format);
368 374
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 near_file_ = NULL; 448 near_file_ = NULL;
443 449
444 if (out_file_) { 450 if (out_file_) {
445 ASSERT_EQ(0, fclose(out_file_)); 451 ASSERT_EQ(0, fclose(out_file_));
446 } 452 }
447 out_file_ = NULL; 453 out_file_ = NULL;
448 } 454 }
449 455
450 void ApmTest::Init(AudioProcessing* ap) { 456 void ApmTest::Init(AudioProcessing* ap) {
451 ASSERT_EQ(kNoErr, 457 ASSERT_EQ(kNoErr,
452 ap->Initialize(frame_->sample_rate_hz_, 458 ap->Initialize(
453 output_sample_rate_hz_, 459 {{{frame_->sample_rate_hz_, frame_->num_channels_},
454 revframe_->sample_rate_hz_, 460 {output_sample_rate_hz_, num_output_channels_},
455 LayoutFromChannels(frame_->num_channels_), 461 {revframe_->sample_rate_hz_, revframe_->num_channels_}}}));
456 LayoutFromChannels(num_output_channels_),
457 LayoutFromChannels(revframe_->num_channels_)));
458 } 462 }
459 463
460 void ApmTest::Init(int sample_rate_hz, 464 void ApmTest::Init(int sample_rate_hz,
461 int output_sample_rate_hz, 465 int output_sample_rate_hz,
462 int reverse_sample_rate_hz, 466 int reverse_sample_rate_hz,
463 int num_input_channels, 467 int num_input_channels,
464 int num_output_channels, 468 int num_output_channels,
465 int num_reverse_channels, 469 int num_reverse_channels,
466 bool open_output_file) { 470 bool open_output_file) {
467 SetContainerFormat(sample_rate_hz, num_input_channels, frame_, &float_cb_); 471 SetContainerFormat(sample_rate_hz, num_input_channels, frame_, &float_cb_);
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 788
785 // Low limit of 0 ms. 789 // Low limit of 0 ms.
786 apm_->set_delay_offset_ms(-50); 790 apm_->set_delay_offset_ms(-50);
787 EXPECT_EQ(-50, apm_->delay_offset_ms()); 791 EXPECT_EQ(-50, apm_->delay_offset_ms());
788 EXPECT_EQ(apm_->kBadStreamParameterWarning, apm_->set_stream_delay_ms(20)); 792 EXPECT_EQ(apm_->kBadStreamParameterWarning, apm_->set_stream_delay_ms(20));
789 EXPECT_EQ(0, apm_->stream_delay_ms()); 793 EXPECT_EQ(0, apm_->stream_delay_ms());
790 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(100)); 794 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(100));
791 EXPECT_EQ(50, apm_->stream_delay_ms()); 795 EXPECT_EQ(50, apm_->stream_delay_ms());
792 } 796 }
793 797
794 void ApmTest::TestChangingChannels(int num_channels, 798 void ApmTest::TestChangingChannelsInt16Interface(
795 AudioProcessing::Error expected_return) { 799 int num_channels,
800 AudioProcessing::Error expected_return) {
796 frame_->num_channels_ = num_channels; 801 frame_->num_channels_ = num_channels;
797 EXPECT_EQ(expected_return, apm_->ProcessStream(frame_)); 802 EXPECT_EQ(expected_return, apm_->ProcessStream(frame_));
798 EXPECT_EQ(expected_return, apm_->AnalyzeReverseStream(frame_)); 803 EXPECT_EQ(expected_return, apm_->AnalyzeReverseStream(frame_));
799 } 804 }
800 805
801 TEST_F(ApmTest, Channels) { 806 void ApmTest::TestChangingForwardChannels(
802 // Testing number of invalid channels. 807 int num_in_channels,
803 TestChangingChannels(0, apm_->kBadNumberChannelsError); 808 int num_out_channels,
804 TestChangingChannels(3, apm_->kBadNumberChannelsError); 809 AudioProcessing::Error expected_return) {
805 // Testing number of valid channels. 810 const StreamConfig input_stream = {frame_->sample_rate_hz_, num_in_channels};
806 for (int i = 1; i < 3; i++) { 811 const StreamConfig output_stream = {output_sample_rate_hz_, num_out_channels};
807 TestChangingChannels(i, kNoErr); 812
813 EXPECT_EQ(expected_return,
814 apm_->ProcessStream(float_cb_->channels(), input_stream,
815 output_stream, float_cb_->channels()));
816 }
817
818 void ApmTest::TestChangingReverseChannels(
819 int num_rev_channels,
820 AudioProcessing::Error expected_return) {
821 const ProcessingConfig processing_config = {
822 {{ frame_->sample_rate_hz_, apm_->num_input_channels() },
823 { output_sample_rate_hz_, apm_->num_output_channels() },
824 { frame_->sample_rate_hz_, num_rev_channels }}};
825
826 EXPECT_EQ(expected_return,
827 apm_->AnalyzeReverseStream(float_cb_->channels(),
828 processing_config.reverse_stream()));
829 }
830
831 TEST_F(ApmTest, ChannelsInt16Interface) {
832 // Testing number of invalid and valid channels.
833 Init(16000, 16000, 16000, 4, 4, 4, false);
834
835 TestChangingChannelsInt16Interface(0, apm_->kBadNumberChannelsError);
836
837 for (int i = 1; i < 4; i++) {
838 TestChangingChannelsInt16Interface(i, kNoErr);
808 EXPECT_EQ(i, apm_->num_input_channels()); 839 EXPECT_EQ(i, apm_->num_input_channels());
809 // We always force the number of reverse channels used for processing to 1. 840 // We always force the number of reverse channels used for processing to 1.
810 EXPECT_EQ(1, apm_->num_reverse_channels()); 841 EXPECT_EQ(1, apm_->num_reverse_channels());
811 } 842 }
812 } 843 }
813 844
845 TEST_F(ApmTest, Channels) {
846 // Testing number of invalid and valid channels.
847 Init(16000, 16000, 16000, 4, 4, 4, false);
848
849 TestChangingForwardChannels(0, 1, apm_->kBadNumberChannelsError);
850 TestChangingReverseChannels(0, apm_->kBadNumberChannelsError);
851
852 for (int i = 1; i < 4; ++i) {
853 for (int j = 0; j < 1; ++j) {
854 // Output channels much be one or match input channels.
855 if (j == 1 || i == j) {
856 TestChangingForwardChannels(i, j, kNoErr);
857 TestChangingReverseChannels(i, kNoErr);
858
859 EXPECT_EQ(i, apm_->num_input_channels());
860 EXPECT_EQ(j, apm_->num_output_channels());
861 // The number of reverse channels used for processing to is always 1.
862 EXPECT_EQ(1, apm_->num_reverse_channels());
863 } else {
864 TestChangingForwardChannels(i, j,
865 AudioProcessing::kBadNumberChannelsError);
866 }
867 }
868 }
869 }
870
814 TEST_F(ApmTest, SampleRatesInt) { 871 TEST_F(ApmTest, SampleRatesInt) {
815 // Testing invalid sample rates 872 // Testing invalid sample rates
816 SetContainerFormat(10000, 2, frame_, &float_cb_); 873 SetContainerFormat(10000, 2, frame_, &float_cb_);
817 EXPECT_EQ(apm_->kBadSampleRateError, ProcessStreamChooser(kIntFormat)); 874 EXPECT_EQ(apm_->kBadSampleRateError, ProcessStreamChooser(kIntFormat));
818 // Testing valid sample rates 875 // Testing valid sample rates
819 int fs[] = {8000, 16000, 32000, 48000}; 876 int fs[] = {8000, 16000, 32000, 48000};
820 for (size_t i = 0; i < sizeof(fs) / sizeof(*fs); i++) { 877 for (size_t i = 0; i < sizeof(fs) / sizeof(*fs); i++) {
821 SetContainerFormat(fs[i], 2, frame_, &float_cb_); 878 SetContainerFormat(fs[i], 2, frame_, &float_cb_);
822 EXPECT_NOERR(ProcessStreamChooser(kIntFormat)); 879 EXPECT_NOERR(ProcessStreamChooser(kIntFormat));
823 EXPECT_EQ(fs[i], apm_->input_sample_rate_hz()); 880 EXPECT_EQ(fs[i], apm_->input_sample_rate_hz());
(...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after
2287 int output_rate, 2344 int output_rate,
2288 int reverse_rate, 2345 int reverse_rate,
2289 int num_input_channels, 2346 int num_input_channels,
2290 int num_output_channels, 2347 int num_output_channels,
2291 int num_reverse_channels, 2348 int num_reverse_channels,
2292 std::string output_file_prefix) { 2349 std::string output_file_prefix) {
2293 Config config; 2350 Config config;
2294 config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); 2351 config.Set<ExperimentalAgc>(new ExperimentalAgc(false));
2295 rtc::scoped_ptr<AudioProcessing> ap(AudioProcessing::Create(config)); 2352 rtc::scoped_ptr<AudioProcessing> ap(AudioProcessing::Create(config));
2296 EnableAllAPComponents(ap.get()); 2353 EnableAllAPComponents(ap.get());
2297 ap->Initialize(input_rate, 2354 ap->Initialize({{{input_rate, num_input_channels},
2298 output_rate, 2355 {output_rate, num_output_channels},
2299 reverse_rate, 2356 {reverse_rate, num_reverse_channels}}});
2300 LayoutFromChannels(num_input_channels),
2301 LayoutFromChannels(num_output_channels),
2302 LayoutFromChannels(num_reverse_channels));
2303 2357
2304 FILE* far_file = fopen(ResourceFilePath("far", reverse_rate).c_str(), "rb"); 2358 FILE* far_file = fopen(ResourceFilePath("far", reverse_rate).c_str(), "rb");
2305 FILE* near_file = fopen(ResourceFilePath("near", input_rate).c_str(), "rb"); 2359 FILE* near_file = fopen(ResourceFilePath("near", input_rate).c_str(), "rb");
2306 FILE* out_file = fopen(OutputFilePath(output_file_prefix, 2360 FILE* out_file = fopen(OutputFilePath(output_file_prefix,
2307 input_rate, 2361 input_rate,
2308 output_rate, 2362 output_rate,
2309 reverse_rate, 2363 reverse_rate,
2310 num_input_channels, 2364 num_input_channels,
2311 num_output_channels, 2365 num_output_channels,
2312 num_reverse_channels).c_str(), "wb"); 2366 num_reverse_channels).c_str(), "wb");
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
2620 std::tr1::make_tuple(16000, 16000, 32000, 40), 2674 std::tr1::make_tuple(16000, 16000, 32000, 40),
2621 std::tr1::make_tuple(16000, 16000, 16000, 0))); 2675 std::tr1::make_tuple(16000, 16000, 16000, 0)));
2622 #endif 2676 #endif
2623 2677
2624 // TODO(henrike): re-implement functionality lost when removing the old main 2678 // TODO(henrike): re-implement functionality lost when removing the old main
2625 // function. See 2679 // function. See
2626 // https://code.google.com/p/webrtc/issues/detail?id=1981 2680 // https://code.google.com/p/webrtc/issues/detail?id=1981
2627 2681
2628 } // namespace 2682 } // namespace
2629 } // namespace webrtc 2683 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698