annotate libtwamr/calc_en.h @ 369:a01de4e40540

libtwamr: integrate q_gain_p.c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 06 May 2024 03:22:07 +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.h
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : calculation of energy coefficients for quantizers
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 #ifndef calc_en_h
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #define calc_en_h "$Id $"
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 /*
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 * INCLUDE FILES
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 ********************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 #include "tw_amr.h"
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 #include "typedef.h"
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 /*
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 * DECLARATION OF PROTOTYPES
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 ********************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 /*************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 * FUNCTION: calc_unfilt_energies
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 * PURPOSE: calculation of several energy coefficients for unfiltered
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 * excitation signals and the LTP coding gain
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 * 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
40 * 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
41 * 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
42 * 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
43 * // (lres = res - gain_pit*exc)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 * ltpg = log2(LP_res_en / LTP_res_en)
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 *************************************************************************/
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 void
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 calc_unfilt_energies(
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 Word16 res[], /* i : LP residual, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 Word16 exc[], /* i : LTP excitation (unfiltered), Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 Word16 code[], /* i : CB innovation (unfiltered), Q13 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 Word16 gain_pit, /* i : pitch gain, Q14 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 Word16 L_subfr, /* i : Subframe length */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 Word16 frac_en[], /* o : energy coefficients (3), fraction part, Q15 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 Word16 exp_en[], /* o : energy coefficients (3), exponent part, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 Word16 *ltpg /* o : LTP coding gain (log2()), Q13 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 );
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 /*************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 * FUNCTION: calc_filt_energies
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 * PURPOSE: calculation of several energy coefficients for filtered
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 * excitation signals
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 * Compute coefficients need for the quantization and the optimum
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 * codebook gain gcu (for MR475 only).
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 * coeff[0] = y1 y1
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 * coeff[1] = -2 xn y1
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 * coeff[2] = y2 y2
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 * coeff[3] = -2 xn y2
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 * coeff[4] = 2 y1 y2
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 * gcu = <xn2, y2> / <y2, y2> (0 if <xn2, y2> <= 0)
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 * 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
80 * are in vector g_coeff[].
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 *************************************************************************/
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 void
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 calc_filt_energies(
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 enum Mode mode, /* i : coder mode */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 Word16 xn[], /* i : LTP target vector, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 Word16 xn2[], /* i : CB target vector, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 Word16 y1[], /* i : Adaptive codebook, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 Word16 Y2[], /* i : Filtered innovative vector, Q12 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 Word16 g_coeff[], /* i : Correlations <xn y1> <y1 y1> */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 /* computed in G_pitch() */
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 Word16 frac_coeff[],/* o : energy coefficients (5), fraction part, Q15 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 Word16 exp_coeff[], /* o : energy coefficients (5), exponent part, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 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
96 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
97 );
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 /*************************************************************************
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 * FUNCTION: calc_target_energy
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 * PURPOSE: calculation of target energy
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 *
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 * en = <xn, xn>
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 *
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 void
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 calc_target_energy(
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 Word16 xn[], /* i: LTP target vector, Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 Word16 *en_exp, /* o: optimum codebook gain (exponent part), Q0 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 Word16 *en_frac /* o: optimum codebook gain (fraction part), Q15 */
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 );
2df212a012af libtwamr: integrate calc_en.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 #endif