From 7126b38d8fe007869057c782d9c3e7be4706d2b9 Mon Sep 17 00:00:00 2001 From: "turaj@webrtc.org" Date: Wed, 31 Jul 2013 16:05:09 +0000 Subject: [PATCH] Handel zero correlation if at the same time distortion is also zero. This is the conversation I had with Henrik Lundin regarding this problem. Me: In Expand::AnalyseSignal() we compute correlation and distortion, then calculate the ratio of correlation to distortion. There if distortion is zero we expect that correlation to be zero. Although in practice this might be true, I suppose we rarely hit into absolutely periodic signal, but in one of the tests the assertion in line 455 of expand.cc was triggered. The distortion is computed over a shorter length of the signal, while correlation is computed over longer segments. Therefore, I guess, if the signal has just enough zeros at the beginning we can end up in situation that distortion is zero but not the correlation. Do you agree? I didn't have time to attempt to solve this, but if my line of thought is correct, we should not have that assert. Perhaps, if correlation is zero we set the ratio to 0, otherwise, ratio would be the largest value of its own type. Any thoughts? Henrik: I agree with you. Go ahead with your solution. R=minyue@google.com Review URL: https://webrtc-codereview.appspot.com/1888006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4448 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/audio_coding/neteq4/expand.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/webrtc/modules/audio_coding/neteq4/expand.cc b/webrtc/modules/audio_coding/neteq4/expand.cc index 6ea3203c0..1e196c9d1 100644 --- a/webrtc/modules/audio_coding/neteq4/expand.cc +++ b/webrtc/modules/audio_coding/neteq4/expand.cc @@ -14,6 +14,7 @@ #include // min, max #include // memset +#include // numeric_limits #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" #include "webrtc/modules/audio_coding/neteq4/background_noise.h" @@ -451,9 +452,10 @@ void Expand::AnalyzeSignal(int16_t* random_vector) { int32_t ratio; if (best_distortion[i] > 0) { ratio = (best_correlation[i] << 16) / best_distortion[i]; + } else if (best_correlation[i] == 0) { + ratio = 0; // No correlation set result to zero. } else { - assert(best_correlation[i] == 0); // If one is zero, both must be. - ratio = 0; // Divide zero by zero => set result to zero. + ratio = std::numeric_limits::max(); // Denominator is zero. } if (ratio > best_ratio) { best_index = i;