comparison libtwamr/s10_8pf.c @ 316:ebd064c52fe3

libtwamr: integrate s10_8pf.c
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 18 Apr 2024 17:49:02 +0000
parents
children
comparison
equal deleted inserted replaced
315:5401aaf7acb0 316:ebd064c52fe3
1 /*
2 ********************************************************************************
3 *
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
5 * R99 Version 3.3.0
6 * REL-4 Version 4.1.0
7 *
8 ********************************************************************************
9 *
10 * File : s10_8pf.c
11 * Purpose : Searches a 35/31 bit algebraic codebook containing
12 * : 10/8 pulses in a frame of 40 samples.
13 *
14 ********************************************************************************
15 */
16 /*
17 ********************************************************************************
18 * MODULE INCLUDE FILE AND VERSION ID
19 ********************************************************************************
20 */
21 #include "namespace.h"
22 #include "s10_8pf.h"
23 /*
24 ********************************************************************************
25 * INCLUDE FILES
26 ********************************************************************************
27 */
28 #include "typedef.h"
29 #include "basic_op.h"
30 #include "no_count.h"
31 #include "cnst.h"
32
33 /*
34 ********************************************************************************
35 * LOCAL VARIABLES AND TABLES
36 ********************************************************************************
37 */
38
39 /*************************************************************************
40 *
41 * FUNCTION search_10and8i40()
42 *
43 * PURPOSE: Search the best codevector; determine positions of the 10/8
44 * pulses in the 40-sample frame.
45 *
46 * search_10and8i40 (10,5,5,dn, rr, ipos, pos_max, codvec); for GSMEFR
47 * search_10and8i40 (8, 4,4,dn, rr, ipos, pos_max, codvec); for 10.2
48 *
49 *************************************************************************/
50
51 #define _1_2 (Word16)(32768L/2)
52 #define _1_4 (Word16)(32768L/4)
53 #define _1_8 (Word16)(32768L/8)
54 #define _1_16 (Word16)(32768L/16)
55 #define _1_32 (Word16)(32768L/32)
56 #define _1_64 (Word16)(32768L/64)
57 #define _1_128 (Word16)(32768L/128)
58
59 void search_10and8i40 (
60 Word16 nbPulse, /* i : nbpulses to find */
61 Word16 step, /* i : stepsize */
62 Word16 nbTracks, /* i : nbTracks */
63 Word16 dn[], /* i : correlation between target and h[] */
64 Word16 rr[][L_CODE], /* i : matrix of autocorrelation */
65 Word16 ipos[], /* i : starting position for each pulse */
66 Word16 pos_max[], /* i : position of maximum of dn[] */
67 Word16 codvec[] /* o : algebraic codebook vector */
68 )
69 {
70 Word16 i0, i1, i2, i3, i4, i5, i6, i7, i8, i9;
71 Word16 i, j, k, pos, ia, ib;
72 Word16 psk, ps, ps0, ps1, ps2, sq, sq2;
73 Word16 alpk, alp, alp_16;
74 Word16 rrv[L_CODE];
75 Word32 s, alp0, alp1, alp2;
76 Word16 gsmefrFlag;
77
78
79 test();
80 if (sub(nbPulse, 10) == 0)
81 {
82 gsmefrFlag=1; move16 ();
83 }
84 else
85 {
86 gsmefrFlag=0; move16 ();
87 }
88
89 /* fix i0 on maximum of correlation position */
90 i0 = pos_max[ipos[0]]; move16 ();
91
92 /*------------------------------------------------------------------*
93 * i1 loop: *
94 *------------------------------------------------------------------*/
95
96 /* Default value */
97 psk = -1; move16 ();
98 alpk = 1; move16 ();
99 for (i = 0; i < nbPulse; i++)
100 {
101 codvec[i] = i; move16 ();
102 }
103
104 for (i = 1; i < nbTracks; i++)
105 {
106 i1 = pos_max[ipos[1]]; move16 ();
107 ps0 = add (dn[i0], dn[i1]);
108 alp0 = L_mult (rr[i0][i0], _1_16);
109 alp0 = L_mac (alp0, rr[i1][i1], _1_16);
110 alp0 = L_mac (alp0, rr[i0][i1], _1_8);
111
112 /*----------------------------------------------------------------*
113 * i2 and i3 loop: *
114 *----------------------------------------------------------------*/
115
116 /* initialize 4 indices for next loop. */
117 move16 (); /* initialize "rr[i3][i3]" pointer */
118 move16 (); /* initialize "rr[i0][i3]" pointer */
119 move16 (); /* initialize "rr[i1][i3]" pointer */
120 move16 (); /* initialize "rrv[i3]" pointer */
121
122 for (i3 = ipos[3]; i3 < L_CODE; i3 += step)
123 {
124 s = L_mult (rr[i3][i3], _1_8); /* index incr= step+L_CODE */
125 s = L_mac (s, rr[i0][i3], _1_4); /* index increment = step */
126 s = L_mac (s, rr[i1][i3], _1_4); /* index increment = step */
127 rrv[i3] = round (s); move16 ();
128 }
129
130 /* Default value */
131 sq = -1; move16 ();
132 alp = 1; move16 ();
133 ps = 0; move16 ();
134 ia = ipos[2]; move16 ();
135 ib = ipos[3]; move16 ();
136
137 /* initialize 4 indices for i2 loop. */
138 move16 (); /* initialize "dn[i2]" pointer */
139 move16 (); /* initialize "rr[i2][i2]" pointer */
140 move16 (); /* initialize "rr[i0][i2]" pointer */
141 move16 (); /* initialize "rr[i1][i2]" pointer */
142
143 for (i2 = ipos[2]; i2 < L_CODE; i2 += step)
144 {
145 /* index increment = step */
146 ps1 = add (ps0, dn[i2]);
147
148 /* index incr= step+L_CODE */
149 alp1 = L_mac (alp0, rr[i2][i2], _1_16);
150 /* index increment = step */
151 alp1 = L_mac (alp1, rr[i0][i2], _1_8);
152 /* index increment = step */
153 alp1 = L_mac (alp1, rr[i1][i2], _1_8);
154
155 /* initialize 3 indices for i3 inner loop */
156 move16 (); /* initialize "dn[i3]" pointer */
157 move16 (); /* initialize "rrv[i3]" pointer */
158 move16 (); /* initialize "rr[i2][i3]" pointer */
159
160 for (i3 = ipos[3]; i3 < L_CODE; i3 += step)
161 {
162 /* index increment = step */
163 ps2 = add (ps1, dn[i3]);
164
165 /* index increment = step */
166 alp2 = L_mac (alp1, rrv[i3], _1_2);
167 /* index increment = step */
168 alp2 = L_mac (alp2, rr[i2][i3], _1_8);
169
170 sq2 = mult (ps2, ps2);
171
172 alp_16 = round (alp2);
173
174 s = L_msu (L_mult (alp, sq2), sq, alp_16);
175
176 test ();
177 if (s > 0)
178 {
179 sq = sq2; move16 ();
180 ps = ps2; move16 ();
181 alp = alp_16; move16 ();
182 ia = i2; move16 ();
183 ib = i3; move16 ();
184 }
185 }
186 }
187 i2 = ia; move16 ();
188 i3 = ib; move16 ();
189
190 /*----------------------------------------------------------------*
191 * i4 and i5 loop: *
192 *----------------------------------------------------------------*/
193
194 ps0 = ps; move16 ();
195 alp0 = L_mult (alp, _1_2);
196
197 /* initialize 6 indices for next loop (see i2-i3 loop) */
198 move16 (); move16 (); move16 (); move16 (); move16 (); move16 ();
199
200 for (i5 = ipos[5]; i5 < L_CODE; i5 += step)
201 {
202 s = L_mult (rr[i5][i5], _1_8);
203 s = L_mac (s, rr[i0][i5], _1_4);
204 s = L_mac (s, rr[i1][i5], _1_4);
205 s = L_mac (s, rr[i2][i5], _1_4);
206 s = L_mac (s, rr[i3][i5], _1_4);
207 rrv[i5] = round (s); move16 ();
208 }
209
210 /* Default value */
211 sq = -1; move16 ();
212 alp = 1; move16 ();
213 ps = 0; move16 ();
214 ia = ipos[4]; move16 ();
215 ib = ipos[5]; move16 ();
216
217 /* initialize 6 indices for i4 loop (see i2-i3 loop) */
218 move16 (); move16 (); move16 (); move16 (); move16 (); move16 ();
219
220 for (i4 = ipos[4]; i4 < L_CODE; i4 += step)
221 {
222 ps1 = add (ps0, dn[i4]);
223
224 alp1 = L_mac (alp0, rr[i4][i4], _1_32);
225 alp1 = L_mac (alp1, rr[i0][i4], _1_16);
226 alp1 = L_mac (alp1, rr[i1][i4], _1_16);
227 alp1 = L_mac (alp1, rr[i2][i4], _1_16);
228 alp1 = L_mac (alp1, rr[i3][i4], _1_16);
229
230 /* initialize 3 indices for i5 inner loop (see i2-i3 loop) */
231 move16 (); move16 (); move16 ();
232
233 for (i5 = ipos[5]; i5 < L_CODE; i5 += step)
234 {
235 ps2 = add (ps1, dn[i5]);
236
237 alp2 = L_mac (alp1, rrv[i5], _1_4);
238 alp2 = L_mac (alp2, rr[i4][i5], _1_16);
239
240 sq2 = mult (ps2, ps2);
241
242 alp_16 = round (alp2);
243
244 s = L_msu (L_mult (alp, sq2), sq, alp_16);
245
246 test ();
247 if (s > 0)
248 {
249 sq = sq2; move16 ();
250 ps = ps2; move16 ();
251 alp = alp_16; move16 ();
252 ia = i4; move16 ();
253 ib = i5; move16 ();
254 }
255 }
256 }
257 i4 = ia; move16 ();
258 i5 = ib; move16 ();
259
260 /*----------------------------------------------------------------*
261 * i6 and i7 loop: *
262 *----------------------------------------------------------------*/
263
264 ps0 = ps; move16 ();
265 alp0 = L_mult (alp, _1_2);
266
267 /* initialize 8 indices for next loop (see i2-i3 loop) */
268 move16 (); move16 (); move16 (); move16 ();
269 move16 (); move16 (); move16 (); move16 ();
270
271 for (i7 = ipos[7]; i7 < L_CODE; i7 += step)
272 {
273 s = L_mult (rr[i7][i7], _1_16);
274 s = L_mac (s, rr[i0][i7], _1_8);
275 s = L_mac (s, rr[i1][i7], _1_8);
276 s = L_mac (s, rr[i2][i7], _1_8);
277 s = L_mac (s, rr[i3][i7], _1_8);
278 s = L_mac (s, rr[i4][i7], _1_8);
279 s = L_mac (s, rr[i5][i7], _1_8);
280 rrv[i7] = round (s); move16 ();
281 }
282
283 /* Default value */
284 sq = -1; move16 ();
285 alp = 1; move16 ();
286 ps = 0; move16 ();
287 ia = ipos[6]; move16 ();
288 ib = ipos[7]; move16 ();
289
290 /* initialize 8 indices for i6 loop (see i2-i3 loop) */
291 move16 (); move16 (); move16 (); move16 ();
292 move16 (); move16 (); move16 (); move16 ();
293
294 for (i6 = ipos[6]; i6 < L_CODE; i6 += step)
295 {
296 ps1 = add (ps0, dn[i6]);
297
298 alp1 = L_mac (alp0, rr[i6][i6], _1_64);
299 alp1 = L_mac (alp1, rr[i0][i6], _1_32);
300 alp1 = L_mac (alp1, rr[i1][i6], _1_32);
301 alp1 = L_mac (alp1, rr[i2][i6], _1_32);
302 alp1 = L_mac (alp1, rr[i3][i6], _1_32);
303 alp1 = L_mac (alp1, rr[i4][i6], _1_32);
304 alp1 = L_mac (alp1, rr[i5][i6], _1_32);
305
306 /* initialize 3 indices for i7 inner loop (see i2-i3 loop) */
307 move16 (); move16 (); move16 ();
308
309 for (i7 = ipos[7]; i7 < L_CODE; i7 += step)
310 {
311 ps2 = add (ps1, dn[i7]);
312
313 alp2 = L_mac (alp1, rrv[i7], _1_4);
314 alp2 = L_mac (alp2, rr[i6][i7], _1_32);
315
316 sq2 = mult (ps2, ps2);
317
318 alp_16 = round (alp2);
319
320 s = L_msu (L_mult (alp, sq2), sq, alp_16);
321
322 test ();
323 if (s > 0)
324 {
325 sq = sq2; move16 ();
326 ps = ps2; move16 ();
327 alp = alp_16; move16 ();
328 ia = i6; move16 ();
329 ib = i7; move16 ();
330 }
331 }
332 }
333 i6 = ia; move16 ();
334 i7 = ib; move16 ();
335
336 /* now finished searching a set of 8 pulses */
337
338 test();
339 if(gsmefrFlag != 0){
340 /* go on with the two last pulses for GSMEFR */
341 /*----------------------------------------------------------------*
342 * i8 and i9 loop: *
343 *----------------------------------------------------------------*/
344
345 ps0 = ps; move16 ();
346 alp0 = L_mult (alp, _1_2);
347
348 /* initialize 10 indices for next loop (see i2-i3 loop) */
349 move16 (); move16 (); move16 (); move16 (); move16 ();
350 move16 (); move16 (); move16 (); move16 (); move16 ();
351
352 for (i9 = ipos[9]; i9 < L_CODE; i9 += step)
353 {
354 s = L_mult (rr[i9][i9], _1_16);
355 s = L_mac (s, rr[i0][i9], _1_8);
356 s = L_mac (s, rr[i1][i9], _1_8);
357 s = L_mac (s, rr[i2][i9], _1_8);
358 s = L_mac (s, rr[i3][i9], _1_8);
359 s = L_mac (s, rr[i4][i9], _1_8);
360 s = L_mac (s, rr[i5][i9], _1_8);
361 s = L_mac (s, rr[i6][i9], _1_8);
362 s = L_mac (s, rr[i7][i9], _1_8);
363 rrv[i9] = round (s); move16 ();
364 }
365
366 /* Default value */
367 sq = -1; move16 ();
368 alp = 1; move16 ();
369 ps = 0; move16 ();
370 ia = ipos[8]; move16 ();
371 ib = ipos[9]; move16 ();
372
373 /* initialize 10 indices for i8 loop (see i2-i3 loop) */
374 move16 (); move16 (); move16 (); move16 (); move16 ();
375 move16 (); move16 (); move16 (); move16 (); move16 ();
376
377 for (i8 = ipos[8]; i8 < L_CODE; i8 += step)
378 {
379 ps1 = add (ps0, dn[i8]);
380
381 alp1 = L_mac (alp0, rr[i8][i8], _1_128);
382 alp1 = L_mac (alp1, rr[i0][i8], _1_64);
383 alp1 = L_mac (alp1, rr[i1][i8], _1_64);
384 alp1 = L_mac (alp1, rr[i2][i8], _1_64);
385 alp1 = L_mac (alp1, rr[i3][i8], _1_64);
386 alp1 = L_mac (alp1, rr[i4][i8], _1_64);
387 alp1 = L_mac (alp1, rr[i5][i8], _1_64);
388 alp1 = L_mac (alp1, rr[i6][i8], _1_64);
389 alp1 = L_mac (alp1, rr[i7][i8], _1_64);
390
391 /* initialize 3 indices for i9 inner loop (see i2-i3 loop) */
392 move16 (); move16 (); move16 ();
393
394 for (i9 = ipos[9]; i9 < L_CODE; i9 += step)
395 {
396 ps2 = add (ps1, dn[i9]);
397
398 alp2 = L_mac (alp1, rrv[i9], _1_8);
399 alp2 = L_mac (alp2, rr[i8][i9], _1_64);
400
401 sq2 = mult (ps2, ps2);
402
403 alp_16 = round (alp2);
404
405 s = L_msu (L_mult (alp, sq2), sq, alp_16);
406
407 test ();
408 if (s > 0)
409 {
410 sq = sq2; move16 ();
411 ps = ps2; move16 ();
412 alp = alp_16; move16 ();
413 ia = i8; move16 ();
414 ib = i9; move16 ();
415 }
416 }
417 }
418 }/* end gsmefrFlag */
419
420 /*---------------------------------------------------------------- *
421 * test and memorise if this combination is better than the last one.*
422 *----------------------------------------------------------------*/
423
424 s = L_msu (L_mult (alpk, sq), psk, alp);
425
426 test ();
427 if (s > 0)
428 {
429 psk = sq; move16 ();
430 alpk = alp; move16 ();
431 codvec[0] = i0; move16 ();
432 codvec[1] = i1; move16 ();
433 codvec[2] = i2; move16 ();
434 codvec[3] = i3; move16 ();
435 codvec[4] = i4; move16 ();
436 codvec[5] = i5; move16 ();
437 codvec[6] = i6; move16 ();
438 codvec[7] = i7; move16 ();
439
440 test();
441 if (gsmefrFlag != 0)
442 {
443 codvec[8] = ia; move16 ();
444 codvec[9] = ib; move16 ();
445 }
446 }
447 /*----------------------------------------------------------------*
448 * Cyclic permutation of i1,i2,i3,i4,i5,i6,i7,(i8 and i9). *
449 *----------------------------------------------------------------*/
450
451 pos = ipos[1]; move16 ();
452 for (j = 1, k = 2; k < nbPulse; j++, k++)
453 {
454 ipos[j] = ipos[k]; move16 ();
455 }
456 ipos[sub(nbPulse,1)] = pos; move16 ();
457 } /* end 1..nbTracks loop*/
458 }