Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / audio_coding / codecs / ilbc / cb_construct.c
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_CbConstruct.c
16
17 ******************************************************************/
18
19 #include "defines.h"
20 #include "gain_dequant.h"
21 #include "get_cd_vec.h"
22
23 /*----------------------------------------------------------------*
24  *  Construct decoded vector from codebook and gains.
25  *---------------------------------------------------------------*/
26
27 void WebRtcIlbcfix_CbConstruct(
28     int16_t *decvector,  /* (o) Decoded vector */
29     int16_t *index,   /* (i) Codebook indices */
30     int16_t *gain_index,  /* (i) Gain quantization indices */
31     int16_t *mem,   /* (i) Buffer for codevector construction */
32     int16_t lMem,   /* (i) Length of buffer */
33     int16_t veclen   /* (i) Length of vector */
34                                ){
35   int j;
36   int16_t gain[CB_NSTAGES];
37   /* Stack based */
38   int16_t cbvec0[SUBL];
39   int16_t cbvec1[SUBL];
40   int16_t cbvec2[SUBL];
41   int32_t a32;
42   int16_t *gainPtr;
43
44   /* gain de-quantization */
45
46   gain[0] = WebRtcIlbcfix_GainDequant(gain_index[0], 16384, 0);
47   gain[1] = WebRtcIlbcfix_GainDequant(gain_index[1], gain[0], 1);
48   gain[2] = WebRtcIlbcfix_GainDequant(gain_index[2], gain[1], 2);
49
50   /* codebook vector construction and construction of total vector */
51
52   /* Stack based */
53   WebRtcIlbcfix_GetCbVec(cbvec0, mem, index[0], lMem, veclen);
54   WebRtcIlbcfix_GetCbVec(cbvec1, mem, index[1], lMem, veclen);
55   WebRtcIlbcfix_GetCbVec(cbvec2, mem, index[2], lMem, veclen);
56
57   gainPtr = &gain[0];
58   for (j=0;j<veclen;j++) {
59     a32  = WEBRTC_SPL_MUL_16_16(*gainPtr++, cbvec0[j]);
60     a32 += WEBRTC_SPL_MUL_16_16(*gainPtr++, cbvec1[j]);
61     a32 += WEBRTC_SPL_MUL_16_16(*gainPtr, cbvec2[j]);
62     gainPtr -= 2;
63     decvector[j] = (int16_t)((a32 + 8192) >> 14);
64   }
65
66   return;
67 }