Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 using ::testing::SetArgPointee; | 26 using ::testing::SetArgPointee; |
| 27 using ::testing::SetArgReferee; | 27 using ::testing::SetArgReferee; |
| 28 | 28 |
| 29 namespace webrtc { | 29 namespace webrtc { |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 const int kSampleRateHz = 32000; | 32 const int kSampleRateHz = 32000; |
| 33 const int kNumChannels = 1; | 33 const int kNumChannels = 1; |
| 34 const int kSamplesPerChannel = kSampleRateHz / 100; | 34 const int kSamplesPerChannel = kSampleRateHz / 100; |
| 35 const int kInitialVolume = 128; | 35 const int kInitialVolume = 128; |
| 36 constexpr int kClippedMin = 165; // Arbitrary, but different from the default. | |
|
peah-webrtc
2016/12/05 09:23:59
Why does this need to differ from the default?
hlundin-webrtc
2016/12/05 15:01:11
No need, but I think it makes nice testing. If I h
| |
| 36 const float kAboveClippedThreshold = 0.2f; | 37 const float kAboveClippedThreshold = 0.2f; |
| 37 | 38 |
| 38 class TestVolumeCallbacks : public VolumeCallbacks { | 39 class TestVolumeCallbacks : public VolumeCallbacks { |
| 39 public: | 40 public: |
| 40 TestVolumeCallbacks() : volume_(0) {} | 41 TestVolumeCallbacks() : volume_(0) {} |
| 41 void SetMicVolume(int volume) override { volume_ = volume; } | 42 void SetMicVolume(int volume) override { volume_ = volume; } |
| 42 int GetMicVolume() override { return volume_; } | 43 int GetMicVolume() override { return volume_; } |
| 43 | 44 |
| 44 private: | 45 private: |
| 45 int volume_; | 46 int volume_; |
| 46 }; | 47 }; |
| 47 | 48 |
| 48 } // namespace | 49 } // namespace |
| 49 | 50 |
| 50 class AgcManagerDirectTest : public ::testing::Test { | 51 class AgcManagerDirectTest : public ::testing::Test { |
| 51 protected: | 52 protected: |
| 52 AgcManagerDirectTest() | 53 AgcManagerDirectTest() |
| 53 : agc_(new MockAgc), manager_(agc_, &gctrl_, &volume_, kInitialVolume) { | 54 : agc_(new MockAgc), |
| 55 manager_(agc_, &gctrl_, &volume_, kInitialVolume, kClippedMin) { | |
| 54 ExpectInitialize(); | 56 ExpectInitialize(); |
| 55 manager_.Initialize(); | 57 manager_.Initialize(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 void FirstProcess() { | 60 void FirstProcess() { |
| 59 EXPECT_CALL(*agc_, Reset()); | 61 EXPECT_CALL(*agc_, Reset()); |
| 60 EXPECT_CALL(*agc_, GetRmsErrorDb(_)).WillOnce(Return(false)); | 62 EXPECT_CALL(*agc_, GetRmsErrorDb(_)).WillOnce(Return(false)); |
| 61 CallProcess(1); | 63 CallProcess(1); |
| 62 } | 64 } |
| 63 | 65 |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 EXPECT_EQ(225, volume_.GetMicVolume()); | 500 EXPECT_EQ(225, volume_.GetMicVolume()); |
| 499 } | 501 } |
| 500 | 502 |
| 501 TEST_F(AgcManagerDirectTest, ClippingLoweringIsLimited) { | 503 TEST_F(AgcManagerDirectTest, ClippingLoweringIsLimited) { |
| 502 SetVolumeAndProcess(180); | 504 SetVolumeAndProcess(180); |
| 503 | 505 |
| 504 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | 506 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) |
| 505 .WillOnce(Return(kAboveClippedThreshold)); | 507 .WillOnce(Return(kAboveClippedThreshold)); |
| 506 EXPECT_CALL(*agc_, Reset()).Times(1); | 508 EXPECT_CALL(*agc_, Reset()).Times(1); |
| 507 CallPreProc(1); | 509 CallPreProc(1); |
| 508 EXPECT_EQ(170, volume_.GetMicVolume()); | 510 EXPECT_EQ(kClippedMin, volume_.GetMicVolume()); |
| 509 | 511 |
| 510 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | 512 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) |
| 511 .WillRepeatedly(Return(kAboveClippedThreshold)); | 513 .WillRepeatedly(Return(kAboveClippedThreshold)); |
| 512 EXPECT_CALL(*agc_, Reset()).Times(0); | 514 EXPECT_CALL(*agc_, Reset()).Times(0); |
| 513 CallPreProc(1000); | 515 CallPreProc(1000); |
| 514 EXPECT_EQ(170, volume_.GetMicVolume()); | 516 EXPECT_EQ(kClippedMin, volume_.GetMicVolume()); |
| 515 } | 517 } |
| 516 | 518 |
| 517 TEST_F(AgcManagerDirectTest, ClippingMaxIsRespectedWhenEqualToLevel) { | 519 TEST_F(AgcManagerDirectTest, ClippingMaxIsRespectedWhenEqualToLevel) { |
| 518 SetVolumeAndProcess(255); | 520 SetVolumeAndProcess(255); |
| 519 | 521 |
| 520 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | 522 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) |
| 521 .WillOnce(Return(kAboveClippedThreshold)); | 523 .WillOnce(Return(kAboveClippedThreshold)); |
| 522 EXPECT_CALL(*agc_, Reset()).Times(1); | 524 EXPECT_CALL(*agc_, Reset()).Times(1); |
| 523 CallPreProc(1); | 525 CallPreProc(1); |
| 524 EXPECT_EQ(240, volume_.GetMicVolume()); | 526 EXPECT_EQ(240, volume_.GetMicVolume()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 .WillOnce(Return(kAboveClippedThreshold)); | 584 .WillOnce(Return(kAboveClippedThreshold)); |
| 583 EXPECT_CALL(*agc_, Reset()).Times(1); | 585 EXPECT_CALL(*agc_, Reset()).Times(1); |
| 584 CallPreProc(1); | 586 CallPreProc(1); |
| 585 EXPECT_EQ(180, volume_.GetMicVolume()); | 587 EXPECT_EQ(180, volume_.GetMicVolume()); |
| 586 | 588 |
| 587 CallPreProc(300); | 589 CallPreProc(300); |
| 588 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | 590 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) |
| 589 .WillOnce(Return(kAboveClippedThreshold)); | 591 .WillOnce(Return(kAboveClippedThreshold)); |
| 590 EXPECT_CALL(*agc_, Reset()).Times(1); | 592 EXPECT_CALL(*agc_, Reset()).Times(1); |
| 591 CallPreProc(1); | 593 CallPreProc(1); |
| 592 EXPECT_EQ(170, volume_.GetMicVolume()); | 594 EXPECT_EQ(kClippedMin, volume_.GetMicVolume()); |
| 593 | 595 |
| 594 // Current level is now at the minimum, but the maximum allowed level still | 596 // Current level is now at the minimum, but the maximum allowed level still |
| 595 // has more to decrease. | 597 // has more to decrease. |
| 596 CallPreProc(300); | 598 CallPreProc(300); |
| 597 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | 599 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) |
| 598 .WillOnce(Return(kAboveClippedThreshold)); | 600 .WillOnce(Return(kAboveClippedThreshold)); |
| 599 CallPreProc(1); | 601 CallPreProc(1); |
| 600 | 602 |
| 601 CallPreProc(300); | 603 CallPreProc(300); |
| 602 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | 604 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 677 FirstProcess(); | 679 FirstProcess(); |
| 678 | 680 |
| 679 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | 681 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) |
| 680 .WillRepeatedly(DoAll(SetArgPointee<0>(30), Return(true))); | 682 .WillRepeatedly(DoAll(SetArgPointee<0>(30), Return(true))); |
| 681 volume_.SetMicVolume(0); | 683 volume_.SetMicVolume(0); |
| 682 CallProcess(10); | 684 CallProcess(10); |
| 683 EXPECT_EQ(0, volume_.GetMicVolume()); | 685 EXPECT_EQ(0, volume_.GetMicVolume()); |
| 684 } | 686 } |
| 685 | 687 |
| 686 } // namespace webrtc | 688 } // namespace webrtc |
| OLD | NEW |