annotate libtwamr/g_code.c @ 454:4b6fa53a8240

INSTALL: document the new way
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 10 May 2024 06:19:24 +0000
parents 1588a7d9e732
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
366
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 ********************************************************************************
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 ********************************************************************************
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : g_code.c
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : Compute the innovative codebook gain.
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 *
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 ********************************************************************************
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 /*
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 ********************************************************************************
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 * MODULE INCLUDE FILE AND VERSION ID
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 ********************************************************************************
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "namespace.h"
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "g_code.h"
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 /*
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 ********************************************************************************
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 * INCLUDE FILES
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 ********************************************************************************
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 #include "typedef.h"
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "basic_op.h"
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "no_count.h"
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "cnst.h"
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 /*
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 ********************************************************************************
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 * LOCAL VARIABLES AND TABLES
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 ********************************************************************************
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 /*
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 ********************************************************************************
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 * PUBLIC PROGRAM CODE
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 ********************************************************************************
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 /*************************************************************************
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 *
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 * FUNCTION: G_code
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 *
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 * PURPOSE: Compute the innovative codebook gain.
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 *
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 * DESCRIPTION:
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 * The innovative codebook gain is given by
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 *
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 * g = <x[], y[]> / <y[], y[]>
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 *
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 * where x[] is the target vector, y[] is the filtered innovative
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 * codevector, and <> denotes dot product.
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 *
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 *************************************************************************/
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 Word16 G_code ( /* out : Gain of innovation code */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 Word16 xn2[], /* in : target vector */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 Word16 y2[] /* in : filtered innovation vector */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 )
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 {
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 Word16 i;
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 Word16 xy, yy, exp_xy, exp_yy, gain;
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 Word16 scal_y2[L_SUBFR];
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 Word32 s;
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 /* Scale down Y[] by 2 to avoid overflow */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 for (i = 0; i < L_SUBFR; i++)
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 {
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 scal_y2[i] = shr (y2[i], 1); move16 ();
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 /* Compute scalar product <X[],Y[]> */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 s = 1L; move32 (); /* Avoid case of all zeros */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 for (i = 0; i < L_SUBFR; i++)
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 {
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 s = L_mac (s, xn2[i], scal_y2[i]);
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 exp_xy = norm_l (s);
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 xy = extract_h (L_shl (s, exp_xy));
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 /* If (xy < 0) gain = 0 */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 test ();
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 if (xy <= 0)
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 return ((Word16) 0);
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 /* Compute scalar product <Y[],Y[]> */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 s = 0L; move32 ();
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 for (i = 0; i < L_SUBFR; i++)
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 {
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 s = L_mac (s, scal_y2[i], scal_y2[i]);
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 exp_yy = norm_l (s);
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 yy = extract_h (L_shl (s, exp_yy));
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 /* compute gain = xy/yy */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 xy = shr (xy, 1); /* Be sure xy < yy */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 gain = div_s (xy, yy);
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 /* Denormalization of division */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 i = add (exp_xy, 5); /* 15-1+9-18 = 5 */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 i = sub (i, exp_yy);
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 gain = shl (shr (gain, i), 1); /* Q0 -> Q1 */
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 return (gain);
1588a7d9e732 libtwamr: integrate g_code.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 }