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

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

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

Powered by Google App Engine
This is Rietveld 408576698