annotate libtwamr/gc_pred.c @ 337:190c4c9a3693

libtwamr: integrate pow2.c
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 18 Apr 2024 23:06:59 +0000
parents 7f99b8ed30e5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
336
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 *****************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 *****************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : gc_pred.c
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : codebook gain MA prediction
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 *****************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 /*
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 *****************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 * MODULE INCLUDE FILE AND VERSION ID
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 *****************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "namespace.h"
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include "gc_pred.h"
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 /*
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 *****************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * INCLUDE FILES
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 *****************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "typedef.h"
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "basic_op.h"
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "oper_32b.h"
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "cnst.h"
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "no_count.h"
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #include "log2.h"
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #include "memops.h"
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 /*
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 *****************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 * LOCAL VARIABLES AND TABLES
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 *****************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 #define NPRED 4 /* number of prediction taps */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 /* MA prediction coefficients (Q13) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 static const Word16 pred[NPRED] = {5571, 4751, 2785, 1556};
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 /* average innovation energy. */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 /* MEAN_ENER = 36.0/constant, constant = 20*Log10(2) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 #define MEAN_ENER_MR122 783741L /* 36/(20*log10(2)) (Q17) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 /* MA prediction coefficients (Q6) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 static const Word16 pred_MR122[NPRED] = {44, 37, 22, 12};
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 /* minimum quantized energy: -14 dB */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 #define MIN_ENERGY -14336 /* 14 Q10 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 #define MIN_ENERGY_MR122 -2381 /* 14 / (20*log10(2)) Q10 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 /*
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 *****************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 * PUBLIC PROGRAM CODE
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 *****************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 /*************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 * Function: gc_pred_reset
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 * Purpose: Initializes state memory to zero
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 **************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 void gc_pred_reset (gc_predState *state)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 Word16 i;
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 for(i = 0; i < NPRED; i++)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 state->past_qua_en[i] = MIN_ENERGY;
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 state->past_qua_en_MR122[i] = MIN_ENERGY_MR122;
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 /*************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 * FUNCTION: gc_pred_copy()
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 * PURPOSE: Copy MA predictor state variable
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 *************************************************************************/
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 void
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 gc_pred_copy(
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 gc_predState *st_src, /* i : State struct */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 gc_predState *st_dest /* o : State struct */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 )
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 Copy (st_src->past_qua_en, st_dest->past_qua_en, NPRED);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 Copy (st_src->past_qua_en_MR122, st_dest->past_qua_en_MR122, NPRED);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 /*************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 * FUNCTION: gc_pred()
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 * PURPOSE: MA prediction of the innovation energy
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 * (in dB/(20*log10(2))) with mean removed).
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 *************************************************************************/
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 void
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 gc_pred(
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 gc_predState *st, /* i/o: State struct */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 enum Mode mode, /* i : AMR mode */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 Word16 *code, /* i : innovative codebook vector (L_SUBFR) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 /* MR122: Q12, other modes: Q13 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 Word16 *exp_gcode0, /* o : exponent of predicted gain factor, Q0 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 Word16 *frac_gcode0,/* o : fraction of predicted gain factor Q15 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 Word16 *exp_en, /* o : exponent of innovation energy, Q0 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 /* (only calculated for MR795) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 Word16 *frac_en /* o : fraction of innovation energy, Q15 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 /* (only calculated for MR795) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 )
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 Word16 i;
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 Word32 ener_code;
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 Word16 exp, frac;
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 /*-------------------------------------------------------------------*
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 * energy of code: *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 * ~~~~~~~~~~~~~~~ *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 * ener_code = sum(code[i]^2) *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 *-------------------------------------------------------------------*/
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 ener_code = L_mac((Word32) 0, code[0], code[0]);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 /* MR122: Q12*Q12 -> Q25 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 /* others: Q13*Q13 -> Q27 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 for (i = 1; i < L_SUBFR; i++)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 ener_code = L_mac(ener_code, code[i], code[i]);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 test ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 if (sub (mode, MR122) == 0)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 Word32 ener;
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 /* ener_code = ener_code / lcode; lcode = 40; 1/40 = 26214 Q20 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 ener_code = L_mult (round (ener_code), 26214); /* Q9 * Q20 -> Q30 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 /*-------------------------------------------------------------------*
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 * energy of code: *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 * ~~~~~~~~~~~~~~~ *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 * ener_code(Q17) = 10 * Log10(energy) / constant *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 * = 1/2 * Log2(energy) *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 * constant = 20*Log10(2) *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 *-------------------------------------------------------------------*/
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 /* ener_code = 1/2 * Log2(ener_code); Note: Log2=log2+30 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 Log2(ener_code, &exp, &frac);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 ener_code = L_Comp (sub (exp, 30), frac); /* Q16 for log() */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 /* ->Q17 for 1/2 log()*/
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 /*-------------------------------------------------------------------*
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 * predicted energy: *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 * ~~~~~~~~~~~~~~~~~ *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 * ener(Q24) = (Emean + sum{pred[i]*past_en[i]})/constant *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 * = MEAN_ENER + sum(pred[i]*past_qua_en[i]) *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 * constant = 20*Log10(2) *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 *-------------------------------------------------------------------*/
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 ener = MEAN_ENER_MR122; move32 (); /* Q24 (Q17) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 for (i = 0; i < NPRED; i++)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 ener = L_mac (ener, st->past_qua_en_MR122[i], pred_MR122[i]);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 /* Q10 * Q13 -> Q24 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 /* Q10 * Q6 -> Q17 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 /*-------------------------------------------------------------------*
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 * predicted codebook gain *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 * ~~~~~~~~~~~~~~~~~~~~~~~ *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 * gc0 = Pow10( (ener*constant - ener_code*constant) / 20 ) *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 * = Pow2(ener-ener_code) *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 * = Pow2(int(d)+frac(d)) *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 * *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 * (store exp and frac for pow2()) *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 *-------------------------------------------------------------------*/
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 ener = L_shr (L_sub (ener, ener_code), 1); /* Q16 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 L_Extract(ener, exp_gcode0, frac_gcode0);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 else /* all modes except 12.2 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 Word32 L_tmp;
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 Word16 exp_code, gcode0;
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 /*-----------------------------------------------------------------*
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 * Compute: means_ener - 10log10(ener_code/ L_sufr) *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 *-----------------------------------------------------------------*/
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 exp_code = norm_l (ener_code);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 ener_code = L_shl (ener_code, exp_code);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 /* Log2 = log2 + 27 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 Log2_norm (ener_code, exp_code, &exp, &frac);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 /* fact = 10/log2(10) = 3.01 = 24660 Q13 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 L_tmp = Mpy_32_16(exp, frac, -24660); /* Q0.Q15 * Q13 -> Q14 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 /* L_tmp = means_ener - 10log10(ener_code/L_SUBFR)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 * = means_ener - 10log10(ener_code) + 10log10(L_SUBFR)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 * = K - fact * Log2(ener_code)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 * = K - fact * log2(ener_code) - fact*27
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 * ==> K = means_ener + fact*27 + 10log10(L_SUBFR)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 * means_ener = 33 = 540672 Q14 (MR475, MR515, MR59)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 * means_ener = 28.75 = 471040 Q14 (MR67)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 * means_ener = 30 = 491520 Q14 (MR74)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 * means_ener = 36 = 589824 Q14 (MR795)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 * means_ener = 33 = 540672 Q14 (MR102)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 * 10log10(L_SUBFR) = 16.02 = 262481.51 Q14
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 * fact * 27 = 1331640 Q14
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 * -----------------------------------------
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 * (MR475, MR515, MR59) K = 2134793.51 Q14 ~= 16678 * 64 * 2
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 * (MR67) K = 2065161.51 Q14 ~= 32268 * 32 * 2
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 * (MR74) K = 2085641.51 Q14 ~= 32588 * 32 * 2
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 * (MR795) K = 2183945.51 Q14 ~= 17062 * 64 * 2
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 * (MR102) K = 2134793.51 Q14 ~= 16678 * 64 * 2
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 if (test (), sub (mode, MR102) == 0)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 /* mean = 33 dB */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 L_tmp = L_mac(L_tmp, 16678, 64); /* Q14 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 else if (test (), sub (mode, MR795) == 0)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 /* ener_code = <xn xn> * 2^27*2^exp_code
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 frac_en = ener_code / 2^16
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 = <xn xn> * 2^11*2^exp_code
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 <xn xn> = <xn xn>*2^11*2^exp * 2^exp_en
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 := frac_en * 2^exp_en
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 ==> exp_en = -11-exp_code;
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 *frac_en = extract_h (ener_code); move16 ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 *exp_en = sub (-11, exp_code); move16 ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 /* mean = 36 dB */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 L_tmp = L_mac(L_tmp, 17062, 64); /* Q14 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 else if (test (), sub (mode, MR74) == 0)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 /* mean = 30 dB */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 L_tmp = L_mac(L_tmp, 32588, 32); /* Q14 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 else if (test (), sub (mode, MR67) == 0)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 /* mean = 28.75 dB */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 L_tmp = L_mac(L_tmp, 32268, 32); /* Q14 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 else /* MR59, MR515, MR475 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 /* mean = 33 dB */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 L_tmp = L_mac(L_tmp, 16678, 64); /* Q14 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 /*-----------------------------------------------------------------*
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 * Compute gcode0. *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 * = Sum(i=0,3) pred[i]*past_qua_en[i] - ener_code + mean_ener *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 *-----------------------------------------------------------------*/
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 L_tmp = L_shl(L_tmp, 10); /* Q24 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 for (i = 0; i < 4; i++)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 L_tmp = L_mac(L_tmp, pred[i], st->past_qua_en[i]);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 /* Q13 * Q10 -> Q24 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 gcode0 = extract_h(L_tmp); /* Q8 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 /*-----------------------------------------------------------------*
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 * gcode0 = pow(10.0, gcode0/20) *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 * = pow(2, 3.3219*gcode0/20) *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 * = pow(2, 0.166*gcode0) *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 *-----------------------------------------------------------------*/
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 /* 5439 Q15 = 0.165985 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 /* (correct: 1/(20*log10(2)) 0.166096 = 5443 Q15) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 test ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 if (sub (mode, MR74) == 0) /* For IS641 bitexactness */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 L_tmp = L_mult(gcode0, 5439); /* Q8 * Q15 -> Q24 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 else
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 L_tmp = L_mult(gcode0, 5443); /* Q8 * Q15 -> Q24 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 L_tmp = L_shr(L_tmp, 8); /* -> Q16 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 L_Extract(L_tmp, exp_gcode0, frac_gcode0); /* -> Q0.Q15 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 /*************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 * FUNCTION: gc_pred_update()
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 * PURPOSE: update MA predictor with last quantized energy
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 *************************************************************************/
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 void gc_pred_update(
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 gc_predState *st, /* i/o: State struct */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 Word16 qua_ener_MR122, /* i : quantized energy for update, Q10 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 /* (log2(qua_err)) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 Word16 qua_ener /* i : quantized energy for update, Q10 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 /* (20*log10(qua_err)) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 )
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 Word16 i;
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 for (i = 3; i > 0; i--)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 st->past_qua_en[i] = st->past_qua_en[i - 1]; move16 ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 st->past_qua_en_MR122[i] = st->past_qua_en_MR122[i - 1]; move16 ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 st->past_qua_en_MR122[0] = qua_ener_MR122; /* log2 (qua_err), Q10 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317 move16 ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 st->past_qua_en[0] = qua_ener; /* 20*log10(qua_err), Q10 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 move16 ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322 /*************************************************************************
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324 * FUNCTION: gc_pred_average_limited()
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 * PURPOSE: get average of MA predictor state values (with a lower limit)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327 * [used in error concealment]
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328 *
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 *************************************************************************/
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 void gc_pred_average_limited(
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 gc_predState *st, /* i: State struct */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332 Word16 *ener_avg_MR122, /* o: everaged quantized energy, Q10 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 /* (log2(qua_err)) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 Word16 *ener_avg /* o: averaged quantized energy, Q10 */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 /* (20*log10(qua_err)) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336 )
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 Word16 av_pred_en;
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
339 Word16 i;
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341 /* do average in MR122 mode (log2() domain) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
342 av_pred_en = 0; move16 ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343 for (i = 0; i < NPRED; i++)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
345 av_pred_en = add (av_pred_en, st->past_qua_en_MR122[i]);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
348 /* av_pred_en = 0.25*av_pred_en */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
349 av_pred_en = mult (av_pred_en, 8192);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
350
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
351 /* if (av_pred_en < -14/(20Log10(2))) av_pred_en = .. */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
352 test ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353 if (sub (av_pred_en, MIN_ENERGY_MR122) < 0)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
354 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355 av_pred_en = MIN_ENERGY_MR122; move16 ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357 *ener_avg_MR122 = av_pred_en; move16 ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
358
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359 /* do average for other modes (20*log10() domain) */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
360 av_pred_en = 0; move16 ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
361 for (i = 0; i < NPRED; i++)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
362 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
363 av_pred_en = add (av_pred_en, st->past_qua_en[i]);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
364 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
365
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
366 /* av_pred_en = 0.25*av_pred_en */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
367 av_pred_en = mult (av_pred_en, 8192);
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
368
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
369 /* if (av_pred_en < -14) av_pred_en = .. */
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
370 test ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
371 if (sub (av_pred_en, MIN_ENERGY) < 0)
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
372 {
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
373 av_pred_en = MIN_ENERGY; move16 ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
374 }
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
375 *ener_avg = av_pred_en; move16 ();
7f99b8ed30e5 libtwamr: integrate gc_pred.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
376 }