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_CbConstruct.c
17 ******************************************************************/
20 #include "gain_dequant.h"
21 #include "get_cd_vec.h"
23 /*----------------------------------------------------------------*
24 * Construct decoded vector from codebook and gains.
25 *---------------------------------------------------------------*/
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 */
36 int16_t gain[CB_NSTAGES];
44 /* gain de-quantization */
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);
50 /* codebook vector construction and construction of total vector */
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);
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]);
63 decvector[j] = (int16_t)((a32 + 8192) >> 14);