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