Utilise new MergeSym feature to no longer overwrite the source .DEF file when buildin...
[openh323.git] / src / iLBC / iCBConstruct.c
blob39a2e3901e675fa4dd2d0e1218ac9a03e183cf84
3 \f
5 /******************************************************************
7 iLBC Speech Coder ANSI-C Source Code
9 iCBConstruct.c
11 Copyright (c) 2001,
12 Global IP Sound AB.
13 All rights reserved.
15 ******************************************************************/
17 #include <math.h>
19 #include "iLBC_define.h"
20 #include "gainquant.h"
21 #include "getCBvec.h"
23 /*----------------------------------------------------------------*
24 * Convert the codebook indexes to make the search easier
25 *---------------------------------------------------------------*/
27 void index_conv_enc(
28 int *index /* (i/o) Codebook indexes */
29 ){
30 int k;
32 for (k=1; k<CB_NSTAGES; k++) {
34 if ((index[k]>=108)&&(index[k]<172)) {
35 index[k]-=64;
36 } else if (index[k]>=236) {
37 index[k]-=128;
38 } else {
39 /* ERROR */
44 void index_conv_dec(
45 int *index /* (i/o) Codebook indexes */
46 ){
47 int k;
49 for (k=1; k<CB_NSTAGES; k++) {
51 if ((index[k]>=44)&&(index[k]<108)) {
52 index[k]+=64;
53 } else if ((index[k]>=108)&&(index[k]<128)) {
54 index[k]+=128;
55 } else {
56 /* ERROR */
64 /*----------------------------------------------------------------*
65 * Construct decoded vector from codebook and gains.
66 *---------------------------------------------------------------*/
68 void iCBConstruct(
69 float *decvector, /* (o) Decoded vector */
70 int *index, /* (i) Codebook indices */
71 int *gain_index,/* (i) Gain quantization indices */
72 float *mem, /* (i) Buffer for codevector construction */
73 int lMem, /* (i) Length of buffer */
74 int veclen, /* (i) Length of vector */
75 int nStages /* (i) Number of codebook stages */
76 ){
77 int j,k;
78 float gain[CB_NSTAGES];
79 float cbvec[SUBL];
81 /* gain de-quantization */
83 gain[0] = gaindequant(gain_index[0], 1.0, 32);
84 if (nStages > 1) {
85 gain[1] = gaindequant(gain_index[1],
86 (float)fabs(gain[0]), 16);
88 if (nStages > 2) {
89 gain[2] = gaindequant(gain_index[2],
90 (float)fabs(gain[1]), 8);
93 /* codebook vector construction and construction of
94 total vector */
96 getCBvec(cbvec, mem, index[0], lMem, veclen);
97 for (j=0;j<veclen;j++){
98 decvector[j] = gain[0]*cbvec[j];
100 if (nStages > 1) {
101 for (k=1; k<nStages; k++) {
102 getCBvec(cbvec, mem, index[k], lMem, veclen);
103 for (j=0;j<veclen;j++) {
104 decvector[j] += gain[k]*cbvec[j];