| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 11 matching lines...) Expand all Loading... |
| 22 * compute cross correlation between sequences | 22 * compute cross correlation between sequences |
| 23 *---------------------------------------------------------------*/ | 23 *---------------------------------------------------------------*/ |
| 24 | 24 |
| 25 void WebRtcIlbcfix_MyCorr( | 25 void WebRtcIlbcfix_MyCorr( |
| 26 int32_t* corr, /* (o) correlation of seq1 and seq2 */ | 26 int32_t* corr, /* (o) correlation of seq1 and seq2 */ |
| 27 const int16_t* seq1, /* (i) first sequence */ | 27 const int16_t* seq1, /* (i) first sequence */ |
| 28 size_t dim1, /* (i) dimension first seq1 */ | 28 size_t dim1, /* (i) dimension first seq1 */ |
| 29 const int16_t* seq2, /* (i) second sequence */ | 29 const int16_t* seq2, /* (i) second sequence */ |
| 30 size_t dim2 /* (i) dimension seq2 */ | 30 size_t dim2 /* (i) dimension seq2 */ |
| 31 ){ | 31 ){ |
| 32 int16_t max; | 32 uint32_t max1, max2; |
| 33 size_t loops; | 33 size_t loops; |
| 34 int scale; | 34 int right_shift; |
| 35 | 35 |
| 36 /* Calculate correlation between the two sequences. Scale the | 36 // Calculate a right shift that will let us sum dim2 pairwise products of |
| 37 result of the multiplcication to maximum 26 bits in order | 37 // values from the two sequences without overflowing an int32_t. (The +1 in |
| 38 to avoid overflow */ | 38 // max1 and max2 are because WebRtcSpl_MaxAbsValueW16 will return 2**15 - 1 |
| 39 max=WebRtcSpl_MaxAbsValueW16(seq1, dim1); | 39 // if the input array contains -2**15.) |
| 40 scale=WebRtcSpl_GetSizeInBits(max); | 40 max1 = WebRtcSpl_MaxAbsValueW16(seq1, dim1) + 1; |
| 41 | 41 max2 = WebRtcSpl_MaxAbsValueW16(seq2, dim2) + 1; |
| 42 scale = 2 * scale - 26; | 42 right_shift = |
| 43 if (scale<0) { | 43 (64 - 31) - WebRtcSpl_CountLeadingZeros64((max1 * max2) * (uint64_t)dim2); |
| 44 scale=0; | 44 if (right_shift < 0) { |
| 45 right_shift = 0; |
| 45 } | 46 } |
| 46 | 47 |
| 47 loops=dim1-dim2+1; | 48 loops=dim1-dim2+1; |
| 48 | 49 |
| 49 /* Calculate the cross correlations */ | 50 /* Calculate the cross correlations */ |
| 50 WebRtcSpl_CrossCorrelation(corr, seq2, seq1, dim2, loops, scale, 1); | 51 WebRtcSpl_CrossCorrelation(corr, seq2, seq1, dim2, loops, right_shift, 1); |
| 51 | 52 |
| 52 return; | 53 return; |
| 53 } | 54 } |
| OLD | NEW |