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