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