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/level_controller_cons tants.h" | |
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; | |
the sun
2016/10/06 07:21:14
Can we use std::numeric_limits<float>::epsilon() i
peah-webrtc
2016/10/07 21:03:58
Done.
| |
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); | |
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.level_controller.initial_peak_level_dbfs = -50.f; | |
2819 apm->ApplyConfig(config); | |
2820 EXPECT_FALSE(apm->config_.level_controller.enabled); | |
2821 // TODO(peah): Add test for the existence of the level controller object once | |
2822 // that is created only when the that is specified in the config. | |
2823 // TODO(peah): Remove the testing for | |
2824 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ | |
2825 // is instead used to activate the level controller. | |
2826 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); | |
2827 EXPECT_NEAR(-50.f, apm->config_.level_controller.initial_peak_level_dbfs, | |
2828 kTolerance); | |
2829 } | |
2830 | |
2831 TEST(ApmConfiguration, InValidConfigBehavior) { | |
2832 // Verify that the config is properly reset when nonproper values are applied | |
2833 // for the initial level. | |
2834 const float kTolerance = 0.0001f; | |
2835 | |
2836 // Verify that the config is properly reset when the specified initial peak | |
2837 // level is too low. | |
2838 std::unique_ptr<AudioProcessingImpl> apm( | |
2839 new AudioProcessingImpl(webrtc::Config())); | |
2840 AudioProcessing::Config config; | |
2841 config.level_controller.enabled = true; | |
2842 config.level_controller.initial_peak_level_dbfs = -101.f; | |
2843 apm->ApplyConfig(config); | |
2844 EXPECT_FALSE(apm->config_.level_controller.enabled); | |
2845 // TODO(peah): Add test for the existence of the level controller object once | |
2846 // that is created only when the that is specified in the config. | |
2847 // TODO(peah): Remove the testing for | |
2848 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ | |
2849 // is instead used to activate the level controller. | |
2850 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); | |
2851 EXPECT_NEAR(kTargetLcPeakLeveldBFS, | |
2852 apm->config_.level_controller.initial_peak_level_dbfs, | |
2853 kTolerance); | |
2854 | |
2855 // Verify that the config is properly reset when the specified initial peak | |
2856 // level is too high. | |
2857 apm.reset(new AudioProcessingImpl(webrtc::Config())); | |
2858 config = AudioProcessing::Config(); | |
2859 config.level_controller.enabled = true; | |
2860 config.level_controller.initial_peak_level_dbfs = 1.f; | |
2861 apm->ApplyConfig(config); | |
2862 EXPECT_FALSE(apm->config_.level_controller.enabled); | |
2863 // TODO(peah): Add test for the existence of the level controller object once | |
2864 // that is created only when that is specified in the config. | |
2865 // TODO(peah): Remove the testing for | |
2866 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ | |
2867 // is instead used to activate the level controller. | |
2868 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); | |
2869 EXPECT_NEAR(kTargetLcPeakLeveldBFS, | |
2870 apm->config_.level_controller.initial_peak_level_dbfs, | |
2871 kTolerance); | |
2872 } | |
2873 | |
2777 } // namespace webrtc | 2874 } // namespace webrtc |
OLD | NEW |