xref: /aosp_15_r20/external/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy_augmentation.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_CbMemEnergyAugmentation.c
16 
17 ******************************************************************/
18 
19 #include "modules/audio_coding/codecs/ilbc/cb_mem_energy_augmentation.h"
20 
21 #include "modules/audio_coding/codecs/ilbc/constants.h"
22 #include "modules/audio_coding/codecs/ilbc/defines.h"
23 
WebRtcIlbcfix_CbMemEnergyAugmentation(int16_t * interpSamples,int16_t * CBmem,int scale,size_t base_size,int16_t * energyW16,int16_t * energyShifts)24 void WebRtcIlbcfix_CbMemEnergyAugmentation(
25     int16_t *interpSamples, /* (i) The interpolated samples */
26     int16_t *CBmem,   /* (i) The CB memory */
27     int scale,   /* (i) The scaling of all energy values */
28     size_t base_size,  /* (i) Index to where energy values should be stored */
29     int16_t *energyW16,  /* (o) Energy in the CB vectors */
30     int16_t *energyShifts /* (o) Shift value of the energy */
31                                            ){
32   int32_t energy, tmp32;
33   int16_t *ppe, *pp, *interpSamplesPtr;
34   int16_t *CBmemPtr;
35   size_t lagcount;
36   int16_t *enPtr=&energyW16[base_size-20];
37   int16_t *enShPtr=&energyShifts[base_size-20];
38   int32_t nrjRecursive;
39 
40   CBmemPtr = CBmem+147;
41   interpSamplesPtr = interpSamples;
42 
43   /* Compute the energy for the first (low-5) noninterpolated samples */
44   nrjRecursive = WebRtcSpl_DotProductWithScale( CBmemPtr-19, CBmemPtr-19, 15, scale);
45   ppe = CBmemPtr - 20;
46 
47   for (lagcount=20; lagcount<=39; lagcount++) {
48 
49     /* Update the energy recursively to save complexity */
50     nrjRecursive += (*ppe * *ppe) >> scale;
51     ppe--;
52     energy = nrjRecursive;
53 
54     /* interpolation */
55     energy += WebRtcSpl_DotProductWithScale(interpSamplesPtr, interpSamplesPtr, 4, scale);
56     interpSamplesPtr += 4;
57 
58     /* Compute energy for the remaining samples */
59     pp = CBmemPtr - lagcount;
60     energy += WebRtcSpl_DotProductWithScale(pp, pp, SUBL-lagcount, scale);
61 
62     /* Normalize the energy and store the number of shifts */
63     (*enShPtr) = (int16_t)WebRtcSpl_NormW32(energy);
64     tmp32 = energy << *enShPtr;
65     *enPtr = (int16_t)(tmp32 >> 16);
66     enShPtr++;
67     enPtr++;
68   }
69 }
70