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_CbMemEnergyCalc.c
16
17 ******************************************************************/
18
19 #include "modules/audio_coding/codecs/ilbc/cb_mem_energy_calc.h"
20
21 #include "modules/audio_coding/codecs/ilbc/defines.h"
22
23 /* Compute the energy of the rest of the cb memory
24 * by step wise adding and subtracting the next
25 * sample and the last sample respectively */
WebRtcIlbcfix_CbMemEnergyCalc(int32_t energy,size_t range,int16_t * ppi,int16_t * ppo,int16_t * energyW16,int16_t * energyShifts,int scale,size_t base_size)26 void WebRtcIlbcfix_CbMemEnergyCalc(
27 int32_t energy, /* (i) input start energy */
28 size_t range, /* (i) number of iterations */
29 int16_t *ppi, /* (i) input pointer 1 */
30 int16_t *ppo, /* (i) input pointer 2 */
31 int16_t *energyW16, /* (o) Energy in the CB vectors */
32 int16_t *energyShifts, /* (o) Shift value of the energy */
33 int scale, /* (i) The scaling of all energy values */
34 size_t base_size /* (i) Index to where energy values should be stored */
35 )
36 {
37 size_t j;
38 int16_t shft;
39 int32_t tmp;
40 int16_t *eSh_ptr;
41 int16_t *eW16_ptr;
42
43
44 eSh_ptr = &energyShifts[1+base_size];
45 eW16_ptr = &energyW16[1+base_size];
46
47 for (j = 0; j + 1 < range; j++) {
48
49 /* Calculate next energy by a +/-
50 operation on the edge samples */
51 tmp = (*ppi) * (*ppi) - (*ppo) * (*ppo);
52 energy += tmp >> scale;
53 energy = WEBRTC_SPL_MAX(energy, 0);
54
55 ppi--;
56 ppo--;
57
58 /* Normalize the energy into a int16_t and store
59 the number of shifts */
60
61 shft = (int16_t)WebRtcSpl_NormW32(energy);
62 *eSh_ptr++ = shft;
63
64 tmp = energy << shft;
65 *eW16_ptr++ = (int16_t)(tmp >> 16);
66 }
67 }
68