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