OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 <vector> | 11 #include <vector> |
12 | 12 |
13 #include "webrtc/base/array_view.h" | 13 #include "webrtc/base/array_view.h" |
| 14 #include "webrtc/base/optional.h" |
14 #include "webrtc/modules/audio_processing/audio_buffer.h" | 15 #include "webrtc/modules/audio_processing/audio_buffer.h" |
15 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 16 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
16 #include "webrtc/modules/audio_processing/level_controller/level_controller.h" | 17 #include "webrtc/modules/audio_processing/level_controller/level_controller.h" |
17 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h" | 18 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h" |
18 #include "webrtc/modules/audio_processing/test/bitexactness_tools.h" | 19 #include "webrtc/modules/audio_processing/test/bitexactness_tools.h" |
19 #include "webrtc/test/gtest.h" | 20 #include "webrtc/test/gtest.h" |
20 | 21 |
21 namespace webrtc { | 22 namespace webrtc { |
22 namespace { | 23 namespace { |
23 | 24 |
24 const int kNumFramesToProcess = 1000; | 25 const int kNumFramesToProcess = 1000; |
25 | 26 |
26 // Processes a specified amount of frames, verifies the results and reports | 27 // Processes a specified amount of frames, verifies the results and reports |
27 // any errors. | 28 // any errors. |
28 void RunBitexactnessTest(int sample_rate_hz, | 29 void RunBitexactnessTest(int sample_rate_hz, |
29 size_t num_channels, | 30 size_t num_channels, |
| 31 rtc::Optional<float> initial_peak_level_dbfs, |
30 rtc::ArrayView<const float> output_reference) { | 32 rtc::ArrayView<const float> output_reference) { |
31 LevelController level_controller; | 33 LevelController level_controller; |
32 level_controller.Initialize(sample_rate_hz); | 34 level_controller.Initialize(sample_rate_hz); |
| 35 if (initial_peak_level_dbfs) { |
| 36 AudioProcessing::Config::LevelController config; |
| 37 config.initial_peak_level_dbfs = *initial_peak_level_dbfs; |
| 38 level_controller.ApplyConfig(config); |
| 39 } |
33 | 40 |
34 int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100); | 41 int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100); |
35 const StreamConfig capture_config(sample_rate_hz, num_channels, false); | 42 const StreamConfig capture_config(sample_rate_hz, num_channels, false); |
36 AudioBuffer capture_buffer( | 43 AudioBuffer capture_buffer( |
37 capture_config.num_frames(), capture_config.num_channels(), | 44 capture_config.num_frames(), capture_config.num_channels(), |
38 capture_config.num_frames(), capture_config.num_channels(), | 45 capture_config.num_frames(), capture_config.num_channels(), |
39 capture_config.num_frames()); | 46 capture_config.num_frames()); |
40 test::InputAudioFile capture_file( | 47 test::InputAudioFile capture_file( |
41 test::GetApmCaptureTestVectorFileName(sample_rate_hz)); | 48 test::GetApmCaptureTestVectorFileName(sample_rate_hz)); |
42 std::vector<float> capture_input(samples_per_channel * num_channels); | 49 std::vector<float> capture_input(samples_per_channel * num_channels); |
(...skipping 18 matching lines...) Expand all Loading... |
61 // memory, testing only the last frame implicitly also tests the preceeding | 68 // memory, testing only the last frame implicitly also tests the preceeding |
62 // frames. | 69 // frames. |
63 const float kVectorElementErrorBound = 1.0f / 32768.0f; | 70 const float kVectorElementErrorBound = 1.0f / 32768.0f; |
64 EXPECT_TRUE(test::VerifyDeinterleavedArray( | 71 EXPECT_TRUE(test::VerifyDeinterleavedArray( |
65 capture_config.num_frames(), capture_config.num_channels(), | 72 capture_config.num_frames(), capture_config.num_channels(), |
66 output_reference, capture_output, kVectorElementErrorBound)); | 73 output_reference, capture_output, kVectorElementErrorBound)); |
67 } | 74 } |
68 | 75 |
69 } // namespace | 76 } // namespace |
70 | 77 |
71 TEST(LevelControlConfigTest, ToStringEnabled) { | 78 TEST(LevelControllerConfig, ToString) { |
72 AudioProcessing::Config config; | 79 AudioProcessing::Config config; |
73 config.level_controller.enabled = true; | 80 config.level_controller.enabled = true; |
74 EXPECT_EQ("{enabled: true}", | 81 config.level_controller.initial_peak_level_dbfs = -6.0206f; |
| 82 EXPECT_EQ("{enabled: true, initial_peak_level_dbfs: -6.0206}", |
75 LevelController::ToString(config.level_controller)); | 83 LevelController::ToString(config.level_controller)); |
76 } | |
77 | 84 |
78 TEST(LevelControlConfigTest, ToStringNotEnabled) { | |
79 AudioProcessing::Config config; | |
80 config.level_controller.enabled = false; | 85 config.level_controller.enabled = false; |
81 EXPECT_EQ("{enabled: false}", | 86 config.level_controller.initial_peak_level_dbfs = -50.f; |
| 87 EXPECT_EQ("{enabled: false, initial_peak_level_dbfs: -50}", |
82 LevelController::ToString(config.level_controller)); | 88 LevelController::ToString(config.level_controller)); |
83 } | 89 } |
84 | 90 |
85 TEST(LevelControlConfigTest, DefaultValue) { | |
86 AudioProcessing::Config config; | |
87 EXPECT_FALSE(config.level_controller.enabled); | |
88 } | |
89 | |
90 TEST(LevelControlBitExactnessTest, DISABLED_Mono8kHz) { | 91 TEST(LevelControlBitExactnessTest, DISABLED_Mono8kHz) { |
91 const float kOutputReference[] = {-0.013939f, -0.012154f, -0.009054f}; | 92 const float kOutputReference[] = {-0.013939f, -0.012154f, -0.009054f}; |
92 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 1, | 93 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 1, |
93 kOutputReference); | 94 rtc::Optional<float>(), kOutputReference); |
94 } | 95 } |
95 | 96 |
96 TEST(LevelControlBitExactnessTest, DISABLED_Mono16kHz) { | 97 TEST(LevelControlBitExactnessTest, DISABLED_Mono16kHz) { |
97 const float kOutputReference[] = {-0.013706f, -0.013215f, -0.013018f}; | 98 const float kOutputReference[] = {-0.013706f, -0.013215f, -0.013018f}; |
98 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 1, | 99 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 1, |
99 kOutputReference); | 100 rtc::Optional<float>(), kOutputReference); |
100 } | 101 } |
101 | 102 |
102 TEST(LevelControlBitExactnessTest, DISABLED_Mono32kHz) { | 103 TEST(LevelControlBitExactnessTest, DISABLED_Mono32kHz) { |
103 const float kOutputReference[] = {-0.014495f, -0.016425f, -0.016085f}; | 104 const float kOutputReference[] = {-0.014495f, -0.016425f, -0.016085f}; |
104 RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 1, | 105 RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 1, |
105 kOutputReference); | 106 rtc::Optional<float>(), kOutputReference); |
106 } | 107 } |
107 | 108 |
108 // TODO(peah): Investigate why this particular testcase differ between Android | 109 // TODO(peah): Investigate why this particular testcase differ between Android |
109 // and the rest of the platforms. | 110 // and the rest of the platforms. |
110 TEST(LevelControlBitExactnessTest, DISABLED_Mono48kHz) { | 111 TEST(LevelControlBitExactnessTest, DISABLED_Mono48kHz) { |
111 #if !(defined(WEBRTC_ARCH_ARM64) || defined(WEBRTC_ARCH_ARM) || \ | 112 #if !(defined(WEBRTC_ARCH_ARM64) || defined(WEBRTC_ARCH_ARM) || \ |
112 defined(WEBRTC_ANDROID)) | 113 defined(WEBRTC_ANDROID)) |
113 const float kOutputReference[] = {-0.014277f, -0.015180f, -0.017437f}; | 114 const float kOutputReference[] = {-0.014277f, -0.015180f, -0.017437f}; |
114 #else | 115 #else |
115 const float kOutputReference[] = {-0.015949f, -0.016957f, -0.019478f}; | 116 const float kOutputReference[] = {-0.015949f, -0.016957f, -0.019478f}; |
116 #endif | 117 #endif |
117 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 1, | 118 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 1, |
118 kOutputReference); | 119 rtc::Optional<float>(), kOutputReference); |
119 } | 120 } |
120 | 121 |
121 TEST(LevelControlBitExactnessTest, DISABLED_Stereo8kHz) { | 122 TEST(LevelControlBitExactnessTest, DISABLED_Stereo8kHz) { |
122 const float kOutputReference[] = {-0.014063f, -0.008450f, -0.012159f, | 123 const float kOutputReference[] = {-0.014063f, -0.008450f, -0.012159f, |
123 -0.051967f, -0.023202f, -0.047858f}; | 124 -0.051967f, -0.023202f, -0.047858f}; |
124 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 2, | 125 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 2, |
125 kOutputReference); | 126 rtc::Optional<float>(), kOutputReference); |
126 } | 127 } |
127 | 128 |
128 TEST(LevelControlBitExactnessTest, DISABLED_Stereo16kHz) { | 129 TEST(LevelControlBitExactnessTest, DISABLED_Stereo16kHz) { |
129 const float kOutputReference[] = {-0.012714f, -0.005896f, -0.012220f, | 130 const float kOutputReference[] = {-0.012714f, -0.005896f, -0.012220f, |
130 -0.053306f, -0.024549f, -0.051527f}; | 131 -0.053306f, -0.024549f, -0.051527f}; |
131 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 2, | 132 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 2, |
132 kOutputReference); | 133 rtc::Optional<float>(), kOutputReference); |
133 } | 134 } |
134 | 135 |
135 TEST(LevelControlBitExactnessTest, DISABLED_Stereo32kHz) { | 136 TEST(LevelControlBitExactnessTest, DISABLED_Stereo32kHz) { |
136 const float kOutputReference[] = {-0.011737f, -0.007018f, -0.013446f, | 137 const float kOutputReference[] = {-0.011737f, -0.007018f, -0.013446f, |
137 -0.053505f, -0.026292f, -0.056221f}; | 138 -0.053505f, -0.026292f, -0.056221f}; |
138 RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 2, | 139 RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 2, |
139 kOutputReference); | 140 rtc::Optional<float>(), kOutputReference); |
140 } | 141 } |
141 | 142 |
142 TEST(LevelControlBitExactnessTest, DISABLED_Stereo48kHz) { | 143 TEST(LevelControlBitExactnessTest, DISABLED_Stereo48kHz) { |
143 const float kOutputReference[] = {-0.010643f, -0.006334f, -0.011377f, | 144 const float kOutputReference[] = {-0.010643f, -0.006334f, -0.011377f, |
144 -0.049088f, -0.023600f, -0.050465f}; | 145 -0.049088f, -0.023600f, -0.050465f}; |
145 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 2, | 146 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 2, |
146 kOutputReference); | 147 rtc::Optional<float>(), kOutputReference); |
147 } | 148 } |
148 | 149 |
149 | 150 TEST(LevelControlBitExactnessTest, DISABLED_MonoInitial48kHz) { |
| 151 const float kOutputReference[] = {-0.013753f, -0.014623f, -0.016797f}; |
| 152 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 1, |
| 153 rtc::Optional<float>(-50), kOutputReference); |
| 154 } |
150 | 155 |
151 } // namespace webrtc | 156 } // namespace webrtc |
OLD | NEW |