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