comparison 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
comparison
equal deleted inserted replaced
52:988fd7ff514f 53:49dd1ac8e75b
1 /*************************************************************************
2 *
3 * FUNCTION: G_code
4 *
5 * PURPOSE: Compute the innovative codebook gain.
6 *
7 * DESCRIPTION:
8 * The innovative codebook gain is given by
9 *
10 * g = <x[], y[]> / <y[], y[]>
11 *
12 * where x[] is the target vector, y[] is the filtered innovative
13 * codevector, and <> denotes dot product.
14 *
15 *************************************************************************/
16
17 #include "typedef.h"
18 #include "basic_op.h"
19 #include "count.h"
20 #include "cnst.h"
21
22 Word16 G_code ( /* out : Gain of innovation code */
23 Word16 xn2[], /* in : target vector */
24 Word16 y2[] /* in : filtered innovation vector */
25 )
26 {
27 Word16 i;
28 Word16 xy, yy, exp_xy, exp_yy, gain;
29 Word16 scal_y2[L_SUBFR];
30 Word32 s;
31
32 /* Scale down Y[] by 2 to avoid overflow */
33
34 for (i = 0; i < L_SUBFR; i++)
35 {
36 scal_y2[i] = shr (y2[i], 1); move16 ();
37 }
38
39 /* Compute scalar product <X[],Y[]> */
40
41 s = 1L; move32 (); /* Avoid case of all zeros */
42 for (i = 0; i < L_SUBFR; i++)
43 {
44 s = L_mac (s, xn2[i], scal_y2[i]);
45 }
46 exp_xy = norm_l (s);
47 xy = extract_h (L_shl (s, exp_xy));
48
49 /* If (xy < 0) gain = 0 */
50
51 test ();
52 if (xy <= 0)
53 return ((Word16) 0);
54
55 /* Compute scalar product <Y[],Y[]> */
56
57 s = 0L; move32 ();
58 for (i = 0; i < L_SUBFR; i++)
59 {
60 s = L_mac (s, scal_y2[i], scal_y2[i]);
61 }
62 exp_yy = norm_l (s);
63 yy = extract_h (L_shl (s, exp_yy));
64
65 /* compute gain = xy/yy */
66
67 xy = shr (xy, 1); /* Be sure xy < yy */
68 gain = div_s (xy, yy);
69
70 /* Denormalization of division */
71 i = add (exp_xy, 5); /* 15-1+9-18 = 5 */
72 i = sub (i, exp_yy);
73
74 gain = shr (gain, i);
75
76 return (gain);
77 }