comparison intercom/ilbc/iCBConstruct.c @ 2:13be24d74cd2

import intercom-0.4.1
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 09:57:52 +0200
parents
children
comparison
equal deleted inserted replaced
1:9cadc470e3da 2:13be24d74cd2
1
2 /******************************************************************
3
4 iLBC Speech Coder ANSI-C Source Code
5
6 iCBConstruct.c
7
8 Copyright (C) The Internet Society (2004).
9 All Rights Reserved.
10
11 ******************************************************************/
12
13 #include <math.h>
14
15 #include "iLBC_define.h"
16 #include "gainquant.h"
17 #include "getCBvec.h"
18
19 /*----------------------------------------------------------------*
20 * Convert the codebook indexes to make the search easier
21 *---------------------------------------------------------------*/
22
23
24
25
26
27
28 void index_conv_enc(int *index /* (i/o) Codebook indexes */
29 )
30 {
31 int k;
32
33 for (k = 1; k < CB_NSTAGES; k++) {
34
35 if ((index[k] >= 108) && (index[k] < 172)) {
36 index[k] -= 64;
37 } else if (index[k] >= 236) {
38 index[k] -= 128;
39 } else {
40 /* ERROR */
41 }
42 }
43 }
44
45 void index_conv_dec(int *index /* (i/o) Codebook indexes */
46 )
47 {
48 int k;
49
50 for (k = 1; k < CB_NSTAGES; k++) {
51
52 if ((index[k] >= 44) && (index[k] < 108)) {
53 index[k] += 64;
54 } else if ((index[k] >= 108) && (index[k] < 128)) {
55 index[k] += 128;
56 } else {
57 /* ERROR */
58 }
59 }
60 }
61
62 /*----------------------------------------------------------------*
63 * Construct decoded vector from codebook and gains.
64 *---------------------------------------------------------------*/
65
66 void iCBConstruct(float *decvector, /* (o) Decoded vector */
67 int *index, /* (i) Codebook indices */
68 int *gain_index, /* (i) Gain quantization indices */
69 float *mem, /* (i) Buffer for codevector construction */
70 int lMem, /* (i) Length of buffer */
71 int veclen, /* (i) Length of vector */
72 int nStages /* (i) Number of codebook stages */
73 )
74 {
75 int j, k;
76
77
78
79
80
81 float gain[CB_NSTAGES];
82 float cbvec[SUBL];
83
84 /* gain de-quantization */
85
86 gain[0] = gaindequant(gain_index[0], 1.0, 32);
87 if (nStages > 1) {
88 gain[1] = gaindequant(gain_index[1], (float) fabs(gain[0]), 16);
89 }
90 if (nStages > 2) {
91 gain[2] = gaindequant(gain_index[2], (float) fabs(gain[1]), 8);
92 }
93
94 /* codebook vector construction and construction of
95 total vector */
96
97 getCBvec(cbvec, mem, index[0], lMem, veclen);
98 for (j = 0; j < veclen; j++) {
99 decvector[j] = gain[0] * cbvec[j];
100 }
101 if (nStages > 1) {
102 for (k = 1; k < nStages; k++) {
103 getCBvec(cbvec, mem, index[k], lMem, veclen);
104 for (j = 0; j < veclen; j++) {
105 decvector[j] += gain[k] * cbvec[j];
106 }
107 }
108 }
109 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.