blob: e2ae361ee37a728ad77c0cbd92b7b455e693d3d0 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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
Mirko Bonadei06c2aa92018-02-01 15:11:41 +010019#include "modules/audio_coding/codecs/ilbc/cb_construct.h"
kwiberg619a2112016-08-24 02:46:44 -070020
Mirko Bonadei06c2aa92018-02-01 15:11:41 +010021#include "modules/audio_coding/codecs/ilbc/defines.h"
22#include "modules/audio_coding/codecs/ilbc/gain_dequant.h"
23#include "modules/audio_coding/codecs/ilbc/get_cd_vec.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024
25/*----------------------------------------------------------------*
26 * Construct decoded vector from codebook and gains.
27 *---------------------------------------------------------------*/
28
kwiberg619a2112016-08-24 02:46:44 -070029bool WebRtcIlbcfix_CbConstruct(
kwibergc31446f2016-08-30 05:36:56 -070030 int16_t* decvector, /* (o) Decoded vector */
31 const int16_t* index, /* (i) Codebook indices */
32 const int16_t* gain_index, /* (i) Gain quantization indices */
33 int16_t* mem, /* (i) Buffer for codevector construction */
34 size_t lMem, /* (i) Length of buffer */
35 size_t veclen) { /* (i) Length of vector */
Peter Kastingdce40cf2015-08-24 14:52:23 -070036 size_t j;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000037 int16_t gain[CB_NSTAGES];
niklase@google.com470e71d2011-07-07 08:21:25 +000038 /* Stack based */
pbos@webrtc.org0946a562013-04-09 00:28:06 +000039 int16_t cbvec0[SUBL];
40 int16_t cbvec1[SUBL];
41 int16_t cbvec2[SUBL];
42 int32_t a32;
43 int16_t *gainPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +000044
45 /* gain de-quantization */
46
47 gain[0] = WebRtcIlbcfix_GainDequant(gain_index[0], 16384, 0);
48 gain[1] = WebRtcIlbcfix_GainDequant(gain_index[1], gain[0], 1);
49 gain[2] = WebRtcIlbcfix_GainDequant(gain_index[2], gain[1], 2);
50
51 /* codebook vector construction and construction of total vector */
52
53 /* Stack based */
kwiberg619a2112016-08-24 02:46:44 -070054 if (!WebRtcIlbcfix_GetCbVec(cbvec0, mem, (size_t)index[0], lMem, veclen))
55 return false; // Failure.
56 if (!WebRtcIlbcfix_GetCbVec(cbvec1, mem, (size_t)index[1], lMem, veclen))
57 return false; // Failure.
58 if (!WebRtcIlbcfix_GetCbVec(cbvec2, mem, (size_t)index[2], lMem, veclen))
59 return false; // Failure.
niklase@google.com470e71d2011-07-07 08:21:25 +000060
61 gainPtr = &gain[0];
62 for (j=0;j<veclen;j++) {
bjornv@webrtc.orgba97ea62015-02-13 09:51:40 +000063 a32 = (*gainPtr++) * cbvec0[j];
64 a32 += (*gainPtr++) * cbvec1[j];
65 a32 += (*gainPtr) * cbvec2[j];
niklase@google.com470e71d2011-07-07 08:21:25 +000066 gainPtr -= 2;
bjornv@webrtc.org78ea06d2014-10-21 07:17:24 +000067 decvector[j] = (int16_t)((a32 + 8192) >> 14);
niklase@google.com470e71d2011-07-07 08:21:25 +000068 }
69
kwiberg619a2112016-08-24 02:46:44 -070070 return true; // Success.
niklase@google.com470e71d2011-07-07 08:21:25 +000071}