Index: webrtc/modules/audio_coding/neteq/time_stretch.cc |
diff --git a/webrtc/modules/audio_coding/neteq/time_stretch.cc b/webrtc/modules/audio_coding/neteq/time_stretch.cc |
index 880b1f82ea595271ee0f92795f8a39542e5039f4..6a91ea487b59fe076a951c0621996450e145a8cf 100644 |
--- a/webrtc/modules/audio_coding/neteq/time_stretch.cc |
+++ b/webrtc/modules/audio_coding/neteq/time_stretch.cc |
@@ -16,7 +16,6 @@ |
#include "webrtc/base/safe_conversions.h" |
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" |
#include "webrtc/modules/audio_coding/neteq/background_noise.h" |
-#include "webrtc/modules/audio_coding/neteq/cross_correlation.h" |
#include "webrtc/modules/audio_coding/neteq/dsp_helper.h" |
namespace webrtc { |
@@ -159,15 +158,20 @@ |
} |
void TimeStretch::AutoCorrelation() { |
+ // Set scaling factor for cross correlation to protect against overflow. |
+ int scaling = kLogCorrelationLen - WebRtcSpl_NormW32( |
+ max_input_value_ * max_input_value_); |
+ scaling = std::max(0, scaling); |
+ |
// Calculate correlation from lag kMinLag to lag kMaxLag in 4 kHz domain. |
int32_t auto_corr[kCorrelationLen]; |
- CrossCorrelationWithAutoShift( |
- &downsampled_input_[kMaxLag], &downsampled_input_[kMaxLag - kMinLag], |
- kCorrelationLen, kMaxLag - kMinLag, -1, auto_corr); |
+ WebRtcSpl_CrossCorrelation(auto_corr, &downsampled_input_[kMaxLag], |
+ &downsampled_input_[kMaxLag - kMinLag], |
+ kCorrelationLen, kMaxLag - kMinLag, scaling, -1); |
// Normalize correlation to 14 bits and write to |auto_correlation_|. |
int32_t max_corr = WebRtcSpl_MaxAbsValueW32(auto_corr, kCorrelationLen); |
- int scaling = std::max(0, 17 - WebRtcSpl_NormW32(max_corr)); |
+ scaling = std::max(0, 17 - WebRtcSpl_NormW32(max_corr)); |
WebRtcSpl_VectorBitShiftW32ToW16(auto_correlation_, kCorrelationLen, |
auto_corr, scaling); |
} |