xref: /aosp_15_r20/external/webrtc/modules/audio_coding/codecs/ilbc/augmented_cb_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_AugmentedCbCorr.c
16 
17 ******************************************************************/
18 
19 #include "modules/audio_coding/codecs/ilbc/augmented_cb_corr.h"
20 
21 #include "modules/audio_coding/codecs/ilbc/constants.h"
22 #include "modules/audio_coding/codecs/ilbc/defines.h"
23 
WebRtcIlbcfix_AugmentedCbCorr(int16_t * target,int16_t * buffer,int16_t * interpSamples,int32_t * crossDot,size_t low,size_t high,int scale)24 void WebRtcIlbcfix_AugmentedCbCorr(
25     int16_t *target,   /* (i) Target vector */
26     int16_t *buffer,   /* (i) Memory buffer */
27     int16_t *interpSamples, /* (i) buffer with
28                                      interpolated samples */
29     int32_t *crossDot,  /* (o) The cross correlation between
30                                  the target and the Augmented
31                                  vector */
32     size_t low,    /* (i) Lag to start from (typically
33                              20) */
34     size_t high,   /* (i) Lag to end at (typically 39) */
35     int scale)   /* (i) Scale factor to use for
36                               the crossDot */
37 {
38   size_t lagcount;
39   size_t ilow;
40   int16_t *targetPtr;
41   int32_t *crossDotPtr;
42   int16_t *iSPtr=interpSamples;
43 
44   /* Calculate the correlation between the target and the
45      interpolated codebook. The correlation is calculated in
46      3 sections with the interpolated part in the middle */
47   crossDotPtr=crossDot;
48   for (lagcount=low; lagcount<=high; lagcount++) {
49 
50     ilow = lagcount - 4;
51 
52     /* Compute dot product for the first (lagcount-4) samples */
53     (*crossDotPtr) = WebRtcSpl_DotProductWithScale(target, buffer-lagcount, ilow, scale);
54 
55     /* Compute dot product on the interpolated samples */
56     (*crossDotPtr) += WebRtcSpl_DotProductWithScale(target+ilow, iSPtr, 4, scale);
57     targetPtr = target + lagcount;
58     iSPtr += lagcount-ilow;
59 
60     /* Compute dot product for the remaining samples */
61     (*crossDotPtr) += WebRtcSpl_DotProductWithScale(targetPtr, buffer-lagcount, SUBL-lagcount, scale);
62     crossDotPtr++;
63   }
64 }
65