Coverage Report

Created: 2026-03-22 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pjsip/third_party/ilbc/getCBvec.c
Line
Count
Source
1
2
   /******************************************************************
3
4
       iLBC Speech Coder ANSI-C Source Code
5
6
       getCBvec.c
7
8
       Copyright (C) The Internet Society (2004).
9
       All Rights Reserved.
10
11
   ******************************************************************/
12
13
   #include "iLBC_define.h"
14
   #include "constants.h"
15
   #include <string.h>
16
17
   /*----------------------------------------------------------------*
18
    *  Construct codebook vector for given index.
19
    *---------------------------------------------------------------*/
20
21
   void getCBvec(
22
23
24
25
26
27
       float *cbvec,   /* (o) Constructed codebook vector */
28
       float *mem,     /* (i) Codebook buffer */
29
       int index,      /* (i) Codebook index */
30
       int lMem,       /* (i) Length of codebook buffer */
31
       int cbveclen/* (i) Codebook vector length */
32
3.67k
   ){
33
3.67k
       int j, k, n, memInd, sFilt;
34
3.67k
       float tmpbuf[CB_MEML];
35
3.67k
       int base_size;
36
3.67k
       int ilow, ihigh;
37
3.67k
       float alfa, alfa1;
38
39
       /* Determine size of codebook sections */
40
41
3.67k
       base_size=lMem-cbveclen+1;
42
43
3.67k
       if (cbveclen==SUBL) {
44
2.94k
           base_size+=cbveclen/2;
45
2.94k
       }
46
47
       /* No filter -> First codebook section */
48
49
3.67k
       if (index<lMem-cbveclen+1) {
50
51
           /* first non-interpolated vectors */
52
53
1.34k
           k=index+cbveclen;
54
           /* get vector */
55
1.34k
           memcpy(cbvec, mem+lMem-k, cbveclen*sizeof(float));
56
57
2.32k
       } else if (index < base_size) {
58
59
278
           k=2*(index-(lMem-cbveclen+1))+cbveclen;
60
61
278
           ihigh=k/2;
62
278
           ilow=ihigh-5;
63
64
           /* Copy first noninterpolated part */
65
66
278
           memcpy(cbvec, mem+lMem-k/2, ilow*sizeof(float));
67
68
           /* interpolation */
69
70
278
           alfa1=(float)0.2;
71
278
           alfa=0.0;
72
1.66k
           for (j=ilow; j<ihigh; j++) {
73
1.39k
               cbvec[j]=((float)1.0-alfa)*mem[lMem-k/2+j]+
74
1.39k
                   alfa*mem[lMem-k+j];
75
76
77
78
79
80
1.39k
               alfa+=alfa1;
81
1.39k
           }
82
83
           /* Copy second noninterpolated part */
84
85
278
           memcpy(cbvec+ihigh, mem+lMem-k+ihigh,
86
278
               (cbveclen-ihigh)*sizeof(float));
87
88
278
       }
89
90
       /* Higher codebook section based on filtering */
91
92
2.05k
       else {
93
94
           /* first non-interpolated vectors */
95
96
2.05k
           if (index-base_size<lMem-cbveclen+1) {
97
1.65k
               float tempbuff2[CB_MEML+CB_FILTERLEN+1];
98
1.65k
               float *pos;
99
1.65k
               float *pp, *pp1;
100
101
1.65k
               memset(tempbuff2, 0,
102
1.65k
                   CB_HALFFILTERLEN*sizeof(float));
103
1.65k
               memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,
104
1.65k
                   lMem*sizeof(float));
105
1.65k
               memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,
106
1.65k
                   (CB_HALFFILTERLEN+1)*sizeof(float));
107
108
1.65k
               k=index-base_size+cbveclen;
109
1.65k
               sFilt=lMem-k;
110
1.65k
               memInd=sFilt+1-CB_HALFFILTERLEN;
111
112
               /* do filtering */
113
1.65k
               pos=cbvec;
114
1.65k
               memset(pos, 0, cbveclen*sizeof(float));
115
61.0k
               for (n=0; n<cbveclen; n++) {
116
59.3k
                   pp=&tempbuff2[memInd+n+CB_HALFFILTERLEN];
117
59.3k
                   pp1=&cbfiltersTbl[CB_FILTERLEN-1];
118
534k
                   for (j=0; j<CB_FILTERLEN; j++) {
119
475k
                       (*pos)+=(*pp++)*(*pp1--);
120
475k
                   }
121
59.3k
                   pos++;
122
59.3k
               }
123
1.65k
           }
124
125
           /* interpolated vectors */
126
127
392
           else {
128
129
130
131
132
133
392
               float tempbuff2[CB_MEML+CB_FILTERLEN+1];
134
135
392
               float *pos;
136
392
               float *pp, *pp1;
137
392
               int i;
138
139
392
               memset(tempbuff2, 0,
140
392
                   CB_HALFFILTERLEN*sizeof(float));
141
392
               memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,
142
392
                   lMem*sizeof(float));
143
392
               memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,
144
392
                   (CB_HALFFILTERLEN+1)*sizeof(float));
145
146
392
               k=2*(index-base_size-
147
392
                   (lMem-cbveclen+1))+cbveclen;
148
392
               sFilt=lMem-k;
149
392
               memInd=sFilt+1-CB_HALFFILTERLEN;
150
151
               /* do filtering */
152
392
               pos=&tmpbuf[sFilt];
153
392
               memset(pos, 0, k*sizeof(float));
154
23.1k
               for (i=0; i<k; i++) {
155
22.7k
                   pp=&tempbuff2[memInd+i+CB_HALFFILTERLEN];
156
22.7k
                   pp1=&cbfiltersTbl[CB_FILTERLEN-1];
157
204k
                   for (j=0; j<CB_FILTERLEN; j++) {
158
182k
                       (*pos)+=(*pp++)*(*pp1--);
159
182k
                   }
160
22.7k
                   pos++;
161
22.7k
               }
162
163
392
               ihigh=k/2;
164
392
               ilow=ihigh-5;
165
166
               /* Copy first noninterpolated part */
167
168
392
               memcpy(cbvec, tmpbuf+lMem-k/2,
169
392
                   ilow*sizeof(float));
170
171
               /* interpolation */
172
173
392
               alfa1=(float)0.2;
174
392
               alfa=0.0;
175
2.35k
               for (j=ilow; j<ihigh; j++) {
176
1.96k
                   cbvec[j]=((float)1.0-alfa)*
177
1.96k
                       tmpbuf[lMem-k/2+j]+alfa*tmpbuf[lMem-k+j];
178
1.96k
                   alfa+=alfa1;
179
1.96k
               }
180
181
182
183
184
185
186
               /* Copy second noninterpolated part */
187
188
392
               memcpy(cbvec+ihigh, tmpbuf+lMem-k+ihigh,
189
392
                   (cbveclen-ihigh)*sizeof(float));
190
392
           }
191
2.05k
       }
192
3.67k
   }
193