2
|
1
|
|
2 /******************************************************************
|
|
3
|
|
4 iLBC Speech Coder ANSI-C Source Code
|
|
5
|
|
6 LPC_decode.c
|
|
7
|
|
8 Copyright (C) The Internet Society (2004).
|
|
9 All Rights Reserved.
|
|
10
|
|
11 ******************************************************************/
|
|
12
|
|
13 #include <math.h>
|
|
14 #include <string.h>
|
|
15
|
|
16 #include "helpfun.h"
|
|
17 #include "lsf.h"
|
|
18 #include "iLBC_define.h"
|
|
19 #include "constants.h"
|
|
20
|
|
21 /*---------------------------------------------------------------*
|
|
22 * interpolation of lsf coefficients for the decoder
|
|
23 *--------------------------------------------------------------*/
|
|
24
|
|
25 void LSFinterpolate2a_dec(float *a, /* (o) lpc coefficients for a sub-frame */
|
|
26 float *lsf1, /* (i) first lsf coefficient vector */
|
|
27 float *lsf2, /* (i) second lsf coefficient vector */
|
|
28 float coef, /* (i) interpolation weight */
|
|
29 int length /* (i) length of lsf vectors */
|
|
30 )
|
|
31 {
|
|
32 float lsftmp[LPC_FILTERORDER];
|
|
33
|
|
34 interpolate(lsftmp, lsf1, lsf2, coef, length);
|
|
35 lsf2a(a, lsftmp);
|
|
36 }
|
|
37
|
|
38 /*---------------------------------------------------------------*
|
|
39 * obtain dequantized lsf coefficients from quantization index
|
|
40 *--------------------------------------------------------------*/
|
|
41
|
|
42 void SimplelsfDEQ(float *lsfdeq, /* (o) dequantized lsf coefficients */
|
|
43 int *index, /* (i) quantization index */
|
|
44 int lpc_n /* (i) number of LPCs */
|
|
45 )
|
|
46 {
|
|
47 int i, j, pos, cb_pos;
|
|
48
|
|
49
|
|
50
|
|
51
|
|
52
|
|
53 /* decode first LSF */
|
|
54
|
|
55 pos = 0;
|
|
56 cb_pos = 0;
|
|
57 for (i = 0; i < LSF_NSPLIT; i++) {
|
|
58 for (j = 0; j < dim_lsfCbTbl[i]; j++) {
|
|
59 lsfdeq[pos + j] = lsfCbTbl[cb_pos +
|
|
60 (long) (index[i]) * dim_lsfCbTbl[i] + j];
|
|
61 }
|
|
62 pos += dim_lsfCbTbl[i];
|
|
63 cb_pos += size_lsfCbTbl[i] * dim_lsfCbTbl[i];
|
|
64 }
|
|
65
|
|
66 if (lpc_n > 1) {
|
|
67
|
|
68 /* decode last LSF */
|
|
69
|
|
70 pos = 0;
|
|
71 cb_pos = 0;
|
|
72 for (i = 0; i < LSF_NSPLIT; i++) {
|
|
73 for (j = 0; j < dim_lsfCbTbl[i]; j++) {
|
|
74 lsfdeq[LPC_FILTERORDER + pos + j] =
|
|
75 lsfCbTbl[cb_pos +
|
|
76 (long) (index[LSF_NSPLIT + i]) * dim_lsfCbTbl[i] + j];
|
|
77 }
|
|
78 pos += dim_lsfCbTbl[i];
|
|
79 cb_pos += size_lsfCbTbl[i] * dim_lsfCbTbl[i];
|
|
80 }
|
|
81 }
|
|
82 }
|
|
83
|
|
84 /*----------------------------------------------------------------*
|
|
85 * obtain synthesis and weighting filters form lsf coefficients
|
|
86 *---------------------------------------------------------------*/
|
|
87
|
|
88 void DecoderInterpolateLSF(float *syntdenum, /* (o) synthesis filter coefficients */
|
|
89 float *weightdenum, /* (o) weighting denumerator
|
|
90 coefficients */
|
|
91 float *lsfdeq, /* (i) dequantized lsf coefficients */
|
|
92 int length, /* (i) length of lsf coefficient vector */
|
|
93 iLBC_Dec_Inst_t * iLBCdec_inst
|
|
94 /* (i) the decoder state structure */
|
|
95 )
|
|
96 {
|
|
97 int i, pos, lp_length;
|
|
98 float lp[LPC_FILTERORDER + 1], *lsfdeq2;
|
|
99
|
|
100
|
|
101
|
|
102
|
|
103
|
|
104
|
|
105 lsfdeq2 = lsfdeq + length;
|
|
106 lp_length = length + 1;
|
|
107
|
|
108 if (iLBCdec_inst->mode == 30) {
|
|
109 /* sub-frame 1: Interpolation between old and first */
|
|
110
|
|
111 LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq,
|
|
112 lsf_weightTbl_30ms[0], length);
|
|
113 memcpy(syntdenum, lp, lp_length * sizeof(float));
|
|
114 bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);
|
|
115
|
|
116 /* sub-frames 2 to 6: interpolation between first
|
|
117 and last LSF */
|
|
118
|
|
119 pos = lp_length;
|
|
120 for (i = 1; i < 6; i++) {
|
|
121 LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2,
|
|
122 lsf_weightTbl_30ms[i], length);
|
|
123 memcpy(syntdenum + pos, lp, lp_length * sizeof(float));
|
|
124 bwexpand(weightdenum + pos, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);
|
|
125 pos += lp_length;
|
|
126 }
|
|
127 } else {
|
|
128 pos = 0;
|
|
129 for (i = 0; i < iLBCdec_inst->nsub; i++) {
|
|
130 LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold,
|
|
131 lsfdeq, lsf_weightTbl_20ms[i], length);
|
|
132 memcpy(syntdenum + pos, lp, lp_length * sizeof(float));
|
|
133 bwexpand(weightdenum + pos, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);
|
|
134 pos += lp_length;
|
|
135 }
|
|
136 }
|
|
137
|
|
138 /* update memory */
|
|
139
|
|
140 if (iLBCdec_inst->mode == 30)
|
|
141 memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2, length * sizeof(float));
|
|
142 else
|
|
143 memcpy(iLBCdec_inst->lsfdeqold, lsfdeq, length * sizeof(float));
|
|
144
|
|
145 }
|