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 "options.h"
7 : #include "cnst.h"
8 : #include "prot_fx.h"
9 : #include "rom_com.h"
10 : #include "rom_enc.h"
11 : #include "ivas_prot_fx.h"
12 :
13 : #define MAX_Q_NEW_INPUT 8
14 : #define Q_WTDA_FX 13
15 : #define Q_32_BITS 15
16 :
17 : /*-------------------------------------------------------------------*
18 : * para_pred_bws()
19 : *
20 : * predict SWB parameters for bandwidth switching
21 : *-------------------------------------------------------------------*/
22 :
23 2742 : static Word16 para_pred_bws_fx(
24 : Decoder_State *st_fx, /* i/o: decoder state structure */
25 : Word16 *signal_wb_fx, /* i : wideband frequency signal Q_syn*/
26 : Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope Q1 */
27 : Word16 Q_syn )
28 : {
29 : Word16 i, j, k;
30 : Word16 mode;
31 : FD_BWE_DEC_HANDLE hBWE_FD;
32 : Word16 tmp, tmp_den, tmp_num;
33 : Word32 L_tmp, L_tmp_max;
34 : Word16 exp;
35 : Word16 *input_hi_fx;
36 : Word32 *mea;
37 : Word16 peak_fx, mag_fx;
38 : Word32 mean_fx[7], peak_32_fx;
39 : Word32 avrg1_fx, avrg2_fx, min_fx;
40 : Word16 att_fx;
41 2742 : Word16 coder_type = st_fx->coder_type;
42 2742 : move16();
43 :
44 2742 : hBWE_FD = st_fx->hBWE_FD;
45 2742 : mode = NORMAL;
46 2742 : move16();
47 :
48 2742 : k = 0;
49 2742 : move16();
50 2742 : input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; /*Q_syn*/
51 21936 : FOR( i = 0; i < 7; i++ )
52 : {
53 19194 : peak_fx = 0;
54 19194 : move16();
55 19194 : mean_fx[i] = 0;
56 19194 : move16();
57 633402 : FOR( j = 0; j < SHARP_WIDTH; j++ )
58 : {
59 614208 : mag_fx = abs_s( *input_hi_fx ); /*Q_syn*/
60 614208 : peak_fx = s_max( peak_fx, mag_fx ); /*Q_syn*/
61 : /*IF (sub(mag_fx, peak_fx) > 0) */
62 : /*{ */
63 : /* peak_fx = mag_fx; */
64 : /*} */
65 614208 : mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); /*Q_syn*/
66 614208 : move32();
67 614208 : input_hi_fx++;
68 : }
69 :
70 19194 : IF( LT_16( Q_syn, 11 ) )
71 : {
72 19194 : tmp = 1;
73 19194 : move16();
74 : }
75 : ELSE
76 : {
77 0 : tmp = 0;
78 0 : move16();
79 0 : if ( GT_16( shr( peak_fx, 3 ), shl( 1, Q_syn ) ) )
80 : {
81 0 : tmp = 1;
82 0 : move16();
83 : }
84 : }
85 19194 : IF( tmp > 0 )
86 : {
87 19194 : L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ) /*Q_syn + 10*/, 18432 /*4.5f Q12*/ ), peak_fx /*Q_syn*/, 4544 /*35.5 (SHARP_WIDTH + 3.5f)Q7*/ );
88 19194 : if ( L_tmp < 0 )
89 : {
90 1134 : k = add( k, 1 );
91 : }
92 : }
93 : }
94 :
95 2742 : avrg1_fx = L_deposit_l( 0 );
96 2742 : avrg2_fx = L_deposit_l( 0 );
97 10968 : FOR( i = 1; i < 4; i++ )
98 : {
99 8226 : avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); /*Q_syn*/
100 8226 : avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); /*Q_syn*/
101 : }
102 2742 : avrg1_fx = Mult_32_16( avrg1_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/
103 2742 : avrg2_fx = Mult_32_16( avrg2_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/
104 :
105 2742 : min_fx = L_add( 2147483647, 0 ); /*2^31 */
106 2742 : peak_32_fx = L_deposit_l( 0 );
107 10968 : FOR( i = 4; i < 7; i++ )
108 : {
109 8226 : IF( GT_32( mean_fx[i], L_shl( avrg2_fx, 1 ) ) )
110 : {
111 0 : exp = norm_l( mean_fx[i] );
112 0 : IF( LT_16( exp, 16 ) )
113 : {
114 0 : tmp_den = extract_l( L_shr( mean_fx[i], sub( 16, exp ) ) ); /*Qsyn - 16 + exp */
115 0 : tmp_num = extract_l( L_shr( avrg2_fx, sub( 15, exp ) ) ); /*//Qsyn - 16 + exp */
116 : }
117 : ELSE
118 : {
119 0 : tmp_den = extract_l( mean_fx[i] );
120 0 : tmp_num = extract_l( L_shl( avrg2_fx, 1 ) );
121 : }
122 :
123 0 : tmp_den = div_s( 1, tmp_den );
124 :
125 0 : tmp = i_mult( tmp_num, tmp_den ); /*Q15 */
126 :
127 0 : mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); // Q_syn + Q15 - 15
128 0 : move32();
129 : }
130 8226 : min_fx = L_min( min_fx, mean_fx[i] );
131 8226 : peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); /*Q_syn*/
132 : /*IF(L_sub(mean_fx[i], min_fx) < 0) */
133 : /*{ */
134 : /* min_fx = mean_fx[i]; */
135 : /*} */
136 : /*IF(L_sub(mean_fx[i], peak_32_fx) > 0) */
137 : /*{ */
138 : /* peak_32_fx = mean_fx[i]; */
139 : /*} */
140 : }
141 :
142 2742 : IF( GT_16( st_fx->tilt_wb_fx, 16384 /*8 in Q11*/ ) )
143 : {
144 2 : IF( GT_16( st_fx->tilt_wb_fx, 30720 /*15.0f in Q11*/ ) )
145 : {
146 0 : min_fx = peak_32_fx;
147 0 : move32();
148 : }
149 : ELSE
150 : {
151 2 : tmp = extract_l( L_shr( L_mult0( st_fx->tilt_wb_fx, 17476 ), 14 ) ); /*Q15 */
152 2 : min_fx = Mult_32_16( peak_32_fx, tmp ); /*Q_syn + Q15 - 15*/
153 : }
154 : }
155 :
156 2742 : test();
157 2742 : IF( peak_32_fx == 0 || min_fx == 0 )
158 : {
159 0 : set16_fx( SWB_fenv_fx, 0, SWB_FENV );
160 : }
161 : ELSE
162 : {
163 2742 : exp = norm_l( peak_32_fx );
164 2742 : IF( LT_16( exp, 16 ) )
165 : {
166 0 : tmp_den = extract_l( L_shr( peak_32_fx, sub( 16, exp ) ) ); /*Qsyn - 16 + exp */
167 0 : tmp = div_s( 16384, tmp_den ); /*Q15+14 - (Qsyn - 16 + exp) */
168 0 : tmp_num = extract_l( L_shr( min_fx, sub( 16, exp ) ) ); /*Qsyn - 16 + exp */
169 :
170 0 : tmp = extract_l( L_shr( L_mult0( tmp_num, tmp ), 14 ) ); /*Q15 */
171 : }
172 : ELSE
173 : {
174 2742 : tmp_den = extract_l( peak_32_fx ); /*Qsyn */
175 2742 : exp = norm_s( tmp_den );
176 2742 : tmp = div_s( shl( 1, sub( 14, exp ) ), tmp_den ); /*Q 29-exp - Qsyn */
177 2742 : tmp_num = extract_l( min_fx ); /*Qsyn */
178 :
179 2742 : tmp = extract_l( L_shr( L_mult0( tmp_num, tmp ), sub( 14, exp ) ) ); /*Q15 */
180 : }
181 :
182 2742 : j = 0;
183 2742 : move16();
184 2742 : mea = &mean_fx[4];
185 2742 : L_tmp_max = L_shl( 32767, add( Q_syn, 5 ) );
186 41130 : FOR( i = 0; i < SWB_FENV; i++ )
187 : {
188 38388 : if ( EQ_16( j, 5 ) )
189 : {
190 5484 : mea++;
191 5484 : j = 0;
192 5484 : move16();
193 : }
194 38388 : j = add( j, 1 );
195 38388 : L_tmp = L_min( Mult_32_16( *mea, tmp ), L_tmp_max );
196 38388 : SWB_fenv_fx[i] = extract_l( L_shr( L_tmp, add( Q_syn, 5 ) ) );
197 38388 : move16();
198 : }
199 : }
200 :
201 2742 : j = 0;
202 2742 : move16();
203 21936 : FOR( i = SWB_FENV / 2; i < SWB_FENV; i++ )
204 : {
205 19194 : tmp = sub( 32767, i_mult( j, 2341 ) );
206 19194 : SWB_fenv_fx[i] = mult_r( SWB_fenv_fx[i], tmp );
207 19194 : move16();
208 19194 : j = add( j, 1 );
209 : }
210 :
211 2742 : IF( GT_32( avrg1_fx, L_shl( avrg2_fx, 3 ) ) )
212 : {
213 60 : FOR( i = 0; i < SWB_FENV; i++ )
214 : {
215 56 : SWB_fenv_fx[i] = shr( SWB_fenv_fx[i], 1 );
216 56 : move16();
217 : }
218 : }
219 :
220 2742 : test();
221 2742 : test();
222 2742 : test();
223 2742 : test();
224 2742 : test();
225 2742 : IF( NE_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->last_codec_mode, MODE1 ) &&
226 : ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) &&
227 : ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) )
228 : {
229 0 : FOR( i = 0; i < SWB_FENV; i++ )
230 : {
231 0 : test();
232 0 : IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 ), hBWE_FD->prev_SWB_fenv_fx[i] ) )
233 : {
234 : /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 3277), mult_r(st_fx->prev_SWB_fenv_fx[i], 29491)); */
235 0 : SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 ), hBWE_FD->prev_SWB_fenv_fx[i], 29491 ) );
236 0 : move16();
237 : }
238 : ELSE
239 : {
240 : /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], st_fx->attenu_fx), mult_r(st_fx->prev_SWB_fenv_fx[i], sub(32767, st_fx->attenu_fx))); */
241 0 : SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), hBWE_FD->prev_SWB_fenv_fx[i], sub( 32767, st_fx->attenu_fx ) ) );
242 0 : move16();
243 : }
244 : }
245 :
246 0 : IF( LT_16( st_fx->attenu_fx, 29491 ) )
247 : {
248 0 : st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 );
249 0 : move16();
250 : }
251 : }
252 : ELSE
253 : {
254 2742 : test();
255 2742 : test();
256 2742 : test();
257 2742 : test();
258 2742 : IF( NE_32( st_fx->core_brate, st_fx->last_core_brate ) || ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) ||
259 : ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) )
260 : {
261 6330 : FOR( i = 0; i < SWB_FENV; i++ )
262 : {
263 5908 : if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 ), hBWE_FD->prev_SWB_fenv_fx[i] ) )
264 : {
265 1351 : SWB_fenv_fx[i] = hBWE_FD->prev_SWB_fenv_fx[i];
266 1351 : move16();
267 : }
268 : }
269 : }
270 :
271 41130 : FOR( i = 0; i < SWB_FENV; i++ )
272 : {
273 : /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 29491), mult_r(st_fx->prev_SWB_fenv_fx[i], 3277)); */
274 38388 : SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), hBWE_FD->prev_SWB_fenv_fx[i], 3277 ) );
275 38388 : move16();
276 : }
277 2742 : st_fx->attenu_fx = 3277; /*Q15*/
278 2742 : move16();
279 : }
280 :
281 2742 : if ( GT_16( k, 3 ) )
282 : {
283 19 : mode = HARMONIC;
284 19 : move16();
285 : }
286 :
287 :
288 2742 : att_fx = i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ); /*15 */
289 2742 : IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
290 : {
291 0 : FOR( i = 0; i < 4; i++ )
292 : {
293 0 : SWB_fenv_fx[i] = mult_r( SWB_fenv_fx[i], att_fx );
294 0 : move16(); /*Q1 */
295 : }
296 : }
297 :
298 30162 : FOR( i = 4; i < SWB_FENV; i++ )
299 : {
300 27420 : SWB_fenv_fx[i] = mult_r( SWB_fenv_fx[i], att_fx );
301 27420 : move16(); /*Q1 */
302 : }
303 :
304 2742 : return mode;
305 : }
306 :
307 : /*-------------------------------------------------------------------*
308 : * WB_BWE_gain_deq()
309 : *
310 : * Decoding of WB parameters
311 : *-------------------------------------------------------------------*/
312 4086 : Word16 WB_BWE_gain_deq_fx(
313 : Decoder_State *st_fx, /* i/o: decoder state structure */
314 : Word16 *WB_fenv /* o : Q15 */
315 : )
316 : {
317 : Word16 mode;
318 : Word16 index, index2;
319 : Word32 L_tmp;
320 : Word16 tmp, exp, frac;
321 :
322 4086 : index = (Word16) get_next_indice_fx( st_fx, 5 );
323 4086 : mode = add( extract_l( get_next_indice_fx( st_fx, 1 ) ), 2 );
324 :
325 4086 : index2 = shl( index, 1 );
326 4086 : L_tmp = L_shr( F_2_5_fx[index2] /*Q10*/, 1 );
327 4086 : L_tmp = L_shl( L_tmp, 6 ); /*Q15*/
328 :
329 4086 : frac = L_Extract_lc( L_tmp, &exp );
330 4086 : tmp = extract_l( Pow2( 14, frac ) );
331 :
332 4086 : exp = sub( exp, 14 );
333 4086 : WB_fenv[0] = shl( tmp, add( exp, 3 ) ); // Q15
334 4086 : move16();
335 :
336 :
337 4086 : L_tmp = L_shr( F_2_5_fx[index2 + 1] /*Q10*/, 1 );
338 4086 : L_tmp = L_shl( L_tmp, 6 ); /*Q15*/
339 :
340 4086 : frac = L_Extract_lc( L_tmp, &exp );
341 4086 : tmp = extract_l( Pow2( 14, frac ) );
342 :
343 4086 : exp = sub( exp, 14 );
344 4086 : WB_fenv[1] = shl( tmp, add( exp, 3 ) ); // Q15
345 4086 : move16();
346 :
347 4086 : return ( mode );
348 : }
349 :
350 : /*-------------------------------------------------------------------*
351 : * wb_bwe_dec()
352 : *
353 : * WB BWE decoder (only for 16kHz signals)
354 : *-------------------------------------------------------------------*/
355 :
356 : /* o : Q_syn_hb */
357 8889 : Word16 ivas_wb_bwe_dec_fx(
358 : Decoder_State *st_fx, /* i/o: decoder state structure */
359 : const Word16 output[], /* i : suntehsis @ internal Fs Q_input */
360 : Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */
361 : Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */
362 : const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
363 : const Word16 output_frame, /* i : frame length */
364 : Word16 *voice_factors_fx, /* i : voicing factors Q15 */
365 : const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */
366 : Word16 *Qpost )
367 : {
368 : Word16 mode;
369 : Word16 WB_fenv_fx[SWB_FENV];
370 : Word16 ysynth_fx[L_FRAME48k];
371 : Word16 Q_syn, exp, Q_syn_hb;
372 : Word32 L_wtda_synth_fx[2 * L_FRAME48k], ysynth_32[L_FRAME48k], t_audio32_tmp[L_FRAME48k];
373 : Word16 scl, new_input_fx_exp;
374 : Word16 i;
375 : FD_BWE_DEC_HANDLE hBWE_FD;
376 : Word16 ysynth_frame_size;
377 8889 : Word16 coder_type = st_fx->coder_type;
378 8889 : move16();
379 :
380 8889 : hBWE_FD = st_fx->hBWE_FD;
381 :
382 : /* MDCT of the core synthesis signal */
383 :
384 8889 : new_input_fx_exp = *Qpost;
385 8889 : move16();
386 8889 : test();
387 8889 : IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft )
388 : {
389 : /* IVAS_fmToDo: wtda() does not support L_FRAME length; thus temporarily resample the signal */
390 : /* IVAS_fmToDo: delay output[] by 1.25ms ? */
391 228 : lerp( output, ysynth_fx, L_FRAME16k, st_fx->L_frame );
392 :
393 228 : wtda_fx( ysynth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k );
394 228 : *Qpost = sub( new_input_fx_exp, 15 );
395 228 : move16();
396 228 : direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, /*st->L_frame*/ L_FRAME16k, &new_input_fx_exp, st_fx->element_mode );
397 228 : ysynth_frame_size = L_FRAME16k;
398 : }
399 : ELSE
400 : {
401 8661 : wtda_fx( synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx,
402 : &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */
403 : output_frame );
404 8661 : *Qpost = sub( new_input_fx_exp, 15 );
405 8661 : move16();
406 : /* DCT of the ACELP core synthesis */
407 8661 : direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode );
408 8661 : ysynth_frame_size = output_frame;
409 : }
410 : /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */
411 8889 : scl = sub( 16 + MAX_Q_NEW_INPUT, new_input_fx_exp );
412 : /* Possible to Upscale? */
413 8889 : IF( scl > 0 )
414 : {
415 : /* Yes */
416 : /* Calc Room to Upscale */
417 8889 : Q_syn = Find_Max_Norm32( ysynth_32, ysynth_frame_size );
418 : /* Stay within MAX_Q_NEW_INPUT */
419 8889 : scl = s_min( Q_syn, scl );
420 : }
421 8889 : Copy_Scale_sig32_16( ysynth_32, ysynth_fx, ysynth_frame_size, scl );
422 8889 : Q_syn = add( sub( new_input_fx_exp, 16 ), scl );
423 8889 : IF( !st_fx->bfi )
424 : {
425 8869 : IF( st_fx->extl_brate > 0 )
426 : {
427 : /* de-quantization */
428 4086 : mode = WB_BWE_gain_deq_fx( st_fx, WB_fenv_fx );
429 4086 : st_fx->hBWE_FD->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 /*0.5f in Q15*/ ) );
430 4086 : move16();
431 : }
432 : ELSE
433 : {
434 : Word32 tmp_brate;
435 :
436 4783 : tmp_brate = st_fx->last_core_brate;
437 4783 : move32();
438 4783 : test();
439 4783 : if ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) && EQ_16( st_fx->last_extl, SWB_TBE ) )
440 : {
441 0 : tmp_brate = ACELP_8k00; /* this is needed in order to stay BE wrt. EVS mono */
442 0 : move32();
443 : }
444 4783 : if ( NE_16( st_fx->last_extl, WB_BWE ) )
445 : {
446 49 : hBWE_FD->prev_SWB_fenv_fx[0] = 0;
447 49 : move16();
448 : }
449 :
450 4783 : mode = WB_BWE_gain_pred_fx( WB_fenv_fx, ysynth_fx, coder_type, st_fx->prev_coder_type, hBWE_FD->prev_SWB_fenv_fx[0],
451 4783 : voice_factors_fx, pitch_buf_fx, tmp_brate, st_fx->hBWE_FD->last_wb_bwe_ener_fx, Q_syn, st_fx->last_extl, st_fx->tilt_wb_fx );
452 : }
453 : }
454 : ELSE
455 : {
456 : /* FEC */
457 20 : mode = NORMAL;
458 20 : move16();
459 60 : FOR( i = 0; i < 2; i++ )
460 : {
461 40 : WB_fenv_fx[i] = mult_r( hBWE_FD->prev_SWB_fenv_fx[i], 24576 );
462 40 : move16();
463 : }
464 : }
465 8889 : test();
466 8889 : IF( NE_16( st_fx->last_extl, WB_BWE ) || st_fx->bfi )
467 : {
468 173 : Copy( WB_fenv_fx, hBWE_FD->prev_SWB_fenv_fx, 2 );
469 : }
470 :
471 8889 : exp = norm_l( hBWE_FD->prev_Energy_wb_fx );
472 8889 : IF( GT_16( add( hBWE_FD->prev_Q_synth, exp ), Q_syn ) )
473 : {
474 8731 : hBWE_FD->prev_Energy_wb_fx = L_shr( hBWE_FD->prev_Energy_wb_fx, sub( hBWE_FD->prev_Q_synth, Q_syn ) );
475 8731 : move32();
476 : }
477 : ELSE
478 : {
479 158 : Q_syn = add( hBWE_FD->prev_Q_synth, exp );
480 158 : hBWE_FD->prev_Energy_wb_fx = L_shl( hBWE_FD->prev_Energy_wb_fx, exp );
481 158 : move32();
482 : }
483 :
484 8889 : WB_BWE_decoding_fx( ysynth_fx, WB_fenv_fx, ysynth_32, L_FRAME16k, mode,
485 8889 : st_fx->last_extl, &hBWE_FD->prev_Energy_wb_fx, hBWE_FD->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm,
486 8889 : st_fx->extl, coder_type, st_fx->total_brate, &hBWE_FD->Seed, &hBWE_FD->prev_flag,
487 8889 : st_fx->prev_coder_type, Q_syn, &Q_syn_hb );
488 :
489 8889 : IF( EQ_32( st_fx->output_Fs, 32000 ) )
490 : {
491 476 : set32_fx( &ysynth_32[L_FRAME16k], 0, L_FRAME16k );
492 : }
493 8413 : ELSE IF( EQ_32( st_fx->output_Fs, 48000 ) )
494 : {
495 7615 : set32_fx( &ysynth_32[L_FRAME16k], 0, L_FRAME32k );
496 : }
497 :
498 8889 : Inverse_Transform( ysynth_32, &Q_syn_hb, t_audio32_tmp, 0, output_frame, output_frame, st_fx->element_mode );
499 :
500 8889 : window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame,
501 : ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 );
502 :
503 8889 : test();
504 8889 : IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft )
505 : {
506 : /* add HB synth from hf_synth() */
507 228 : v_add_16( hb_synth_fx, synth_fx, hb_synth_fx, output_frame );
508 : }
509 :
510 8889 : hBWE_FD->prev_mode = mode;
511 8889 : move16();
512 8889 : hBWE_FD->prev_Q_synth = Q_syn;
513 8889 : move16();
514 :
515 8889 : return Q_syn_hb;
516 : }
517 :
518 :
519 0 : Word16 wb_bwe_dec_fx(
520 : Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */
521 : Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */
522 : const Word16 output_frame, /* i : frame length */
523 : Word16 *voice_factors_fx, /* i : voicing factors Q15 */
524 : const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */
525 : Decoder_State *st_fx, /* i/o: decoder state structure */
526 : Word16 *Qpost )
527 : {
528 : Word16 mode;
529 : Word16 WB_fenv_fx[SWB_FENV];
530 : Word16 ysynth_fx[L_FRAME48k];
531 : Word16 Q_syn, exp, Q_syn_hb;
532 : Word32 L_wtda_synth_fx[2 * L_FRAME48k], ysynth_32[L_FRAME48k], t_audio32_tmp[L_FRAME48k];
533 : Word16 scl, new_input_fx_exp;
534 : Word16 i;
535 : FD_BWE_DEC_HANDLE hBWE_FD;
536 :
537 0 : Word16 coder_type = st_fx->coder_type;
538 0 : move16();
539 :
540 0 : hBWE_FD = st_fx->hBWE_FD;
541 :
542 : /* MDCT of the core synthesis signal */
543 :
544 0 : new_input_fx_exp = *Qpost;
545 0 : move16();
546 :
547 : {
548 0 : wtda_fx( synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx,
549 : &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */
550 : output_frame );
551 0 : *Qpost = sub( new_input_fx_exp, 15 );
552 0 : move16();
553 : /* DCT of the ACELP core synthesis */
554 0 : direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode );
555 : }
556 : /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */
557 0 : scl = sub( 16 + MAX_Q_NEW_INPUT, new_input_fx_exp );
558 : /* Possible to Upscale? */
559 0 : IF( scl > 0 )
560 : {
561 : /* Yes */
562 : /* Calc Room to Upscale */
563 0 : Q_syn = Find_Max_Norm32( ysynth_32, output_frame );
564 : /* Stay within MAX_Q_NEW_INPUT */
565 0 : scl = s_min( Q_syn, scl );
566 : }
567 0 : Copy_Scale_sig32_16( ysynth_32, ysynth_fx, output_frame, scl );
568 0 : Q_syn = add( sub( new_input_fx_exp, 16 ), scl );
569 0 : IF( !st_fx->bfi )
570 : {
571 0 : IF( EQ_32( st_fx->total_brate, ACELP_13k20 ) )
572 : {
573 : /* de-quantization */
574 0 : mode = WB_BWE_gain_deq_fx( st_fx, WB_fenv_fx );
575 0 : hBWE_FD->last_wb_bwe_ener_fx = mult_r( add_sat( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 ); // this would not saturate if written like : rounf_fx(L_mac(L_mult(WB_fenv_fx[0], 16384), WB_fenv_fx[1], 16384))
576 0 : move16();
577 : }
578 : ELSE
579 : {
580 : Word32 tmp_brate;
581 :
582 0 : tmp_brate = st_fx->last_core_brate;
583 0 : move32();
584 :
585 0 : test();
586 0 : if ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) && EQ_16( st_fx->last_extl, SWB_TBE ) )
587 : {
588 0 : tmp_brate = ACELP_8k00; /* this is needed in order to stay BE wrt. EVS mono */
589 0 : move32();
590 : }
591 :
592 0 : if ( NE_16( st_fx->last_extl, WB_BWE ) )
593 : {
594 0 : hBWE_FD->prev_SWB_fenv_fx[0] = 0;
595 0 : move16();
596 : }
597 :
598 0 : mode = WB_BWE_gain_pred_fx( WB_fenv_fx, ysynth_fx, coder_type, st_fx->prev_coder_type, hBWE_FD->prev_SWB_fenv_fx[0],
599 0 : voice_factors_fx, pitch_buf_fx, tmp_brate, hBWE_FD->last_wb_bwe_ener_fx, Q_syn, st_fx->last_extl, st_fx->tilt_wb_fx );
600 : }
601 : }
602 : ELSE
603 : {
604 : /* FEC */
605 0 : mode = NORMAL;
606 0 : move16();
607 0 : FOR( i = 0; i < 2; i++ )
608 : {
609 0 : WB_fenv_fx[i] = mult_r( hBWE_FD->prev_SWB_fenv_fx[i], 24576 );
610 0 : move16();
611 : }
612 : }
613 0 : test();
614 0 : IF( NE_16( st_fx->last_extl, WB_BWE ) || st_fx->bfi )
615 : {
616 0 : Copy( WB_fenv_fx, hBWE_FD->prev_SWB_fenv_fx, 2 );
617 : }
618 :
619 0 : exp = norm_l( hBWE_FD->prev_Energy_wb_fx );
620 0 : IF( GT_16( add( hBWE_FD->prev_Q_synth, exp ), Q_syn ) )
621 : {
622 0 : hBWE_FD->prev_Energy_wb_fx = L_shr( hBWE_FD->prev_Energy_wb_fx, sub( hBWE_FD->prev_Q_synth, Q_syn ) );
623 0 : move32();
624 : }
625 : ELSE
626 : {
627 0 : Q_syn = add( hBWE_FD->prev_Q_synth, exp );
628 0 : hBWE_FD->prev_Energy_wb_fx = L_shl( hBWE_FD->prev_Energy_wb_fx, exp );
629 0 : move32();
630 : }
631 :
632 0 : WB_BWE_decoding_fx( ysynth_fx, WB_fenv_fx, ysynth_32, L_FRAME16k, mode,
633 0 : st_fx->last_extl, &hBWE_FD->prev_Energy_wb_fx, hBWE_FD->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm,
634 0 : st_fx->extl, coder_type, st_fx->total_brate, &hBWE_FD->Seed, &hBWE_FD->prev_flag,
635 0 : st_fx->prev_coder_type, Q_syn, &Q_syn_hb );
636 :
637 0 : IF( EQ_32( st_fx->output_Fs, 32000 ) )
638 : {
639 0 : set32_fx( &ysynth_32[L_FRAME16k], 0, L_FRAME16k );
640 : }
641 0 : ELSE IF( EQ_32( st_fx->output_Fs, 48000 ) )
642 : {
643 0 : set32_fx( &ysynth_32[L_FRAME16k], 0, L_FRAME32k );
644 : }
645 :
646 0 : Inverse_Transform( ysynth_32, &Q_syn_hb, t_audio32_tmp, 0, output_frame, output_frame, st_fx->element_mode );
647 :
648 0 : window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame,
649 : ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 );
650 :
651 0 : hBWE_FD->prev_mode = mode;
652 0 : move16();
653 0 : hBWE_FD->prev_Q_synth = Q_syn;
654 0 : move16();
655 :
656 0 : return Q_syn_hb;
657 : }
658 :
659 :
660 : /*-------------------------------------------------------------------*
661 : * swb_bwe_gain_deq()
662 : *
663 : * Decoding of SWB parameters
664 : *-------------------------------------------------------------------*/
665 :
666 : /* o : BWE class */
667 12387 : Word16 swb_bwe_gain_deq_fx(
668 : Decoder_State *st_fx, /* i/o: decoder state structure */
669 : const Word16 core, /* i : core : Q0 */
670 : Word16 *SWB_tenv, /* o : time-domain BWE envelope : Q0 */
671 : Word16 *SWB_fenv, /* o : frequency-domain BWE envelope : Q1 */
672 : const Word16 hr_flag, /* i : high rate flag : Q0 */
673 : const Word16 hqswb_clas /* i : HQ BWE class : Q0 */
674 : )
675 : {
676 : Word16 index, mode, n_band;
677 : Word16 indice[6];
678 : Word16 quant_tmp[SWB_FENV / 2], quant_tmp2[SWB_FENV / 2];
679 : Word16 nb_bits[6];
680 : Word16 nenv;
681 : Word16 tmp, exp, frac;
682 : Word32 L_tmp;
683 :
684 12387 : IF( hqswb_clas > 0 )
685 : {
686 2789 : mode = (Word16) get_next_indice_fx( st_fx, 1 );
687 2789 : IF( mode == 0 )
688 : {
689 2653 : mode = (Word16) get_next_indice_fx( st_fx, 1 );
690 : }
691 : ELSE
692 : {
693 136 : mode = HQ_GENERIC_SP_EXC;
694 136 : move16();
695 : }
696 : }
697 : ELSE
698 : {
699 9598 : mode = (Word16) get_next_indice_fx( st_fx, 2 );
700 : }
701 :
702 12387 : test();
703 12387 : IF( EQ_16( mode, 1 ) && core == ACELP_CORE )
704 : {
705 315 : FOR( n_band = 0; n_band < SWB_TENV; n_band++ )
706 : {
707 252 : index = (Word16) get_next_indice_fx( st_fx, 4 );
708 252 : SWB_tenv[n_band] = shl_sat( 1, index );
709 252 : move16();
710 : }
711 :
712 63 : indice[0] = (Word16) get_next_indice_fx( st_fx, 7 );
713 63 : move16();
714 63 : indice[1] = (Word16) get_next_indice_fx( st_fx, 6 );
715 63 : move16();
716 :
717 63 : tmp = shl( indice[0], 1 );
718 189 : FOR( n_band = 0; n_band < DIM_TR1; n_band++ )
719 : {
720 : /*Env_TR_Cdbk1_fx[ indice[0]*DIM_TR1+n_band]*/
721 126 : quant_tmp[2 * n_band] = Env_TR_Cdbk1_fx[tmp + n_band]; /*Q8 */
722 126 : move16();
723 : }
724 :
725 : /*tmp = indice[1]*DIM_TR2*/
726 63 : tmp = shl( indice[1], 1 );
727 63 : quant_tmp[1] = add_sat( shr( add_sat( quant_tmp[0], quant_tmp[2] ), 1 ), Env_TR_Cdbk2_fx[tmp] );
728 : /* To prevent an unnecessary saturation, it would be better to write the code as below, but might have an impact on EVS bit exactness */
729 : /* quant_tmp[1] = add( extract_h( L_mac( L_mult( quant_tmp[0], 16384 ), quant_tmp[2], 16384 ) ), Env_TR_Cdbk2_fx[tmp] ); */
730 63 : move16(); /*Q8 */
731 63 : quant_tmp[3] = add( quant_tmp[2], Env_TR_Cdbk2_fx[tmp + 1] );
732 63 : move16(); /*Q8 */
733 :
734 315 : FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ )
735 : {
736 252 : tmp = add( quant_tmp[n_band], Mean_env_tr_fx[n_band] ); /*Q8 */
737 :
738 : /*-----------------------------------------------------------------*
739 : * SWB_fenv[n_band] = pow(10.0, tmp/40)
740 : * = pow(2, 3.321928*tmp/40)
741 : * = pow(2, 0.0830482*tmp)
742 : *-----------------------------------------------------------------*/
743 252 : L_tmp = L_mult( tmp, 21771 ); /* 0.0830482 in Q18 -> Q27 */
744 252 : L_tmp = L_shr( L_tmp, 11 ); /* From Q27 to Q16 */
745 252 : frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */
746 252 : tmp = extract_l( Pow2( 13, frac ) );
747 252 : exp = sub( exp, 13 );
748 252 : SWB_fenv[n_band] = shl( tmp, add( exp, 1 ) );
749 252 : move16(); /*Q1 */
750 : }
751 : /* in case of band-width switching, attenuate frame gain */
752 63 : IF( st_fx->bws_cnt1 > 0 )
753 : {
754 0 : tmp = i_mult( st_fx->bws_cnt1, 1638 );
755 0 : FOR( n_band = 0; n_band < SWB_TENV; n_band++ )
756 : {
757 0 : SWB_tenv[n_band] = mult_r( SWB_tenv[n_band], tmp );
758 0 : move16();
759 : }
760 :
761 0 : FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ )
762 : {
763 0 : SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp );
764 0 : move16();
765 : }
766 : }
767 : }
768 : ELSE
769 : {
770 12324 : nb_bits[0] = 5;
771 12324 : move16();
772 12324 : nb_bits[1] = 7;
773 12324 : move16();
774 12324 : nb_bits[2] = 6;
775 12324 : move16();
776 12324 : nb_bits[3] = 5;
777 12324 : move16();
778 :
779 12324 : IF( EQ_16( hr_flag, 1 ) )
780 : {
781 0 : nb_bits[4] = 5;
782 0 : move16();
783 0 : nenv = SWB_FENV - 2;
784 0 : move16();
785 : }
786 : ELSE
787 : {
788 12324 : nb_bits[4] = 6;
789 12324 : move16();
790 12324 : nenv = SWB_FENV;
791 12324 : move16();
792 : }
793 :
794 73944 : FOR( n_band = 0; n_band < 5; n_band++ )
795 : {
796 61620 : indice[n_band] = (Word16) get_next_indice_fx( st_fx, nb_bits[n_band] );
797 61620 : move16();
798 : }
799 :
800 12324 : IF( EQ_16( hqswb_clas, HQ_GEN_FB ) )
801 : {
802 2070 : indice[n_band] = (Word16) get_next_indice_fx( st_fx, 5 );
803 2070 : move16();
804 : }
805 :
806 12324 : Copy( &EnvCdbk11_fx[indice[0] * DIM11], quant_tmp, DIM11 );
807 12324 : Copy( &EnvCdbk1st_fx[indice[1] * DIM1ST], quant_tmp2, DIM1ST );
808 12324 : Copy( &EnvCdbk2nd_fx[indice[2] * DIM2ND], quant_tmp2 + DIM1ST, DIM2ND );
809 :
810 86268 : FOR( n_band = 0; n_band < ( DIM11 - 1 ); n_band++ )
811 : {
812 73944 : quant_tmp[n_band] = add( quant_tmp[n_band], quant_tmp2[n_band] );
813 73944 : move16(); /*Q8 */
814 73944 : SWB_fenv[n_band * 2] = quant_tmp[n_band];
815 73944 : move16(); /*Q8 */
816 : }
817 :
818 12324 : IF( EQ_16( hr_flag, 1 ) )
819 : {
820 0 : quant_tmp[6] = add( quant_tmp[6], quant_tmp2[6] );
821 0 : move16(); /*Q8 */
822 0 : SWB_fenv[11] = quant_tmp[6];
823 0 : move16();
824 :
825 0 : Copy( &EnvCdbk3rd_fx[indice[3] * DIM3RD], quant_tmp2, DIM3RD );
826 0 : Copy( &EnvCdbk3rd_fx[indice[4] * DIM3RD], quant_tmp2 + DIM3RD, DIM3RD );
827 :
828 0 : FOR( n_band = 0; n_band < 5; n_band++ )
829 : {
830 0 : SWB_fenv[n_band * 2 + 1] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] );
831 0 : move16(); /*Q8 */
832 : }
833 :
834 0 : SWB_fenv[0] = add( SWB_fenv[0], quant_tmp2[0] );
835 0 : move16(); /*Q8 */
836 : }
837 : ELSE
838 : {
839 12324 : quant_tmp[DIM11 - 1] = add( quant_tmp[DIM11 - 1], quant_tmp2[DIM11 - 1] );
840 12324 : move16(); /*Q8 */
841 12324 : SWB_fenv[( DIM11 - 1 ) * 2] = quant_tmp[DIM11 - 1];
842 12324 : move16();
843 :
844 12324 : Copy( &EnvCdbk3rd_fx[i_mult2( indice[3], DIM3RD )], quant_tmp2, DIM3RD );
845 12324 : Copy( &EnvCdbk4th_fx[indice[4] * DIM4TH], quant_tmp2 + DIM3RD, DIM4TH );
846 :
847 86268 : FOR( n_band = 0; n_band < DIM12 - 1; n_band++ )
848 : {
849 73944 : SWB_fenv[n_band * 2 + 1] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] );
850 73944 : move16(); /*Q8 */
851 : }
852 :
853 12324 : SWB_fenv[add( n_band * 2, 1 )] = add( quant_tmp[n_band], quant_tmp2[n_band] );
854 12324 : move16(); /*Q8 */
855 : }
856 :
857 184860 : FOR( n_band = 0; n_band < nenv; n_band++ )
858 : {
859 172536 : tmp = add( SWB_fenv[n_band], Mean_env_fx[n_band] ); /*Q8 */
860 :
861 172536 : L_tmp = L_mult( tmp, 21771 ); /* 0.166096 in Q17 -> Q26 */
862 172536 : L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */
863 172536 : frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */
864 :
865 172536 : tmp = extract_l( Pow2( 13, frac ) ); /* Put 13 as exponent so that */
866 : /* output of Pow2() will be: */
867 : /* 16384 < Pow2() <= 32767 */
868 172536 : exp = sub( exp, 13 );
869 172536 : SWB_fenv[n_band] = shl_sat( tmp, add( exp, 1 ) );
870 172536 : move16(); /*Q1 */
871 : }
872 :
873 12324 : IF( EQ_16( hqswb_clas, HQ_GEN_FB ) )
874 : {
875 2070 : Copy( &EnvCdbkFB_fx[indice[5] * DIM_FB], &SWB_fenv[nenv], DIM_FB ); /*Q7 */
876 :
877 8280 : FOR( n_band = 0; n_band < DIM_FB; n_band++ )
878 : {
879 6210 : tmp = add( SWB_fenv[n_band + nenv], Mean_env_fb_fx[n_band] );
880 6210 : L_tmp = L_mult( tmp, 21771 ); /* 0.166096 in Q17 -> Q25 */
881 6210 : L_tmp = L_shr( L_tmp, 9 ); /* From Q25 to Q16 */
882 6210 : frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */
883 :
884 6210 : tmp = extract_l( Pow2( 13, frac ) ); /* Put 13 as exponent so that */
885 : /* output of Pow2() will be: */
886 : /* 16384 < Pow2() <= 32767 */
887 6210 : exp = sub( exp, 13 );
888 6210 : SWB_fenv[n_band + nenv] = shl( tmp, add( exp, 1 ) );
889 6210 : move16();
890 : }
891 : }
892 :
893 : /* in case of band-width switching, attenuate frame gain */
894 : }
895 :
896 12387 : return mode;
897 : }
898 :
899 : /*-------------------------------------------------------------------*
900 : * swb_bwe_dec()
901 : *
902 : * SWB BWE decoder
903 : *-------------------------------------------------------------------*/
904 :
905 : /*o : Q_syn_hb */
906 6 : Word16 swb_bwe_dec_fx(
907 : Decoder_State *st_fx, /* i/o: decoder state structure */
908 : Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */
909 : Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */
910 : const Word16 output_frame, /* i : frame length */
911 : Word16 *Qpost )
912 : {
913 : Word16 i, l_subfr;
914 : Word16 mode;
915 6 : Word16 frica_flag = 0;
916 6 : move16();
917 : Word16 idxGain;
918 : Word16 Q_syn, Q_syn_hb;
919 : Word16 ysynth_fx[L_FRAME48k];
920 : Word16 tmp;
921 : Word16 SWB_tenv_fx[SWB_TENV];
922 : Word32 L_wtda_synth_fx[2 * L_FRAME48k], ysynth_32[L_FRAME48k];
923 : Word16 scl, new_input_fx_exp;
924 : Word32 t_audio32_tmp[L_FRAME48k];
925 : Word32 SWB_tenv_tmp_fx[SWB_TENV];
926 : Word32 L_tmp;
927 : Word16 exp, frac;
928 6 : Word16 fb_ener_adjust_fx = 0;
929 6 : move16();
930 : Word16 SWB_fenv_fx[SWB_FENV];
931 : Word16 L;
932 6 : Word16 j = 0;
933 6 : move16();
934 : Word16 ener_adjust_quan_fx;
935 : Word16 tmp2;
936 : Word16 fb_band_begin;
937 : FD_BWE_DEC_HANDLE hBWE_FD;
938 6 : hBWE_FD = st_fx->hBWE_FD;
939 :
940 : /*---------------------------------------------------------------------*
941 : * SWB BWE decoding
942 : *---------------------------------------------------------------------*/
943 : /* windowing of the ACELP core synthesis */
944 6 : new_input_fx_exp = *Qpost;
945 6 : move16();
946 :
947 : {
948 6 : wtda_fx( synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx,
949 : &hBWE_FD->old_wtda_swb_fx_exp,
950 : ALDO_WINDOW,
951 : ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */
952 : output_frame );
953 6 : *Qpost = sub( new_input_fx_exp, 15 );
954 6 : move16();
955 : /* DCT of the ACELP core synthesis */
956 6 : direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode );
957 : }
958 : /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */
959 6 : scl = sub( 16 + MAX_Q_NEW_INPUT, new_input_fx_exp );
960 : /* Possible to Upscale? */
961 6 : IF( scl > 0 )
962 : {
963 : /* Yes */
964 : /* Calc Room to Upscale */
965 6 : Q_syn = Find_Max_Norm32( ysynth_32, output_frame );
966 : /* Stay within MAX_Q_NEW_INPUT */
967 6 : scl = s_min( Q_syn, scl );
968 : }
969 6 : Copy_Scale_sig32_16( ysynth_32, ysynth_fx, output_frame, scl );
970 6 : Q_syn = add( sub( new_input_fx_exp, 16 ), scl );
971 :
972 6 : IF( !st_fx->bfi )
973 : {
974 6 : IF( st_fx->bws_cnt > 0 )
975 : {
976 : /* estimate parameters */
977 0 : mode = para_pred_bws_fx( st_fx, ysynth_fx, SWB_fenv_fx, Q_syn );
978 : }
979 : ELSE
980 : {
981 : /* de-quantization */
982 6 : mode = swb_bwe_gain_deq_fx( st_fx, ACELP_CORE, SWB_tenv_fx, SWB_fenv_fx, 0, -1 );
983 : }
984 :
985 6 : L = SWB_FENV;
986 6 : move16();
987 6 : if ( EQ_16( mode, TRANSIENT ) )
988 : {
989 0 : L = SWB_FENV_TRANS;
990 0 : move16();
991 : }
992 6 : L_tmp = 0;
993 6 : move16();
994 90 : FOR( i = 0; i < L; i++ )
995 : {
996 84 : L_tmp = L_add( L_tmp, L_deposit_l( SWB_fenv_fx[i] ) );
997 : }
998 :
999 6 : exp = norm_s( L );
1000 6 : tmp = div_s( shl( 1, sub( 14, exp ) ), L ); /*Q(29-exp) */
1001 :
1002 6 : L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(1+29-exp+1-16)->Q(15-exp) */
1003 6 : st_fx->prev_ener_shb_fx = round_fx( L_shl( L_tmp, add( exp, 2 ) ) ); /*Q1 */
1004 6 : move16();
1005 : }
1006 : ELSE
1007 : {
1008 : /* SHB FEC */
1009 0 : IF( NE_16( hBWE_FD->prev_mode, TRANSIENT ) )
1010 : {
1011 0 : mode = hBWE_FD->prev_mode;
1012 0 : move16();
1013 : }
1014 : ELSE
1015 : {
1016 0 : mode = NORMAL;
1017 0 : move16();
1018 : }
1019 :
1020 0 : Copy( hBWE_FD->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV );
1021 : }
1022 :
1023 : /* reconstruction of MDCT spectrum of the error signal */
1024 6 : set32_fx( ysynth_32, 0, output_frame );
1025 6 : IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
1026 : {
1027 0 : SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, hBWE_FD->prev_SWB_fenv_fx,
1028 0 : &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 80, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl );
1029 : }
1030 : ELSE
1031 : {
1032 6 : SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, hBWE_FD->prev_SWB_fenv_fx,
1033 6 : &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 6, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl );
1034 : }
1035 :
1036 6 : test();
1037 6 : IF( EQ_16( hBWE_FD->prev_frica_flag, 1 ) && frica_flag == 0 )
1038 : {
1039 0 : FOR( i = 0; i < L_SUBFR; i++ )
1040 : {
1041 0 : tmp = sub( 32767, extract_l( L_mult0( i, 512 ) ) ); /*Q15 */
1042 0 : hBWE_FD->mem_imdct_fx[i] = mult_r( hBWE_FD->mem_imdct_fx[i], tmp );
1043 0 : move16(); /*Q_synth */
1044 : }
1045 :
1046 0 : FOR( ; i < output_frame; i++ )
1047 : {
1048 0 : hBWE_FD->mem_imdct_fx[i] = 0;
1049 0 : move16();
1050 : }
1051 : }
1052 :
1053 : /* decode information */
1054 6 : IF( EQ_16( st_fx->extl, FB_BWE ) )
1055 : {
1056 0 : IF( !st_fx->bfi )
1057 : {
1058 0 : idxGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_FB_FRAMEGAIN );
1059 0 : fb_ener_adjust_fx = usdequant_fx( idxGain, FB_GAIN_QLOW_FX, FB_GAIN_QDELTA_FX ); /*Q15 */
1060 : }
1061 0 : ELSE IF( st_fx->bfi )
1062 : {
1063 0 : fb_ener_adjust_fx = hBWE_FD->prev_fb_ener_adjust_fx;
1064 0 : move16();
1065 : }
1066 :
1067 0 : hBWE_FD->prev_fb_ener_adjust_fx = fb_ener_adjust_fx;
1068 0 : move16();
1069 0 : IF( EQ_16( mode, TRANSIENT ) )
1070 : {
1071 0 : ener_adjust_quan_fx = shr( fb_ener_adjust_fx, 2 ); /*Q13*/
1072 : }
1073 : ELSE
1074 : {
1075 0 : IF( SWB_fenv_fx[7] != 0 )
1076 : {
1077 0 : tmp = div_s( 1, SWB_fenv_fx[7] );
1078 0 : move16(); /*Q14*/
1079 0 : ener_adjust_quan_fx = s_min( shr( i_mult_sat( SWB_fenv_fx[13], tmp ), 2 ), 32767 ); /*Q13*/
1080 : }
1081 : ELSE
1082 : {
1083 0 : ener_adjust_quan_fx = 0;
1084 0 : move16(); /*Q13*/
1085 : }
1086 : }
1087 0 : fb_band_begin = FB_BAND_BEGIN;
1088 0 : move16();
1089 :
1090 0 : FOR( i = fb_band_begin; i < add( fb_band_begin, DE_OFFSET1 ); i++ )
1091 : {
1092 0 : tmp = sub( 32767, i_mult( j, 1024 ) );
1093 0 : tmp = mult_r( tmp, ener_adjust_quan_fx ); /*Q13*/
1094 :
1095 0 : tmp2 = i_mult( j, 256 ); /*Q13*/
1096 0 : tmp2 = mult_r( tmp2, fb_ener_adjust_fx ); /*Q13*/
1097 :
1098 0 : tmp = add( tmp, tmp2 ); /*Q13*/
1099 0 : ysynth_32[i] = ysynth_32[i - FB_BAND_WIDTH];
1100 0 : move16();
1101 0 : ysynth_32[i] = L_shl( Mult_32_16( ysynth_32[i], tmp ), 2 );
1102 0 : move32(); /*15+Q_syn */
1103 0 : j = add( j, 1 );
1104 : }
1105 :
1106 0 : FOR( ; i < FB_BAND_END; i++ )
1107 : {
1108 0 : ysynth_32[i] = ysynth_32[i - FB_BAND_WIDTH];
1109 0 : move16();
1110 0 : ysynth_32[i] = Mult_32_16( ysynth_32[i], fb_ener_adjust_fx );
1111 0 : move32(); /*15+Q_syn */
1112 : }
1113 : }
1114 :
1115 6 : Q_syn_hb = add( Q_syn, Q_32_BITS );
1116 6 : Inverse_Transform( ysynth_32, &Q_syn_hb, t_audio32_tmp, 0, output_frame, output_frame, st_fx->element_mode );
1117 6 : window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 );
1118 6 : l_subfr = mult( output_frame, 8192 );
1119 :
1120 6 : test();
1121 6 : IF( EQ_16( mode, TRANSIENT ) )
1122 : {
1123 0 : FOR( i = 0; i < SWB_TENV; i++ )
1124 : {
1125 0 : SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i], 26214 );
1126 0 : move32(); /*Q15 */
1127 : }
1128 :
1129 : /* time envelope shaping when the current frame is TRANSIENT frame */
1130 0 : time_envelop_shaping_fx( hb_synth_fx, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb );
1131 0 : Q_syn_hb = sub( Q_syn_hb, 3 );
1132 :
1133 0 : hBWE_FD->prev_td_energy_fx = SWB_tenv_fx[3];
1134 0 : move16();
1135 : }
1136 6 : ELSE IF( EQ_16( frica_flag, 1 ) && hBWE_FD->prev_frica_flag == 0 )
1137 : {
1138 0 : time_reduce_pre_echo_fx( synth_fx, hb_synth_fx, hBWE_FD->prev_td_energy_fx, l_subfr, *Qpost, Q_syn_hb );
1139 : }
1140 : ELSE
1141 : {
1142 6 : tmp = i_mult2( 3, l_subfr );
1143 6 : L_tmp = L_deposit_l( 0 );
1144 966 : FOR( i = 0; i < l_subfr; i++ )
1145 : {
1146 960 : L_tmp = L_mac0_sat( L_tmp, hb_synth_fx[add( tmp, i )], hb_synth_fx[add( tmp, i )] ); /*(2*Q_syn_hb) */
1147 : }
1148 6 : L_tmp = Mult_32_16( L_tmp, div_s( 1, l_subfr ) ); /*(2*Q_syn_hb) */
1149 :
1150 6 : hBWE_FD->prev_td_energy_fx = 0;
1151 6 : move16();
1152 6 : IF( L_tmp != 0 )
1153 : {
1154 4 : exp = norm_l( L_tmp );
1155 4 : frac = extract_h( L_shl( L_tmp, exp ) );
1156 4 : exp = sub( exp, sub( 30, shl( Q_syn_hb, 1 ) ) );
1157 :
1158 4 : tmp = div_s( 16384, frac );
1159 4 : L_tmp = L_deposit_h( tmp );
1160 4 : L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */
1161 4 : hBWE_FD->prev_td_energy_fx = round_fx( L_shl( L_tmp, sub( exp, 15 ) ) ); /*Q0 */
1162 4 : move16();
1163 : }
1164 : }
1165 :
1166 6 : hBWE_FD->prev_frica_flag = frica_flag;
1167 6 : move16();
1168 6 : hBWE_FD->prev_mode = mode;
1169 6 : move16();
1170 :
1171 6 : return Q_syn_hb;
1172 : }
1173 :
1174 :
1175 : /*-------------------------------------------------------------------*
1176 : * fd_bwe_dec_init()
1177 : *
1178 : * Initialize FD BWE state structure at the decoder
1179 : *-------------------------------------------------------------------*/
1180 :
1181 3085 : void fd_bwe_dec_init_fx(
1182 : FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */
1183 : )
1184 : {
1185 3085 : set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
1186 3085 : set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k );
1187 3085 : hBWE_FD->old_wtda_swb_fx_exp = 0;
1188 3085 : move16();
1189 :
1190 3085 : hBWE_FD->prev_mode = NORMAL;
1191 3085 : move16();
1192 3085 : set16_fx( hBWE_FD->prev_SWB_fenv_fx, 0, SWB_FENV );
1193 3085 : hBWE_FD->prev_Energy_fx = 0;
1194 3085 : move16();
1195 3085 : hBWE_FD->prev_L_swb_norm = 8;
1196 3085 : move16();
1197 3085 : hBWE_FD->Seed = 21211;
1198 3085 : move16();
1199 3085 : hBWE_FD->prev_frica_flag = 0;
1200 3085 : move16();
1201 3085 : set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k );
1202 3085 : hBWE_FD->mem_imdct_exp_fx = 0;
1203 3085 : move16();
1204 3085 : hBWE_FD->prev_td_energy_fx = 0;
1205 3085 : move16();
1206 3085 : hBWE_FD->prev_weight_fx = 6554; /*0.2 in Q15*/
1207 3085 : move16();
1208 3085 : hBWE_FD->prev_flag = 0;
1209 3085 : move16();
1210 3085 : hBWE_FD->last_wb_bwe_ener_fx = 0;
1211 3085 : move16();
1212 3085 : hBWE_FD->prev_Energy_wb_fx = L_deposit_l( 0 );
1213 3085 : move32();
1214 3085 : hBWE_FD->memExp1 = 0;
1215 3085 : move16();
1216 :
1217 : /* Previous frame LPC initialization for PPP */
1218 3085 : hBWE_FD->prev_Q_synth = 0;
1219 3085 : move16();
1220 :
1221 3085 : hBWE_FD->mem_deemph_old_syn_fx = 0;
1222 3085 : move16();
1223 3085 : hBWE_FD->prev_fb_ener_adjust_fx = 0;
1224 3085 : move16();
1225 :
1226 3085 : return;
1227 : }
1228 :
1229 : /*-------------------------------------------------------------------*
1230 : * WB_BWE_gain_deq()
1231 : *
1232 : * Decoding of WB parameters
1233 : *-------------------------------------------------------------------*/
1234 :
1235 :
1236 12399 : Word16 swb_bwe_dec_fx32(
1237 : Decoder_State *st_fx, /* i/o: decoder state structure */
1238 : Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */
1239 : Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis : Q11 */
1240 : Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis : Q_syn_hb */
1241 : Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
1242 : Word16 output_frame /* i : frame length */
1243 : )
1244 : {
1245 : Word16 L;
1246 : Word16 mode;
1247 : Word16 idxGain;
1248 : Word16 i, j, l_subfr;
1249 : Word16 fb_band_begin;
1250 12399 : Word16 frica_flag = 0;
1251 12399 : move16();
1252 : Word16 ener_adjust_quan_fx;
1253 12399 : Word16 fb_ener_adjust_fx = 0;
1254 12399 : move16();
1255 : Word16 scl, new_input_fx_exp, ysynth_frame_size;
1256 : Word16 Q_syn, Q_syn_hb, tmp, tmp2, q_tmp, Qsynth_fx16;
1257 :
1258 : Word16 ysynth_fx[L_FRAME48k];
1259 : Word16 SWB_fenv_fx[SWB_FENV];
1260 : Word16 SWB_tenv_fx[SWB_TENV];
1261 : Word16 synth_fx16[L_FRAME48k];
1262 : Word16 hb_synth_fx16[L_FRAME48k];
1263 :
1264 : Word32 L_tmp;
1265 : Word32 yerror_fx[L_FRAME48k];
1266 : Word32 ysynth_fx32[L_FRAME48k];
1267 : Word32 SWB_tenv_tmp_fx[SWB_TENV];
1268 : Word32 wtda_synth_fx[2 * L_FRAME48k];
1269 :
1270 : FD_BWE_DEC_HANDLE hBWE_FD;
1271 12399 : hBWE_FD = st_fx->hBWE_FD;
1272 :
1273 : /*---------------------------------------------------------------------*
1274 : * SWB BWE decoding
1275 : *---------------------------------------------------------------------*/
1276 12399 : test();
1277 12399 : IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft )
1278 : {
1279 : /* todo - wtda() does not support L_FRAME length; thus temporarily resample the signal */
1280 : /* todo - delay output[] by 1.25ms ? */
1281 952 : L_lerp_fx_q11( output_fx, ysynth_fx32, L_FRAME16k, st_fx->L_frame );
1282 :
1283 : /* windowing of the ACELP core synthesis */
1284 952 : wtda_fx32( ysynth_fx32, wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx32, ALDO_WINDOW, ALDO_WINDOW, /*st_fx->L_frame*/ L_FRAME16k );
1285 :
1286 : /* DCT of the ACELP core synthesis */
1287 952 : new_input_fx_exp = 11;
1288 952 : move16();
1289 952 : direct_transform_fx( wtda_synth_fx, ysynth_fx32, 0, /*st_fx->L_frame*/ L_FRAME16k, &new_input_fx_exp, st_fx->element_mode );
1290 952 : ysynth_frame_size = L_FRAME16k;
1291 952 : move16();
1292 : }
1293 : ELSE
1294 : {
1295 : /* windowing of the ACELP core synthesis */
1296 11447 : wtda_fx32( synth_fx, wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx32, ALDO_WINDOW, ALDO_WINDOW, output_frame );
1297 :
1298 : /* DCT of the ACELP core synthesis */
1299 11447 : new_input_fx_exp = 11;
1300 11447 : move16();
1301 11447 : direct_transform_fx( wtda_synth_fx, ysynth_fx32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode );
1302 11447 : ysynth_frame_size = output_frame;
1303 11447 : move16();
1304 : }
1305 :
1306 : /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */
1307 12399 : scl = sub( 16 + 11, new_input_fx_exp );
1308 : /* Possible to Upscale? */
1309 12399 : IF( scl > 0 )
1310 : {
1311 : /* Yes */
1312 : /* Calc Room to Upscale */
1313 12399 : Q_syn = sub( Find_Max_Norm32( ysynth_fx32, ysynth_frame_size ), 3 );
1314 : /* Stay within MAX_Q_NEW_INPUT */
1315 12399 : scl = s_min( Q_syn, scl );
1316 : }
1317 : /*Don't upscale if already in 15 bits*/
1318 12399 : IF( GT_16( scl, 15 ) )
1319 : {
1320 5183093 : FOR( i = 0; i < ysynth_frame_size; i++ )
1321 : {
1322 5177600 : ysynth_fx[i] = extract_l( ysynth_fx32[i] );
1323 5177600 : move16();
1324 : }
1325 5493 : Q_syn = new_input_fx_exp;
1326 5493 : move16();
1327 : }
1328 : ELSE
1329 : {
1330 6906 : Copy_Scale_sig32_16( ysynth_fx32, ysynth_fx, ysynth_frame_size, scl );
1331 6906 : Q_syn = add( sub( new_input_fx_exp, 16 ), scl );
1332 : }
1333 :
1334 12399 : IF( !st_fx->bfi )
1335 : {
1336 12334 : IF( st_fx->bws_cnt > 0 )
1337 : {
1338 : /* estimate parameters */
1339 2742 : mode = para_pred_bws_fx( st_fx, ysynth_fx, SWB_fenv_fx, Q_syn );
1340 : }
1341 : ELSE
1342 : {
1343 : /* de-quantization */
1344 9592 : mode = swb_bwe_gain_deq_fx( st_fx, ACELP_CORE, SWB_tenv_fx, SWB_fenv_fx, 0, -1 );
1345 : }
1346 :
1347 12334 : L = SWB_FENV;
1348 12334 : move16();
1349 12334 : if ( EQ_16( mode, TRANSIENT ) )
1350 : {
1351 63 : L = SWB_FENV_TRANS;
1352 63 : move16();
1353 : }
1354 :
1355 12334 : L_tmp = 0;
1356 12334 : move32();
1357 184380 : FOR( i = 0; i < L; i++ )
1358 : {
1359 172046 : L_tmp = L_add( L_tmp, L_deposit_l( SWB_fenv_fx[i] ) );
1360 : }
1361 12334 : q_tmp = norm_s( L );
1362 12334 : tmp = div_s( shl( 1, sub( 14, q_tmp ) ), L ); /*Q(29-q_tmp) */
1363 12334 : L_tmp = Mpy_32_16_1( L_tmp, tmp ); /*Q(1+29-q_tmp+1-16)->Q(15-q_tmp) */
1364 12334 : st_fx->prev_ener_shb_fx = round_fx( L_shl( L_tmp, add( q_tmp, 2 ) ) ); /*Q1 */
1365 12334 : move16();
1366 : }
1367 : ELSE
1368 : {
1369 : /* SHB FEC */
1370 :
1371 65 : IF( NE_16( hBWE_FD->prev_mode, TRANSIENT ) )
1372 : {
1373 65 : mode = hBWE_FD->prev_mode;
1374 65 : move16();
1375 : }
1376 : ELSE
1377 : {
1378 0 : mode = NORMAL;
1379 0 : move16();
1380 : }
1381 :
1382 65 : Copy( hBWE_FD->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV );
1383 : }
1384 :
1385 : /* reconstruction of MDCT spectrum of the error signal */
1386 12399 : set32_fx( yerror_fx, 0, output_frame );
1387 :
1388 12399 : IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
1389 : {
1390 3533 : SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, hBWE_FD->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 80, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl );
1391 : }
1392 : ELSE
1393 : {
1394 8866 : SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, hBWE_FD->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 6, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl );
1395 : }
1396 :
1397 12399 : test();
1398 12399 : IF( EQ_16( hBWE_FD->prev_frica_flag, 1 ) && frica_flag == 0 )
1399 : {
1400 2080 : FOR( i = 0; i < L_SUBFR; i++ )
1401 : {
1402 2048 : tmp = sub( 32767, extract_l( L_mult0( i, 512 ) ) ); /*Q15 */
1403 2048 : hBWE_FD->mem_imdct_fx[i] = mult_r( hBWE_FD->mem_imdct_fx[i], tmp );
1404 2048 : move16();
1405 : }
1406 :
1407 28064 : FOR( ; i < output_frame; i++ )
1408 : {
1409 28032 : hBWE_FD->mem_imdct_fx[i] = 0;
1410 28032 : move16();
1411 : }
1412 : }
1413 :
1414 : /* decode information */
1415 12399 : IF( EQ_16( st_fx->extl, FB_BWE ) )
1416 : {
1417 3960 : IF( !st_fx->bfi )
1418 : {
1419 3957 : idxGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_FB_FRAMEGAIN );
1420 3957 : fb_ener_adjust_fx = usdequant_fx( idxGain, FB_GAIN_QLOW_FX, FB_GAIN_QDELTA_FX ); /*Q15 */
1421 : }
1422 3 : ELSE IF( st_fx->bfi )
1423 : {
1424 3 : fb_ener_adjust_fx = hBWE_FD->prev_fb_ener_adjust_fx;
1425 3 : move16();
1426 : }
1427 :
1428 3960 : hBWE_FD->prev_fb_ener_adjust_fx = fb_ener_adjust_fx;
1429 3960 : move16();
1430 3960 : IF( EQ_16( mode, TRANSIENT ) )
1431 : {
1432 1 : ener_adjust_quan_fx = shr( fb_ener_adjust_fx, 2 );
1433 : }
1434 : ELSE
1435 : {
1436 3959 : IF( SWB_fenv_fx[7] != 0 )
1437 : {
1438 3921 : tmp = div_s( 1, SWB_fenv_fx[7] );
1439 3921 : ener_adjust_quan_fx = s_min( shr( i_mult_sat( SWB_fenv_fx[13], tmp ), 2 ), 32767 );
1440 : }
1441 : ELSE
1442 : {
1443 38 : ener_adjust_quan_fx = 0;
1444 38 : move16();
1445 : }
1446 : }
1447 :
1448 3960 : fb_band_begin = FB_BAND_BEGIN;
1449 3960 : move16();
1450 3960 : if ( EQ_16( st_fx->L_frame, L_FRAME ) )
1451 : {
1452 743 : fb_band_begin = FB_BAND_BEGIN_12k8;
1453 743 : move16();
1454 : }
1455 :
1456 3960 : j = 0;
1457 3960 : move16();
1458 130680 : FOR( i = fb_band_begin; i < add( fb_band_begin, DE_OFFSET1 ); i++ )
1459 : {
1460 126720 : tmp = sub( 32767, i_mult( j, 1024 ) );
1461 126720 : tmp = mult_r( tmp, ener_adjust_quan_fx ); /*Q13*/
1462 :
1463 126720 : tmp2 = i_mult( j, 256 ); /*Q13*/
1464 126720 : tmp2 = mult_r( tmp2, fb_ener_adjust_fx ); /*Q13*/
1465 :
1466 126720 : tmp = add( tmp, tmp2 ); /*Q13*/
1467 126720 : yerror_fx[i] = L_shl( Mpy_32_16_1( yerror_fx[i - FB_BAND_WIDTH], tmp ), 2 ); /*15+Q_syn */
1468 126720 : move32();
1469 126720 : j = add( j, 1 );
1470 : }
1471 634620 : FOR( ; i < FB_BAND_END; i++ )
1472 : {
1473 630660 : yerror_fx[i] = Mpy_32_16_1( yerror_fx[i - FB_BAND_WIDTH], fb_ener_adjust_fx ); /*15+Q_syn */
1474 630660 : move32();
1475 : }
1476 : }
1477 :
1478 : /* iDCT of the error signal */
1479 12399 : Q_syn_hb = add( Q_syn, 15 );
1480 12399 : Inverse_Transform( yerror_fx, &Q_syn_hb, wtda_synth_fx, 0, output_frame, -1, st_fx->element_mode );
1481 :
1482 : /* inverse windowing of the error signal */
1483 12399 : window_ola_fx( wtda_synth_fx, hb_synth_fx16, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 );
1484 12399 : l_subfr = mult( output_frame, 8192 );
1485 :
1486 12399 : test();
1487 12399 : IF( EQ_16( mode, TRANSIENT ) )
1488 : {
1489 315 : FOR( i = 0; i < SWB_TENV; i++ )
1490 : {
1491 252 : SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i] /*Q0*/, 26214 /*0.8f Q15*/ ); // Q15
1492 252 : move32();
1493 : }
1494 :
1495 : /* time envelope shaping when the current frame is TRANSIENT frame */
1496 63 : time_envelop_shaping_ivas_fx( hb_synth_fx16, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb );
1497 :
1498 63 : Q_syn_hb = sub( Q_syn_hb, 3 );
1499 :
1500 63 : hBWE_FD->prev_td_energy_fx = SWB_tenv_fx[3];
1501 63 : move16();
1502 : }
1503 12336 : ELSE IF( EQ_16( frica_flag, 1 ) && hBWE_FD->prev_frica_flag == 0 )
1504 : {
1505 96 : Qsynth_fx16 = Find_Max_Norm32( synth_fx, output_frame );
1506 96 : Qsynth_fx16 = sub( Qsynth_fx16, shr( add( sub( 15, norm_s( l_subfr ) ), 1 ), 1 ) );
1507 96 : Copy_Scale_sig32_16( synth_fx, synth_fx16, output_frame, Qsynth_fx16 );
1508 96 : Qsynth_fx16 = add( 11 - 16, Qsynth_fx16 );
1509 :
1510 : /* IVAS_fmToDo: synth[] is @internal_Fs!!! */
1511 96 : time_reduce_pre_echo_fx( synth_fx16, hb_synth_fx16, hBWE_FD->prev_td_energy_fx, l_subfr, Qsynth_fx16, Q_syn_hb );
1512 : }
1513 : ELSE
1514 : {
1515 12240 : tmp = i_mult2( 3, l_subfr );
1516 12240 : L_tmp = L_deposit_l( 0 );
1517 :
1518 2788000 : FOR( i = 0; i < l_subfr; i++ )
1519 : {
1520 2775760 : L_tmp = L_mac0_sat( L_tmp, hb_synth_fx16[add( tmp, i )], hb_synth_fx16[add( tmp, i )] ); /*(2*Q_syn_hb) */
1521 : }
1522 :
1523 12240 : L_tmp = Mult_32_16( L_tmp, div_s( 1, l_subfr ) ); /*(2*Q_syn_hb) */
1524 12240 : hBWE_FD->prev_td_energy_fx = 0;
1525 12240 : move16();
1526 :
1527 12240 : IF( L_tmp != 0 )
1528 : {
1529 10417 : q_tmp = norm_l( L_tmp );
1530 10417 : tmp = extract_h( L_shl( L_tmp, q_tmp ) );
1531 10417 : q_tmp = sub( q_tmp, sub( 30, shl( Q_syn_hb, 1 ) ) );
1532 :
1533 10417 : tmp = div_s( 16384, tmp );
1534 10417 : L_tmp = L_deposit_h( tmp );
1535 10417 : L_tmp = Isqrt_lc( L_tmp, &q_tmp ); /*Q(31-exp) */
1536 10417 : hBWE_FD->prev_td_energy_fx = round_fx( L_shl( L_tmp, sub( q_tmp, 15 ) ) ); /*Q0 */
1537 10417 : move16();
1538 : }
1539 : }
1540 :
1541 12399 : test();
1542 12399 : IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft )
1543 : {
1544 952 : Qsynth_fx16 = add( 16 - 11, Q_syn_hb );
1545 952 : Copy_Scale_sig32_16( synth_fx, synth_fx16, output_frame, Qsynth_fx16 );
1546 :
1547 : /* add HB synth from hf_synth() */
1548 952 : v_add_16( hb_synth_fx16, synth_fx16, hb_synth_fx16, output_frame );
1549 : }
1550 :
1551 12399 : hBWE_FD->prev_mode = mode;
1552 12399 : move16();
1553 12399 : hBWE_FD->prev_frica_flag = frica_flag;
1554 12399 : move16();
1555 :
1556 11256559 : FOR( i = 0; i < output_frame; i++ )
1557 : {
1558 11244160 : hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); // Q_syn_hb
1559 11244160 : move32();
1560 : }
1561 :
1562 12399 : return Q_syn_hb;
1563 : }
|