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