1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 /******************************************************************
12
13 iLBC Speech Coder ANSI-C Source Code
14
15 WebRtcIlbcfix_MyCorr.c
16
17 ******************************************************************/
18
19 #include "modules/audio_coding/codecs/ilbc/my_corr.h"
20
21 #include "modules/audio_coding/codecs/ilbc/defines.h"
22
23 /*----------------------------------------------------------------*
24 * compute cross correlation between sequences
25 *---------------------------------------------------------------*/
26
WebRtcIlbcfix_MyCorr(int32_t * corr,const int16_t * seq1,size_t dim1,const int16_t * seq2,size_t dim2)27 void WebRtcIlbcfix_MyCorr(
28 int32_t* corr, /* (o) correlation of seq1 and seq2 */
29 const int16_t* seq1, /* (i) first sequence */
30 size_t dim1, /* (i) dimension first seq1 */
31 const int16_t* seq2, /* (i) second sequence */
32 size_t dim2 /* (i) dimension seq2 */
33 ){
34 uint32_t max1, max2;
35 size_t loops;
36 int right_shift;
37
38 // Calculate a right shift that will let us sum dim2 pairwise products of
39 // values from the two sequences without overflowing an int32_t. (The +1 in
40 // max1 and max2 are because WebRtcSpl_MaxAbsValueW16 will return 2**15 - 1
41 // if the input array contains -2**15.)
42 max1 = WebRtcSpl_MaxAbsValueW16(seq1, dim1) + 1;
43 max2 = WebRtcSpl_MaxAbsValueW16(seq2, dim2) + 1;
44 right_shift =
45 (64 - 31) - WebRtcSpl_CountLeadingZeros64((max1 * max2) * (uint64_t)dim2);
46 if (right_shift < 0) {
47 right_shift = 0;
48 }
49
50 loops=dim1-dim2+1;
51
52 /* Calculate the cross correlations */
53 WebRtcSpl_CrossCorrelation(corr, seq2, seq1, dim2, loops, right_shift, 1);
54
55 return;
56 }
57