2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
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.
11 /******************************************************************
13 iLBC Speech Coder ANSI-C Source Code
15 WebRtcIlbcfix_CbMemEnergyCalc.c
17 ******************************************************************/
21 /* Compute the energy of the rest of the cb memory
22 * by step wise adding and subtracting the next
23 * sample and the last sample respectively */
24 void WebRtcIlbcfix_CbMemEnergyCalc(
25 int32_t energy, /* (i) input start energy */
26 int16_t range, /* (i) number of iterations */
27 int16_t *ppi, /* (i) input pointer 1 */
28 int16_t *ppo, /* (i) input pointer 2 */
29 int16_t *energyW16, /* (o) Energy in the CB vectors */
30 int16_t *energyShifts, /* (o) Shift value of the energy */
31 int16_t scale, /* (i) The scaling of all energy values */
32 int16_t base_size /* (i) Index to where the energy values should be stored */
41 eSh_ptr = &energyShifts[1+base_size];
42 eW16_ptr = &energyW16[1+base_size];
44 for(j=0;j<range-1;j++) {
46 /* Calculate next energy by a +/-
47 operation on the edge samples */
48 tmp = WEBRTC_SPL_MUL_16_16(*ppi, *ppi);
49 tmp -= WEBRTC_SPL_MUL_16_16(*ppo, *ppo);
50 energy += tmp >> scale;
51 energy = WEBRTC_SPL_MAX(energy, 0);
56 /* Normalize the energy into a int16_t and store
57 the number of shifts */
59 shft = (int16_t)WebRtcSpl_NormW32(energy);
62 tmp = WEBRTC_SPL_LSHIFT_W32(energy, shft);
63 *eW16_ptr++ = (int16_t)(tmp >> 16);