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

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

Issue 2337083002: Reland of added functionality for specifying the initial signal level to use for the gain estimation (Closed)
Patch Set: Changes in response to reviewer comments Created 4 years, 2 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
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
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);
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();
hlundin-webrtc 2016/10/05 12:29:18 Isn't config already default constructed as a resu
peah-webrtc 2016/10/06 06:27:27 True! Done.
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
2837 // Verify that the config is properly reset when the specified initial peak
2838 // level is too low.
2839 std::unique_ptr<AudioProcessingImpl> apm(
2840 new AudioProcessingImpl(webrtc::Config()));
2841 AudioProcessing::Config config;
2842 config = AudioProcessing::Config();
hlundin-webrtc 2016/10/05 12:29:18 Same here.
peah-webrtc 2016/10/06 06:27:27 True! Done.
2843 config.level_controller.enabled = true;
2844 config.level_controller.initial_peak_level_dbfs = -101.f;
2845 apm->ApplyConfig(config);
2846 EXPECT_FALSE(apm->config_.level_controller.enabled);
2847 // TODO(peah): Add test for the existence of the level controller object once
2848 // that is created only when the that is specified in the config.
2849 // TODO(peah): Remove the testing for
2850 // apm->capture_nonlocked_.level_controller_enabled once the value in config_
2851 // is instead used to activate the level controller.
2852 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled);
2853 EXPECT_NEAR(kTargetLcPeakLeveldBFS,
2854 apm->config_.level_controller.initial_peak_level_dbfs,
2855 kTolerance);
2856
2857 // Verify that the config is properly reset when the specified initial peak
2858 // level is too high.
2859 apm.reset(new AudioProcessingImpl(webrtc::Config()));
2860 config = AudioProcessing::Config();
2861 config.level_controller.enabled = true;
2862 config.level_controller.initial_peak_level_dbfs = 1.f;
2863 apm->ApplyConfig(config);
2864 EXPECT_FALSE(apm->config_.level_controller.enabled);
2865 // TODO(peah): Add test for the existence of the level controller object once
2866 // that is created only when that is specified in the config.
2867 // TODO(peah): Remove the testing for
2868 // apm->capture_nonlocked_.level_controller_enabled once the value in config_
2869 // is instead used to activate the level controller.
2870 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled);
2871 EXPECT_NEAR(kTargetLcPeakLeveldBFS,
2872 apm->config_.level_controller.initial_peak_level_dbfs,
2873 kTolerance);
2874 }
2875
2777 } // namespace webrtc 2876 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/audio_processing_impl.cc ('k') | webrtc/modules/audio_processing/include/audio_processing.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698