Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 :
5 : #include <stdint.h>
6 : #include <assert.h>
7 : #include "options.h"
8 : #include "cnst.h"
9 : #include "rom_enc.h"
10 : #include "rom_com.h"
11 : #include "prot_fx.h" /* Function prototypes */
12 : #include "prot_fx_enc.h" /* Function prototypes */
13 : #include "basop_util.h"
14 : #include "rom_basop_util.h"
15 :
16 : /*-------------------------------------------------------------------*
17 : * local constants
18 : *--------------------------------------------------------------------*/
19 :
20 : #define MIN_LOG_FX 0
21 : #define MIN_LOG_VAL_FX -15360 /* -60.0f in Q8 */
22 :
23 : /*-------------------------------------------------------------------*
24 : * lpc_quantization_fx()
25 : *
26 : *
27 : *--------------------------------------------------------------------*/
28 1246 : void lpc_quantization_fx(
29 : Encoder_State *st,
30 : const Word16 lsp[], /* Q15 */
31 : const Word16 lspmid[], /* Q15 */
32 : Word16 lsp_q[], /* Q15 */
33 : Word16 lsf_q[], /* 14Q1*1.28 */
34 : Word16 lspmid_q[], /* Q15 */
35 : Word16 lspq_ind[], /* Q15 */
36 : Word16 clip_var[], /* [2.56x,Q14,Q8,Q0,Q14,Q14] */
37 : const Word16 coder_type, /* Q0 */
38 : const Word16 acelp_midLpc, /* Q0 */
39 : Word16 param_lpc[], /* Q0 */
40 : Word16 nbits_lpc[], /* Q0 */
41 : Word16 *bits_param_lpc, /* Q0 */
42 : Word16 *no_param_lpc, /* Q0 */
43 : const Word16 Q_ener )
44 : {
45 : Word16 nb_indices;
46 : Word16 lsfmid_q[M]; /* 14Q1*1.28 */
47 : Word16 lsfmid_idx;
48 : Word16 i, force_sf;
49 : Word16 lsf[M], lsfmid[M];
50 : Word16 fec_lsf[M], stab;
51 :
52 1246 : nb_indices = 0;
53 1246 : move16();
54 :
55 : /****** High-rate LPC quantizer *******/
56 :
57 1246 : IF( st->lpcQuantization == 0 )
58 : {
59 0 : if ( st->sr_core != 12800 )
60 : {
61 : // PMT("from the comment in E_LPC_isp_isf_conversion, it seems built for 12.8kHz, current sampling rate is NOT 12800, is it ok?")
62 : /*_DIFF_FLOAT_FIX_ E_LPC_lsp_lsf_conversion, does it work for 16kHz as well ?*/
63 : }
64 0 : E_LPC_lsp_lsf_conversion( lsp, lsf, M );
65 :
66 : /* check resonance for pitch clipping algorithm */
67 0 : gp_clip_test_lsf_fx( st->element_mode, lsf, clip_var, M );
68 :
69 0 : IF( ( EQ_16( st->core, TCX_10_CORE ) ) )
70 : {
71 0 : E_LPC_lsp_lsf_conversion( lspmid, lsfmid, M );
72 : }
73 :
74 : /* LPC quantizer */
75 0 : qlpc_avq_fx( lsf, lsfmid, lsf_q, lsfmid_q, param_lpc, &nb_indices, nbits_lpc, st->core, st->sr_core );
76 :
77 0 : E_LPC_lsf_lsp_conversion( lsf_q, lsp_q, M );
78 :
79 0 : IF( EQ_16( st->core, TCX_10_CORE ) )
80 : {
81 0 : E_LPC_lsf_lsp_conversion( lsfmid_q, lspmid_q, M );
82 : }
83 :
84 : /* assert(nb_indices<=NPRM_LPC_NEW); */
85 : }
86 :
87 : /****** Low-rate LPC quantizer *******/
88 :
89 1246 : ELSE IF( EQ_16( st->lpcQuantization, 1 ) )
90 : {
91 1246 : assert( st->sr_core <= 32000 );
92 :
93 1246 : lsp2lsf_fx( lsp, lsf, M, extract_l( st->sr_core ) );
94 :
95 1246 : gp_clip_test_lsf_fx( st->element_mode, lsf, clip_var, M );
96 :
97 1246 : force_sf = 0;
98 1246 : move16();
99 : /*Force safety net when possible in case of transitions*/
100 1246 : test();
101 1246 : test();
102 1246 : IF( st->tc_cnt >= 1 || LE_32( st->last_core_brate, SID_2k40 ) || ( EQ_16( st->next_force_safety_net, 1 ) ) )
103 : {
104 104 : force_sf = 1;
105 104 : move16();
106 104 : st->next_force_safety_net = 0;
107 104 : move16();
108 : }
109 :
110 1246 : test();
111 1246 : IF( EQ_16( st->next_force_safety_net, 1 ) && EQ_16( st->Opt_RF_ON, 1 ) )
112 : {
113 0 : force_sf = 1;
114 0 : move16();
115 0 : st->next_force_safety_net = 0;
116 0 : move16();
117 : }
118 :
119 1246 : test();
120 1246 : IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, UNVOICED ) )
121 : {
122 27 : lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener,
123 : force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC );
124 :
125 27 : nb_indices = *no_param_lpc; // Q0
126 27 : move16();
127 : }
128 : ELSE
129 : {
130 1219 : lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener,
131 : force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type );
132 :
133 1219 : nb_indices = *no_param_lpc; // Q0
134 1219 : move16();
135 : }
136 :
137 :
138 1246 : FEC_lsf_estim_enc_fx( st, fec_lsf );
139 :
140 : /* FEC - calculate LSF stability */
141 1246 : stab = lsf_stab_fx( lsf_q, fec_lsf, 0, st->L_frame ); /*Q15*/
142 :
143 :
144 1246 : test();
145 1246 : test();
146 1246 : test();
147 1246 : IF( LT_16( stab, add( STAB_FAC_LIMIT_FX, 6553 /* =0.2 in Q15*/ ) ) &&
148 : ( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) ) && EQ_16( st->Opt_RF_ON, 1 ) )
149 : {
150 0 : st->next_force_safety_net = 1;
151 0 : move16();
152 : }
153 :
154 1246 : lsf2lsp_fx( lsf_q, lsp_q, M, st->sr_core );
155 :
156 1246 : *nbits_lpc = ENDLSF_NBITS;
157 1246 : move16();
158 : }
159 : ELSE
160 : {
161 0 : assert( 0 );
162 : }
163 :
164 1246 : IF( lspq_ind != NULL )
165 : {
166 1246 : E_LPC_lsf_lsp_conversion( lsf_q, lspq_ind, M );
167 : }
168 :
169 1246 : st->seed_acelp = 0;
170 1246 : move16();
171 6959 : FOR( i = nb_indices - 1; i >= 0; i-- )
172 : {
173 5713 : st->seed_acelp = extract_l( L_mac0( L_mac0( 13849, shr( st->seed_acelp, 1 ), 31821 ), param_lpc[i], 31821 ) ); // Q0
174 5713 : move16();
175 : }
176 :
177 : /* Mid-frame LPC quantization */
178 :
179 1246 : test();
180 1246 : IF( st->lpcQuantization && acelp_midLpc )
181 : {
182 :
183 722 : IF( st->rate_switching_reset == 0 )
184 : {
185 708 : lsp2lsf_fx( lspmid, lsfmid, M, extract_l( st->sr_core ) );
186 :
187 708 : midlsf_enc_fx( st->lsf_old_fx, lsf_q, lsfmid, &lsfmid_idx, M, st->Bin_E_old_fx, Q_ener, (Word8) st->narrowBand, st->sr_core, coder_type );
188 708 : param_lpc[nb_indices++] = lsfmid_idx; // Q0
189 708 : move16();
190 708 : midlsf_dec( st->lsf_old_fx, lsf_q, lsfmid_idx, lsfmid_q, coder_type, NULL, 0, 1 );
191 :
192 708 : reorder_lsf_fx( lsfmid_q, LSF_GAP_MID_FX, M, st->sr_core );
193 708 : lsf2lsp_fx( lsfmid_q, lspmid_q, M, st->sr_core );
194 : }
195 : ELSE
196 : {
197 14 : param_lpc[nb_indices++] = 0;
198 14 : move16();
199 : }
200 : }
201 :
202 :
203 1246 : return;
204 : }
205 :
206 219018 : void lpc_quantization_ivas_fx(
207 : Encoder_State *st,
208 : const Word16 lsp[], /* Q15 */
209 : const Word16 lspmid[], /* Q15 */
210 : Word16 lsp_q[], /* Q15 */
211 : Word16 lsf_q[], /* 14Q1*1.28 */
212 : Word16 lspmid_q[], /* Q15 */
213 : const Word16 coder_type, /* Q0 */
214 : const Word16 acelp_midLpc, /* Q0 */
215 : Word16 param_lpc[], /* Q0 */
216 : Word16 nbits_lpc[], /* Q0 */
217 : Word16 *bits_param_lpc, /* Q0 */
218 : Word16 *no_param_lpc, /* Q0 */
219 : const Word16 Q_ener )
220 : {
221 : Word16 nb_indices;
222 : Word16 lsfmid_q[M]; /* 14Q1*1.28 */
223 : Word16 lsfmid_idx;
224 : Word16 i, force_sf;
225 : Word16 lsf[M], lsfmid[M];
226 : Word16 fec_lsf[M], stab;
227 :
228 219018 : nb_indices = 0;
229 219018 : move16();
230 :
231 : /****** High-rate LPC quantizer *******/
232 :
233 219018 : IF( st->lpcQuantization == 0 )
234 : {
235 106889 : E_LPC_lsp_lsf_conversion( lsp, lsf, M );
236 :
237 106889 : IF( ( EQ_16( st->core, TCX_10_CORE ) ) )
238 : {
239 2059 : E_LPC_lsp_lsf_conversion( lspmid, lsfmid, M );
240 : }
241 :
242 : /* LPC quantizer */
243 106889 : qlpc_avq_fx( lsf, lsfmid, lsf_q, lsfmid_q, param_lpc, &nb_indices, nbits_lpc, st->core, st->sr_core );
244 :
245 106889 : E_LPC_lsf_lsp_conversion( lsf_q, lsp_q, M );
246 :
247 106889 : IF( EQ_16( st->core, TCX_10_CORE ) )
248 : {
249 2059 : E_LPC_lsf_lsp_conversion( lsfmid_q, lspmid_q, M );
250 : }
251 :
252 106889 : assert( nb_indices <= NPRM_LPC_NEW );
253 : }
254 :
255 : /****** Low-rate LPC quantizer *******/
256 :
257 112129 : ELSE IF( EQ_16( st->lpcQuantization, 1 ) )
258 : {
259 :
260 112129 : lsp2lsf_fx( lsp, lsf, M, extract_l( st->sr_core ) );
261 :
262 112129 : force_sf = 0;
263 112129 : move16();
264 : /*Force safety net when possible in case of transitions*/
265 112129 : test();
266 112129 : test();
267 112129 : IF( GE_32( st->tc_cnt, 1 ) || LE_32( st->last_core_brate, SID_2k40 ) || ( EQ_16( st->next_force_safety_net, 1 ) ) )
268 : {
269 12297 : force_sf = 1;
270 12297 : move16();
271 12297 : st->next_force_safety_net = 0;
272 12297 : move16();
273 : }
274 :
275 112129 : test();
276 112129 : IF( EQ_16( st->next_force_safety_net, 1 ) && EQ_16( st->Opt_RF_ON, 1 ) )
277 : {
278 0 : force_sf = 1;
279 0 : st->next_force_safety_net = 0;
280 0 : move16();
281 0 : move16();
282 : }
283 :
284 112129 : test();
285 112129 : IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, UNVOICED ) )
286 : {
287 0 : lsf_end_enc_ivas_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener,
288 : force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC, NULL );
289 :
290 0 : nb_indices = *no_param_lpc; // Q0
291 0 : move16();
292 : }
293 : ELSE
294 : {
295 112129 : lsf_end_enc_ivas_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener,
296 : force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type, NULL );
297 :
298 112129 : nb_indices = *no_param_lpc; // Q0
299 112129 : move16();
300 : }
301 :
302 :
303 112129 : FEC_lsf_estim_enc_fx( st, fec_lsf );
304 :
305 : /* FEC - calculate LSF stability */
306 112129 : stab = lsf_stab_fx( lsf_q, fec_lsf, 0, st->L_frame ); /*Q15*/
307 :
308 :
309 112129 : test();
310 112129 : test();
311 112129 : test();
312 112129 : IF( LT_16( stab, add( STAB_FAC_LIMIT_FX, 6553 /* =0.2 in Q15*/ ) ) &&
313 : ( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) ) && EQ_16( st->Opt_RF_ON, 1 ) )
314 : {
315 0 : st->next_force_safety_net = 1;
316 0 : move16();
317 : }
318 :
319 112129 : lsf2lsp_fx( lsf_q, lsp_q, M, st->sr_core );
320 :
321 112129 : *nbits_lpc = ENDLSF_NBITS;
322 112129 : move16();
323 : }
324 : ELSE
325 : {
326 0 : assert( 0 );
327 : }
328 :
329 219018 : st->seed_acelp = 0;
330 219018 : move16();
331 2134057 : FOR( i = nb_indices - 1; i >= 0; i-- )
332 : {
333 1915039 : st->seed_acelp = extract_l( L_mac0( L_mac0( 13849, shr( st->seed_acelp, 1 ), 31821 ), param_lpc[i], 31821 ) ); // Q0
334 1915039 : move16();
335 : }
336 :
337 : /* Mid-frame LPC quantization */
338 :
339 219018 : test();
340 219018 : IF( st->lpcQuantization && acelp_midLpc )
341 : {
342 :
343 0 : IF( st->rate_switching_reset == 0 )
344 : {
345 0 : lsp2lsf_fx( lspmid, lsfmid, M, extract_l( st->sr_core ) );
346 :
347 0 : midlsf_enc_fx( st->lsf_old_fx, lsf_q, lsfmid, &lsfmid_idx, M, st->Bin_E_old_fx, Q_ener, (Word8) st->narrowBand, st->sr_core, coder_type );
348 0 : param_lpc[nb_indices] = lsfmid_idx; // Q0
349 0 : move16();
350 0 : nb_indices = add( nb_indices, 1 );
351 0 : midlsf_dec( st->lsf_old_fx, lsf_q, lsfmid_idx, lsfmid_q, coder_type, NULL, 0, 1 );
352 :
353 0 : reorder_lsf_fx( lsfmid_q, LSF_GAP_MID_FX, M, st->sr_core );
354 0 : lsf2lsp_fx( lsfmid_q, lspmid_q, M, st->sr_core );
355 : }
356 : ELSE
357 : {
358 0 : param_lpc[nb_indices] = 0;
359 0 : move16();
360 0 : nb_indices = add( nb_indices, 1 ); // Q0
361 : }
362 : }
363 :
364 :
365 219018 : return;
366 : }
367 :
368 :
369 : /*-------------------------------------------------------------------*
370 : * Unified_weighting()
371 : *
372 : * LSF weighting
373 : *-------------------------------------------------------------------*/
374 :
375 448086 : void Unified_weighting_fx(
376 : const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */
377 : Word16 Q_ener,
378 : const Word16 lsf_fx[], /* i : LSF vector x2.56 */
379 : Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */
380 : const Word16 narrowBand, /* i : flag for Narrowband Q0*/
381 : const Word16 unvoiced, /* i : flag for Unvoiced frame Q0*/
382 : const Word32 sr_core, /* i : sampling rate of core-coder Q0*/
383 : const Word16 order /* i : LP order Q0*/
384 : )
385 : {
386 : Word16 i;
387 : const Word16( *ptr_lsf_fit_model )[M];
388 : Word16 last_bin;
389 : /*float compen;*/
390 :
391 : Word16 exp, frac;
392 : Word16 w_fft_fx[M] /*, w_fx[M]*/;
393 : Word16 norm_lsf_fx[M]; /* Q0 */
394 : Word16 tmp_fx, min_fx, tmp1_fx, tmp2_fx, s1, s2;
395 : Word32 L_tmp;
396 : Word16 nf_fx;
397 : Word32 Bin_Ener_160_fx[160];
398 : const Word32 *Freq_w_Table_fx, *Bin_Ener_fx;
399 :
400 : /*Config. weighting*/
401 448086 : IF( narrowBand )
402 : {
403 0 : ptr_lsf_fit_model = lsf_unified_fit_model_nb; // Q0
404 0 : nf_fx = 16384; /* 6400 in x2.56 */
405 0 : move16();
406 :
407 0 : last_bin = 127;
408 0 : move16();
409 0 : Bin_Ener_fx = Bin_Ener_128_fx; /* Q_ener */
410 : }
411 448086 : ELSE IF( EQ_32( sr_core, INT_FS_12k8 ) )
412 : {
413 223233 : ptr_lsf_fit_model = lsf_unified_fit_model_wb;
414 223233 : nf_fx = 16384; /* 6400 in x2.56 */
415 223233 : move16();
416 :
417 223233 : last_bin = 127;
418 223233 : move16();
419 223233 : Bin_Ener_fx = Bin_Ener_128_fx; /* Q_ener */
420 : }
421 : ELSE
422 : {
423 224853 : ptr_lsf_fit_model = lsf_unified_fit_model_wbhb;
424 224853 : nf_fx = 20480; /* 8000 in x2.56 */
425 224853 : move16();
426 :
427 : /* Fill the missing part (128~159) of the bin energy */
428 224853 : last_bin = 159;
429 224853 : move16();
430 :
431 224853 : Copy32( Bin_Ener_128_fx, Bin_Ener_160_fx, L_FFT / 2 ); /* Q_ener */
432 :
433 : /* Find average bin energy (32 Energy) */
434 224853 : L_tmp = L_deposit_l( 0 );
435 7420149 : FOR( i = 95; i < 127; i++ )
436 : {
437 7195296 : L_tmp = L_add_sat( L_tmp, Bin_Ener_160_fx[i] ); /* Q_ener */
438 : }
439 :
440 224853 : L_tmp = L_shr( L_tmp, 5 );
441 7645002 : FOR( i = 127; i < 160; i++ )
442 : {
443 7420149 : Bin_Ener_160_fx[i] = L_tmp; /* Q_ener */
444 7420149 : move32();
445 : }
446 :
447 224853 : Bin_Ener_fx = Bin_Ener_160_fx; /* Q_ener */
448 : }
449 :
450 : /* 1) FFT weights*/
451 448086 : Freq_w_Table_fx = Freq_Weight_Com_fx; /* Q31 */
452 448086 : if ( unvoiced )
453 : {
454 4944 : Freq_w_Table_fx = Freq_Weight_UV_fx; /* Q31 */
455 : }
456 :
457 : /* Use Envelope */
458 448086 : min_fx = MAX_16;
459 448086 : move16();
460 7617462 : FOR( i = 0; i < M; i++ )
461 : {
462 7169376 : norm_lsf_fx[i] = mult_r( lsf_fx[i], 256 );
463 7169376 : move16();
464 :
465 7169376 : IF( norm_lsf_fx[i] == 0 )
466 : {
467 17 : L_tmp = L_add( Bin_Ener_fx[1], 0 );
468 : }
469 7169359 : ELSE IF( norm_lsf_fx[i] == last_bin )
470 : {
471 24 : L_tmp = L_add( Bin_Ener_fx[last_bin - 1], 0 );
472 : }
473 : ELSE
474 : {
475 7169335 : L_tmp = L_max( Bin_Ener_fx[norm_lsf_fx[i]], Bin_Ener_fx[norm_lsf_fx[i] - 1] ); /* Q_ener */
476 7169335 : L_tmp = L_max( Bin_Ener_fx[norm_lsf_fx[i] + 1], L_tmp ); /* Q_ener */
477 : }
478 :
479 7169376 : IF( LE_32( L_tmp, MIN_LOG_FX ) )
480 : {
481 29177 : w_fft_fx[i] = MIN_LOG_VAL_FX;
482 29177 : move16(); /* Q8 */
483 : }
484 : ELSE
485 : {
486 7140199 : exp = norm_l( L_tmp );
487 7140199 : move16();
488 7140199 : IF( L_tmp == 0 )
489 : {
490 0 : frac = 0;
491 0 : move16();
492 : }
493 : ELSE
494 : {
495 7140199 : frac = Log2_norm_lc( L_shl( L_tmp, exp ) );
496 : }
497 7140199 : exp = sub( sub( 30, exp ), Q_ener );
498 7140199 : L_tmp = Mpy_32_16( exp, frac, 24660 ); /* Q14 */ /* 10*log10(2) in Q13*/
499 7140199 : w_fft_fx[i] = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */
500 : }
501 :
502 7169376 : if ( LT_16( w_fft_fx[i], min_fx ) )
503 : {
504 2499467 : min_fx = w_fft_fx[i]; // Q8
505 2499467 : move16();
506 : }
507 : }
508 :
509 7617462 : FOR( i = 0; i < M; i++ )
510 : {
511 7169376 : IF( EQ_16( w_fft_fx[i], min_fx ) )
512 : {
513 533472 : w_fft_fx[i] = 2048;
514 533472 : move16(); /* 2.0 in Q10 */
515 : }
516 : ELSE
517 : {
518 6635904 : L_tmp = L_shl_sat( L_deposit_l( sub_sat( w_fft_fx[i], min_fx ) ), 13 ); /* Q21 */
519 6635904 : exp = norm_l( L_tmp );
520 6635904 : frac = round_fx( L_shl( L_tmp, exp ) );
521 6635904 : exp = sub( add( exp, 21 ), 30 );
522 6635904 : tmp_fx = div_s( 16384, frac );
523 6635904 : L_tmp = Isqrt_lc( L_deposit_h( tmp_fx ), &exp ); /* Q(31-exp) */
524 6635904 : w_fft_fx[i] = round_fx( L_shl( L_tmp, sub( exp, 5 ) ) ); /* Q10 */
525 6635904 : w_fft_fx[i] = add( w_fft_fx[i], 2048 );
526 6635904 : move16(); /* Q10; 2.0 in Q10 */
527 : }
528 7169376 : w_fft_fx[i] = round_fx( Mult_32_16( Freq_w_Table_fx[norm_lsf_fx[i]], w_fft_fx[i] ) ); /* Q10 */
529 : }
530 :
531 : /* 2) IHM weights*/
532 7617462 : FOR( i = 0; i < order; i++ )
533 : {
534 : /* 2) IHM weights*/
535 7169376 : tmp1_fx = lsf_fx[i]; /* x2.56 */
536 7169376 : move16();
537 7169376 : if ( i > 0 )
538 : {
539 6721290 : tmp1_fx = sub( tmp1_fx, lsf_fx[i - 1] ); /* x2.56 */
540 : }
541 :
542 7169376 : tmp2_fx = nf_fx;
543 7169376 : move16();
544 7169376 : if ( NE_16( i, sub( order, 1 ) ) )
545 : {
546 6721290 : tmp2_fx = lsf_fx[i + 1]; /* x2.56 */
547 6721290 : move16();
548 : }
549 7169376 : tmp2_fx = sub( tmp2_fx, lsf_fx[i] ); /* x2.56 */
550 :
551 7169376 : s1 = 15;
552 7169376 : move16();
553 7169376 : s2 = 15;
554 7169376 : move16();
555 7169376 : if ( tmp1_fx == 0 )
556 : {
557 0 : tmp1_fx = 8;
558 0 : move16();
559 : }
560 7169376 : tmp1_fx = Inv16( tmp1_fx, &s1 );
561 7169376 : if ( tmp2_fx == 0 )
562 : {
563 0 : tmp2_fx = 8;
564 0 : move16();
565 : }
566 7169376 : tmp2_fx = Inv16( tmp2_fx, &s2 );
567 7169376 : s1 = BASOP_Util_Add_MantExp( tmp1_fx, s1, tmp2_fx, s2, &tmp1_fx ); /* x * 2.56 / pow(2.0, 15 + |s1|) */
568 7169376 : tmp_fx = mult_r( nf_fx, 10430 /* 0.31 in Q15*/ );
569 7169376 : s2 = norm_s( tmp_fx );
570 7169376 : tmp_fx = shl( tmp_fx, s2 );
571 7169376 : s1 = sub( s1, s2 );
572 :
573 7169376 : tmp1_fx = mult_r( tmp1_fx, tmp_fx ); /* |s1| */
574 7169376 : s1 = abs_s( s1 );
575 :
576 : /* 3) Fitting model combining the two weights*/
577 7169376 : L_tmp = L_add( ptr_lsf_fit_model[0][i], 0 ); /* Q10 */
578 7169376 : L_tmp = L_add( L_tmp, L_shl( L_mult0( ptr_lsf_fit_model[1][i], tmp1_fx ), sub( -5, s1 ) ) ); /* Q10 */
579 7169376 : L_tmp = L_add( L_tmp, L_shl( L_mult0( mult_r( tmp1_fx, tmp1_fx ), ptr_lsf_fit_model[2][i] ), sub( 7, shl( s1, 1 ) ) ) );
580 7169376 : L_tmp = L_add( L_tmp, L_shl( L_mult0( w_fft_fx[i], ptr_lsf_fit_model[3][i] ), -12 ) );
581 7169376 : move16(); /* Q10 */
582 :
583 7169376 : IF( LT_32( L_shl( L_tmp, 5 ), InvIntTable[i + 1] ) )
584 : {
585 4 : w_fx[i] = shr( InvIntTable[i + 1], 7 ); // Q8
586 4 : move16();
587 : }
588 : ELSE
589 : {
590 7169372 : IF( norm_l( L_tmp ) < 14 )
591 : {
592 0 : w_fx[i] = MAX_16;
593 0 : move16();
594 : }
595 : ELSE
596 : {
597 7169372 : w_fx[i] = extract_l( L_shr( L_tmp, 2 ) ); // Q8
598 7169372 : move16();
599 : }
600 : }
601 : }
602 :
603 448086 : return;
604 : }
|