diff --git a/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc b/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc index 83d1aed2d5..c30ab08625 100644 --- a/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc +++ b/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc @@ -26,6 +26,9 @@ enum { kLookahead = 10 }; // Length of binary spectrum sequence. enum { kSequenceLength = 400 }; +const int kEnable[] = { 0, 1 }; +const size_t kSizeEnable = sizeof(kEnable) / sizeof(*kEnable); + class DelayEstimatorTest : public ::testing::Test { protected: DelayEstimatorTest(); @@ -38,7 +41,8 @@ class DelayEstimatorTest : public ::testing::Test { void RunBinarySpectra(BinaryDelayEstimator* binary1, BinaryDelayEstimator* binary2, int near_offset, int lookahead_offset, int far_offset); - void RunBinarySpectraTest(int near_offset, int lookahead_offset); + void RunBinarySpectraTest(int near_offset, int lookahead_offset, + int ref_robust_validation, int robust_validation); void* handle_; DelayEstimator* self_; @@ -143,6 +147,8 @@ void DelayEstimatorTest::RunBinarySpectra(BinaryDelayEstimator* binary1, int near_offset, int lookahead_offset, int far_offset) { + int different_validations = binary1->robust_validation_enabled ^ + binary2->robust_validation_enabled; WebRtc_InitBinaryDelayEstimatorFarend(binary_farend_); WebRtc_InitBinaryDelayEstimator(binary1); WebRtc_InitBinaryDelayEstimator(binary2); @@ -167,8 +173,19 @@ void DelayEstimatorTest::RunBinarySpectra(BinaryDelayEstimator* binary1, if ((delay_1 != -2) && (delay_2 != -2)) { EXPECT_EQ(delay_1, delay_2 - lookahead_offset - near_offset); } + // For the case of identical signals |delay_1| and |delay_2| should match + // all the time, unless one of them has robust validation turned on. In + // that case the robust validation leaves the initial state faster. if ((near_offset == 0) && (lookahead_offset == 0)) { - EXPECT_EQ(delay_1, delay_2); + if (!different_validations) { + EXPECT_EQ(delay_1, delay_2); + } else { + if (binary1->robust_validation_enabled) { + EXPECT_GE(delay_1, delay_2); + } else { + EXPECT_GE(delay_2, delay_1); + } + } } } // Verify that we have left the initialized state. @@ -179,7 +196,9 @@ void DelayEstimatorTest::RunBinarySpectra(BinaryDelayEstimator* binary1, } void DelayEstimatorTest::RunBinarySpectraTest(int near_offset, - int lookahead_offset) { + int lookahead_offset, + int ref_robust_validation, + int robust_validation) { BinaryDelayEstimator* binary2 = WebRtc_CreateBinaryDelayEstimator(binary_farend_, kLookahead + lookahead_offset); @@ -187,6 +206,8 @@ void DelayEstimatorTest::RunBinarySpectraTest(int near_offset, // the delay is equivalent with a positive |offset| of the far-end sequence. // For non-causal systems the delay is equivalent with a negative |offset| of // the far-end sequence. + binary_->robust_validation_enabled = ref_robust_validation; + binary2->robust_validation_enabled = robust_validation; for (int offset = -kLookahead; offset < kMaxDelay - lookahead_offset - near_offset; offset++) { @@ -194,6 +215,7 @@ void DelayEstimatorTest::RunBinarySpectraTest(int near_offset, } WebRtc_FreeBinaryDelayEstimator(binary2); binary2 = NULL; + binary_->robust_validation_enabled = 0; // Reset reference. } TEST_F(DelayEstimatorTest, CorrectErrorReturnsOfWrapper) { @@ -257,7 +279,7 @@ TEST_F(DelayEstimatorTest, CorrectErrorReturnsOfWrapper) { // WebRtc_enable_robust_validation() should return -1 if we have: // 1) NULL pointer as |handle|. // 2) Incorrect |enable| value (not 0 or 1). - EXPECT_EQ(-1, WebRtc_enable_robust_validation(NULL, 0)); + EXPECT_EQ(-1, WebRtc_enable_robust_validation(NULL, kEnable[0])); EXPECT_EQ(-1, WebRtc_enable_robust_validation(handle_, -1)); EXPECT_EQ(-1, WebRtc_enable_robust_validation(handle_, 2)); @@ -317,12 +339,12 @@ TEST_F(DelayEstimatorTest, VerifyAllowedOffset) { TEST_F(DelayEstimatorTest, VerifyEnableRobustValidation) { // Disabled by default. EXPECT_EQ(0, WebRtc_is_robust_validation_enabled(handle_)); - for (int i = 1; i >= 0; i--) { - EXPECT_EQ(0, WebRtc_enable_robust_validation(handle_, i)); - EXPECT_EQ(i, WebRtc_is_robust_validation_enabled(handle_)); + for (size_t i = 0; i < kSizeEnable; ++i) { + EXPECT_EQ(0, WebRtc_enable_robust_validation(handle_, kEnable[i])); + EXPECT_EQ(kEnable[i], WebRtc_is_robust_validation_enabled(handle_)); Init(); // Unaffected over a reset. - EXPECT_EQ(i, WebRtc_is_robust_validation_enabled(handle_)); + EXPECT_EQ(kEnable[i], WebRtc_is_robust_validation_enabled(handle_)); } } @@ -450,26 +472,57 @@ TEST_F(DelayEstimatorTest, ExactDelayEstimateMultipleNearSameSpectrum) { // the signal accordingly. We create two Binary Delay Estimators and feed them // with the same signals, so they should output the same results. // We verify both causal and non-causal delays. + // For these noise free signals, the robust validation should not have an + // impact, hence we turn robust validation on/off for both reference and + // delayed near end. - RunBinarySpectraTest(0, 0); + for (size_t i = 0; i < kSizeEnable; ++i) { + for (size_t j = 0; j < kSizeEnable; ++j) { + RunBinarySpectraTest(0, 0, kEnable[i], kEnable[j]); + } + } } TEST_F(DelayEstimatorTest, ExactDelayEstimateMultipleNearDifferentSpectrum) { // In this test we use the same setup as above, but we now feed the two Binary // Delay Estimators with different signals, so they should output different // results. + // For these noise free signals, the robust validation should not have an + // impact, hence we turn robust validation on/off for both reference and + // delayed near end. const int kNearOffset = 1; - RunBinarySpectraTest(kNearOffset, 0); + for (size_t i = 0; i < kSizeEnable; ++i) { + for (size_t j = 0; j < kSizeEnable; ++j) { + RunBinarySpectraTest(kNearOffset, 0, kEnable[i], kEnable[j]); + } + } } TEST_F(DelayEstimatorTest, ExactDelayEstimateMultipleNearDifferentLookahead) { // In this test we use the same setup as above, feeding the two Binary // Delay Estimators with the same signals. The difference is that we create // them with different lookahead. + // For these noise free signals, the robust validation should not have an + // impact, hence we turn robust validation on/off for both reference and + // delayed near end. const int kLookaheadOffset = 1; - RunBinarySpectraTest(0, kLookaheadOffset); + for (size_t i = 0; i < kSizeEnable; ++i) { + for (size_t j = 0; j < kSizeEnable; ++j) { + RunBinarySpectraTest(0, kLookaheadOffset, kEnable[i], kEnable[j]); + } + } +} + +TEST_F(DelayEstimatorTest, AllowedOffsetNoImpactWhenRobustValidationDisabled) { + // The same setup as in ExactDelayEstimateMultipleNearSameSpectrum with the + // difference that |allowed_offset| is set for the reference binary delay + // estimator. + + binary_->allowed_offset = 10; + RunBinarySpectraTest(0, 0, 0, 0); + binary_->allowed_offset = 0; // Reset reference. } } // namespace diff --git a/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c b/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c index e48dc98721..1e6eff0835 100644 --- a/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c +++ b/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c @@ -323,7 +323,7 @@ int WebRtc_set_allowed_offset(void* handle, int allowed_offset) { } int WebRtc_get_allowed_offset(const void* handle) { - DelayEstimator* self = (DelayEstimator*) handle; + const DelayEstimator* self = (const DelayEstimator*) handle; if (self == NULL) { return -1; @@ -345,7 +345,7 @@ int WebRtc_enable_robust_validation(void* handle, int enable) { } int WebRtc_is_robust_validation_enabled(const void* handle) { - DelayEstimator* self = (DelayEstimator*) handle; + const DelayEstimator* self = (const DelayEstimator*) handle; if (self == NULL) { return -1;