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 : #include <stdint.h>
34 : #include "options.h"
35 : #include "prot_fx.h"
36 : #include "basop_util.h"
37 : #include "rom_com.h"
38 :
39 :
40 : /*==========================================================================*/
41 : /* FUNCTION : Word16 WB_BWE_gain_pred_fx () */
42 : /*--------------------------------------------------------------------------*/
43 : /* PURPOSE : predict WB frequency envelopes for 0b WB BWE */
44 : /*--------------------------------------------------------------------------*/
45 : /* INPUT ARGUMENTS : */
46 : /* _Word16 *core_dec_freq i : Frequency domain core decoded signal */
47 : /* _Word16 coder_type i : coding type */
48 : /* _Word16 prev_coder_type i : coding type of last frame */
49 : /* _Word16 prev_WB_fenv i : envelope for last frame */
50 : /* _Word16 *voice_factors i : voicing factors //Q15 */
51 : /* _Word16 pitch_buf[] i : pitch buffer //Q6 */
52 : /* _Word16 last_core_brate i : previous frame core bitrate */
53 : /* _Word16 last_wb_bwe_ener i : previous frame wb bwe signal energy */
54 : /*--------------------------------------------------------------------------*/
55 : /* OUTPUT ARGUMENTS : */
56 : /* _Word16 *WB_fenv, o : WB frequency envelopes Q3 */
57 : /*--------------------------------------------------------------------------*/
58 : /* INPUT/OUTPUT ARGUMENTS : */
59 : /*--------------------------------------------------------------------------*/
60 : /* RETURN ARGUMENTS : */
61 : /* _Word16 mode */
62 : /*--------------------------------------------------------------------------*/
63 : /* CALLED FROM : */
64 : /*==========================================================================*/
65 :
66 4783 : Word16 WB_BWE_gain_pred_fx(
67 : Word16 *WB_fenv, /* o : WB frequency envelopes Q3 */
68 : const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal Q_syn */
69 : const Word16 coder_type, /* i : coding type */
70 : Word16 prev_coder_type, /* i : coding type of last frame */
71 : Word16 prev_WB_fenv, /* i : envelope for last frame Q3 */
72 : Word16 *voice_factors, /* i : voicing factors Q15 */
73 : const Word16 pitch_buf[], /* i : pitch buffer Q6 */
74 : Word32 last_core_brate, /* i : previous frame core bitrate */
75 : Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy Q3 */
76 : Word16 Q_syn, /* i : synthesis scaling */
77 : Word16 last_extl_fx, /* i : extl. layer for last frame */
78 : Word16 tilt_wb_fx /* Q4 */
79 : )
80 : {
81 : Word32 enerL;
82 : Word16 n_freq, mode, pitch;
83 4783 : Word16 ener_var_flag = 0;
84 4783 : move16();
85 : Word16 voice_factor, enerL_16, enerL_40, enerL_64;
86 4783 : Word16 env_var_flag = 0;
87 4783 : move16();
88 : Word16 exp;
89 : Word16 tmp, tmp1;
90 : Word32 L_tmp;
91 : Word32 L_WB_fenv0, L_WB_fenv1;
92 : Word16 pitch_buf_tmp[4];
93 4783 : Word16 alfa = MAX_16;
94 4783 : move16();
95 :
96 4783 : mode = NORMAL;
97 4783 : move16();
98 :
99 4783 : enerL = L_deposit_l( 0 );
100 310895 : FOR( n_freq = 128; n_freq < 192; n_freq++ )
101 : {
102 306112 : enerL = L_mac0_sat( enerL, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2(Q_syn) */
103 : }
104 :
105 4783 : L_WB_fenv0 = L_deposit_l( 0 );
106 157839 : FOR( n_freq = 192; n_freq < 224; n_freq++ )
107 : {
108 153056 : L_WB_fenv0 = L_mac0_sat( L_WB_fenv0, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2*Q_syn */
109 : }
110 :
111 4783 : L_WB_fenv1 = L_deposit_l( 0 );
112 157839 : FOR( n_freq = 224; n_freq < 256; n_freq++ )
113 : {
114 153056 : L_WB_fenv1 = L_mac0_sat( L_WB_fenv1, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2*Q_syn */
115 : }
116 :
117 4783 : L_tmp = sum16_32_fx( voice_factors, 4 );
118 4783 : voice_factor = extract_l( L_shr( L_tmp, 2 ) ); /*Q13 */
119 4783 : Copy_Scale_sig( pitch_buf, pitch_buf_tmp, 4, -1 );
120 4783 : pitch = sum16_fx( pitch_buf_tmp, 4 );
121 : /*Q5 */
122 :
123 4783 : L_tmp = L_shr( enerL, 4 );
124 4783 : test();
125 4783 : if ( GT_32( L_max( L_WB_fenv1, L_WB_fenv0 ), L_tmp ) && GT_16( 9856 /* 308 in Q5 */, pitch ) )
126 : {
127 4426 : ener_var_flag = 1;
128 4426 : move16();
129 : }
130 :
131 4783 : test();
132 4783 : IF( GT_32( L_WB_fenv0, L_shl_sat( L_WB_fenv1, 1 ) ) )
133 : {
134 1122 : exp = norm_l( L_WB_fenv0 );
135 1122 : tmp = extract_h( L_shl( L_WB_fenv0, exp ) );
136 1122 : tmp = div_s( 16384 /* 1 in Q14 */, tmp ); /*Q(15+14-2*Q_syn-exp) */
137 1122 : L_tmp = L_shr( Mult_32_16( L_shl( L_WB_fenv1, 1 ), tmp ), sub( 15, exp ) ); /*2*Q_syn+15+exp-15->2*Q_syn+exp */
138 : /*L_tmp Q15 */
139 1122 : tmp = extract_l( L_tmp );
140 1122 : alfa = s_max( tmp, 3277 /* 0.1 in Q15 */ ); /*Q15 */
141 1122 : L_WB_fenv0 = Mult_32_16( L_WB_fenv0, alfa ); /*2*Q_syn+15-15->2*Q_syn */
142 : }
143 3661 : ELSE IF( GT_32( L_WB_fenv1, L_shl_sat( L_WB_fenv0, 1 ) ) && NE_16( coder_type, UNVOICED ) )
144 : {
145 155 : exp = norm_l( L_WB_fenv1 );
146 155 : tmp = extract_h( L_shl( L_WB_fenv1, exp ) );
147 155 : tmp = div_s( 16384 /* 1 in Q14 */, tmp ); /*Q(15+14-2*Q_syn-exp) */
148 155 : L_tmp = L_shr( Mult_32_16( L_shl( L_WB_fenv0, 1 ), tmp ), sub( 15, exp ) ); /*2*Q_syn+15+exp-15->2*Q_syn+exp */
149 : /*L_tmp Q15 */
150 155 : tmp = extract_l( L_tmp );
151 155 : alfa = s_max( tmp, 3277 /* 0.1 in Q15 */ ); /*Q15 */
152 155 : L_WB_fenv1 = Mult_32_16( L_WB_fenv1, alfa ); /*2*Q_syn+15-15->2*Q_syn */
153 : }
154 :
155 4783 : if ( L_WB_fenv0 == 0 )
156 : {
157 0 : L_WB_fenv0 = L_deposit_l( 1 );
158 : }
159 :
160 4783 : if ( L_WB_fenv1 == 0 )
161 : {
162 0 : L_WB_fenv1 = L_deposit_l( 1 );
163 : }
164 :
165 4783 : if ( enerL == 0 )
166 : {
167 0 : enerL = L_deposit_l( 1 );
168 : }
169 :
170 4783 : L_tmp = L_add_sat( L_WB_fenv0, L_WB_fenv1 ); /* In 2*Q_syn */
171 4783 : exp = norm_l( L_tmp );
172 4783 : tmp = extract_h( L_shl( L_tmp, exp ) );
173 : /*exp = sub(exp, 30-(2*Q_syn+6)); //+6(/64) */
174 4783 : exp = sub( exp, sub( 30, add( shl( Q_syn, 1 ), 6 ) ) ); /*+6(/64) */
175 :
176 4783 : tmp = div_s( 16384, tmp );
177 4783 : L_tmp = L_deposit_h( tmp );
178 4783 : L_tmp = Isqrt_lc( L_tmp, &exp );
179 :
180 4783 : WB_fenv[0] = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /* Q3 */
181 4783 : move16();
182 4783 : test();
183 4783 : test();
184 4783 : IF( NE_16( coder_type, AUDIO ) && NE_16( coder_type, UNVOICED ) && ener_var_flag == 0 )
185 : {
186 357 : WB_fenv[0] = add_sat( WB_fenv[0], mult_r_sat( WB_fenv[0], 16384 /* 0.5 in Q15 */ ) );
187 357 : move16();
188 : }
189 :
190 4783 : exp = norm_l( enerL );
191 4783 : tmp = extract_h( L_shl( enerL, exp ) );
192 4783 : exp = sub( exp, sub( 30, shl( Q_syn, 1 ) ) );
193 :
194 4783 : tmp = div_s( 16384, tmp );
195 4783 : L_tmp = L_deposit_h( tmp );
196 4783 : L_tmp = Isqrt_lc( L_tmp, &exp );
197 4783 : enerL_16 = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 15 ) ) ); /* Q0 */
198 4783 : enerL_40 = mult_r( 6554 /* 0.2 in Q15 */, enerL_16 ); /*1/40 in Q18 ->Q3 */
199 :
200 4783 : test();
201 4783 : test();
202 4783 : test();
203 4783 : test();
204 4783 : test();
205 4783 : test();
206 4783 : IF( NE_16( coder_type, TRANSITION ) && NE_16( coder_type, AUDIO ) && NE_16( coder_type, UNVOICED ) &&
207 : GT_16( enerL_40, WB_fenv[0] ) && GT_16( alfa, 29491 /*0.9 in Q15*/ ) && !( EQ_16( coder_type, prev_coder_type ) && GT_16( WB_fenv[0], prev_WB_fenv ) ) )
208 : {
209 0 : IF( WB_fenv[0] != 0 )
210 : {
211 0 : exp = norm_s( WB_fenv[0] );
212 0 : tmp = div_s( shl( 1, sub( 14, exp ) ), WB_fenv[0] ); /*Q(29-exp-3) */
213 0 : L_tmp = L_mult( enerL_40, tmp ); /*Q(30-exp) */
214 0 : tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 2 ) ) ); /*Q12 */
215 0 : tmp = s_min( tmp, 16384 /*4 in Q12*/ );
216 0 : L_tmp = L_shr( L_mult0( tmp, WB_fenv[0] ), 12 ); /*Q15 */
217 0 : WB_fenv[0] = extract_l( L_tmp ); /*Q3 */
218 0 : move16();
219 : }
220 :
221 0 : IF( GT_16( WB_fenv[0], prev_WB_fenv ) )
222 : {
223 : /*WB_fenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv)); move16();//Q3 */
224 0 : WB_fenv[0] = round_fx( L_mac( L_mult( 9830 /* 0.5 in Q15 */, WB_fenv[0] ), 22938 /* 0.7 in Q15 */, prev_WB_fenv ) ); /*Q3 */
225 0 : move16();
226 : }
227 : }
228 :
229 4783 : L_tmp = L_mult0( voice_factor, 77 );
230 4783 : tmp1 = extract_l( L_shr( L_tmp, 13 ) );
231 :
232 4783 : exp = norm_s( pitch );
233 4783 : tmp = div_s( shl( 1, sub( 14, exp ) ), pitch ); /*Q(29-exp-5) */
234 4783 : L_tmp = L_mult0( tmp1, tmp ); /*29-exp-5->24-exp */
235 4783 : tmp = round_fx_sat( L_shl_sat( L_tmp, add( exp, 6 ) ) ); /*14 */
236 4783 : tmp1 = s_max( tmp, 8192 /* 0.5 in Q14 */ );
237 4783 : alfa = s_min( 24576 /* 1.5 in Q14 */, tmp1 ); /*Q14 */
238 :
239 4783 : L_tmp = L_mult0( alfa, WB_fenv[0] ); /*Q14+Q3->Q17 */
240 4783 : L_tmp = L_shr( L_tmp, 14 ); /*Q3 */
241 4783 : tmp = extract_l( L_tmp );
242 :
243 4783 : enerL = L_deposit_l( enerL_16 );
244 4783 : enerL = L_shl( enerL, 6 ); /*Q6 */
245 4783 : tmp1 = i_mult_sat( 3, WB_fenv[0] ); /*Q3 */
246 4783 : L_tmp = L_mult0( tmp1, WB_fenv[0] ); /*Q6 */
247 :
248 4783 : test();
249 4783 : test();
250 4783 : test();
251 4783 : IF( GT_16( shr( enerL_16, 3 ), tmp ) && GT_32( enerL, L_tmp ) && NE_16( prev_coder_type, UNVOICED ) && WB_fenv[0] != 0 )
252 : {
253 27 : env_var_flag = 1;
254 27 : move16();
255 27 : enerL_64 = mult_r( 4096, enerL_16 ); /* 1/64 in Q18 ->Q3 */
256 :
257 27 : exp = norm_s( WB_fenv[0] );
258 27 : tmp = div_s( shl( 1, sub( 14, exp ) ), WB_fenv[0] ); /*Q(29-exp-3) */
259 27 : L_tmp = L_mult( enerL_64, tmp ); /*Q(30-exp) */
260 27 : tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 2 ) ) ); /*Q12 */
261 27 : tmp = s_min( tmp, 16384 /*4 in Q12*/ );
262 27 : L_tmp = L_shr( L_mult0( tmp, WB_fenv[0] ), 12 ); /*Q3 */
263 27 : WB_fenv[0] = extract_l( L_tmp ); /*Q3 */
264 27 : move16();
265 27 : IF( GT_16( WB_fenv[0], prev_WB_fenv ) )
266 : {
267 : /*WB_fenv[0] = add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv));//Q3 */
268 25 : WB_fenv[0] = round_fx( L_mac( L_mult( 9830 /* 0.3 in Q15 */, WB_fenv[0] ), 22938 /* 0.7 in Q15 */, prev_WB_fenv ) ); /*Q3 */
269 25 : move16();
270 : }
271 : }
272 :
273 4783 : test();
274 4783 : IF( EQ_16( coder_type, UNVOICED ) || EQ_16( prev_coder_type, UNVOICED ) )
275 : {
276 35 : WB_fenv[0] = shr( WB_fenv[0], 1 );
277 35 : move16(); /*Q3 */
278 : }
279 :
280 4783 : IF( NE_16( coder_type, AUDIO ) )
281 : {
282 4783 : tmp = mult_r( voice_factor, 19661 /* 1.2 in Q14 */ ); /*Q12 */
283 4783 : tmp = s_max( tmp, 4096 /* 1 in Q12 */ );
284 4783 : exp = norm_s( tmp );
285 4783 : tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /*Q(29-exp-12) */
286 4783 : L_tmp = L_mult( WB_fenv[0], tmp ); /*Q(21-exp) */
287 :
288 4783 : WB_fenv[0] = round_fx( L_shl( L_tmp, sub( exp, 2 ) ) ); /*Q3 */
289 4783 : move16();
290 4783 : tmp1 = mult_r( 328 /* (1/400) in Q17 */, pitch ); /*Q7 */
291 4783 : tmp = s_min( s_max( tmp1, 16 /* 0.125 in Q7 */ ), 256 /* 1 in Q7 */ ); /*Q7 */
292 4783 : L_tmp = L_shr( L_mult0( WB_fenv[0], tmp ), 7 ); /*Q3 */
293 : /*WB_fenv[0] = saturate(L_tmp); //Q3 */
294 4783 : WB_fenv[0] = round_fx_sat( L_shl_sat( L_tmp, 16 ) ); /*Q3 */
295 4783 : move16();
296 : }
297 4783 : test();
298 4783 : IF( GT_32( last_core_brate, ACELP_8k00 ) && GT_16( WB_fenv[0], last_wb_bwe_ener ) )
299 : {
300 : /*WB_fenv[0]= add(mult_r(29491, last_wb_bwe_ener), mult_r(3277, WB_fenv[0]));//Q3 */
301 721 : WB_fenv[0] = round_fx( L_mac( L_mult( 29491 /* 0.9 in Q15 */, last_wb_bwe_ener ), 3277, WB_fenv[0] ) ); /*Q3 */
302 721 : move16();
303 : }
304 :
305 4783 : IF( NE_16( last_extl_fx, WB_BWE ) && LT_16( tilt_wb_fx, 128 /* 8 in Q4 */ ) )
306 : {
307 32 : WB_fenv[0] = mult_r( s_min( 16384 /* 0.5 in Q15 */, shl( tilt_wb_fx, 8 ) ), WB_fenv[0] );
308 32 : move16();
309 : }
310 :
311 4783 : IF( EQ_16( env_var_flag, 1 ) )
312 : {
313 27 : WB_fenv[1] = add( WB_fenv[0], mult_r( WB_fenv[0], 16384 /* 0.5 in Q15 */ ) );
314 27 : move16();
315 27 : WB_fenv[0] = mult_r( 24576 /* 0.75 in Q15 */, WB_fenv[0] );
316 27 : move16(); /*Q3 */
317 : }
318 : ELSE
319 : {
320 4756 : WB_fenv[1] = WB_fenv[0];
321 4756 : move16();
322 : }
323 :
324 4783 : test();
325 4783 : IF( EQ_16( coder_type, UNVOICED ) || EQ_16( prev_coder_type, UNVOICED ) )
326 : {
327 35 : WB_fenv[1] = shr( WB_fenv[1], 1 );
328 35 : move16(); /*Q3 */
329 : }
330 :
331 4783 : return ( mode );
332 : }
333 :
334 : /*-------------------------------------------------------------------*
335 : * calc_norm_envelop_lf_fx()
336 : *
337 : * calc_envelope of low frequency spectrum
338 : *-------------------------------------------------------------------*/
339 2789 : static void calc_norm_envelop_lf_fx(
340 : const Word32 SWB_signal[],
341 : /* i : SWB spectrum */ /* Q12 */
342 : Word32 *envelope,
343 : /* o : normalized envelope */ /* Q12 */
344 : Word16 *L_swb_norm, /* i/o : length of envelope */
345 : const Word16 HQ_mode,
346 : /* i : HQ mode */ /* Q0 */
347 : const Word16 hq_generic_offset,
348 : /* i : frequency offset for representing hq generic */ /* Q0 */
349 : Word16 *sfreq, /* i : starting frequency index */
350 : Word16 *efreq /* i : ending frequency index */
351 : )
352 : {
353 : Word16 lookback, env_index, n_freq, n_lag_now, n_lag;
354 :
355 2789 : *sfreq = 2;
356 2789 : move16();
357 2789 : IF( EQ_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) )
358 : {
359 2789 : *efreq = 146;
360 2789 : move16();
361 2789 : if ( EQ_16( HQ_mode, HQ_GEN_FB ) )
362 : {
363 2070 : *efreq = 306;
364 2070 : move16();
365 : }
366 2789 : IF( LT_16( add( shl( sub( 328, *efreq ), 1 ), 1 ), *L_swb_norm ) )
367 : {
368 38 : *L_swb_norm = add( shl( sub( 328, *efreq ), 1 ), 1 );
369 38 : move16();
370 : }
371 : }
372 : ELSE
373 : {
374 0 : *efreq = 130;
375 0 : move16();
376 0 : if ( EQ_16( HQ_mode, HQ_GEN_FB ) )
377 : {
378 0 : *efreq = 290;
379 0 : move16();
380 : }
381 0 : IF( LT_16( add( shl( sub( 400, *efreq ), 1 ), 1 ), *L_swb_norm ) )
382 : {
383 0 : *L_swb_norm = add( shl( sub( 400, *efreq ), 1 ), 1 );
384 : }
385 : }
386 2789 : lookback = shr( *L_swb_norm, 1 );
387 2789 : env_index = 0;
388 2789 : move16();
389 2789 : n_lag_now = *L_swb_norm;
390 2789 : move16();
391 :
392 19313 : FOR( n_freq = 0; n_freq < lookback; n_freq++ )
393 : {
394 : Word16 tmp;
395 : Word32 L_tmp;
396 :
397 16524 : L_tmp = L_deposit_l( 1 );
398 16524 : tmp = add( lookback, n_freq );
399 276954 : FOR( n_lag = 0; n_lag < tmp; n_lag++ )
400 : {
401 260430 : L_tmp = L_add_sat( L_tmp, L_abs( SWB_signal[n_lag] ) );
402 : }
403 16524 : envelope[env_index] = L_tmp;
404 16524 : move32();
405 16524 : env_index = add( env_index, 1 );
406 : }
407 :
408 724659 : FOR( ; n_freq < *efreq; n_freq++ )
409 : {
410 : /* Apply MA filter */
411 721870 : Word32 L_tmp = L_deposit_l( 1 );
412 9126864 : FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ )
413 : {
414 8404994 : L_tmp = L_add_sat( L_tmp, L_abs( SWB_signal[n_freq - lookback + n_lag] ) );
415 : }
416 :
417 721870 : envelope[env_index] = L_tmp;
418 721870 : move32();
419 721870 : env_index = add( env_index, 1 );
420 : }
421 :
422 2789 : return;
423 : }
424 : /*-------------------------------------------------------------------*
425 : * calc_normal_length()
426 : *
427 : *-------------------------------------------------------------------*/
428 :
429 37098 : void calc_normal_length_fx(
430 : const Word16 core, /* i : core */
431 : const Word16 *sp, /* i : input signal Q_syn */
432 : const Word16 mode, /* i : input mode */
433 : const Word16 extl, /* i : extension layer */
434 : Word16 *L_swb_norm, /* o : normalize length */
435 : Word16 *prev_L_swb_norm, /*i/o : last normalize length */
436 : Word16 Q_syn )
437 : {
438 : Word16 i, n_freq, n_band, THRES;
439 : const Word16 *pit;
440 : Word16 peak, mag;
441 : Word16 L_swb_norm_trans, L_swb_norm_norm, L_swb_norm_harm, L_swb_norm_cur;
442 : Word16 N;
443 : Word32 L_mean, L_tmp, L_tmp1;
444 :
445 37098 : THRES = 4;
446 37098 : move16();
447 37098 : test();
448 37098 : test();
449 37098 : if ( EQ_16( core, HQ_CORE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) )
450 : {
451 21310 : THRES = 8;
452 21310 : move16();
453 : }
454 :
455 37098 : N = 16;
456 37098 : move16();
457 37098 : test();
458 37098 : test();
459 37098 : if ( EQ_16( core, HQ_CORE ) && ( EQ_16( mode, HQ_HARMONIC ) || EQ_16( mode, HQ_HVQ ) ) )
460 : {
461 0 : N = 13;
462 0 : move16();
463 : }
464 :
465 37098 : n_band = 0;
466 37098 : move16();
467 37098 : pit = sp;
468 630666 : FOR( i = 0; i < N; i++ )
469 : {
470 593568 : peak = 0;
471 593568 : move16();
472 593568 : L_mean = L_deposit_l( 0 );
473 :
474 10090656 : FOR( n_freq = 0; n_freq < 16; n_freq++ )
475 : {
476 9497088 : mag = abs_s( *pit );
477 :
478 9497088 : peak = s_max( peak, mag );
479 9497088 : L_mean = L_add( L_mean, mag ); /*Q_syn */
480 9497088 : pit++;
481 : }
482 :
483 593568 : L_tmp = L_mult0( peak, 15 + THRES ); /*Q_syn */
484 593568 : IF( EQ_16( THRES, 8 ) )
485 : {
486 340960 : L_tmp1 = L_shl( Mpy_32_16_1( L_mean, 32767 ), 3 );
487 : }
488 : ELSE
489 : {
490 252608 : L_tmp1 = L_shl( Mpy_32_16_1( L_mean, 32767 ), 2 );
491 : }
492 :
493 593568 : test();
494 593568 : if ( GT_32( L_tmp, L_tmp1 ) && ( GT_16( peak, shl( 10, Q_syn ) ) ) )
495 : {
496 82429 : n_band = add( 1, n_band );
497 : }
498 : }
499 :
500 37098 : IF( EQ_16( core, ACELP_CORE ) )
501 : {
502 37098 : L_swb_norm_trans = add( 4, mult( n_band, 8192 /* 0.25 in Q15 */ ) );
503 37098 : L_swb_norm_norm = add( 8, mult( n_band, 16384 /* 0.5 in Q15 */ ) );
504 :
505 37098 : L_tmp = L_add( 65536, L_mult0( n_band, 4096 ) ); /*Q16 */
506 37098 : L_swb_norm_harm = s_max( round_fx( L_shl( L_tmp, 5 ) ), 24 ); /* Q0 */
507 :
508 37098 : IF( EQ_16( mode, HARMONIC ) )
509 : {
510 3427 : L_swb_norm_cur = L_swb_norm_harm;
511 3427 : move16();
512 : }
513 33671 : ELSE IF( EQ_16( mode, NORMAL ) )
514 : {
515 32034 : L_swb_norm_cur = L_swb_norm_norm;
516 32034 : move16();
517 : }
518 : ELSE
519 : {
520 1637 : L_swb_norm_cur = L_swb_norm_trans;
521 1637 : move16();
522 : }
523 37098 : *L_swb_norm = shr( add( L_swb_norm_cur, *prev_L_swb_norm ), 1 );
524 37098 : move16();
525 37098 : *prev_L_swb_norm = L_swb_norm_cur;
526 37098 : move16();
527 : }
528 : ELSE
529 : {
530 0 : test();
531 0 : IF( EQ_16( mode, HQ_HARMONIC ) || EQ_16( mode, HQ_HVQ ) )
532 : {
533 0 : L_tmp = L_add( 65536, L_mult( n_band, 2560 /* 2.5 in Q10*/ ) );
534 0 : L_swb_norm_cur = round_fx( L_shl( L_tmp, 5 ) ); /*Q0 */
535 : }
536 : ELSE
537 : {
538 0 : L_tmp = L_add( 65536, L_mult( n_band, 2048 ) ); /*Q16 */
539 0 : L_swb_norm_cur = round_fx( L_shl( L_tmp, 3 ) ); /*Q0 */
540 : }
541 :
542 : /**L_swb_norm = add(mult_r(L_swb_norm_cur, 3277), mult_r(*prev_L_swb_norm, 29491)); */
543 0 : *L_swb_norm = round_fx( L_mac( L_mult( L_swb_norm_cur, 3277 /* 0.1 in Q15 */ ), *prev_L_swb_norm, 29491 /* 0.9 in Q15 */ ) );
544 0 : move16();
545 0 : *prev_L_swb_norm = L_swb_norm_cur;
546 0 : move16();
547 : }
548 :
549 37098 : return;
550 : }
551 : /*-------------------------------------------------------------------*
552 : * calc_tilt_bwe()
553 : *
554 : * calculate tilt parameter
555 : *-------------------------------------------------------------------*/
556 :
557 181537 : Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */
558 : const Word16 *sp, /* i : input signal Q(15 - exp_sp) */
559 : const Word16 exp_sp, /* i : Exp of inp signal */
560 : const Word16 N /* i : signal length */
561 : )
562 : {
563 : Word16 i, j;
564 : Word32 L_ener, L_ener_tot, L_temp;
565 : Word16 tmp1, tmp2;
566 : const Word16 *ptr;
567 : Word16 exp2;
568 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
569 181537 : Flag Overflow = 0;
570 181537 : move32();
571 : #endif
572 :
573 : BASOP_SATURATE_WARNING_OFF_EVS
574 :
575 : /* this is required for adaptative precision energy summation loop, do not remove */
576 181537 : Overflow = 0;
577 181537 : move16();
578 181537 : exp2 = 0;
579 181537 : move16();
580 :
581 181537 : ptr = sp;
582 181537 : move16();
583 181537 : L_ener_tot = L_deposit_l( 1 );
584 :
585 : /* Divide Frame Length by 32 */
586 1943823 : FOR( j = shr( N, 5 ); j > 0; j-- )
587 : {
588 1762286 : tmp1 = mult_ro( *ptr++, 8192 /*0.25 in Q15 */, &Overflow ); /* Divide by 4 */
589 1762286 : L_ener = L_mult0( tmp1, tmp1 );
590 : /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */
591 56393152 : FOR( i = 1; i < 32; i++ )
592 : {
593 54630866 : tmp1 = mult_ro( *ptr++, 8192 /*0.25 in Q15 */, &Overflow ); /* Divide by 4 */
594 54630866 : L_ener = L_mac0_o( L_ener, tmp1, tmp1, &Overflow );
595 : }
596 1762286 : L_ener = L_shr_o( L_ener, exp2, &Overflow );
597 1762286 : L_temp = L_add_o( L_ener_tot, L_ener, &Overflow );
598 1762286 : IF( Overflow != 0 )
599 : {
600 33 : L_ener_tot = L_shr( L_ener_tot, 1 );
601 33 : L_ener = L_shr( L_ener, 1 );
602 33 : exp2 = add( exp2, 1 );
603 : /* this is required, do not remove */
604 33 : Overflow = 0;
605 33 : move16();
606 : }
607 1762286 : L_ener_tot = L_add_o( L_ener_tot, L_ener, &Overflow );
608 : }
609 181537 : L_ener = L_deposit_l( abs_s( sub_o( sp[1], sp[0], &Overflow ) ) );
610 56211615 : FOR( i = 2; i < N; i++ )
611 : {
612 : /* Eq to (sp[i] - sp[i-1]) * (sp[i-1] - sp[i-2]) < 0 */
613 56030078 : tmp1 = sub_o( sp[i], sp[i - 1], &Overflow );
614 56030078 : tmp2 = sub_o( sp[i - 1], sp[i - 2], &Overflow );
615 56030078 : tmp2 = mult( tmp1, tmp2 );
616 56030078 : tmp1 = abs_s( tmp1 );
617 : /* to Get either 0 or -1 in 'tmp2' */
618 56030078 : tmp2 = shr( tmp2, 15 );
619 : /* this allows this code */
620 56030078 : L_ener = L_msu0( L_ener, tmp2, tmp1 );
621 : /* instead of this one */
622 : /* test(); */
623 : /* if (tmp2 < 0) */
624 : /* { */
625 : /* L_ener = L_mac0(L_ener, 1, tmp1); */
626 : /* } */
627 : /* it saves one op */
628 : }
629 :
630 181537 : tmp1 = norm_l( L_ener_tot );
631 181537 : L_temp = L_shl( L_ener_tot, tmp1 );
632 181537 : tmp1 = sub( add( 31 + 4, exp2 ), add( tmp1, shl( exp_sp, 1 ) ) );
633 181537 : L_temp = Isqrt_lc( L_temp, &tmp1 );
634 :
635 : /* *tilt_flt = (float)(r1/sqrt(r0)); */
636 181537 : exp2 = norm_l( L_ener );
637 181537 : L_temp = Mult_32_16( L_temp, round_fx_sat( L_shl_sat( L_ener, exp2 ) ) );
638 181537 : exp2 = sub( exp2, tmp1 );
639 181537 : exp2 = add( exp2, exp_sp );
640 :
641 : /* Put in Q24 */
642 181537 : L_temp = L_shr_sat( L_temp, sub( exp2, 24 ) );
643 : BASOP_SATURATE_WARNING_ON_EVS
644 :
645 181537 : return L_temp;
646 : }
647 173965 : Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */
648 : const Word32 *sp, /* i : input signal */
649 : const Word16 exp_sp, /* i : Exp of inp signal Q(15 - exp_sp) */
650 : const Word16 N /* i : signal length */
651 : )
652 : {
653 : Word16 i, j;
654 : Word32 L_ener, L_ener_tot, L_temp;
655 : Word32 tmp1, tmp2;
656 173965 : Word16 sign = 0;
657 173965 : move16();
658 : const Word32 *ptr;
659 : Word16 exp2, tmp_exp;
660 :
661 : BASOP_SATURATE_WARNING_OFF_EVS
662 :
663 : /* this is required for adaptative precision energy summation loop, do not remove */
664 173965 : exp2 = 0;
665 173965 : move16();
666 173965 : ptr = sp;
667 :
668 173965 : L_ener_tot = L_deposit_l( 1 );
669 : /* Divide Frame Length by 32 */
670 : Word64 W_ener;
671 173965 : W_ener = Mpy_32_32( *ptr, *ptr );
672 173965 : ptr++;
673 111337600 : FOR( j = 1; j < N; j++ )
674 : {
675 : /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */
676 111163635 : W_ener = W_mac_32_32( W_ener, *ptr, *ptr );
677 111163635 : ptr++;
678 : }
679 173965 : L_ener_tot = W_round64_L( W_ener );
680 173965 : L_ener_tot = L_max( L_ener_tot, 1 ); /* L_ener_tot is energy, it is always positive, but have to be > 0 for the following division */
681 173965 : L_ener = L_abs( L_sub( sp[1], sp[0] ) );
682 :
683 111163635 : FOR( i = 2; i < N; i++ )
684 : {
685 : /* Eq to (sp[i] - sp[i-1]) * (sp[i-1] - sp[i-2]) < 0 */
686 110989670 : tmp1 = L_sub( sp[i], sp[i - 1] );
687 110989670 : tmp2 = L_sub( sp[i - 1], sp[i - 2] );
688 :
689 110989670 : tmp2 = Mpy_32_32( tmp1, tmp2 );
690 110989670 : tmp1 = L_abs( tmp1 );
691 : /* to Get either 0 or -1 in 'tmp2' */
692 110989670 : tmp2 = L_shr( tmp2, 31 );
693 110989670 : sign = extract_l( L_shl( tmp2, Q15 ) );
694 : /* this allows this code */
695 110989670 : L_ener = Msub_32_16( L_ener, tmp1, sign );
696 : /* instead of this one */
697 : /* test(); */
698 : /* if (tmp2 < 0) */
699 : /* { */
700 : /* L_ener = L_mac0(L_ener, 1, tmp1); */
701 : /* } */
702 : /* it saves one op */
703 : }
704 :
705 173965 : L_temp = L_ener_tot;
706 173965 : move32();
707 173965 : tmp_exp = sub( Q31, sub( shl( exp_sp, 1 ), Q31 ) );
708 173965 : L_temp = Sqrt32( L_temp, &tmp_exp );
709 173965 : L_temp = L_shl( L_temp, sub( exp_sp, sub( Q31, tmp_exp ) ) );
710 :
711 : /* *tilt_flt = (float)(r1/sqrt(r0)); */
712 173965 : L_temp = L_deposit_l( BASOP_Util_Divide3232_Scale( L_ener, L_temp, &exp2 ) );
713 173965 : IF( GT_16( sub( exp2, 4 ), norm_l( L_temp ) ) )
714 : {
715 13692 : L_temp = MAX_16;
716 13692 : move32();
717 : }
718 : ELSE
719 : {
720 160273 : L_temp = L_shl( L_temp, sub( exp2, 4 ) ); // Output is expected in Q11
721 : }
722 : BASOP_SATURATE_WARNING_ON_EVS
723 173965 : return extract_h( L_shl_sat( L_temp, 16 ) );
724 : }
725 :
726 : /*-------------------------------------------------------------------*
727 : * calc_norm_envelop()
728 : *
729 : * calculate normalized parameter
730 : *-------------------------------------------------------------------*/
731 :
732 36303 : void calc_norm_envelop_fx(
733 : const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/
734 : Word32 *envelope, /* o : normalized envelope Q_syn*/
735 : const Word16 L_swb_norm, /* i : length of envelope Q0 */
736 : const Word16 SWB_flength, /* i : Length of input/output */
737 : const Word16 st_offset /* i : offset */
738 : )
739 : {
740 : Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp;
741 :
742 36303 : lookback = shr( L_swb_norm, 1 );
743 36303 : env_index = add( swb_bwe_subband[0], st_offset );
744 36303 : n_lag_now = L_swb_norm;
745 36303 : move16();
746 36303 : tmp = sub( add( SWB_flength, st_offset ), L_swb_norm );
747 8298167 : FOR( n_freq = sub( add( swb_bwe_trans_subband[0], st_offset ), lookback ); n_freq < tmp; n_freq++ )
748 : {
749 : /* Apply MA filter */
750 8261864 : Word32 L_tmp = L_deposit_l( 0 );
751 85726481 : FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ )
752 : {
753 77464617 : L_tmp = L_add( L_tmp, abs_s( SWB_signal[n_freq + n_lag] ) );
754 : }
755 8261864 : envelope[env_index] = L_tmp;
756 8261864 : move32();
757 8261864 : env_index++;
758 : }
759 :
760 36303 : i = 0;
761 36303 : move16();
762 36303 : tmp = sub( add( SWB_flength, st_offset ), lookback );
763 260359 : FOR( n_freq = sub( add( SWB_flength, st_offset ), L_swb_norm ); n_freq < tmp; n_freq++ )
764 : {
765 : Word32 L_tmp;
766 :
767 224056 : n_lag_now = sub( L_swb_norm, i );
768 : /* Apply MA filter */
769 224056 : L_tmp = L_deposit_l( 0 );
770 4348395 : FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ )
771 : {
772 4124339 : L_tmp = L_add( L_tmp, abs_s( SWB_signal[n_freq + n_lag] ) );
773 : }
774 224056 : envelope[env_index] = L_tmp;
775 224056 : move32();
776 224056 : env_index++;
777 224056 : i = add( i, 1 );
778 : }
779 :
780 36303 : return;
781 : }
782 :
783 : /*==========================================================================*/
784 : /* FUNCTION : void WB_BWE_decoding_fx () */
785 : /*--------------------------------------------------------------------------*/
786 : /* PURPOSE : WB BWE decoder */
787 : /*--------------------------------------------------------------------------*/
788 : /* INPUT ARGUMENTS : */
789 : /* _Word16 *core_dec_freq i : Frequency domain core decoded signal Q_syn*/
790 : /* _Word16 *WB_fenv i : WB frequency envelopes Q3 */
791 : /* _Word16 WB_flength i : Length of input/output */
792 : /* _Word16 mode i : classification for WB signal */
793 : /* _Word16 prev_mode i : classification for last frame */
794 : /* _Word16 last_extl i : extl. layer for last frame */
795 : /* _Word16 extl i : extension layer */
796 : /* _Word16 coder_type i : coding type */
797 : /* _Word16 total_brate i : core layer bitrate */
798 : /* _Word16 prev_coder_type i : coding type of last frame */
799 : /* _Word16 Q_syn i : Q format */
800 : /*--------------------------------------------------------------------------*/
801 : /* OUTPUT ARGUMENTS : */
802 : /* _Word16 *WB_signal, o : WB signal in MDCT domain Q_syn */
803 : /*--------------------------------------------------------------------------*/
804 : /* INPUT/OUTPUT ARGUMENTS : */
805 : /* _Word32 *prev_Energy, i/o: energy for last frame Q_syn */
806 : /* _Word16 *prev_WB_fenv, i/o: envelope for last frame Q3 */
807 : /* _Word16 *prev_L_wb_norm, i/o: length for last frame wb norm Q0 */
808 : /* _Word16 *Seed, i/o: random generator seed Q15 */
809 : /* _Word16 *prev_flag, i/o: attenu flag of last frame Q0 */
810 : /*--------------------------------------------------------------------------*/
811 : /* RETURN ARGUMENTS : */
812 : /* _ None */
813 : /*--------------------------------------------------------------------------*/
814 : /* CALLED FROM : */
815 : /*==========================================================================*/
816 8889 : void WB_BWE_decoding_fx(
817 : const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */
818 : Word16 *WB_fenv, /* i : WB frequency envelopes */
819 : Word32 *WB_signal_32, /* o : WB signal in MDCT domain */
820 : const Word16 WB_flength, /* i : Length of input/output */
821 : const Word16 mode, /* i : classification for WB signal */
822 : const Word16 last_extl, /* i : extl. layer for last frame */
823 : Word32 *prev_Energy, /* i/o: energy for last frame */
824 : Word16 *prev_WB_fenv, /* i/o: envelope for last frame */
825 : Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */
826 : const Word16 extl, /* i : extension layer */
827 : const Word16 coder_type, /* i : coding type */
828 : const Word32 total_brate, /* i : core layer bitrate */
829 : Word16 *Seed, /* i/o: random generator seed */
830 : Word16 *prev_flag, /* i/o: attenu flag of last frame */
831 : Word16 prev_coder_type, /* i : coding type of last frame */
832 : Word16 Q_syn,
833 : Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */
834 : )
835 : {
836 : Word16 n_freq, n_band;
837 : Word16 i, L;
838 : Word32 envelope[L_FRAME16k];
839 : Word32 energy, EnergyL;
840 : Word32 *pit1;
841 : Word16 WB_signal[L_FRAME16k];
842 : Word16 L_wb_norm, wfenv[2];
843 : Word16 alfa, beta;
844 8889 : Word16 flag = 0;
845 8889 : Word16 core_type = 1;
846 8889 : move16();
847 8889 : move16();
848 : Word16 tmp, tmp1, exp, tmp2;
849 : Word32 L_tmp, L_tmp1, L_tmp2;
850 : Word32 prev_ener_alpha, prev_ener_beta;
851 : Word16 signum[L_FRAME16k];
852 : Word16 inv_L_wb_norm, weight;
853 :
854 8889 : calc_normal_length_fx( ACELP_CORE, core_dec_freq, mode, extl, &L_wb_norm, prev_L_wb_norm, Q_syn );
855 8889 : set32_fx( WB_signal_32, 0, L_FRAME16k );
856 8889 : set16_fx( WB_signal, 0, L_FRAME16k );
857 :
858 : /* copy excitation */
859 8889 : test();
860 8889 : if ( NE_16( coder_type, AUDIO ) && LE_32( total_brate, ACELP_8k00 ) )
861 : {
862 4083 : core_type = 0;
863 4083 : move16();
864 : }
865 :
866 8889 : IF( core_type == 0 )
867 : {
868 4083 : Copy( &core_dec_freq[160], &WB_signal[240], 80 );
869 : }
870 : ELSE
871 : {
872 4806 : Copy( &core_dec_freq[80], &WB_signal[240], 80 );
873 : }
874 :
875 : /* calculate envelope */
876 8889 : calc_norm_envelop_fx( WB_signal, envelope, L_wb_norm, WB_flength, 0 );
877 8889 : test();
878 8889 : IF( coder_type != UNVOICED && total_brate <= ACELP_8k00 )
879 : {
880 7748 : exp = norm_s( L_wb_norm );
881 7748 : inv_L_wb_norm = shl( div_s( shl( 1, sub( 14, exp ) ), L_wb_norm ), sub( exp, 14 ) ); /* Q(15) */
882 7748 : IF( NE_16( mode, HARMONIC ) )
883 : {
884 6282 : tmp = add( shl( inv_L_wb_norm, 1 ), inv_L_wb_norm );
885 6282 : weight = s_max( s_min( tmp, 16384 /* 0.5 in Q15 */ ), 8192 /*0.25 in Q15 */ );
886 : }
887 : ELSE
888 : {
889 1466 : weight = 8192; /*0.25 in Q15 */
890 1466 : move16();
891 : }
892 627588 : FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++ )
893 : {
894 619840 : signum[n_freq] = 1;
895 619840 : move16();
896 619840 : IF( WB_signal[n_freq] < 0 )
897 : {
898 309595 : signum[n_freq] = -1;
899 309595 : move16();
900 309595 : WB_signal[n_freq] = negate( WB_signal[n_freq] );
901 309595 : move16();
902 : }
903 619840 : L_tmp = Mult_32_16( envelope[n_freq], inv_L_wb_norm ); /* Q_syn */
904 619840 : L_tmp = Mult_32_16( L_tmp, 14746 ); /* Q_syn */
905 619840 : L_tmp1 = L_deposit_l( WB_signal[n_freq] ); /* Q_syn */
906 619840 : L_tmp = L_sub( L_tmp1, L_tmp ); /* Q_syn */
907 619840 : WB_signal[n_freq] = extract_l( L_tmp ); /* Q_syn */
908 619840 : move16();
909 619840 : IF( L_tmp > 0 )
910 : {
911 455187 : tmp = sub( 18022, weight ); /* Q15 */
912 455187 : WB_signal[n_freq] = extract_l( Mult_32_16( L_tmp, tmp ) ); /* Q_syn */
913 455187 : move16();
914 : }
915 :
916 619840 : IF( NE_16( signum[n_freq], 1 ) )
917 : {
918 309595 : WB_signal[n_freq] = negate( WB_signal[n_freq] );
919 309595 : move16();
920 : }
921 : }
922 : }
923 :
924 : /* Normalize with envelope */
925 720009 : FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++ )
926 : {
927 711120 : IF( envelope[n_freq] != 0 )
928 : {
929 711120 : exp = norm_l( envelope[n_freq] );
930 711120 : tmp = extract_h( L_shl( envelope[n_freq], exp ) );
931 711120 : exp = sub( sub( 30, exp ), Q_syn );
932 711120 : tmp = div_s( 16384, tmp );
933 711120 : L_tmp = L_shr( L_mult0( WB_signal[n_freq], tmp ), add( exp, Q_syn ) ); /*Q15 */
934 711120 : WB_signal[n_freq] = extract_l( L_tmp ); /*Q15 */
935 711120 : move16();
936 : }
937 : ELSE
938 : {
939 0 : WB_signal[n_freq] = shl( WB_signal[n_freq], sub( 15, Q_syn ) ); /*Q15 */
940 0 : move16();
941 : }
942 : }
943 :
944 8889 : L = 1;
945 8889 : move16();
946 8889 : if ( EQ_16( mode, HARMONIC ) )
947 : {
948 1468 : L = 4;
949 1468 : move16();
950 : }
951 :
952 8889 : IF( EQ_16( coder_type, UNVOICED ) )
953 : {
954 2430 : FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++ )
955 : {
956 2400 : *Seed = extract_l( L_mac0( 20101L, *Seed, 12345 ) );
957 2400 : L_tmp = L_shl( *Seed, add( Q_syn, 1 ) );
958 2400 : WB_signal_32[n_freq] = L_tmp;
959 2400 : move32();
960 : }
961 : }
962 : ELSE
963 : {
964 39891 : FOR( n_band = 0; n_band < 4; n_band += L )
965 : {
966 31032 : energy = L_deposit_l( 0 );
967 739752 : FOR( n_freq = swb_bwe_subband[n_band]; n_freq < swb_bwe_subband[n_band + L]; n_freq++ )
968 : {
969 708720 : L_tmp = L_mult0( WB_signal[n_freq], WB_signal[n_freq] ); /*Q30 */
970 708720 : energy = L_add( energy, L_shr( L_tmp, 5 ) ); /*Q25 */
971 : }
972 :
973 31032 : tmp = sub( swb_bwe_subband[n_band + L], swb_bwe_subband[n_band] );
974 31032 : tmp = div_s( 1, tmp ); /*Q15 */
975 31032 : energy = Mult_32_16( energy, tmp ); /*Q(15+25-15)->Q(25) */
976 :
977 31032 : exp = norm_l( energy );
978 31032 : L_tmp1 = L_shl( energy, exp );
979 31032 : exp = 31 - exp - ( 25 );
980 31032 : move16();
981 31032 : L_tmp1 = Isqrt_lc( L_tmp1, &exp ); /*Q(31-exp) */
982 :
983 739752 : FOR( n_freq = swb_bwe_subband[n_band]; n_freq < swb_bwe_subband[n_band + L]; n_freq++ )
984 : {
985 708720 : L_tmp2 = Mult_32_16( L_tmp1, WB_signal[n_freq] );
986 708720 : WB_signal_32[n_freq] = L_shl( L_tmp2, sub( add( exp, Q_syn ), 15 ) );
987 708720 : move32();
988 : }
989 : }
990 : }
991 :
992 8889 : EnergyL = L_deposit_l( 0 );
993 8889 : IF( EQ_16( core_type, 1 ) )
994 : {
995 4806 : test();
996 4806 : IF( NE_16( prev_coder_type, AUDIO ) && LE_32( total_brate, ACELP_8k00 ) )
997 : {
998 4860 : FOR( i = 160; i < 240; i++ )
999 : {
1000 4800 : EnergyL = L_add( abs_s( core_dec_freq[i] ), EnergyL );
1001 : }
1002 : }
1003 : ELSE
1004 : {
1005 764106 : FOR( i = 80; i < 240; i++ )
1006 : {
1007 759360 : EnergyL = L_add( abs_s( core_dec_freq[i] ), EnergyL );
1008 : }
1009 : }
1010 :
1011 4806 : IF( LE_32( total_brate, ACELP_8k00 ) )
1012 : {
1013 3677 : alfa = 26214;
1014 3677 : move16(); /*0.8f in Q15; */
1015 3677 : beta = 10240;
1016 3677 : move16(); /*1.25f in Q13; */
1017 : }
1018 : ELSE
1019 : {
1020 1129 : alfa = 16384;
1021 1129 : move16(); /* 0.5f in Q15; */
1022 1129 : beta = 16384;
1023 1129 : move16(); /*2.0f in Q13 */
1024 : }
1025 : }
1026 : ELSE
1027 : {
1028 4083 : IF( EQ_16( prev_coder_type, AUDIO ) )
1029 : {
1030 644 : FOR( i = 80; i < 240; i++ )
1031 : {
1032 640 : EnergyL = L_add( abs_s( core_dec_freq[i] ), EnergyL ); /*Q_syn */
1033 : }
1034 : }
1035 : ELSE
1036 : {
1037 330399 : FOR( i = 160; i < 240; i++ )
1038 : {
1039 326320 : EnergyL = L_add( abs_s( core_dec_freq[i] ), EnergyL );
1040 : }
1041 : }
1042 :
1043 4083 : test();
1044 4083 : IF( EQ_16( prev_coder_type, coder_type ) && GT_16( WB_fenv[0], prev_WB_fenv[0] ) )
1045 : {
1046 369 : alfa = 13107;
1047 369 : move16(); /*.4 in Q15 */
1048 369 : beta = 20480;
1049 369 : move16(); /*2.5 in Q13 */
1050 : }
1051 : ELSE
1052 : {
1053 3714 : alfa = 19661;
1054 3714 : move16(); /*.6 in Q15 */
1055 3714 : beta = 13681;
1056 3714 : move16(); /*1.67 in Q13 */
1057 : }
1058 :
1059 4083 : test();
1060 4083 : test();
1061 4083 : test();
1062 4083 : IF( EQ_16( coder_type, GENERIC ) || ( GT_32( EnergyL, L_shr( *prev_Energy, 1 ) ) && GT_32( *prev_Energy, L_shr( EnergyL, 1 ) ) && EQ_16( *prev_flag, 1 ) ) )
1063 : {
1064 56 : WB_fenv[0] = shr( WB_fenv[0], 1 );
1065 56 : move16();
1066 56 : WB_fenv[1] = shr( WB_fenv[1], 1 );
1067 56 : move16();
1068 56 : flag = 1;
1069 56 : move16();
1070 : }
1071 : }
1072 8889 : L_tmp1 = Mult_32_16( EnergyL, prev_WB_fenv[0] ); /*Qsyn+3-15 */
1073 8889 : L_tmp2 = Mult_32_16( *prev_Energy, WB_fenv[0] ); /*Q_syn+3-15 */
1074 8889 : prev_ener_alpha = Mult_32_16( *prev_Energy, alfa ); /*Q_syn+15-15->Q_syn */
1075 8889 : prev_ener_beta = L_shl( Mult_32_16( *prev_Energy, beta ), 2 ); /*Q_syn+13-15+2 ->Q_syn */
1076 :
1077 8889 : test();
1078 8889 : test();
1079 8889 : IF( ( EQ_16( mode, HARMONIC ) && GT_16( shr( WB_fenv[0], 2 ), WB_fenv[1] ) ) || EQ_16( mode, NORMAL ) )
1080 : {
1081 7445 : test();
1082 7445 : test();
1083 7445 : test();
1084 7445 : test();
1085 7445 : test();
1086 7445 : test();
1087 7445 : test();
1088 7445 : test();
1089 7445 : test();
1090 7445 : test();
1091 7445 : test();
1092 7445 : test();
1093 7445 : test();
1094 7445 : IF( EQ_16( last_extl, WB_BWE ) &&
1095 : ( ( EQ_16( prev_coder_type, AUDIO ) && NE_16( coder_type, AUDIO ) ) ||
1096 : ( NE_16( prev_coder_type, AUDIO ) && EQ_16( coder_type, AUDIO ) ) ) &&
1097 : LE_32( total_brate, ACELP_8k00 ) )
1098 : {
1099 8 : IF( GT_16( WB_fenv[0], prev_WB_fenv[0] ) )
1100 : {
1101 : /*wfenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv[0]));//Q3 */
1102 4 : wfenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv[0] ) ); /*Q3 */
1103 4 : move16();
1104 : /*wfenv[1]= add(mult_r(9830, WB_fenv[1]), mult_r(22938, prev_WB_fenv[1]));//Q3 */
1105 4 : wfenv[1] = round_fx( L_mac( L_mult( 9830, WB_fenv[1] ), 22938, prev_WB_fenv[1] ) ); /*Q3 */
1106 4 : move16();
1107 : }
1108 : ELSE
1109 : {
1110 : /*wfenv[0]= add(mult_r(16384,WB_fenv[0]),mult_r(16384,prev_WB_fenv[0]));//Q3 */
1111 4 : wfenv[0] = round_fx( L_mac( L_mult( 16384, WB_fenv[0] ), 16384, prev_WB_fenv[0] ) ); /*Q3 */
1112 4 : move16();
1113 : /*wfenv[1]= add(mult_r(13108,WB_fenv[1]),mult_r(13108,prev_WB_fenv[1]));//Q3 */
1114 4 : wfenv[1] = round_fx( L_mac( L_mult( 13108, WB_fenv[1] ), 13108, prev_WB_fenv[1] ) ); /*Q3 */
1115 4 : move16();
1116 : }
1117 : }
1118 7437 : ELSE IF( EQ_16( last_extl, WB_BWE ) && LT_32( L_tmp1, L_tmp2 ) && GT_16( WB_fenv[0], prev_WB_fenv[0] ) &&
1119 : NE_16( coder_type, AUDIO ) && NE_16( coder_type, UNVOICED ) && LE_32( total_brate, ACELP_8k00 ) )
1120 : {
1121 : /*wfenv[0]= add(mult_r(9830,WB_fenv[0]),mult_r(22938,prev_WB_fenv[0]));//Q3 */
1122 76 : wfenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv[0] ) ); /*Q3 */
1123 76 : move16();
1124 : /*wfenv[1]= add(mult_r(9830,WB_fenv[1]),mult_r(22938,prev_WB_fenv[1]));//Q3 */
1125 76 : wfenv[1] = round_fx( L_mac( L_mult( 9830, WB_fenv[1] ), 22938, prev_WB_fenv[1] ) ); /*Q3 */
1126 76 : move16();
1127 : }
1128 7361 : ELSE IF( EQ_16( last_extl, WB_BWE ) && GT_32( EnergyL, prev_ener_alpha ) && GT_32( prev_ener_beta, EnergyL ) &&
1129 : NE_16( prev_coder_type, UNVOICED ) )
1130 : {
1131 : /*wfenv[0] = add(shr(WB_fenv[0],1), shr(prev_WB_fenv[0],1));//Q3 */
1132 5963 : wfenv[0] = round_fx( L_mac( L_mult( WB_fenv[0], 16384 ), prev_WB_fenv[0], 16384 ) ); /*Q3 */
1133 5963 : move16();
1134 : /*wfenv[1] = add(shr(WB_fenv[1],1), shr(prev_WB_fenv[1],1));//Q3 */
1135 5963 : wfenv[1] = round_fx( L_mac( L_mult( WB_fenv[1], 16384 ), prev_WB_fenv[1], 16384 ) ); /*Q3 */
1136 5963 : move16();
1137 : }
1138 : ELSE
1139 : {
1140 1398 : wfenv[0] = WB_fenv[0];
1141 1398 : move16();
1142 1398 : wfenv[1] = WB_fenv[1];
1143 1398 : move16();
1144 : }
1145 305245 : FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[2]; n_freq++ )
1146 : {
1147 297800 : WB_signal_32[n_freq] = Mult_32_16( WB_signal_32[n_freq], wfenv[0] );
1148 297800 : move32(); /* Q_syn+3+1 */
1149 : }
1150 :
1151 305245 : FOR( n_freq = swb_bwe_subband[2]; n_freq < swb_bwe_subband[4]; n_freq++ )
1152 : {
1153 297800 : WB_signal_32[n_freq] = Mult_32_16( WB_signal_32[n_freq], wfenv[1] );
1154 297800 : move32(); /* Q_syn+3+1 */
1155 : }
1156 :
1157 7445 : prev_WB_fenv[0] = wfenv[0];
1158 7445 : move16();
1159 7445 : prev_WB_fenv[1] = wfenv[1];
1160 7445 : move16();
1161 : }
1162 : ELSE
1163 : {
1164 1444 : wfenv[0] = add( shr( WB_fenv[0], 1 ), shr( WB_fenv[1], 1 ) ); /*Q3 */
1165 :
1166 1444 : test();
1167 1444 : test();
1168 1444 : IF( EQ_16( last_extl, WB_BWE ) && GT_32( EnergyL, L_shr( *prev_Energy, 1 ) ) && GT_32( *prev_Energy, L_shr( EnergyL, 1 ) ) )
1169 : {
1170 1400 : L_tmp1 = L_mac( L_mult( 8192 /* 0.25 in Q15 */, wfenv[0] ), 12288 /* 0.375 in Q15 */, prev_WB_fenv[0] ); /* Q3 */
1171 1400 : wfenv[0] = round_fx( L_mac( L_tmp1, 12288 /* 0.375 in Q15 */, prev_WB_fenv[1] ) ); /* Q3 */
1172 : }
1173 116964 : FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++ )
1174 : {
1175 115520 : WB_signal_32[n_freq] = Mult_32_16( WB_signal_32[n_freq], wfenv[0] );
1176 115520 : move32(); /* Q_syn+3+1 */
1177 : }
1178 1444 : prev_WB_fenv[0] = wfenv[0]; /* Q3 */
1179 1444 : move16();
1180 1444 : prev_WB_fenv[1] = wfenv[0]; /* Q3 */
1181 1444 : move16();
1182 : }
1183 :
1184 8889 : *prev_flag = flag;
1185 8889 : move16();
1186 8889 : *prev_Energy = EnergyL;
1187 8889 : move32();
1188 8889 : pit1 = &WB_signal_32[240];
1189 :
1190 151113 : FOR( n_freq = 0; n_freq < 16; n_freq++ )
1191 : {
1192 142224 : tmp1 = extract_l( L_mult0( n_freq, 1638 /* 0.05 in Q15 */ ) ); /*Q15 */
1193 142224 : tmp2 = add( 6554 /* 0.2 in Q15 */, tmp1 ); /*Q15 */
1194 142224 : L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */
1195 142224 : *( pit1++ ) = L_tmp1;
1196 142224 : move32();
1197 : }
1198 :
1199 8889 : IF( EQ_16( core_type, 1 ) )
1200 : {
1201 4806 : pit1 = &WB_signal_32[280];
1202 197046 : FOR( n_freq = 0; n_freq < 40; n_freq++ )
1203 : {
1204 192240 : tmp1 = extract_l( L_mult0( n_freq, 655 /* 0.02 in Q15 */ ) ); /*Q15 */
1205 192240 : tmp2 = sub( 32767, tmp1 );
1206 192240 : L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */
1207 192240 : *( pit1++ ) = L_tmp1;
1208 192240 : move32();
1209 : }
1210 : }
1211 : ELSE
1212 : {
1213 4083 : pit1 = &WB_signal_32[300];
1214 85743 : FOR( n_freq = 0; n_freq < 20; n_freq++ )
1215 : {
1216 81660 : tmp1 = extract_l( L_mult0( n_freq, 1311 /* 0.04 in Q15 */ ) ); /*Q15 */
1217 81660 : tmp2 = sub( 32767, tmp1 );
1218 81660 : L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */
1219 81660 : *( pit1++ ) = L_tmp1;
1220 81660 : move32();
1221 : }
1222 : }
1223 8889 : pit1 = &WB_signal_32[240];
1224 8889 : tmp = Find_Max_Norm32( pit1, 80 );
1225 720009 : FOR( i = 0; i < 80; i++ )
1226 : {
1227 711120 : L_tmp = *pit1;
1228 711120 : *( pit1++ ) = L_shl( L_tmp, sub( tmp, 1 ) );
1229 711120 : move32();
1230 : }
1231 8889 : *Q_syn_hb = add( Q_syn, add( tmp, 3 ) );
1232 8889 : move16();
1233 8889 : return;
1234 : }
1235 :
1236 :
1237 : /*==========================================================================*/
1238 : /* FUNCTION : void SWB_BWE_decoding_fx() */
1239 : /*--------------------------------------------------------------------------*/
1240 : /* PURPOSE : SWB BWE decoder */
1241 : /*--------------------------------------------------------------------------*/
1242 : /* INPUT ARGUMENTS */
1243 : /* _(Word16*) core_dec_freq :Frequency domain core decoded signal Q_syn */
1244 : /* _(Word16) SWB_flength :Length of input/output Q0 */
1245 : /* _(Word16) mode :classification for SWB signal */
1246 : /* _(Word16) tilt_nb :tilt of synthesis wb signal Q11 */
1247 : /* _(Word16) st_offset :offset value due to different core */
1248 : /* _(Word16) Q_syn :Q format */
1249 : /*--------------------------------------------------------------------------*/
1250 : /* OUTPUT ARGUMENTS : */
1251 : /* _(Word16*)SWB_fenv : SWB frequency envelopes Q1 */
1252 : /* _(Word16*)prev_Energy : energy for last frame Q3 */
1253 : /* _(Word16*)prev_SWB_fenv : envelope for last frame Q1 */
1254 : /* _(Word16*)prev_L_swb_norm : length for last frame wb norm Q0 */
1255 : /* _(Word16*)Seed : random generator seed Q0 */
1256 : /*--------------------------------------------------------------------------*/
1257 : /* INPUT/OUTPUT ARGUMENTS : */
1258 : /* _(Word16*)SWB_signal : SWB signal in MDCT domain Q0 */
1259 : /* _(Word16*)frica_flag : fricative signal flag Q0 */
1260 : /*--------------------------------------------------------------------------*/
1261 : /* RETURN ARGUMENTS : */
1262 : /* _ None */
1263 : /*--------------------------------------------------------------------------*/
1264 :
1265 12405 : void SWB_BWE_decoding_fx(
1266 : const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */
1267 : Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */
1268 : Word32 *SWB_signal_32, /* o : SWB signal in MDCT domain */
1269 : const Word16 SWB_flength, /* i : Length of input/output */
1270 : const Word16 mode, /* i : classification for SWB signal */
1271 : Word16 *frica_flag, /* o : fricative signal flag */
1272 : Word16 *prev_Energy, /* i/o: energy for last frame */
1273 : Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */
1274 : Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */
1275 : const Word16 tilt_nb, /* i : tilt of synthesis wb signal */
1276 : Word16 *Seed, /* i/o: random generator seed */
1277 : const Word16 st_offset, /* i : offset value due to different core */
1278 : Word16 *prev_weight, /* i/o: excitation weight value of last frame */
1279 : const Word16 extl, /* i : extension layer */
1280 : Word16 Q_syn,
1281 : const Word16 last_extl /* i : extension layer of last frame */
1282 : )
1283 : {
1284 : Word16 n_freq, n_band, L, L_swb_norm;
1285 : Word32 *pit1_32;
1286 : Word16 *pit1;
1287 : Word32 envelope[L_FRAME32k];
1288 : Word32 fenvL, EnergyL, Energy, energy, L_mean;
1289 : Word16 fenvL_16, EnergyL_16, Energy_16, tmp, exp, exp1;
1290 : Word16 SWB_signal[L_FRAME32k];
1291 : Word16 mean, factor, factor1, tmp1, tmp2, tmp3, tmp_exp, tmp_ener, weight, wfenv;
1292 : Word32 L_tmp, L_tmp3, L_tmp4, Ltmp_ener, L_tmp1;
1293 : Word32 L_energy;
1294 : Word16 signum[L_FRAME32k];
1295 : Word16 inv_L_swb_norm;
1296 :
1297 12405 : fenvL = L_deposit_l( 0 );
1298 12405 : EnergyL = L_deposit_l( 0 );
1299 210885 : FOR( n_freq = 224 + st_offset; n_freq < swb_bwe_trans_subband[0] + st_offset; n_freq++ )
1300 : {
1301 198480 : fenvL = L_mac0_sat( fenvL, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2*Q_syn */
1302 : }
1303 :
1304 2989605 : FOR( n_freq = 16; n_freq < L_FRAME; n_freq++ )
1305 : {
1306 2977200 : EnergyL = L_mac0_sat( EnergyL, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2*Q_syn */
1307 : }
1308 :
1309 12405 : fenvL_16 = 0;
1310 12405 : move16();
1311 12405 : IF( fenvL != 0 )
1312 : {
1313 12389 : exp = norm_l( fenvL ); /* In 2*Q_syn */
1314 12389 : tmp = extract_h( L_shl( fenvL, exp ) );
1315 12389 : exp = sub( exp, sub( 30, add( shl( Q_syn, 1 ), 4 ) ) ); /*+4(/16) */
1316 :
1317 12389 : tmp = div_s( 16384, tmp );
1318 12389 : L_tmp = L_deposit_h( tmp );
1319 12389 : L_tmp = Isqrt_lc( L_tmp, &exp );
1320 :
1321 12389 : fenvL_16 = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /* Q3 */
1322 : }
1323 12405 : IF( GT_16( fenvL_16, shl_sat( SWB_fenv[0], 5 ) ) )
1324 : {
1325 1958 : fenvL_16 = shl( SWB_fenv[0], 2 );
1326 1958 : move16();
1327 : }
1328 12405 : EnergyL = Mult_32_16( EnergyL, 17476 ); /*2*Q_syn+3; 17476=(1/15) in Q18 */
1329 12405 : EnergyL_16 = 0;
1330 12405 : move16();
1331 12405 : IF( EnergyL != 0 )
1332 : {
1333 12405 : exp = norm_l( EnergyL ); /* In 2*Q_syn+3 */
1334 12405 : tmp = extract_h( L_shl( EnergyL, exp ) );
1335 12405 : exp = sub( exp, sub( 30, add( shl( Q_syn, 1 ), 3 + 4 ) ) ); /*+4(/16) */
1336 :
1337 12405 : tmp = div_s( 16384, tmp );
1338 12405 : L_tmp = L_deposit_h( tmp );
1339 12405 : L_tmp = Isqrt_lc( L_tmp, &exp );
1340 :
1341 12405 : EnergyL_16 = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /* Q3 */
1342 : }
1343 12405 : calc_normal_length_fx( ACELP_CORE, core_dec_freq, mode, extl, &L_swb_norm, prev_L_swb_norm, Q_syn );
1344 :
1345 12405 : set16_fx( SWB_signal, 0, L_FRAME32k );
1346 12405 : IF( EQ_16( mode, TRANSIENT ) )
1347 : {
1348 63 : Energy = L_deposit_l( 0 );
1349 315 : FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ )
1350 : {
1351 252 : Energy = L_mac( Energy, SWB_fenv[n_band], SWB_fenv[n_band] ); /*Q(2*1+1)->Q3 */
1352 : }
1353 63 : exp = norm_s( SWB_FENV_TRANS );
1354 63 : tmp = div_s( shl( 1, sub( 14, exp ) ), SWB_FENV_TRANS ); /*Q(29-exp) */
1355 63 : L_tmp = Mult_32_16( Energy, tmp ); /*Q(3+29-exp+1-16)->Q(17-exp) */
1356 63 : Energy_16 = round_fx( L_shl( L_tmp, add( exp, 2 ) ) ); /*Q3 */
1357 :
1358 : /* Reconstruct excitation from LF signal */
1359 63 : Copy( &core_dec_freq[112], &SWB_signal[240 + st_offset], 128 );
1360 63 : Copy( &core_dec_freq[112], &SWB_signal[368 + st_offset], 128 );
1361 63 : Copy( &core_dec_freq[176], &SWB_signal[496 + st_offset], 64 );
1362 :
1363 : /* calculate envelope */
1364 63 : calc_norm_envelop_fx( SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset );
1365 :
1366 : /* Normalize with envelope */
1367 63 : tmp_exp = sub( 15, Q_syn );
1368 20223 : FOR( n_freq = swb_bwe_trans_subband[0] + st_offset; n_freq < swb_bwe_trans_subband[SWB_FENV_TRANS] + st_offset; n_freq++ )
1369 : {
1370 20160 : IF( envelope[n_freq] != 0 )
1371 : {
1372 20160 : exp = norm_l( envelope[n_freq] );
1373 20160 : tmp = extract_h( L_shl( envelope[n_freq], exp ) );
1374 20160 : exp = sub( sub( 30, exp ), Q_syn );
1375 20160 : tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+exp) */
1376 20160 : L_tmp = L_shr( L_mult0( SWB_signal[n_freq], tmp ), add( exp, Q_syn ) ); /*Q15 */
1377 20160 : SWB_signal[n_freq] = extract_l( L_tmp ); /*Q15 */
1378 20160 : move16();
1379 : }
1380 : ELSE
1381 : {
1382 0 : SWB_signal[n_freq] = shl( SWB_signal[n_freq], tmp_exp );
1383 0 : move16(); /*Q15 */
1384 : }
1385 : }
1386 :
1387 315 : FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ )
1388 : {
1389 252 : energy = L_deposit_l( 0 );
1390 252 : tmp = add( swb_bwe_trans_subband[n_band + 1], st_offset );
1391 20412 : FOR( n_freq = add( swb_bwe_trans_subband[n_band], st_offset ); n_freq < tmp; n_freq++ )
1392 : {
1393 20160 : L_tmp = L_mult_sat( SWB_signal[n_freq], SWB_signal[n_freq] ); /*Q31 */
1394 20160 : energy = L_add_sat( energy, L_shr( L_tmp, 6 ) ); /*Q25 */
1395 : }
1396 :
1397 252 : IF( energy == 0 )
1398 : {
1399 0 : Ltmp_ener = L_mult( sqrt_swb_bwe_trans_subband_width_fx[n_band], SWB_fenv[n_band] ); /*Q13 */
1400 0 : tmp = add( swb_bwe_trans_subband[n_band + 1], st_offset );
1401 0 : FOR( n_freq = add( swb_bwe_trans_subband[n_band], st_offset ); n_freq < tmp; n_freq++ )
1402 : {
1403 0 : SWB_signal_32[n_freq] = L_shl( Mult_32_16( Ltmp_ener, SWB_signal[n_freq] ), 2 + Q_syn );
1404 0 : move32(); /*15+Qsyn */
1405 : }
1406 : }
1407 : ELSE
1408 : {
1409 252 : exp1 = norm_s( swb_bwe_trans_subband_width[n_band] );
1410 252 : tmp = div_s( shl( 1, sub( 14, exp1 ) ), swb_bwe_trans_subband_width[n_band] ); /*Q(29-exp1) */
1411 252 : energy = Mult_32_16( energy, tmp ); /*Q(29-exp1+25-15)->Q(-exp1+39) */
1412 :
1413 252 : exp = norm_l( energy );
1414 252 : L_tmp = L_shl( energy, exp );
1415 : /*exp = 31-exp-(-exp1+39); */
1416 252 : exp = sub( sub( exp1, exp ), 8 );
1417 252 : L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */
1418 :
1419 252 : Ltmp_ener = Mult_32_16( L_tmp, SWB_fenv[n_band] ); /*Q(31-exp+1+1-16)->Q(17-exp) */
1420 252 : tmp = add( swb_bwe_trans_subband[n_band + 1], st_offset );
1421 252 : tmp_exp = add( Q_syn, sub( exp, 2 ) );
1422 20412 : FOR( n_freq = add( swb_bwe_trans_subband[n_band], st_offset ); n_freq < tmp; n_freq++ )
1423 : {
1424 20160 : SWB_signal_32[n_freq] = L_shl( Mult_32_16( Ltmp_ener, SWB_signal[n_freq] ), tmp_exp );
1425 20160 : move32(); /*15+Qsyn */
1426 : }
1427 : }
1428 : }
1429 :
1430 567 : FOR( n_band = 0; n_band < 8; n_band++ )
1431 : {
1432 504 : L_tmp = L_mult( SWB_fenv[n_band / 4], SWB_fenv[n_band / 4] ); /*Q3 */
1433 504 : prev_SWB_fenv[n_band] = round_fx( L_shl( L_tmp, 14 ) ); /*Q1 */
1434 504 : move16();
1435 : }
1436 :
1437 441 : FOR( n_band = 0; n_band < 6; n_band++ )
1438 : {
1439 378 : L_tmp = L_mult( SWB_fenv[2 + n_band / 3], SWB_fenv[2 + n_band / 3] ); /*Q3 */
1440 378 : prev_SWB_fenv[8 + n_band] = round_fx( L_shl( L_tmp, 14 ) ); /*Q1 */
1441 378 : move16();
1442 : }
1443 :
1444 63 : *prev_weight = 16384 /* 0.5 in Q15 */;
1445 63 : move16();
1446 : }
1447 : ELSE
1448 : {
1449 12342 : Energy_16 = 0;
1450 12342 : move16();
1451 12342 : L_energy = L_deposit_l( 0 );
1452 185130 : FOR( n_band = 0; n_band < SWB_FENV; n_band++ )
1453 : {
1454 172788 : L_energy = L_add( L_energy, SWB_fenv[n_band] ); /*Q1 */
1455 : }
1456 12342 : exp = norm_s( SWB_FENV );
1457 12342 : tmp = div_s( shl( 1, sub( 14, exp ) ), SWB_FENV ); /*Q(29-exp) */
1458 12342 : L_tmp = Mult_32_16( L_energy, tmp ); /*Q(1+29-exp+1)->Q(15-exp) */
1459 :
1460 12342 : Energy_16 = round_fx_sat( L_shl_sat( L_tmp, add( exp, 4 ) ) ); /* Q3 */
1461 :
1462 12342 : test();
1463 12342 : IF( NE_16( last_extl, SWB_BWE ) && NE_16( last_extl, FB_BWE ) )
1464 : {
1465 4316 : test();
1466 4316 : IF( LT_16( Energy_16, shr( EnergyL_16, 4 ) ) && EQ_16( extl, FB_BWE ) )
1467 : {
1468 0 : FOR( n_band = 0; n_band < SWB_FENV; n_band++ )
1469 : {
1470 0 : SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], 6554 /* 0.2 in Q15 */ );
1471 0 : move16();
1472 : }
1473 0 : fenvL_16 = mult_r( fenvL_16, 6554 /* 0.2 in Q15 */ );
1474 : }
1475 4316 : Copy( SWB_fenv, prev_SWB_fenv, SWB_FENV );
1476 : }
1477 :
1478 12342 : IF( EQ_16( mode, HARMONIC ) )
1479 : {
1480 195 : Copy( core_dec_freq, &SWB_signal[240 + st_offset], 240 );
1481 195 : Copy( &core_dec_freq[128], &SWB_signal[480 + st_offset], 80 );
1482 : /* calculate envelope */
1483 195 : calc_norm_envelop_fx( SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset );
1484 : }
1485 : ELSE
1486 : {
1487 12147 : test();
1488 12147 : test();
1489 12147 : test();
1490 12147 : test();
1491 12147 : test();
1492 12147 : test();
1493 12147 : IF( EQ_16( mode, NOISE ) || ( ( GT_16( Energy_16, EnergyL_16 ) || ( GT_16( tilt_nb, 14336 /*7 in Q11*/ ) && GT_16( Energy_16, shr( EnergyL_16, 1 ) ) ) ||
1494 : GT_16( tilt_nb, 24576 /*12 in Q11*/ ) ) &&
1495 : GT_16( Energy_16, 600 /* 75 in Q3*/ ) && GT_16( fenvL_16, 200 /* 25 in Q3*/ ) ) )
1496 : {
1497 795 : tmp = add( swb_bwe_subband[SWB_FENV], st_offset );
1498 255195 : FOR( n_freq = add( swb_bwe_subband[0], st_offset ); n_freq < tmp; n_freq++ )
1499 : {
1500 254400 : *Seed = extract_l( L_mac0( 20101L, 12345, *Seed ) );
1501 254400 : move16();
1502 254400 : SWB_signal[n_freq] = mult_r( *Seed, 32767 );
1503 254400 : move16(); /*Q15 */
1504 : }
1505 795 : if ( NE_16( mode, NOISE ) )
1506 : {
1507 142 : *frica_flag = 1;
1508 142 : move16();
1509 : }
1510 : }
1511 : ELSE
1512 : {
1513 : /* modify SHB frequency envelopes when SHB spectrum is unflat */
1514 158928 : FOR( n_band = 0; n_band < 13; n_band++ )
1515 : {
1516 147576 : IF( GT_16( mult_r( SWB_fenv[n_band], 29491 /* 0.9 in Q15 */ ), SWB_fenv[n_band + 1] ) )
1517 : {
1518 43687 : tmp = extract_l( L_mac0( 26214 /* 0.8 in Q15 */, n_band, 492 ) ); /*Q15; 0.015 in Q15 = 492 */
1519 43687 : SWB_fenv[n_band + 1] = mult_r( SWB_fenv[n_band + 1], tmp );
1520 43687 : move16(); /*Q1 */
1521 : }
1522 :
1523 147576 : IF( GT_16( mult_r( SWB_fenv[n_band + 1], 29491 /* 0.9 in Q15 */ ), SWB_fenv[n_band] ) )
1524 : {
1525 39267 : tmp = extract_l( L_mac0( 26214 /* 0.8 in Q15 */, n_band, 492 ) ); /*Q15; 0.015 in Q15 = 492 */
1526 39267 : SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp );
1527 39267 : move16(); /*Q1 */
1528 : }
1529 : }
1530 11352 : Copy( &core_dec_freq[112], &SWB_signal[240 + st_offset], 128 );
1531 11352 : Copy( &core_dec_freq[112], &SWB_signal[368 + st_offset], 128 );
1532 11352 : Copy( &core_dec_freq[176], &SWB_signal[496 + st_offset], 64 );
1533 :
1534 11352 : tmp1 = add_sat( abs_s( SWB_signal[368 + st_offset] ), abs_s( SWB_signal[369 + st_offset] ) ); /*Q_syn */
1535 11352 : tmp2 = add_sat( abs_s( SWB_signal[365 + st_offset] ), abs_s( SWB_signal[366 + st_offset] ) ); /*Q_syn */
1536 11352 : pit1 = &SWB_signal[368 + st_offset];
1537 11352 : move16();
1538 :
1539 11352 : test();
1540 11352 : IF( ( tmp2 == 0 ) || ( LT_16( tmp2, mult_r( tmp1, 9830 /* 0.3 in Q15*/ ) ) ) )
1541 : {
1542 3337 : tmp3 = 9830;
1543 3337 : move16(); /*0.3 in Q15 */
1544 26696 : WHILE( LT_16( tmp3, 32767 ) )
1545 : {
1546 23359 : *pit1 = mult_r( *pit1, tmp3 );
1547 23359 : move16(); /*Q_syn */
1548 23359 : pit1++;
1549 23359 : tmp3 = add_sat( tmp3, 3277 /* 0.1 in Q15*/ ); /*Q15 */
1550 : }
1551 : }
1552 8015 : ELSE IF( LT_16( tmp2, tmp1 ) )
1553 : {
1554 5079 : exp = norm_s( tmp1 );
1555 5079 : tmp = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(29-exp) */
1556 5079 : tmp3 = round_fx_sat( L_shl_sat( L_mult( tmp2, tmp ), add( exp, 2 ) ) ); /*Q15 */
1557 11685 : WHILE( LT_16( tmp3, 32767 ) )
1558 : {
1559 6606 : *pit1 = mult_r( *pit1, tmp3 );
1560 6606 : move16(); /*Q_syn */
1561 6606 : pit1++;
1562 6606 : tmp3 = add_sat( tmp3, 3277 /* 0.1 in Q15*/ ); /*Q15 */
1563 : }
1564 : }
1565 :
1566 11352 : pit1 = &SWB_signal[367 + st_offset];
1567 :
1568 11352 : IF( GT_16( mult_r( tmp1, 6554 /*0.2 in Q15*/ ), tmp2 ) )
1569 : {
1570 : /*20480 = 5 in Q12 */
1571 19251 : FOR( tmp3 = 20480; tmp3 > 4096; tmp3 -= 2048 )
1572 : {
1573 17112 : *pit1 = round_fx_sat( L_shl_sat( L_mult( *pit1, tmp3 ), 3 ) ); /*Q_syn */
1574 17112 : move16();
1575 17112 : pit1--;
1576 : }
1577 : }
1578 :
1579 11352 : tmp1 = add_sat( abs_s( SWB_signal[496 + st_offset] ), abs_s( SWB_signal[497 + st_offset] ) ); /*Q_syn */
1580 11352 : tmp2 = add_sat( add_sat( abs_s( SWB_signal[492 + st_offset] ), abs_s( SWB_signal[493 + st_offset] ) ), add_sat( abs_s( SWB_signal[494 + st_offset] ), abs_s( SWB_signal[495 + st_offset] ) ) );
1581 11352 : pit1 = &SWB_signal[496 + st_offset];
1582 :
1583 11352 : test();
1584 11352 : IF( ( tmp2 == 0 ) || ( LT_16( tmp2, mult_r( tmp1, 9830 /* 0.3 in Q15 */ ) ) ) )
1585 : {
1586 602 : tmp3 = 9830;
1587 602 : move16(); /*0.3 in Q15 */
1588 4816 : WHILE( LT_16( tmp3, 32767 ) )
1589 : {
1590 4214 : *pit1 = mult_r( *pit1, tmp3 );
1591 4214 : move16(); /*Q_syn */
1592 4214 : pit1++;
1593 4214 : tmp3 = add_sat( tmp3, 3277 /* 0.1 in Q15 */ ); /*Q15 */
1594 : }
1595 : }
1596 10750 : ELSE IF( LT_16( tmp2, tmp1 ) )
1597 : {
1598 3024 : exp = norm_s( tmp1 );
1599 3024 : tmp = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(29-exp) */
1600 3024 : tmp3 = round_fx_sat( L_shl_sat( L_mult( tmp2, tmp ), add( exp, 2 ) ) ); /*Q15 */
1601 4855 : WHILE( LT_16( tmp3, 32767 ) )
1602 : {
1603 1831 : *pit1 = mult_r( *pit1, tmp3 );
1604 1831 : move16(); /*Q_syn */
1605 1831 : pit1++;
1606 1831 : tmp3 = add_sat( tmp3, 3277 /* 0.1 in Q15 */ ); /*Q15 */
1607 : }
1608 : }
1609 11352 : pit1 = &SWB_signal[495 + st_offset];
1610 :
1611 11352 : L_tmp3 = L_deposit_h( tmp1 ); /*Q17 */
1612 11352 : L_tmp4 = Mult_32_16( L_tmp3, 1638 /* 0.05 in Q15*/ ); /*Q17 */
1613 11352 : exp = 14;
1614 11352 : move16();
1615 11352 : IF( tmp2 != 0 )
1616 : {
1617 11239 : exp = norm_s( tmp2 );
1618 11239 : tmp = div_s( shl( 1, sub( 14, exp ) ), tmp2 ); /*Q(29-exp) */
1619 11239 : L_tmp3 = L_shr( L_mult( tmp1, tmp ), 1 ); /*Q(30-exp+1)->Q(30-exp) (+1) due to *0.5 */
1620 11239 : L_tmp4 = Mult_32_16( L_tmp3, 1638 /* 0.05 in Q15 */ ); /*Q(30-exp) */
1621 : }
1622 :
1623 11352 : L_tmp1 = L_shl( 1L, sub( 30, exp ) );
1624 22155 : WHILE( GT_32( L_tmp3, L_tmp1 ) )
1625 : {
1626 10803 : L_tmp = Mult_32_16( L_tmp3, *pit1 ); /*Q(16-exp) */
1627 10803 : *pit1-- = round_fx( L_shl( L_tmp, exp ) ); /*Q_syn */
1628 10803 : move16();
1629 10803 : L_tmp3 = L_sub( L_tmp3, L_tmp4 );
1630 : }
1631 :
1632 : /* calculate envelope */
1633 11352 : calc_norm_envelop_fx( SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset );
1634 : }
1635 : }
1636 :
1637 : /* Normalize with envelope */
1638 12342 : test();
1639 12342 : IF( *frica_flag == 0 && NE_16( mode, NOISE ) )
1640 : {
1641 11547 : L = add( swb_bwe_subband[0], st_offset );
1642 11547 : exp = norm_s( L_swb_norm );
1643 11547 : inv_L_swb_norm = shl( div_s( shl( 1, sub( 14, exp ) ), L_swb_norm ), sub( exp, 14 ) ); /* Q15 */
1644 :
1645 11547 : IF( NE_16( mode, HARMONIC ) )
1646 : {
1647 11352 : tmp = add( shl( inv_L_swb_norm, 1 ), inv_L_swb_norm );
1648 11352 : weight = s_max( s_min( tmp, 16384 /* 0.5 in Q15 */ ), 6554 /* 0.2 in Q15 */ );
1649 : }
1650 : ELSE
1651 : {
1652 195 : weight = 6554; /* 0.2 in Q15 */
1653 195 : move16();
1654 : }
1655 :
1656 11547 : weight = mac_r( L_mult( 13107 /* 0.4 in Q15 */, weight ), 19661 /* 0.6 in Q15 */, ( *prev_weight ) );
1657 :
1658 3706587 : FOR( n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++ )
1659 : {
1660 3695040 : signum[n_freq] = 1;
1661 3695040 : move16();
1662 3695040 : IF( SWB_signal[n_freq] < 0 )
1663 : {
1664 1760549 : signum[n_freq] = -1;
1665 1760549 : move16();
1666 1760549 : SWB_signal[n_freq] = negate( SWB_signal[n_freq] );
1667 1760549 : move16();
1668 : }
1669 3695040 : L_tmp = Mult_32_16( envelope[n_freq], inv_L_swb_norm ); /* Q_syn */
1670 3695040 : L_tmp1 = L_deposit_l( SWB_signal[n_freq] ); /* Q_syn */
1671 3695040 : L_tmp = L_sub( L_tmp1, L_tmp ); /* Q_syn */
1672 3695040 : IF( L_tmp > 0 )
1673 : {
1674 1649466 : tmp = shr( weight, 1 ); /* Q14 */
1675 1649466 : tmp = sub( 19661, tmp ); /* Q14 */
1676 1649466 : SWB_signal[n_freq] = extract_l( L_shl( Mult_32_16( L_tmp, tmp ), 1 ) ); /* Q_syn */
1677 : }
1678 : ELSE
1679 : {
1680 2045574 : SWB_signal[n_freq] = extract_l( L_tmp ); /* Q_syn */
1681 : }
1682 3695040 : move16();
1683 3695040 : IF( NE_16( signum[n_freq], 1 ) )
1684 : {
1685 1760549 : SWB_signal[n_freq] = negate( SWB_signal[n_freq] );
1686 1760549 : move16();
1687 : }
1688 : }
1689 :
1690 11547 : tmp_exp = sub( 15, Q_syn );
1691 3706587 : FOR( n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++ ){
1692 3695040 : IF( envelope[n_freq] != 0 ){
1693 3689460 : exp = norm_l( envelope[n_freq] );
1694 3689460 : tmp = extract_h( L_shl( envelope[n_freq], exp ) );
1695 3689460 : exp = sub( sub( 30, exp ), Q_syn );
1696 3689460 : tmp = div_s( 16384 /* 0.5 in Q15*/, tmp ); /* Q(15+exp) */
1697 3689460 : L_tmp = L_shr( L_mult0( SWB_signal[n_freq], tmp ), add( exp, Q_syn ) ); /* Q15 */
1698 3689460 : SWB_signal[n_freq] = extract_l( L_tmp );
1699 3689460 : move16(); /* Q15 */
1700 : }
1701 : ELSE
1702 : {
1703 5580 : SWB_signal[n_freq] = shl( SWB_signal[n_freq], tmp_exp );
1704 5580 : move16(); /* Q15 */
1705 : }
1706 : }
1707 11547 : *prev_weight = weight;
1708 11547 : move16();
1709 : }
1710 : ELSE
1711 : {
1712 795 : exp = norm_s( L_swb_norm );
1713 795 : tmp = shl( div_s( shl( 1, sub( 14, exp ) ), L_swb_norm ), sub( exp, 14 ) ); /* Q15 */
1714 795 : tmp = add( shl( tmp, 1 ), tmp );
1715 795 : *prev_weight = s_max( s_min( tmp, 16384 /* 0.5 in Q15 */ ), 6554 /* 0.2 in Q15 */ ); /* Q15 */
1716 795 : move16();
1717 : }
1718 :
1719 12342 : IF( EQ_16( mode, HARMONIC ) )
1720 : {
1721 195 : pit1 = &SWB_signal[swb_bwe_subband[0] + st_offset];
1722 195 : move16();
1723 3900 : FOR( n_band = 0; n_band < 19; n_band++ )
1724 : {
1725 3705 : L_mean = L_deposit_l( 0 );
1726 62985 : FOR( n_freq = 0; n_freq < 16; n_freq++ )
1727 : {
1728 59280 : L_mean = L_add( L_mean, abs_s( *pit1 ) ); /*Q15 */
1729 59280 : pit1++;
1730 : }
1731 3705 : mean = extract_l( Mult_32_16( L_mean, 2048 /* 1/16 in Q15 */ ) ); /*Q15 */
1732 3705 : pit1 -= 16;
1733 62985 : FOR( n_freq = 0; n_freq < 16; n_freq++ )
1734 : {
1735 59280 : IF( LT_16( abs_s( *pit1 ), mean ) )
1736 : {
1737 34929 : *pit1 = mult_r( *pit1, 6554 /* 0.2 in Q15 */ ); /*Q15*/
1738 34929 : move16();
1739 : }
1740 59280 : pit1++;
1741 : }
1742 : }
1743 : }
1744 :
1745 12342 : L = 1;
1746 12342 : move16();
1747 12342 : if ( EQ_16( mode, HARMONIC ) )
1748 : {
1749 195 : L = 2;
1750 195 : move16();
1751 : }
1752 :
1753 183765 : FOR( n_band = 0; n_band < SWB_FENV; n_band += L )
1754 : {
1755 171423 : energy = L_deposit_l( 0 );
1756 171423 : tmp = add( swb_bwe_subband[n_band + L], st_offset );
1757 4120863 : FOR( n_freq = add( swb_bwe_subband[n_band], st_offset ); n_freq < tmp; n_freq++ )
1758 : {
1759 3949440 : L_tmp = L_mult( SWB_signal[n_freq], SWB_signal[n_freq] ); /*Q31 */
1760 3949440 : energy = L_add( energy, L_shr( L_tmp, 6 ) ); /*Q25 */
1761 : }
1762 :
1763 171423 : IF( energy == 0 )
1764 : {
1765 4072 : tmp_ener = sqrt_swb_bwe_subband_fx_L1[n_band]; /*Q12 */
1766 4072 : move16();
1767 4072 : if ( NE_16( L, 1 ) )
1768 : {
1769 3 : tmp_ener = sqrt_swb_bwe_subband_fx_L2[shr( n_band, 1 )]; /*Q12 */
1770 3 : move16();
1771 : }
1772 :
1773 4072 : tmp = add( swb_bwe_subband[n_band + L], st_offset );
1774 4072 : tmp_exp = sub( Q_syn, 12 );
1775 101392 : FOR( n_freq = add( swb_bwe_subband[n_band], st_offset ); n_freq < tmp; n_freq++ )
1776 : {
1777 97320 : SWB_signal_32[n_freq] = L_shl( L_mult( tmp_ener, SWB_signal[n_freq] ), tmp_exp ); /*Qsyn */
1778 97320 : move32();
1779 : }
1780 : }
1781 : ELSE
1782 : {
1783 167351 : tmp = sub( swb_bwe_subband[n_band + L], swb_bwe_subband[n_band] );
1784 167351 : exp1 = norm_s( tmp );
1785 167351 : tmp = div_s( shl( 1, sub( 14, exp1 ) ), tmp ); /*Q(29-exp1) */
1786 167351 : energy = Mult_32_16( energy, tmp ); /*Q(29-exp1+25-15)->Q(-exp1+39) */
1787 :
1788 167351 : exp = norm_l( energy );
1789 167351 : L_tmp = L_shl( energy, exp );
1790 : /*exp = 31-exp-(-exp1+39);move16(); */
1791 167351 : exp = sub( sub( exp1, exp ), 8 );
1792 167351 : Ltmp_ener = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */
1793 :
1794 167351 : tmp = add( swb_bwe_subband[n_band + L], st_offset );
1795 167351 : tmp_exp = add( Q_syn, sub( exp, 15 ) );
1796 4019471 : FOR( n_freq = add( swb_bwe_subband[n_band], st_offset ); n_freq < tmp; n_freq++ )
1797 : {
1798 3852120 : SWB_signal_32[n_freq] = L_shl( Mult_32_16( Ltmp_ener, SWB_signal[n_freq] ), tmp_exp );
1799 3852120 : move32(); /*Qsyn+16 */
1800 : }
1801 : }
1802 : }
1803 :
1804 12342 : IF( GT_16( *prev_Energy, add_sat( Energy_16, shr( Energy_16, 2 ) ) ) && Energy_16 > 0 )
1805 : {
1806 1297 : weight = shr( div_s( Energy_16, *prev_Energy ), 1 ); /*Q15 */
1807 : }
1808 : ELSE
1809 : {
1810 11045 : weight = 16384;
1811 11045 : move16(); /*Q15 */
1812 : }
1813 12342 : L_tmp = L_mult( weight, prev_SWB_fenv[0] ); /*Q17 */
1814 12342 : L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[0] ); /*Q17 */
1815 12342 : wfenv = round_fx( L_tmp ); /*Q1 */
1816 :
1817 12342 : tmp = norm_s( wfenv );
1818 12342 : IF( GT_16( tmp, 4 ) )
1819 : {
1820 10221 : tmp = 12;
1821 10221 : move16();
1822 10221 : factor = fenvL_16;
1823 10221 : move16(); /*Q3 */
1824 10221 : factor1 = mult_r( sub( shl( wfenv, 2 ), fenvL_16 ), 4096 /* 0.125 in Q15 */ ); /*Q3 */
1825 : }
1826 : ELSE
1827 : {
1828 2121 : tmp = 14;
1829 2121 : move16();
1830 2121 : factor = shr( fenvL_16, 2 ); /*Q1 */
1831 2121 : factor1 = mult_r( sub( wfenv, factor ), 4096 /* 0.125 in Q15 */ ); /*Q1 */
1832 : }
1833 :
1834 12342 : tmp2 = add( add( swb_bwe_subband[0], 8 ), st_offset );
1835 111078 : FOR( n_freq = add( swb_bwe_subband[0], st_offset ); n_freq < tmp2; n_freq++ )
1836 : {
1837 98736 : L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor );
1838 98736 : SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 );
1839 98736 : move32(); /*15+Qsyn */
1840 98736 : factor = add( factor, factor1 ); /*Q3 */
1841 : }
1842 :
1843 160446 : FOR( n_band = 0; n_band < 12; n_band++ )
1844 : {
1845 148104 : L_tmp = L_mult( weight, prev_SWB_fenv[n_band + 1] ); /*Q17 */
1846 148104 : L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[n_band + 1] ); /*Q17 */
1847 148104 : wfenv = round_fx( L_tmp ); /*Q1 */
1848 148104 : factor = SWB_fenv[n_band];
1849 148104 : move16(); /*Q1 */
1850 148104 : factor1 = mult_r( sub( wfenv, SWB_fenv[n_band] ), smooth_factor_fx[n_band] ); /*Q1 */
1851 148104 : tmp = norm_s( factor );
1852 148104 : IF( GT_16( tmp, 4 ) )
1853 : {
1854 121473 : tmp = 12;
1855 121473 : move16();
1856 121473 : factor = shl( factor, 2 );
1857 121473 : factor1 = shl( factor1, 2 );
1858 : }
1859 : ELSE
1860 : {
1861 26631 : tmp = 14;
1862 26631 : move16();
1863 : }
1864 :
1865 148104 : tmp2 = add( swb_bwe_sm_subband[n_band + 1], st_offset );
1866 3406392 : FOR( ; n_freq < tmp2; n_freq++ )
1867 : {
1868 3258288 : L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor );
1869 3258288 : SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, tmp - 1 );
1870 3258288 : move32(); /*15+Qsyn */
1871 3258288 : factor = add_sat( factor, factor1 ); /*Q1 */
1872 : }
1873 : }
1874 12342 : L_tmp = L_mult( weight, prev_SWB_fenv[13] ); /*Q17 */
1875 12342 : L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[13] ); /*Q17 */
1876 12342 : wfenv = round_fx( L_tmp ); /*Q1 */
1877 12342 : factor = SWB_fenv[12];
1878 12342 : move16(); /*Q1 */
1879 12342 : factor1 = mult_r( sub( wfenv, SWB_fenv[12] ), smooth_factor_fx[12] ); /*Q1 */
1880 12342 : tmp2 = add( swb_bwe_sm_subband[13], st_offset );
1881 407286 : FOR( ; n_freq < tmp2; n_freq++ )
1882 : {
1883 394944 : L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor );
1884 394944 : SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 );
1885 394944 : move32(); /*15+Qsyn */
1886 394944 : factor = add( factor, factor1 ); /*Q1 */
1887 : }
1888 :
1889 24684 : FOR( n_band = 13; n_band < SWB_FENV; n_band++ )
1890 : {
1891 12342 : L_tmp = L_mult( weight, prev_SWB_fenv[n_band] ); /*Q17 */
1892 12342 : L_tmp = L_mac( L_tmp, sub( 32767, weight ), SWB_fenv[n_band] ); /*Q17 */
1893 12342 : wfenv = round_fx( L_tmp ); /*Q1 */
1894 12342 : tmp2 = add( swb_bwe_subband[n_band + 1], st_offset );
1895 209814 : FOR( ; n_freq < tmp2; n_freq++ )
1896 : {
1897 197472 : L_tmp1 = Mult_32_16( SWB_signal_32[n_freq], factor );
1898 197472 : SWB_signal_32[n_freq] = L_shl_sat( L_tmp1, 13 );
1899 197472 : move32(); /*15+Qsyn */
1900 : }
1901 : }
1902 185130 : FOR( n_band = 0; n_band < SWB_FENV; n_band++ )
1903 : {
1904 172788 : prev_SWB_fenv[n_band] = SWB_fenv[n_band];
1905 172788 : move16(); /*Q1 */
1906 : }
1907 : }
1908 12405 : pit1_32 = &SWB_signal_32[240 + st_offset]; /*15+Qsyn */
1909 62025 : FOR( n_freq = 0; n_freq < 4; n_freq++ )
1910 : {
1911 49620 : L_tmp1 = Mult_32_16( *pit1_32, 16384 /* 0.5 in Q15 */ ); /*15+Qsyn */
1912 49620 : *( pit1_32++ ) = L_tmp1;
1913 49620 : move32();
1914 : }
1915 12405 : *prev_Energy = Energy_16;
1916 12405 : move16();
1917 :
1918 12405 : return;
1919 : }
1920 :
1921 : /*==========================================================================*/
1922 : /* FUNCTION : void time_envelop_shaping_fx() */
1923 : /*--------------------------------------------------------------------------*/
1924 : /* PURPOSE : Time shaping of SHB signal */
1925 : /*--------------------------------------------------------------------------*/
1926 : /* INPUT ARGUMENTS */
1927 : /* _(Word16) L :length */
1928 : /* _(Word16) Q_syn :Q format */
1929 : /*--------------------------------------------------------------------------*/
1930 : /* OUTPUT ARGUMENTS : */
1931 : /* _None */
1932 : /*--------------------------------------------------------------------------*/
1933 : /* INPUT/OUTPUT ARGUMENTS : */
1934 : /* _(Word16[])werr : SHB synthesis */
1935 : /* _(Word16[])SWB_tenv : frequency envelope */
1936 : /*--------------------------------------------------------------------------*/
1937 : /* RETURN ARGUMENTS : */
1938 : /* _ None */
1939 : /*--------------------------------------------------------------------------*/
1940 0 : void time_envelop_shaping_fx(
1941 : Word16 werr[], /* i/o: SHB synthesis Q_synth*/
1942 : Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/
1943 : const Word16 L, /* i : frame length */
1944 : Word16 *Q_synth )
1945 : {
1946 : Word16 *pit;
1947 : Word32 Energy;
1948 : Word16 i, j;
1949 : Word16 tmp_ener, Energy_16;
1950 : Word16 exp_L, exp, frac, tmp, inv_L;
1951 : Word32 L_tmp;
1952 :
1953 0 : pit = werr;
1954 0 : exp_L = norm_s( L );
1955 0 : inv_L = div_s( shl( 1, sub( 14, exp_L ) ), L ); /*Q(29-exp_L) */
1956 0 : FOR( i = 0; i < SWB_TENV; i++ )
1957 : {
1958 0 : Energy = L_deposit_l( 0 );
1959 0 : FOR( j = 0; j < L / 4; j++ )
1960 : {
1961 0 : Energy = L_mac0_sat( Energy, *pit, *pit ); /*(2*Q_synth) */
1962 0 : pit++;
1963 : }
1964 0 : Energy = Mult_32_16( Energy, inv_L ); /*Q(29-exp_L-15) -> Q(-exp_L+14+2*Q_synth) */
1965 0 : Energy_16 = 0;
1966 0 : move16();
1967 : /*exp = 31-(-exp_L+14 +(2*(*Q_synth))); */
1968 0 : exp = sub( 17, sub( shl( ( *Q_synth ), 1 ), exp_L ) );
1969 :
1970 0 : IF( Energy != 0 )
1971 : {
1972 0 : exp = norm_l( Energy );
1973 0 : frac = extract_h( L_shl( Energy, exp ) );
1974 : /*exp = sub(exp, 30-(-exp_L+14-2+(2*(*Q_synth)))); */
1975 0 : exp = sub( exp, sub( 30, add( sub( shl( ( *Q_synth ), 1 ), exp_L ), 14 - 2 ) ) );
1976 :
1977 0 : tmp = div_s( 16384, frac );
1978 0 : L_tmp = L_deposit_h( tmp );
1979 0 : Energy = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */
1980 0 : Energy_16 = round_fx( L_shl( Energy, sub( exp, 15 ) ) ); /*Q0 */
1981 : }
1982 :
1983 0 : test();
1984 0 : IF( LT_32( SWB_tenv[i], 65536 /* 2 in Q15 */ ) && LT_32( Energy, L_shl_sat( SWB_tenv[i], sub( 16, exp ) ) ) )
1985 : {
1986 0 : *Q_synth = add( *Q_synth, 3 );
1987 0 : move16();
1988 : }
1989 : ELSE
1990 : {
1991 0 : pit -= shr( L, 2 );
1992 0 : move16();
1993 0 : tmp_ener = 0;
1994 0 : move16();
1995 0 : exp = 0;
1996 0 : move16();
1997 :
1998 0 : IF( Energy_16 != 0 )
1999 : {
2000 0 : exp = norm_s( Energy_16 );
2001 0 : tmp_ener = div_s( shl( 1, sub( 14, exp ) ), Energy_16 ); /*Q(29-exp) */
2002 : }
2003 :
2004 0 : L_tmp = Mult_32_16( SWB_tenv[i], tmp_ener ); /*Q(29-exp) */
2005 0 : tmp = round_fx( L_tmp ); /*Q(13-exp) */
2006 :
2007 0 : FOR( j = 0; j < L / 4; j++ )
2008 : {
2009 0 : *pit = round_fx_sat( L_shl_sat( L_mult( tmp, *pit ), sub( exp, 1 ) ) ); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */
2010 0 : move16();
2011 0 : pit++;
2012 : }
2013 : }
2014 : }
2015 :
2016 0 : return;
2017 : }
2018 :
2019 63 : void time_envelop_shaping_ivas_fx(
2020 : Word16 werr[], /* i/o: SHB synthesis Q_synth*/
2021 : Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/
2022 : const Word16 L, /* i : frame length */
2023 : Word16 *Q_synth )
2024 : {
2025 : Word16 *pit;
2026 : Word32 Energy;
2027 : Word16 i, j;
2028 : Word16 tmp_ener, Energy_16;
2029 : Word64 Energy_64;
2030 : Word16 exp_L, exp, frac, tmp, inv_L, w_tmp, Energy_Q;
2031 : Word32 L_tmp;
2032 :
2033 63 : pit = werr;
2034 63 : exp_L = norm_s( L );
2035 63 : inv_L = div_s( shl( 1, sub( 14, exp_L ) ), L ); /*Q(29-exp_L) */
2036 315 : FOR( i = 0; i < SWB_TENV; i++ )
2037 : {
2038 252 : Energy_64 = L_deposit_l( 0 );
2039 54332 : FOR( j = 0; j < L / 4; j++ )
2040 : {
2041 54080 : Energy_64 = W_mac0_16_16( Energy_64, *pit, *pit ); /*(2*Q_synth) */
2042 54080 : pit++;
2043 : }
2044 252 : w_tmp = W_norm( Energy_64 );
2045 252 : Energy_64 = W_shl( Energy_64, w_tmp );
2046 252 : Energy = W_extract_h( Energy_64 ); /*2*Q_synth + w_tmp -32*/
2047 252 : Energy_Q = sub( add( shl( ( *Q_synth ), 1 ), w_tmp ), 32 );
2048 252 : Energy = Mult_32_16( Energy, inv_L ); /*Q(29-exp_L-15) -> Q(-exp_L+14+2*Q_synth+w_tmp-32) */
2049 252 : Energy_16 = 0;
2050 252 : move16();
2051 : /*exp = 31-(-exp_L+14 +(2*(*Q_synth)+w_tmp-32)); */
2052 252 : exp = sub( 17, sub( Energy_Q, exp_L ) );
2053 :
2054 252 : IF( Energy != 0 )
2055 : {
2056 252 : exp = norm_l( Energy );
2057 252 : frac = extract_h( L_shl( Energy, exp ) );
2058 : /*exp = sub(exp, 30-(-exp_L+14-2+(2*(*Q_synth)+w_tmp-32))); */
2059 252 : exp = sub( exp, sub( 30, add( sub( Energy_Q, exp_L ), 14 - 2 ) ) );
2060 :
2061 252 : tmp = div_s( 16384, frac );
2062 252 : L_tmp = L_deposit_h( tmp );
2063 252 : Energy = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */
2064 252 : Energy_16 = round_fx( L_shl( Energy, sub( exp, 15 ) ) ); /*Q0 */
2065 : }
2066 :
2067 252 : test();
2068 252 : IF( LT_32( SWB_tenv[i], 65536 /* 2 in Q15 */ ) && LT_32( Energy, L_shl_sat( SWB_tenv[i], sub( 16, exp ) ) ) )
2069 : {
2070 4 : *Q_synth = add( *Q_synth, 3 );
2071 4 : move16();
2072 : }
2073 : ELSE
2074 : {
2075 248 : pit -= shr( L, 2 );
2076 248 : tmp_ener = 0;
2077 248 : move16();
2078 248 : exp = 0;
2079 248 : move16();
2080 :
2081 248 : IF( Energy_16 != 0 )
2082 : {
2083 247 : exp = norm_s( Energy_16 );
2084 247 : tmp_ener = div_s( shl( 1, sub( 14, exp ) ), Energy_16 ); /*Q(29-exp) */
2085 : }
2086 :
2087 248 : L_tmp = Mult_32_16( SWB_tenv[i], tmp_ener ); /*Q(29-exp) */
2088 248 : tmp = round_fx( L_tmp ); /*Q(13-exp) */
2089 :
2090 53368 : FOR( j = 0; j < L / 4; j++ )
2091 : {
2092 53120 : *pit = round_fx_sat( L_shl_sat( L_mult( tmp, *pit ), sub( exp, 1 ) ) ); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */
2093 53120 : move16();
2094 53120 : pit++;
2095 : }
2096 : }
2097 : }
2098 :
2099 63 : return;
2100 : }
2101 :
2102 : /*==========================================================================*/
2103 : /* FUNCTION : void time_reduce_pre_echo_fx() */
2104 : /*--------------------------------------------------------------------------*/
2105 : /* PURPOSE : Windowing and time-domain aliasing */
2106 : /*--------------------------------------------------------------------------*/
2107 : /* INPUT ARGUMENTS */
2108 : /* _(Word16*) synth :ACELP core synthesis Q_syn */
2109 : /* _(Word16) L :subframe length */
2110 : /* _(Word16) Q_syn :Q format */
2111 : /*--------------------------------------------------------------------------*/
2112 : /* OUTPUT ARGUMENTS : */
2113 : /* _(Word16*)error : SHB BWE synthesis Q_syn */
2114 : /* _(Word16)prev_td_energy : last td energy Q_syn */
2115 : /*--------------------------------------------------------------------------*/
2116 : /* INPUT/OUTPUT ARGUMENTS : */
2117 : /* _None */
2118 : /*--------------------------------------------------------------------------*/
2119 : /* RETURN ARGUMENTS : */
2120 : /* _ None */
2121 : /*--------------------------------------------------------------------------*/
2122 96 : void time_reduce_pre_echo_fx(
2123 : const Word16 *synth, /* i : ACELP core synthesis Q_syn*/
2124 : Word16 *error, /* i/o: SHB BWE synthesis Q0*/
2125 : Word16 prev_td_energy, /* o : last td energy Q0*/
2126 : const Word16 L, /* i : subframe length */
2127 : Word16 Q_syn,
2128 : Word16 Q_synth )
2129 : {
2130 96 : Word16 i, j, pos = 0, Len;
2131 : Word32 energy;
2132 : Word16 energy_16;
2133 : Word32 energyL[4];
2134 : Word16 tmp_ener;
2135 : Word16 *pit;
2136 : Word16 tmpi, tmp_exp;
2137 : Word16 exp_L, exp, frac, inv_L, exp_j, tmp;
2138 : Word32 L_tmp, L_tmp1, Ltmp_ener;
2139 :
2140 96 : exp_L = norm_s( L );
2141 96 : inv_L = div_s( shl( 1, sub( 14, exp_L ) ), L ); /*Q(29-exp_L) */
2142 480 : FOR( i = 0; i < 4; i++ )
2143 : {
2144 384 : Len = i_mult( L, i );
2145 :
2146 384 : L_tmp = L_deposit_l( 0 );
2147 87424 : FOR( j = 0; j < L; j++ )
2148 : {
2149 87040 : L_tmp = L_mac0_sat( L_tmp, synth[Len + j], synth[Len + j] ); /*2*Q_syn */
2150 : }
2151 384 : energyL[i] = Mult_32_16( L_shr( L_tmp, sub( 14, exp_L ) ), inv_L );
2152 384 : move32(); /*Q(2*Q_syn +29-exp_L-15 - (14-exp_L) ) -> Q(2*Q_syn) */
2153 :
2154 384 : IF( energyL[i] != 0 )
2155 : {
2156 352 : exp = norm_l( energyL[i] );
2157 352 : frac = extract_h( L_shl( energyL[i], exp ) );
2158 352 : exp = sub( exp, sub( 30, shl( Q_syn, 1 ) ) );
2159 :
2160 352 : tmp = div_s( 16384, frac );
2161 352 : L_tmp = L_deposit_h( tmp );
2162 352 : L_tmp = Isqrt_lc( L_tmp, &exp );
2163 352 : energyL[i] = L_shl( L_tmp, sub( exp, 16 ) );
2164 352 : move32(); /* Q15 */
2165 : }
2166 : }
2167 :
2168 363 : FOR( i = 0; i < 3; i++ )
2169 : {
2170 278 : L_tmp = Mult_32_16( energyL[i], 29491 /* 0.9 in Q15 */ ); /*Q14 */
2171 278 : IF( GT_32( L_shr( energyL[i + 1], 1 ), L_tmp ) && GT_32( energyL[i + 1], 1638400 /* 100 in Q14 */ ) )
2172 : {
2173 11 : pos = add( i, 1 );
2174 11 : move16();
2175 11 : BREAK;
2176 : }
2177 : }
2178 :
2179 96 : IF( pos > 0 )
2180 : {
2181 11 : IF( LT_16( pos, 3 ) )
2182 : {
2183 6 : pos = add( pos, 1 );
2184 : }
2185 11 : energy = L_deposit_l( 0 );
2186 11 : j = i_mult( L, pos );
2187 6971 : FOR( i = 0; i < j; i++ )
2188 : {
2189 6960 : energy = L_mac0_sat( energy, error[i], error[i] ); /*Q(2*Q_synth) */
2190 : }
2191 :
2192 11 : exp_j = norm_s( j );
2193 11 : tmp = div_s( shl( 1, sub( 14, exp_j ) ), j ); /*Q(29-exp_j) */
2194 11 : energy = Mult_32_16( energy, tmp ); /*Q(29-exp_j+1-16) -> Q(-exp_j+14 +2*Q_synth) */
2195 11 : energy_16 = 0;
2196 11 : move16();
2197 :
2198 11 : IF( energy != 0 )
2199 : {
2200 11 : exp = norm_l( energy );
2201 11 : frac = extract_h( L_shl( energy, exp ) );
2202 : /*exp = sub(exp, 30-(-exp_j+14 +2*Q_synth)); */
2203 11 : exp = sub( exp, sub( 14, sub( shl( Q_synth, 1 ), exp_j ) ) );
2204 11 : tmp = div_s( 16384, frac );
2205 11 : L_tmp = L_deposit_h( tmp );
2206 11 : energy = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */
2207 11 : energy_16 = round_fx( L_shl( energy, sub( exp, 15 ) ) ); /*Q0 */
2208 : }
2209 :
2210 11 : tmp = mult_r( energy_16, 6554 /* 0.2 in Q15 */ ); /*Q0 */
2211 11 : if ( LT_16( prev_td_energy, tmp ) )
2212 : {
2213 8 : prev_td_energy = tmp;
2214 8 : move16();
2215 : }
2216 :
2217 11 : tmp_ener = 0;
2218 11 : move16();
2219 11 : exp = 0;
2220 11 : move16();
2221 11 : IF( energy_16 != 0 )
2222 : {
2223 11 : exp = norm_s( energy_16 );
2224 11 : tmp_ener = div_s( shl( 1, sub( 14, exp ) ), energy_16 ); /*Q(29-exp) */
2225 : }
2226 11 : L_tmp = L_mult( prev_td_energy, tmp_ener ); /*Q(30-exp) */
2227 11 : tmp_exp = add( 1, exp );
2228 6971 : FOR( i = 0; i < j; i++ )
2229 : {
2230 6960 : error[i] = round_fx_sat( L_shl_sat( Mult_32_16( L_tmp, error[i] ), tmp_exp ) ); /*Q(30-exp+1-16)->Q(15-exp)->Q_synth */
2231 6960 : move16();
2232 : }
2233 :
2234 11 : energy = L_deposit_l( 0 );
2235 2651 : FOR( i = j; i < ( j + L ); i++ )
2236 : {
2237 2640 : energy = L_mac0_sat( energy, error[i], error[i] ); /*(2*Q_synth) */
2238 : }
2239 :
2240 11 : energy = Mult_32_16( energy, inv_L ); /*Q(29-exp_L+1-16) -> Q(-exp_L+14) */
2241 11 : energy_16 = 0;
2242 11 : move16();
2243 11 : IF( energy != 0 )
2244 : {
2245 11 : exp = norm_l( energy );
2246 11 : frac = extract_h( L_shl( energy, exp ) );
2247 : /*exp = sub(exp, 30-(-exp_L+14+2*Q_synth)); */
2248 11 : exp = sub( exp, sub( 14, sub( shl( Q_synth, 1 ), exp_L ) ) );
2249 :
2250 11 : tmp = div_s( 16384, frac );
2251 11 : L_tmp = L_deposit_h( tmp );
2252 11 : energy = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */
2253 11 : energy_16 = round_fx( L_shl( energy, sub( exp, 15 ) ) ); /*Q0 */
2254 : }
2255 :
2256 11 : tmp_ener = 0;
2257 11 : move16();
2258 11 : exp = 0;
2259 11 : move16();
2260 11 : IF( energy_16 != 0 )
2261 : {
2262 11 : exp = norm_s( energy_16 );
2263 11 : tmp_ener = div_s( shl( 1, sub( 14, exp ) ), energy_16 ); /*Q(29-exp) */
2264 : }
2265 11 : Ltmp_ener = L_mult( prev_td_energy, tmp_ener ); /*Q(30-exp) */
2266 11 : L_tmp1 = L_shl( 1, sub( 30, exp ) );
2267 :
2268 11 : pit = &error[j];
2269 11 : move16();
2270 2651 : FOR( i = 0; i < L; i++ )
2271 : {
2272 2640 : tmpi = round_fx( L_shl( L_mult( i, inv_L ), add( 1, exp_L ) ) ); /*Q15 */
2273 2640 : L_tmp = L_sub( L_tmp1, Ltmp_ener ); /*Q(30-exp) */
2274 2640 : L_tmp = Mult_32_16( L_tmp, tmpi ); /*Q(30-exp) */
2275 2640 : L_tmp = L_add( Ltmp_ener, L_tmp ); /*Q(30-exp) */
2276 2640 : tmp = round_fx_sat( L_shl_sat( Mult_32_16( L_tmp, *pit ), add( 1, exp ) ) ); /*Q0 */
2277 2640 : *pit++ = tmp;
2278 2640 : move16();
2279 : }
2280 : }
2281 :
2282 96 : return;
2283 : }
2284 :
2285 : /*-------------------------------------------------------------------*
2286 : * calc_normal_length_fx_32()
2287 : *
2288 : *-------------------------------------------------------------------*/
2289 7583 : void calc_normal_length_fx_32(
2290 : const Word16 core, /* i : core : Q0 */
2291 : const Word32 *sp, /* i : input signal : Q12 */
2292 : const Word16 mode, /* i : input mode : Q0 */
2293 : const Word16 extl, /* i : extension layer : Q0 */
2294 : Word16 *L_swb_norm, /* o : normalize length : Q0 */
2295 : Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */
2296 : )
2297 : {
2298 : Word16 i, n_freq, n_band, THRES;
2299 : Word16 L_swb_norm_trans, L_swb_norm_norm, L_swb_norm_harm, L_swb_norm_cur;
2300 : Word16 N;
2301 :
2302 : const Word32 *pit;
2303 : Word32 peak, mean, mag;
2304 : Word32 L_tmp1, L_tmp2;
2305 :
2306 7583 : THRES = 4;
2307 7583 : move16();
2308 7583 : test();
2309 7583 : test();
2310 7583 : if ( EQ_16( core, HQ_CORE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) )
2311 : {
2312 7583 : THRES = 8;
2313 7583 : move16();
2314 : }
2315 :
2316 7583 : N = 16;
2317 7583 : move16();
2318 7583 : test();
2319 7583 : test();
2320 7583 : if ( EQ_16( core, HQ_CORE ) && ( EQ_16( mode, HQ_HARMONIC ) || EQ_16( mode, HQ_HVQ ) ) )
2321 : {
2322 1957 : N = 13;
2323 1957 : move16();
2324 : }
2325 :
2326 7583 : n_band = 0;
2327 7583 : move16();
2328 7583 : pit = sp;
2329 :
2330 123040 : FOR( i = 0; i < N; i++ )
2331 : {
2332 115457 : peak = 0;
2333 115457 : move16();
2334 115457 : mean = 0;
2335 115457 : move16();
2336 :
2337 1962769 : FOR( n_freq = 0; n_freq < 16; n_freq++ )
2338 : {
2339 1847312 : mag = L_abs( *pit );
2340 1847312 : if ( GT_32( mag, peak ) )
2341 : {
2342 381384 : peak = mag;
2343 381384 : move16();
2344 : }
2345 1847312 : mean = L_add_sat( mean, mag );
2346 1847312 : pit++;
2347 : }
2348 :
2349 115457 : L_tmp1 = Mult_32_16( peak, shl( add( 15, THRES ), 10 ) );
2350 115457 : L_tmp2 = Mult_32_16( mean, shl( THRES, 10 ) );
2351 115457 : test();
2352 115457 : IF( GT_32( L_tmp1, L_tmp2 ) && GT_32( peak, 40960 /* 10 in Q12 */ ) )
2353 : {
2354 26245 : n_band = add( n_band, 1 );
2355 : }
2356 : }
2357 :
2358 7583 : IF( core == ACELP_CORE )
2359 : {
2360 0 : L_swb_norm_trans = add( 4, shr( n_band, 2 ) );
2361 0 : L_swb_norm_norm = add( 8, shr( n_band, 1 ) );
2362 0 : L_swb_norm_harm = s_max( add( 32, shl( n_band, 1 ) ), 24 );
2363 :
2364 0 : IF( EQ_16( mode, HARMONIC ) )
2365 : {
2366 0 : L_swb_norm_cur = L_swb_norm_harm;
2367 0 : move16();
2368 : }
2369 0 : ELSE IF( EQ_16( mode, NORMAL ) )
2370 : {
2371 0 : L_swb_norm_cur = L_swb_norm_norm;
2372 0 : move16();
2373 : }
2374 : ELSE
2375 : {
2376 0 : L_swb_norm_cur = L_swb_norm_trans;
2377 0 : move16();
2378 : }
2379 :
2380 0 : *L_swb_norm = shr( add( L_swb_norm_cur, *prev_L_swb_norm ), 1 );
2381 0 : move16();
2382 0 : *prev_L_swb_norm = L_swb_norm_cur;
2383 0 : move16();
2384 : }
2385 : ELSE
2386 : {
2387 7583 : test();
2388 7583 : IF( EQ_16( mode, HQ_HARMONIC ) || EQ_16( mode, HQ_HVQ ) )
2389 : {
2390 1957 : L_swb_norm_cur = add( 32, add( shl( n_band, 1 ), shr( n_band, 1 ) ) );
2391 : }
2392 : ELSE
2393 : {
2394 5626 : L_swb_norm_cur = add( 8, shr( n_band, 1 ) );
2395 : }
2396 :
2397 7583 : *L_swb_norm = extract_h( L_add( L_mac( L_mult( L_swb_norm_cur, 3276 /* 0.1 in Q15 */ ), *prev_L_swb_norm, 29491 /* 0.9 in Q15 */ ), 32768 /* 1 in Q15 */ ) );
2398 7583 : *prev_L_swb_norm = L_swb_norm_cur;
2399 7583 : move16();
2400 7583 : move16();
2401 : }
2402 :
2403 7583 : return;
2404 : }
2405 :
2406 :
2407 : /*-------------------------------------------------------------------*
2408 : * calc_norm_envelop_fx_32()
2409 : *
2410 : *-------------------------------------------------------------------*/
2411 2837 : void calc_norm_envelop_fx_32(
2412 : const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */
2413 : Word32 *envelope_fx, /* o : normalized envelope : Q16 */
2414 : const Word16 L_swb_norm, /* i : length of envelope : Q0 */
2415 : const Word16 SWB_flength, /* i : Length of input/output : Q0 */
2416 : const Word16 st_offset /* i : offset : Q0 */
2417 : )
2418 : {
2419 : Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp;
2420 :
2421 2837 : lookback = shr( L_swb_norm, 1 );
2422 2837 : move16();
2423 2837 : env_index = add( swb_bwe_subband[0], st_offset );
2424 2837 : move16();
2425 2837 : n_lag_now = L_swb_norm;
2426 2837 : move16();
2427 2837 : tmp = sub( add( SWB_flength, st_offset ), L_swb_norm );
2428 896374 : FOR( n_freq = sub( add( swb_bwe_trans_subband[0], st_offset ), lookback ); n_freq < tmp; n_freq++ )
2429 : {
2430 : /* Apply MA filter */
2431 893537 : envelope_fx[env_index] = 0;
2432 893537 : move16();
2433 9524652 : FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ )
2434 : {
2435 8631115 : envelope_fx[env_index] = L_add_sat( envelope_fx[env_index], L_abs( SWB_signal_fx[n_freq + n_lag] ) );
2436 8631115 : move32();
2437 : }
2438 893537 : env_index = add( env_index, 1 );
2439 : }
2440 2837 : i = 0;
2441 2837 : move16();
2442 2837 : tmp = sub( add( SWB_flength, st_offset ), lookback );
2443 17140 : FOR( n_freq = sub( add( SWB_flength, st_offset ), L_swb_norm ); n_freq < tmp; n_freq++ )
2444 : {
2445 : Word32 L_tmp;
2446 :
2447 14303 : n_lag_now = sub( L_swb_norm, i );
2448 14303 : move16();
2449 : /* Apply MA filter */
2450 14303 : L_tmp = L_deposit_l( 0 );
2451 126108 : FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ )
2452 : {
2453 111805 : L_tmp = L_add( L_tmp, L_abs( SWB_signal_fx[n_freq + n_lag] ) );
2454 : }
2455 14303 : envelope_fx[env_index] = L_tmp;
2456 14303 : move32();
2457 14303 : env_index = add( env_index, 1 );
2458 14303 : i++;
2459 : }
2460 :
2461 2837 : return;
2462 : }
2463 :
2464 : /*-------------------------------------------------------------------*
2465 : * hq_generic_decoding_fx()
2466 : *
2467 : *-------------------------------------------------------------------*/
2468 46 : void hq_generic_decoding_fx(
2469 : const Word16 HQ_mode, /* i : HQ mode : Q0 */
2470 : Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer : Q12 */
2471 : const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes : Q1 */
2472 : Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain : Q12 */
2473 : const Word16 hq_generic_offset, /* i : frequency offset for representing hq generci : Q0 */
2474 : Word16 *prev_L_swb_norm, /* i/o: last normalize length : Q0 */
2475 : const Word16 hq_generic_exc_clas, /* i : bwe excitation class " Q0 */
2476 : const Word16 *R )
2477 : {
2478 : Word16 i, n_freq, n_band, L_swb_norm;
2479 : Word16 k;
2480 : Word16 nenv;
2481 : Word16 tenv;
2482 :
2483 : Word16 exp, exp1, exp2, frac, tmp, tmp2, cs;
2484 : Word32 L_tmp, L_tmp1, L_tmp2, max_coeff_fx;
2485 : Word16 fenvL_fx, wfenv_fx, factor_fx;
2486 : Word32 *pit1_fx;
2487 : Word16 tmp1_fx, tmp2_fx, tmp3_fx, tmp4_fx;
2488 : Word32 energy_fx;
2489 :
2490 : Word32 envelope_fx[L_FRAME16k];
2491 : Word32 mean_vector_fx[20];
2492 : Word16 rn_weight0_fx;
2493 : Word16 s;
2494 : Word16 blen, nband_lf, sfidx, efidx;
2495 : Word16 bwe_seed;
2496 : Word16 signum[L_FRAME16k];
2497 :
2498 46 : nenv = sub( SWB_FENV, 2 );
2499 46 : if ( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) )
2500 : {
2501 46 : nenv = SWB_FENV;
2502 46 : move16();
2503 : }
2504 :
2505 46 : tenv = nenv;
2506 46 : move16();
2507 46 : if ( EQ_16( HQ_mode, HQ_GEN_FB ) )
2508 : {
2509 0 : tenv = add( nenv, DIM_FB );
2510 : }
2511 :
2512 46 : max_coeff_fx = 0;
2513 46 : move16();
2514 46 : tmp = add( swb_bwe_subband[0], hq_generic_offset );
2515 782 : FOR( n_freq = add( HQ_GENERIC_ST_FREQ, hq_generic_offset ); n_freq < tmp; n_freq++ )
2516 : {
2517 736 : max_coeff_fx = L_max( max_coeff_fx, L_abs( coeff_out1_fx[n_freq] ) );
2518 : }
2519 46 : cs = norm_l( max_coeff_fx );
2520 :
2521 46 : L_tmp = 0;
2522 46 : move16();
2523 46 : tmp2 = add( swb_bwe_subband[0], hq_generic_offset );
2524 782 : FOR( n_freq = add( HQ_GENERIC_ST_FREQ, hq_generic_offset ); n_freq < tmp2; n_freq++ )
2525 : {
2526 736 : tmp = extract_h( L_shl( coeff_out1_fx[n_freq], cs ) ); /*12 + cs - 16 */
2527 736 : L_tmp1 = L_mult0( tmp, tmp ); /*2*(cs-2) */
2528 736 : L_tmp = L_add( L_tmp, L_shr( L_tmp1, 5 ) ); /*2*(cs-2) - 5 */
2529 : }
2530 46 : cs = sub( shl( cs, 1 ), 9 );
2531 46 : fenvL_fx = 0;
2532 46 : move16();
2533 46 : IF( L_tmp != 0 )
2534 : {
2535 46 : exp = norm_l( L_tmp );
2536 46 : frac = round_fx_sat( L_shl( L_tmp, exp ) ); /*cs+exp-16 */
2537 46 : tmp = div_s( 16384, frac ); /*15 + 14 - (cs+exp-16) */
2538 46 : exp = sub( add( cs, exp ), 30 );
2539 46 : L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /*Q31 - exp */
2540 46 : fenvL_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /*Q1 */
2541 : }
2542 :
2543 46 : calc_normal_length_fx_32( HQ_CORE, coeff_out1_fx, HQ_GEN_SWB, -1, &L_swb_norm, prev_L_swb_norm );
2544 :
2545 46 : calc_norm_envelop_lf_fx( coeff_out1_fx, envelope_fx, &L_swb_norm, HQ_mode, hq_generic_offset, &sfidx, &efidx );
2546 :
2547 46 : blen = 16;
2548 46 : move16();
2549 :
2550 46 : IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC0 ) )
2551 : {
2552 19 : rn_weight0_fx = 819;
2553 19 : move16(); /* 0.8 Q10 */
2554 : }
2555 27 : ELSE IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC1 ) )
2556 : {
2557 0 : rn_weight0_fx = 51;
2558 0 : move16(); /* 0.05 Q10*/
2559 : }
2560 : ELSE
2561 : {
2562 27 : rn_weight0_fx = 205;
2563 27 : move16(); /* 0.02 Q10 */
2564 : }
2565 :
2566 46 : tmp = sub( efidx, sfidx );
2567 46 : IF( tmp == 0 )
2568 : {
2569 0 : nband_lf = 0;
2570 0 : move16();
2571 : }
2572 : ELSE
2573 : {
2574 46 : exp = norm_s( tmp );
2575 46 : nband_lf = shl( tmp, sub( exp, 1 ) );
2576 46 : exp1 = norm_s( blen );
2577 46 : tmp = shl( blen, exp1 );
2578 46 : nband_lf = shr( div_s( nband_lf, tmp ), add( sub( 14, exp1 ), exp ) ); /* 15 + exp-1 - exp1, Q0*/
2579 : }
2580 :
2581 6670 : FOR( n_freq = sfidx; n_freq < efidx; n_freq++ )
2582 : {
2583 6624 : IF( coeff_out1_fx[n_freq] < 0 )
2584 : {
2585 3356 : signum[n_freq] = -1;
2586 3356 : move16();
2587 3356 : coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] );
2588 3356 : move32();
2589 : }
2590 : ELSE
2591 : {
2592 3268 : signum[n_freq] = 1;
2593 3268 : move16();
2594 : }
2595 : }
2596 :
2597 : /* applying whitening */
2598 6670 : FOR( n_freq = sfidx; n_freq < efidx; n_freq++ )
2599 : {
2600 6624 : exp = norm_l( coeff_out1_fx[n_freq] ) - 1;
2601 6624 : exp1 = norm_l( envelope_fx[n_freq] );
2602 :
2603 6624 : L_tmp = L_shl( coeff_out1_fx[n_freq], exp );
2604 6624 : L_tmp1 = L_shl( envelope_fx[n_freq], exp1 );
2605 :
2606 6624 : logic16();
2607 6624 : coeff_out1_fx[n_freq] = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff );
2608 6624 : move32(); /*31 + exp1 - exp2*/
2609 :
2610 6624 : exp = add( 31, sub( exp, exp1 ) );
2611 6624 : coeff_out1_fx[n_freq] = L_shl( coeff_out1_fx[n_freq], sub( 20, exp ) );
2612 6624 : move32(); /*Q12->Q20*/
2613 : }
2614 :
2615 : /* mean vector generation for controlling dynamic range */
2616 460 : FOR( k = 0; k < nband_lf; ++k )
2617 : {
2618 414 : energy_fx = 1;
2619 414 : move16();
2620 :
2621 414 : tmp = add( i_mult2( add( k, 1 ), blen ), sfidx );
2622 7038 : FOR( i = add( i_mult2( k, blen ), sfidx ); i < tmp; ++i )
2623 : {
2624 6624 : energy_fx = L_add( energy_fx, coeff_out1_fx[i] );
2625 : }
2626 414 : exp = sub( norm_l( energy_fx ), 1 );
2627 414 : L_tmp = L_shl( energy_fx, exp );
2628 414 : exp1 = norm_l( L_and( blen, 0x00007fff ) );
2629 414 : L_tmp1 = L_shl( blen, exp1 );
2630 414 : logic16();
2631 414 : mean_vector_fx[k] = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff );
2632 414 : move32(); /*31 + 20 + exp1 - exp2*/
2633 414 : exp = add( 51, sub( exp, exp1 ) );
2634 414 : mean_vector_fx[k] = L_shl( mean_vector_fx[k], sub( 20, exp ) );
2635 414 : move32(); /*Q12->Q20*/
2636 : }
2637 :
2638 : /* dynamics control */
2639 460 : FOR( k = 0; k < nband_lf; ++k )
2640 : {
2641 414 : tmp = add( i_mult2( add( k, 1 ), blen ), sfidx );
2642 7038 : FOR( i = add( i_mult2( k, blen ), sfidx ); i < tmp; ++i )
2643 : {
2644 6624 : L_tmp = L_sub( coeff_out1_fx[i], mean_vector_fx[k] );
2645 6624 : exp = norm_l( L_tmp );
2646 6624 : L_tmp = L_shl( L_tmp, exp ); /* exp+12*/
2647 6624 : exp1 = norm_l( rn_weight0_fx );
2648 6624 : L_tmp1 = L_shl( rn_weight0_fx, exp1 ); /* exp1+10*/
2649 6624 : L_tmp = L_mult( extract_h( L_tmp ), extract_h( L_tmp1 ) );
2650 6624 : L_tmp = L_shr( L_tmp, add( exp, sub( exp1, 21 ) ) ); /* Q20*/
2651 6624 : coeff_out1_fx[i] = L_sub( coeff_out1_fx[i], L_tmp );
2652 6624 : move32();
2653 : }
2654 : }
2655 :
2656 46 : IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC0 ) )
2657 : {
2658 19 : bwe_seed = add( add( shl( R[0], 3 ), shl( R[1], 2 ) ), add( shl( R[2], 1 ), R[3] ) );
2659 :
2660 2755 : FOR( n_freq = sfidx; n_freq < efidx; n_freq++ )
2661 : {
2662 2736 : IF( signum[n_freq] < 0 )
2663 : {
2664 1422 : coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] );
2665 1422 : move32();
2666 : }
2667 :
2668 2736 : IF( Random( &bwe_seed ) < 0 )
2669 : {
2670 1380 : coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] );
2671 1380 : move32();
2672 : }
2673 : }
2674 : }
2675 : ELSE
2676 : {
2677 3915 : FOR( n_freq = sfidx; n_freq < efidx; n_freq++ )
2678 : {
2679 3888 : IF( signum[n_freq] < 0 )
2680 : {
2681 1934 : coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] );
2682 1934 : move32();
2683 : }
2684 : }
2685 : }
2686 :
2687 : /* normalizing modified low frequency spectrum */
2688 460 : FOR( k = 0; k < nband_lf; ++k )
2689 : {
2690 414 : energy_fx = 1;
2691 414 : move16();
2692 414 : tmp = add( i_mult2( add( k, 1 ), blen ), sfidx );
2693 7038 : FOR( i = add( ( i_mult2( k, blen ) ), sfidx ); i < tmp; ++i )
2694 : {
2695 6624 : exp = norm_l( coeff_out1_fx[i] );
2696 6624 : L_tmp1 = L_shl( coeff_out1_fx[i], exp ); /* exp + 12*/
2697 :
2698 6624 : L_tmp = Mult_32_32( L_tmp1, L_tmp1 );
2699 6624 : L_tmp = L_shr( L_tmp, sub( i_mult2( 2, exp ), 11 ) ); /*Q20 */
2700 6624 : energy_fx = L_add( energy_fx, L_tmp );
2701 : }
2702 :
2703 414 : exp = norm_l( energy_fx );
2704 414 : L_tmp = L_shl( energy_fx, sub( exp, 1 ) );
2705 414 : exp1 = norm_s( blen );
2706 414 : L_tmp1 = L_shl( (Word32) blen, add( exp1, 16 ) );
2707 :
2708 414 : L_tmp = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff );
2709 414 : exp = sub( add( 34, exp ), exp1 );
2710 414 : L_tmp = L_shr( L_tmp, sub( exp, 31 ) );
2711 414 : exp = 31;
2712 414 : move16();
2713 :
2714 414 : exp = sub( 31, exp );
2715 414 : IF( exp & 0x1 )
2716 : {
2717 0 : L_tmp = L_shr( L_tmp, 1 );
2718 0 : exp = add( exp, 1 );
2719 : }
2720 414 : L_tmp = Sqrt_l( L_tmp, &exp1 );
2721 414 : exp = add( 31, sub( shr( exp1, 1 ), shr( exp, 1 ) ) );
2722 414 : energy_fx = L_shl( L_tmp, sub( 31, exp ) ); /*Q31*/
2723 :
2724 414 : tmp = add( i_mult2( add( k, 1 ), blen ), sfidx );
2725 7038 : FOR( i = add( ( i_mult2( k, blen ) ), sfidx ); i < tmp; ++i )
2726 : {
2727 6624 : IF( NE_32( L_abs( coeff_out1_fx[i] ), coeff_out1_fx[i] ) )
2728 : {
2729 3310 : s = -1;
2730 3310 : move16();
2731 3310 : coeff_out1_fx[i] = L_abs( coeff_out1_fx[i] );
2732 3310 : move32();
2733 : }
2734 : ELSE
2735 : {
2736 3314 : s = 0;
2737 3314 : move16();
2738 : }
2739 6624 : exp = norm_l( coeff_out1_fx[i] );
2740 6624 : L_tmp = L_shl( coeff_out1_fx[i], sub( exp, 1 ) );
2741 6624 : exp1 = norm_l( energy_fx );
2742 6624 : L_tmp1 = L_shl( (Word32) energy_fx, exp1 );
2743 6624 : logic16();
2744 6624 : L_tmp = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff );
2745 6624 : exp = add( sub( 19, exp1 ), exp );
2746 6624 : coeff_out1_fx[i] = L_shl( L_tmp, add( sub( 12, exp ), 15 ) );
2747 6624 : move32(); /* Q12 -> Q27 */
2748 6624 : IF( s )
2749 : {
2750 3310 : coeff_out1_fx[i] = L_negate( coeff_out1_fx[i] );
2751 3310 : move32();
2752 : }
2753 : }
2754 : }
2755 :
2756 46 : Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[HQ_GENERIC_HIGH0 + hq_generic_offset], HQ_GENERIC_LEN0 );
2757 46 : Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset], HQ_GENERIC_LEN0 );
2758 :
2759 46 : IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) )
2760 : {
2761 46 : Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0], &coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset], HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2 );
2762 : }
2763 :
2764 46 : IF( EQ_16( HQ_mode, HQ_GEN_FB ) )
2765 : {
2766 0 : IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) )
2767 : {
2768 0 : Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0 + HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2], &coeff_out_fx[fb_bwe_subband[0]], 160 );
2769 : }
2770 : ELSE
2771 : {
2772 0 : Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET + HQ_GENERIC_LEN0], &coeff_out_fx[fb_bwe_subband[0]], 160 );
2773 : }
2774 : }
2775 :
2776 :
2777 46 : L_tmp1 = L_deposit_l( 0 );
2778 46 : L_tmp2 = L_deposit_l( 0 );
2779 276 : FOR( i = 0; i < 5; ++i )
2780 : {
2781 230 : L_tmp1 = L_add( L_tmp1, L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset + i] ) );
2782 230 : L_tmp2 = L_add( L_tmp2, L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 - 2 + hq_generic_offset - i] ) );
2783 : }
2784 :
2785 46 : pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset];
2786 46 : L_tmp1 = L_max( L_tmp1, 1 );
2787 46 : L_tmp2 = L_max( L_tmp2, 1 );
2788 46 : exp1 = norm_l( L_tmp1 );
2789 46 : exp2 = sub( norm_l( L_tmp2 ), 1 );
2790 46 : tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) );
2791 46 : tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) );
2792 46 : tmp3_fx = div_s( tmp2_fx, tmp1_fx ); /*15 + exp2 + 15 - (exp1 + 15) */
2793 46 : tmp3_fx = shr( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */
2794 :
2795 46 : if ( LT_16( tmp3_fx, 307 /*0.3 in Q10 */ ) )
2796 : {
2797 0 : tmp3_fx = 307 /*0.3 in Q10 */;
2798 0 : move16();
2799 : }
2800 88 : FOR( ; tmp3_fx < 1024; tmp3_fx += 102 )
2801 : {
2802 42 : *pit1_fx = Mult_32_16( *pit1_fx, shl( tmp3_fx, 5 ) );
2803 42 : move32(); /*15 + 5 + 10 -15 */
2804 42 : pit1_fx++;
2805 : }
2806 :
2807 46 : pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 - 1 + hq_generic_offset];
2808 :
2809 46 : exp1 = sub( norm_l( L_tmp1 ), 1 );
2810 46 : exp2 = norm_l( L_tmp2 );
2811 46 : tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) );
2812 46 : tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) );
2813 46 : tmp3_fx = div_s( tmp1_fx, tmp2_fx ); /*15 + exp2 + 15 - (exp1 + 15) */
2814 46 : tmp3_fx = shr( tmp3_fx, add( 5, sub( exp1, exp2 ) ) ); /*10 */
2815 :
2816 46 : IF( GT_16( tmp3_fx, 5120 ) )
2817 : {
2818 0 : FOR( tmp3_fx = 5120; tmp3_fx > 1024; tmp3_fx -= 512 )
2819 : {
2820 : /* Adding saturation suggested as fix for issue #957 */
2821 0 : L_tmp1 = L_shl_sat( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */
2822 0 : *pit1_fx-- = L_tmp1;
2823 0 : move32();
2824 : }
2825 : }
2826 :
2827 46 : IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) )
2828 : {
2829 46 : L_tmp1 = L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset] ), L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 + 1 + hq_generic_offset] ) );
2830 46 : L_tmp2 = L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 4 + hq_generic_offset] ), L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 3 + hq_generic_offset] ),
2831 46 : L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 2 + hq_generic_offset] ), L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 1 + hq_generic_offset] ) ) ) );
2832 :
2833 46 : pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset];
2834 :
2835 46 : L_tmp1 = L_max( L_tmp1, 1 );
2836 46 : L_tmp2 = L_max( L_tmp2, 1 );
2837 46 : exp1 = norm_l( L_tmp1 );
2838 46 : exp2 = sub( norm_l( L_tmp2 ), 1 );
2839 46 : tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) );
2840 46 : tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) );
2841 46 : tmp3_fx = div_s( tmp2_fx, tmp1_fx ); /*15 + exp2 + 15 - (exp1 + 15) */
2842 46 : tmp3_fx = shr_sat( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */
2843 46 : if ( LT_16( tmp3_fx, 307 /* 0.3 in Q10*/ ) )
2844 : {
2845 0 : tmp3_fx = 307; /* 0.3 in Q10*/
2846 0 : move16();
2847 : }
2848 51 : FOR( ; tmp3_fx < 1024; tmp3_fx += 102 )
2849 : {
2850 5 : L_tmp = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */
2851 5 : *pit1_fx++ = L_tmp;
2852 5 : move32();
2853 : }
2854 :
2855 46 : pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH2 - 1 + hq_generic_offset];
2856 :
2857 46 : exp1 = sub( norm_l( L_tmp1 ), 1 );
2858 46 : exp2 = norm_l( L_tmp2 );
2859 46 : tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) );
2860 46 : tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) );
2861 46 : tmp3_fx = div_s( tmp1_fx, tmp2_fx ); /*15 + exp2 + 15 - (exp1 + 15) */
2862 46 : tmp3_fx = shr( tmp3_fx, add( 5, sub( exp1, exp2 ) ) ); /*10 */
2863 46 : tmp3_fx = shr( tmp3_fx, 1 );
2864 46 : tmp4_fx = mult_r( tmp3_fx, 1638 /* 0.05 in Q15 */ );
2865 46 : WHILE( tmp3_fx > 1024 /* 1 in Q10*/ )
2866 : {
2867 0 : L_tmp1 = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */
2868 0 : *pit1_fx-- = L_tmp1;
2869 0 : move32();
2870 0 : tmp3_fx = sub( tmp3_fx, tmp4_fx );
2871 : }
2872 : }
2873 :
2874 :
2875 46 : wfenv_fx = hq_generic_fenv_fx[0];
2876 46 : move16(); /*1 */
2877 46 : i = 0;
2878 46 : move16();
2879 46 : tmp2 = add( add( swb_bwe_subband[0], hq_generic_offset ), 8 );
2880 414 : FOR( n_freq = add( swb_bwe_subband[0], hq_generic_offset ); n_freq < tmp2; n_freq++ )
2881 : {
2882 368 : factor_fx = shl( i, 12 ); /*15 */
2883 368 : L_tmp1 = L_mult( sub( 32767, factor_fx ), fenvL_fx ); /*17 */
2884 368 : L_tmp2 = L_mult( factor_fx, wfenv_fx ); /*17 */
2885 368 : L_tmp1 = L_add( L_tmp1, L_tmp2 ); /*17 */
2886 :
2887 368 : cs = norm_l( L_tmp1 );
2888 368 : tmp = extract_h( L_shl( L_tmp1, cs ) ); /*17 + cs - 16 */
2889 368 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 17 + cs - 16 - 15 */
2890 368 : coeff_out_fx[n_freq] = L_shr( L_tmp, add( 1, cs ) );
2891 368 : move32(); /*12 */
2892 368 : i++;
2893 368 : move16();
2894 : }
2895 :
2896 46 : k = sub( nenv, 2 );
2897 598 : FOR( n_band = 0; n_band < k; n_band++ )
2898 : {
2899 552 : wfenv_fx = hq_generic_fenv_fx[n_band + 1];
2900 552 : move16(); /*1 */
2901 :
2902 552 : tmp2 = swb_bwe_sm_subband[n_band + 1] + hq_generic_offset;
2903 12696 : FOR( i = 0; n_freq < tmp2; i++ )
2904 : {
2905 12144 : L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[n_band] ), smooth_factor_fx[n_band] ); /*17 */
2906 12144 : L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */
2907 12144 : L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[n_band], 11 ) ); /*12 */
2908 :
2909 12144 : cs = norm_l( L_tmp1 );
2910 12144 : tmp = extract_h( L_shl( L_tmp1, cs ) ); /*12 + cs - 16 */
2911 12144 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 12 + cs - 16 - 15 */
2912 12144 : coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 4, cs ) );
2913 12144 : move32(); /*12 */
2914 12144 : n_freq++;
2915 : }
2916 : }
2917 :
2918 46 : wfenv_fx = hq_generic_fenv_fx[nenv - 1];
2919 46 : move16(); /*1 */
2920 46 : tmp2 = add( swb_bwe_sm_subband[nenv - 1], hq_generic_offset );
2921 1518 : FOR( i = 0; n_freq < tmp2; i++ )
2922 : {
2923 1472 : L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[nenv - 2] ), smooth_factor_fx[nenv - 2] ); /*17 */
2924 1472 : L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */
2925 1472 : L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[nenv - 2], 11 ) ); /*12 */
2926 :
2927 1472 : cs = norm_l( L_tmp1 );
2928 1472 : tmp = extract_h( L_shl( L_tmp1, cs ) ); /*12 + cs - 16 */
2929 1472 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 12 + cs - 16 - 15 */
2930 1472 : coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 4, cs ) );
2931 1472 : move32(); /*12 */
2932 1472 : n_freq++;
2933 : }
2934 :
2935 46 : IF( EQ_16( HQ_mode, HQ_GEN_SWB ) )
2936 : {
2937 92 : FOR( n_band = sub( nenv, 1 ); n_band < nenv; ++n_band )
2938 : {
2939 46 : wfenv_fx = hq_generic_fenv_fx[n_band];
2940 46 : move16(); /*1 */
2941 46 : tmp2 = add( swb_bwe_subband[n_band + 1], hq_generic_offset );
2942 782 : FOR( ; n_freq < tmp2; n_freq++ )
2943 : {
2944 736 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */
2945 736 : coeff_out_fx[n_freq] = L_shr( L_tmp, 1 );
2946 736 : move32(); /*12 */
2947 : }
2948 : }
2949 : }
2950 : ELSE
2951 : {
2952 0 : test();
2953 0 : IF( GT_16( sub( hq_generic_fenv_fx[nenv - 1], hq_generic_fenv_fx[nenv] ), 30 ) || LT_16( hq_generic_fenv_fx[nenv], 10 ) )
2954 : {
2955 0 : wfenv_fx = hq_generic_fenv_fx[nenv - 1];
2956 0 : move16(); /*1 */
2957 0 : FOR( i = 0; n_freq < fb_bwe_subband[0]; i++ )
2958 : {
2959 0 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */
2960 0 : coeff_out_fx[n_freq] = L_shr( L_tmp, 1 );
2961 0 : move32(); /*12 */
2962 0 : n_freq++;
2963 : }
2964 :
2965 0 : FOR( n_band = 0; n_band < DIM_FB; n_band++ )
2966 : {
2967 0 : wfenv_fx = hq_generic_fenv_fx[n_band + nenv];
2968 0 : move16(); /*1 */
2969 0 : tmp2 = fb_bwe_subband[n_band + 1];
2970 0 : FOR( i = 0; n_freq < tmp2; i++ )
2971 : {
2972 0 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */
2973 0 : coeff_out_fx[n_freq] = L_shr( L_tmp, 1 );
2974 0 : move32(); /*12 */
2975 0 : n_freq++;
2976 : }
2977 : }
2978 : }
2979 : ELSE
2980 : {
2981 0 : FOR( n_band = 0; n_band < DIM_FB; n_band++ )
2982 : {
2983 0 : wfenv_fx = hq_generic_fenv_fx[n_band + nenv - 1];
2984 0 : move16(); /*1 */
2985 :
2986 0 : FOR( i = 0; n_freq < fb_bwe_sm_subband[n_band]; i++ )
2987 : {
2988 0 : L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[n_band + nenv] ), fb_smooth_factor_fx[n_band] ); /*17 */
2989 0 : L_tmp1 = Mult_32_16( L_tmp1, shl( i, 9 ) ); /*17 + 9 - 15 */
2990 0 : L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[n_band + nenv], 10 ) ); /*11 */
2991 :
2992 0 : cs = norm_l( L_tmp1 );
2993 0 : tmp = extract_h( L_shl( L_tmp1, cs ) ); /*11 + cs - 16 */
2994 0 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 11 + cs - 16 - 15 */
2995 0 : coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 5, cs ) );
2996 0 : move32(); /*12 */
2997 0 : n_freq = add( n_freq, 1 );
2998 : }
2999 : }
3000 :
3001 0 : wfenv_fx = hq_generic_fenv_fx[tenv - 1];
3002 0 : move16(); /*1 */
3003 :
3004 0 : FOR( ; n_freq < fb_bwe_subband[DIM_FB]; n_freq++ )
3005 : {
3006 0 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */
3007 0 : coeff_out_fx[n_freq] = L_shr( L_tmp, 1 );
3008 0 : move32(); /*12 */
3009 : }
3010 : }
3011 : }
3012 :
3013 46 : return;
3014 : }
3015 :
3016 2743 : void hq_generic_decoding_ivas_fx(
3017 : const Word16 HQ_mode, /* i : HQ mode : Q0 */
3018 : Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer : Q12 */
3019 : const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes : Q1 */
3020 : Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain : Q12 */
3021 : const Word16 hq_generic_offset, /* i : frequency offset for representing hq generci : Q0 */
3022 : Word16 *prev_L_swb_norm, /* i/o: last normalize length : Q0 */
3023 : const Word16 hq_generic_exc_clas, /* i : bwe excitation class " Q0 */
3024 : const Word16 *R )
3025 : {
3026 : Word16 i, n_freq, n_band, L_swb_norm;
3027 : Word16 k;
3028 : Word16 nenv;
3029 : Word16 tenv;
3030 :
3031 : Word16 exp, exp1, exp2, frac, tmp, tmp2, cs;
3032 : Word32 L_tmp, L_tmp1, L_tmp2, max_coeff_fx;
3033 : Word16 fenvL_fx, wfenv_fx, factor_fx;
3034 : Word32 *pit1_fx;
3035 : Word16 tmp1_fx, tmp2_fx, tmp3_fx, tmp4_fx;
3036 : Word32 energy_fx;
3037 :
3038 : Word32 envelope_fx[L_FRAME16k];
3039 : Word32 mean_vector_fx[20];
3040 : Word16 rn_weight0_fx;
3041 : Word16 s;
3042 : Word16 blen, nband_lf, sfidx, efidx;
3043 : Word16 bwe_seed;
3044 : Word16 signum[L_FRAME16k];
3045 :
3046 2743 : nenv = sub( SWB_FENV, 2 );
3047 2743 : if ( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) )
3048 : {
3049 2743 : nenv = SWB_FENV;
3050 2743 : move16();
3051 : }
3052 :
3053 2743 : tenv = nenv;
3054 2743 : move16();
3055 2743 : if ( EQ_16( HQ_mode, HQ_GEN_FB ) )
3056 : {
3057 2070 : tenv = add( nenv, DIM_FB );
3058 : }
3059 :
3060 2743 : max_coeff_fx = 0;
3061 2743 : move16();
3062 2743 : tmp = add( swb_bwe_subband[0], hq_generic_offset );
3063 46631 : FOR( n_freq = add( HQ_GENERIC_ST_FREQ, hq_generic_offset ); n_freq < tmp; n_freq++ )
3064 : {
3065 43888 : max_coeff_fx = L_max( max_coeff_fx, L_abs( coeff_out1_fx[n_freq] ) );
3066 : }
3067 2743 : cs = norm_l( max_coeff_fx );
3068 :
3069 2743 : L_tmp = 0;
3070 2743 : move16();
3071 2743 : tmp2 = add( swb_bwe_subband[0], hq_generic_offset );
3072 46631 : FOR( n_freq = add( HQ_GENERIC_ST_FREQ, hq_generic_offset ); n_freq < tmp2; n_freq++ )
3073 : {
3074 43888 : tmp = extract_h( L_shl( coeff_out1_fx[n_freq], cs ) ); /*12 + cs - 16 */
3075 43888 : L_tmp1 = L_mult0( tmp, tmp ); /*2*(cs-2) */
3076 43888 : L_tmp = L_add( L_tmp, L_shr( L_tmp1, 5 ) ); /*2*(cs-2) - 5 */
3077 : }
3078 2743 : cs = sub( shl( cs, 1 ), 9 );
3079 2743 : fenvL_fx = 0;
3080 2743 : move16();
3081 2743 : IF( L_tmp != 0 )
3082 : {
3083 2743 : exp = norm_l( L_tmp );
3084 2743 : frac = round_fx_sat( L_shl( L_tmp, exp ) ); /*cs+exp-16 */
3085 2743 : tmp = div_s( 16384, frac ); /*15 + 14 - (cs+exp-16) */
3086 2743 : exp = sub( add( cs, exp ), 30 );
3087 2743 : L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /*Q31 - exp */
3088 2743 : fenvL_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /*Q1 */
3089 : }
3090 :
3091 2743 : calc_normal_length_fx_32( HQ_CORE, coeff_out1_fx, HQ_GEN_SWB, -1, &L_swb_norm, prev_L_swb_norm );
3092 :
3093 2743 : calc_norm_envelop_lf_fx( coeff_out1_fx, envelope_fx, &L_swb_norm, HQ_mode, hq_generic_offset, &sfidx, &efidx );
3094 :
3095 2743 : blen = 16;
3096 2743 : move16();
3097 :
3098 2743 : IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC0 ) )
3099 : {
3100 2620 : rn_weight0_fx = 819;
3101 2620 : move16(); /* 0.8 Q10 */
3102 : }
3103 123 : ELSE IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC1 ) )
3104 : {
3105 14 : rn_weight0_fx = 51;
3106 14 : move16(); /* 0.05 Q10*/
3107 : }
3108 : ELSE
3109 : {
3110 109 : rn_weight0_fx = 205;
3111 109 : move16(); /* 0.02 Q10 */
3112 : }
3113 :
3114 2743 : tmp = sub( efidx, sfidx );
3115 2743 : IF( tmp == 0 )
3116 : {
3117 0 : nband_lf = 0;
3118 0 : move16();
3119 : }
3120 : ELSE
3121 : {
3122 2743 : exp = norm_s( tmp );
3123 2743 : nband_lf = shl( tmp, sub( exp, 1 ) );
3124 2743 : exp1 = norm_s( blen );
3125 2743 : tmp = shl( blen, exp1 );
3126 2743 : nband_lf = shr( div_s( nband_lf, tmp ), add( sub( 14, exp1 ), exp ) ); /* 15 + exp-1 - exp1, Q0*/
3127 : }
3128 :
3129 728935 : FOR( n_freq = sfidx; n_freq < efidx; n_freq++ )
3130 : {
3131 726192 : IF( coeff_out1_fx[n_freq] < 0 )
3132 : {
3133 361339 : signum[n_freq] = -1;
3134 361339 : move16();
3135 361339 : coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] );
3136 361339 : move32();
3137 : }
3138 : ELSE
3139 : {
3140 364853 : signum[n_freq] = 1;
3141 364853 : move16();
3142 : }
3143 : }
3144 :
3145 : /* applying whitening */
3146 728935 : FOR( n_freq = sfidx; n_freq < efidx; n_freq++ )
3147 : {
3148 726192 : exp = norm_l( coeff_out1_fx[n_freq] ) - 1;
3149 726192 : exp1 = norm_l( envelope_fx[n_freq] );
3150 :
3151 726192 : L_tmp = L_shl( coeff_out1_fx[n_freq], exp );
3152 726192 : L_tmp1 = L_shl( envelope_fx[n_freq], exp1 );
3153 :
3154 726192 : logic16();
3155 726192 : coeff_out1_fx[n_freq] = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff );
3156 726192 : move32(); /*31 + exp1 - exp2*/
3157 :
3158 726192 : exp = add( 31, sub( exp, exp1 ) );
3159 726192 : coeff_out1_fx[n_freq] = L_shl( coeff_out1_fx[n_freq], sub( 20, exp ) );
3160 726192 : move32(); /*Q12->Q20*/
3161 : }
3162 :
3163 : /* mean vector generation for controlling dynamic range */
3164 48130 : FOR( k = 0; k < nband_lf; ++k )
3165 : {
3166 45387 : energy_fx = 1;
3167 45387 : move16();
3168 :
3169 45387 : tmp = add( i_mult2( add( k, 1 ), blen ), sfidx );
3170 771579 : FOR( i = add( i_mult2( k, blen ), sfidx ); i < tmp; ++i )
3171 : {
3172 726192 : energy_fx = L_add( energy_fx, coeff_out1_fx[i] );
3173 : }
3174 45387 : exp = sub( norm_l( energy_fx ), 1 );
3175 45387 : L_tmp = L_shl( energy_fx, exp );
3176 45387 : exp1 = norm_l( L_and( blen, 0x00007fff ) );
3177 45387 : L_tmp1 = L_shl( blen, exp1 );
3178 45387 : logic16();
3179 45387 : mean_vector_fx[k] = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff );
3180 45387 : move32(); /*31 + 20 + exp1 - exp2*/
3181 45387 : exp = add( 51, sub( exp, exp1 ) );
3182 45387 : mean_vector_fx[k] = L_shl( mean_vector_fx[k], sub( 20, exp ) );
3183 45387 : move32(); /*Q12->Q20*/
3184 : }
3185 :
3186 : /* dynamics control */
3187 48130 : FOR( k = 0; k < nband_lf; ++k )
3188 : {
3189 45387 : tmp = add( i_mult2( add( k, 1 ), blen ), sfidx );
3190 771579 : FOR( i = add( i_mult2( k, blen ), sfidx ); i < tmp; ++i )
3191 : {
3192 726192 : L_tmp = L_sub( coeff_out1_fx[i], mean_vector_fx[k] );
3193 726192 : exp = norm_l( L_tmp );
3194 726192 : L_tmp = L_shl( L_tmp, exp ); /* exp+12*/
3195 726192 : exp1 = norm_l( rn_weight0_fx );
3196 726192 : L_tmp1 = L_shl( rn_weight0_fx, exp1 ); /* exp1+10*/
3197 726192 : L_tmp = L_mult( extract_h( L_tmp ), extract_h( L_tmp1 ) );
3198 726192 : L_tmp = L_shr( L_tmp, add( exp, sub( exp1, 21 ) ) ); /* Q20*/
3199 726192 : coeff_out1_fx[i] = L_sub( coeff_out1_fx[i], L_tmp );
3200 726192 : move32();
3201 : }
3202 : }
3203 :
3204 2743 : IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC0 ) )
3205 : {
3206 2620 : bwe_seed = add( add( shl( R[0], 3 ), shl( R[1], 2 ) ), add( shl( R[2], 1 ), R[3] ) );
3207 :
3208 698460 : FOR( n_freq = sfidx; n_freq < efidx; n_freq++ )
3209 : {
3210 695840 : IF( signum[n_freq] < 0 )
3211 : {
3212 346384 : coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] );
3213 346384 : move32();
3214 : }
3215 :
3216 695840 : IF( Random( &bwe_seed ) < 0 )
3217 : {
3218 345308 : coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] );
3219 345308 : move32();
3220 : }
3221 : }
3222 : }
3223 : ELSE
3224 : {
3225 30475 : FOR( n_freq = sfidx; n_freq < efidx; n_freq++ )
3226 : {
3227 30352 : IF( signum[n_freq] < 0 )
3228 : {
3229 14955 : coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] );
3230 14955 : move32();
3231 : }
3232 : }
3233 : }
3234 :
3235 : /* normalizing modified low frequency spectrum */
3236 48130 : FOR( k = 0; k < nband_lf; ++k )
3237 : {
3238 45387 : energy_fx = 1;
3239 45387 : move16();
3240 45387 : tmp = add( i_mult2( add( k, 1 ), blen ), sfidx );
3241 771579 : FOR( i = add( ( i_mult2( k, blen ) ), sfidx ); i < tmp; ++i )
3242 : {
3243 726192 : exp = norm_l( coeff_out1_fx[i] );
3244 726192 : L_tmp1 = L_shl( coeff_out1_fx[i], exp ); /* exp + 12*/
3245 :
3246 726192 : L_tmp = Mult_32_32( L_tmp1, L_tmp1 );
3247 726192 : L_tmp = L_shr( L_tmp, sub( i_mult2( 2, exp ), 11 ) ); /*Q20 */
3248 726192 : energy_fx = L_add( energy_fx, L_tmp );
3249 : }
3250 :
3251 45387 : exp = norm_l( energy_fx );
3252 45387 : L_tmp = L_shl( energy_fx, sub( exp, 1 ) );
3253 45387 : exp1 = norm_s( blen );
3254 45387 : L_tmp1 = L_shl( (Word32) blen, add( exp1, 16 ) );
3255 :
3256 45387 : L_tmp = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff );
3257 45387 : exp = sub( add( 34, exp ), exp1 );
3258 45387 : L_tmp = L_shr( L_tmp, sub( exp, 31 ) );
3259 45387 : exp = 31;
3260 45387 : move16();
3261 :
3262 45387 : exp = sub( 31, exp );
3263 45387 : IF( exp & 0x1 )
3264 : {
3265 0 : L_tmp = L_shr( L_tmp, 1 );
3266 0 : exp = add( exp, 1 );
3267 : }
3268 45387 : L_tmp = Sqrt_l( L_tmp, &exp1 );
3269 45387 : exp = add( 31, sub( shr( exp1, 1 ), shr( exp, 1 ) ) );
3270 45387 : energy_fx = L_shl( L_tmp, sub( 31, exp ) ); /*Q31*/
3271 :
3272 45387 : tmp = add( i_mult2( add( k, 1 ), blen ), sfidx );
3273 771579 : FOR( i = add( ( i_mult2( k, blen ) ), sfidx ); i < tmp; ++i )
3274 : {
3275 726192 : IF( NE_32( L_abs( coeff_out1_fx[i] ), coeff_out1_fx[i] ) )
3276 : {
3277 362653 : s = -1;
3278 362653 : move16();
3279 362653 : coeff_out1_fx[i] = L_abs( coeff_out1_fx[i] );
3280 362653 : move32();
3281 : }
3282 : ELSE
3283 : {
3284 363539 : s = 0;
3285 363539 : move16();
3286 : }
3287 726192 : exp = norm_l( coeff_out1_fx[i] );
3288 726192 : L_tmp = L_shl( coeff_out1_fx[i], sub( exp, 1 ) );
3289 726192 : exp1 = norm_l( energy_fx );
3290 726192 : L_tmp1 = L_shl( (Word32) energy_fx, exp1 );
3291 726192 : logic16();
3292 726192 : L_tmp = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff );
3293 726192 : exp = add( sub( 19, exp1 ), exp );
3294 726192 : coeff_out1_fx[i] = L_shl( L_tmp, add( sub( 12, exp ), 15 ) );
3295 726192 : move32(); /* Q12 -> Q27 */
3296 726192 : IF( s )
3297 : {
3298 362653 : coeff_out1_fx[i] = L_negate( coeff_out1_fx[i] );
3299 362653 : move32();
3300 : }
3301 : }
3302 : }
3303 :
3304 2743 : Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[HQ_GENERIC_HIGH0 + hq_generic_offset], HQ_GENERIC_LEN0 );
3305 2743 : Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset], HQ_GENERIC_LEN0 );
3306 :
3307 2743 : IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) )
3308 : {
3309 2743 : Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0], &coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset], HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2 );
3310 : }
3311 :
3312 2743 : IF( EQ_16( HQ_mode, HQ_GEN_FB ) )
3313 : {
3314 2070 : IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) )
3315 : {
3316 2070 : Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0 + HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2], &coeff_out_fx[fb_bwe_subband[0]], 160 );
3317 : }
3318 : ELSE
3319 : {
3320 0 : Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET + HQ_GENERIC_LEN0], &coeff_out_fx[fb_bwe_subband[0]], 160 );
3321 : }
3322 : }
3323 :
3324 :
3325 2743 : L_tmp1 = L_deposit_l( 0 );
3326 2743 : L_tmp2 = L_deposit_l( 0 );
3327 16458 : FOR( i = 0; i < 5; ++i )
3328 : {
3329 13715 : L_tmp1 = L_add( L_tmp1, L_shr( L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset + i] ), 3 ) ); // adding guard bits
3330 13715 : L_tmp2 = L_add( L_tmp2, L_shr( L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 - 2 + hq_generic_offset - i] ), 3 ) ); // adding guard bits
3331 : }
3332 :
3333 2743 : pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset];
3334 2743 : L_tmp1 = L_max( L_tmp1, 1 );
3335 2743 : L_tmp2 = L_max( L_tmp2, 1 );
3336 2743 : exp1 = norm_l( L_tmp1 );
3337 2743 : exp2 = sub( norm_l( L_tmp2 ), 1 );
3338 2743 : tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) );
3339 2743 : tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) );
3340 2743 : tmp3_fx = div_s( tmp2_fx, tmp1_fx ); /*15 + exp2 + 15 - (exp1 + 15) */
3341 2743 : tmp3_fx = shr( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */
3342 :
3343 2743 : if ( LT_16( tmp3_fx, 307 /*0.3 in Q10 */ ) )
3344 : {
3345 0 : tmp3_fx = 307 /*0.3 in Q10 */;
3346 0 : move16();
3347 : }
3348 5022 : FOR( ; tmp3_fx < 1024; tmp3_fx += 102 )
3349 : {
3350 2279 : *pit1_fx = Mult_32_16( *pit1_fx, shl( tmp3_fx, 5 ) );
3351 2279 : move32(); /*15 + 5 + 10 -15 */
3352 2279 : pit1_fx++;
3353 : }
3354 :
3355 2743 : pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 - 1 + hq_generic_offset];
3356 :
3357 2743 : exp1 = sub( norm_l( L_tmp1 ), 1 );
3358 2743 : exp2 = norm_l( L_tmp2 );
3359 2743 : tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) );
3360 2743 : tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) );
3361 2743 : tmp3_fx = div_s( tmp1_fx, tmp2_fx ); /*15 + exp2 + 15 - (exp1 + 15) */
3362 2743 : tmp3_fx = shr( tmp3_fx, add( 5, sub( exp1, exp2 ) ) ); /*10 */
3363 :
3364 2743 : IF( GT_16( tmp3_fx, 5120 ) )
3365 : {
3366 0 : FOR( tmp3_fx = 5120; tmp3_fx > 1024; tmp3_fx -= 512 )
3367 : {
3368 : /* Adding saturation suggested as fix for issue #957 */
3369 0 : L_tmp1 = L_shl_sat( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */
3370 0 : *pit1_fx-- = L_tmp1;
3371 0 : move32();
3372 : }
3373 : }
3374 :
3375 2743 : IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) )
3376 : {
3377 2743 : L_tmp1 = L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset] ), L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 + 1 + hq_generic_offset] ) );
3378 2743 : L_tmp2 = L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 4 + hq_generic_offset] ), L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 3 + hq_generic_offset] ),
3379 2743 : L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 2 + hq_generic_offset] ), L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 1 + hq_generic_offset] ) ) ) );
3380 :
3381 2743 : pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset];
3382 :
3383 2743 : L_tmp1 = L_max( L_tmp1, 1 );
3384 2743 : L_tmp2 = L_max( L_tmp2, 1 );
3385 2743 : exp1 = norm_l( L_tmp1 );
3386 2743 : exp2 = sub( norm_l( L_tmp2 ), 1 );
3387 2743 : tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) );
3388 2743 : tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) );
3389 2743 : tmp3_fx = div_s( tmp2_fx, tmp1_fx ); /*15 + exp2 + 15 - (exp1 + 15) */
3390 2743 : tmp3_fx = shr_sat( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */
3391 2743 : if ( LT_16( tmp3_fx, 307 /* 0.3 in Q10*/ ) )
3392 : {
3393 0 : tmp3_fx = 307; /* 0.3 in Q10*/
3394 0 : move16();
3395 : }
3396 2744 : FOR( ; tmp3_fx < 1024; tmp3_fx += 102 )
3397 : {
3398 1 : L_tmp = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */
3399 1 : *pit1_fx++ = L_tmp;
3400 1 : move32();
3401 : }
3402 :
3403 2743 : pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH2 - 1 + hq_generic_offset];
3404 :
3405 2743 : exp1 = sub( norm_l( L_tmp1 ), 1 );
3406 2743 : exp2 = norm_l( L_tmp2 );
3407 2743 : tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) );
3408 2743 : tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) );
3409 2743 : tmp3_fx = div_s( tmp1_fx, tmp2_fx ); /*15 + exp2 + 15 - (exp1 + 15) */
3410 2743 : tmp3_fx = shr( tmp3_fx, add( 5, sub( exp1, exp2 ) ) ); /*10 */
3411 2743 : tmp3_fx = shr( tmp3_fx, 1 );
3412 2743 : tmp4_fx = mult_r( tmp3_fx, 1638 /* 0.05 in Q15 */ );
3413 2743 : WHILE( tmp3_fx > 1024 /* 1 in Q10*/ )
3414 : {
3415 0 : L_tmp1 = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */
3416 0 : *pit1_fx-- = L_tmp1;
3417 0 : move32();
3418 0 : tmp3_fx = sub( tmp3_fx, tmp4_fx );
3419 : }
3420 : }
3421 :
3422 :
3423 2743 : wfenv_fx = hq_generic_fenv_fx[0];
3424 2743 : move16(); /*1 */
3425 2743 : i = 0;
3426 2743 : move16();
3427 2743 : tmp2 = add( add( swb_bwe_subband[0], hq_generic_offset ), 8 );
3428 24687 : FOR( n_freq = add( swb_bwe_subband[0], hq_generic_offset ); n_freq < tmp2; n_freq++ )
3429 : {
3430 21944 : factor_fx = shl( i, 12 ); /*15 */
3431 21944 : L_tmp1 = L_mult( sub( 32767, factor_fx ), fenvL_fx ); /*17 */
3432 21944 : L_tmp2 = L_mult( factor_fx, wfenv_fx ); /*17 */
3433 21944 : L_tmp1 = L_add( L_tmp1, L_tmp2 ); /*17 */
3434 :
3435 21944 : cs = norm_l( L_tmp1 );
3436 21944 : tmp = extract_h( L_shl( L_tmp1, cs ) ); /*17 + cs - 16 */
3437 21944 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 17 + cs - 16 - 15 */
3438 21944 : coeff_out_fx[n_freq] = L_shr( L_tmp, add( 1, cs ) );
3439 21944 : move32(); /*12 */
3440 21944 : i++;
3441 21944 : move16();
3442 : }
3443 :
3444 2743 : k = sub( nenv, 2 );
3445 35659 : FOR( n_band = 0; n_band < k; n_band++ )
3446 : {
3447 32916 : wfenv_fx = hq_generic_fenv_fx[n_band + 1];
3448 32916 : move16(); /*1 */
3449 :
3450 32916 : tmp2 = swb_bwe_sm_subband[n_band + 1] + hq_generic_offset;
3451 757068 : FOR( i = 0; n_freq < tmp2; i++ )
3452 : {
3453 724152 : L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[n_band] ), smooth_factor_fx[n_band] ); /*17 */
3454 724152 : L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */
3455 724152 : L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[n_band], 11 ) ); /*12 */
3456 :
3457 724152 : cs = norm_l( L_tmp1 );
3458 724152 : tmp = extract_h( L_shl( L_tmp1, cs ) ); /*12 + cs - 16 */
3459 724152 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 12 + cs - 16 - 15 */
3460 724152 : coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 4, cs ) );
3461 724152 : move32(); /*12 */
3462 724152 : n_freq++;
3463 : }
3464 : }
3465 :
3466 2743 : wfenv_fx = hq_generic_fenv_fx[nenv - 1];
3467 2743 : move16(); /*1 */
3468 2743 : tmp2 = add( swb_bwe_sm_subband[nenv - 1], hq_generic_offset );
3469 90519 : FOR( i = 0; n_freq < tmp2; i++ )
3470 : {
3471 87776 : L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[nenv - 2] ), smooth_factor_fx[nenv - 2] ); /*17 */
3472 87776 : L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */
3473 87776 : L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[nenv - 2], 11 ) ); /*12 */
3474 :
3475 87776 : cs = norm_l( L_tmp1 );
3476 87776 : tmp = extract_h( L_shl( L_tmp1, cs ) ); /*12 + cs - 16 */
3477 87776 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 12 + cs - 16 - 15 */
3478 87776 : coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 4, cs ) );
3479 87776 : move32(); /*12 */
3480 87776 : n_freq++;
3481 : }
3482 :
3483 2743 : IF( EQ_16( HQ_mode, HQ_GEN_SWB ) )
3484 : {
3485 1346 : FOR( n_band = sub( nenv, 1 ); n_band < nenv; ++n_band )
3486 : {
3487 673 : wfenv_fx = hq_generic_fenv_fx[n_band];
3488 673 : move16(); /*1 */
3489 673 : tmp2 = add( swb_bwe_subband[n_band + 1], hq_generic_offset );
3490 11441 : FOR( ; n_freq < tmp2; n_freq++ )
3491 : {
3492 10768 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */
3493 10768 : coeff_out_fx[n_freq] = L_shr( L_tmp, 1 );
3494 10768 : move32(); /*12 */
3495 : }
3496 : }
3497 : }
3498 : ELSE
3499 : {
3500 2070 : test();
3501 2070 : IF( GT_16( sub( hq_generic_fenv_fx[nenv - 1], hq_generic_fenv_fx[nenv] ), 30 ) || LT_16( hq_generic_fenv_fx[nenv], 10 ) )
3502 : {
3503 1615 : wfenv_fx = hq_generic_fenv_fx[nenv - 1];
3504 1615 : move16(); /*1 */
3505 27455 : FOR( i = 0; n_freq < fb_bwe_subband[0]; i++ )
3506 : {
3507 25840 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */
3508 25840 : coeff_out_fx[n_freq] = L_shr( L_tmp, 1 );
3509 25840 : move32(); /*12 */
3510 25840 : n_freq++;
3511 : }
3512 :
3513 6460 : FOR( n_band = 0; n_band < DIM_FB; n_band++ )
3514 : {
3515 4845 : wfenv_fx = hq_generic_fenv_fx[n_band + nenv];
3516 4845 : move16(); /*1 */
3517 4845 : tmp2 = fb_bwe_subband[n_band + 1];
3518 263245 : FOR( i = 0; n_freq < tmp2; i++ )
3519 : {
3520 258400 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */
3521 258400 : coeff_out_fx[n_freq] = L_shr( L_tmp, 1 );
3522 258400 : move32(); /*12 */
3523 258400 : n_freq++;
3524 : }
3525 : }
3526 : }
3527 : ELSE
3528 : {
3529 1820 : FOR( n_band = 0; n_band < DIM_FB; n_band++ )
3530 : {
3531 1365 : wfenv_fx = hq_generic_fenv_fx[n_band + nenv - 1];
3532 1365 : move16(); /*1 */
3533 :
3534 63245 : FOR( i = 0; n_freq < fb_bwe_sm_subband[n_band]; i++ )
3535 : {
3536 61880 : L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[n_band + nenv] ), fb_smooth_factor_fx[n_band] ); /*17 */
3537 61880 : L_tmp1 = Mult_32_16( L_tmp1, shl( i, 9 ) ); /*17 + 9 - 15 */
3538 61880 : L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[n_band + nenv], 10 ) ); /*11 */
3539 :
3540 61880 : cs = norm_l( L_tmp1 );
3541 61880 : tmp = extract_h( L_shl( L_tmp1, cs ) ); /*11 + cs - 16 */
3542 61880 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 11 + cs - 16 - 15 */
3543 61880 : coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 5, cs ) );
3544 61880 : move32(); /*12 */
3545 61880 : n_freq = add( n_freq, 1 );
3546 : }
3547 : }
3548 :
3549 455 : wfenv_fx = hq_generic_fenv_fx[tenv - 1];
3550 455 : move16(); /*1 */
3551 :
3552 18655 : FOR( ; n_freq < fb_bwe_subband[DIM_FB]; n_freq++ )
3553 : {
3554 18200 : L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */
3555 18200 : coeff_out_fx[n_freq] = L_shr( L_tmp, 1 );
3556 18200 : move32(); /*12 */
3557 : }
3558 : }
3559 : }
3560 :
3561 2743 : return;
3562 : }
3563 :
3564 :
3565 : /*-------------------------------------------------------------------*
3566 : * save_old_syn()
3567 : *
3568 : * Save and delay the ACELP core synthesis signal by
3569 : * DELAY_FD_BWE_ENC_xxkx to be used by SWB BWE
3570 : *-------------------------------------------------------------------*/
3571 :
3572 327491 : void save_old_syn_fx(
3573 : const Word16 L_frame, /* i : frame length */
3574 : const Word16 syn[], /* i : ACELP synthesis */
3575 : Word16 old_syn[], /* o : old synthesis buffer */
3576 : Word16 old_syn_mem[], /* i/o: old synthesis buffer memory */
3577 : const Word16 preemph_fac, /* i : preemphasis factor */
3578 : Word16 *mem_deemph /* i/o: deemphasis filter memory */
3579 : )
3580 : {
3581 : Word16 tmps;
3582 :
3583 327491 : tmps = NS2SA( 16000, DELAY_FD_BWE_ENC_16k_NS );
3584 327491 : move16();
3585 327491 : if ( EQ_16( L_frame, L_FRAME ) )
3586 : {
3587 171931 : tmps = NS2SA( 12800, DELAY_FD_BWE_ENC_12k8_NS );
3588 171931 : move16();
3589 : }
3590 327491 : Copy( old_syn_mem, old_syn, tmps );
3591 327491 : Copy( syn, old_syn + tmps, sub( L_frame, tmps ) );
3592 327491 : Copy( syn + L_frame - tmps, old_syn_mem, tmps );
3593 :
3594 327491 : deemph_fx( old_syn, preemph_fac, L_frame, mem_deemph );
3595 :
3596 327491 : return;
3597 : }
|