annotate libtwamr/calc_en.c @ 405:8fff74ca83e8

libtwamr: integrate ton_stab.c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 06 May 2024 23:23:40 +0000
parents 2df212a012af
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
327
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 ********************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 ********************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : calc_en.c
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : (pre-) quantization of pitch gain for MR795
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 ********************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 /*
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 ********************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 * MODULE INCLUDE FILE AND VERSION ID
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 ********************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "namespace.h"
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include "calc_en.h"
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 /*
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 ********************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * INCLUDE FILES
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 ********************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "typedef.h"
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "basic_op.h"
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "oper_32b.h"
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "no_count.h"
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "cnst.h"
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #include "log2.h"
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 /*
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 ********************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 * PUBLIC PROGRAM CODE
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 ********************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 /*************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 * FUNCTION: calc_unfilt_energies
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 * PURPOSE: calculation of several energy coefficients for unfiltered
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 * excitation signals and the LTP coding gain
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 * frac_en[0]*2^exp_en[0] = <res res> // LP residual energy
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 * frac_en[1]*2^exp_en[1] = <exc exc> // LTP residual energy
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 * frac_en[2]*2^exp_en[2] = <exc code> // LTP/CB innovation dot product
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 * frac_en[3]*2^exp_en[3] = <lres lres> // LTP residual energy
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 * // (lres = res - gain_pit*exc)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 * ltpg = log2(LP_res_en / LTP_res_en)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 *************************************************************************/
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 void
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 calc_unfilt_energies(
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 Word16 res[], /* i : LP residual, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 Word16 exc[], /* i : LTP excitation (unfiltered), Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 Word16 code[], /* i : CB innovation (unfiltered), Q13 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 Word16 gain_pit, /* i : pitch gain, Q14 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 Word16 L_subfr, /* i : Subframe length */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 Word16 frac_en[], /* o : energy coefficients (4), fraction part, Q15 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 Word16 exp_en[], /* o : energy coefficients (4), exponent part, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 Word16 *ltpg /* o : LTP coding gain (log2()), Q13 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 )
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 Word32 s, L_temp;
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 Word16 i, exp, tmp;
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 Word16 ltp_res_en, pred_gain;
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 Word16 ltpg_exp, ltpg_frac;
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 /* Compute residual energy */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 s = L_mac((Word32) 0, res[0], res[0]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 for (i = 1; i < L_subfr; i++)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 s = L_mac(s, res[i], res[i]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 /* ResEn := 0 if ResEn < 200.0 (= 400 Q1) */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 test();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (L_sub (s, 400L) < 0)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 frac_en[0] = 0; move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 exp_en[0] = -15; move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 else
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 exp = norm_l(s);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 frac_en[0] = extract_h(L_shl(s, exp)); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 exp_en[0] = sub(15, exp); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 /* Compute ltp excitation energy */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 s = L_mac((Word32) 0, exc[0], exc[0]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 for (i = 1; i < L_subfr; i++)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 s = L_mac(s, exc[i], exc[i]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 exp = norm_l(s);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 frac_en[1] = extract_h(L_shl(s, exp)); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 exp_en[1] = sub(15, exp); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 /* Compute scalar product <exc[],code[]> */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 s = L_mac((Word32) 0, exc[0], code[0]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 for (i = 1; i < L_subfr; i++)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 s = L_mac(s, exc[i], code[i]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 exp = norm_l(s);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 frac_en[2] = extract_h(L_shl(s, exp)); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 exp_en[2] = sub(16-14, exp); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 /* Compute energy of LTP residual */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 s = 0L; move32 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 for (i = 0; i < L_subfr; i++)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 L_temp = L_mult(exc[i], gain_pit);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 L_temp = L_shl(L_temp, 1);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 tmp = sub(res[i], round(L_temp)); /* LTP residual, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 s = L_mac (s, tmp, tmp);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 }
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 exp = norm_l(s);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 ltp_res_en = extract_h (L_shl (s, exp));
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 exp = sub (15, exp);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 frac_en[3] = ltp_res_en; move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 exp_en[3] = exp; move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 /* calculate LTP coding gain, i.e. energy reduction LP res -> LTP res */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 test (); test ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 if (ltp_res_en > 0 && frac_en[0] != 0)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 /* gain = ResEn / LTPResEn */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 pred_gain = div_s (shr (frac_en[0], 1), ltp_res_en);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 exp = sub (exp, exp_en[0]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 /* L_temp = ltpGain * 2^(30 + exp) */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 L_temp = L_deposit_h (pred_gain);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 /* L_temp = ltpGain * 2^27 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 L_temp = L_shr (L_temp, add (exp, 3));
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 /* Log2 = log2() + 27 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 Log2(L_temp, &ltpg_exp, &ltpg_frac);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 /* ltpg = log2(LtpGain) * 2^13 --> range: +- 4 = +- 12 dB */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 L_temp = L_Comp (sub (ltpg_exp, 27), ltpg_frac);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 *ltpg = round (L_shl (L_temp, 13)); /* Q13 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 }
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 else
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 *ltpg = 0; move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 }
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 }
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 /*************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 * FUNCTION: calc_filt_energies
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 * PURPOSE: calculation of several energy coefficients for filtered
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 * excitation signals
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 * Compute coefficients need for the quantization and the optimum
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 * codebook gain gcu (for MR475 only).
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 * coeff[0] = y1 y1
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 * coeff[1] = -2 xn y1
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 * coeff[2] = y2 y2
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 * coeff[3] = -2 xn y2
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 * coeff[4] = 2 y1 y2
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 * gcu = <xn2, y2> / <y2, y2> (0 if <xn2, y2> <= 0)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 * Product <y1 y1> and <xn y1> have been computed in G_pitch() and
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 * are in vector g_coeff[].
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 *************************************************************************/
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 void
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 calc_filt_energies(
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 enum Mode mode, /* i : coder mode */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 Word16 xn[], /* i : LTP target vector, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 Word16 xn2[], /* i : CB target vector, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 Word16 y1[], /* i : Adaptive codebook, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 Word16 Y2[], /* i : Filtered innovative vector, Q12 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 Word16 g_coeff[], /* i : Correlations <xn y1> <y1 y1> */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 /* computed in G_pitch() */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 Word16 frac_coeff[],/* o : energy coefficients (5), fraction part, Q15 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 Word16 exp_coeff[], /* o : energy coefficients (5), exponent part, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 Word16 *cod_gain_frac,/* o: optimum codebook gain (fraction part), Q15 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 Word16 *cod_gain_exp /* o: optimum codebook gain (exponent part), Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 )
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 Word32 s, ener_init;
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 Word16 i, exp, frac;
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 Word16 y2[L_SUBFR];
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 if (test(), sub(mode, MR795) == 0 || sub(mode, MR475) == 0)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 ener_init = 0L; move32 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 }
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 else
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 ener_init = 1L; move32 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 }
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 for (i = 0; i < L_SUBFR; i++) {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 y2[i] = shr(Y2[i], 3); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 }
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 frac_coeff[0] = g_coeff[0]; move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 exp_coeff[0] = g_coeff[1]; move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 frac_coeff[1] = negate(g_coeff[2]); move16 (); /* coeff[1] = -2 xn y1 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 exp_coeff[1] = add(g_coeff[3], 1); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 /* Compute scalar product <y2[],y2[]> */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 s = L_mac(ener_init, y2[0], y2[0]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 for (i = 1; i < L_SUBFR; i++)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 s = L_mac(s, y2[i], y2[i]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 exp = norm_l(s);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 frac_coeff[2] = extract_h(L_shl(s, exp)); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 exp_coeff[2] = sub(15 - 18, exp); move16();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 /* Compute scalar product -2*<xn[],y2[]> */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 s = L_mac(ener_init, xn[0], y2[0]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 for (i = 1; i < L_SUBFR; i++)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 s = L_mac(s, xn[i], y2[i]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 exp = norm_l(s);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 frac_coeff[3] = negate(extract_h(L_shl(s, exp))); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 exp_coeff[3] = sub(15 - 9 + 1, exp); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 /* Compute scalar product 2*<y1[],y2[]> */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 s = L_mac(ener_init, y1[0], y2[0]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 for (i = 1; i < L_SUBFR; i++)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 s = L_mac(s, y1[i], y2[i]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 exp = norm_l(s);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 frac_coeff[4] = extract_h(L_shl(s, exp)); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 exp_coeff[4] = sub(15 - 9 + 1, exp); move16();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 if (test(), test (), sub(mode, MR475) == 0 || sub(mode, MR795) == 0)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 /* Compute scalar product <xn2[],y2[]> */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 s = L_mac(ener_init, xn2[0], y2[0]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 for (i = 1; i < L_SUBFR; i++)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 s = L_mac(s, xn2[i], y2[i]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 exp = norm_l(s);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 frac = extract_h(L_shl(s, exp));
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 exp = sub(15 - 9, exp);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 if (test (), frac <= 0)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 *cod_gain_frac = 0; move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 *cod_gain_exp = 0; move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 }
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 else
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 /*
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 gcu = <xn2, y2> / c[2]
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 = (frac>>1)/frac[2] * 2^(exp+1-exp[2])
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 = div_s(frac>>1, frac[2])*2^-15 * 2^(exp+1-exp[2])
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 = div_s * 2^(exp-exp[2]-14)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 *cod_gain_frac = div_s (shr (frac,1), frac_coeff[2]); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 *cod_gain_exp = sub (sub (exp, exp_coeff[2]), 14); move16 ();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 }
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 }
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 }
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 /*************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 * FUNCTION: calc_target_energy
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 * PURPOSE: calculation of target energy
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 * en = <xn, xn>
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 *************************************************************************/
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 void
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 calc_target_energy(
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 Word16 xn[], /* i: LTP target vector, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 Word16 *en_exp, /* o: optimum codebook gain (exponent part), Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 Word16 *en_frac /* o: optimum codebook gain (fraction part), Q15 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 )
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 {
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 Word32 s;
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 Word16 i, exp;
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 /* Compute scalar product <xn[], xn[]> */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 s = L_mac(0L, xn[0], xn[0]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 for (i = 1; i < L_SUBFR; i++)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 s = L_mac(s, xn[i], xn[i]);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 /* s = SUM 2*xn(i) * xn(i) = <xn xn> * 2 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 exp = norm_l(s);
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 *en_frac = extract_h(L_shl(s, exp));
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 *en_exp = sub(16, exp); move16();
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309 }