Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 :
37 : #include <stdint.h>
38 : #include "options.h"
39 : #ifdef DEBUGGING
40 : #include "debug.h"
41 : #endif
42 : #include <math.h>
43 : #include "cnst.h"
44 : #include "rom_com.h"
45 : #include "rom_dec.h"
46 : #include "prot.h"
47 : #include "wmc_auto.h"
48 :
49 : /*-------------------------------------------------------------------*
50 : * Local function prototypes
51 : *-------------------------------------------------------------------*/
52 :
53 : static void gain_dec_bfi( float *past_qua_en );
54 :
55 : static void pulseRes_preCalc( Word16 *cond1, Word16 *cond2, Word32 *cond3, Word16 new_pit, Word16 Tc, Word16 L_frame );
56 :
57 :
58 : /*-------------------------------------------------------------------*
59 : * FEC_exc_estim()
60 : *
61 : * Calculation of excitation signal
62 : *-------------------------------------------------------------------*/
63 :
64 23796 : void FEC_exc_estim(
65 : Decoder_State *st, /* i/o: Decoder static memory */
66 : const int16_t L_frame, /* i : length of the frame */
67 : float *exc, /* o : pointer to excitation buffer (with past) */
68 : float *exc2, /* o : total excitation (for synthesis) */
69 : float *exc_dct_in, /* o : GSC excitation in DCT domain */
70 : float *pitch_buf, /* o : pitch buffer for each subframe */
71 : float *voice_factors, /* o : voicing factors */
72 : float *tmp_tc, /* o : FEC pitch */
73 : float *bwe_exc, /* o : excitation for SWB TBE */
74 : float *lsf_new, /* i : ISFs at the end of the frame */
75 : float *tmp_noise /* o : long-term noise energy */
76 : )
77 : {
78 : int16_t i, Tc, new_pit;
79 : float exc2_buf[L_FRAME16k + MODE1_L_FIR_FER - 1];
80 : float *pt_exc, *pt1_exc, alpha, step, gain_inov, gain, gainCNG, hp_filt[5];
81 : float fT0, delta, ftmp;
82 : int16_t Diff_len;
83 : int16_t Len, max_len;
84 : int16_t last_bin;
85 23796 : int16_t extrapolationFailed = 1;
86 : float predPitchLag;
87 : Word16 cond1, cond2;
88 : Word32 cond3;
89 :
90 : /*-----------------------------------------------------------------*
91 : * Initializations
92 : *-----------------------------------------------------------------*/
93 :
94 23796 : gainCNG = (float) sqrt( st->lp_ener );
95 :
96 23796 : ftmp = 2.0f * st->lp_gainc;
97 23796 : if ( gainCNG > ftmp )
98 : {
99 210 : gainCNG = ftmp;
100 : }
101 :
102 23796 : Diff_len = 0;
103 23796 : set_f( exc_dct_in, 0.0f, L_FRAME16k );
104 :
105 : /*-----------------------------------------------------------------*
106 : * Pitch extrapolation
107 : *-----------------------------------------------------------------*/
108 :
109 : /* pitch extrapolation */
110 23796 : pitch_pred_linear_fit( st->nbLostCmpt, st->last_good, st->old_pitch_buf, L_frame == L_FRAME ? &st->old_pitch_buf[2 * NB_SUBFR - 1] : &st->old_pitch_buf[2 * NB_SUBFR16k - 1], &predPitchLag, L_frame == L_FRAME ? PIT_MIN_DOUBLEEXTEND : PIT16k_MIN_EXTEND, L_frame == L_FRAME ? PIT_MAX : PIT16k_MAX, st->mem_pitch_gain, 0, 0, &extrapolationFailed, L_frame / L_SUBFR );
111 :
112 23796 : new_pit = (int16_t) ( predPitchLag + 0.5f );
113 :
114 : /* initialize FEC pitch to the long-term pitch */
115 23796 : *tmp_tc = st->bfi_pitch;
116 23796 : if ( L_frame == L_FRAME )
117 : {
118 7782 : if ( ( ( st->old_pitch_buf[2 * NB_SUBFR - 1] < 1.8f * st->bfi_pitch ) &&
119 7566 : ( st->old_pitch_buf[2 * NB_SUBFR - 1] > 0.6f * st->bfi_pitch ) ) || /* last pitch coherent with the past */
120 486 : ( st->upd_cnt >= MAX_UPD_CNT ) ) /* or last update too far in the past */
121 : {
122 : /* take the pitch value of last subframe of the previous frame */
123 7608 : *tmp_tc = st->old_pitch_buf[2 * NB_SUBFR - 1];
124 : }
125 : }
126 : else /* L_frame == L_FRAME16k */
127 : {
128 16014 : if ( ( ( st->old_pitch_buf[2 * NB_SUBFR16k - 1] < 1.8f * st->bfi_pitch ) &&
129 15717 : ( st->old_pitch_buf[2 * NB_SUBFR16k - 1] > 0.6f * st->bfi_pitch ) ) || /* last pitch coherent with the past */
130 627 : ( st->upd_cnt >= MAX_UPD_CNT ) ) /* or last update too far in the past */
131 : {
132 : /* take the pitch value of last subframe of the previous frame */
133 15843 : *tmp_tc = st->old_pitch_buf[2 * NB_SUBFR16k - 1];
134 : }
135 : }
136 : /* convert pitch period */
137 23796 : Tc = (int16_t) ( *tmp_tc + 0.5f );
138 :
139 23796 : pulseRes_preCalc( &cond1, &cond2, &cond3, (Word16) new_pit, (Word16) Tc, (Word16) L_frame );
140 :
141 23796 : if ( ( cond1 < 0 ) && ( new_pit > 0 ) && ( cond2 != 0 ) && ( cond3 > 0 ) && extrapolationFailed == 0 )
142 : {
143 1263 : fT0 = *tmp_tc;
144 1263 : delta = (float) ( new_pit - fT0 ) / ( L_frame / L_SUBFR ); /* # of subframes */
145 7113 : for ( i = 0; i < L_frame / L_SUBFR; i++ ) /* subframe pitch values */
146 : {
147 5850 : fT0 += delta;
148 5850 : pitch_buf[i] = (int16_t) ( fT0 + 0.5f );
149 : }
150 : }
151 : else
152 : {
153 127881 : for ( i = 0; i < L_frame / L_SUBFR; i++ )
154 : {
155 105348 : pitch_buf[i] = *tmp_tc;
156 : }
157 : }
158 :
159 : /*-----------------------------------------------------------------*
160 : * Estimate gain damping factor
161 : *-----------------------------------------------------------------*/
162 :
163 23796 : alpha = ALPHA_VT; /* rapid convergence to 0 */
164 23796 : if ( st->last_coder_type == UNVOICED && st->nbLostCmpt <= 3 )
165 : {
166 : /* last good frame was clearly unvoiced */
167 1269 : alpha = ALPHA_UU;
168 : }
169 22527 : else if ( st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS )
170 : {
171 1224 : if ( st->hGSCDec->Last_GSC_pit_band_idx > 0 && st->nbLostCmpt > 1 )
172 : {
173 258 : alpha = 0.8f;
174 : }
175 966 : else if ( st->nbLostCmpt <= 5 )
176 : {
177 966 : alpha = 0.995f;
178 : }
179 : else
180 : {
181 0 : alpha = 0.95f;
182 : }
183 : }
184 21303 : else if ( st->last_good == UNVOICED_CLAS )
185 : {
186 4254 : if ( st->nbLostCmpt <= 1 )
187 : {
188 : /* If stable, do not decrease the energy, pitch gain = 0 */
189 3264 : alpha = st->stab_fac * ( 1.0f - 2.0f * ALPHA_U ) + 2.0f * ALPHA_U; /* [0.8, 1.0] */
190 : }
191 990 : else if ( st->nbLostCmpt == 2 )
192 : {
193 888 : alpha = ALPHA_U * 1.5f; /* 0.6 */
194 : }
195 : else
196 : {
197 102 : alpha = ALPHA_U; /* 0.4 go rapidly to CNG gain, pitch gain = 0 */
198 : }
199 : }
200 17049 : else if ( st->last_good == UNVOICED_TRANSITION )
201 : {
202 96 : alpha = ALPHA_UT;
203 : }
204 16953 : else if ( st->last_good == ONSET && st->nbLostCmpt <= 3 && ( st->last_coder_type == GENERIC || st->last_coder_type == TRANSITION ) )
205 : {
206 858 : alpha = 0.8f; /* mild convergence to 0 for the first 3 erased frames */
207 : }
208 16095 : else if ( ( st->last_good == VOICED_CLAS || st->last_good == ONSET ) && st->nbLostCmpt <= 3 )
209 : {
210 9723 : alpha = ALPHA_V; /* constant for the first 3 erased frames */
211 : }
212 6372 : else if ( st->last_good == SIN_ONSET )
213 : {
214 36 : alpha = ALPHA_S;
215 : }
216 :
217 23796 : if ( st->last_good >= VOICED_CLAS && st->last_good < INACTIVE_CLAS && st->last_coder_type != AUDIO )
218 : {
219 11127 : if ( st->nbLostCmpt == 1 )
220 : {
221 : /* if this is the first erased frame, move pitch gain towards 1 for voiced to remove energy fluctuations */
222 8283 : gain = (float) sqrt( st->lp_gainp );
223 8283 : if ( gain > 0.98f )
224 : {
225 1446 : gain = 0.98f;
226 : }
227 6837 : else if ( gain < 0.85f )
228 : {
229 1926 : gain = 0.85f;
230 : }
231 :
232 8283 : alpha *= gain;
233 : }
234 : else
235 : {
236 2844 : alpha = st->lp_gainp;
237 : }
238 : }
239 :
240 : /*-----------------------------------------------------------------*
241 : * Extrapolate past excitation signal using estimated pitch period
242 : *-----------------------------------------------------------------*/
243 :
244 23796 : if ( ( st->last_good >= UNVOICED_TRANSITION && st->last_good < INACTIVE_CLAS ) ||
245 5643 : ( ( st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS ) && st->hGSCDec->Last_GSC_pit_band_idx > 0 ) )
246 : {
247 : /* Do pitch-based extrapolation only for stable voiced and audio signals */
248 :
249 18213 : pt_exc = exc;
250 18213 : pt1_exc = pt_exc - Tc;
251 :
252 18213 : if ( st->nbLostCmpt == 1 )
253 : {
254 : /* first pitch cycle is low-pass filtered */
255 915762 : for ( i = 0; i < Tc; i++ )
256 : {
257 906021 : *pt_exc++ = ( 0.18f * pt1_exc[-1] + 0.64f * pt1_exc[0] + 0.18f * pt1_exc[1] );
258 906021 : pt1_exc++;
259 : }
260 : }
261 :
262 : /* last pitch cycle of the previous frame is repeatedly copied up to an extra subframe */
263 5778240 : while ( pt_exc < exc + L_frame + L_SUBFR )
264 : {
265 5760027 : *pt_exc++ = *pt1_exc++;
266 : }
267 :
268 : /* resynchronization of excitation based on glottal pulse locations in the last good frame */
269 18213 : if ( new_pit > 0 )
270 : {
271 10914 : if ( ( cond1 < 0 ) && ( new_pit > 0 ) && ( cond2 != 0 ) && ( cond3 > 0 ) && extrapolationFailed == 0 )
272 : {
273 1263 : mvr2r( exc, exc - L_frame - L_SUBFR, L_frame + L_SUBFR );
274 1263 : PulseResynchronization( exc - L_frame - L_SUBFR, exc, L_frame, L_frame / L_SUBFR, Tc, new_pit );
275 : }
276 : }
277 :
278 18213 : if ( st->last_good == UNVOICED_TRANSITION && ( st->last_coder_type == GENERIC || st->last_coder_type == TRANSITION ) )
279 : {
280 : /* start of the frame gain */
281 96 : gain = 0.0f;
282 :
283 : /* end of the frame gain */
284 96 : st->lp_gainp = 0.0f;
285 :
286 96 : step = 0.0f;
287 : }
288 : else
289 : {
290 : /* start of the frame gain */
291 18117 : gain = 1.0f;
292 :
293 : /* end of the frame gain */
294 18117 : st->lp_gainp = alpha;
295 :
296 : /* linearly attenuate the gain throughout the frame */
297 18117 : step = ( 1.0f / L_frame ) * ( gain - st->lp_gainp );
298 : }
299 :
300 : /* scaling of the harmonic part of excitation */
301 5518629 : for ( i = 0; i < L_frame; i++ )
302 : {
303 5500416 : exc[i] *= gain;
304 5500416 : gain -= step;
305 : }
306 :
307 18213 : if ( ( st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS ) && st->hGSCDec->Last_GSC_pit_band_idx > 0 )
308 : {
309 : /* in case the last frame was coded by GSC, convert the excitation signal to frequency domain */
310 933 : edct( exc, exc_dct_in, st->L_frame, st->element_mode );
311 :
312 : /* Reset unvaluable part of the adaptive (pitch) excitation contribution */
313 933 : Diff_len = (int16_t) ( mfreq_loc[st->hGSCDec->Last_GSC_pit_band_idx] / BIN_SIZE );
314 933 : max_len = st->L_frame - Diff_len;
315 933 : Len = min( max_len, 80 );
316 :
317 71679 : for ( i = 0; i < Len; i++ )
318 : {
319 70746 : exc_dct_in[i + Diff_len] *= sm_table[i];
320 : }
321 :
322 40176 : for ( ; i < max_len; i++ )
323 : {
324 39243 : exc_dct_in[i + Diff_len] = 0.0f;
325 : }
326 :
327 933 : Diff_len++;
328 : }
329 : }
330 :
331 : /*-----------------------------------------------------------------*
332 : * Replicate the last spectrum in case the last good frame was coded by GSC
333 : *-----------------------------------------------------------------*/
334 :
335 23796 : if ( ( st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS ) && st->inactive_coder_type_flag && !st->Opt_AMR_WB )
336 : {
337 : /* Replication of the last spectrum, with a slight downscaling of its dynamic */
338 1560 : st->GSC_noisy_speech = st->Last_GSC_noisy_speech_flag;
339 1560 : gsc_dec( st, exc_dct_in, st->hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, st->L_frame / L_SUBFR, st->last_coder_type, &last_bin, lsf_new, NULL, tmp_noise );
340 :
341 : /* Transform back to time domain */
342 1560 : edct( exc_dct_in, exc, st->L_frame, st->element_mode );
343 : }
344 :
345 : /*-----------------------------------------------------------------*
346 : * Construct the random part of excitation
347 : *-----------------------------------------------------------------*/
348 :
349 : else
350 : {
351 : /* generate the random part of the excitation */
352 6820428 : for ( i = 0; i < L_frame + MODE1_L_FIR_FER - 1; i++ )
353 : {
354 6798192 : exc2_buf[i] = (float) own_random( &st->seed );
355 : }
356 :
357 : /* start of the frame gain */
358 22236 : gain = st->lp_gainc;
359 :
360 : /* end of the frame gain */
361 22236 : st->lp_gainc = alpha * st->lp_gainc + ( 1.0f - alpha ) * gainCNG;
362 :
363 22236 : if ( st->last_good == UNVOICED_TRANSITION && ( st->last_coder_type == GENERIC || st->last_coder_type == TRANSITION ) && gainCNG > 0 )
364 : {
365 24 : st->lp_gainc = gainCNG;
366 : }
367 :
368 : /* linearly attenuate the gain throughout the frame */
369 22236 : step = ( 1.0f / L_frame ) * ( gain - st->lp_gainc );
370 :
371 : /* calculate gain to normalize energy */
372 22236 : pt_exc = exc2_buf + MODE1_L_FIR_FER / 2;
373 :
374 22236 : gain_inov = 1.0f / (float) sqrt( dotp( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f );
375 :
376 : /* attenuate somewhat on unstable unvoiced */
377 22236 : if ( ( st->last_good == UNVOICED_CLAS || st->last_good == INACTIVE_CLAS ) && st->last_coder_type != UNVOICED )
378 : {
379 4440 : gain_inov *= 0.8f;
380 : }
381 :
382 : /* scaling of the random part of excitation */
383 22236 : pt_exc = exc2_buf;
384 66708 : for ( i = 0; i < MODE1_L_FIR_FER / 2; i++ )
385 : {
386 : /* non-causal ringing of the FIR filter */
387 44472 : *pt_exc++ *= ( gain_inov * gain );
388 : }
389 :
390 6731484 : for ( i = 0; i < L_frame; i++ )
391 : {
392 : /* the inner part of the FIR filter */
393 6709248 : *pt_exc++ *= ( gain_inov * gain );
394 6709248 : gain -= step;
395 : }
396 :
397 66708 : for ( i = 0; i < MODE1_L_FIR_FER / 2; i++ )
398 : {
399 : /* causal ringing of the FIR filter */
400 44472 : *pt_exc++ *= ( gain_inov * gain );
401 : }
402 : }
403 :
404 : /*-----------------------------------------------------------------*
405 : * Total excitation
406 : *-----------------------------------------------------------------*/
407 :
408 23796 : if ( ( st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS ) && st->inactive_coder_type_flag && !st->Opt_AMR_WB )
409 : {
410 : /* For GSC - the excitation is already computed */
411 1560 : mvr2r( exc, exc2, st->L_frame );
412 : }
413 22236 : else if ( st->last_good >= UNVOICED_TRANSITION && st->last_good < INACTIVE_CLAS )
414 : {
415 : /* For voiced and generic signals - prepare a HP filter for the random part of excitation */
416 103482 : for ( i = 0; i < MODE1_L_FIR_FER; i++ )
417 : {
418 86235 : hp_filt[i] = ( 1.0f - st->tilt_code ) * h_high[i];
419 : }
420 :
421 : /* HP filter the random part of the excitation and add the adaptive part */
422 5270367 : for ( i = 0; i < L_frame; i++ )
423 : {
424 5253120 : exc2[i] = exc[i] + dotp( &exc2_buf[i], hp_filt, MODE1_L_FIR_FER );
425 : }
426 : }
427 : else
428 : {
429 : /* For purely unvoiced signals - just copy the unfiltered random part of the excitation */
430 4989 : mvr2r( exc2_buf + MODE1_L_FIR_FER / 2, exc, L_frame );
431 4989 : mvr2r( exc2_buf + MODE1_L_FIR_FER / 2, exc2, L_frame );
432 : }
433 :
434 23796 : if ( st->hBWE_TD != NULL )
435 : {
436 23775 : if ( L_frame == L_FRAME )
437 : {
438 7761 : interp_code_5over2( exc, bwe_exc, L_frame );
439 : }
440 : else
441 : {
442 16014 : interp_code_4over2( exc, bwe_exc, L_frame );
443 : }
444 : }
445 :
446 : /*-----------------------------------------------------------------*
447 : * Updates
448 : *-----------------------------------------------------------------*/
449 :
450 : /* Update voicing factors of TBE */
451 23796 : if ( st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS )
452 : {
453 1746 : if ( st->L_frame == L_FRAME )
454 : {
455 1434 : set_f( voice_factors, 1.0f, NB_SUBFR );
456 : }
457 : else
458 : {
459 312 : set_f( voice_factors, 1.0f, NB_SUBFR16k );
460 : }
461 : }
462 : else
463 : {
464 22050 : if ( st->L_frame == L_FRAME )
465 : {
466 6348 : set_f( voice_factors, st->last_voice_factor, NB_SUBFR );
467 : }
468 : else
469 : {
470 15702 : set_f( voice_factors, st->last_voice_factor, NB_SUBFR16k );
471 : }
472 : }
473 :
474 23796 : if ( st->Opt_AMR_WB )
475 : {
476 : /* update buffer of gains for the next frame */
477 0 : gain_dec_bfi( st->hAmrwb_IO->past_qua_en );
478 : }
479 :
480 23796 : st->bfi_pitch = pitch_buf[L_frame / L_SUBFR - 1];
481 23796 : st->bfi_pitch_frame = st->L_frame;
482 :
483 23796 : return;
484 : }
485 :
486 :
487 : /*-------------------------------------------------------------------*
488 : * gain_dec_bfi()
489 : *
490 : * Estimate past quantized gain prediction residual to be used in
491 : * next frame
492 : *-------------------------------------------------------------------*/
493 :
494 0 : static void gain_dec_bfi(
495 : float *past_qua_en /* i/o: gain quantization memory (4 words) */
496 : )
497 : {
498 : int16_t i;
499 : float av_pred_en;
500 :
501 0 : av_pred_en = 0.0f;
502 0 : for ( i = 0; i < GAIN_PRED_ORDER; i++ )
503 : {
504 0 : av_pred_en += past_qua_en[i];
505 : }
506 :
507 0 : av_pred_en = (float) ( av_pred_en * ( 1.0f / (float) GAIN_PRED_ORDER ) - 3.0f );
508 :
509 0 : if ( av_pred_en < -14.0f )
510 : {
511 0 : av_pred_en = -14.0f;
512 : }
513 :
514 0 : for ( i = GAIN_PRED_ORDER - 1; i > 0; i-- )
515 : {
516 0 : past_qua_en[i] = past_qua_en[i - 1];
517 : }
518 :
519 0 : past_qua_en[0] = av_pred_en;
520 :
521 0 : return;
522 : }
523 :
524 :
525 : #define WMC_TOOL_SKIP
526 : /*-------------------------------------------------------------------*
527 : * pulseRes_preCalc()
528 : *
529 : * calculates some conditions for Pulse resynchronization to take place
530 : *-------------------------------------------------------------------*/
531 :
532 23796 : static void pulseRes_preCalc(
533 : Word16 *cond1,
534 : Word16 *cond2,
535 : Word32 *cond3,
536 : Word16 new_pit,
537 : Word16 Tc,
538 : Word16 L_frame )
539 : {
540 : Word16 tmp_pit, tmp_pit_e, tmp_frame, tmp_frame_e;
541 : Word32 tmp_pit2;
542 : #ifdef BASOP_NOGLOB
543 : Flag Overflow;
544 : #endif /* BASOP_NOGLOB */
545 :
546 23796 : tmp_pit = BASOP_Util_Divide1616_Scale( new_pit /*Q0*/, Tc /*Q0*/, &tmp_pit_e ) /*Q15*/;
547 23796 : tmp_frame = add( extract_l( L_mult0( L_frame, 64 /*1.f/L_SUBFR Q12*/ ) /*Q12*/ ), 4096 /*1.f Q12*/ ); /*Q12*/
548 23796 : tmp_frame = BASOP_Util_Divide1616_Scale( 4096 /*1.f Q12*/, tmp_frame, &tmp_frame_e ); /*Q15*/
549 23796 : tmp_frame = shl( tmp_frame, add( tmp_frame_e, 1 ) );
550 23796 : tmp_frame = sub( 32767 /*1.f Q15*/, tmp_frame ); /*Q15*/
551 :
552 : #ifndef BASOP_NOGLOB
553 : BASOP_SATURATE_WARNING_OFF
554 : #endif /* ! BASOP_NOGLOB */
555 : /*To calc Q15 threshold, overflow may happen - do negation and compare with negated value to check also highest possible value*/
556 : #ifndef BASOP_NOGLOB
557 : tmp_pit = shl( negate( tmp_pit ), tmp_pit_e );
558 : BASOP_SATURATE_WARNING_ON
559 : #else /* BASOP_NOGLOB */
560 23796 : tmp_pit = shl_o( negate( tmp_pit ), tmp_pit_e, &Overflow );
561 : #endif /* BASOP_NOGLOB */
562 :
563 23796 : *cond1 = sub( tmp_pit, negate( tmp_frame ) );
564 :
565 23796 : *cond2 = sub( Tc, new_pit );
566 :
567 23796 : tmp_pit_e = BASOP_Util_Add_MantExp( new_pit, 15 - 0, negate( Tc ), 15 - 0, &tmp_pit ); /*Q15*/
568 23796 : tmp_pit = abs_s( tmp_pit );
569 23796 : tmp_pit2 = L_mult( Tc, 4915 /*0.15f Q15*/ ); /*Q16*/
570 :
571 : BASOP_SATURATE_WARNING_OFF
572 : /*To calc Q15 threshold, overflow may happen - do negation and compare with negated value to check also highest possible value*/
573 23796 : tmp_pit2 = L_shl( L_negate( tmp_pit2 ), sub( 15 - 16, tmp_pit_e ) );
574 : BASOP_SATURATE_WARNING_ON
575 :
576 23796 : *cond3 = L_sub( L_mult0( -1, tmp_pit ), tmp_pit2 );
577 :
578 23796 : return;
579 : }
580 : #undef WMC_TOOL_SKIP
|