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_CompCorr.c
16
17 ******************************************************************/
18
19 #include "defines.h"
20
21 /*----------------------------------------------------------------*
22 * Compute cross correlation and pitch gain for pitch prediction
23 * of last subframe at given lag.
24 *---------------------------------------------------------------*/
25
WebRtcIlbcfix_CompCorr(int32_t * corr,int32_t * ener,int16_t * buffer,size_t lag,size_t bLen,size_t sRange,int16_t scale)26 void WebRtcIlbcfix_CompCorr(
27 int32_t *corr, /* (o) cross correlation */
28 int32_t *ener, /* (o) energy */
29 int16_t *buffer, /* (i) signal buffer */
30 size_t lag, /* (i) pitch lag */
31 size_t bLen, /* (i) length of buffer */
32 size_t sRange, /* (i) correlation search length */
33 int16_t scale /* (i) number of rightshifts to use */
34 ){
35 int16_t *w16ptr;
36
37 w16ptr=&buffer[bLen-sRange-lag];
38
39 /* Calculate correlation and energy */
40 (*corr)=WebRtcSpl_DotProductWithScale(&buffer[bLen-sRange], w16ptr, sRange, scale);
41 (*ener)=WebRtcSpl_DotProductWithScale(w16ptr, w16ptr, sRange, scale);
42
43 /* For zero energy set the energy to 0 in order to avoid potential
44 problems for coming divisions */
45 if (*ener == 0) {
46 *corr = 0;
47 *ener = 1;
48 }
49 }
50