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 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <limits> | 15 #include <limits> |
16 #include <memory> | 16 #include <memory> |
17 #include <queue> | 17 #include <queue> |
18 | 18 |
19 #include "testing/gtest/include/gtest/gtest.h" | |
19 #include "webrtc/base/arraysize.h" | 20 #include "webrtc/base/arraysize.h" |
20 #include "webrtc/base/checks.h" | 21 #include "webrtc/base/checks.h" |
21 #include "webrtc/common_audio/include/audio_util.h" | 22 #include "webrtc/common_audio/include/audio_util.h" |
22 #include "webrtc/common_audio/resampler/include/push_resampler.h" | 23 #include "webrtc/common_audio/resampler/include/push_resampler.h" |
23 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" | 24 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" |
24 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" | 25 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" |
26 #include "webrtc/modules/audio_processing/audio_processing_impl.h" | |
25 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h " | 27 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h " |
26 #include "webrtc/modules/audio_processing/common.h" | 28 #include "webrtc/modules/audio_processing/common.h" |
27 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 29 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
30 #include "webrtc/modules/audio_processing/level_controller/lc_constants.h" | |
the sun
2016/09/30 08:51:16
please don't abbreviate file names
peah-webrtc
2016/10/03 09:52:13
Done.
| |
28 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" | 31 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" |
29 #include "webrtc/modules/audio_processing/test/test_utils.h" | 32 #include "webrtc/modules/audio_processing/test/test_utils.h" |
30 #include "webrtc/modules/include/module_common_types.h" | 33 #include "webrtc/modules/include/module_common_types.h" |
31 #include "webrtc/system_wrappers/include/event_wrapper.h" | 34 #include "webrtc/system_wrappers/include/event_wrapper.h" |
32 #include "webrtc/system_wrappers/include/trace.h" | 35 #include "webrtc/system_wrappers/include/trace.h" |
33 #include "webrtc/test/testsupport/fileutils.h" | 36 #include "webrtc/test/testsupport/fileutils.h" |
34 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 37 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
35 #include "gtest/gtest.h" | |
36 #include "external/webrtc/webrtc/modules/audio_processing/test/unittest.pb.h" | 38 #include "external/webrtc/webrtc/modules/audio_processing/test/unittest.pb.h" |
37 #else | 39 #else |
38 #include "testing/gtest/include/gtest/gtest.h" | |
39 #include "webrtc/modules/audio_processing/unittest.pb.h" | 40 #include "webrtc/modules/audio_processing/unittest.pb.h" |
40 #endif | 41 #endif |
41 | 42 |
42 namespace webrtc { | 43 namespace webrtc { |
43 namespace { | 44 namespace { |
44 | 45 |
45 // TODO(ekmeyerson): Switch to using StreamConfig and ProcessingConfig where | 46 // TODO(ekmeyerson): Switch to using StreamConfig and ProcessingConfig where |
46 // applicable. | 47 // applicable. |
47 | 48 |
48 // TODO(bjornv): This is not feasible until the functionality has been | 49 // TODO(bjornv): This is not feasible until the functionality has been |
(...skipping 2718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2767 std::tr1::make_tuple(16000, 44100, 16000, 44100, 15, 15), | 2768 std::tr1::make_tuple(16000, 44100, 16000, 44100, 15, 15), |
2768 std::tr1::make_tuple(16000, 32000, 48000, 32000, 25, 35), | 2769 std::tr1::make_tuple(16000, 32000, 48000, 32000, 25, 35), |
2769 std::tr1::make_tuple(16000, 32000, 32000, 32000, 25, 0), | 2770 std::tr1::make_tuple(16000, 32000, 32000, 32000, 25, 0), |
2770 std::tr1::make_tuple(16000, 32000, 16000, 32000, 25, 20), | 2771 std::tr1::make_tuple(16000, 32000, 16000, 32000, 25, 20), |
2771 std::tr1::make_tuple(16000, 16000, 48000, 16000, 35, 20), | 2772 std::tr1::make_tuple(16000, 16000, 48000, 16000, 35, 20), |
2772 std::tr1::make_tuple(16000, 16000, 32000, 16000, 35, 20), | 2773 std::tr1::make_tuple(16000, 16000, 32000, 16000, 35, 20), |
2773 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0))); | 2774 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0))); |
2774 #endif | 2775 #endif |
2775 | 2776 |
2776 } // namespace | 2777 } // namespace |
2778 | |
2779 TEST(ApmConfiguration, DefaultBehavior) { | |
2780 // Verify that the level controller is default off, it can be activated using | |
2781 // the config, and that the default initial level is maintained after the | |
2782 // config has been applied. | |
2783 const float kTolerance = 0.0001f; | |
2784 std::unique_ptr<AudioProcessingImpl> apm( | |
2785 new AudioProcessingImpl(webrtc::Config())); | |
2786 AudioProcessing::Config config; | |
2787 EXPECT_FALSE(apm->config_.level_controller.enabled); | |
2788 // TODO(peah): Add test for the existence of the level controller object once | |
2789 // that is created only when that is specified in the config. | |
2790 // TODO(peah): Remove the testing for | |
2791 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ | |
2792 // is instead used to activate the level controller. | |
2793 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); | |
2794 EXPECT_NEAR(kTargetLcPeakLeveldBFS, | |
2795 apm->config_.level_controller.initial_peak_level_dbfs, | |
2796 kTolerance); | |
2797 config.level_controller.enabled = true; | |
2798 apm->ApplyConfig(config); | |
2799 EXPECT_TRUE(apm->config_.level_controller.enabled); | |
the sun
2016/09/30 08:51:16
Aren't you testing this in ValidConfigBehavior? De
peah-webrtc
2016/10/03 09:52:13
No, if I understand your question correctly, I don
the sun
2016/10/06 07:21:13
Acknowledged.
| |
2800 // TODO(peah): Add test for the existence of the level controller object once | |
2801 // that is created only when the that is specified in the config. | |
2802 // TODO(peah): Remove the testing for | |
2803 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ | |
2804 // is instead used to activate the level controller. | |
2805 EXPECT_TRUE(apm->capture_nonlocked_.level_controller_enabled); | |
2806 EXPECT_NEAR(kTargetLcPeakLeveldBFS, | |
2807 apm->config_.level_controller.initial_peak_level_dbfs, | |
2808 kTolerance); | |
2809 } | |
2810 | |
2811 TEST(ApmConfiguration, ValidConfigBehavior) { | |
2812 // Verify that the initial level can be specified and is retained after the | |
2813 // config has been applied. | |
2814 const float kTolerance = 0.0001f; | |
2815 std::unique_ptr<AudioProcessingImpl> apm( | |
2816 new AudioProcessingImpl(webrtc::Config())); | |
2817 AudioProcessing::Config config; | |
2818 config = AudioProcessing::Config(); | |
2819 config.level_controller.initial_peak_level_dbfs = -50.f; | |
2820 apm->ApplyConfig(config); | |
2821 EXPECT_FALSE(apm->config_.level_controller.enabled); | |
2822 // TODO(peah): Add test for the existence of the level controller object once | |
2823 // that is created only when the that is specified in the config. | |
2824 // TODO(peah): Remove the testing for | |
2825 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ | |
2826 // is instead used to activate the level controller. | |
2827 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); | |
2828 EXPECT_NEAR(-50.f, apm->config_.level_controller.initial_peak_level_dbfs, | |
2829 kTolerance); | |
2830 } | |
2831 | |
2832 TEST(ApmConfiguration, InValidConfigBehavior) { | |
2833 // Verify that the config is properly reset when nonproper values are applied | |
2834 // for the initial level. | |
2835 const float kTolerance = 0.0001f; | |
2836 std::unique_ptr<AudioProcessingImpl> apm( | |
2837 new AudioProcessingImpl(webrtc::Config())); | |
2838 AudioProcessing::Config config; | |
2839 config = AudioProcessing::Config(); | |
2840 config.level_controller.enabled = true; | |
2841 config.level_controller.initial_peak_level_dbfs = -101.f; | |
2842 apm->ApplyConfig(config); | |
2843 EXPECT_FALSE(apm->config_.level_controller.enabled); | |
2844 // TODO(peah): Add test for the existence of the level controller object once | |
2845 // that is created only when the that is specified in the config. | |
2846 // TODO(peah): Remove the testing for | |
2847 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ | |
2848 // is instead used to activate the level controller. | |
2849 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); | |
2850 EXPECT_NEAR(kTargetLcPeakLeveldBFS, | |
2851 apm->config_.level_controller.initial_peak_level_dbfs, | |
2852 kTolerance); | |
2853 | |
2854 apm.reset(new AudioProcessingImpl(webrtc::Config())); | |
the sun
2016/09/30 08:51:16
So here's either a separate test case, or a commen
peah-webrtc
2016/10/03 09:52:13
I added comments about what is being done. Ideally
the sun
2016/10/06 07:21:13
Acknowledged.
| |
2855 config = AudioProcessing::Config(); | |
2856 config.level_controller.enabled = true; | |
2857 config.level_controller.initial_peak_level_dbfs = 1.f; | |
2858 apm->ApplyConfig(config); | |
2859 EXPECT_FALSE(apm->config_.level_controller.enabled); | |
2860 // TODO(peah): Add test for the existence of the level controller object once | |
2861 // that is created only when that is specified in the config. | |
2862 // TODO(peah): Remove the testing for | |
2863 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ | |
2864 // is instead used to activate the level controller. | |
2865 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); | |
2866 EXPECT_NEAR(kTargetLcPeakLeveldBFS, | |
2867 apm->config_.level_controller.initial_peak_level_dbfs, | |
2868 kTolerance); | |
2869 } | |
2870 | |
2777 } // namespace webrtc | 2871 } // namespace webrtc |
OLD | NEW |