From 04ecd49ec5cdf664b78578e96b8f57bd6643eec8 Mon Sep 17 00:00:00 2001 From: "bjornv@webrtc.org" Date: Mon, 18 Mar 2013 14:15:12 +0000 Subject: [PATCH] Truncated delay quality to avoid negative return values This forces the output of last_delay_quality to the interval [0, 1] in Q14. BUG=none TESTED=audioproc_unittest, trybot Review URL: https://webrtc-codereview.appspot.com/1211004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3675 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../modules/audio_processing/utility/delay_estimator.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/webrtc/modules/audio_processing/utility/delay_estimator.c b/webrtc/modules/audio_processing/utility/delay_estimator.c index bcbb00aa8d..91c1e9b40f 100644 --- a/webrtc/modules/audio_processing/utility/delay_estimator.c +++ b/webrtc/modules/audio_processing/utility/delay_estimator.c @@ -302,6 +302,7 @@ int WebRtc_binary_last_delay(BinaryDelayEstimator* self) { } int WebRtc_binary_last_delay_quality(BinaryDelayEstimator* self) { + int delay_quality = 0; assert(self != NULL); // |last_delay_probability| is the opposite of quality and states how deep the // minimum of the cost function is. The value states how many non-matching @@ -309,8 +310,12 @@ int WebRtc_binary_last_delay_quality(BinaryDelayEstimator* self) { // estimate. The range is thus from 0 to 32, since we use 32 bits in the // binary spectra. - // Return the quality = 1 - |last_delay_probability| / 32 (in Q14). - return (32 << 9) - self->last_delay_probability; + // Return the |delay_quality| = 1 - |last_delay_probability| / 32 (in Q14). + delay_quality = (32 << 9) - self->last_delay_probability; + if (delay_quality < 0) { + delay_quality = 0; + } + return delay_quality; } void WebRtc_MeanEstimatorFix(int32_t new_value,