Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 : #include <stdint.h>
5 : #include "options.h"
6 : #include "rom_com.h"
7 : #include "prot_fx.h"
8 :
9 : /*-------------------------------------------------------------------*
10 : * gs_noisf()
11 : *
12 : * Noise fill-in function
13 : *-------------------------------------------------------------------*/
14 :
15 230612 : static void gs_noisf_fx(
16 : const Word16 Start_BIN, /* i : First bin for noise fill */
17 : const Word16 NB_Qbins, /* i : Number of bin per band */
18 : const Word16 Noise_fac, /* i : Noise level Q15 */
19 : const Word16 *y_norm, /* i : Quantized pulses Q(qNoise_fac) */
20 : Word16 *exc_diffQ, /* o : Quantized pulses with noise added Q(qNoise_fac) */
21 : Word16 *seed_tcx, /* i : Random generator seed */
22 : const Word16 coder_type, /* i : coder type */
23 : Word16 qNoise_fac )
24 : {
25 : Word32 ftmp;
26 : Word16 i, k;
27 : Word16 NB_zer;
28 230612 : Word32 const_1 = 1;
29 230612 : move32();
30 : Word16 tmp;
31 :
32 230612 : NB_zer = shr( NB_Qbins, 1 );
33 :
34 230612 : const_1 = L_shl( const_1, add( qNoise_fac, qNoise_fac ) ); /*2*Q(qNoise_fac)*/
35 230612 : if ( ( coder_type == INACTIVE ) )
36 : {
37 71194 : NB_zer = 2;
38 71194 : move16();
39 : }
40 :
41 : /*----------------------------------------------*
42 : * noise fill-in on unquantized subvector *
43 : * injected only from 1066Hz to 6400Hz. *
44 : *----------------------------------------------*/
45 :
46 1159528 : FOR( k = Start_BIN; k < NB_Qbins + Start_BIN; k += NB_zer )
47 : {
48 928916 : ftmp = L_deposit_l( 0 );
49 4699796 : FOR( i = k; i < k + NB_zer; i++ )
50 : {
51 3770880 : exc_diffQ[i] = y_norm[i];
52 3770880 : move16();
53 3770880 : ftmp = L_mac0( ftmp, exc_diffQ[i], exc_diffQ[i] ); /*2*Q(qNoise_fac)*/
54 : }
55 :
56 928916 : IF( LT_32( L_shl( ftmp, 1 ), const_1 ) )
57 : {
58 3514067 : FOR( i = k; i < k + NB_zer; i++ )
59 : {
60 : /*exc_diffQ[i] += Noise_fac*((float)own_random(seed_tcx)/32768.0f);*/
61 2817584 : tmp = mult( Noise_fac, Random( seed_tcx ) ); /*Q15 */
62 2817584 : tmp = shr( tmp, sub( 15, qNoise_fac ) ); /*qNoise_fac */
63 2817584 : exc_diffQ[i] = add( exc_diffQ[i], tmp );
64 2817584 : move16(); /*Q */
65 : }
66 : }
67 : ELSE
68 : {
69 : /* This is added only to keep the seed in sync between different compilers */
70 1185729 : FOR( i = k; i < k + NB_zer; i++ )
71 : {
72 953296 : Random( seed_tcx );
73 : }
74 : }
75 : }
76 :
77 230612 : return;
78 : }
79 :
80 : /*-------------------------------------------------------------------*
81 : * EstimateNoiseLevel_inner()
82 : *
83 : * Estimate noise level from the power spectrum
84 : *-------------------------------------------------------------------*/
85 :
86 11518 : static void EstimateNoiseLevel_inner_fx(
87 : Word16 *noisepb, /* o : Noise per band Q15 */
88 : const long bitrate, /* i : Bitrate of the codec */
89 : const Word16 i_band, /* i : First band to compute the noise */
90 : const Word16 Mbands_gn /* i : number of bands */
91 : )
92 : {
93 : Word16 i;
94 : Word16 noise_offset;
95 :
96 11518 : noise_offset = 8192;
97 11518 : move16();
98 : /*0.25f * 32768 */
99 11518 : IF( GT_32( bitrate, ACELP_24k40 ) )
100 : {
101 185 : noise_offset = 6554;
102 185 : move16(); /*.2f * 32768 */
103 : }
104 11333 : ELSE IF( GE_32( bitrate, ACELP_22k60 ) )
105 : {
106 634 : noise_offset = 9830;
107 634 : move16(); /*.3f * 32768 */
108 : }
109 10699 : ELSE IF( GE_32( bitrate, ACELP_9k60 ) )
110 : {
111 4664 : noise_offset = 11469;
112 4664 : move16(); /*0.35f * 32768 */
113 : }
114 : ELSE
115 : {
116 6035 : noise_offset = 13107;
117 6035 : move16(); /*.4f * 32768 */
118 : }
119 :
120 11518 : set16_fx( noisepb + i_band, noise_offset, sub( Mbands_gn, i_band ) ); /*Q15*/
121 :
122 69108 : FOR( i = i_band; i < 5; i++ )
123 : {
124 57590 : noisepb[i] = s_min( noisepb[i], 6554 /*0.2(Q15)*/ );
125 57590 : move16();
126 : }
127 :
128 11518 : return;
129 : }
130 : /*==========================================================================*/
131 : /* FUNCTION : void EstimateNoiseLevel_fx() */
132 : /*--------------------------------------------------------------------------*/
133 : /* PURPOSE : */
134 : /*--------------------------------------------------------------------------*/
135 : /* INPUT ARGUMENTS : */
136 : /* _ (Word32) bitrate : Bitrate of the codec Q0 */
137 : /* _ (Word16) Diff_len : number of bin before cut-off frequency */
138 : /* _ (Word16) Mbands_gn : number of bands Q0 */
139 : /* _ (Word16) coder_type : coder type Q0 */
140 : /* _ (Word16) noise_lev : pulses dynamic Q0 */
141 : /* _ (Word16) pit_band_idx : bin position of the cut-off frequency */
142 : /* _ (Word16*) freq_nsbin_per_band : bin per bands tables Q0 */
143 : /*--------------------------------------------------------------------------*/
144 : /* OUTPUT ARGUMENTS : */
145 : /* _ (Word16*) noisepb : Noise per band Q15 */
146 : /*--------------------------------------------------------------------------*/
147 : /* INPUT/OUTPUT ARGUMENTS : */
148 : /* None */
149 : /*--------------------------------------------------------------------------*/
150 : /* RETURN ARGUMENTS : */
151 : /* _ None */
152 : /*==========================================================================*/
153 11518 : static void EstimateNoiseLevel_fx(
154 : Word16 *noisepb, /* o : Noise per band */
155 : const Word32 bitrate, /* i : Bitrate of the codec */
156 : const Word16 Diff_len, /* i : number of bin before cut-off frequency */
157 : const Word16 Mbands_gn, /* i : number of bands */
158 : const Word16 coder_type, /* i : coder type */
159 : const Word16 noise_lev, /* i : pulses dynamic */
160 : const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */
161 : Word16 last_bin, /* i : the last bin of bit allocation */
162 : Word16 bwidth,
163 : const Word16 L_frame /* i : frame length */
164 : )
165 : {
166 : Word16 i_band;
167 :
168 11518 : i_band = 0;
169 11518 : move16();
170 :
171 11518 : IF( LT_16( Diff_len, L_frame ) )
172 : {
173 11518 : EstimateNoiseLevel_inner_fx( noisepb, bitrate, i_band, MBANDS_GN );
174 11518 : IF( coder_type != INACTIVE )
175 : {
176 7506 : test();
177 7506 : test();
178 7506 : IF( ( EQ_32( bitrate, ACELP_8k00 ) && GT_16( last_bin, 8 ) ) && NE_16( bwidth, NB ) )
179 : {
180 0 : FOR( ; Mbands_gn > i_band; i_band++ )
181 : {
182 0 : noisepb[i_band] = add( noisepb[i_band], noisepb[i_band] );
183 0 : move16();
184 : }
185 : }
186 : ELSE
187 : {
188 71313 : FOR( ; pit_band_idx > i_band; i_band++ )
189 : {
190 63807 : noisepb[i_band] = mult_r( noisepb[i_band], 16384 );
191 63807 : move16(); /* 1/2=0.5 in Q15 */
192 : }
193 : }
194 : }
195 : }
196 11518 : test();
197 11518 : test();
198 11518 : IF( ( ( coder_type == INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) && EQ_16( L_frame, L_FRAME ) )
199 : {
200 46848 : FOR( i_band = 9; i_band < Mbands_gn; i_band++ )
201 : {
202 40992 : noisepb[i_band] = add( noisepb[i_band], mult_r( noisepb[i_band], 4915 ) );
203 40992 : move16(); /*noisepb[i_band]*1.15=noisepb[i_band] *(1 + 0.15) */
204 : }
205 : }
206 5662 : ELSE IF( EQ_16( L_frame, L_FRAME16k ) )
207 : {
208 2533 : IF( EQ_32( bitrate, ACELP_13k20 ) )
209 : {
210 0 : set16_fx( noisepb, 14746 /*0.45*/, Mbands_gn );
211 : }
212 :
213 2533 : IF( ( coder_type == INACTIVE ) )
214 : {
215 48127 : FOR( ; i_band < Mbands_gn; i_band++ )
216 : {
217 45594 : noisepb[i_band] = 13107 /*.4f*/;
218 45594 : move16();
219 : }
220 : }
221 0 : ELSE IF( LE_16( noise_lev, NOISE_LEVEL_SP1 ) && GT_32( bitrate, ACELP_16k40 ) )
222 : {
223 0 : FOR( ; i_band < sub( Mbands_gn, 4 ); i_band++ )
224 : {
225 0 : noisepb[i_band] = mult_r( noisepb[i_band], 19661 ) /*.6f*/;
226 0 : move16();
227 : }
228 : }
229 0 : ELSE IF( LE_16( noise_lev, NOISE_LEVEL_SP2 ) && GT_32( bitrate, ACELP_16k40 ) )
230 : {
231 0 : FOR( ; i_band < sub( Mbands_gn, 4 ); i_band++ )
232 : {
233 0 : noisepb[i_band] = mult_r( noisepb[i_band], 26214 ) /*.8f*/;
234 0 : move16();
235 : }
236 : }
237 : }
238 :
239 :
240 11518 : return;
241 : }
242 :
243 : /*============================================================================*/
244 : /* FUNCTION : void Appy_NoiseFill_fx() */
245 : /*----------------------------------------------------------------------------*/
246 : /* PURPOSE : */
247 : /*----------------------------------------------------------------------------*/
248 : /* INPUT ARGUMENTS : */
249 : /* _ (Word16*) seed_tcx : Seed for noise Q0 */
250 : /* _ (Word16*) noisepb : Noise per band Q15 */
251 : /* _ (Word16) Diff_len : number of bin before cut-off frequency Q0 */
252 : /* _ (Word16) Mbands_gn : number of bands Q0 */
253 : /* _ (Word16) coder_type : pulses dynamic Q0 */
254 : /* _ (Word16*) freq_nsbin_per_band: bin per bands tables Q0 */
255 : /* _ (Word16) qexc_diffQ : Q format of exc_diffQ */
256 : /*----------------------------------------------------------------------------*/
257 : /* OUTPUT ARGUMENTS : */
258 : /* _ (Word16*) exc_diffQ : Noise per band qexc_diffQ */
259 : /*----------------------------------------------------------------------------*/
260 : /* INPUT/OUTPUT ARGUMENTS : */
261 : /* None */
262 : /*----------------------------------------------------------------------------*/
263 : /* RETURN ARGUMENTS : */
264 : /* _ None */
265 : /*============================================================================*/
266 14098 : static void Apply_NoiseFill_fx(
267 : Word16 *exc_diffQ, /* i/o: Noise per band qexc_diffQ */
268 : Word16 *seed_tcx, /* i : Seed for noise */
269 : const Word16 *noisepb, /* i : Noise per band Q15 */
270 : const Word16 Diff_len, /* i : number of bin before cut-off frequency */
271 : const Word16 Mbands_gn, /* i : number of bands */
272 : const Word16 coder_type, /* i : coder type */
273 : const Word16 *freq_nsbin_per_band, /* i : bin per bands tables */
274 : Word16 qexc_diffQ )
275 : {
276 : Word16 StartBin, NB_Qbins, i_band;
277 14098 : StartBin = 0;
278 14098 : move16();
279 14098 : NB_Qbins = 0;
280 14098 : move16();
281 :
282 244710 : FOR( i_band = 0; i_band < Mbands_gn; i_band++ )
283 : {
284 230612 : StartBin = add( StartBin, NB_Qbins );
285 230612 : NB_Qbins = freq_nsbin_per_band[i_band];
286 230612 : move16();
287 :
288 230612 : IF( LT_16( Diff_len, L_FRAME ) )
289 : {
290 230612 : gs_noisf_fx( StartBin, NB_Qbins, noisepb[i_band], exc_diffQ, exc_diffQ, seed_tcx, coder_type, qexc_diffQ );
291 : }
292 : }
293 :
294 14098 : return;
295 : }
296 : /*==========================================================================*/
297 : /* FUNCTION :void freq_dnw_scaling_fx () */
298 : /*--------------------------------------------------------------------------*/
299 : /* PURPOSE : */
300 : /*--------------------------------------------------------------------------*/
301 : /* INPUT ARGUMENTS : */
302 : /* _ (Word16) cor_strong_limit : HF correlation Q0 */
303 : /* _ (Word16) coder_type : coder type Q0 */
304 : /* _ (Word16) noise_lev : Noise level Q0 */
305 : /* _ (Word32) core_brate : Core bitrate Q0 */
306 : /* _ (Word16) Qx : Q format of fy_norm */
307 : /*--------------------------------------------------------------------------*/
308 : /* OUTPUT ARGUMENTS : */
309 : /* _ None */
310 : /*--------------------------------------------------------------------------*/
311 : /* INPUT/OUTPUT ARGUMENTS : */
312 : /* _ (Word16[]) fy_norm : Frequency quantized parameter Qx */
313 : /*--------------------------------------------------------------------------*/
314 : /* RETURN ARGUMENTS : */
315 : /* _None */
316 : /*==========================================================================*/
317 13803 : void freq_dnw_scaling_fx(
318 : const Word16 cor_strong_limit, /* i : HF correlation */
319 : const Word16 coder_type, /* i : coder type */
320 : const Word16 noise_lev, /* i : Noise level */
321 : const Word32 core_brate, /* i : Core bitrate */
322 : Word16 fy_norm[], /* i/o: Frequency quantized parameter Qx */
323 : Word16 Qx, /* Q format of fy_norm*/
324 : const Word16 L_frame /* i : frame length */
325 :
326 : )
327 : {
328 : Word16 sc_dyn;
329 : Word16 start_sc, i;
330 :
331 13803 : sc_dyn = 32767;
332 13803 : move16(); /*Q15 */
333 13803 : start_sc = L_frame;
334 13803 : move16();
335 13803 : test();
336 13803 : IF( LE_32( core_brate, ACELP_8k00 ) && ( coder_type == INACTIVE ) )
337 : {
338 51 : sc_dyn = mult_r( sc_dyn, 4915 ); /*Q15 (0.15 in Q15) */
339 51 : start_sc = 64;
340 51 : move16();
341 : }
342 13752 : ELSE IF( ( coder_type == INACTIVE ) )
343 : {
344 4056 : sc_dyn = mult_r( sc_dyn, 8192 ); /*Q15 (0.25 in Q15) */
345 4056 : start_sc = 80;
346 4056 : move16();
347 : }
348 : ELSE
349 : {
350 : /*sc_dyn = (float)(NOISE_LEVEL_SP3 - noise_lev)/10.0f + 0.4f;*/
351 9696 : sc_dyn = extract_l( L_mac( 13107, sub( NOISE_LEVEL_SP3, noise_lev ), 1638 ) ); /*Q0*Q14x2+Q15 =Q15*/
352 9696 : start_sc = add( 112, shl( sub( NOISE_LEVEL_SP3, noise_lev ), 4 ) );
353 9696 : if ( EQ_16( noise_lev, NOISE_LEVEL_SP0 ) )
354 : {
355 2189 : start_sc = L_FRAME;
356 2189 : move16();
357 : }
358 : }
359 :
360 13803 : test();
361 13803 : IF( EQ_16( L_frame, L_FRAME16k ) && LE_32( core_brate, ACELP_24k40 ) )
362 : {
363 : /*sc_dyn += 0.125f;*/
364 2348 : sc_dyn = add( sc_dyn, 4096 ); /* Saturates to 1.0 */
365 : }
366 :
367 1885803 : FOR( i = start_sc; i < L_frame; i++ )
368 : {
369 1872000 : fy_norm[i] = mult_r( fy_norm[i], sc_dyn );
370 1872000 : move16(); /*Qx */
371 : }
372 :
373 13803 : test();
374 13803 : test();
375 13803 : IF( ( LT_32( core_brate, ACELP_13k20 ) && cor_strong_limit == 0 ) || LT_32( core_brate, ACELP_9k60 ) )
376 : {
377 989012 : FOR( i = 160; i < L_frame; i++ )
378 : {
379 978816 : fy_norm[i] = s_min( fy_norm[i], shl( 1, Qx ) ); /*Qx*/
380 978816 : move16();
381 978816 : fy_norm[i] = s_max( fy_norm[i], shl( -1, Qx ) ); /*Qx*/
382 978816 : move16();
383 : }
384 : }
385 3607 : ELSE IF( LT_32( core_brate, ACELP_22k60 ) )
386 : {
387 380132 : FOR( i = 160; i < L_frame; i++ )
388 : {
389 377344 : fy_norm[i] = s_min( fy_norm[i], shr_r( 1536 /*1.5 in Q10*/, sub( 10, Qx ) ) ); /*Qx*/
390 377344 : move16();
391 377344 : fy_norm[i] = s_max( fy_norm[i], shr_r( -1536 /*1.5 in Q10*/, sub( 10, Qx ) ) ); /*Qx*/
392 377344 : move16();
393 : }
394 : }
395 :
396 13803 : return;
397 : }
398 :
399 21 : static void Decreas_freqPeak_fx(
400 : const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx2.56 */
401 : Word16 *exc_diffQ, /* i/o: frequency coefficients of per band */
402 : Word16 rat /* i : threshold of ratio between consecutive lsf_new_diff */
403 : )
404 : {
405 : Word16 i, j, k;
406 21 : Word16 last_bin = 0;
407 21 : Word16 pos = 0;
408 21 : move16();
409 : Word16 *src, max_val, avrg;
410 : Word32 L_avrg, L_tmp;
411 : Word16 lsf_new_diff[M];
412 : Word16 tmp, tmp1, exp;
413 : Word16 tmp2;
414 : #ifndef ISSUE_1836_replace_overflow_libcom
415 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
416 : Flag Overflow = 0;
417 : move16();
418 : #endif
419 : #endif
420 21 : move16(); /*ptr init*/
421 21 : lsf_new_diff[0] = 0; /* prevent unitialized value */
422 21 : move16();
423 315 : FOR( j = 1; j < ( M - 1 ); j++ )
424 : {
425 294 : lsf_new_diff[j] = sub( lsf_new[j], lsf_new[j - 1] ); /*Qx2.56 */
426 294 : move16();
427 : }
428 :
429 21 : avrg = 0;
430 21 : move16();
431 21 : L_avrg = L_deposit_l( 0 );
432 21 : max_val = 1;
433 21 : move16();
434 2037 : FOR( i = 160; i < L_FRAME; i++ )
435 : {
436 2016 : IF( GT_16( abs_s( exc_diffQ[i] ), max_val ) )
437 : {
438 87 : max_val = abs_s( exc_diffQ[i] );
439 87 : pos = i;
440 87 : move16();
441 : }
442 2016 : L_avrg = L_add( L_avrg, abs_s( exc_diffQ[i] ) );
443 : }
444 : /* avrg /= 96; */
445 21 : L_avrg = Mult_32_16( L_avrg, 21845 ); /*Q_exc+21 -15 ->Q_exc + 6 */
446 21 : avrg = round_fx( L_shl( L_avrg, 10 ) ); /*Q_exc */
447 21 : last_bin = M - 1;
448 21 : move16(); /* When the search is false, should equate the end of the vector, not the beginning */
449 227 : FOR( i = 0; i < ( M - 1 ); i++ )
450 : {
451 227 : IF( GT_16( lsf_new[i], 10240 /*4000 in Qx2.56*/ ) )
452 : {
453 21 : last_bin = i;
454 21 : move16();
455 21 : BREAK;
456 : }
457 : }
458 :
459 109 : FOR( i = last_bin; i < 14; i++ )
460 : {
461 88 : tmp = mult_r( rat, lsf_new_diff[i - 1] ); /*Qx2.56 */
462 88 : IF( GT_16( tmp, lsf_new_diff[i] ) )
463 : {
464 5 : src = &exc_diffQ[( i - 1 ) << 4];
465 5 : move16();
466 15 : FOR( j = 0; j < 2; j++ )
467 : {
468 170 : FOR( k = 0; k < 16; k++ )
469 : {
470 160 : tmp = mult_r( 16384, abs_s( *src ) );
471 160 : IF( GT_16( tmp, avrg ) )
472 : {
473 8 : tmp = abs_s( *src );
474 8 : exp = norm_s( max_val );
475 8 : tmp1 = div_s( shl( 1, sub( 14, exp ) ), max_val ); /*Q(29 - exp - Q_exc) */
476 8 : L_tmp = L_mult( tmp, tmp1 ); /*Q(30 - exp) */
477 : #ifdef ISSUE_1836_replace_overflow_libcom
478 8 : tmp = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q14 */
479 : #else
480 : tmp = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q14 */
481 : #endif
482 8 : tmp = sub( 32767, tmp ); /*Q14 */
483 8 : L_tmp = L_mult( avrg, tmp ); /*Q_exc +15 */
484 :
485 8 : tmp = round_fx( L_shl( L_tmp, 1 ) );
486 8 : tmp1 = negate( tmp );
487 :
488 8 : tmp2 = *src;
489 8 : move16();
490 8 : *( src ) = tmp1;
491 8 : move16();
492 8 : if ( tmp2 > 0 )
493 : {
494 2 : *( src ) = tmp;
495 2 : move16();
496 : }
497 : }
498 160 : src++;
499 : }
500 : }
501 : }
502 : }
503 :
504 21 : tmp = mult_r( 8192, max_val ); /*Q_exc */
505 21 : test();
506 21 : IF( EQ_16( abs_s( exc_diffQ[pos] ), max_val ) && GT_16( tmp, avrg ) )
507 : {
508 24 : FOR( i = pos - 1; i < pos + 2; i++ )
509 : {
510 18 : exc_diffQ[pos] = mult_r( 16384 /*0.5 in Q15*/, exc_diffQ[pos] );
511 18 : move16();
512 : }
513 : }
514 :
515 21 : return;
516 : }
517 :
518 6 : static void envelop_modify_fx(
519 : Word16 *exc_diffQ_fx, /* i/o: frequency coefficients of per band */
520 : Word16 *seed_tcx, /* i : Seed for noise */
521 : Word16 last_bin, /* i : last bin of bit allocation */
522 : Word16 *Ener_per_bd_iQ_fx, /* i : Quantized energy of targeted vector */
523 : Word16 Q_exc,
524 : Word16 *Q_hb_exc )
525 : {
526 : Word16 i, j, end_band;
527 : Word16 start_band;
528 : Word32 Ener_fx;
529 : Word16 Ener1_fx;
530 : Word16 tmp, tmp1;
531 : Word32 L_tmp;
532 : Word16 exp, exp1, frac;
533 : Word16 *src_fx;
534 : Word16 weight_fx;
535 : Word32 L_exc_diffQ_fx[L_FRAME16k], exc_diffQ_max;
536 : Word16 Q_tmp;
537 : #ifndef ISSUE_1836_replace_overflow_libcom
538 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
539 : Flag Overflow = 0;
540 : move16();
541 : #endif
542 : #endif
543 :
544 6 : start_band = i_mult( last_bin, 16 );
545 6 : end_band = L_FRAME;
546 6 : move16();
547 6 : Ener_fx = L_deposit_l( 0 );
548 582 : FOR( i = start_band; i < end_band; i++ )
549 : {
550 576 : L_tmp = L_mult0( exc_diffQ_fx[i], exc_diffQ_fx[i] ); /*2*Q_exc */
551 576 : Ener_fx = L_add( Ener_fx, L_shr( L_tmp, 7 ) ); /*2*Q_exc-7 */
552 : }
553 :
554 6 : tmp = sub( end_band, start_band );
555 6 : tmp = div_s( 1, tmp ); /*Q15 */
556 6 : Ener_fx = Mult_32_16( Ener_fx, tmp ); /*Q(2*Q_exc-7+15)->Q(2*Q_exc-7) */
557 :
558 6 : exp1 = norm_l( Ener_fx );
559 6 : Ener_fx = L_shl( Ener_fx, exp1 );
560 6 : exp1 = sub( sub( 31, exp1 ), sub( shl( Q_exc, 1 ), 7 ) );
561 6 : Ener_fx = Isqrt_lc( Ener_fx, &exp1 ); /*Q(31-exp1) */
562 :
563 6 : weight_fx = 16384; /*Q15 */
564 6 : move16();
565 6 : src_fx = &exc_diffQ_fx[start_band]; /*Q_exc */
566 30 : FOR( i = last_bin; i < last_bin + 4; i++ )
567 : {
568 : /*Ener1 = (float)(0.4f*pow(10, Ener_per_bd_iQ[i+1])); */
569 24 : L_tmp = L_shr( L_mult0( Ener_per_bd_iQ_fx[i + 1], 27213 ), 9 ); /* 3.321928 in Q13 -> Q16 */
570 :
571 24 : frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */
572 24 : tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */
573 : /* output of Pow2() will be: */
574 : /* 16384 < Pow2() <= 32767 */
575 24 : exp = sub( exp, 14 );
576 : #ifdef ISSUE_1836_replace_overflow_libcom
577 24 : Ener1_fx = mult_r( 13107, shl_sat( tmp, exp ) ); /*Q0 */
578 : #else
579 : Ener1_fx = mult_ro( 13107, shl_o( tmp, exp, &Overflow ), &Overflow ); /*Q0 */
580 : #endif
581 :
582 408 : FOR( j = 0; j < 16; j++ )
583 : {
584 : /**src = Ener1*(weight*(*src)*Ener + (1.0f-weight)*own_random(seed_tcx)/32768.0f); */
585 384 : L_tmp = Mult_32_16( Ener_fx, *src_fx ); /*Q(31-exp+Q_exc-15) -> Q(16-exp+Q_exc) */
586 384 : tmp = extract_l( L_shr( L_tmp, add( 4, sub( Q_exc, exp1 ) ) ) ); /*Q12 */
587 384 : tmp = mult_r( weight_fx, tmp ); /*Q12 */
588 :
589 384 : L_tmp = L_mult0( sub( 32767, weight_fx ), Random( seed_tcx ) ); /*Q30 */
590 384 : tmp1 = round_fx( L_shr( L_tmp, 2 ) );
591 :
592 384 : L_exc_diffQ_fx[( ( 16 * i ) + j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */
593 384 : move32();
594 384 : src_fx++;
595 : }
596 : }
597 :
598 : /*Ener1 = (float)(0.4f*pow(10, Ener_per_bd_iQ[15])); */
599 6 : L_tmp = L_shr( L_mult0( Ener_per_bd_iQ_fx[15], 27213 ), 9 ); /* 3.321928 in Q13 -> Q16 */
600 :
601 6 : frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */
602 6 : tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */
603 : /* output of Pow2() will be: */
604 : /* 16384 < Pow2() <= 32767 */
605 6 : exp = sub( exp, 14 );
606 : #ifdef ISSUE_1836_replace_overflow_libcom
607 6 : Ener1_fx = mult_r( 13107, shl_sat( tmp, exp ) ); /*Q0 */
608 : #else
609 : Ener1_fx = mult_r( 13107, shl_o( tmp, exp, &Overflow ) ); /*Q0 */
610 : #endif
611 :
612 6 : src_fx = &exc_diffQ_fx[224];
613 198 : FOR( j = 0; j < 32; j++ )
614 : {
615 : /**src = Ener1*(weight*(*src)*Ener + (1.0f-weight)*own_random(seed_tcx)/32768.0f); */
616 192 : L_tmp = Mult_32_16( Ener_fx, *src_fx ); /*Q(31-exp+Q_exc-15) -> Q(16-exp+Q_exc) */
617 192 : tmp = extract_l( L_shr( L_tmp, add( 4, sub( Q_exc, exp1 ) ) ) ); /*Q12 */
618 192 : tmp = mult_r( weight_fx, tmp ); /*Q12 */
619 :
620 192 : L_tmp = L_mult0( sub( 32767, weight_fx ), Random( seed_tcx ) ); /*Q30 */
621 192 : tmp1 = round_fx( L_shr( L_tmp, 2 ) ); /*Q12 */
622 :
623 192 : L_exc_diffQ_fx[( ( 16 * i ) + j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */
624 192 : move32();
625 192 : src_fx++;
626 : }
627 :
628 6 : exc_diffQ_max = 0;
629 6 : move16();
630 582 : FOR( i = start_band; i < L_FRAME; i++ )
631 : {
632 576 : if ( GT_32( L_abs( L_exc_diffQ_fx[i] ), exc_diffQ_max ) )
633 : {
634 6 : exc_diffQ_max = L_abs( L_exc_diffQ_fx[i] );
635 : }
636 : }
637 6 : exp = norm_l( exc_diffQ_max );
638 :
639 6 : IF( GT_16( exp, 16 ) )
640 : {
641 0 : *Q_hb_exc = 12;
642 0 : move16();
643 0 : FOR( i = start_band; i < L_FRAME; i++ )
644 : {
645 0 : exc_diffQ_fx[i] = extract_l( L_exc_diffQ_fx[i] );
646 0 : move16();
647 : }
648 : }
649 : ELSE
650 : {
651 6 : Q_tmp = sub( 16, exp );
652 6 : *Q_hb_exc = sub( 12, Q_tmp );
653 6 : move16();
654 582 : FOR( i = start_band; i < L_FRAME; i++ )
655 : {
656 576 : exc_diffQ_fx[i] = extract_l( L_shr( L_exc_diffQ_fx[i], Q_tmp ) );
657 576 : move16();
658 : }
659 : }
660 :
661 6 : return;
662 : }
663 :
664 0 : void highband_exc_dct_in_fx(
665 : const Word32 core_brate, /* i : core bitrate */
666 : const Word16 *mfreq_bindiv, /* i : bin per bands tables */
667 : Word16 last_bin, /* i : last bin of bit allocation */
668 : Word16 Diff_len, /* i : number of bin before cut-off frequency */
669 : Word16 noise_lev, /* i : pulses dynamic */
670 : Word16 pit_band_idx, /* i : bin position of the cut-off frequency */
671 : Word16 *exc_diffQ, /* i : frequency coefficients of per band */
672 : Word16 *seed_tcx, /* i : Seed for noise */
673 : Word16 *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */
674 : Word16 nb_subfr, /* i : Number of subframe considered */
675 : Word16 *exc_dct_in, /* o : dct of residual signal */
676 : Word16 last_coder_type, /* i : coding type of last frame */
677 : Word16 *bitallocation_band, /* i : bit allocation flag of each band */
678 : const Word16 *lsf_new, /* i : LSFs at the end of the frame */
679 : Word16 *last_exc_dct_in, /* i : dct of residual signal of last frame */
680 : Word16 *last_ener, /* i : frequency energy of last frame */
681 : Word16 *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */
682 : Word16 *bitallocation_exc, /* i : flag of decoded coefficients */
683 : Word16 bfi, /* i : bad frame indicator */
684 : const Word16 coder_type, /* i : coder type */
685 : Word16 bwidth,
686 : Word16 *exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */
687 : Word16 Qexc_diffQ,
688 : Word16 Q_exc,
689 : const Word16 GSC_noisy_speech,
690 : Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy */
691 : const Word16 L_frame, /* i : frame length */
692 : const Word16 element_mode, /* i : IVAS element mode */
693 : const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */
694 : )
695 : {
696 : Word16 i, j, k;
697 0 : Word16 MAX_Bin = 0;
698 0 : Word16 last_bin_tmp, ener = 0;
699 0 : move16();
700 : Word16 noisepb[MBANDS_GN16k];
701 : Word16 Ener_per_bd_yQ[MBANDS_GN16k];
702 : Word16 *src, *dst;
703 : Word32 L_tmp;
704 0 : Word16 length_bin, bwe_flag = 0, tmp;
705 0 : move16();
706 : Word16 frac, exp, tmp1;
707 : Word16 tmp2;
708 : Word16 *end, Q_hb_exc;
709 : #ifndef ISSUE_1836_replace_overflow_libcom
710 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
711 : Flag Overflow = 0;
712 : move16();
713 : #endif
714 : #endif
715 :
716 0 : FOR( j = 10; j < MBANDS_GN; j++ )
717 : {
718 : /* ener += (float)pow(10, Ener_per_bd_iQ[j]);
719 : ener += (float)pow(2, 3.321928*Ener_per_bd_iQ[j]); */
720 :
721 0 : L_tmp = L_mult( Ener_per_bd_iQ[j], 27213 ); /* 3.321928 in Q13 -> Q27 */
722 0 : L_tmp = L_shr( L_tmp, 10 ); /* From Q27 to Q16 */
723 :
724 0 : frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */
725 0 : tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */
726 : /* output of Pow2() will be: */
727 : /* 16384 < Pow2() <= 32767 */
728 0 : exp = sub( exp, 14 );
729 : #ifdef ISSUE_1836_replace_overflow_libcom
730 0 : tmp1 = shl_sat( tmp, exp );
731 0 : move16();
732 0 : ener = add_sat( tmp1, ener ); /*Q0 */
733 : #else
734 : tmp1 = shl_o( tmp, exp, &Overflow );
735 : move16();
736 : ener = add_o( tmp1, ener, &Overflow ); /*Q0 */
737 : #endif
738 : }
739 :
740 0 : test();
741 0 : IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) )
742 : {
743 0 : if ( NE_16( last_coder_type, AUDIO ) )
744 : {
745 0 : *last_ener = ener;
746 0 : move16();
747 : }
748 0 : test();
749 0 : test();
750 0 : IF( ( GT_16( last_bin, 8 ) || Diff_len != 0 ) && EQ_16( last_coder_type, AUDIO ) )
751 : {
752 0 : MAX_Bin = 10;
753 0 : move16();
754 0 : bwe_flag = 1;
755 0 : move16();
756 : }
757 : ELSE
758 : {
759 0 : MAX_Bin = 15;
760 0 : move16();
761 : }
762 :
763 0 : last_bin_tmp = last_bin;
764 0 : move16();
765 0 : last_bin = s_max( last_bin, MAX_Bin );
766 0 : last_bin = add( last_bin, 1 );
767 : }
768 : ELSE
769 : {
770 0 : IF( EQ_16( L_frame, L_FRAME16k ) )
771 : {
772 0 : last_bin = MBANDS_GN16k;
773 0 : move16();
774 : }
775 : ELSE
776 : {
777 0 : last_bin = MBANDS_GN;
778 0 : move16();
779 : }
780 0 : last_bin_tmp = last_bin;
781 0 : move16();
782 : }
783 :
784 0 : test();
785 0 : test();
786 0 : test();
787 0 : test();
788 0 : IF( bfi || LT_32( core_brate, 6000 ) || ( LT_32( core_brate, 8600 ) && EQ_16( coder_type, UNVOICED ) ) )
789 : {
790 0 : set16_fx( noisepb, 13107, MBANDS_GN ); /*0.4 in Q15 */
791 : }
792 0 : ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) || ( GSC_IVAS_mode > 0 && EQ_16( GSC_noisy_speech, 1 ) ) )
793 : {
794 0 : set16_fx( noisepb, 13107 /*0.4f*/, MBANDS_GN16k );
795 : }
796 : ELSE
797 : {
798 0 : EstimateNoiseLevel_fx( noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, last_bin_tmp, bwidth, L_frame );
799 : }
800 :
801 0 : IF( exc_wo_nf != NULL )
802 : {
803 0 : Copy( exc_diffQ, exc_wo_nf, L_frame );
804 : }
805 :
806 0 : test();
807 0 : test();
808 0 : test();
809 0 : IF( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16( element_mode, IVAS_SCE ) )
810 : {
811 0 : set16_fx( noisepb, 3277, MBANDS_GN );
812 : }
813 0 : test();
814 0 : IF( LT_32( core_brate, 6000 ) && LE_16( coder_type, UNVOICED ) )
815 : {
816 0 : FOR( i = 0; i < L_frame; i++ )
817 : {
818 0 : IF( exc_diffQ[i] == 0 )
819 : {
820 : /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/
821 0 : tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */
822 0 : tmp = shr( tmp, sub( 15, Qexc_diffQ ) ); /*qNoise_fac */
823 0 : exc_diffQ[i] = add( exc_diffQ[i], tmp );
824 0 : move16(); /*Q */
825 : }
826 : }
827 : }
828 : ELSE
829 : {
830 0 : Apply_NoiseFill_fx( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ );
831 : }
832 : /*--------------------------------------------------------------------------------------*
833 : * Quantize average gain
834 : * Subtract Q averaged gain
835 : * VQ of remaining gain per band
836 : *--------------------------------------------------------------------------------------*/
837 0 : test();
838 0 : IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) )
839 : {
840 0 : Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0 );
841 : }
842 : ELSE
843 : {
844 0 : Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1 );
845 :
846 0 : IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) )
847 : {
848 0 : FOR( i = L_FRAME - 16; i < L_FRAME; i++ )
849 : {
850 : /*exc_diffQ[i] *= 0.067f * i - 15.0f; = -15 - (-0.067f * i) */
851 0 : tmp = msu_r( -7680 * 65536, -17564, shl( i, 6 ) ); /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */
852 0 : L_tmp = L_mult( exc_diffQ[i], tmp ); /*Q(Qexc_diffQ+10) */
853 0 : exc_diffQ[i] = round_fx( L_shl( L_tmp, 16 - 10 ) ); /*Qexc_diffQ */
854 0 : move16();
855 : }
856 : }
857 : }
858 : /*--------------------------------------------------------------------------------------*
859 : * Check potential energy excitation overshoot
860 : *--------------------------------------------------------------------------------------*/
861 0 : IF( bfi )
862 : {
863 0 : test();
864 0 : IF( GSC_noisy_speech == 0 && GT_16( coder_type, UNVOICED ) ) /* Here coder_type == last_coder_type because of the bfi */
865 : {
866 0 : FOR( i = 0; i < last_bin; i++ )
867 : {
868 0 : Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( sub( lt_ener_per_band_fx[i], 154 ), Ener_per_bd_yQ[i] ) );
869 0 : move16();
870 0 : lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
871 0 : move16();
872 : }
873 0 : FOR( ; i < MBANDS_GN; i++ )
874 : {
875 0 : Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( lt_ener_per_band_fx[i], 154 ) );
876 0 : move16();
877 0 : lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
878 0 : move16();
879 : }
880 : }
881 : ELSE
882 : {
883 0 : FOR( i = 0; i < last_bin; i++ )
884 : {
885 0 : Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( add( lt_ener_per_band_fx[i], 1229 ), Ener_per_bd_yQ[i] ) );
886 0 : move16();
887 0 : lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
888 0 : move16();
889 : }
890 0 : FOR( ; i < MBANDS_GN; i++ )
891 : {
892 0 : Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], add( lt_ener_per_band_fx[i], 1229 ) );
893 0 : move16();
894 0 : lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
895 0 : move16();
896 : }
897 : }
898 : }
899 : /*--------------------------------------------------------------------------------------*
900 : * Apply decoded gain onto the difference signal
901 : *--------------------------------------------------------------------------------------*/
902 :
903 0 : IF( GSC_noisy_speech )
904 : {
905 0 : FOR( i = 0; i < L_frame; i++ )
906 : {
907 0 : exc_diffQ[i] = mult_r( exc_diffQ[i], 29491 );
908 0 : move16();
909 : }
910 : }
911 :
912 0 : Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc );
913 :
914 0 : IF( exc_wo_nf != NULL )
915 : {
916 0 : Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, Q_exc );
917 0 : Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame );
918 : }
919 : /*--------------------------------------------------------------------------------------*
920 : * add the correction layer to the LF bins,
921 : * and add the quantized pulses or the noise for the higher part of the spectrum
922 : * (non valuable temporal content already zeroed)
923 : * DC is Zeroed
924 : *--------------------------------------------------------------------------------------*/
925 :
926 0 : Vr_add( exc_dct_in, exc_diffQ, exc_dct_in, L_frame );
927 0 : test();
928 0 : IF( core_brate == ACELP_8k00 && bwidth != NB )
929 : {
930 0 : IF( EQ_16( bwe_flag, 1 ) )
931 : {
932 0 : last_bin = sub( last_bin, 1 );
933 0 : tmp = i_mult( MAX_Bin, 16 );
934 0 : tmp1 = i_mult( last_bin, 16 );
935 0 : src = &exc_diffQ[L_FRAME - 1];
936 0 : move16();
937 0 : dst = &exc_dct_in[( tmp - 1 )];
938 0 : move16();
939 0 : end = &exc_diffQ[( tmp1 - 1 )];
940 0 : move16();
941 :
942 0 : WHILE( src > end )
943 : {
944 0 : *src-- = *dst--;
945 0 : move16();
946 : }
947 0 : test();
948 0 : test();
949 0 : if ( ( bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0 ) && EQ_32( core_brate, ACELP_8k00 ) )
950 : {
951 0 : exc_diffQ[160] = 0;
952 0 : move16();
953 : }
954 :
955 0 : Q_hb_exc = 0;
956 0 : move16();
957 0 : envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, Q_exc, &Q_hb_exc );
958 0 : Copy_Scale_sig( &exc_diffQ[tmp1], &exc_dct_in[tmp1], sub( L_FRAME, tmp1 ), sub( Q_exc, Q_hb_exc ) ); /* from Q_hb_exc -> Q_exc as expected */
959 : }
960 :
961 0 : IF( LT_16( nb_subfr, 4 ) )
962 : {
963 0 : FOR( i = sub( L_FRAME, 16 ); i < L_FRAME; i++ )
964 : {
965 : /*exc_dct_in[i] *= (0.067f*i-15.f); */
966 0 : tmp = mult_r( 17564, shl( i, 6 ) ); /*0.067 in Q18 and i in Q6= Q9 */
967 0 : tmp = sub( tmp, 7680 ); /*15 in Q9 = Q9 */
968 0 : L_tmp = L_mult( exc_dct_in[i], tmp ); /*Q(Q_exc+10) */
969 : #ifdef ISSUE_1836_replace_overflow_libcom
970 0 : exc_dct_in[i] = round_fx_sat( L_shl_sat( L_tmp, 6 ) ); /*Q_exc */
971 : #else
972 : exc_dct_in[i] = round_fx_o( L_shl_o( L_tmp, 6, &Overflow ), &Overflow ); /*Q_exc */
973 : #endif
974 : }
975 : }
976 :
977 0 : tmp1 = mult_r( ener, 16384 );
978 0 : tmp1 = sub( *last_ener, tmp1 );
979 0 : tmp = mult_r( *last_ener, 16384 );
980 0 : tmp = sub( ener, tmp );
981 0 : test();
982 0 : IF( tmp > 0 && tmp1 > 0 )
983 : {
984 0 : length_bin = 6;
985 0 : move16();
986 0 : IF( last_coder_type != AUDIO )
987 : {
988 0 : set16_fx( last_bitallocation_band, 0, 6 );
989 0 : Copy( &exc_dct_in[( 4 + length_bin ) * 16], &last_exc_dct_in[( 4 + length_bin ) * 16], length_bin * 16 );
990 : }
991 :
992 0 : FOR( i = 4; i < ( 4 + length_bin ); i++ )
993 : {
994 0 : test();
995 0 : IF( !( bitallocation_band[i] == 0 && last_bitallocation_band[i - 4] == 0 ) )
996 : {
997 0 : k = shl( add( i, length_bin ), 4 );
998 0 : src = &exc_dct_in[k]; /*(i+length_bin)*16*/
999 0 : dst = &last_exc_dct_in[k];
1000 0 : FOR( j = 0; j < 16; j++ )
1001 : {
1002 0 : tmp = mult_r( 10923, abs_s( *src ) );
1003 0 : tmp1 = mult_r( 10923, abs_s( *dst ) );
1004 :
1005 0 : IF( GT_16( tmp, abs_s( *dst ) ) )
1006 : {
1007 0 : tmp2 = *src;
1008 : #ifdef ISSUE_1836_replace_overflow_libcom
1009 0 : *src = mult_r( 16384, sub_sat( *src, abs_s( *dst ) ) ); /*Q_exc */
1010 0 : move16();
1011 0 : tmp = mult_r( 16384, add_sat( tmp2, abs_s( *dst ) ) ); /*Q_exc */
1012 : #else
1013 : *src = mult_r( 16384, sub_o( *src, abs_s( *dst ), &Overflow ) ); /*Q_exc */
1014 : move16();
1015 : tmp = mult_r( 16384, add_o( tmp2, abs_s( *dst ), &Overflow ) ); /*Q_exc */
1016 : #endif
1017 0 : if ( tmp2 > 0 )
1018 : {
1019 0 : *src = tmp;
1020 0 : move16();
1021 : }
1022 : }
1023 0 : ELSE IF( GT_16( tmp1, abs_s( *src ) ) )
1024 : {
1025 0 : tmp = mult_r( *src, 22938 );
1026 0 : tmp1 = mult_r( 9830, abs_s( *dst ) );
1027 0 : tmp2 = *src;
1028 0 : *src = sub( tmp, tmp1 ); /*Q_exc */
1029 0 : move16();
1030 0 : if ( tmp2 > 0 )
1031 : {
1032 0 : *src = add( tmp, tmp1 ); /*Q_exc */
1033 0 : move16();
1034 : }
1035 : }
1036 0 : src++;
1037 0 : dst++;
1038 : }
1039 : }
1040 : }
1041 : }
1042 0 : IF( EQ_16( bwe_flag, 1 ) )
1043 : {
1044 0 : Decreas_freqPeak_fx( lsf_new, exc_dct_in, 9830 );
1045 : }
1046 : ELSE
1047 : {
1048 0 : Decreas_freqPeak_fx( lsf_new, exc_dct_in, 16384 );
1049 : }
1050 : }
1051 :
1052 0 : Copy( &exc_dct_in[64], &last_exc_dct_in[64], L_frame - 64 );
1053 0 : Copy( &bitallocation_band[4], last_bitallocation_band, 6 );
1054 0 : *last_ener = ener;
1055 0 : move16();
1056 :
1057 0 : return;
1058 : }
1059 :
1060 20795 : void highband_exc_dct_in_ivas_fx(
1061 : const Word32 core_brate, /* i : core bitrate */
1062 : const Word16 *mfreq_bindiv, /* i : bin per bands tables */
1063 : Word16 last_bin, /* i : last bin of bit allocation */
1064 : Word16 Diff_len, /* i : number of bin before cut-off frequency */
1065 : Word16 noise_lev, /* i : pulses dynamic */
1066 : Word16 pit_band_idx, /* i : bin position of the cut-off frequency */
1067 : Word16 *exc_diffQ, /* i : frequency coefficients of per band */
1068 : Word16 *seed_tcx, /* i : Seed for noise */
1069 : Word16 *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */
1070 : Word16 nb_subfr, /* i : Number of subframe considered */
1071 : Word16 *exc_dct_in, /* o : dct of residual signal */
1072 : Word16 last_coder_type, /* i : coding type of last frame */
1073 : Word16 *bitallocation_band, /* i : bit allocation flag of each band */
1074 : const Word16 *lsf_new, /* i : LSFs at the end of the frame */
1075 : Word16 *last_exc_dct_in, /* i : dct of residual signal of last frame */
1076 : Word16 *last_ener, /* i : frequency energy of last frame */
1077 : Word16 *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */
1078 : Word16 *bitallocation_exc, /* i : flag of decoded coefficients */
1079 : Word16 bfi, /* i : bad frame indicator */
1080 : const Word16 coder_type, /* i : coder type */
1081 : Word16 bwidth,
1082 : Word16 *exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */
1083 : Word16 Qexc_diffQ,
1084 : Word16 *Q_exc,
1085 : const Word16 GSC_noisy_speech,
1086 : Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy */
1087 : const Word16 L_frame, /* i : frame length */
1088 : const Word16 element_mode, /* i : IVAS element mode */
1089 : const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */
1090 : )
1091 : {
1092 : Word16 i, j, k;
1093 20795 : Word16 MAX_Bin = 0;
1094 20795 : Word16 last_bin_tmp, ener = 0;
1095 20795 : move16();
1096 : Word16 noisepb[MBANDS_GN16k];
1097 : Word16 Ener_per_bd_yQ[MBANDS_GN16k];
1098 : Word16 *src, *dst;
1099 : Word32 L_tmp;
1100 20795 : Word16 length_bin, bwe_flag = 0, tmp;
1101 20795 : move16();
1102 : Word16 frac, exp, tmp1;
1103 : Word16 tmp2;
1104 : Word16 *end, Q_hb_exc;
1105 : #ifndef ISSUE_1836_replace_overflow_libcom
1106 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
1107 : Flag Overflow = 0;
1108 : move16();
1109 : #endif
1110 : #endif
1111 :
1112 145565 : FOR( j = 10; j < MBANDS_GN; j++ )
1113 : {
1114 : /* ener += (float)pow(10, Ener_per_bd_iQ[j]);
1115 : ener += (float)pow(2, 3.321928*Ener_per_bd_iQ[j]); */
1116 :
1117 124770 : L_tmp = L_mult( Ener_per_bd_iQ[j], 27213 ); /* 3.321928 in Q13 -> Q27 */
1118 124770 : L_tmp = L_shr( L_tmp, 10 ); /* From Q27 to Q16 */
1119 :
1120 124770 : frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */
1121 124770 : tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */
1122 : /* output of Pow2() will be: */
1123 : /* 16384 < Pow2() <= 32767 */
1124 124770 : exp = sub( exp, 14 );
1125 : #ifdef ISSUE_1836_replace_overflow_libcom
1126 124770 : tmp1 = shl_sat( tmp, exp );
1127 124770 : move16();
1128 124770 : ener = add_sat( tmp1, ener ); /*Q0 */
1129 : #else
1130 : tmp1 = shl_o( tmp, exp, &Overflow );
1131 : move16();
1132 : ener = add_o( tmp1, ener, &Overflow ); /*Q0 */
1133 : #endif
1134 : }
1135 :
1136 20795 : test();
1137 20795 : IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) )
1138 : {
1139 21 : IF( NE_16( last_coder_type, AUDIO ) )
1140 : {
1141 15 : *last_ener = ener;
1142 15 : move16();
1143 : }
1144 21 : test();
1145 21 : test();
1146 21 : IF( ( GT_16( last_bin, 8 ) || Diff_len != 0 ) && EQ_16( last_coder_type, AUDIO ) )
1147 : {
1148 6 : MAX_Bin = 10;
1149 6 : move16();
1150 6 : bwe_flag = 1;
1151 6 : move16();
1152 : }
1153 : ELSE
1154 : {
1155 15 : MAX_Bin = 15;
1156 15 : move16();
1157 : }
1158 :
1159 21 : last_bin_tmp = last_bin;
1160 21 : move16();
1161 21 : last_bin = s_max( last_bin, MAX_Bin );
1162 21 : last_bin = add( last_bin, 1 );
1163 : }
1164 : ELSE
1165 : {
1166 20774 : IF( EQ_16( L_frame, L_FRAME16k ) )
1167 : {
1168 2537 : last_bin = MBANDS_GN16k;
1169 2537 : move16();
1170 : }
1171 : ELSE
1172 : {
1173 18237 : last_bin = MBANDS_GN;
1174 18237 : move16();
1175 : }
1176 20774 : last_bin_tmp = last_bin;
1177 20774 : move16();
1178 : }
1179 :
1180 20795 : test();
1181 20795 : test();
1182 20795 : test();
1183 20795 : test();
1184 20795 : IF( bfi || LT_32( core_brate, 6000 ) || ( LT_32( core_brate, 8600 ) && EQ_16( coder_type, UNVOICED ) ) )
1185 : {
1186 6875 : set16_fx( noisepb, 13107, MBANDS_GN ); /*0.4 in Q15 */
1187 : }
1188 13920 : ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) || ( GSC_IVAS_mode > 0 && EQ_16( GSC_noisy_speech, 1 ) ) )
1189 : {
1190 2402 : set16_fx( noisepb, 13107 /*0.4f*/, MBANDS_GN16k );
1191 : }
1192 : ELSE
1193 : {
1194 11518 : EstimateNoiseLevel_fx( noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, last_bin_tmp, bwidth, L_frame );
1195 : }
1196 :
1197 20795 : IF( exc_wo_nf != NULL )
1198 : {
1199 20591 : Copy( exc_diffQ, exc_wo_nf, L_frame );
1200 : }
1201 :
1202 20795 : test();
1203 20795 : test();
1204 :
1205 20795 : IF( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16( element_mode, IVAS_SCE ) )
1206 : {
1207 7147 : set16_fx( noisepb, 3277, MBANDS_GN );
1208 : }
1209 :
1210 20795 : test();
1211 20795 : IF( LT_32( core_brate, 6000 ) && LE_16( coder_type, UNVOICED ) )
1212 : {
1213 1721129 : FOR( i = 0; i < L_frame; i++ )
1214 : {
1215 1714432 : IF( exc_diffQ[i] == 0 )
1216 : {
1217 : /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/
1218 1700460 : tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */
1219 1700460 : tmp = shr( tmp, sub( 15, Qexc_diffQ ) ); /*qNoise_fac */
1220 1700460 : exc_diffQ[i] = add( exc_diffQ[i], tmp );
1221 1700460 : move16(); /*Q */
1222 : }
1223 : }
1224 : }
1225 : ELSE
1226 : {
1227 14098 : Apply_NoiseFill_fx( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ );
1228 : }
1229 : /*--------------------------------------------------------------------------------------*
1230 : * Quantize average gain
1231 : * Subtract Q averaged gain
1232 : * VQ of remaining gain per band
1233 : *--------------------------------------------------------------------------------------*/
1234 20795 : test();
1235 20795 : IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) )
1236 : {
1237 21 : Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame );
1238 : }
1239 : ELSE
1240 : {
1241 20774 : Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame );
1242 :
1243 20774 : test();
1244 20774 : IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) )
1245 : {
1246 255510 : FOR( i = L_FRAME - 16; i < L_FRAME; i++ )
1247 : {
1248 : /*exc_diffQ[i] *= 0.067f * i - 15.0f; = -15 - (-0.067f * i) */
1249 240480 : tmp = msu_r( -7680 * 65536, -17564, shl( i, 6 ) ); /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */
1250 240480 : L_tmp = L_mult( exc_diffQ[i], tmp ); /*Q(Qexc_diffQ+10) */
1251 240480 : exc_diffQ[i] = round_fx( L_shl( L_tmp, 16 - 10 ) ); /*Qexc_diffQ */
1252 240480 : move16();
1253 : }
1254 : }
1255 : }
1256 : /*--------------------------------------------------------------------------------------*
1257 : * Check potential energy excitation overshoot
1258 : *--------------------------------------------------------------------------------------*/
1259 20795 : IF( bfi )
1260 : {
1261 204 : test();
1262 204 : IF( GSC_noisy_speech == 0 && GT_16( coder_type, UNVOICED ) ) /* Here coder_type == last_coder_type because of the bfi */
1263 : {
1264 1428 : FOR( i = 0; i < last_bin; i++ )
1265 : {
1266 1344 : Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub_sat( sub_sat( lt_ener_per_band_fx[i], 154 ), Ener_per_bd_yQ[i] ) );
1267 1344 : move16();
1268 1344 : lt_ener_per_band_fx[i] = sub_sat( lt_ener_per_band_fx[i], 77 );
1269 1344 : move16();
1270 : }
1271 84 : FOR( ; i < MBANDS_GN; i++ )
1272 : {
1273 0 : Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( lt_ener_per_band_fx[i], 154 ) );
1274 0 : move16();
1275 0 : lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
1276 0 : move16();
1277 : }
1278 : }
1279 : ELSE
1280 : {
1281 2048 : FOR( i = 0; i < last_bin; i++ )
1282 : {
1283 1928 : Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub_sat( add( lt_ener_per_band_fx[i], 1229 ), Ener_per_bd_yQ[i] ) );
1284 1928 : move16();
1285 1928 : lt_ener_per_band_fx[i] = sub_sat( lt_ener_per_band_fx[i], 77 );
1286 1928 : move16();
1287 : }
1288 120 : FOR( ; i < MBANDS_GN; i++ )
1289 : {
1290 0 : Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], add( lt_ener_per_band_fx[i], 1229 ) );
1291 0 : move16();
1292 0 : lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
1293 0 : move16();
1294 : }
1295 : }
1296 : }
1297 :
1298 : /*--------------------------------------------------------------------------------------*
1299 : * Apply decoded gain onto the difference signal
1300 : *--------------------------------------------------------------------------------------*/
1301 :
1302 20795 : IF( GSC_IVAS_mode >= 1 )
1303 : {
1304 4152 : Word16 scale_factLF = 29491; /* 0.9f */
1305 4152 : move16();
1306 4152 : Word16 scale_factHF = 29491; /* 0.9f */
1307 4152 : move16();
1308 :
1309 4152 : test();
1310 4152 : test();
1311 4152 : IF( EQ_16( GSC_IVAS_mode, 1 ) && GSC_noisy_speech == 0 )
1312 : {
1313 1532 : scale_factHF = 26214;
1314 1532 : move16();
1315 : }
1316 2620 : ELSE IF( EQ_16( GSC_IVAS_mode, 2 ) || EQ_16( GSC_noisy_speech, 1 ) )
1317 : {
1318 317 : scale_factHF = 23265; /* 0.71f */
1319 317 : move16();
1320 : }
1321 2303 : ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) )
1322 : {
1323 2303 : scale_factHF = 29491; /* 0.9f */
1324 2303 : move16();
1325 : }
1326 576328 : FOR( i = 0; i < pit_band_idx * 16; i++ )
1327 : {
1328 572176 : exc_diffQ[i] = mult_r( exc_diffQ[i], scale_factLF );
1329 : }
1330 494888 : FOR( ; i < L_frame; i++ )
1331 : {
1332 490736 : exc_diffQ[i] = mult_r( exc_diffQ[i], scale_factHF );
1333 490736 : move16();
1334 : }
1335 : }
1336 16643 : ELSE IF( GSC_noisy_speech )
1337 : {
1338 7524 : Word16 scale_fact = 29491; /* 0.9f */
1339 7524 : move16();
1340 :
1341 7524 : IF( EQ_16( element_mode, IVAS_CPE_TD ) )
1342 : {
1343 26 : IF( coder_type == INACTIVE )
1344 : {
1345 0 : scale_fact = 32767; /* 1.0f */
1346 0 : move16();
1347 : }
1348 : ELSE
1349 : {
1350 26 : scale_fact = 31129; /* 0.95f */
1351 26 : move16();
1352 : }
1353 : }
1354 7498 : ELSE IF( GT_16( element_mode, IVAS_SCE ) )
1355 : {
1356 305 : scale_fact = 23265; /* 0.71f */
1357 305 : move16();
1358 : }
1359 :
1360 1933668 : FOR( i = 0; i < L_frame; i++ )
1361 : {
1362 1926144 : exc_diffQ[i] = mult_r( exc_diffQ[i], scale_fact );
1363 1926144 : move16();
1364 : }
1365 : }
1366 :
1367 20795 : IF( GSC_noisy_speech && GT_16( element_mode, IVAS_SCE ) && LT_32( core_brate, ACELP_7k20 ) )
1368 : {
1369 4425 : FOR( i = 80; i < L_frame; i++ )
1370 : {
1371 : /* exc_diffQ[i] *= (+0.0024f * (float)i + 1.192f); */
1372 4400 : exc_diffQ[i] = mult_r( shl( exc_diffQ[i], 1 ) /*Q16*/, (Word16) L_shr( L_add( 629 * i, 312475 ) /*Q18*/, Q4 ) /*Q14*/ );
1373 4400 : move16();
1374 : }
1375 : }
1376 :
1377 20795 : IF( EQ_16( element_mode, EVS_MONO ) )
1378 : {
1379 6 : Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc );
1380 :
1381 6 : IF( exc_wo_nf != NULL )
1382 : {
1383 6 : Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, *Q_exc );
1384 6 : Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame );
1385 : }
1386 : }
1387 : ELSE
1388 : {
1389 20789 : Word16 Q_tmp = *Q_exc;
1390 20789 : move16();
1391 20789 : Word16 Q_old = *Q_exc;
1392 20789 : move16();
1393 20789 : Comp_and_apply_gain_ivas_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc );
1394 :
1395 20789 : IF( exc_wo_nf != NULL )
1396 : {
1397 20585 : Comp_and_apply_gain_ivas_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, &Q_tmp );
1398 20585 : IF( GT_16( Q_tmp, *Q_exc ) )
1399 : {
1400 0 : Scale_sig( exc_wo_nf, L_frame, sub( *Q_exc, Q_tmp ) );
1401 : }
1402 20585 : ELSE IF( LT_16( Q_tmp, *Q_exc ) )
1403 : {
1404 4 : Scale_sig( exc_diffQ, L_frame, sub( Q_tmp, *Q_exc ) );
1405 4 : *Q_exc = Q_tmp;
1406 4 : move16();
1407 : }
1408 20585 : Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) );
1409 20585 : Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame );
1410 : }
1411 : ELSE
1412 : {
1413 204 : Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) );
1414 : }
1415 : }
1416 :
1417 : /*--------------------------------------------------------------------------------------*
1418 : * add the correction layer to the LF bins,
1419 : * and add the quantized pulses or the noise for the higher part of the spectrum
1420 : * (non valuable temporal content already zeroed)
1421 : * DC is Zeroed
1422 : *--------------------------------------------------------------------------------------*/
1423 :
1424 20795 : Vr_add( exc_dct_in, exc_diffQ, exc_dct_in, L_frame );
1425 20795 : test();
1426 20795 : IF( EQ_32( core_brate, ACELP_8k00 ) && bwidth != NB )
1427 : {
1428 21 : IF( EQ_16( bwe_flag, 1 ) )
1429 : {
1430 6 : last_bin = sub( last_bin, 1 );
1431 6 : tmp = i_mult( MAX_Bin, 16 );
1432 6 : tmp1 = i_mult( last_bin, 16 );
1433 6 : src = &exc_diffQ[( L_FRAME - 1 )];
1434 6 : move16();
1435 6 : dst = &exc_dct_in[( tmp - 1 )];
1436 6 : move16();
1437 6 : end = &exc_diffQ[( tmp1 - 1 )];
1438 6 : move16();
1439 :
1440 582 : WHILE( src > end )
1441 : {
1442 576 : *src-- = *dst--;
1443 576 : move16();
1444 : }
1445 6 : test();
1446 6 : test();
1447 6 : IF( ( bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0 ) && EQ_32( core_brate, ACELP_8k00 ) )
1448 : {
1449 0 : exc_diffQ[160] = 0;
1450 0 : move16();
1451 : }
1452 :
1453 6 : Q_hb_exc = 0;
1454 6 : move16();
1455 6 : envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, *Q_exc, &Q_hb_exc );
1456 :
1457 6 : test();
1458 6 : test();
1459 6 : IF( GT_16( *Q_exc, Q_hb_exc ) && GT_16( element_mode, EVS_MONO ) && exc_wo_nf != NULL )
1460 : {
1461 0 : Scale_sig( exc_wo_nf, L_frame, sub( Q_hb_exc, *Q_exc ) );
1462 0 : *Q_exc = Q_hb_exc;
1463 0 : move16();
1464 : }
1465 : ELSE
1466 : {
1467 6 : Scale_sig( &exc_diffQ[tmp1], sub( L_FRAME, tmp1 ), sub( *Q_exc, Q_hb_exc ) );
1468 : }
1469 6 : Copy( &exc_diffQ[tmp1], &exc_dct_in[tmp1], sub( L_FRAME, tmp1 ) ); /* from Q_hb_exc -> Q_exc as expected */
1470 : }
1471 :
1472 21 : IF( LT_16( nb_subfr, 4 ) )
1473 : {
1474 68 : FOR( i = sub( L_FRAME, 16 ); i < L_FRAME; i++ )
1475 : {
1476 : /*exc_dct_in[i] *= (0.067f*i-15.f); */
1477 64 : tmp = mult_r( 17564, shl( i, 6 ) ); /*0.067 in Q18 and i in Q6= Q9 */
1478 64 : tmp = sub( tmp, 7680 ); /*15 in Q9 = Q9 */
1479 64 : L_tmp = L_mult( exc_dct_in[i], tmp ); /*Q(Q_exc+10) */
1480 : #ifdef ISSUE_1836_replace_overflow_libcom
1481 64 : exc_dct_in[i] = round_fx_sat( L_shl_sat( L_tmp, 6 ) ); /*Q_exc */
1482 : #else
1483 : exc_dct_in[i] = round_fx_o( L_shl_o( L_tmp, 6, &Overflow ), &Overflow ); /*Q_exc */
1484 : #endif
1485 : }
1486 : }
1487 :
1488 21 : tmp1 = mult_r( ener, 16384 );
1489 21 : tmp1 = sub( *last_ener, tmp1 );
1490 21 : tmp = mult_r( *last_ener, 16384 );
1491 21 : tmp = sub( ener, tmp );
1492 21 : test();
1493 21 : IF( tmp > 0 && tmp1 > 0 )
1494 : {
1495 21 : length_bin = 6;
1496 21 : move16();
1497 21 : IF( last_coder_type != AUDIO )
1498 : {
1499 15 : set16_fx( last_bitallocation_band, 0, 6 );
1500 15 : Copy( &exc_dct_in[( 4 + length_bin ) * 16], &last_exc_dct_in[( 4 + length_bin ) * 16], length_bin * 16 );
1501 : }
1502 :
1503 147 : FOR( i = 4; i < ( 4 + length_bin ); i++ )
1504 : {
1505 126 : test();
1506 126 : IF( !( bitallocation_band[i] == 0 && last_bitallocation_band[i - 4] == 0 ) )
1507 : {
1508 103 : k = shl( add( i, length_bin ), 4 );
1509 103 : src = &exc_dct_in[k]; /*(i+length_bin)*16*/
1510 103 : dst = &last_exc_dct_in[k];
1511 1751 : FOR( j = 0; j < 16; j++ )
1512 : {
1513 1648 : tmp = mult_r( 10923, abs_s( *src ) );
1514 1648 : tmp1 = mult_r( 10923, abs_s( *dst ) );
1515 :
1516 1648 : IF( GT_16( tmp, abs_s( *dst ) ) )
1517 : {
1518 114 : tmp2 = *src;
1519 : #ifdef ISSUE_1836_replace_overflow_libcom
1520 114 : *src = mult_r( 16384, sub_sat( *src, abs_s( *dst ) ) ); /*Q_exc */
1521 114 : move16();
1522 114 : tmp = mult_r( 16384, add_sat( tmp2, abs_s( *dst ) ) ); /*Q_exc */
1523 : #else
1524 : *src = mult_r( 16384, sub_o( *src, abs_s( *dst ), &Overflow ) ); /*Q_exc */
1525 : move16();
1526 : tmp = mult_r( 16384, add_o( tmp2, abs_s( *dst ), &Overflow ) ); /*Q_exc */
1527 : #endif
1528 114 : IF( tmp2 > 0 )
1529 : {
1530 72 : *src = tmp;
1531 72 : move16();
1532 : }
1533 : }
1534 1534 : ELSE IF( GT_16( tmp1, abs_s( *src ) ) )
1535 : {
1536 126 : tmp = mult_r( *src, 22938 );
1537 126 : tmp1 = mult_r( 9830, abs_s( *dst ) );
1538 126 : tmp2 = *src;
1539 126 : *src = sub( tmp, tmp1 ); /*Q_exc */
1540 126 : move16();
1541 126 : IF( tmp2 > 0 )
1542 : {
1543 72 : *src = add( tmp, tmp1 ); /*Q_exc */
1544 72 : move16();
1545 : }
1546 : }
1547 1648 : src++;
1548 1648 : dst++;
1549 : }
1550 : }
1551 : }
1552 : }
1553 21 : IF( EQ_16( bwe_flag, 1 ) )
1554 : {
1555 6 : Decreas_freqPeak_fx( lsf_new, exc_dct_in, 9830 );
1556 : }
1557 : ELSE
1558 : {
1559 15 : Decreas_freqPeak_fx( lsf_new, exc_dct_in, 16384 );
1560 : }
1561 : }
1562 :
1563 20795 : Copy( &exc_dct_in[64], &last_exc_dct_in[64], L_frame - 64 );
1564 20795 : Copy( &bitallocation_band[4], last_bitallocation_band, 6 );
1565 20795 : *last_ener = ener;
1566 20795 : move16();
1567 :
1568 20795 : return;
1569 : }
|