FreeCalypso > hg > gsm-codec-lib
comparison libgsmefr/q_gains.c @ 88:03599300d2db
libgsmefr: q_gains.c compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 26 Nov 2022 11:21:22 +0000 |
parents | 49dd1ac8e75b |
children | 33487966077e |
comparison
equal
deleted
inserted
replaced
87:41d8e8f4058d | 88:03599300d2db |
---|---|
5 * * | 5 * * |
6 * MA prediction is performed on the innovation energy * | 6 * MA prediction is performed on the innovation energy * |
7 * (in dB/(20*log10(2))) with mean removed. * | 7 * (in dB/(20*log10(2))) with mean removed. * |
8 *-------------------------------------------------------------------------*/ | 8 *-------------------------------------------------------------------------*/ |
9 | 9 |
10 #include "gsm_efr.h" | |
10 #include "typedef.h" | 11 #include "typedef.h" |
12 #include "namespace.h" | |
11 #include "basic_op.h" | 13 #include "basic_op.h" |
12 #include "oper_32b.h" | 14 #include "oper_32b.h" |
13 #include "count.h" | 15 #include "no_count.h" |
14 #include "sig_proc.h" | 16 #include "sig_proc.h" |
17 #include "codec.h" | |
15 | 18 |
16 #include "gains_tb.h" | 19 #include "gains_tb.h" |
17 | 20 |
18 #include "cnst.h" | 21 #include "cnst.h" |
19 #include "dtx.h" | 22 #include "dtx.h" |
20 | 23 #include "enc_state.h" |
21 /* past quantized energies. */ | |
22 /* initialized to -14.0/constant, constant = 20*Log10(2) */ | |
23 Word16 past_qua_en[4]; | |
24 | |
25 /* MA prediction coeff */ | |
26 Word16 pred[4]; | |
27 | |
28 extern Word16 CN_excitation_gain, gain_code_old_tx[4 * DTX_HANGOVER]; | |
29 | 24 |
30 Word16 q_gain_pitch ( /* Return index of quantization */ | 25 Word16 q_gain_pitch ( /* Return index of quantization */ |
31 Word16 *gain /* (i) : Pitch gain to quantize */ | 26 Word16 *gain /* (i) : Pitch gain to quantize */ |
32 ) | 27 ) |
33 { | 28 { |
59 /* MEAN_ENER = 36.0/constant, constant = 20*Log10(2) */ | 54 /* MEAN_ENER = 36.0/constant, constant = 20*Log10(2) */ |
60 | 55 |
61 #define MEAN_ENER 783741L /* 36/(20*log10(2)) */ | 56 #define MEAN_ENER 783741L /* 36/(20*log10(2)) */ |
62 | 57 |
63 Word16 q_gain_code ( /* Return quantization index */ | 58 Word16 q_gain_code ( /* Return quantization index */ |
59 struct EFR_encoder_state *st, | |
64 Word16 code[], /* (i) : fixed codebook excitation */ | 60 Word16 code[], /* (i) : fixed codebook excitation */ |
65 Word16 lcode, /* (i) : codevector size */ | 61 Word16 lcode, /* (i) : codevector size */ |
66 Word16 *gain, /* (i/o) : quantized fixed codebook gain */ | 62 Word16 *gain, /* (i/o) : quantized fixed codebook gain */ |
67 Word16 txdtx_ctrl, | 63 Word16 txdtx_ctrl, |
68 Word16 i_subfr | 64 Word16 i_subfr |
70 { | 66 { |
71 Word16 i, index; | 67 Word16 i, index; |
72 Word16 gcode0, err, err_min, exp, frac; | 68 Word16 gcode0, err, err_min, exp, frac; |
73 Word32 ener, ener_code; | 69 Word32 ener, ener_code; |
74 Word16 aver_gain; | 70 Word16 aver_gain; |
75 static Word16 gcode0_CN; | 71 |
76 | |
77 logic16 (); test (); | |
78 if ((txdtx_ctrl & TX_SP_FLAG) != 0) | 72 if ((txdtx_ctrl & TX_SP_FLAG) != 0) |
79 { | 73 { |
80 | 74 |
81 /*-------------------------------------------------------------------* | 75 /*-------------------------------------------------------------------* |
82 * energy of code: * | 76 * energy of code: * |
102 /* predicted energy */ | 96 /* predicted energy */ |
103 | 97 |
104 ener = MEAN_ENER; move32 (); | 98 ener = MEAN_ENER; move32 (); |
105 for (i = 0; i < 4; i++) | 99 for (i = 0; i < 4; i++) |
106 { | 100 { |
107 ener = L_mac (ener, past_qua_en[i], pred[i]); | 101 ener = L_mac (ener, st->past_qua_en[i], st->pred[i]); |
108 } | 102 } |
109 | 103 |
110 /*-------------------------------------------------------------------* | 104 /*-------------------------------------------------------------------* |
111 * predicted codebook gain * | 105 * predicted codebook gain * |
112 * ~~~~~~~~~~~~~~~~~~~~~~~ * | 106 * ~~~~~~~~~~~~~~~~~~~~~~~ * |
152 * constant = 20*Log10(2) * | 146 * constant = 20*Log10(2) * |
153 *------------------------------------------------------------------*/ | 147 *------------------------------------------------------------------*/ |
154 | 148 |
155 for (i = 3; i > 0; i--) | 149 for (i = 3; i > 0; i--) |
156 { | 150 { |
157 past_qua_en[i] = past_qua_en[i - 1];move16 (); | 151 st->past_qua_en[i] = st->past_qua_en[i - 1]; |
158 } | 152 } |
159 Log2 (L_deposit_l (qua_gain_code[index]), &exp, &frac); | 153 Log2 (L_deposit_l (qua_gain_code[index]), &exp, &frac); |
160 | 154 |
161 past_qua_en[0] = shr (frac, 5); move16 (); | 155 st->past_qua_en[0] = shr (frac, 5); |
162 past_qua_en[0] = add (past_qua_en[0], shl (sub (exp, 11), 10)); | 156 st->past_qua_en[0] = add (st->past_qua_en[0], shl (sub (exp, 11), 10)); |
163 move16 (); | 157 |
164 | 158 update_gain_code_history_tx (st, *gain); |
165 update_gain_code_history_tx (*gain, gain_code_old_tx); | |
166 } | 159 } |
167 else | 160 else |
168 { | 161 { |
169 logic16 (); test (); test (); | |
170 if ((txdtx_ctrl & TX_PREV_HANGOVER_ACTIVE) != 0 && (i_subfr == 0)) | 162 if ((txdtx_ctrl & TX_PREV_HANGOVER_ACTIVE) != 0 && (i_subfr == 0)) |
171 { | 163 { |
172 gcode0_CN = update_gcode0_CN (gain_code_old_tx); | 164 st->gcode0_CN = update_gcode0_CN (st->gain_code_old_tx); |
173 gcode0_CN = shl (gcode0_CN, 4); | 165 st->gcode0_CN = shl (st->gcode0_CN, 4); |
174 } | 166 } |
175 *gain = CN_excitation_gain; move16 (); | 167 *gain = st->CN_excitation_gain; |
176 | 168 |
177 logic16 (); test (); test (); | |
178 if ((txdtx_ctrl & TX_SID_UPDATE) != 0) | 169 if ((txdtx_ctrl & TX_SID_UPDATE) != 0) |
179 { | 170 { |
180 aver_gain = aver_gain_code_history (CN_excitation_gain, | 171 aver_gain = aver_gain_code_history (st->CN_excitation_gain, |
181 gain_code_old_tx); | 172 st->gain_code_old_tx); |
182 | 173 |
183 /*---------------------------------------------------------------* | 174 /*---------------------------------------------------------------* |
184 * Search for best quantizer * | 175 * Search for best quantizer * |
185 *---------------------------------------------------------------*/ | 176 *---------------------------------------------------------------*/ |
186 | 177 |
187 err_min = abs_s (sub (aver_gain, | 178 err_min = abs_s (sub (aver_gain, |
188 mult (gcode0_CN, qua_gain_code[0]))); | 179 mult (st->gcode0_CN, qua_gain_code[0]))); |
189 index = 0; move16 (); | 180 index = 0; |
190 | 181 |
191 for (i = 1; i < NB_QUA_CODE; i++) | 182 for (i = 1; i < NB_QUA_CODE; i++) |
192 { | 183 { |
193 err = abs_s (sub (aver_gain, | 184 err = abs_s (sub (aver_gain, |
194 mult (gcode0_CN, qua_gain_code[i]))); | 185 mult (st->gcode0_CN, qua_gain_code[i]))); |
195 | 186 |
196 test (); | |
197 if (sub (err, err_min) < 0) | 187 if (sub (err, err_min) < 0) |
198 { | 188 { |
199 err_min = err; move16 (); | 189 err_min = err; move16 (); |
200 index = i; move16 (); | 190 index = i; move16 (); |
201 } | 191 } |
202 } | 192 } |
203 } | 193 } |
204 update_gain_code_history_tx (*gain, gain_code_old_tx); | 194 update_gain_code_history_tx (st, *gain); |
205 | 195 |
206 /*-------------------------------------------------------------------* | 196 /*-------------------------------------------------------------------* |
207 * reset table of past quantized energies * | 197 * reset table of past quantized energies * |
208 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * | 198 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * |
209 *-------------------------------------------------------------------*/ | 199 *-------------------------------------------------------------------*/ |
210 | 200 |
211 for (i = 0; i < 4; i++) | 201 for (i = 0; i < 4; i++) |
212 { | 202 { |
213 past_qua_en[i] = -2381; move16 (); | 203 st->past_qua_en[i] = -2381; |
214 } | 204 } |
215 } | 205 } |
216 | 206 |
217 return index; | 207 return index; |
218 } | 208 } |