Mercurial > hg > audiostuff
comparison intercom/ilbc/LPCencode.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 LPCencode.c | |
7 | |
8 Copyright (C) The Internet Society (2004). | |
9 All Rights Reserved. | |
10 | |
11 ******************************************************************/ | |
12 | |
13 #include <string.h> | |
14 | |
15 #include "iLBC_define.h" | |
16 #include "helpfun.h" | |
17 #include "lsf.h" | |
18 #include "constants.h" | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 /*----------------------------------------------------------------* | |
25 * lpc analysis (subrutine to LPCencode) | |
26 *---------------------------------------------------------------*/ | |
27 | |
28 void SimpleAnalysis(float *lsf, /* (o) lsf coefficients */ | |
29 float *data, /* (i) new data vector */ | |
30 iLBC_Enc_Inst_t * iLBCenc_inst | |
31 /* (i/o) the encoder state structure */ | |
32 ) | |
33 { | |
34 int k, is; | |
35 float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1]; | |
36 float lp2[LPC_FILTERORDER + 1]; | |
37 float r[LPC_FILTERORDER + 1]; | |
38 | |
39 is = LPC_LOOKBACK + BLOCKL_MAX - iLBCenc_inst->blockl; | |
40 memcpy(iLBCenc_inst->lpc_buffer + is, data, | |
41 iLBCenc_inst->blockl * sizeof(float)); | |
42 | |
43 /* No lookahead, last window is asymmetric */ | |
44 | |
45 for (k = 0; k < iLBCenc_inst->lpc_n; k++) { | |
46 | |
47 is = LPC_LOOKBACK; | |
48 | |
49 if (k < (iLBCenc_inst->lpc_n - 1)) { | |
50 window(temp, lpc_winTbl, iLBCenc_inst->lpc_buffer, BLOCKL_MAX); | |
51 } else { | |
52 window(temp, lpc_asymwinTbl, | |
53 iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX); | |
54 } | |
55 | |
56 autocorr(r, temp, BLOCKL_MAX, LPC_FILTERORDER); | |
57 window(r, r, lpc_lagwinTbl, LPC_FILTERORDER + 1); | |
58 | |
59 levdurb(lp, temp, r, LPC_FILTERORDER); | |
60 bwexpand(lp2, lp, LPC_CHIRP_SYNTDENUM, LPC_FILTERORDER + 1); | |
61 | |
62 a2lsf(lsf + k * LPC_FILTERORDER, lp2); | |
63 } | |
64 is = LPC_LOOKBACK + BLOCKL_MAX - iLBCenc_inst->blockl; | |
65 memmove(iLBCenc_inst->lpc_buffer, | |
66 iLBCenc_inst->lpc_buffer + LPC_LOOKBACK + BLOCKL_MAX - is, | |
67 is * sizeof(float)); | |
68 } | |
69 | |
70 /*----------------------------------------------------------------* | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 * lsf interpolator and conversion from lsf to a coefficients | |
77 * (subrutine to SimpleInterpolateLSF) | |
78 *---------------------------------------------------------------*/ | |
79 | |
80 void LSFinterpolate2a_enc(float *a, /* (o) lpc coefficients */ | |
81 float *lsf1, /* (i) first set of lsf coefficients */ | |
82 float *lsf2, /* (i) second set of lsf coefficients */ | |
83 float coef, /* (i) weighting coefficient to use between | |
84 lsf1 and lsf2 */ | |
85 long length /* (i) length of coefficient vectors */ | |
86 ) | |
87 { | |
88 float lsftmp[LPC_FILTERORDER]; | |
89 | |
90 interpolate(lsftmp, lsf1, lsf2, coef, length); | |
91 lsf2a(a, lsftmp); | |
92 } | |
93 | |
94 /*----------------------------------------------------------------* | |
95 * lsf interpolator (subrutine to LPCencode) | |
96 *---------------------------------------------------------------*/ | |
97 | |
98 void SimpleInterpolateLSF(float *syntdenum, /* (o) the synthesis filter denominator | |
99 resulting from the quantized | |
100 interpolated lsf */ | |
101 float *weightdenum, /* (o) the weighting filter denominator | |
102 resulting from the unquantized | |
103 interpolated lsf */ | |
104 float *lsf, /* (i) the unquantized lsf coefficients */ | |
105 float *lsfdeq, /* (i) the dequantized lsf coefficients */ | |
106 float *lsfold, /* (i) the unquantized lsf coefficients of | |
107 the previous signal frame */ | |
108 float *lsfdeqold, /* (i) the dequantized lsf coefficients of | |
109 the previous signal frame */ | |
110 int length, /* (i) should equate LPC_FILTERORDER */ | |
111 iLBC_Enc_Inst_t * iLBCenc_inst | |
112 /* (i/o) the encoder state structure */ | |
113 ) | |
114 { | |
115 int i, pos, lp_length; | |
116 float lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2; | |
117 | |
118 lsf2 = lsf + length; | |
119 lsfdeq2 = lsfdeq + length; | |
120 lp_length = length + 1; | |
121 | |
122 if (iLBCenc_inst->mode == 30) { | |
123 /* sub-frame 1: Interpolation between old and first | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 set of lsf coefficients */ | |
130 | |
131 LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, | |
132 lsf_weightTbl_30ms[0], length); | |
133 memcpy(syntdenum, lp, lp_length * sizeof(float)); | |
134 LSFinterpolate2a_enc(lp, lsfold, lsf, | |
135 lsf_weightTbl_30ms[0], length); | |
136 bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length); | |
137 | |
138 /* sub-frame 2 to 6: Interpolation between first | |
139 and second set of lsf coefficients */ | |
140 | |
141 pos = lp_length; | |
142 for (i = 1; i < iLBCenc_inst->nsub; i++) { | |
143 LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq2, | |
144 lsf_weightTbl_30ms[i], length); | |
145 memcpy(syntdenum + pos, lp, lp_length * sizeof(float)); | |
146 | |
147 LSFinterpolate2a_enc(lp, lsf, lsf2, | |
148 lsf_weightTbl_30ms[i], length); | |
149 bwexpand(weightdenum + pos, lp, LPC_CHIRP_WEIGHTDENUM, lp_length); | |
150 pos += lp_length; | |
151 } | |
152 } else { | |
153 pos = 0; | |
154 for (i = 0; i < iLBCenc_inst->nsub; i++) { | |
155 LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, | |
156 lsf_weightTbl_20ms[i], length); | |
157 memcpy(syntdenum + pos, lp, lp_length * sizeof(float)); | |
158 LSFinterpolate2a_enc(lp, lsfold, lsf, | |
159 lsf_weightTbl_20ms[i], length); | |
160 bwexpand(weightdenum + pos, lp, LPC_CHIRP_WEIGHTDENUM, lp_length); | |
161 pos += lp_length; | |
162 } | |
163 } | |
164 | |
165 /* update memory */ | |
166 | |
167 if (iLBCenc_inst->mode == 30) { | |
168 memcpy(lsfold, lsf2, length * sizeof(float)); | |
169 memcpy(lsfdeqold, lsfdeq2, length * sizeof(float)); | |
170 } else { | |
171 memcpy(lsfold, lsf, length * sizeof(float)); | |
172 memcpy(lsfdeqold, lsfdeq, length * sizeof(float)); | |
173 | |
174 | |
175 | |
176 | |
177 | |
178 } | |
179 } | |
180 | |
181 /*----------------------------------------------------------------* | |
182 * lsf quantizer (subrutine to LPCencode) | |
183 *---------------------------------------------------------------*/ | |
184 | |
185 void SimplelsfQ(float *lsfdeq, /* (o) dequantized lsf coefficients | |
186 (dimension FILTERORDER) */ | |
187 int *index, /* (o) quantization index */ | |
188 float *lsf, /* (i) the lsf coefficient vector to be | |
189 quantized (dimension FILTERORDER ) */ | |
190 int lpc_n /* (i) number of lsf sets to quantize */ | |
191 ) | |
192 { | |
193 /* Quantize first LSF with memoryless split VQ */ | |
194 SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT, | |
195 dim_lsfCbTbl, size_lsfCbTbl); | |
196 | |
197 if (lpc_n == 2) { | |
198 /* Quantize second LSF with memoryless split VQ */ | |
199 SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT, | |
200 lsf + LPC_FILTERORDER, lsfCbTbl, LSF_NSPLIT, | |
201 dim_lsfCbTbl, size_lsfCbTbl); | |
202 } | |
203 } | |
204 | |
205 /*----------------------------------------------------------------* | |
206 * lpc encoder | |
207 *---------------------------------------------------------------*/ | |
208 | |
209 void LPCencode(float *syntdenum, /* (i/o) synthesis filter coefficients | |
210 before/after encoding */ | |
211 float *weightdenum, /* (i/o) weighting denumerator | |
212 coefficients before/after | |
213 encoding */ | |
214 int *lsf_index, /* (o) lsf quantization index */ | |
215 float *data, /* (i) lsf coefficients to quantize */ | |
216 iLBC_Enc_Inst_t * iLBCenc_inst | |
217 /* (i/o) the encoder state structure */ | |
218 ) | |
219 { | |
220 float lsf[LPC_FILTERORDER * LPC_N_MAX]; | |
221 float lsfdeq[LPC_FILTERORDER * LPC_N_MAX]; | |
222 int change = 0; | |
223 | |
224 SimpleAnalysis(lsf, data, iLBCenc_inst); | |
225 SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n); | |
226 | |
227 | |
228 | |
229 | |
230 | |
231 change = LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n); | |
232 SimpleInterpolateLSF(syntdenum, weightdenum, | |
233 lsf, lsfdeq, iLBCenc_inst->lsfold, | |
234 iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst); | |
235 } |