2
|
1
|
|
2 /******************************************************************
|
|
3
|
|
4 iLBC Speech Coder ANSI-C Source Code
|
|
5
|
|
6 getCBvec.c
|
|
7
|
|
8 Copyright (C) The Internet Society (2004).
|
|
9 All Rights Reserved.
|
|
10
|
|
11 ******************************************************************/
|
|
12
|
|
13 #include "iLBC_define.h"
|
|
14 #include "constants.h"
|
|
15 #include <string.h>
|
|
16
|
|
17 /*----------------------------------------------------------------*
|
|
18 * Construct codebook vector for given index.
|
|
19 *---------------------------------------------------------------*/
|
|
20
|
|
21 void getCBvec(float *cbvec, /* (o) Constructed codebook vector */
|
|
22 float *mem, /* (i) Codebook buffer */
|
|
23 int index, /* (i) Codebook index */
|
|
24 int lMem, /* (i) Length of codebook buffer */
|
|
25 int cbveclen /* (i) Codebook vector length */
|
|
26 )
|
|
27 {
|
|
28 int j, k, n, memInd, sFilt;
|
|
29 float tmpbuf[CB_MEML];
|
|
30 int base_size;
|
|
31 int ilow, ihigh;
|
|
32 float alfa, alfa1;
|
|
33
|
|
34 /* Determine size of codebook sections */
|
|
35
|
|
36 base_size = lMem - cbveclen + 1;
|
|
37
|
|
38 if (cbveclen == SUBL) {
|
|
39 base_size += cbveclen / 2;
|
|
40 }
|
|
41
|
|
42 /* No filter -> First codebook section */
|
|
43
|
|
44 if (index < lMem - cbveclen + 1) {
|
|
45
|
|
46 /* first non-interpolated vectors */
|
|
47
|
|
48 k = index + cbveclen;
|
|
49 /* get vector */
|
|
50 memcpy(cbvec, mem + lMem - k, cbveclen * sizeof(float));
|
|
51
|
|
52 } else if (index < base_size) {
|
|
53
|
|
54 k = 2 * (index - (lMem - cbveclen + 1)) + cbveclen;
|
|
55
|
|
56 ihigh = k / 2;
|
|
57 ilow = ihigh - 5;
|
|
58
|
|
59 /* Copy first noninterpolated part */
|
|
60
|
|
61 memcpy(cbvec, mem + lMem - k / 2, ilow * sizeof(float));
|
|
62
|
|
63 /* interpolation */
|
|
64
|
|
65 alfa1 = (float) 0.2;
|
|
66 alfa = 0.0;
|
|
67 for (j = ilow; j < ihigh; j++) {
|
|
68 cbvec[j] = ((float) 1.0 - alfa) * mem[lMem - k / 2 + j] +
|
|
69 alfa * mem[lMem - k + j];
|
|
70
|
|
71
|
|
72
|
|
73
|
|
74
|
|
75 alfa += alfa1;
|
|
76 }
|
|
77
|
|
78 /* Copy second noninterpolated part */
|
|
79
|
|
80 memcpy(cbvec + ihigh, mem + lMem - k + ihigh,
|
|
81 (cbveclen - ihigh) * sizeof(float));
|
|
82
|
|
83 }
|
|
84
|
|
85 /* Higher codebook section based on filtering */
|
|
86
|
|
87 else {
|
|
88
|
|
89 /* first non-interpolated vectors */
|
|
90
|
|
91 if (index - base_size < lMem - cbveclen + 1) {
|
|
92 float tempbuff2[CB_MEML + CB_FILTERLEN + 1];
|
|
93 float *pos;
|
|
94 float *pp, *pp1;
|
|
95
|
|
96 memset(tempbuff2, 0, CB_HALFFILTERLEN * sizeof(float));
|
|
97 memcpy(&tempbuff2[CB_HALFFILTERLEN], mem, lMem * sizeof(float));
|
|
98 memset(&tempbuff2[lMem + CB_HALFFILTERLEN], 0,
|
|
99 (CB_HALFFILTERLEN + 1) * sizeof(float));
|
|
100
|
|
101 k = index - base_size + cbveclen;
|
|
102 sFilt = lMem - k;
|
|
103 memInd = sFilt + 1 - CB_HALFFILTERLEN;
|
|
104
|
|
105 /* do filtering */
|
|
106 pos = cbvec;
|
|
107 memset(pos, 0, cbveclen * sizeof(float));
|
|
108 for (n = 0; n < cbveclen; n++) {
|
|
109 pp = &tempbuff2[memInd + n + CB_HALFFILTERLEN];
|
|
110 pp1 = &cbfiltersTbl[CB_FILTERLEN - 1];
|
|
111 for (j = 0; j < CB_FILTERLEN; j++) {
|
|
112 (*pos) += (*pp++) * (*pp1--);
|
|
113 }
|
|
114 pos++;
|
|
115 }
|
|
116 }
|
|
117
|
|
118 /* interpolated vectors */
|
|
119
|
|
120 else {
|
|
121
|
|
122
|
|
123
|
|
124
|
|
125
|
|
126 float tempbuff2[CB_MEML + CB_FILTERLEN + 1];
|
|
127
|
|
128 float *pos;
|
|
129 float *pp, *pp1;
|
|
130 int i;
|
|
131
|
|
132 memset(tempbuff2, 0, CB_HALFFILTERLEN * sizeof(float));
|
|
133 memcpy(&tempbuff2[CB_HALFFILTERLEN], mem, lMem * sizeof(float));
|
|
134 memset(&tempbuff2[lMem + CB_HALFFILTERLEN], 0,
|
|
135 (CB_HALFFILTERLEN + 1) * sizeof(float));
|
|
136
|
|
137 k = 2 * (index - base_size - (lMem - cbveclen + 1)) + cbveclen;
|
|
138 sFilt = lMem - k;
|
|
139 memInd = sFilt + 1 - CB_HALFFILTERLEN;
|
|
140
|
|
141 /* do filtering */
|
|
142 pos = &tmpbuf[sFilt];
|
|
143 memset(pos, 0, k * sizeof(float));
|
|
144 for (i = 0; i < k; i++) {
|
|
145 pp = &tempbuff2[memInd + i + CB_HALFFILTERLEN];
|
|
146 pp1 = &cbfiltersTbl[CB_FILTERLEN - 1];
|
|
147 for (j = 0; j < CB_FILTERLEN; j++) {
|
|
148 (*pos) += (*pp++) * (*pp1--);
|
|
149 }
|
|
150 pos++;
|
|
151 }
|
|
152
|
|
153 ihigh = k / 2;
|
|
154 ilow = ihigh - 5;
|
|
155
|
|
156 /* Copy first noninterpolated part */
|
|
157
|
|
158 memcpy(cbvec, tmpbuf + lMem - k / 2, ilow * sizeof(float));
|
|
159
|
|
160 /* interpolation */
|
|
161
|
|
162 alfa1 = (float) 0.2;
|
|
163 alfa = 0.0;
|
|
164 for (j = ilow; j < ihigh; j++) {
|
|
165 cbvec[j] = ((float) 1.0 - alfa) *
|
|
166 tmpbuf[lMem - k / 2 + j] + alfa * tmpbuf[lMem - k + j];
|
|
167 alfa += alfa1;
|
|
168 }
|
|
169
|
|
170
|
|
171
|
|
172
|
|
173
|
|
174
|
|
175 /* Copy second noninterpolated part */
|
|
176
|
|
177 memcpy(cbvec + ihigh, tmpbuf + lMem - k + ihigh,
|
|
178 (cbveclen - ihigh) * sizeof(float));
|
|
179 }
|
|
180 }
|
|
181 }
|