OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h" | |
12 | |
13 #include "testing/gmock/include/gmock/gmock.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 #include "webrtc/common_types.h" | |
16 #include "webrtc/modules/audio_processing/agc/mock_agc.h" | |
17 #include "webrtc/modules/audio_processing/include/mock_audio_processing.h" | |
18 #include "webrtc/system_wrappers/interface/trace.h" | |
19 #include "webrtc/test/testsupport/trace_to_stderr.h" | |
20 | |
21 using ::testing::_; | |
22 using ::testing::DoAll; | |
23 using ::testing::Eq; | |
24 using ::testing::Mock; | |
25 using ::testing::Return; | |
26 using ::testing::SetArgPointee; | |
27 using ::testing::SetArgReferee; | |
28 | |
29 namespace webrtc { | |
30 namespace { | |
31 | |
32 const int kSampleRateHz = 32000; | |
33 const int kNumChannels = 1; | |
34 const int kSamplesPerChannel = kSampleRateHz / 100; | |
35 const int kInitialVolume = 128; | |
36 const float kAboveClippedThreshold = 0.2f; | |
37 | |
38 class TestVolumeCallbacks : public VolumeCallbacks { | |
39 public: | |
40 void SetMicVolume(int volume) override { volume_ = volume; } | |
41 int GetMicVolume() override { return volume_; } | |
42 | |
43 private: | |
44 int volume_; | |
45 }; | |
46 | |
47 } // namespace | |
48 | |
49 class AgcManagerDirectTest : public ::testing::Test { | |
50 protected: | |
51 AgcManagerDirectTest() | |
52 : agc_(new MockAgc), manager_(agc_, &gctrl_, &volume_, kInitialVolume) { | |
53 ExpectInitialize(); | |
54 manager_.Initialize(); | |
55 } | |
56 | |
57 void FirstProcess() { | |
58 EXPECT_CALL(*agc_, Reset()); | |
59 EXPECT_CALL(*agc_, GetRmsErrorDb(_)).WillOnce(Return(false)); | |
60 CallProcess(1); | |
61 } | |
62 | |
63 void SetVolumeAndProcess(int volume) { | |
64 volume_.SetMicVolume(volume); | |
65 FirstProcess(); | |
66 } | |
67 | |
68 void ExpectCheckVolumeAndReset(int volume) { | |
69 volume_.SetMicVolume(volume); | |
70 EXPECT_CALL(*agc_, Reset()); | |
71 } | |
72 | |
73 void ExpectInitialize() { | |
74 EXPECT_CALL(gctrl_, set_mode(GainControl::kFixedDigital)); | |
75 EXPECT_CALL(gctrl_, set_target_level_dbfs(2)); | |
76 EXPECT_CALL(gctrl_, set_compression_gain_db(7)); | |
77 EXPECT_CALL(gctrl_, enable_limiter(true)); | |
78 } | |
79 | |
80 void CallProcess(int num_calls) { | |
81 for (int i = 0; i < num_calls; ++i) { | |
82 EXPECT_CALL(*agc_, Process(_, _, _)).WillOnce(Return(0)); | |
83 manager_.Process(nullptr, kSamplesPerChannel, kSampleRateHz); | |
84 } | |
85 } | |
86 | |
87 void CallPreProc(int num_calls) { | |
88 for (int i = 0; i < num_calls; ++i) { | |
89 manager_.AnalyzePreProcess(nullptr, kNumChannels, kSamplesPerChannel); | |
90 } | |
91 } | |
92 | |
93 MockAgc* agc_; | |
94 MockGainControl gctrl_; | |
95 TestVolumeCallbacks volume_; | |
96 AgcManagerDirect manager_; | |
97 test::TraceToStderr trace_to_stderr; | |
98 }; | |
99 | |
100 TEST_F(AgcManagerDirectTest, StartupMinVolumeConfigurationIsRespected) { | |
101 FirstProcess(); | |
102 EXPECT_EQ(kInitialVolume, volume_.GetMicVolume()); | |
Andrew MacDonald
2015/09/29 22:49:32
Is this checking anything? The earlier test sets t
aluebs-webrtc
2015/09/29 23:00:17
This one does the same. The volume_ is initialized
Andrew MacDonald
2015/09/29 23:02:26
Got it, thanks.
| |
103 } | |
104 | |
105 TEST_F(AgcManagerDirectTest, MicVolumeResponseToRmsError) { | |
106 FirstProcess(); | |
Andrew MacDonald
2015/09/29 22:49:32
Just curious, why did you switch these?
aluebs-webrtc
2015/09/29 23:00:18
2 additional of these were necessary to not break,
Andrew MacDonald
2015/09/29 23:02:26
No, this is fine.
| |
107 | |
108 // Compressor default; no residual error. | |
109 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
110 .WillOnce(DoAll(SetArgPointee<0>(5), Return(true))); | |
111 CallProcess(1); | |
112 | |
113 // Inside the compressor's window; no change of volume. | |
114 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
115 .WillOnce(DoAll(SetArgPointee<0>(10), Return(true))); | |
116 CallProcess(1); | |
117 | |
118 // Above the compressor's window; volume should be increased. | |
119 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
120 .WillOnce(DoAll(SetArgPointee<0>(11), Return(true))); | |
121 CallProcess(1); | |
122 EXPECT_EQ(130, volume_.GetMicVolume()); | |
123 | |
124 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
125 .WillOnce(DoAll(SetArgPointee<0>(20), Return(true))); | |
126 CallProcess(1); | |
127 EXPECT_EQ(168, volume_.GetMicVolume()); | |
128 | |
129 // Inside the compressor's window; no change of volume. | |
130 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
131 .WillOnce(DoAll(SetArgPointee<0>(5), Return(true))); | |
132 CallProcess(1); | |
133 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
134 .WillOnce(DoAll(SetArgPointee<0>(0), Return(true))); | |
135 CallProcess(1); | |
136 | |
137 // Below the compressor's window; volume should be decreased. | |
138 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
139 .WillOnce(DoAll(SetArgPointee<0>(-1), Return(true))); | |
140 CallProcess(1); | |
141 EXPECT_EQ(167, volume_.GetMicVolume()); | |
142 | |
143 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
144 .WillOnce(DoAll(SetArgPointee<0>(-1), Return(true))); | |
145 CallProcess(1); | |
146 EXPECT_EQ(163, volume_.GetMicVolume()); | |
147 | |
148 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
149 .WillOnce(DoAll(SetArgPointee<0>(-9), Return(true))); | |
150 CallProcess(1); | |
151 EXPECT_EQ(129, volume_.GetMicVolume()); | |
152 } | |
153 | |
154 TEST_F(AgcManagerDirectTest, MicVolumeIsLimited) { | |
155 FirstProcess(); | |
156 | |
157 // Maximum upwards change is limited. | |
158 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
159 .WillOnce(DoAll(SetArgPointee<0>(30), Return(true))); | |
160 CallProcess(1); | |
161 EXPECT_EQ(183, volume_.GetMicVolume()); | |
162 | |
163 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
164 .WillOnce(DoAll(SetArgPointee<0>(30), Return(true))); | |
165 CallProcess(1); | |
166 EXPECT_EQ(243, volume_.GetMicVolume()); | |
167 | |
168 // Won't go higher than the maximum. | |
169 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
170 .WillOnce(DoAll(SetArgPointee<0>(30), Return(true))); | |
171 CallProcess(1); | |
172 EXPECT_EQ(255, volume_.GetMicVolume()); | |
173 | |
174 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
175 .WillOnce(DoAll(SetArgPointee<0>(-1), Return(true))); | |
176 CallProcess(1); | |
177 EXPECT_EQ(254, volume_.GetMicVolume()); | |
178 | |
179 // Maximum downwards change is limited. | |
180 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
181 .WillOnce(DoAll(SetArgPointee<0>(-40), Return(true))); | |
182 CallProcess(1); | |
183 EXPECT_EQ(194, volume_.GetMicVolume()); | |
184 | |
185 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
186 .WillOnce(DoAll(SetArgPointee<0>(-40), Return(true))); | |
187 CallProcess(1); | |
188 EXPECT_EQ(137, volume_.GetMicVolume()); | |
189 | |
190 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
191 .WillOnce(DoAll(SetArgPointee<0>(-40), Return(true))); | |
192 CallProcess(1); | |
193 EXPECT_EQ(88, volume_.GetMicVolume()); | |
194 | |
195 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
196 .WillOnce(DoAll(SetArgPointee<0>(-40), Return(true))); | |
197 CallProcess(1); | |
198 EXPECT_EQ(54, volume_.GetMicVolume()); | |
199 | |
200 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
201 .WillOnce(DoAll(SetArgPointee<0>(-40), Return(true))); | |
202 CallProcess(1); | |
203 EXPECT_EQ(33, volume_.GetMicVolume()); | |
204 | |
205 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
206 .WillOnce(DoAll(SetArgPointee<0>(-40), Return(true))); | |
207 CallProcess(1); | |
208 EXPECT_EQ(18, volume_.GetMicVolume()); | |
209 | |
210 // Won't go lower than the minimum. | |
211 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
212 .WillOnce(DoAll(SetArgPointee<0>(-40), Return(true))); | |
213 CallProcess(1); | |
214 EXPECT_EQ(12, volume_.GetMicVolume()); | |
215 } | |
216 | |
217 TEST_F(AgcManagerDirectTest, CompressorStepsTowardsTarget) { | |
218 FirstProcess(); | |
219 | |
220 // Compressor default; no call to set_compression_gain_db. | |
221 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
222 .WillOnce(DoAll(SetArgPointee<0>(5), Return(true))) | |
223 .WillRepeatedly(Return(false)); | |
224 EXPECT_CALL(gctrl_, set_compression_gain_db(_)).Times(0); | |
225 CallProcess(20); | |
226 | |
227 // Moves slowly upwards. | |
228 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
229 .WillOnce(DoAll(SetArgPointee<0>(9), Return(true))) | |
230 .WillRepeatedly(Return(false)); | |
231 EXPECT_CALL(gctrl_, set_compression_gain_db(_)).Times(0); | |
232 CallProcess(19); | |
233 EXPECT_CALL(gctrl_, set_compression_gain_db(8)).WillOnce(Return(0)); | |
234 CallProcess(1); | |
235 | |
236 EXPECT_CALL(gctrl_, set_compression_gain_db(_)).Times(0); | |
237 CallProcess(19); | |
238 EXPECT_CALL(gctrl_, set_compression_gain_db(9)).WillOnce(Return(0)); | |
239 CallProcess(1); | |
240 | |
241 EXPECT_CALL(gctrl_, set_compression_gain_db(_)).Times(0); | |
242 CallProcess(20); | |
243 | |
244 // Moves slowly downward, then reverses before reaching the original target. | |
245 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
246 .WillOnce(DoAll(SetArgPointee<0>(5), Return(true))) | |
247 .WillRepeatedly(Return(false)); | |
248 EXPECT_CALL(gctrl_, set_compression_gain_db(_)).Times(0); | |
249 CallProcess(19); | |
250 EXPECT_CALL(gctrl_, set_compression_gain_db(8)).WillOnce(Return(0)); | |
251 CallProcess(1); | |
252 | |
253 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
254 .WillOnce(DoAll(SetArgPointee<0>(9), Return(true))) | |
255 .WillRepeatedly(Return(false)); | |
256 EXPECT_CALL(gctrl_, set_compression_gain_db(_)).Times(0); | |
257 CallProcess(19); | |
258 EXPECT_CALL(gctrl_, set_compression_gain_db(9)).WillOnce(Return(0)); | |
259 CallProcess(1); | |
260 | |
261 EXPECT_CALL(gctrl_, set_compression_gain_db(_)).Times(0); | |
262 CallProcess(20); | |
263 } | |
264 | |
265 TEST_F(AgcManagerDirectTest, CompressorErrorIsDeemphasized) { | |
266 FirstProcess(); | |
267 | |
268 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
269 .WillOnce(DoAll(SetArgPointee<0>(10), Return(true))) | |
270 .WillRepeatedly(Return(false)); | |
271 CallProcess(19); | |
272 EXPECT_CALL(gctrl_, set_compression_gain_db(8)).WillOnce(Return(0)); | |
273 CallProcess(20); | |
274 EXPECT_CALL(gctrl_, set_compression_gain_db(9)).WillOnce(Return(0)); | |
275 CallProcess(1); | |
276 EXPECT_CALL(gctrl_, set_compression_gain_db(_)).Times(0); | |
277 CallProcess(20); | |
278 | |
279 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
280 .WillOnce(DoAll(SetArgPointee<0>(0), Return(true))) | |
281 .WillRepeatedly(Return(false)); | |
282 CallProcess(19); | |
283 EXPECT_CALL(gctrl_, set_compression_gain_db(8)).WillOnce(Return(0)); | |
284 CallProcess(20); | |
285 EXPECT_CALL(gctrl_, set_compression_gain_db(7)).WillOnce(Return(0)); | |
286 CallProcess(20); | |
287 EXPECT_CALL(gctrl_, set_compression_gain_db(6)).WillOnce(Return(0)); | |
288 CallProcess(1); | |
289 EXPECT_CALL(gctrl_, set_compression_gain_db(_)).Times(0); | |
290 CallProcess(20); | |
291 } | |
292 | |
293 TEST_F(AgcManagerDirectTest, CompressorReachesMaximum) { | |
294 FirstProcess(); | |
295 | |
296 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
297 .WillOnce(DoAll(SetArgPointee<0>(10), Return(true))) | |
298 .WillOnce(DoAll(SetArgPointee<0>(10), Return(true))) | |
299 .WillOnce(DoAll(SetArgPointee<0>(10), Return(true))) | |
300 .WillOnce(DoAll(SetArgPointee<0>(10), Return(true))) | |
301 .WillRepeatedly(Return(false)); | |
302 CallProcess(19); | |
303 EXPECT_CALL(gctrl_, set_compression_gain_db(8)).WillOnce(Return(0)); | |
304 CallProcess(20); | |
305 EXPECT_CALL(gctrl_, set_compression_gain_db(9)).WillOnce(Return(0)); | |
306 CallProcess(20); | |
307 EXPECT_CALL(gctrl_, set_compression_gain_db(10)).WillOnce(Return(0)); | |
308 CallProcess(20); | |
309 EXPECT_CALL(gctrl_, set_compression_gain_db(11)).WillOnce(Return(0)); | |
310 CallProcess(20); | |
311 EXPECT_CALL(gctrl_, set_compression_gain_db(12)).WillOnce(Return(0)); | |
312 CallProcess(1); | |
313 } | |
314 | |
315 TEST_F(AgcManagerDirectTest, CompressorReachesMinimum) { | |
316 FirstProcess(); | |
317 | |
318 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
319 .WillOnce(DoAll(SetArgPointee<0>(0), Return(true))) | |
320 .WillOnce(DoAll(SetArgPointee<0>(0), Return(true))) | |
321 .WillOnce(DoAll(SetArgPointee<0>(0), Return(true))) | |
322 .WillOnce(DoAll(SetArgPointee<0>(0), Return(true))) | |
323 .WillRepeatedly(Return(false)); | |
324 CallProcess(19); | |
325 EXPECT_CALL(gctrl_, set_compression_gain_db(6)).WillOnce(Return(0)); | |
326 CallProcess(20); | |
327 EXPECT_CALL(gctrl_, set_compression_gain_db(5)).WillOnce(Return(0)); | |
328 CallProcess(20); | |
329 EXPECT_CALL(gctrl_, set_compression_gain_db(4)).WillOnce(Return(0)); | |
330 CallProcess(20); | |
331 EXPECT_CALL(gctrl_, set_compression_gain_db(3)).WillOnce(Return(0)); | |
332 CallProcess(20); | |
333 EXPECT_CALL(gctrl_, set_compression_gain_db(2)).WillOnce(Return(0)); | |
334 CallProcess(1); | |
335 } | |
336 | |
337 TEST_F(AgcManagerDirectTest, NoActionWhileMuted) { | |
338 manager_.SetCaptureMuted(true); | |
339 manager_.Process(nullptr, kSamplesPerChannel, kSampleRateHz); | |
340 } | |
341 | |
342 TEST_F(AgcManagerDirectTest, UnmutingChecksVolumeWithoutRaising) { | |
343 FirstProcess(); | |
344 | |
345 manager_.SetCaptureMuted(true); | |
346 manager_.SetCaptureMuted(false); | |
347 ExpectCheckVolumeAndReset(127); | |
348 // SetMicVolume should not be called. | |
349 EXPECT_CALL(*agc_, GetRmsErrorDb(_)).WillOnce(Return(false)); | |
350 CallProcess(1); | |
351 EXPECT_EQ(127, volume_.GetMicVolume()); | |
352 } | |
353 | |
354 TEST_F(AgcManagerDirectTest, UnmutingRaisesTooLowVolume) { | |
355 FirstProcess(); | |
356 | |
357 manager_.SetCaptureMuted(true); | |
358 manager_.SetCaptureMuted(false); | |
359 ExpectCheckVolumeAndReset(11); | |
360 EXPECT_CALL(*agc_, GetRmsErrorDb(_)).WillOnce(Return(false)); | |
361 CallProcess(1); | |
362 EXPECT_EQ(12, volume_.GetMicVolume()); | |
363 } | |
364 | |
365 TEST_F(AgcManagerDirectTest, ManualLevelChangeResultsInNoSetMicCall) { | |
366 FirstProcess(); | |
367 | |
368 // Change outside of compressor's range, which would normally trigger a call | |
369 // to SetMicVolume. | |
370 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
371 .WillOnce(DoAll(SetArgPointee<0>(11), Return(true))); | |
372 // GetMicVolume returns a value outside of the quantization slack, indicating | |
373 // a manual volume change. | |
374 volume_.SetMicVolume(154); | |
375 // SetMicVolume should not be called. | |
376 EXPECT_CALL(*agc_, Reset()).Times(1); | |
377 CallProcess(1); | |
378 EXPECT_EQ(154, volume_.GetMicVolume()); | |
379 | |
380 // Do the same thing, except downwards now. | |
381 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
382 .WillOnce(DoAll(SetArgPointee<0>(-1), Return(true))); | |
383 volume_.SetMicVolume(100); | |
384 EXPECT_CALL(*agc_, Reset()).Times(1); | |
385 CallProcess(1); | |
386 EXPECT_EQ(100, volume_.GetMicVolume()); | |
387 | |
388 // And finally verify the AGC continues working without a manual change. | |
389 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
390 .WillOnce(DoAll(SetArgPointee<0>(-1), Return(true))); | |
391 CallProcess(1); | |
392 EXPECT_EQ(99, volume_.GetMicVolume()); | |
393 } | |
394 | |
395 TEST_F(AgcManagerDirectTest, RecoveryAfterManualLevelChangeFromMax) { | |
396 FirstProcess(); | |
397 | |
398 // Force the mic up to max volume. Takes a few steps due to the residual | |
399 // gain limitation. | |
400 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
401 .WillRepeatedly(DoAll(SetArgPointee<0>(30), Return(true))); | |
402 CallProcess(1); | |
403 EXPECT_EQ(183, volume_.GetMicVolume()); | |
404 CallProcess(1); | |
405 EXPECT_EQ(243, volume_.GetMicVolume()); | |
406 CallProcess(1); | |
407 EXPECT_EQ(255, volume_.GetMicVolume()); | |
408 | |
409 // Manual change does not result in SetMicVolume call. | |
410 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
411 .WillOnce(DoAll(SetArgPointee<0>(-1), Return(true))); | |
412 volume_.SetMicVolume(50); | |
413 EXPECT_CALL(*agc_, Reset()).Times(1); | |
414 CallProcess(1); | |
415 EXPECT_EQ(50, volume_.GetMicVolume()); | |
416 | |
417 // Continues working as usual afterwards. | |
418 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
419 .WillOnce(DoAll(SetArgPointee<0>(20), Return(true))); | |
420 CallProcess(1); | |
421 EXPECT_EQ(69, volume_.GetMicVolume()); | |
422 } | |
423 | |
424 TEST_F(AgcManagerDirectTest, RecoveryAfterManualLevelChangeBelowMin) { | |
425 FirstProcess(); | |
426 | |
427 // Manual change below min. | |
428 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
429 .WillOnce(DoAll(SetArgPointee<0>(-1), Return(true))); | |
430 // Don't set to zero, which will cause AGC to take no action. | |
431 volume_.SetMicVolume(1); | |
432 EXPECT_CALL(*agc_, Reset()).Times(1); | |
433 CallProcess(1); | |
434 EXPECT_EQ(1, volume_.GetMicVolume()); | |
435 | |
436 // Continues working as usual afterwards. | |
437 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
438 .WillOnce(DoAll(SetArgPointee<0>(11), Return(true))); | |
439 CallProcess(1); | |
440 EXPECT_EQ(2, volume_.GetMicVolume()); | |
441 | |
442 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
443 .WillOnce(DoAll(SetArgPointee<0>(30), Return(true))); | |
444 CallProcess(1); | |
445 EXPECT_EQ(11, volume_.GetMicVolume()); | |
446 | |
447 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
448 .WillOnce(DoAll(SetArgPointee<0>(20), Return(true))); | |
449 CallProcess(1); | |
450 EXPECT_EQ(18, volume_.GetMicVolume()); | |
451 } | |
452 | |
453 TEST_F(AgcManagerDirectTest, NoClippingHasNoImpact) { | |
454 FirstProcess(); | |
455 | |
456 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)).WillRepeatedly(Return(0)); | |
457 CallPreProc(100); | |
458 EXPECT_EQ(128, volume_.GetMicVolume()); | |
459 } | |
460 | |
461 TEST_F(AgcManagerDirectTest, ClippingUnderThresholdHasNoImpact) { | |
462 FirstProcess(); | |
463 | |
464 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)).WillOnce(Return(0.099)); | |
465 CallPreProc(1); | |
466 EXPECT_EQ(128, volume_.GetMicVolume()); | |
467 } | |
468 | |
469 TEST_F(AgcManagerDirectTest, ClippingLowersVolume) { | |
470 SetVolumeAndProcess(255); | |
471 | |
472 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)).WillOnce(Return(0.101)); | |
473 EXPECT_CALL(*agc_, Reset()).Times(1); | |
474 CallPreProc(1); | |
475 EXPECT_EQ(240, volume_.GetMicVolume()); | |
476 } | |
477 | |
478 TEST_F(AgcManagerDirectTest, WaitingPeriodBetweenClippingChecks) { | |
479 SetVolumeAndProcess(255); | |
480 | |
481 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
482 .WillOnce(Return(kAboveClippedThreshold)); | |
483 EXPECT_CALL(*agc_, Reset()).Times(1); | |
484 CallPreProc(1); | |
485 EXPECT_EQ(240, volume_.GetMicVolume()); | |
486 | |
487 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
488 .WillRepeatedly(Return(kAboveClippedThreshold)); | |
489 EXPECT_CALL(*agc_, Reset()).Times(0); | |
490 CallPreProc(300); | |
491 EXPECT_EQ(240, volume_.GetMicVolume()); | |
492 | |
493 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
494 .WillOnce(Return(kAboveClippedThreshold)); | |
495 EXPECT_CALL(*agc_, Reset()).Times(1); | |
496 CallPreProc(1); | |
497 EXPECT_EQ(225, volume_.GetMicVolume()); | |
498 } | |
499 | |
500 TEST_F(AgcManagerDirectTest, ClippingLoweringIsLimited) { | |
501 SetVolumeAndProcess(180); | |
502 | |
503 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
504 .WillOnce(Return(kAboveClippedThreshold)); | |
505 EXPECT_CALL(*agc_, Reset()).Times(1); | |
506 CallPreProc(1); | |
507 EXPECT_EQ(170, volume_.GetMicVolume()); | |
508 | |
509 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
510 .WillRepeatedly(Return(kAboveClippedThreshold)); | |
511 EXPECT_CALL(*agc_, Reset()).Times(0); | |
512 CallPreProc(1000); | |
513 EXPECT_EQ(170, volume_.GetMicVolume()); | |
514 } | |
515 | |
516 TEST_F(AgcManagerDirectTest, ClippingMaxIsRespectedWhenEqualToLevel) { | |
517 SetVolumeAndProcess(255); | |
518 | |
519 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
520 .WillOnce(Return(kAboveClippedThreshold)); | |
521 EXPECT_CALL(*agc_, Reset()).Times(1); | |
522 CallPreProc(1); | |
523 EXPECT_EQ(240, volume_.GetMicVolume()); | |
524 | |
525 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
526 .WillRepeatedly(DoAll(SetArgPointee<0>(30), Return(true))); | |
527 CallProcess(10); | |
528 EXPECT_EQ(240, volume_.GetMicVolume()); | |
529 } | |
530 | |
531 TEST_F(AgcManagerDirectTest, ClippingMaxIsRespectedWhenHigherThanLevel) { | |
532 SetVolumeAndProcess(200); | |
533 | |
534 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
535 .WillOnce(Return(kAboveClippedThreshold)); | |
536 EXPECT_CALL(*agc_, Reset()).Times(1); | |
537 CallPreProc(1); | |
538 EXPECT_EQ(185, volume_.GetMicVolume()); | |
539 | |
540 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
541 .WillRepeatedly(DoAll(SetArgPointee<0>(40), Return(true))); | |
542 CallProcess(1); | |
543 EXPECT_EQ(240, volume_.GetMicVolume()); | |
544 CallProcess(10); | |
545 EXPECT_EQ(240, volume_.GetMicVolume()); | |
546 } | |
547 | |
548 TEST_F(AgcManagerDirectTest, MaxCompressionIsIncreasedAfterClipping) { | |
549 SetVolumeAndProcess(210); | |
550 | |
551 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
552 .WillOnce(Return(kAboveClippedThreshold)); | |
553 EXPECT_CALL(*agc_, Reset()).Times(1); | |
554 CallPreProc(1); | |
555 EXPECT_EQ(195, volume_.GetMicVolume()); | |
556 | |
557 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
558 .WillOnce(DoAll(SetArgPointee<0>(11), Return(true))) | |
559 .WillOnce(DoAll(SetArgPointee<0>(11), Return(true))) | |
560 .WillOnce(DoAll(SetArgPointee<0>(11), Return(true))) | |
561 .WillOnce(DoAll(SetArgPointee<0>(11), Return(true))) | |
562 .WillOnce(DoAll(SetArgPointee<0>(11), Return(true))) | |
563 .WillRepeatedly(Return(false)); | |
564 CallProcess(19); | |
565 EXPECT_CALL(gctrl_, set_compression_gain_db(8)).WillOnce(Return(0)); | |
566 CallProcess(20); | |
567 EXPECT_CALL(gctrl_, set_compression_gain_db(9)).WillOnce(Return(0)); | |
568 CallProcess(20); | |
569 EXPECT_CALL(gctrl_, set_compression_gain_db(10)).WillOnce(Return(0)); | |
570 CallProcess(20); | |
571 EXPECT_CALL(gctrl_, set_compression_gain_db(11)).WillOnce(Return(0)); | |
572 CallProcess(20); | |
573 EXPECT_CALL(gctrl_, set_compression_gain_db(12)).WillOnce(Return(0)); | |
574 CallProcess(20); | |
575 EXPECT_CALL(gctrl_, set_compression_gain_db(13)).WillOnce(Return(0)); | |
576 CallProcess(1); | |
577 | |
578 // Continue clipping until we hit the maximum surplus compression. | |
579 CallPreProc(300); | |
580 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
581 .WillOnce(Return(kAboveClippedThreshold)); | |
582 EXPECT_CALL(*agc_, Reset()).Times(1); | |
583 CallPreProc(1); | |
584 EXPECT_EQ(180, volume_.GetMicVolume()); | |
585 | |
586 CallPreProc(300); | |
587 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
588 .WillOnce(Return(kAboveClippedThreshold)); | |
589 EXPECT_CALL(*agc_, Reset()).Times(1); | |
590 CallPreProc(1); | |
591 EXPECT_EQ(170, volume_.GetMicVolume()); | |
592 | |
593 // Current level is now at the minimum, but the maximum allowed level still | |
594 // has more to decrease. | |
595 CallPreProc(300); | |
596 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
597 .WillOnce(Return(kAboveClippedThreshold)); | |
598 CallPreProc(1); | |
599 | |
600 CallPreProc(300); | |
601 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
602 .WillOnce(Return(kAboveClippedThreshold)); | |
603 CallPreProc(1); | |
604 | |
605 CallPreProc(300); | |
606 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
607 .WillOnce(Return(kAboveClippedThreshold)); | |
608 CallPreProc(1); | |
609 | |
610 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
611 .WillOnce(DoAll(SetArgPointee<0>(16), Return(true))) | |
612 .WillOnce(DoAll(SetArgPointee<0>(16), Return(true))) | |
613 .WillOnce(DoAll(SetArgPointee<0>(16), Return(true))) | |
614 .WillOnce(DoAll(SetArgPointee<0>(16), Return(true))) | |
615 .WillRepeatedly(Return(false)); | |
616 CallProcess(19); | |
617 EXPECT_CALL(gctrl_, set_compression_gain_db(14)).WillOnce(Return(0)); | |
618 CallProcess(20); | |
619 EXPECT_CALL(gctrl_, set_compression_gain_db(15)).WillOnce(Return(0)); | |
620 CallProcess(20); | |
621 EXPECT_CALL(gctrl_, set_compression_gain_db(16)).WillOnce(Return(0)); | |
622 CallProcess(20); | |
623 EXPECT_CALL(gctrl_, set_compression_gain_db(17)).WillOnce(Return(0)); | |
624 CallProcess(20); | |
625 EXPECT_CALL(gctrl_, set_compression_gain_db(18)).WillOnce(Return(0)); | |
626 CallProcess(1); | |
627 } | |
628 | |
629 TEST_F(AgcManagerDirectTest, UserCanRaiseVolumeAfterClipping) { | |
630 SetVolumeAndProcess(225); | |
631 | |
632 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
633 .WillOnce(Return(kAboveClippedThreshold)); | |
634 EXPECT_CALL(*agc_, Reset()).Times(1); | |
635 CallPreProc(1); | |
636 EXPECT_EQ(210, volume_.GetMicVolume()); | |
637 | |
638 // High enough error to trigger a volume check. | |
639 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
640 .WillOnce(DoAll(SetArgPointee<0>(14), Return(true))); | |
641 // User changed the volume. | |
642 volume_.SetMicVolume(250); | |
643 EXPECT_CALL(*agc_, Reset()).Times(1); | |
644 CallProcess(1); | |
645 EXPECT_EQ(250, volume_.GetMicVolume()); | |
646 | |
647 // Move down... | |
648 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
649 .WillOnce(DoAll(SetArgPointee<0>(-10), Return(true))); | |
650 CallProcess(1); | |
651 EXPECT_EQ(210, volume_.GetMicVolume()); | |
652 // And back up to the new max established by the user. | |
653 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
654 .WillOnce(DoAll(SetArgPointee<0>(40), Return(true))); | |
655 CallProcess(1); | |
656 EXPECT_EQ(250, volume_.GetMicVolume()); | |
657 // Will not move above new maximum. | |
658 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
659 .WillOnce(DoAll(SetArgPointee<0>(30), Return(true))); | |
660 CallProcess(1); | |
661 EXPECT_EQ(250, volume_.GetMicVolume()); | |
662 } | |
663 | |
664 TEST_F(AgcManagerDirectTest, ClippingDoesNotPullLowVolumeBackUp) { | |
665 SetVolumeAndProcess(80); | |
666 | |
667 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
668 .WillOnce(Return(kAboveClippedThreshold)); | |
669 EXPECT_CALL(*agc_, Reset()).Times(0); | |
670 int initial_volume = volume_.GetMicVolume(); | |
671 CallPreProc(1); | |
672 EXPECT_EQ(initial_volume, volume_.GetMicVolume()); | |
673 } | |
674 | |
675 TEST_F(AgcManagerDirectTest, TakesNoActionOnZeroMicVolume) { | |
676 FirstProcess(); | |
677 | |
678 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
679 .WillRepeatedly(DoAll(SetArgPointee<0>(30), Return(true))); | |
680 volume_.SetMicVolume(0); | |
681 CallProcess(10); | |
682 EXPECT_EQ(0, volume_.GetMicVolume()); | |
683 } | |
684 | |
685 } // namespace webrtc | |
OLD | NEW |