annotate libgsmefr/g_code.c @ 53:49dd1ac8e75b

libgsmefr: import most *.c files from ETSI source
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Nov 2022 16:18:21 +0000
parents
children 9dac98926a2d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * FUNCTION: G_code
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * PURPOSE: Compute the innovative codebook gain.
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * DESCRIPTION:
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 * The innovative codebook gain is given by
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * g = <x[], y[]> / <y[], y[]>
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 * where x[] is the target vector, y[] is the filtered innovative
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 * codevector, and <> denotes dot product.
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 *************************************************************************/
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "typedef.h"
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "basic_op.h"
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "count.h"
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "cnst.h"
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 Word16 G_code ( /* out : Gain of innovation code */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 Word16 xn2[], /* in : target vector */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 Word16 y2[] /* in : filtered innovation vector */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 )
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 Word16 i;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 Word16 xy, yy, exp_xy, exp_yy, gain;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 Word16 scal_y2[L_SUBFR];
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 Word32 s;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 /* Scale down Y[] by 2 to avoid overflow */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 for (i = 0; i < L_SUBFR; i++)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 scal_y2[i] = shr (y2[i], 1); move16 ();
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 /* Compute scalar product <X[],Y[]> */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 s = 1L; move32 (); /* Avoid case of all zeros */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 for (i = 0; i < L_SUBFR; i++)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 s = L_mac (s, xn2[i], scal_y2[i]);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 exp_xy = norm_l (s);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 xy = extract_h (L_shl (s, exp_xy));
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 /* If (xy < 0) gain = 0 */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 test ();
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (xy <= 0)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return ((Word16) 0);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 /* Compute scalar product <Y[],Y[]> */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 s = 0L; move32 ();
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 for (i = 0; i < L_SUBFR; i++)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 s = L_mac (s, scal_y2[i], scal_y2[i]);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 exp_yy = norm_l (s);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 yy = extract_h (L_shl (s, exp_yy));
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 /* compute gain = xy/yy */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 xy = shr (xy, 1); /* Be sure xy < yy */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 gain = div_s (xy, yy);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 /* Denormalization of division */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 i = add (exp_xy, 5); /* 15-1+9-18 = 5 */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 i = sub (i, exp_yy);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 gain = shr (gain, i);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 return (gain);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }