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

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

Issue 2961723004: Allow an external audio processing module to be used in WebRTC (Closed)
Patch Set: Moved creation of APMs from CreateVoiceEngines Created 3 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
11 #include <math.h> 10 #include <math.h>
12 #include <stdio.h> 11 #include <stdio.h>
13 12
14 #include <algorithm> 13 #include <algorithm>
15 #include <limits> 14 #include <limits>
16 #include <memory> 15 #include <memory>
17 #include <queue> 16 #include <queue>
18 17
19 #include "webrtc/base/arraysize.h" 18 #include "webrtc/base/arraysize.h"
20 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
(...skipping 2777 matching lines...) Expand 10 before | Expand all | Expand 10 after
2798 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0))); 2797 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0)));
2799 #endif 2798 #endif
2800 2799
2801 } // namespace 2800 } // namespace
2802 2801
2803 TEST(ApmConfiguration, DefaultBehavior) { 2802 TEST(ApmConfiguration, DefaultBehavior) {
2804 // Verify that the level controller is default off, it can be activated using 2803 // Verify that the level controller is default off, it can be activated using
2805 // the config, and that the default initial level is maintained after the 2804 // the config, and that the default initial level is maintained after the
2806 // config has been applied. 2805 // config has been applied.
2807 std::unique_ptr<AudioProcessingImpl> apm( 2806 std::unique_ptr<AudioProcessingImpl> apm(
2808 new AudioProcessingImpl(webrtc::Config())); 2807 new rtc::RefCountedObject<AudioProcessingImpl>(webrtc::Config()));
2809 AudioProcessing::Config config; 2808 AudioProcessing::Config config;
2810 EXPECT_FALSE(apm->config_.level_controller.enabled); 2809 EXPECT_FALSE(apm->config_.level_controller.enabled);
2811 // TODO(peah): Add test for the existence of the level controller object once 2810 // TODO(peah): Add test for the existence of the level controller object once
2812 // that is created only when that is specified in the config. 2811 // that is created only when that is specified in the config.
2813 // TODO(peah): Remove the testing for 2812 // TODO(peah): Remove the testing for
2814 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ 2813 // apm->capture_nonlocked_.level_controller_enabled once the value in config_
2815 // is instead used to activate the level controller. 2814 // is instead used to activate the level controller.
2816 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); 2815 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled);
2817 EXPECT_NEAR(kTargetLcPeakLeveldBFS, 2816 EXPECT_NEAR(kTargetLcPeakLeveldBFS,
2818 apm->config_.level_controller.initial_peak_level_dbfs, 2817 apm->config_.level_controller.initial_peak_level_dbfs,
2819 std::numeric_limits<float>::epsilon()); 2818 std::numeric_limits<float>::epsilon());
2820 config.level_controller.enabled = true; 2819 config.level_controller.enabled = true;
2821 apm->ApplyConfig(config); 2820 apm->ApplyConfig(config);
2822 EXPECT_TRUE(apm->config_.level_controller.enabled); 2821 EXPECT_TRUE(apm->config_.level_controller.enabled);
2823 // TODO(peah): Add test for the existence of the level controller object once 2822 // TODO(peah): Add test for the existence of the level controller object once
2824 // that is created only when the that is specified in the config. 2823 // that is created only when the that is specified in the config.
2825 // TODO(peah): Remove the testing for 2824 // TODO(peah): Remove the testing for
2826 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ 2825 // apm->capture_nonlocked_.level_controller_enabled once the value in config_
2827 // is instead used to activate the level controller. 2826 // is instead used to activate the level controller.
2828 EXPECT_TRUE(apm->capture_nonlocked_.level_controller_enabled); 2827 EXPECT_TRUE(apm->capture_nonlocked_.level_controller_enabled);
2829 EXPECT_NEAR(kTargetLcPeakLeveldBFS, 2828 EXPECT_NEAR(kTargetLcPeakLeveldBFS,
2830 apm->config_.level_controller.initial_peak_level_dbfs, 2829 apm->config_.level_controller.initial_peak_level_dbfs,
2831 std::numeric_limits<float>::epsilon()); 2830 std::numeric_limits<float>::epsilon());
2832 } 2831 }
2833 2832
2834 TEST(ApmConfiguration, ValidConfigBehavior) { 2833 TEST(ApmConfiguration, ValidConfigBehavior) {
2835 // Verify that the initial level can be specified and is retained after the 2834 // Verify that the initial level can be specified and is retained after the
2836 // config has been applied. 2835 // config has been applied.
2837 std::unique_ptr<AudioProcessingImpl> apm( 2836 std::unique_ptr<AudioProcessingImpl> apm(
2838 new AudioProcessingImpl(webrtc::Config())); 2837 new rtc::RefCountedObject<AudioProcessingImpl>(webrtc::Config()));
2839 AudioProcessing::Config config; 2838 AudioProcessing::Config config;
2840 config.level_controller.initial_peak_level_dbfs = -50.f; 2839 config.level_controller.initial_peak_level_dbfs = -50.f;
2841 apm->ApplyConfig(config); 2840 apm->ApplyConfig(config);
2842 EXPECT_FALSE(apm->config_.level_controller.enabled); 2841 EXPECT_FALSE(apm->config_.level_controller.enabled);
2843 // TODO(peah): Add test for the existence of the level controller object once 2842 // TODO(peah): Add test for the existence of the level controller object once
2844 // that is created only when the that is specified in the config. 2843 // that is created only when the that is specified in the config.
2845 // TODO(peah): Remove the testing for 2844 // TODO(peah): Remove the testing for
2846 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ 2845 // apm->capture_nonlocked_.level_controller_enabled once the value in config_
2847 // is instead used to activate the level controller. 2846 // is instead used to activate the level controller.
2848 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); 2847 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled);
2849 EXPECT_NEAR(-50.f, apm->config_.level_controller.initial_peak_level_dbfs, 2848 EXPECT_NEAR(-50.f, apm->config_.level_controller.initial_peak_level_dbfs,
2850 std::numeric_limits<float>::epsilon()); 2849 std::numeric_limits<float>::epsilon());
2851 } 2850 }
2852 2851
2853 TEST(ApmConfiguration, InValidConfigBehavior) { 2852 TEST(ApmConfiguration, InValidConfigBehavior) {
2854 // Verify that the config is properly reset when nonproper values are applied 2853 // Verify that the config is properly reset when nonproper values are applied
2855 // for the initial level. 2854 // for the initial level.
2856 2855
2857 // Verify that the config is properly reset when the specified initial peak 2856 // Verify that the config is properly reset when the specified initial peak
2858 // level is too low. 2857 // level is too low.
2859 std::unique_ptr<AudioProcessingImpl> apm( 2858 std::unique_ptr<AudioProcessingImpl> apm(
2860 new AudioProcessingImpl(webrtc::Config())); 2859 new rtc::RefCountedObject<AudioProcessingImpl>(webrtc::Config()));
2861 AudioProcessing::Config config; 2860 AudioProcessing::Config config;
2862 config.level_controller.enabled = true; 2861 config.level_controller.enabled = true;
2863 config.level_controller.initial_peak_level_dbfs = -101.f; 2862 config.level_controller.initial_peak_level_dbfs = -101.f;
2864 apm->ApplyConfig(config); 2863 apm->ApplyConfig(config);
2865 EXPECT_FALSE(apm->config_.level_controller.enabled); 2864 EXPECT_FALSE(apm->config_.level_controller.enabled);
2866 // TODO(peah): Add test for the existence of the level controller object once 2865 // TODO(peah): Add test for the existence of the level controller object once
2867 // that is created only when the that is specified in the config. 2866 // that is created only when the that is specified in the config.
2868 // TODO(peah): Remove the testing for 2867 // TODO(peah): Remove the testing for
2869 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ 2868 // apm->capture_nonlocked_.level_controller_enabled once the value in config_
2870 // is instead used to activate the level controller. 2869 // is instead used to activate the level controller.
2871 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); 2870 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled);
2872 EXPECT_NEAR(kTargetLcPeakLeveldBFS, 2871 EXPECT_NEAR(kTargetLcPeakLeveldBFS,
2873 apm->config_.level_controller.initial_peak_level_dbfs, 2872 apm->config_.level_controller.initial_peak_level_dbfs,
2874 std::numeric_limits<float>::epsilon()); 2873 std::numeric_limits<float>::epsilon());
2875 2874
2876 // Verify that the config is properly reset when the specified initial peak 2875 // Verify that the config is properly reset when the specified initial peak
2877 // level is too high. 2876 // level is too high.
2878 apm.reset(new AudioProcessingImpl(webrtc::Config())); 2877 apm.reset(new rtc::RefCountedObject<AudioProcessingImpl>(webrtc::Config()));
2879 config = AudioProcessing::Config(); 2878 config = AudioProcessing::Config();
2880 config.level_controller.enabled = true; 2879 config.level_controller.enabled = true;
2881 config.level_controller.initial_peak_level_dbfs = 1.f; 2880 config.level_controller.initial_peak_level_dbfs = 1.f;
2882 apm->ApplyConfig(config); 2881 apm->ApplyConfig(config);
2883 EXPECT_FALSE(apm->config_.level_controller.enabled); 2882 EXPECT_FALSE(apm->config_.level_controller.enabled);
2884 // TODO(peah): Add test for the existence of the level controller object once 2883 // TODO(peah): Add test for the existence of the level controller object once
2885 // that is created only when that is specified in the config. 2884 // that is created only when that is specified in the config.
2886 // TODO(peah): Remove the testing for 2885 // TODO(peah): Remove the testing for
2887 // apm->capture_nonlocked_.level_controller_enabled once the value in config_ 2886 // apm->capture_nonlocked_.level_controller_enabled once the value in config_
2888 // is instead used to activate the level controller. 2887 // is instead used to activate the level controller.
2889 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled); 2888 EXPECT_FALSE(apm->capture_nonlocked_.level_controller_enabled);
2890 EXPECT_NEAR(kTargetLcPeakLeveldBFS, 2889 EXPECT_NEAR(kTargetLcPeakLeveldBFS,
2891 apm->config_.level_controller.initial_peak_level_dbfs, 2890 apm->config_.level_controller.initial_peak_level_dbfs,
2892 std::numeric_limits<float>::epsilon()); 2891 std::numeric_limits<float>::epsilon());
2893 } 2892 }
2894 2893
2895 } // namespace webrtc 2894 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698