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 "webrtc/base/arraysize.h" | 19 #include "webrtc/base/arraysize.h" |
20 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
| 21 #include "webrtc/base/gtest_prod_util.h" |
21 #include "webrtc/base/ignore_wundef.h" | 22 #include "webrtc/base/ignore_wundef.h" |
22 #include "webrtc/common_audio/include/audio_util.h" | 23 #include "webrtc/common_audio/include/audio_util.h" |
23 #include "webrtc/common_audio/resampler/include/push_resampler.h" | 24 #include "webrtc/common_audio/resampler/include/push_resampler.h" |
24 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" | 25 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" |
25 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 26 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
| 27 #include "webrtc/modules/audio_processing/audio_processing_impl.h" |
26 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h
" | 28 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h
" |
27 #include "webrtc/modules/audio_processing/common.h" | 29 #include "webrtc/modules/audio_processing/common.h" |
28 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 30 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 31 #include "webrtc/modules/audio_processing/level_controller/level_controller_cons
tants.h" |
29 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" | 32 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" |
30 #include "webrtc/modules/audio_processing/test/test_utils.h" | 33 #include "webrtc/modules/audio_processing/test/test_utils.h" |
31 #include "webrtc/modules/include/module_common_types.h" | 34 #include "webrtc/modules/include/module_common_types.h" |
32 #include "webrtc/system_wrappers/include/event_wrapper.h" | 35 #include "webrtc/system_wrappers/include/event_wrapper.h" |
33 #include "webrtc/system_wrappers/include/trace.h" | 36 #include "webrtc/system_wrappers/include/trace.h" |
34 #include "webrtc/test/gtest.h" | 37 #include "webrtc/test/gtest.h" |
35 #include "webrtc/test/testsupport/fileutils.h" | 38 #include "webrtc/test/testsupport/fileutils.h" |
36 | 39 |
37 RTC_PUSH_IGNORING_WUNDEF() | 40 RTC_PUSH_IGNORING_WUNDEF() |
38 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 41 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
(...skipping 2736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2775 std::tr1::make_tuple(16000, 44100, 16000, 44100, 15, 15), | 2778 std::tr1::make_tuple(16000, 44100, 16000, 44100, 15, 15), |
2776 std::tr1::make_tuple(16000, 32000, 48000, 32000, 25, 35), | 2779 std::tr1::make_tuple(16000, 32000, 48000, 32000, 25, 35), |
2777 std::tr1::make_tuple(16000, 32000, 32000, 32000, 25, 0), | 2780 std::tr1::make_tuple(16000, 32000, 32000, 32000, 25, 0), |
2778 std::tr1::make_tuple(16000, 32000, 16000, 32000, 25, 20), | 2781 std::tr1::make_tuple(16000, 32000, 16000, 32000, 25, 20), |
2779 std::tr1::make_tuple(16000, 16000, 48000, 16000, 35, 20), | 2782 std::tr1::make_tuple(16000, 16000, 48000, 16000, 35, 20), |
2780 std::tr1::make_tuple(16000, 16000, 32000, 16000, 35, 20), | 2783 std::tr1::make_tuple(16000, 16000, 32000, 16000, 35, 20), |
2781 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0))); | 2784 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0))); |
2782 #endif | 2785 #endif |
2783 | 2786 |
2784 } // namespace | 2787 } // namespace |
| 2788 |
| 2789 TEST(ApmConfiguration, DefaultBehavior) { |
| 2790 // Verify that the level controller is default off, it can be activated using |
| 2791 // the config, and that the default initial level is maintained after the |
| 2792 // config has been applied. |
| 2793 std::unique_ptr<AudioProcessingImpl> apm( |
| 2794 new AudioProcessingImpl(webrtc::Config())); |
| 2795 AudioProcessing::Config config; |
| 2796 EXPECT_FALSE(apm->config_.level_controller.enabled); |
| 2797 // TODO(peah): Add test for the existence of the level controller object once |
| 2798 // that is created only when that is specified in the config. |
| 2799 // TODO(peah): Remove the testing for |
| 2800 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ |
| 2801 // is instead used to activate the level controller. |
| 2802 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); |
| 2803 EXPECT_NEAR(kTargetLcPeakLeveldBFS, |
| 2804 apm->config_.level_controller.initial_peak_level_dbfs, |
| 2805 std::numeric_limits<float>::epsilon()); |
| 2806 config.level_controller.enabled = true; |
| 2807 apm->ApplyConfig(config); |
| 2808 EXPECT_TRUE(apm->config_.level_controller.enabled); |
| 2809 // TODO(peah): Add test for the existence of the level controller object once |
| 2810 // that is created only when the that is specified in the config. |
| 2811 // TODO(peah): Remove the testing for |
| 2812 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ |
| 2813 // is instead used to activate the level controller. |
| 2814 EXPECT_TRUE(apm->capture_nonlocked_.level_controller_enabled); |
| 2815 EXPECT_NEAR(kTargetLcPeakLeveldBFS, |
| 2816 apm->config_.level_controller.initial_peak_level_dbfs, |
| 2817 std::numeric_limits<float>::epsilon()); |
| 2818 } |
| 2819 |
| 2820 TEST(ApmConfiguration, ValidConfigBehavior) { |
| 2821 // Verify that the initial level can be specified and is retained after the |
| 2822 // config has been applied. |
| 2823 std::unique_ptr<AudioProcessingImpl> apm( |
| 2824 new AudioProcessingImpl(webrtc::Config())); |
| 2825 AudioProcessing::Config config; |
| 2826 config.level_controller.initial_peak_level_dbfs = -50.f; |
| 2827 apm->ApplyConfig(config); |
| 2828 EXPECT_FALSE(apm->config_.level_controller.enabled); |
| 2829 // TODO(peah): Add test for the existence of the level controller object once |
| 2830 // that is created only when the that is specified in the config. |
| 2831 // TODO(peah): Remove the testing for |
| 2832 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ |
| 2833 // is instead used to activate the level controller. |
| 2834 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); |
| 2835 EXPECT_NEAR(-50.f, apm->config_.level_controller.initial_peak_level_dbfs, |
| 2836 std::numeric_limits<float>::epsilon()); |
| 2837 } |
| 2838 |
| 2839 TEST(ApmConfiguration, InValidConfigBehavior) { |
| 2840 // Verify that the config is properly reset when nonproper values are applied |
| 2841 // for the initial level. |
| 2842 |
| 2843 // Verify that the config is properly reset when the specified initial peak |
| 2844 // level is too low. |
| 2845 std::unique_ptr<AudioProcessingImpl> apm( |
| 2846 new AudioProcessingImpl(webrtc::Config())); |
| 2847 AudioProcessing::Config config; |
| 2848 config.level_controller.enabled = true; |
| 2849 config.level_controller.initial_peak_level_dbfs = -101.f; |
| 2850 apm->ApplyConfig(config); |
| 2851 EXPECT_FALSE(apm->config_.level_controller.enabled); |
| 2852 // TODO(peah): Add test for the existence of the level controller object once |
| 2853 // that is created only when the that is specified in the config. |
| 2854 // TODO(peah): Remove the testing for |
| 2855 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ |
| 2856 // is instead used to activate the level controller. |
| 2857 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); |
| 2858 EXPECT_NEAR(kTargetLcPeakLeveldBFS, |
| 2859 apm->config_.level_controller.initial_peak_level_dbfs, |
| 2860 std::numeric_limits<float>::epsilon()); |
| 2861 |
| 2862 // Verify that the config is properly reset when the specified initial peak |
| 2863 // level is too high. |
| 2864 apm.reset(new AudioProcessingImpl(webrtc::Config())); |
| 2865 config = AudioProcessing::Config(); |
| 2866 config.level_controller.enabled = true; |
| 2867 config.level_controller.initial_peak_level_dbfs = 1.f; |
| 2868 apm->ApplyConfig(config); |
| 2869 EXPECT_FALSE(apm->config_.level_controller.enabled); |
| 2870 // TODO(peah): Add test for the existence of the level controller object once |
| 2871 // that is created only when that is specified in the config. |
| 2872 // TODO(peah): Remove the testing for |
| 2873 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ |
| 2874 // is instead used to activate the level controller. |
| 2875 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); |
| 2876 EXPECT_NEAR(kTargetLcPeakLeveldBFS, |
| 2877 apm->config_.level_controller.initial_peak_level_dbfs, |
| 2878 std::numeric_limits<float>::epsilon()); |
| 2879 } |
| 2880 |
2785 } // namespace webrtc | 2881 } // namespace webrtc |
OLD | NEW |