FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/gain_q.c @ 555:62943a1ad64e
doc/FR1-Rx-DTX-detail: grammar fix
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 11 Oct 2024 00:22:47 +0000 |
parents | ccba5812fa44 |
children |
rev | line source |
---|---|
378
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ******************************************************************************** |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ******************************************************************************** |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : gain_q.c |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * Purpose : Quantazation of gains |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 ******************************************************************************** |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 /* |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 ******************************************************************************** |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 * MODULE INCLUDE FILE AND VERSION ID |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 ******************************************************************************** |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "namespace.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include "gain_q.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 /* |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 ******************************************************************************** |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 * INCLUDE FILES |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 ******************************************************************************** |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #include "tw_amr.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "typedef.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "basic_op.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include "no_count.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #include "qua_gain.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #include "cnst.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 #include "g_code.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 #include "q_gain_c.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 #include "gc_pred.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 #include "calc_en.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 #include "qgain795.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 #include "qgain475.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 #include "memops.h" |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 /* |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 ******************************************************************************** |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 * PUBLIC PROGRAM CODE |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 ******************************************************************************** |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 /************************************************************************* |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 * Function: gainQuant_reset |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 * Purpose: Initializes state memory to zero |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 ************************************************************************** |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 void gainQuant_reset (gainQuantState *state) |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 { |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 state->sf0_exp_gcode0 = 0; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 state->sf0_frac_gcode0 = 0; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 state->sf0_exp_target_en = 0; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 state->sf0_frac_target_en = 0; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 Set_zero (state->sf0_exp_coeff, 5); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 Set_zero (state->sf0_frac_coeff, 5); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 gc_pred_reset(&state->gc_predSt); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 gc_pred_reset(&state->gc_predUnqSt); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 gain_adapt_reset(&state->adaptSt); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 int gainQuant( |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 gainQuantState *st, /* i/o : State struct */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 enum Mode mode, /* i : coder mode */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 Word16 res[], /* i : LP residual, Q0 */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 Word16 exc[], /* i : LTP excitation (unfiltered), Q0 */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 Word16 code[], /* i : CB innovation (unfiltered), Q13 */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 /* (unsharpened for MR475) */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 Word16 xn[], /* i : Target vector. */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 Word16 xn2[], /* i : Target vector. */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 Word16 y1[], /* i : Adaptive codebook. */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 Word16 Y2[], /* i : Filtered innovative vector. */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 Word16 g_coeff[], /* i : Correlations <xn y1> <y1 y1> */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 /* Compute in G_pitch(). */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 Word16 even_subframe, /* i : even subframe indicator flag */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 Word16 gp_limit, /* i : pitch gain limit */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 Word16 *sf0_gain_pit, /* o : Pitch gain sf 0. MR475 */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 Word16 *sf0_gain_cod, /* o : Code gain sf 0. MR475 */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 Word16 *gain_pit, /* i/o : Pitch gain. */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 Word16 *gain_cod, /* o : Code gain. */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 /* MR475: gain_* unquantized in even */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 /* subframes, quantized otherwise */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 Word16 **anap /* o : Index of quantization */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 ) |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 { |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 Word16 exp_gcode0; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 Word16 frac_gcode0; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 Word16 qua_ener_MR122; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 Word16 qua_ener; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 Word16 frac_coeff[5]; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 Word16 exp_coeff[5]; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 Word16 exp_en, frac_en; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 Word16 cod_gain_exp, cod_gain_frac; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 test (); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 if (sub (mode, MR475) == 0) |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 { |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 test (); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 if (even_subframe != 0) |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 { |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 /* save position in output parameter stream and current |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 state of codebook gain predictor */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 st->gain_idx_ptr = (*anap)++; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 gc_pred_copy(&st->gc_predSt, &st->gc_predUnqSt); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 /* predict codebook gain (using "unquantized" predictor)*/ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 /* (note that code[] is unsharpened in MR475) */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 gc_pred(&st->gc_predUnqSt, mode, code, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 &st->sf0_exp_gcode0, &st->sf0_frac_gcode0, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 &exp_en, &frac_en); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 /* calculate energy coefficients for quantization |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 and store them in state structure (will be used |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 in next subframe when real quantizer is run) */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 calc_filt_energies(mode, xn, xn2, y1, Y2, g_coeff, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 st->sf0_frac_coeff, st->sf0_exp_coeff, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 &cod_gain_frac, &cod_gain_exp); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 /* store optimum codebook gain (Q1) */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 *gain_cod = shl (cod_gain_frac, add (cod_gain_exp, 1)); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 move16 (); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 calc_target_energy(xn, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 &st->sf0_exp_target_en, &st->sf0_frac_target_en); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 /* calculate optimum codebook gain and update |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 "unquantized" predictor */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 MR475_update_unq_pred(&st->gc_predUnqSt, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 st->sf0_exp_gcode0, st->sf0_frac_gcode0, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 cod_gain_exp, cod_gain_frac); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 /* the real quantizer is not run here... */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 } |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 else |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 { |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 /* predict codebook gain (using "unquantized" predictor) */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 /* (note that code[] is unsharpened in MR475) */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 gc_pred(&st->gc_predUnqSt, mode, code, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 &exp_gcode0, &frac_gcode0, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 &exp_en, &frac_en); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 /* calculate energy coefficients for quantization */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 calc_filt_energies(mode, xn, xn2, y1, Y2, g_coeff, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 frac_coeff, exp_coeff, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 &cod_gain_frac, &cod_gain_exp); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 calc_target_energy(xn, &exp_en, &frac_en); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 /* run real (4-dim) quantizer and update real gain predictor */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 *st->gain_idx_ptr = MR475_gain_quant( |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 &st->gc_predSt, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 st->sf0_exp_gcode0, st->sf0_frac_gcode0, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 st->sf0_exp_coeff, st->sf0_frac_coeff, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 st->sf0_exp_target_en, st->sf0_frac_target_en, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 code, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 exp_gcode0, frac_gcode0, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 exp_coeff, frac_coeff, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 exp_en, frac_en, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 gp_limit, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 sf0_gain_pit, sf0_gain_cod, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 gain_pit, gain_cod); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 } |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 } |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 else |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 { |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 /*-------------------------------------------------------------------* |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 * predict codebook gain and quantize * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 * (also compute normalized CB innovation energy for MR795) * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 *-------------------------------------------------------------------*/ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 gc_pred(&st->gc_predSt, mode, code, &exp_gcode0, &frac_gcode0, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 &exp_en, &frac_en); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 test (); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 if (sub(mode, MR122) == 0) |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 { |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 *gain_cod = G_code (xn2, Y2); move16 (); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 *(*anap)++ = q_gain_code (mode, exp_gcode0, frac_gcode0, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 gain_cod, &qua_ener_MR122, &qua_ener); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 move16 (); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 } |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 else |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 { |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 /* calculate energy coefficients for quantization */ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 calc_filt_energies(mode, xn, xn2, y1, Y2, g_coeff, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 frac_coeff, exp_coeff, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 &cod_gain_frac, &cod_gain_exp); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 test (); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 if (sub (mode, MR795) == 0) |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 { |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 MR795_gain_quant(&st->adaptSt, res, exc, code, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 frac_coeff, exp_coeff, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 exp_en, frac_en, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 exp_gcode0, frac_gcode0, L_SUBFR, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 cod_gain_frac, cod_gain_exp, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 gp_limit, gain_pit, gain_cod, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 &qua_ener_MR122, &qua_ener, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 anap); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 } |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 else |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 { |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 *(*anap)++ = Qua_gain(mode, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 exp_gcode0, frac_gcode0, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 frac_coeff, exp_coeff, gp_limit, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 gain_pit, gain_cod, |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 &qua_ener_MR122, &qua_ener); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 move16 (); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 } |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 } |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 /*------------------------------------------------------------------* |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 * update table of past quantized energies * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 * st->past_qua_en(Q10) = 20 * Log10(qua_gain_code) / constant * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 * = Log2(qua_gain_code) * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 * = qua_ener * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 * constant = 20*Log10(2) * |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 *------------------------------------------------------------------*/ |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 gc_pred_update(&st->gc_predSt, qua_ener_MR122, qua_ener); |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 } |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 return 0; |
ccba5812fa44
libtwamr: integrate gain_q.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 } |