annotate libtwamr/g_pitch.c @ 518:087a88d25ba2

new program gsmhr-dec-craft
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 01 Sep 2024 18:58:02 +0000
parents bd4f660eb75a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
367
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 ********************************************************************************
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 ********************************************************************************
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : g_pitch.c
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : Compute the pitch (adaptive codebook) gain.
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 *
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 ********************************************************************************
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 /*
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 ********************************************************************************
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 * MODULE INCLUDE FILE AND VERSION ID
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 ********************************************************************************
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "namespace.h"
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "g_pitch.h"
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 /*
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 ********************************************************************************
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 * INCLUDE FILES
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 ********************************************************************************
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 #include "tw_amr.h"
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "typedef.h"
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "basic_op.h"
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "oper_32b.h"
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "no_count.h"
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "cnst.h"
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 /*
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 ********************************************************************************
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 * PUBLIC PROGRAM CODE
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 ********************************************************************************
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 /*************************************************************************
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 *
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 * FUNCTION: G_pitch
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 *
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 * PURPOSE: Compute the pitch (adaptive codebook) gain.
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 * Result in Q14 (NOTE: 12.2 bit exact using Q12)
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 *
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 * DESCRIPTION:
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 * The adaptive codebook gain is given by
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 *
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 * g = <x[], y[]> / <y[], y[]>
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 *
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 * where x[] is the target vector, y[] is the filtered adaptive
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 * codevector, and <> denotes dot product.
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 * The gain is limited to the range [0,1.2] (=0..19661 Q14)
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 *
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 *************************************************************************/
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 Word16 G_pitch ( /* o : Gain of pitch lag saturated to 1.2 */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 enum Mode mode, /* i : AMR mode */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 Word16 xn[], /* i : Pitch target. */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 Word16 y1[], /* i : Filtered adaptive codebook. */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 Word16 g_coeff[], /* i : Correlations need for gain quantization */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 Word16 L_subfr /* i : Length of subframe. */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 )
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 {
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 Word16 i;
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 Word16 xy, yy, exp_xy, exp_yy, gain;
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 Word32 s;
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 Word16 scaled_y1[L_SUBFR]; /* Usually dynamic allocation of (L_subfr) */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 /* divide "y1[]" by 4 to avoid overflow */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 for (i = 0; i < L_subfr; i++)
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 {
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 scaled_y1[i] = shr (y1[i], 2); move16 ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 /* Compute scalar product <y1[],y1[]> */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 /* Q12 scaling / MR122 */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 Overflow = 0; move16 ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 s = 1L; move32 (); /* Avoid case of all zeros */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 for (i = 0; i < L_subfr; i++)
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 {
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 s = L_mac (s, y1[i], y1[i]);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 test ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (Overflow == 0) /* Test for overflow */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 {
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 exp_yy = norm_l (s);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 yy = round (L_shl (s, exp_yy));
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 else
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 {
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 s = 1L; move32 (); /* Avoid case of all zeros */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 for (i = 0; i < L_subfr; i++)
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 {
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 s = L_mac (s, scaled_y1[i], scaled_y1[i]);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 exp_yy = norm_l (s);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 yy = round (L_shl (s, exp_yy));
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 exp_yy = sub (exp_yy, 4);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 }
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 /* Compute scalar product <xn[],y1[]> */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 Overflow = 0; move16 ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 s = 1L; move32 (); /* Avoid case of all zeros */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 for (i = 0; i < L_subfr; i++)
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 {
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 s = L_mac(s, xn[i], y1[i]);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 }
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 test ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 if (Overflow == 0)
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 {
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 exp_xy = norm_l (s);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 xy = round (L_shl (s, exp_xy));
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 }
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 else
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 {
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 s = 1L; move32 (); /* Avoid case of all zeros */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 for (i = 0; i < L_subfr; i++)
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 {
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 s = L_mac (s, xn[i], scaled_y1[i]);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 }
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 exp_xy = norm_l (s);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 xy = round (L_shl (s, exp_xy));
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 exp_xy = sub (exp_xy, 2);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 }
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 g_coeff[0] = yy; move16 ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 g_coeff[1] = sub (15, exp_yy); move16 ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 g_coeff[2] = xy; move16 ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 g_coeff[3] = sub (15, exp_xy); move16 ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 /* If (xy < 4) gain = 0 */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 i = sub (xy, 4);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 test ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 if (i < 0)
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 return ((Word16) 0);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 /* compute gain = xy/yy */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 xy = shr (xy, 1); /* Be sure xy < yy */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 gain = div_s (xy, yy);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 i = sub (exp_xy, exp_yy); /* Denormalization of division */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 gain = shr (gain, i);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 /* if(gain >1.2) gain = 1.2 */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 test ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 if (sub (gain, 19661) > 0)
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 {
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 gain = 19661; move16 ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 }
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 test ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 if (sub(mode, MR122) == 0)
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 {
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 /* clear 2 LSBits */
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 gain = gain & 0xfffC; logic16 ();
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 }
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 return (gain);
bd4f660eb75a libtwamr: integrate g_pitch.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 }