annotate src/q_gains.c @ 7:1fd613cec7ab

Theory-and-mystery: document written
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Apr 2024 17:14:41 +0000
parents 56410792419a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*--------------------------------------------------------------------------*
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Function q_gain_pitch(), q_gain_code() *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * Scalar quantization of the pitch gain and the innovative codebook gain. *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * MA prediction is performed on the innovation energy *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * (in dB/(20*log10(2))) with mean removed. *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 *-------------------------------------------------------------------------*/
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "typedef.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "basic_op.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "oper_32b.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "count.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "sig_proc.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "gains_tb.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "cnst.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "dtx.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 /* past quantized energies. */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 /* initialized to -14.0/constant, constant = 20*Log10(2) */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 Word16 past_qua_en[4];
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 /* MA prediction coeff */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 Word16 pred[4];
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 extern Word16 CN_excitation_gain, gain_code_old_tx[4 * DTX_HANGOVER];
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 Word16 q_gain_pitch ( /* Return index of quantization */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 Word16 *gain /* (i) : Pitch gain to quantize */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 )
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 Word16 i, index, gain_q14, err, err_min;
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 gain_q14 = shl (*gain, 2);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 err_min = abs_s (sub (gain_q14, qua_gain_pitch[0]));
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 index = 0; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 for (i = 1; i < NB_QUA_PITCH; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 err = abs_s (sub (gain_q14, qua_gain_pitch[i]));
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 test ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (sub (err, err_min) < 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 err_min = err; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 index = i; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 *gain = shr (qua_gain_pitch[index], 2); move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return index;
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 /* average innovation energy. */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 /* MEAN_ENER = 36.0/constant, constant = 20*Log10(2) */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 #define MEAN_ENER 783741L /* 36/(20*log10(2)) */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 Word16 q_gain_code ( /* Return quantization index */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 Word16 code[], /* (i) : fixed codebook excitation */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 Word16 lcode, /* (i) : codevector size */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 Word16 *gain, /* (i/o) : quantized fixed codebook gain */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 Word16 txdtx_ctrl,
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 Word16 i_subfr
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 )
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 Word16 i, index;
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 Word16 gcode0, err, err_min, exp, frac;
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 Word32 ener, ener_code;
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 Word16 aver_gain;
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 static Word16 gcode0_CN;
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 logic16 (); test ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if ((txdtx_ctrl & TX_SP_FLAG) != 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 /*-------------------------------------------------------------------*
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 * energy of code: *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 * ~~~~~~~~~~~~~~~ *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 * ener_code(Q17) = 10 * Log10(energy/lcode) / constant *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 * = 1/2 * Log2(energy/lcode) *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 * constant = 20*Log10(2) *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 *-------------------------------------------------------------------*/
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 /* ener_code = log10(ener_code/lcode) / (20*log10(2)) */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 ener_code = 0; move32 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 for (i = 0; i < lcode; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 ener_code = L_mac (ener_code, code[i], code[i]);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 /* ener_code = ener_code / lcode */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 ener_code = L_mult (round (ener_code), 26214);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 /* ener_code = 1/2 * Log2(ener_code) */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 Log2 (ener_code, &exp, &frac);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 ener_code = L_Comp (sub (exp, 30), frac);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 /* predicted energy */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 ener = MEAN_ENER; move32 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 for (i = 0; i < 4; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 ener = L_mac (ener, past_qua_en[i], pred[i]);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 /*-------------------------------------------------------------------*
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 * predicted codebook gain *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 * ~~~~~~~~~~~~~~~~~~~~~~~ *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 * gcode0(Qx) = Pow10( (ener*constant - ener_code*constant) / 20 ) *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 * = Pow2(ener-ener_code) *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 * constant = 20*Log10(2) *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 *-------------------------------------------------------------------*/
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 ener = L_shr (L_sub (ener, ener_code), 1);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 L_Extract (ener, &exp, &frac);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 gcode0 = extract_l (Pow2 (exp, frac)); /* predicted gain */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 gcode0 = shl (gcode0, 4);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 /*-------------------------------------------------------------------*
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 * Search for best quantizer *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 *-------------------------------------------------------------------*/
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 err_min = abs_s (sub (*gain, mult (gcode0, qua_gain_code[0])));
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 index = 0; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 for (i = 1; i < NB_QUA_CODE; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 err = abs_s (sub (*gain, mult (gcode0, qua_gain_code[i])));
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 test ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 if (sub (err, err_min) < 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 err_min = err; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 index = i; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 *gain = mult (gcode0, qua_gain_code[index]);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 /*------------------------------------------------------------------*
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 * update table of past quantized energies *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 * past_qua_en(Q12) = 20 * Log10(qua_gain_code) / constant *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 * = Log2(qua_gain_code) *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 * constant = 20*Log10(2) *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 *------------------------------------------------------------------*/
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 for (i = 3; i > 0; i--)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 past_qua_en[i] = past_qua_en[i - 1];move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 Log2 (L_deposit_l (qua_gain_code[index]), &exp, &frac);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 past_qua_en[0] = shr (frac, 5); move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 past_qua_en[0] = add (past_qua_en[0], shl (sub (exp, 11), 10));
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 update_gain_code_history_tx (*gain, gain_code_old_tx);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 else
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 logic16 (); test (); test ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 if ((txdtx_ctrl & TX_PREV_HANGOVER_ACTIVE) != 0 && (i_subfr == 0))
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 gcode0_CN = update_gcode0_CN (gain_code_old_tx);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 gcode0_CN = shl (gcode0_CN, 4);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 *gain = CN_excitation_gain; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 logic16 (); test (); test ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 if ((txdtx_ctrl & TX_SID_UPDATE) != 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 aver_gain = aver_gain_code_history (CN_excitation_gain,
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 gain_code_old_tx);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 /*---------------------------------------------------------------*
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 * Search for best quantizer *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 *---------------------------------------------------------------*/
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 err_min = abs_s (sub (aver_gain,
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 mult (gcode0_CN, qua_gain_code[0])));
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 index = 0; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 for (i = 1; i < NB_QUA_CODE; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 err = abs_s (sub (aver_gain,
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 mult (gcode0_CN, qua_gain_code[i])));
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 test ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 if (sub (err, err_min) < 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 err_min = err; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 index = i; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 update_gain_code_history_tx (*gain, gain_code_old_tx);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 /*-------------------------------------------------------------------*
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 * reset table of past quantized energies *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 *-------------------------------------------------------------------*/
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 for (i = 0; i < 4; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 past_qua_en[i] = -2381; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 return index;
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 }