aboutsummaryrefslogtreecommitdiffstats
path: root/codecs/ilbc/getCBvec.c
blob: 9c57f7bf9788297d624a2170e40c4a257f4f861e (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
 
/****************************************************************** 
 
    iLBC Speech Coder ANSI-C Source Code 
 
    getCBvec.c  
 
    Copyright (c) 2001, 
    Global IP Sound AB. 
    All rights reserved. 
 
******************************************************************/ 
 
#include "iLBC_define.h" 
#include "constants.h" 
#include "getCBvec.h"
#include <string.h> 
 
/*----------------------------------------------------------------* 
 *  Construct codebook vector for given index. 
 *---------------------------------------------------------------*/ 
 
void getCBvec( 
    float *cbvec,   /* (o) Constructed codebook vector */ 
    float *mem,     /* (i) Codebook buffer */ 
    int index,      /* (i) Codebook index */ 
    int lMem,       /* (i) Length of codebook buffer */ 
    int cbveclen/* (i) Codebook vector length */ 
){ 
    int j, k, n, memInd, sFilt; 
    float tmpbuf[CB_MEML]; 
    int base_size; 
    int ilow, ihigh; 
    float alfa, alfa1; 
 
    /* Determine size of codebook sections */ 
 
    base_size=lMem-cbveclen+1; 
     
    if (cbveclen==SUBL) { 
        base_size+=cbveclen/2; 
    } 
 
    /* No filter -> First codebook section */ 
     
    if (index<lMem-cbveclen+1) { 
 
        /* first non-interpolated vectors */ 
 
        k=index+cbveclen; 
        /* get vector */ 
        memcpy(cbvec, mem+lMem-k, cbveclen*sizeof(float)); 
 
    } else if (index < base_size) { 
 
        k=2*(index-(lMem-cbveclen+1))+cbveclen; 
     
        ihigh=k/2; 
        ilow=ihigh-5; 
 
        /* Copy first noninterpolated part */ 
 
        memcpy(cbvec, mem+lMem-k/2, ilow*sizeof(float)); 
 
        /* interpolation */ 
 
        alfa1=(float)0.2; 
        alfa=0.0; 
        for (j=ilow; j<ihigh; j++) { 
            cbvec[j]=((float)1.0-alfa)*mem[lMem-k/2+j]+ 
                alfa*mem[lMem-k+j]; 
            alfa+=alfa1; 
        } 
 
        /* Copy second noninterpolated part */ 
 
        memcpy(cbvec+ihigh, mem+lMem-k+ihigh,  
            (cbveclen-ihigh)*sizeof(float)); 
 
    } 
 
    /* Higher codebbok section based on filtering */ 
 
    else { 
 
        /* first non-interpolated vectors */ 
 
        if (index-base_size<lMem-cbveclen+1) { 
            float tempbuff2[CB_MEML+CB_FILTERLEN+1]; 
            float *pos; 
            float *pp, *pp1; 
 
            memset(tempbuff2, 0, CB_HALFFILTERLEN*sizeof(float)); 
            memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,  
                lMem*sizeof(float)); 
            memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,  
                (CB_HALFFILTERLEN+1)*sizeof(float)); 
 
            k=index-base_size+cbveclen; 
            sFilt=lMem-k; 
            memInd=sFilt+1-CB_HALFFILTERLEN; 
 
            /* do filtering */ 
            pos=cbvec; 
            memset(pos, 0, cbveclen*sizeof(float)); 
            for (n=0; n<cbveclen; n++) { 
                pp=&tempbuff2[memInd+n+CB_HALFFILTERLEN]; 
                pp1=&cbfiltersTbl[0]; 
                for (j=0;j<CB_FILTERLEN;j++) { 
                    (*pos)+=(*pp++)*(*pp1++); 
                } 
                pos++; 
            } 
        } 
 
        /* interpolated vectors */ 
 
        else { 
            float tempbuff2[CB_MEML+CB_FILTERLEN+1]; 
 
            float *pos; 
            float *pp, *pp1; 
            int i; 
 
            memset(tempbuff2, 0, CB_HALFFILTERLEN*sizeof(float)); 
            memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,  
                lMem*sizeof(float)); 
            memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,  
                (CB_HALFFILTERLEN+1)*sizeof(float)); 
 
            k=2*(index-base_size-(lMem-cbveclen+1))+cbveclen; 
            sFilt=lMem-k; 
            memInd=sFilt+1-CB_HALFFILTERLEN; 
 
            /* do filtering */ 
            pos=&tmpbuf[sFilt]; 
            memset(pos, 0, k*sizeof(float)); 
            for (i=0; i<k; i++) { 
                pp=&tempbuff2[memInd+i+CB_HALFFILTERLEN]; 
                pp1=&cbfiltersTbl[0]; 
                for (j=0;j<CB_FILTERLEN;j++) { 
                    (*pos)+=(*pp++)*(*pp1++); 
                } 
                pos++; 
            } 
 
            ihigh=k/2; 
            ilow=ihigh-5; 
 
            /* Copy first noninterpolated part */ 
 
            memcpy(cbvec, tmpbuf+lMem-k/2, ilow*sizeof(float)); 
 
            /* interpolation */ 
 
            alfa1=(float)0.2; 
            alfa=0.0; 
            for (j=ilow; j<ihigh; j++) { 
                cbvec[j]=((float)1.0-alfa)* 
                    tmpbuf[lMem-k/2+j]+alfa*tmpbuf[lMem-k+j]; 
                alfa+=alfa1; 
            } 
 
            /* Copy second noninterpolated part */ 
 
            memcpy(cbvec+ihigh, tmpbuf+lMem-k+ihigh,  
                (cbveclen-ihigh)*sizeof(float)); 
        } 
    } 
}