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 <assert.h>
34 : #include <stdint.h>
35 : #include "options.h"
36 : #include <math.h>
37 : #include "cnst.h"
38 : #include "ivas_cnst.h"
39 : #include "prot_fx.h"
40 : #include "ivas_prot_fx.h"
41 : #include "wmc_auto.h"
42 : #include "rom_com.h"
43 : #include "ivas_rom_com.h"
44 : #include "ivas_rom_com_fx.h"
45 :
46 :
47 : #define Q_icBWE 16
48 :
49 : /*-------------------------------------------------------------------*
50 : * ic_bwe_dec_reset()
51 : *
52 : * core switching reset of IC BWE memory
53 : *-------------------------------------------------------------------*/
54 :
55 16099 : static void ic_bwe_dec_reset_fx(
56 : STEREO_ICBWE_DEC_HANDLE hStereoICBWE /* i/o: Stereo ICBWE handle */
57 : )
58 : {
59 : /* unscaled & scaled SHB synthesis memory */
60 16099 : set32_fx( hStereoICBWE->mem_syn_shb_nonref_fx, 0, L_SHB_LAHEAD ); /* use samples from !acelp) */
61 16099 : set32_fx( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 0, LPC_SHB_ORDER );
62 16099 : set32_fx( hStereoICBWE->mem_syn_shb_ola_nonref_fx, 0, L_SHB_LAHEAD ); /* use samples from !acelp) */
63 :
64 16099 : hStereoICBWE->prev_Q_syn_shb_nonref = 31;
65 16099 : move16();
66 16099 : hStereoICBWE->prev_Q_lpc_shbsynth_nonref = 31;
67 16099 : move16();
68 16099 : hStereoICBWE->prev_Q_syn_shb_ola_nonref = 31;
69 16099 : move16();
70 :
71 : /* inter-channel BWE SP and GSP mem reset */
72 16099 : hStereoICBWE->memShbSpecMapping_fx = 0;
73 16099 : move32();
74 16099 : hStereoICBWE->prev_Q_memshbspec = 31;
75 16099 : move16();
76 :
77 16099 : set32_fx( hStereoICBWE->memShbHilbert_nonref_fx, 0, HILBERT_MEM_SIZE );
78 16099 : set32_fx( hStereoICBWE->memShbInterp_nonref_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
79 16099 : set32_fx( hStereoICBWE->memShb_fsout_nonref_fx, 0, INTERP_3_2_MEM_LEN );
80 :
81 16099 : hStereoICBWE->prev_Q_hilb = 31;
82 16099 : move16();
83 16099 : hStereoICBWE->prev_Q_interp = 31;
84 16099 : move16();
85 16099 : hStereoICBWE->prev_Q_fsout = 31;
86 16099 : move16();
87 :
88 16099 : hStereoICBWE->syn_dm_phase_nonref = 0;
89 16099 : move16();
90 :
91 16099 : return;
92 : }
93 :
94 :
95 95958 : static Word16 FindScale(
96 : Word32 *buff, /* Q_buff */
97 : Word16 len, /* Q0 */
98 : Word16 Q_buff,
99 : Word16 Q_prev )
100 : {
101 : Word32 maxVal;
102 : Word16 norm_shift, Q_out;
103 :
104 95958 : maximum_abs_32_fx( buff, len, &maxVal );
105 95958 : norm_shift = norm_l( maxVal );
106 95958 : if ( maxVal == 0 )
107 : {
108 11140 : norm_shift = 31;
109 11140 : move16();
110 : }
111 :
112 95958 : Q_out = s_min( Q_prev, add( Q_buff, norm_shift ) );
113 :
114 95958 : return Q_out;
115 : }
116 :
117 :
118 145402 : void stereo_icBWE_dec_fx(
119 : CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
120 : Word32 *synthRef_fx, /* i/o: Reference channel HB synthesis at output Fs Q11 */
121 : Word32 *synth_fx, /* o : Non reference channel HB synthesis at output Fs Q11 */
122 : const Word16 *fb_synth_ref_fx, /* i : ref. high-band synthesis 16-20 kHz Q_white_exc*/
123 : const Word16 *voice_factors_fx, /* i : voicing factors Q15 */
124 : const Word16 output_frame, /* i : frame length Q0 */
125 : Word16 *Q_syn /* i : Q of synth and synthRef buffers */
126 : ,
127 : const Word16 Q_white_exc /* i : Q of fb_synth_ref_fx */
128 : )
129 : {
130 : Word16 i, j, k, nbSubFr;
131 : Decoder_State *st; /* i/o: decoder state structure, primary channel */
132 : Word16 spIndx, gsIndx;
133 : Word32 excSHB_nonref_fx[L_FRAME16k];
134 : Word32 shb_synth_nonref_fx[L_FRAME16k + L_SHB_LAHEAD];
135 : Word32 error_fx[L_FRAME32k];
136 : Word16 nlMixFac_fx[NB_SUBFR16k];
137 : Word16 specMapping_fx;
138 : Word16 fb_synth_nonref_fx[L_FRAME48k];
139 : Word32 prev_pow_fx, curr_pow_fx, maxVal1, maxVal;
140 : Word16 scale_fx, e_scale_fx;
141 : Word16 alpha_fx, winSlope_fx, winLen_fx;
142 : Word16 prevgsMapping_fx;
143 : Word16 temp1_fx, temp2_fx;
144 : Word16 icbweM2Ref_fx, ratio_L_fx;
145 : Word16 gsMapping_fx;
146 : Word32 hb_nrg_fx;
147 : Word16 Q_syn_shb;
148 : Word16 shift_prev_pow, synthRef_shift;
149 : Word32 L_tmp;
150 : Word16 tmp;
151 : Word32 L_nlExc16k, L_mixExc16k;
152 :
153 145402 : STEREO_DFT_DEC_DATA_HANDLE hStereoDft = hCPE->hStereoDft;
154 145402 : STEREO_ICBWE_DEC_HANDLE hStereoICBWE = hCPE->hStereoICBWE;
155 145402 : st = hCPE->hCoreCoder[0];
156 :
157 : /*--------------------------------------------------------------------*
158 : * skip IC-BWE in case of mono DMX output *
159 : * -------------------------------------------------------------------*/
160 :
161 145402 : test();
162 145402 : test();
163 145402 : test();
164 145402 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && GT_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) )
165 : {
166 5345 : hCPE->hStereoDft->core_hist[0] = st->core; /* Q0 */
167 5345 : move16();
168 :
169 5345 : return;
170 : }
171 140057 : ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) )
172 : {
173 17001 : return;
174 : }
175 :
176 : /*--------------------------------------------------------------------*
177 : * skip IC-BWE in case of SID or NO_DATA frame
178 : * -------------------------------------------------------------------*/
179 :
180 123056 : IF( LE_32( st->core_brate, SID_2k40 ) )
181 : {
182 9642 : return;
183 : }
184 :
185 : /*--------------------------------------------------------------------*
186 : * TD high band stereo filling *
187 : * -------------------------------------------------------------------*/
188 :
189 : /* update buffers for TD stereo filling */
190 113414 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
191 : {
192 31231 : hb_nrg_fx = 0;
193 31231 : move32();
194 31231 : move32();
195 31231 : maximum_abs_32_fx( synthRef_fx, output_frame, &maxVal );
196 31231 : synthRef_shift = norm_l( maxVal );
197 31231 : if ( maxVal == 0 )
198 : {
199 12936 : synthRef_shift = 31;
200 12936 : move16();
201 : }
202 31231 : synthRef_shift = sub( synthRef_shift, shr( add( find_guarded_bits_fx( shr( output_frame, 1 ) ), 1 ), 1 ) );
203 31231 : test();
204 31231 : IF( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->last_core, ACELP_CORE ) )
205 21152 : {
206 21152 : Word64 W_tmp = 0;
207 21152 : move64();
208 21152 : tmp = shl_sat( 1, synthRef_shift );
209 6866752 : FOR( i = 0; i < output_frame / 2; i++ )
210 : {
211 : // needed to be adjusted for q
212 6845600 : L_tmp = Mpy_32_16_1( synthRef_fx[i], tmp ); /* Qsyn + SynthRef_shift - 15 */
213 6845600 : W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); /* 2 * (Qsyn + SynthRef_shift) - 29 */
214 : }
215 21152 : hb_nrg_fx = W_round48_L( W_tmp ); /* 2 * (Qsyn + SynthRef_shift) - 45 */
216 21152 : hCPE->hStereoDft->hb_nrg_subr_fx[0] = hb_nrg_fx; /* 2 * (Qsyn + SynthRef_shift) - 45 */
217 21152 : move32();
218 21152 : hStereoDft->q_hb_nrg_subr = sub( shl( add( *Q_syn, synthRef_shift ), 1 ), 45 );
219 21152 : move16();
220 21152 : W_tmp = 0;
221 21152 : move64();
222 6866752 : FOR( ; i < output_frame; i++ )
223 : {
224 6845600 : L_tmp = Mpy_32_16_1( synthRef_fx[i], tmp ); /* Qsyn + SynthRef_shift - 15 */
225 6845600 : W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); /* 2 * (Qsyn + SynthRef_shift) - 45 */
226 : }
227 :
228 21152 : hCPE->hStereoDft->hb_nrg_subr_fx[1] = W_round48_L( W_tmp ); // 2 * (Qsyn + SynthRef_shift) - 45
229 21152 : hb_nrg_fx = L_add( hCPE->hStereoDft->hb_nrg_subr_fx[0], hCPE->hStereoDft->hb_nrg_subr_fx[1] ); // 2 * (Qsyn + SynthRef_shift) - 45
230 :
231 :
232 21152 : Copy32( synthRef_fx, hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame ); /* Qsynth */
233 : }
234 : ELSE
235 : {
236 10079 : set32_fx( hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, 0, output_frame );
237 10079 : hCPE->hStereoDft->hb_nrg_subr_fx[0] = 0;
238 10079 : move32();
239 10079 : hCPE->hStereoDft->hb_nrg_subr_fx[1] = 0;
240 10079 : move32();
241 : }
242 31231 : hCPE->hStereoDft->hb_nrg_subr_fx[0] = ( Mpy_32_16_1( hCPE->hStereoDft->hb_nrg_subr_fx[0], shl( shr( hCPE->hStereoDft->NFFT, 1 ), 6 ) ) ); // 2 * (Qsynth + SynthRef_shift) - 40 // 2 * (Qx + SynthRef_shift) - 31 - 15
243 31231 : move32();
244 31231 : hCPE->hStereoDft->hb_nrg_subr_fx[1] = ( Mpy_32_16_1( hCPE->hStereoDft->hb_nrg_subr_fx[1], shl( shr( hCPE->hStereoDft->NFFT, 1 ), 6 ) ) ); // 2 * (Qsynth + SynthRef_shift) - 40
245 31231 : move32();
246 31231 : hCPE->hStereoDft->q_hb_nrg_subr = sub( shl( ( *Q_syn + synthRef_shift ), 1 ), 45 + 9 );
247 31231 : hCPE->hStereoDft->hb_nrg_fx[0] = hb_nrg_fx; // 2 * (Qx + SynthRef_shift) - 31
248 31231 : move32();
249 31231 : hCPE->hStereoDft->td_gain_fx[0] = 0;
250 31231 : move32();
251 31231 : hCPE->hStereoDft->core_hist[0] = st->core;
252 31231 : move16();
253 : }
254 :
255 : /*--------------------------------------------------------------------*
256 : * IC-BWE *
257 : * -------------------------------------------------------------------*/
258 113414 : test();
259 113414 : test();
260 113414 : test();
261 113414 : test();
262 113414 : IF( st->core != ACELP_CORE || EQ_16( st->extl, -1 ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && NE_16( hCPE->hCoreCoder[0]->tdm_LRTD_flag, 0 ) ) )
263 : {
264 95561 : return;
265 : }
266 17853 : ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && LE_32( st->core_brate, SID_2k40 ) )
267 : {
268 0 : Copy32( synthRef_fx, synth_fx, output_frame ); /* Qsynth */
269 0 : return;
270 : }
271 :
272 :
273 17853 : set16_fx( fb_synth_nonref_fx, 0, L_FRAME48k );
274 :
275 : /* core switching reset */
276 17853 : test();
277 17853 : IF( st->last_core != ACELP_CORE || EQ_16( st->bwidth, (Word16) WB ) )
278 : {
279 3210 : ic_bwe_dec_reset_fx( hStereoICBWE );
280 :
281 3210 : IF( st->last_core != ACELP_CORE )
282 : {
283 574 : hStereoICBWE->prevSpecMapping_fx = 0;
284 574 : move16();
285 574 : hStereoICBWE->prevgsMapping_fx = 16384; /* 1.f in Q14 */
286 574 : move16();
287 574 : hStereoICBWE->icbweM2Ref_prev_fx = 16384; /* 1.f in Q14 */
288 574 : move16();
289 : }
290 :
291 3210 : IF( EQ_16( st->bwidth, WB ) )
292 : {
293 : /* copy to outputHB and reset hb_synth values */
294 2688 : Copy32( synthRef_fx, synth_fx, output_frame );
295 :
296 2688 : IF( EQ_16( st->element_mode, IVAS_CPE_TD ) )
297 : {
298 3 : hStereoICBWE->prevSpecMapping_fx = 0;
299 3 : move16();
300 3 : hStereoICBWE->prevgsMapping_fx = 16384; /* 1.f in Q14 */
301 3 : move16();
302 3 : hStereoICBWE->icbweM2Ref_prev_fx = 16384; /* 1.f in Q14 */
303 3 : move16();
304 : }
305 2685 : ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
306 : {
307 : Word32 temp;
308 2685 : hStereoICBWE->refChanIndx_bwe = L_CH_INDX;
309 2685 : move16();
310 2685 : hStereoICBWE->prevSpecMapping_fx = 0;
311 2685 : move16();
312 :
313 2685 : prevgsMapping_fx = hStereoICBWE->prevgsMapping_fx;
314 2685 : move16();
315 2685 : temp = L_shr( hStereoDft->side_gain_fx[2 * STEREO_DFT_BAND_MAX + hStereoDft->nbands - 1], 1 ); // Q30
316 2685 : icbweM2Ref_fx = extract_h( L_add( ONE_IN_Q30, temp ) ); // Q14
317 2685 : gsMapping_fx = extract_h( L_sub( ONE_IN_Q30, temp ) ); // Q14
318 :
319 2685 : winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); //(int16_t)((SHB_OVERLAP_LEN * st->output_Fs) / 16000); Q0
320 2685 : winSlope_fx = div_s( 1, winLen_fx ); /* Q15 */
321 2685 : alpha_fx = winSlope_fx; /* Q15 */
322 2685 : move16();
323 60145 : FOR( i = 0; i < winLen_fx; i++ )
324 : {
325 : /*synthRef[i] *= ( alpha * ( icbweM2Ref ) + ( 1.0f - alpha ) * ( hStereoICBWE->icbweM2Ref_prev ) );*/
326 57460 : temp1_fx = sub( 32767, alpha_fx ); /* 1.f in Q15 */
327 57460 : L_tmp = L_mult( alpha_fx, icbweM2Ref_fx ); // Q15 + Q14 + 1
328 57460 : L_tmp = L_mac( L_tmp, temp1_fx, hStereoICBWE->icbweM2Ref_prev_fx ); // Q15 + Q14 + 1
329 57460 : synthRef_fx[i] = L_shl( Mpy_32_32( synthRef_fx[i], L_tmp ), 1 ); // Qsynth
330 57460 : move32();
331 : /*synth[i] *= ( alpha * ( gsMapping ) + ( 1.0f - alpha ) * ( prevgsMapping ) );*/
332 57460 : L_tmp = L_mult( alpha_fx, gsMapping_fx ); // Q15 + Q14 + 1
333 57460 : L_tmp = L_mac( L_tmp, temp1_fx, prevgsMapping_fx ); // Q15 + Q14 +1
334 57460 : synth_fx[i] = L_shl( Mpy_32_32( synth_fx[i], L_tmp ), 1 ); // Qsynth
335 57460 : move32();
336 57460 : alpha_fx = add_sat( alpha_fx, winSlope_fx ); /* Q15 */
337 : }
338 864585 : FOR( ; i < NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS ); i++ )
339 : {
340 861900 : synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); // Qsyth - 1
341 861900 : move32();
342 861900 : synth_fx[i] = Mpy_32_16_1( synth_fx[i], gsMapping_fx ); // Qsynth - 1
343 861900 : move32();
344 : }
345 2685 : hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; // Q14
346 2685 : move16();
347 2685 : hStereoICBWE->prevgsMapping_fx = gsMapping_fx; // Q14
348 2685 : move16();
349 :
350 2685 : *Q_syn = sub( *Q_syn, 1 );
351 : }
352 :
353 2688 : return;
354 : }
355 : }
356 :
357 15165 : IF( st->bfi == 0 )
358 : {
359 14949 : hStereoICBWE->refChanIndx_bwe = get_next_indice_fx( st, STEREO_ICBWE_REFBITS );
360 14949 : IF( EQ_16( st->flag_ACELP16k, 1 ) )
361 : {
362 8766 : spIndx = get_next_indice_fx( st, STEREO_ICBWE_SPBITS ); /* Q0 */
363 : }
364 : ELSE
365 : {
366 6183 : spIndx = 3;
367 6183 : move16();
368 : }
369 14949 : IF( EQ_16( st->element_mode, IVAS_CPE_TD ) )
370 : {
371 34 : gsIndx = get_next_indice_fx( st, STEREO_ICBWE_GSBITS ); /* Q0 */
372 : }
373 : ELSE
374 : {
375 14915 : gsIndx = get_next_indice_fx( st, STEREO_ICBWE_GSBITS_DFT ); /* Q0 */
376 : }
377 :
378 : /* Store indices in case of frame loss */
379 14949 : hStereoICBWE->prev_spIndx = spIndx; /* Q0 */
380 14949 : move16();
381 14949 : hStereoICBWE->prev_gsIndx = gsIndx; /* Q0 */
382 14949 : move16();
383 : }
384 : ELSE /*bfi*/
385 : {
386 : /* Retrieve last decoded indices */
387 216 : spIndx = hStereoICBWE->prev_spIndx; /* Q0 */
388 216 : move16();
389 216 : gsIndx = hStereoICBWE->prev_gsIndx; /* Q0 */
390 216 : move16();
391 216 : hStereoICBWE->refChanIndx_bwe = hStereoICBWE->prev_refChanIndx_bwe; /* Q0 */
392 216 : move16();
393 : }
394 :
395 : /* IC-BWE parameter de-quant */
396 : /* sp Mapping */
397 15165 : hStereoICBWE->prevSpecMapping_fx = usdequant_fx( spIndx, -19661 /* -0.6 in Q15 */, 3277 /* 0.2 in Q14 */ ); // Q15
398 :
399 : /* gs Mapping */
400 15165 : prevgsMapping_fx = hStereoICBWE->prevgsMapping_fx; // Q14
401 15165 : move16();
402 :
403 15165 : IF( EQ_16( st->element_mode, IVAS_CPE_TD ) )
404 : {
405 34 : hStereoICBWE->prevgsMapping_fx = pow_10_icbwe_gsMapping_tbl_fx[gsIndx]; /* Q14 */
406 34 : move16();
407 : }
408 : ELSE
409 : {
410 15131 : hStereoICBWE->prevgsMapping_fx = pow_10_icbwe_gsMappingDFT_tbl_fx[gsIndx]; /* Q14 */
411 15131 : move16();
412 : }
413 :
414 : // hStereoICBWE->prevgsMapping = powf( 10, hStereoICBWE->prevgsMapping );
415 :
416 15165 : specMapping_fx = hStereoICBWE->prevSpecMapping_fx; // Q15
417 15165 : move16();
418 15165 : gsMapping_fx = hStereoICBWE->prevgsMapping_fx; // Q14
419 15165 : move16();
420 :
421 15165 : test();
422 15165 : test();
423 15165 : IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) )
424 : {
425 8556 : Copy( voice_factors_fx, nlMixFac_fx, NB_SUBFR16k ); // Q15
426 8556 : IF( hCPE->hStereoDftDmx != NULL )
427 : {
428 6 : test();
429 6 : IF( LT_32( hCPE->hStereoDftDmx->targetGain_fx, 268435456 /* 0.5 in Q29 */ ) || GT_32( hCPE->hStereoDftDmx->targetGain_fx, 1073741824 /* 2.0 in Q29 */ ) )
430 : {
431 0 : v_multc_fixed_16_16( voice_factors_fx, 16384 /* 0.5 in Q15 */, nlMixFac_fx, NB_SUBFR16k );
432 : }
433 : }
434 : ELSE
435 : {
436 8550 : test();
437 8550 : IF( LT_32( hCPE->hStereoTCA->targetGain_fx, 268435456 /* 0.5 in Q29 */ ) || GT_32( hCPE->hStereoTCA->targetGain_fx, 1073741824 /* 2.0 in Q29 */ ) )
438 : {
439 0 : v_multc_fixed_16_16( voice_factors_fx, 16384 /* 0.5 in Q15 */, nlMixFac_fx, NB_SUBFR16k );
440 : }
441 : }
442 :
443 : // nbSubFr = ( st->flag_ACELP16k == 0 ) ? NB_SUBFR : NB_SUBFR16k;
444 8556 : IF( st->flag_ACELP16k == 0 )
445 : {
446 0 : nbSubFr = NB_SUBFR;
447 0 : move16();
448 : }
449 : ELSE
450 : {
451 8556 : nbSubFr = NB_SUBFR16k;
452 8556 : move16();
453 : }
454 8556 : k = 0;
455 8556 : move16();
456 51336 : FOR( i = 0; i < nbSubFr; i++ )
457 : {
458 42780 : IF( EQ_16( hCPE->hCoreCoder[0]->coder_type, UNVOICED ) || EQ_16( hStereoICBWE->MSFlag, 1 ) )
459 : {
460 9305 : temp1_fx = 0;
461 9305 : move16();
462 9305 : temp2_fx = 32767; /* 1.0f in Q15 */
463 9305 : move16();
464 : }
465 : ELSE
466 : {
467 33475 : tmp = 0;
468 33475 : move16();
469 33475 : temp1_fx = Sqrt16( nlMixFac_fx[i], &tmp );
470 33475 : IF( LT_16( tmp, 0 ) )
471 : {
472 20997 : temp1_fx = shl( temp1_fx, tmp );
473 : }
474 33475 : tmp = 0;
475 33475 : move16();
476 33475 : temp2_fx = Sqrt16( sub( 32767 /* 1.0f in Q15 */, nlMixFac_fx[i] ), &tmp );
477 33475 : IF( LT_16( tmp, 0 ) )
478 : {
479 706 : temp2_fx = shl( temp2_fx, tmp );
480 : }
481 : }
482 :
483 2780700 : FOR( j = 0; j < L_FRAME16k / nbSubFr; j++ )
484 : {
485 : // common Q for addition
486 2737920 : L_nlExc16k = L_deposit_l( hStereoICBWE->nlExc16k_fx[k] ); // prev_q_bwe_exc - 16
487 2737920 : L_mixExc16k = L_deposit_l( hStereoICBWE->mixExc16k_fx[k] ); // Q_exc
488 2737920 : L_nlExc16k = L_shl( L_nlExc16k, sub( Q_icBWE, ( sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // Q_icBWE
489 2737920 : L_mixExc16k = L_shl( L_mixExc16k, sub( Q_icBWE, ( sub( st->prev_Q_bwe_exc, 25 ) ) ) ); // Q_icBWE
490 2737920 : excSHB_nonref_fx[k] = L_add( Mpy_32_16_1( L_nlExc16k, temp1_fx ), Mpy_32_16_1( L_mixExc16k, temp2_fx ) ); // Q_icBWE
491 2737920 : move32();
492 2737920 : k++;
493 : }
494 : }
495 :
496 : /* LP synthesis */
497 8556 : Q_syn_shb = 31;
498 8556 : move16();
499 :
500 8556 : Q_syn_shb = FindScale( hStereoICBWE->mem_syn_shb_nonref_fx, LPC_SHB_ORDER, hStereoICBWE->prev_Q_syn_shb_nonref, Q_syn_shb );
501 8556 : Q_syn_shb = FindScale( hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, 12, Q_syn_shb );
502 8556 : Q_syn_shb = FindScale( excSHB_nonref_fx, L_FRAME16k, Q_icBWE, Q_syn_shb );
503 8556 : Q_syn_shb = FindScale( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, hStereoICBWE->prev_Q_lpc_shbsynth_nonref, Q_syn_shb );
504 :
505 8556 : Q_syn_shb = sub( Q_syn_shb, 3 ); // gaurded bits
506 :
507 8556 : Scale_sig32( hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, sub( Q_syn_shb, 12 ) ); // Q_syn_shb
508 8556 : Scale_sig32( excSHB_nonref_fx, L_FRAME16k, sub( Q_syn_shb, Q_icBWE ) ); // Q_syn_shb
509 8556 : Scale_sig32( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, sub( Q_syn_shb, hStereoICBWE->prev_Q_lpc_shbsynth_nonref ) ); // Q_syn_shb
510 8556 : Scale_sig32( hStereoICBWE->mem_syn_shb_nonref_fx, L_SHB_LAHEAD, sub( Q_syn_shb, hStereoICBWE->prev_Q_syn_shb_nonref ) ); // Q_syn_shb
511 :
512 :
513 8556 : Copy32( hStereoICBWE->mem_syn_shb_nonref_fx, shb_synth_nonref_fx, L_SHB_LAHEAD ); // Q_syn_shb
514 :
515 8556 : E_UTIL_synthesis_fx( 0, hStereoICBWE->lpSHBRef_fx, excSHB_nonref_fx, shb_synth_nonref_fx + L_SHB_LAHEAD, L_FRAME16k, hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 1, LPC_SHB_ORDER );
516 :
517 8556 : hStereoICBWE->prev_Q_lpc_shbsynth_nonref = Q_syn_shb;
518 8556 : move16();
519 :
520 8556 : maximum_abs_32_fx( shb_synth_nonref_fx, L_SHB_LAHEAD + 10 + L_SHB_LAHEAD + 10, &maxVal1 ); // Qsyn_shb
521 :
522 8556 : shift_prev_pow = sub( norm_l( maxVal1 ), find_guarded_bits_fx( L_SHB_LAHEAD + 10 ) );
523 :
524 8556 : prev_pow_fx = 0;
525 8556 : move32();
526 8556 : curr_pow_fx = 0;
527 8556 : move32();
528 265236 : FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ )
529 : {
530 256680 : L_tmp = L_shl( shb_synth_nonref_fx[i], shift_prev_pow ); // Qsyn_shb + shift_prev_pow
531 256680 : prev_pow_fx = L_add( prev_pow_fx, Mpy_32_32( L_tmp, L_tmp ) ); /* 2 * ( Qsyn_shb + shift_prev_pow ) - 31 */
532 : }
533 265236 : FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ )
534 : {
535 256680 : L_tmp = L_shl( shb_synth_nonref_fx[L_SHB_LAHEAD + 10 + i], shift_prev_pow ); // Qsyn_shb + shift_prev_pow
536 256680 : curr_pow_fx = L_add( curr_pow_fx, Mpy_32_32( L_tmp, L_tmp ) ); /* 2 * ( Qsyn_shb + shift_prev_pow ) - 31 */
537 : }
538 :
539 8556 : IF( prev_pow_fx == 0 )
540 : {
541 4 : e_scale_fx = 0;
542 4 : move16();
543 4 : scale_fx = 0;
544 4 : move16();
545 : }
546 : ELSE
547 : {
548 8552 : e_scale_fx = 0;
549 8552 : move16();
550 8552 : scale_fx = BASOP_Util_Divide3232_Scale( curr_pow_fx, prev_pow_fx, &e_scale_fx );
551 8552 : scale_fx = Sqrt16( scale_fx, &e_scale_fx );
552 : }
553 8556 : IF( e_scale_fx < 0 )
554 : {
555 886 : scale_fx = shl( scale_fx, e_scale_fx ); /* exp(e_scale_fx) */
556 886 : e_scale_fx = 0;
557 886 : move16();
558 : }
559 179676 : FOR( i = 0; i < L_SHB_LAHEAD; i++ )
560 : {
561 171120 : shb_synth_nonref_fx[i] = Mpy_32_16_1( shb_synth_nonref_fx[i], scale_fx ); // Qsyn_shb
562 171120 : move32();
563 : }
564 8556 : tmp = 3276; /* 0.1 in Q15 */
565 8556 : move16();
566 94116 : FOR( ; i < L_SHB_LAHEAD + 10; i++ )
567 : {
568 85560 : IF( EQ_16( e_scale_fx, 0 ) )
569 : {
570 45560 : temp1_fx = 32767; /* 1.0f in Q15 */
571 45560 : move16();
572 : }
573 : ELSE
574 : {
575 40000 : temp1_fx = shl( 1, sub( 15, e_scale_fx ) ); /* 15 - e_scale_fx */
576 40000 : move16();
577 : }
578 85560 : L_tmp = L_mult0( tmp, temp1_fx ); /* Q15 + Q15 - e_scale_fx */
579 85560 : L_tmp = L_mac0( L_tmp, sub( 32767 /* 1.0f in Q15 */, tmp ), scale_fx ); /* Q15 + Q15 - e_scale_fx */
580 85560 : shb_synth_nonref_fx[i] = Mpy_32_16_1( shb_synth_nonref_fx[i], shl( round_fx( L_tmp ), 1 ) ); // Q_syn_shb - e_scale_fx
581 85560 : move32();
582 85560 : IF( LT_16( tmp, 29492 /* 0.9f in Q15 */ ) )
583 : {
584 77004 : tmp = add( tmp, 3276 /* 0.1f in Q15 */ );
585 : }
586 : }
587 :
588 : /* spec and gs adjustment */
589 8556 : Q_syn_shb = sub( Q_syn_shb, e_scale_fx );
590 8556 : Scale_sig32( shb_synth_nonref_fx + L_SHB_LAHEAD + 10, L_FRAME16k - 10, -e_scale_fx ); /* Q_syn_shb */
591 :
592 8556 : tmp = 31;
593 8556 : move16();
594 8556 : tmp = FindScale( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, Q_syn_shb, tmp );
595 8556 : temp1_fx = norm_l( hStereoICBWE->memShbSpecMapping_fx );
596 8556 : IF( EQ_32( hStereoICBWE->memShbSpecMapping_fx, 0 ) )
597 : {
598 570 : temp1_fx = 31;
599 570 : move16();
600 : }
601 8556 : temp1_fx = add( temp1_fx, hStereoICBWE->prev_Q_memshbspec );
602 8556 : tmp = s_min( temp1_fx, tmp );
603 :
604 8556 : tmp = sub( tmp, 9 );
605 :
606 8556 : Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, sub( tmp, Q_syn_shb ) ); /* tmp */
607 8556 : hStereoICBWE->memShbSpecMapping_fx = L_shl( hStereoICBWE->memShbSpecMapping_fx, sub( tmp, hStereoICBWE->prev_Q_memshbspec ) ); /* tmp */
608 :
609 8556 : hStereoICBWE->prev_Q_memshbspec = tmp;
610 8556 : move16();
611 8556 : Q_syn_shb = tmp;
612 8556 : move16();
613 :
614 8556 : deemph_fx_32( shb_synth_nonref_fx + L_SHB_LAHEAD, specMapping_fx, L_FRAME16k, &( hStereoICBWE->memShbSpecMapping_fx ) );
615 8556 : hStereoICBWE->prev_Q_memshbspec = Q_syn_shb;
616 8556 : move16();
617 8556 : Copy32( shb_synth_nonref_fx + L_FRAME16k, hStereoICBWE->mem_syn_shb_nonref_fx, L_SHB_LAHEAD ); /* Q_syn_shb */
618 8556 : hStereoICBWE->prev_Q_syn_shb_nonref = Q_syn_shb;
619 8556 : move16();
620 :
621 8556 : tmp = 31;
622 8556 : move16();
623 8556 : tmp = FindScale( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, Q_syn_shb, tmp );
624 8556 : tmp = FindScale( hStereoICBWE->mem_syn_shb_ola_nonref_fx, L_SHB_LAHEAD, hStereoICBWE->prev_Q_syn_shb_ola_nonref, tmp );
625 :
626 8556 : tmp = sub( tmp, 3 );
627 :
628 8556 : Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, sub( tmp, Q_syn_shb ) ); /* tmp */
629 8556 : Scale_sig32( hStereoICBWE->mem_syn_shb_ola_nonref_fx, L_SHB_LAHEAD, sub( tmp, hStereoICBWE->prev_Q_syn_shb_ola_nonref ) ); /* tmp */
630 :
631 8556 : ScaleShapedSHB_fx32( SHB_OVERLAP_LEN, shb_synth_nonref_fx, hStereoICBWE->mem_syn_shb_ola_nonref_fx, hStereoICBWE->gshapeRef_fx, ( Mpy_32_16_1( L_shl( hStereoICBWE->gFrameRef_fx, 1 ), mult_r( gsMapping_fx, 29492 /* 0.9 in Q15 */ ) ) ), window_shb_fx, subwin_shb_fx, &tmp, &temp1_fx );
632 :
633 8556 : hStereoICBWE->prev_Q_syn_shb_ola_nonref = tmp;
634 8556 : move16();
635 8556 : Q_syn_shb = tmp;
636 8556 : move16();
637 :
638 8556 : IF( EQ_16( st->extl, FB_TBE ) )
639 : {
640 4093 : v_multc_fixed_16_16( fb_synth_ref_fx, gsMapping_fx, fb_synth_nonref_fx, L_FRAME48k );
641 : }
642 :
643 : /* generate 32kHz SHB synthesis from 12.8(16)kHz signal */
644 :
645 8556 : tmp = 31;
646 8556 : move16();
647 8556 : tmp = FindScale( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, Q_syn_shb, tmp );
648 8556 : tmp = FindScale( hStereoICBWE->memShbHilbert_nonref_fx, HILBERT_MEM_SIZE, hStereoICBWE->prev_Q_hilb, tmp );
649 8556 : tmp = FindScale( hStereoICBWE->memShbInterp_nonref_fx, 2 * ALLPASSSECTIONS_STEEP + 1, hStereoICBWE->prev_Q_interp, tmp );
650 :
651 8556 : tmp = sub( tmp, 3 );
652 :
653 8556 : Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, sub( tmp, Q_syn_shb ) ); /* tmp */
654 8556 : Scale_sig32( hStereoICBWE->memShbHilbert_nonref_fx, HILBERT_MEM_SIZE, sub( tmp, hStereoICBWE->prev_Q_hilb ) ); /* tmp */
655 8556 : Scale_sig32( hStereoICBWE->memShbInterp_nonref_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sub( tmp, hStereoICBWE->prev_Q_interp ) ); /* tmp */
656 :
657 8556 : hStereoICBWE->prev_Q_hilb = tmp;
658 8556 : move16();
659 8556 : hStereoICBWE->prev_Q_interp = tmp;
660 8556 : move16();
661 :
662 8556 : Q_syn_shb = tmp;
663 8556 : move16();
664 :
665 8556 : GenSHBSynth_fx32( shb_synth_nonref_fx, error_fx, hStereoICBWE->memShbHilbert_nonref_fx, hStereoICBWE->memShbInterp_nonref_fx, st->L_frame, &( hStereoICBWE->syn_dm_phase_nonref ) );
666 : }
667 : ELSE
668 : {
669 6609 : Copy32( synthRef_fx, synth_fx, output_frame ); /* Q_syn */
670 :
671 6609 : winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); /* Q0 */
672 6609 : winSlope_fx = div_s( 1, winLen_fx ); /* Q15 */
673 6609 : alpha_fx = winSlope_fx; /* Q15 */
674 6609 : move16();
675 :
676 :
677 6609 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
678 : {
679 6597 : ratio_L_fx = 16384; /* 0.5 in Q15 */
680 6597 : move16();
681 : }
682 : ELSE
683 : {
684 12 : ratio_L_fx = extract_h( tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx] ); /* Q15 */
685 12 : move16();
686 : }
687 :
688 6609 : icbweM2Ref_fx = gsMapping_fx; /* Q14 */
689 6609 : move16();
690 6609 : IF( hStereoICBWE->refChanIndx_bwe == L_CH_INDX )
691 : {
692 :
693 2088 : IF( GE_16( ratio_L_fx, 3276 /* 0.1 in Q15 */ ) )
694 : {
695 2084 : tmp = mult_r( sub( 32767 /* 1.0 in Q15 */, ratio_L_fx ), sub( 32767 /* 1.0 in Q15 */, ratio_L_fx ) ); // Q15
696 2084 : tmp = mult_r( tmp, gsMapping_fx ); // Q14
697 2084 : tmp = mult_r( tmp, gsMapping_fx ); // Q13
698 2084 : IF( LT_16( tmp, 4096 /* 0.5 in Q13*/ ) )
699 : {
700 2080 : temp1_fx = 0;
701 2080 : move16();
702 2080 : temp2_fx = 0;
703 2080 : move16();
704 2080 : tmp = shl( tmp, 2 ); /* Q13 + Q2 */
705 2080 : icbweM2Ref_fx = Sqrt16( sub( 16384 /* 0.5 in Q15 */, tmp ), &temp1_fx );
706 2080 : icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, ratio_L_fx, &temp2_fx );
707 2080 : icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14
708 : }
709 : ELSE
710 : {
711 4 : icbweM2Ref_fx = 0;
712 4 : move16();
713 : }
714 : }
715 : }
716 : ELSE
717 : {
718 4521 : IF( LE_16( ratio_L_fx, 29490 /* 0.9 in Q15*/ ) )
719 : {
720 4521 : tmp = mult_r( ratio_L_fx, ratio_L_fx ); // Q15
721 4521 : tmp = mult_r( tmp, gsMapping_fx ); // Q14
722 4521 : tmp = mult_r( tmp, gsMapping_fx ); // Q13
723 4521 : IF( LT_16( tmp, 4096 /* 0.5 in Q13*/ ) )
724 : {
725 4521 : temp1_fx = 0;
726 4521 : move16();
727 4521 : temp2_fx = 0;
728 4521 : move16();
729 4521 : tmp = shl( tmp, 2 );
730 4521 : icbweM2Ref_fx = Sqrt16( sub( 16384 /* 0.5 in Q15 */, tmp ), &temp1_fx );
731 4521 : icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, sub( 32767, ratio_L_fx ), &temp2_fx );
732 4521 : icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14
733 : }
734 : ELSE
735 : {
736 0 : icbweM2Ref_fx = 0;
737 0 : move16();
738 : }
739 : }
740 : }
741 :
742 6609 : icbweM2Ref_fx = s_max( gsMapping_fx, icbweM2Ref_fx );
743 :
744 248749 : FOR( i = 0; i < winLen_fx; i++ )
745 : {
746 242140 : L_tmp = L_mult0( alpha_fx, icbweM2Ref_fx ); /* Q29 */
747 242140 : L_tmp = L_mac0( L_tmp, sub( 32767 /* 1.0 in Q15*/, alpha_fx ), hStereoICBWE->icbweM2Ref_prev_fx ); /* Q29 */
748 242140 : tmp = shl( round_fx( L_tmp ), 1 ); /* Q14 */
749 242140 : synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], tmp ); /* Qsyn - 1*/
750 242140 : move32();
751 242140 : L_tmp = L_mult0( alpha_fx, gsMapping_fx ); /* Q29 */
752 242140 : L_tmp = L_mac0( L_tmp, sub( 32767 /* 1.0 in Q15*/, alpha_fx ), prevgsMapping_fx ); /* Q29 */
753 242140 : tmp = shl( round_fx( L_tmp ), 1 ); /* Q14 */
754 242140 : synth_fx[i] = Mpy_32_16_1( synth_fx[i], tmp ); /* Qsyn - 1 */
755 242140 : move32();
756 242140 : IF( LE_16( alpha_fx, sub( 32767 /* 1.0 in Q15*/, winSlope_fx ) ) )
757 : {
758 235531 : alpha_fx = add( alpha_fx, winSlope_fx ); /* Q15 */
759 : }
760 : }
761 3638709 : FOR( ; i < NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS ); i++ )
762 : {
763 3632100 : synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); /* Qsyn - 1 */
764 3632100 : move32();
765 3632100 : synth_fx[i] = Mpy_32_16_1( synth_fx[i], gsMapping_fx ); /* Qsyn - 1 */
766 3632100 : move32();
767 : }
768 6609 : hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; /* Q14 */
769 6609 : move16();
770 :
771 6609 : ic_bwe_dec_reset_fx( hStereoICBWE );
772 6609 : hStereoICBWE->prevSpecMapping_fx = 0;
773 6609 : move16();
774 :
775 6609 : *Q_syn = sub( *Q_syn, 1 );
776 6609 : move16();
777 :
778 6609 : return;
779 : }
780 :
781 : /* resample to output FS */
782 :
783 :
784 8556 : IF( EQ_32( st->output_Fs, 48000 /* Q0 */ ) )
785 : {
786 5199 : tmp = 31;
787 5199 : move16();
788 5199 : tmp = FindScale( error_fx, L_FRAME32k, Q_syn_shb, tmp );
789 5199 : tmp = FindScale( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, hStereoICBWE->prev_Q_fsout, tmp );
790 5199 : tmp = sub( tmp, 4 );
791 :
792 5199 : Scale_sig32( error_fx, L_FRAME32k, sub( tmp, Q_syn_shb ) ); /* tmp */
793 5199 : Scale_sig32( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, sub( tmp, hStereoICBWE->prev_Q_fsout ) ); /* tmp */
794 5199 : interpolate_3_over_2_allpass_fx32( error_fx, L_FRAME32k, synth_fx, hStereoICBWE->memShb_fsout_nonref_fx );
795 5199 : hStereoICBWE->prev_Q_fsout = tmp;
796 5199 : move16();
797 : }
798 3357 : ELSE IF( EQ_32( st->output_Fs, 32000 /* Q0 */ ) )
799 : {
800 3357 : Copy32( error_fx, synth_fx, L_FRAME32k ); /* tmp */
801 : }
802 0 : ELSE IF( EQ_32( st->output_Fs, 16000 /* Q0 */ ) )
803 : {
804 0 : tmp = 31;
805 0 : move16();
806 0 : tmp = FindScale( error_fx, L_FRAME32k, Q_syn_shb, tmp );
807 0 : tmp = FindScale( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, hStereoICBWE->prev_Q_fsout, tmp );
808 0 : tmp = sub( tmp, 4 );
809 :
810 0 : Scale_sig32( error_fx, L_FRAME32k, sub( tmp, Q_syn_shb ) ); /* tmp */
811 0 : Scale_sig32( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, sub( tmp, hStereoICBWE->prev_Q_fsout ) ); /* tmp */
812 0 : Decimate_allpass_steep_fx32( error_fx, hStereoICBWE->memShb_fsout_nonref_fx, L_FRAME32k, synth_fx );
813 0 : hStereoICBWE->prev_Q_fsout = tmp;
814 0 : move16();
815 : }
816 8556 : Scale_sig32( synth_fx, output_frame, sub( *Q_syn, add( 1, tmp ) ) ); /* Qsyn - 1 */
817 :
818 8556 : *Q_syn = sub( *Q_syn, 1 );
819 :
820 8556 : test();
821 8556 : IF( EQ_16( st->extl, FB_TBE ) && EQ_32( st->output_Fs, 48000 /* Q0*/ ) )
822 : {
823 :
824 : // v_add( fb_synth_nonref_fx, synth_fx, synth_fx, L_FRAME48k, 0 );
825 3152 : tmp = shl_sat( 1, sub( Q11 + 15, Q_white_exc ) ); /* 29 - Q_white_exc */
826 3152 : IF( tmp != 0 )
827 : {
828 2933933 : FOR( i = 0; i < L_FRAME48k; i++ )
829 : {
830 2930880 : synth_fx[i] = L_mac( synth_fx[i], fb_synth_nonref_fx[i], tmp ); /* Q_syn */
831 : }
832 : }
833 : }
834 :
835 : /* copy to outputHB and reset hb_synth values */
836 :
837 8556 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
838 : {
839 8534 : ratio_L_fx = 16384; /* 1.0 in Q15 */
840 8534 : move16();
841 : }
842 : ELSE
843 : {
844 22 : ratio_L_fx = extract_h( tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx] ); /* Q15 */
845 22 : move16();
846 : }
847 :
848 8556 : icbweM2Ref_fx = gsMapping_fx;
849 8556 : move16();
850 8556 : IF( hStereoICBWE->refChanIndx_bwe == L_CH_INDX )
851 : {
852 2743 : IF( GE_16( ratio_L_fx, 3276 /* 0.1 in Q15*/ ) )
853 : {
854 2735 : tmp = mult_r( sub( 32767 /* 1.0 in Q15*/, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15
855 2735 : tmp = mult_r( tmp, gsMapping_fx ); // Q14
856 2735 : tmp = mult_r( tmp, gsMapping_fx ); // Q13
857 2735 : IF( LT_16( tmp, 4096 /* 0.5 in Q13*/ ) )
858 : {
859 2730 : temp1_fx = 0;
860 2730 : move16();
861 2730 : temp2_fx = 0;
862 2730 : move16();
863 2730 : tmp = shl( tmp, 2 );
864 2730 : icbweM2Ref_fx = Sqrt16( sub( 16384 /* 0.5 in Q15*/, tmp ), &temp1_fx );
865 2730 : icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, ratio_L_fx, &temp2_fx );
866 2730 : icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp1_fx, sub( temp2_fx, 1 ) ) ); // Q14
867 : }
868 : ELSE
869 : {
870 5 : icbweM2Ref_fx = 0;
871 5 : move16();
872 : }
873 : }
874 : }
875 : ELSE
876 : {
877 5813 : IF( LE_16( ratio_L_fx, 29490 /* 0.9 in Q15*/ ) )
878 : {
879 5813 : tmp = mult_r( ratio_L_fx, ratio_L_fx ); // Q15
880 5813 : tmp = mult_r( tmp, gsMapping_fx ); // Q14
881 5813 : tmp = mult_r( tmp, gsMapping_fx ); // Q13
882 5813 : IF( LT_16( tmp, 4096 /* 0.5 in Q13*/ ) )
883 : {
884 5813 : temp1_fx = 0;
885 5813 : move16();
886 5813 : temp2_fx = 0;
887 5813 : move16();
888 5813 : tmp = shl( tmp, 2 );
889 5813 : icbweM2Ref_fx = Sqrt16( sub( 16384 /* 0.5 in Q15*/, tmp ), &temp1_fx );
890 5813 : icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, sub( 32767, ratio_L_fx ), &temp2_fx );
891 5813 : icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14
892 : }
893 : ELSE
894 : {
895 0 : icbweM2Ref_fx = 0;
896 0 : move16();
897 : }
898 : }
899 : }
900 :
901 8556 : icbweM2Ref_fx = s_max( gsMapping_fx, icbweM2Ref_fx ); /* Q14 */
902 :
903 8556 : winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); /* Q0 */
904 8556 : winSlope_fx = div_s( 1, winLen_fx ); /* Q15 */
905 8556 : alpha_fx = winSlope_fx; /* Q15 */
906 8556 : move16();
907 : #ifdef FIX_1439_SPEEDUP_stereo_icBWE_dec_fx
908 8556 : Word16 winSlope_fx_ = sub( 32767 /* 1.0 in Q15*/, winSlope_fx );
909 : #endif
910 454776 : FOR( i = 0; i < winLen_fx; i++ )
911 : {
912 446220 : L_tmp = L_mult0( alpha_fx, icbweM2Ref_fx ); /* Q29 */
913 446220 : L_tmp = L_mac0( L_tmp, sub( 32767 /* 1.0 in Q15*/, alpha_fx ), hStereoICBWE->icbweM2Ref_prev_fx ); /* Q29 */
914 446220 : tmp = shl( round_fx( L_tmp ), 1 ); /* Q14 */
915 446220 : synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], tmp ); /* Qsyn - 1 */
916 446220 : move32();
917 : #ifdef FIX_1439_SPEEDUP_stereo_icBWE_dec_fx
918 446220 : if ( LE_16( alpha_fx, winSlope_fx_ ) )
919 : {
920 437664 : alpha_fx = add( alpha_fx, winSlope_fx ); /* Q15 */
921 : }
922 : #else
923 : IF( LE_16( alpha_fx, sub( 32767 /* 1.0 in Q15*/, winSlope_fx ) ) )
924 : {
925 : alpha_fx = add( alpha_fx, winSlope_fx ); /* Q15 */
926 : }
927 : #endif
928 : }
929 :
930 6701856 : FOR( ; i < NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS ); i++ )
931 : {
932 6693300 : synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); /* Qsyn - 1 */
933 6693300 : move32();
934 : }
935 :
936 8556 : hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; /* Q14 */
937 8556 : move16();
938 :
939 8556 : return;
940 : }
941 :
942 : /*-------------------------------------------------------------------*
943 : * stereo_icBWE_decproc()
944 : *
945 : * Stereo (inter-channel) BWE mapping - decoder initialization
946 : *-------------------------------------------------------------------*/
947 :
948 145402 : void stereo_icBWE_decproc_fx(
949 : CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */
950 : Word32 *output[CPE_CHANNELS], /* i/o: output synthesis Q11*/
951 : Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis Q11*/
952 : const Word16 last_core, /* i : last core, primary channel Q0*/
953 : const Word16 last_bwidth, /* i : last bandwidth Q0*/
954 : const Word16 output_frame /* i : frame length Q0*/
955 : )
956 : {
957 : Word16 i, j, n, decoderDelay, icbweOLASize, dftOvlLen;
958 : Word16 core, memOffset, refChanIndx_bwe;
959 :
960 : Word32 temp0_fx[L_FRAME48k + NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )], temp1_fx[L_FRAME48k + NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )];
961 145402 : Word16 winSlope_fx = 0, alpha_fx;
962 145402 : move32();
963 : const Word16 *win_dft_fx;
964 : Word32 extl_brate, output_Fs;
965 :
966 145402 : STEREO_ICBWE_DEC_HANDLE hStereoICBWE = hCPE->hStereoICBWE;
967 :
968 : /*--------------------------------------------------------------------*
969 : * skip IC-BWE in case of SID or NO_DATA frame
970 : * -------------------------------------------------------------------*/
971 :
972 145402 : test();
973 145402 : test();
974 145402 : test();
975 145402 : IF( ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) && EQ_16( hCPE->nchan_out, 2 ) /*&& hCPE->hCoreCoder[0]->core_brate > SID_2k40*/ && LE_32( hCPE->hCoreCoder[0]->last_core_brate, SID_2k40 ) )
976 : {
977 5470 : stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE );
978 : }
979 :
980 145402 : IF( LE_32( hCPE->hCoreCoder[0]->core_brate, SID_2k40 ) )
981 : {
982 14523 : return;
983 : }
984 :
985 : /*--------------------------------------------------------------------*
986 : * skip IC-BWE in case of mono DMX output *
987 : * -------------------------------------------------------------------*/
988 :
989 130879 : test();
990 130879 : test();
991 130879 : IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
992 : {
993 17465 : add_HB_to_mono_dmx_fx( hCPE, output[0], outputHB[0], last_core, output_frame );
994 17465 : return;
995 : }
996 113414 : ELSE IF( EQ_16( hCPE->nchan_out, 1 ) && NE_16( hCPE->element_mode, IVAS_CPE_TD ) )
997 : {
998 5872 : return;
999 : }
1000 :
1001 : /*--------------------------------------------------------------------*
1002 : * IC-BWE processing
1003 : * -------------------------------------------------------------------*/
1004 :
1005 107542 : core = hCPE->hCoreCoder[0]->core; /* Q0 */
1006 107542 : move16();
1007 107542 : extl_brate = hCPE->hCoreCoder[0]->extl_brate; /* Q0 */
1008 107542 : move32();
1009 107542 : output_Fs = hCPE->hCoreCoder[0]->output_Fs; /* Q0 */
1010 107542 : move32();
1011 :
1012 107542 : memOffset = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); /* Q0 */
1013 :
1014 : /* LRTD stereo mode - 2xBWEs used */
1015 107542 : test();
1016 107542 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->tdm_LRTD_flag )
1017 : {
1018 : /* delay HB synth */
1019 10875 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1020 : {
1021 7250 : Copy32( outputHB[n] + output_frame - memOffset, temp0_fx, memOffset ); /* Q11 */
1022 7250 : Copy32( outputHB[n], outputHB[n] + memOffset, output_frame - memOffset ); /* Q11 */
1023 7250 : Copy32( hCPE->prev_hb_synth_fx[n], outputHB[n], memOffset ); /* Q11 */
1024 7250 : Copy32( temp0_fx, hCPE->prev_hb_synth_fx[n], memOffset ); /* Q11 */
1025 : }
1026 :
1027 3625 : IF( EQ_16( hCPE->nchan_out, 1 ) )
1028 : {
1029 : /* stereo to mono downmix */
1030 791399 : FOR( i = 0; i < output_frame; i++ )
1031 : {
1032 790080 : outputHB[0][i] = W_extract_l( W_shr( W_mac_32_16( W_mult_32_16( outputHB[0][i], 16384 ), outputHB[1][i], 16384 ), Q16 ) ); /* Q11 */
1033 790080 : move32();
1034 : }
1035 1319 : v_add_32( output[0], outputHB[0], output[0], output_frame );
1036 : }
1037 : ELSE
1038 : {
1039 : /* Add the delayed hb_synth component to the delayed ACELP synthesis */
1040 6918 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1041 : {
1042 4612 : v_add_32( output[n], outputHB[n], output[n], output_frame );
1043 : }
1044 : }
1045 : }
1046 : ELSE
1047 : {
1048 311751 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1049 : {
1050 207834 : set32_fx( hCPE->prev_hb_synth_fx[n], 0, memOffset );
1051 : }
1052 : }
1053 :
1054 107542 : test();
1055 107542 : test();
1056 107542 : test();
1057 107542 : test();
1058 107542 : test();
1059 107542 : test();
1060 107542 : IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->tdm_LRTD_flag ) )
1061 : {
1062 31357 : IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) )
1063 : {
1064 262 : set32_fx( hStereoICBWE->memOutHB_fx[0], 0, memOffset );
1065 262 : set32_fx( hStereoICBWE->memOutHB_fx[1], 0, memOffset );
1066 :
1067 262 : set32_fx( hStereoICBWE->memTransitionHB_fx[0], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
1068 262 : set32_fx( hStereoICBWE->memTransitionHB_fx[1], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
1069 : }
1070 :
1071 31357 : test();
1072 31357 : IF( EQ_16( core, ACELP_CORE ) && extl_brate > 0 )
1073 : {
1074 17839 : refChanIndx_bwe = hStereoICBWE->refChanIndx_bwe;
1075 17839 : move16();
1076 :
1077 17839 : test();
1078 17839 : test();
1079 17839 : test();
1080 17839 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && GT_16( hCPE->hCoreCoder[0]->bwidth, WB ) && EQ_16( last_bwidth, WB ) && GT_16( hCPE->hCoreCoder[0]->ini_frame, 1 ) /* counter wass already updated */ )
1081 : {
1082 : /* fad-in reference HB signal */
1083 21 : IF( GT_16( memOffset, 0 ) )
1084 : {
1085 21 : SWITCH( memOffset )
1086 : {
1087 0 : case 15:
1088 0 : winSlope_fx = 2185; /* 0.06 in Q15 */
1089 0 : move32();
1090 0 : BREAK;
1091 10 : case 30:
1092 10 : winSlope_fx = 1092; /* 0.03 in Q15 */
1093 10 : move32();
1094 10 : BREAK;
1095 11 : case 45:
1096 11 : winSlope_fx = 728; /* 0.02 in Q15 */
1097 11 : move32();
1098 11 : BREAK;
1099 : }
1100 : // memOffset for 16K 32K 48K are 15 30 45 respectively.camera
1101 21 : }
1102 : ELSE
1103 : {
1104 0 : winSlope_fx = 0;
1105 0 : move32();
1106 : }
1107 21 : alpha_fx = 0;
1108 21 : move16();
1109 816 : FOR( i = 0; i < memOffset; i++ )
1110 : {
1111 795 : alpha_fx = add_sat( alpha_fx, winSlope_fx ); /* Q15 */
1112 795 : outputHB[refChanIndx_bwe][i] = W_round48_L( W_mult_32_16( outputHB[refChanIndx_bwe][i] /* Q11 + Q15 + 1 - 16 = Q11)*/, winSlope_fx ) ); // Q11
1113 795 : move32();
1114 : }
1115 : }
1116 : /* Resampled LB and HB offset */
1117 17839 : Copy32( outputHB[refChanIndx_bwe], temp0_fx + memOffset, sub( output_frame, memOffset ) ); /* Q11 */
1118 17839 : Copy32( outputHB[!refChanIndx_bwe], temp1_fx + memOffset, sub( output_frame, memOffset ) ); /* Q11 */
1119 :
1120 17839 : decoderDelay = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */
1121 :
1122 17839 : test();
1123 17839 : IF( last_core != ACELP_CORE && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
1124 : {
1125 : /* hb_synth of mid band is faded out in the 1.25 ms prior to DFT analysis and the icbwe is faded in time domain */
1126 603 : icbweOLASize = NS2SA_FX2( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); /* Q0 */
1127 :
1128 70751 : FOR( i = 0; i < decoderDelay; i++ )
1129 : {
1130 70148 : temp0_fx[i] = 0;
1131 70148 : move32();
1132 70148 : temp1_fx[i] = 0;
1133 70148 : move32();
1134 : }
1135 :
1136 603 : assert( icbweOLASize > 0 );
1137 603 : SWITCH( icbweOLASize )
1138 : {
1139 250 : case 60:
1140 250 : winSlope_fx = 546; /* 0.0166 in Q15 */
1141 250 : move16();
1142 250 : BREAK;
1143 246 : case 40:
1144 246 : winSlope_fx = 819; /* 0.025 in Q15 */
1145 246 : move16();
1146 246 : BREAK;
1147 107 : case 20:
1148 107 : winSlope_fx = 1638; /* 0.05 in Q15 */
1149 107 : move16();
1150 107 : BREAK;
1151 0 : default:
1152 0 : fprintf( stderr, "icbweOLASize of size %d not implemented \n", icbweOLASize );
1153 0 : assert( 0 );
1154 : BREAK;
1155 : }
1156 603 : alpha_fx = winSlope_fx; // Q15
1157 603 : move32();
1158 27583 : FOR( ; i < add( decoderDelay, icbweOLASize ); i++ )
1159 : {
1160 26980 : temp0_fx[i] = W_round48_L( W_mult_32_16( temp0_fx[i], alpha_fx ) ); // Q11
1161 26980 : move32();
1162 26980 : temp1_fx[i] = W_round48_L( W_mult_32_16( temp1_fx[i], alpha_fx ) ); // Q11
1163 26980 : move32();
1164 26980 : alpha_fx = add_sat( alpha_fx, winSlope_fx ); // Q15
1165 : }
1166 : }
1167 : ELSE
1168 : {
1169 17236 : IF( NE_16( refChanIndx_bwe, hStereoICBWE->prev_refChanIndx_bwe ) )
1170 : {
1171 2287 : IF( memOffset > 0 )
1172 : {
1173 2287 : SWITCH( memOffset )
1174 : {
1175 330 : case 15:
1176 330 : winSlope_fx = 2185; /* 0.06 in Q15 */
1177 330 : move16();
1178 330 : BREAK;
1179 863 : case 30:
1180 863 : winSlope_fx = 1092; /* 0.03 in Q15 */
1181 863 : move16();
1182 863 : BREAK;
1183 1094 : case 45:
1184 1094 : winSlope_fx = 728; /* 0.022 in Q15 */
1185 1094 : move16();
1186 1094 : BREAK;
1187 : }
1188 : // memOffset for 16K 32K 48K are 15 30 45 respectively.camera
1189 2287 : }
1190 : ELSE
1191 : {
1192 0 : winSlope_fx = 0;
1193 0 : move32();
1194 : }
1195 2287 : Word16 Incr = 0;
1196 2287 : Word16 Decr = MAX_16;
1197 2287 : move16();
1198 2287 : move16();
1199 82357 : FOR( i = 0; i < memOffset; i++ )
1200 : {
1201 80070 : Incr = add_sat( Incr, winSlope_fx ); /* Q15 */
1202 80070 : Decr = sub( Decr, winSlope_fx ); /* Q15 */
1203 80070 : temp0_fx[i] = W_round48_L( W_mac_32_16( W_mult_32_16( hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i], Incr ), hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i], Decr ) ); /* Q11 */
1204 80070 : temp1_fx[i] = W_round48_L( W_mac_32_16( W_mult_32_16( hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i], Incr ), hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i], Decr ) ); /* Q11 */
1205 80070 : move32();
1206 : }
1207 : }
1208 : ELSE
1209 : {
1210 14949 : Copy32( hStereoICBWE->memOutHB_fx[refChanIndx_bwe], temp0_fx, memOffset ); /* Q11 */
1211 14949 : Copy32( hStereoICBWE->memOutHB_fx[!refChanIndx_bwe], temp1_fx, memOffset ); /* Q11 */
1212 : }
1213 : }
1214 :
1215 17839 : IF( EQ_16( hCPE->nchan_out, 1 ) )
1216 : {
1217 : Word64 W_tmp;
1218 : /* stereo to mono downmix */
1219 5769 : FOR( i = 0; i < output_frame; i++ )
1220 : {
1221 5760 : W_tmp = W_mult_32_16( output[0][i], 32767 /* 1.0 in Q15*/ ); /* Q11 */
1222 5760 : W_tmp = W_mac_32_16( W_tmp, temp0_fx[i], 16384 /* 0.5 in Q15*/ ); /* Q11*/
1223 5760 : output[0][i] = W_round48_L( W_mac_32_16( W_tmp, temp1_fx[i], 16384 /* 0.5 in Q15*/ ) ); /* Q11 */
1224 5760 : move32();
1225 5760 : move32();
1226 : }
1227 : }
1228 : ELSE
1229 : {
1230 17830 : v_add_32( temp0_fx, output[0], output[0], output_frame );
1231 17830 : v_add_32( temp1_fx, output[1], output[1], output_frame );
1232 : }
1233 :
1234 17839 : Copy32( outputHB[0] + output_frame - memOffset, hStereoICBWE->memOutHB_fx[0], memOffset ); /* Q11*/
1235 17839 : Copy32( outputHB[1] + output_frame - memOffset, hStereoICBWE->memOutHB_fx[1], memOffset ); /* Q11 */
1236 :
1237 17839 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
1238 : {
1239 : /*win_dft = hCPE->hStereoDft->win32ms;*/
1240 17802 : win_dft_fx = hCPE->hStereoDft->win32ms_fx; /* Q15 */
1241 17802 : dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; /* Q0 */
1242 17802 : move16();
1243 :
1244 : /* Preparing buffers in anticipation of an ACELP to TCX switch */
1245 :
1246 17802 : j = sub( dftOvlLen, 1 );
1247 575667 : FOR( i = 0; i < memOffset; i++ )
1248 : {
1249 557865 : Word16 tmp_mul = i_mult( STEREO_DFT32MS_STEP, j );
1250 557865 : hStereoICBWE->memTransitionHB_fx[0][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[0][i], win_dft_fx[tmp_mul] ); /* Q11 */
1251 557865 : move32();
1252 557865 : hStereoICBWE->memTransitionHB_fx[1][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[1][i], win_dft_fx[tmp_mul] ); /* Q11 */
1253 557865 : move32();
1254 557865 : j = sub( j, 1 );
1255 : }
1256 :
1257 593469 : FOR( i = 0; j < dftOvlLen; i++ )
1258 : {
1259 575667 : Word16 tmp_mul = mult0( STEREO_DFT32MS_STEP, ( sub( dftOvlLen, add( 1, j ) ) ) );
1260 575667 : hStereoICBWE->memTransitionHB_fx[0][memOffset + i] = Mpy_32_16_1( outputHB[0][output_frame - i - 1], win_dft_fx[tmp_mul] ); /* Q11 */
1261 575667 : move32();
1262 575667 : hStereoICBWE->memTransitionHB_fx[1][memOffset + i] = Mpy_32_16_1( outputHB[1][output_frame - i - 1], win_dft_fx[tmp_mul] ); /* Q11 */
1263 575667 : move32();
1264 575667 : j = add( j, 1 );
1265 : }
1266 : }
1267 :
1268 17839 : hStereoICBWE->prev_refChanIndx_bwe = refChanIndx_bwe;
1269 17839 : move16();
1270 : }
1271 : ELSE
1272 : {
1273 13518 : IF( last_core == ACELP_CORE )
1274 : {
1275 3238 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
1276 : {
1277 23 : v_add_32( output[0], hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe], output[0], memOffset );
1278 23 : v_add_32( output[1], hStereoICBWE->memOutHB_fx[!hStereoICBWE->prev_refChanIndx_bwe], output[1], memOffset );
1279 : }
1280 : ELSE
1281 : {
1282 : /* This is generated in the ACELP frame and windowed. This process is akin to GenTransition for IC-BWE */
1283 3215 : v_add_32( output[0], hStereoICBWE->memTransitionHB_fx[hStereoICBWE->prev_refChanIndx_bwe], output[0], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
1284 3215 : v_add_32( output[1], hStereoICBWE->memTransitionHB_fx[!hStereoICBWE->prev_refChanIndx_bwe], output[1], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
1285 : }
1286 :
1287 3238 : set32_fx( hStereoICBWE->memOutHB_fx[0], 0, memOffset );
1288 3238 : set32_fx( hStereoICBWE->memOutHB_fx[1], 0, memOffset );
1289 :
1290 3238 : set32_fx( hStereoICBWE->memTransitionHB_fx[0], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
1291 3238 : set32_fx( hStereoICBWE->memTransitionHB_fx[1], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
1292 : }
1293 : }
1294 : }
1295 76185 : ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->tdm_LRTD_flag && hStereoICBWE != NULL )
1296 : {
1297 0 : stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE );
1298 : }
1299 76185 : ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && EQ_16( last_core, ACELP_CORE ) )
1300 : {
1301 511 : Word16 delay_tdbwe = NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS );
1302 :
1303 1533 : FOR( n = 0; n < hCPE->nchan_out; n++ )
1304 : {
1305 101366 : FOR( i = 0; i < delay_tdbwe; i++ )
1306 : {
1307 100344 : output[n][NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe + i] = L_add_sat( output[n][NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe + i], outputHB[0][i] );
1308 100344 : move32();
1309 : }
1310 : }
1311 :
1312 : /* reset BWE structs as they are only needed in the transition frame in MDCT Stereo */
1313 511 : td_bwe_dec_init_fx( hCPE->hCoreCoder[0]->hBWE_TD, -1, output_Fs );
1314 511 : fd_bwe_dec_init_fx( hCPE->hCoreCoder[0]->hBWE_FD );
1315 :
1316 511 : hCPE->hCoreCoder[0]->prev_Q_bwe_exc = 31;
1317 511 : move16();
1318 : }
1319 :
1320 107542 : test();
1321 107542 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && GT_32( L_max( hCPE->hStereoDft->td_gain_fx[0], hCPE->hStereoDft->td_gain_fx[1] ), 0 ) )
1322 : {
1323 : Word32 win_in_fx, win_out_fx, tmp_fx;
1324 : Word64 W_tmp, W_tmp1;
1325 16790 : win_dft_fx = hCPE->hStereoDft->win32ms_fx; /* Q15 */
1326 16790 : dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; /* Q0 */
1327 16790 : move16();
1328 :
1329 : // Scale_sig32(hCPE->hStereoDft->td_gain_fx, STEREO_DFT_CORE_HIST_MAX, -12);
1330 :
1331 1773790 : FOR( i = 0; i < dftOvlLen; i++ )
1332 : {
1333 1757000 : j = i_mult( STEREO_DFT32MS_STEP, i );
1334 1757000 : win_in_fx = L_mult( win_dft_fx[j], win_dft_fx[j] ); /* Q31 */
1335 1757000 : win_out_fx = L_sub( ONE_IN_Q31, win_in_fx ); /* Q31 */
1336 : /* hCPE->hStereoDft->q_hb_stefi_sig_fx is always 31 here */
1337 : /* tmp = ( win_in * hCPE->hStereoDft->td_gain[0] + win_out * hCPE->hStereoDft->td_gain[1] ) * hCPE->hStereoDft->hb_stefi_sig[i]; */
1338 :
1339 1757000 : W_tmp = W_mult_32_32( hCPE->hStereoDft->td_gain_fx[0], win_in_fx ); /* q_td_gain + Q31 + 1 */
1340 1757000 : if ( hCPE->hStereoDft->q_td_gain[0] != 0 )
1341 : {
1342 1659250 : W_tmp = W_shl( W_tmp, sub( 31, hCPE->hStereoDft->q_td_gain[0] ) ); /* Q63 */
1343 : }
1344 1757000 : W_tmp1 = W_mult_32_32( hCPE->hStereoDft->td_gain_fx[1], win_out_fx ); /* q_td_gain + Q31 + 1 */
1345 1757000 : if ( hCPE->hStereoDft->q_td_gain[1] != 0 )
1346 : {
1347 1644900 : W_tmp1 = W_shl( W_tmp1, sub( 31, hCPE->hStereoDft->q_td_gain[1] ) ); /* Q63 */
1348 : }
1349 1757000 : tmp_fx = W_extract_h( W_add_nosat( W_tmp, W_tmp1 ) ); /* Q31 */
1350 1757000 : tmp_fx = W_extract_h( W_mult_32_32( tmp_fx, hCPE->hStereoDft->hb_stefi_sig_fx[i] ) ); /* Q11 */
1351 :
1352 1757000 : output[0][i] = L_add_sat( output[0][i], tmp_fx ); /* Q11 */
1353 1757000 : move32();
1354 1757000 : output[1][i] = L_sub_sat( output[1][i], tmp_fx ); /* Q11 */
1355 1757000 : move32();
1356 : }
1357 9504590 : FOR( i = dftOvlLen; i < output_frame; i++ )
1358 : {
1359 9487800 : tmp_fx = W_extract_h( W_mult_32_32( hCPE->hStereoDft->td_gain_fx[0], hCPE->hStereoDft->hb_stefi_sig_fx[i] ) ); /* Q11 --> Q11 */
1360 9487800 : output[0][i] = L_add_sat( output[0][i], tmp_fx ); /* Q11 */
1361 9487800 : move32();
1362 9487800 : output[1][i] = L_sub_sat( output[1][i], tmp_fx ); /* Q11 */
1363 9487800 : move32();
1364 : }
1365 : }
1366 :
1367 107542 : return;
1368 : }
1369 :
1370 : /*-------------------------------------------------------------------*
1371 : * stereo_icBWE_init_dec()
1372 : *
1373 : * Stereo (inter-channel) BWE mapping - decoder initialization
1374 : *-------------------------------------------------------------------*/
1375 :
1376 6280 : void stereo_icBWE_init_dec_fx(
1377 : STEREO_ICBWE_DEC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */
1378 : )
1379 : {
1380 : /* BWE ref channel */
1381 6280 : hStereoICBWE->refChanIndx_bwe = L_CH_INDX;
1382 6280 : move16();
1383 6280 : hStereoICBWE->prev_refChanIndx_bwe = L_CH_INDX;
1384 6280 : move16();
1385 :
1386 : /* SHB output memory */
1387 6280 : set32_fx( hStereoICBWE->memOutHB_fx[0], 0, NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) );
1388 6280 : set32_fx( hStereoICBWE->memOutHB_fx[1], 0, NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) );
1389 :
1390 :
1391 : /* SHB output memory */
1392 6280 : set32_fx( hStereoICBWE->memTransitionHB_fx[0], 0, NS2SA( 48000, STEREO_DFT32MS_OVL_NS ) );
1393 6280 : set32_fx( hStereoICBWE->memTransitionHB_fx[1], 0, NS2SA( 48000, STEREO_DFT32MS_OVL_NS ) );
1394 :
1395 : /* inter-channel BWE spectral shape adj. */
1396 6280 : hStereoICBWE->prevSpecMapping_fx = 0;
1397 6280 : move16();
1398 6280 : hStereoICBWE->prevgsMapping_fx = 16384; /* 1.0 in Q14 */
1399 6280 : move16();
1400 6280 : hStereoICBWE->icbweM2Ref_prev_fx = 16384; /* 1.0 in Q14 */
1401 6280 : move16();
1402 :
1403 6280 : hStereoICBWE->prev_spIndx = 0;
1404 6280 : move16();
1405 6280 : hStereoICBWE->prev_gsIndx = 0;
1406 6280 : move16();
1407 :
1408 6280 : ic_bwe_dec_reset_fx( hStereoICBWE );
1409 :
1410 6280 : return;
1411 : }
|