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 <assert.h>
35 : #include <math.h>
36 : #include "options.h"
37 : #include "ivas_prot_rend_fx.h"
38 : #include "prot_fx.h"
39 : #include "rom_com.h"
40 : #include "ivas_rom_com.h"
41 : #include "ivas_rom_dec.h"
42 : #include "wmc_auto.h"
43 : #include "ivas_prot_fx.h"
44 : #include "debug.h"
45 :
46 :
47 : /*-----------------------------------------------------------------------*
48 : * Local function definitions
49 : *-----------------------------------------------------------------------*/
50 :
51 21113 : static void ivas_param_ism_dec_dequant_DOA_fx(
52 : PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */
53 : const Word16 nchan_ism /* i : number of ISM channels */
54 : )
55 : {
56 : Word16 i;
57 : PARAM_ISM_CONFIG_HANDLE hParamIsm;
58 :
59 21113 : hParamIsm = hParamIsmDec->hParamIsm;
60 :
61 21113 : assert( nchan_ism <= MAX_NUM_OBJECTS );
62 :
63 : /* Get the azimuth and elevation values */
64 98814 : FOR( i = 0; i < nchan_ism; i++ )
65 : {
66 77701 : hParamIsmDec->azimuth_values_fx[i] = ism_dequant_meta_fx( hParamIsm->azi_index[i], ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); // Q22
67 77701 : move16();
68 77701 : hParamIsmDec->elevation_values_fx[i] = ism_dequant_meta_fx( hParamIsm->ele_index[i], ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); // Q22
69 77701 : move16();
70 : }
71 :
72 21113 : return;
73 : }
74 :
75 21113 : static void ivas_param_ism_dec_dequant_powrat_fx(
76 : PARAM_ISM_DEC_HANDLE hParamIsmDec /* i/o: decoder ParamISM handle */
77 : )
78 : {
79 : Word16 band_idx, slot_idx;
80 : PARAM_ISM_CONFIG_HANDLE hParamIsm;
81 :
82 21113 : hParamIsm = hParamIsmDec->hParamIsm;
83 : /* Get the power ratio values */
84 253356 : FOR( band_idx = 0; band_idx < hParamIsm->nbands; band_idx++ )
85 : {
86 464486 : FOR( slot_idx = 0; slot_idx < hParamIsm->nblocks[band_idx]; slot_idx++ )
87 : {
88 232243 : hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] = add( shr( imult1616( hParamIsm->power_ratios_idx[band_idx][slot_idx], 4681 /* ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) in Q15 */ ), 1 ), 16384 /*.5f in Q15 */ ); /* Q15 */
89 232243 : move16();
90 232243 : hParamIsmDec->power_ratios_fx[band_idx][slot_idx][1] = sub( 32767, hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] ); // Q15 , 32767= (1.0f in Q15) -1
91 232243 : move16();
92 : }
93 : }
94 21113 : return;
95 : }
96 :
97 :
98 166 : static void ivas_ism_get_interpolator_fx(
99 : const Word16 subframe_nbslots,
100 : Word16 *interpolator /*Q15*/
101 : )
102 : {
103 : Word16 interp_idx, q_tmp, tmp;
104 :
105 4038 : FOR( interp_idx = 0; interp_idx < subframe_nbslots; interp_idx++ )
106 : {
107 3872 : tmp = BASOP_Util_Divide1616_Scale( add( interp_idx, 1 ), subframe_nbslots, &q_tmp ); /*Q = 15 - q_tmp*/
108 3872 : interpolator[interp_idx] = shl_sat( tmp, q_tmp ); /* Q15 */
109 3872 : move16();
110 : }
111 :
112 166 : return;
113 : }
114 :
115 :
116 21 : static void ivas_ism_get_proto_matrix_fx(
117 : IVAS_OUTPUT_SETUP hOutSetup,
118 : const Word16 nchan_transport,
119 : Word16 *proto_matrix /*Q15*/
120 : )
121 : {
122 : Word16 idx;
123 :
124 : /* compute proto_matrix */
125 21 : SWITCH( nchan_transport )
126 : {
127 21 : case 2:
128 : {
129 21 : IF( hOutSetup.nchan_out_woLFE )
130 : {
131 248 : FOR( idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ )
132 : {
133 227 : IF( hOutSetup.ls_azimuth_fx[idx] > 0 )
134 : {
135 103 : proto_matrix[idx] = 32767; /* 1.0f in Q15 */
136 103 : move16();
137 103 : proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0;
138 103 : move16();
139 : }
140 124 : ELSE IF( hOutSetup.ls_azimuth_fx[idx] < 0 )
141 : {
142 103 : proto_matrix[idx] = 0;
143 103 : move16();
144 103 : proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 32767; /* 1.0f in Q15 */
145 103 : move16();
146 : }
147 : ELSE
148 : {
149 21 : proto_matrix[idx] = ONE_IN_Q14; /* 0.5 -> Q15*/
150 21 : move16();
151 21 : proto_matrix[idx + hOutSetup.nchan_out_woLFE] = ONE_IN_Q14; /* 0.5 -> Q15*/
152 21 : move16();
153 : }
154 : }
155 : }
156 : ELSE
157 : {
158 0 : assert( 0 && "Error: number of output channels not supported" );
159 : }
160 21 : BREAK;
161 : }
162 :
163 0 : default:
164 0 : assert( 0 && "Error: number of transport channels not supported" );
165 : }
166 :
167 21 : return;
168 : }
169 :
170 168096 : static void ivas_param_ism_collect_slot_fx(
171 : PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */
172 : Word32 *Cldfb_RealBuffer_in_fx, /*Q(31-exp_real)*/
173 : Word16 exp_real,
174 : Word32 *Cldfb_ImagBuffer_in_fx, /*Q(31-exp_imag)*/
175 : Word16 exp_imag,
176 : const Word16 ch,
177 : Word32 cx_diag_fx[][PARAM_ISM_MAX_DMX], /*Q(31-exp_cx_diag)*/
178 : Word16 exp_cx_diag[][PARAM_ISM_MAX_DMX] )
179 : {
180 : Word16 band_idx, bin_idx;
181 : Word16 brange[2];
182 : Word32 tmp_fx;
183 : Word16 exp_tmp;
184 :
185 : /* loop over parameter bands to collect transport channel energies */
186 :
187 2017152 : FOR( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
188 : {
189 1849056 : brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
190 1849056 : move16();
191 1849056 : brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
192 1849056 : move16();
193 11934816 : FOR( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
194 : {
195 10085760 : tmp_fx = 0;
196 10085760 : move32();
197 10085760 : exp_tmp = 0;
198 10085760 : move16();
199 10085760 : Word32 var1 = Mpy_32_32( Cldfb_RealBuffer_in_fx[bin_idx], Cldfb_RealBuffer_in_fx[bin_idx] ); // Q(31-2 * exp_real)
200 10085760 : Word32 var2 = Mpy_32_32( Cldfb_ImagBuffer_in_fx[bin_idx], Cldfb_ImagBuffer_in_fx[bin_idx] ); // Q(31-2 * exp_imag)
201 10085760 : tmp_fx = BASOP_Util_Add_Mant32Exp( tmp_fx, exp_tmp, var1, add( exp_real, exp_real ), &exp_tmp );
202 10085760 : tmp_fx = BASOP_Util_Add_Mant32Exp( tmp_fx, exp_tmp, var2, add( exp_imag, exp_imag ), &exp_tmp );
203 :
204 : Word16 exp_cx_diag_new;
205 10085760 : move16();
206 10085760 : move16();
207 10085760 : cx_diag_fx[bin_idx][ch] = BASOP_Util_Add_Mant32Exp( cx_diag_fx[bin_idx][ch], exp_cx_diag[bin_idx][ch], tmp_fx, exp_tmp, &exp_cx_diag_new );
208 10085760 : move32();
209 10085760 : exp_cx_diag[bin_idx][ch] = exp_cx_diag_new;
210 10085760 : move16();
211 : }
212 : }
213 168096 : return;
214 : }
215 :
216 5253 : static void ivas_param_ism_compute_mixing_matrix_fx(
217 : const Word16 nchan_ism, /* i : number of ISM channels */
218 : PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */
219 : ISM_DTX_DATA_DEC hISMDTX, /* i : ISM DTX handle */
220 : Word32 direct_response_fx[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN], // Q30
221 : const Word16 nchan_transport,
222 : const Word16 nchan_out_woLFE,
223 : Word32 cx_diag_fx[][PARAM_ISM_MAX_DMX], /*Q(31-cx_diag_e)*/
224 : Word16 cx_diag_e[][PARAM_ISM_MAX_DMX],
225 : Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], /*Q(31-mixing_matrix_e)*/
226 : Word16 mixing_matrix_e[CLDFB_NO_CHANNELS_MAX] )
227 : {
228 : Word16 band_idx, bin_idx;
229 : Word16 i, w, obj_indx;
230 : Word16 brange[2];
231 : Word32 direct_power_fx[MAX_NUM_OBJECTS];
232 : Word32 cy_diag_fx[PARAM_ISM_MAX_CHAN];
233 : Word32 cy_diag_tmp_fx[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN];
234 : Word32 *dir_res_ptr_fx;
235 : Word16 *proto_matrix_fx;
236 : Word32 response_matrix_fx[PARAM_ISM_MAX_CHAN * MAX_NUM_OBJECTS];
237 : Word16 num_wave;
238 : Word16 dir_res_ptr_e, cy_diag_e, cy_diag_e_arr[PARAM_ISM_MAX_CHAN], cy_diag_tmp_e[MAX_NUM_OBJECTS], response_matrix_e, direct_power_e, temp_e[PARAM_ISM_MAX_CHAN];
239 :
240 5253 : proto_matrix_fx = hParamIsmDec->hParamIsmRendering->proto_matrix_fx;
241 :
242 5253 : assert( ( nchan_ism == 3 ) || ( nchan_ism == 4 ) );
243 5253 : assert( nchan_transport == 2 );
244 :
245 5253 : test();
246 5253 : IF( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
247 : {
248 60 : num_wave = nchan_ism;
249 60 : move16();
250 : }
251 : ELSE
252 : {
253 5193 : num_wave = MAX_PARAM_ISM_WAVE;
254 5193 : move16();
255 : }
256 5253 : set32_fx( response_matrix_fx, 0, PARAM_ISM_MAX_CHAN * MAX_NUM_OBJECTS );
257 5253 : response_matrix_e = 0;
258 5253 : move16();
259 :
260 : /* loop over parameter bands to compute the mixing matrix */
261 63036 : FOR( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
262 : {
263 57783 : brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
264 57783 : move16();
265 57783 : brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
266 57783 : move16();
267 :
268 : /* Compute covaraince matrix from direct response*/
269 174669 : FOR( w = 0; w < num_wave; w++ )
270 : {
271 116886 : set32_fx( cy_diag_tmp_fx[w], 0, nchan_out_woLFE );
272 116886 : test();
273 116886 : IF( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
274 : {
275 2640 : dir_res_ptr_fx = direct_response_fx[w];
276 : }
277 : ELSE
278 : {
279 114246 : obj_indx = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][w];
280 114246 : move16();
281 114246 : dir_res_ptr_fx = direct_response_fx[obj_indx];
282 : }
283 116886 : Copy32( dir_res_ptr_fx, response_matrix_fx + w * nchan_out_woLFE, nchan_out_woLFE ); // Q30
284 116886 : dir_res_ptr_e = 1;
285 116886 : move16();
286 116886 : response_matrix_e = 1;
287 116886 : move16();
288 : /* we only need the diagonal of Cy*/
289 116886 : matrix_product_diag_fx( dir_res_ptr_fx, dir_res_ptr_e, nchan_out_woLFE, 1, 0, dir_res_ptr_fx, dir_res_ptr_e, 1, nchan_out_woLFE, 0, cy_diag_tmp_fx[w], &cy_diag_tmp_e[w] );
290 : }
291 :
292 372963 : FOR( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
293 : {
294 :
295 315180 : set32_fx( cy_diag_fx, 0, nchan_out_woLFE );
296 315180 : set16_fx( cy_diag_e_arr, 0, nchan_out_woLFE );
297 :
298 : /* equal cx diag exponents, compute ref power from cx_diag*/
299 : Word16 max_exp_cx_diag;
300 : Word32 cx_diag_eq_exp_fx[PARAM_ISM_MAX_DMX];
301 : Word32 ref_power_fx;
302 : Word16 ref_power_e, ref_power_e_new;
303 315180 : ref_power_fx = cx_diag_fx[bin_idx][0];
304 315180 : ref_power_e = cx_diag_e[bin_idx][0];
305 :
306 630360 : FOR( i = 1; i < PARAM_ISM_MAX_DMX; i++ )
307 : {
308 315180 : ref_power_fx = BASOP_Util_Add_Mant32Exp( ref_power_fx, ref_power_e, cx_diag_fx[bin_idx][i], cx_diag_e[bin_idx][i], &ref_power_e_new );
309 315180 : ref_power_e = ref_power_e_new;
310 : }
311 315180 : max_exp_cx_diag = ref_power_e;
312 945540 : FOR( i = 0; i < PARAM_ISM_MAX_DMX; i++ )
313 : {
314 630360 : cx_diag_eq_exp_fx[i] = L_shr_r( cx_diag_fx[bin_idx][i], sub( max_exp_cx_diag, cx_diag_e[bin_idx][i] ) ); // Q(31-max_exp_cx_diag)
315 : }
316 :
317 :
318 952740 : FOR( w = 0; w < num_wave; w++ )
319 : {
320 637560 : test();
321 637560 : IF( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
322 : {
323 : // direct_power[w] = ( 1.0f / nchan_ism ) * ref_power[bin_idx];
324 14400 : SWITCH( nchan_ism )
325 : {
326 0 : case 2:
327 0 : direct_power_fx[w] = L_shr_r( ref_power_fx, 1 );
328 0 : move32();
329 0 : BREAK;
330 0 : case 3:
331 0 : direct_power_fx[w] = Mpy_32_16_1( ref_power_fx, 10923 ); // 10923 = 1/3f in Q15
332 0 : move32();
333 0 : BREAK;
334 14400 : case 4:
335 14400 : direct_power_fx[w] = L_shr_r( ref_power_fx, 2 );
336 14400 : move32();
337 14400 : BREAK;
338 : }
339 14400 : }
340 : ELSE
341 : {
342 623160 : direct_power_fx[w] = Mpy_32_16_1( ref_power_fx, hParamIsmDec->power_ratios_fx[band_idx][0][w] ); // Q(31-ref_power_e[bin_idx])
343 623160 : move32();
344 : }
345 : // direct_power_e = ref_power_e[bin_idx];
346 637560 : direct_power_e = ref_power_e;
347 637560 : move16();
348 637560 : IF( direct_power_fx[w] != 0 )
349 : {
350 5440304 : FOR( i = 0; i < nchan_out_woLFE; i++ )
351 : {
352 4904120 : cy_diag_fx[i] = BASOP_Util_Add_Mant32Exp( cy_diag_fx[i], cy_diag_e_arr[i], Mpy_32_32( direct_power_fx[w], cy_diag_tmp_fx[w][i] ), add( direct_power_e, cy_diag_tmp_e[w] ), &cy_diag_e_arr[i] );
353 4904120 : move32();
354 : }
355 : }
356 637560 : temp_e[w] = direct_power_e;
357 637560 : move16();
358 637560 : direct_power_fx[w] = Sqrt32( direct_power_fx[w], &temp_e[w] );
359 637560 : move32();
360 : }
361 315180 : cy_diag_e = cy_diag_e_arr[0];
362 315180 : move16();
363 2878920 : FOR( i = 1; i < nchan_out_woLFE; i++ )
364 : {
365 2563740 : cy_diag_e = s_max( cy_diag_e, cy_diag_e_arr[i] );
366 : }
367 3194100 : FOR( i = 0; i < nchan_out_woLFE; i++ )
368 : {
369 2878920 : cy_diag_fx[i] = L_shr_r( cy_diag_fx[i], sub( cy_diag_e, cy_diag_e_arr[i] ) ); // cy_diag_e
370 2878920 : move32();
371 : }
372 :
373 315180 : direct_power_e = temp_e[0];
374 315180 : move16();
375 637560 : FOR( w = 1; w < num_wave; w++ )
376 : {
377 322380 : direct_power_e = s_max( direct_power_e, temp_e[w] );
378 : }
379 952740 : FOR( w = 0; w < num_wave; w++ )
380 : {
381 637560 : direct_power_fx[w] = L_shr_r( direct_power_fx[w], sub( direct_power_e, temp_e[w] ) ); // diract_power_e
382 637560 : move32();
383 : }
384 :
385 : /* Compute mixing matrix */
386 315180 : computeMixingMatricesISM_fx( nchan_transport, num_wave, nchan_out_woLFE, response_matrix_fx, response_matrix_e, direct_power_fx, direct_power_e, cx_diag_eq_exp_fx, max_exp_cx_diag, cy_diag_fx, cy_diag_e, proto_matrix_fx, 1,
387 315180 : PARAM_MC_REG_SX_FX, PARAM_MC_REG_GHAT_FX, mixing_matrix_fx[bin_idx], &mixing_matrix_e[bin_idx] );
388 : }
389 : }
390 :
391 5253 : return;
392 : }
393 :
394 84048 : static void ivas_param_ism_render_slot_fx(
395 : PARAM_ISM_DEC_HANDLE hParamIsmDec,
396 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom,
397 : Word32 *Cldfb_RealBuffer_in_fx[PARAM_ISM_MAX_DMX], /*Q11 (31-Cldfb_RealBuffer_tc_exp)*/
398 : Word32 *Cldfb_ImagBuffer_in_fx[PARAM_ISM_MAX_DMX], /*Q11 (31-Cldfb_ImagBuffer_tc_exp)*/
399 : Word32 Cldfb_RealBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*Q(31-exp_real)*/
400 : Word32 Cldfb_ImagBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*Q(31-exp_imag)*/
401 : Word16 *exp_real,
402 : Word16 *exp_imag,
403 : Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], /*Q(31-exp_mixing_matrix_lin_fx)*/
404 : const Word16 interpolator_idx,
405 : const Word16 out_slot_idx,
406 : const Word16 num_ch_LS,
407 : const Word16 nchan_transport )
408 : {
409 : Word16 outchIdx, inchIdx, bin_idx;
410 : Word32 tmp_1_fx, mixing_matrix_smooth_fx;
411 :
412 84048 : tmp_1_fx = L_deposit_h( hParamIsmDec->hParamIsmRendering->interpolator_fx[interpolator_idx] ); /* Q31 */
413 :
414 84048 : Word16 res_exp = 0;
415 84048 : move16();
416 84048 : Word16 real_buf_exp = hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp;
417 84048 : move16();
418 84048 : Word16 imag_buf_exp = hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp;
419 84048 : move16();
420 : Word16 i, j, k;
421 :
422 : /*exponent buffers to handle variable exp*/
423 : Word16 exp_buf_real[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
424 : Word16 exp_buf_imag[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
425 1428816 : FOR( i = 0; i < PARAM_ISM_MAX_CHAN; i++ )
426 : {
427 6723840 : FOR( j = 0; j < JBM_CLDFB_SLOTS_IN_SUBFRAME; j++ )
428 : {
429 328123392 : FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
430 : {
431 322744320 : exp_buf_real[i][j][k] = 0;
432 322744320 : move16();
433 322744320 : exp_buf_imag[i][j][k] = 0;
434 322744320 : move16();
435 : }
436 : }
437 : }
438 5126928 : FOR( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
439 : {
440 : /* smooth the mixing matrix */
441 51105600 : FOR( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ )
442 : {
443 138188160 : FOR( inchIdx = 0; inchIdx < nchan_transport; inchIdx++ )
444 : {
445 92125440 : Word32 tmp_2 = Mpy_32_32( tmp_1_fx, mixing_matrix_fx[bin_idx][outchIdx + inchIdx * num_ch_LS] ); // hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin
446 92125440 : Word32 tmp_3 = Mpy_32_32( L_sub( ONE_IN_Q31, tmp_1_fx ), hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old_fx[bin_idx][outchIdx + inchIdx * num_ch_LS] ); // 1 + hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old
447 92125440 : mixing_matrix_smooth_fx = BASOP_Util_Add_Mant32Exp( tmp_2, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_fx[bin_idx], tmp_3, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old_fx[bin_idx], &res_exp );
448 :
449 92125440 : Word32 tmp_4 = Mpy_32_32( mixing_matrix_smooth_fx, Cldfb_RealBuffer_in_fx[inchIdx][bin_idx] ); // Q(31-(res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp))
450 92125440 : Word32 tmp_5 = Mpy_32_32( mixing_matrix_smooth_fx, Cldfb_ImagBuffer_in_fx[inchIdx][bin_idx] ); // Q(31-(res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp))
451 :
452 184250880 : Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx] = BASOP_Util_Add_Mant32Exp( Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx], real_buf_exp,
453 92125440 : tmp_4, res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp, &real_buf_exp );
454 92125440 : move32();
455 184250880 : Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx] = BASOP_Util_Add_Mant32Exp( Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx], imag_buf_exp,
456 92125440 : tmp_5, res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp, &imag_buf_exp );
457 92125440 : move32();
458 92125440 : exp_buf_real[outchIdx][out_slot_idx][bin_idx] = real_buf_exp;
459 92125440 : move16();
460 92125440 : exp_buf_imag[outchIdx][out_slot_idx][bin_idx] = imag_buf_exp;
461 92125440 : move16();
462 : }
463 : }
464 : }
465 :
466 : /*Make same exponent for whole buffer*/
467 84048 : Word16 max_exp_real = MIN_16;
468 84048 : move16();
469 84048 : Word16 max_exp_imag = MIN_16;
470 84048 : move16();
471 5126928 : FOR( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
472 : {
473 51105600 : FOR( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ )
474 : {
475 46062720 : max_exp_real = s_max( max_exp_real, exp_buf_real[outchIdx][out_slot_idx][bin_idx] );
476 46062720 : max_exp_imag = s_max( max_exp_imag, exp_buf_imag[outchIdx][out_slot_idx][bin_idx] );
477 : }
478 : }
479 :
480 5126928 : FOR( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
481 : {
482 51105600 : FOR( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ )
483 : {
484 46062720 : Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr( Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub( max_exp_real, exp_buf_real[outchIdx][out_slot_idx][bin_idx] ) ); // Q(31-(max_exp_real))
485 46062720 : move32();
486 46062720 : Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr( Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub( max_exp_imag, exp_buf_imag[outchIdx][out_slot_idx][bin_idx] ) ); // Q(31-(max_exp_imag))
487 46062720 : move32();
488 : }
489 : }
490 :
491 84048 : *exp_real = max_exp_real;
492 84048 : move16();
493 84048 : *exp_imag = max_exp_imag;
494 84048 : move16();
495 :
496 84048 : return;
497 : }
498 :
499 :
500 166 : static ivas_error ivas_param_ism_rendering_init_fx(
501 : PARAM_ISM_RENDERING_HANDLE hParamIsmRendering,
502 : IVAS_OUTPUT_SETUP hOutSetup,
503 : const Word16 nchan_transport,
504 : const Word16 subframe_nbslots,
505 : AUDIO_CONFIG output_config )
506 : {
507 : Word16 bin_idx;
508 :
509 : /* initialization of mixing matrix buffer for smoothing */
510 10126 : FOR( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ )
511 : {
512 9960 : set32_fx( hParamIsmRendering->mixing_matrix_lin_old_fx[bin_idx], 0, PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX );
513 : }
514 166 : set16_fx( hParamIsmRendering->exp_mixing_matrix_lin_old_fx, 0, CLDFB_NO_CHANNELS_MAX );
515 :
516 : /* memory allocation for proto matrix and interpolator */
517 166 : IF( ( hParamIsmRendering->proto_matrix_fx = (Word16 *) malloc( hOutSetup.nchan_out_woLFE * nchan_transport * sizeof( Word16 ) ) ) == NULL )
518 : {
519 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for proto matrix\n" ) );
520 : }
521 :
522 :
523 166 : IF( ( hParamIsmRendering->interpolator_fx = (Word16 *) malloc( subframe_nbslots * sizeof( Word16 ) ) ) == NULL )
524 : {
525 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) );
526 : }
527 166 : test();
528 166 : test();
529 166 : test();
530 166 : IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) )
531 : {
532 : /* computation of proto matrix */
533 21 : ivas_ism_get_proto_matrix_fx( hOutSetup, nchan_transport, hParamIsmRendering->proto_matrix_fx );
534 : }
535 :
536 : /* computation of interpolator*/
537 166 : ivas_ism_get_interpolator_fx( subframe_nbslots, hParamIsmRendering->interpolator_fx );
538 :
539 166 : return IVAS_ERR_OK;
540 : }
541 :
542 5253 : static void ivas_param_ism_update_mixing_matrix_fx(
543 : PARAM_ISM_DEC_HANDLE hParamIsmDec,
544 : Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], /*Q(31-mixing_matrix_exp)*/
545 : Word16 mixing_matrix_exp[CLDFB_NO_CHANNELS_MAX],
546 : const Word16 nchan_in,
547 : const Word16 nchan_out )
548 : {
549 : Word16 inchIdx, outchIdx, bin_idx, band_idx;
550 : Word16 brange[2];
551 :
552 63036 : FOR( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
553 : {
554 57783 : brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
555 57783 : move16();
556 57783 : brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
557 57783 : move16();
558 :
559 372963 : FOR( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
560 : {
561 945540 : FOR( inchIdx = 0; inchIdx < nchan_in; inchIdx++ )
562 : {
563 6388200 : FOR( outchIdx = 0; outchIdx < nchan_out; outchIdx++ )
564 : {
565 5757840 : hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old_fx[bin_idx][outchIdx + inchIdx * nchan_out] = mixing_matrix_fx[bin_idx][outchIdx + inchIdx * nchan_out];
566 5757840 : move32();
567 : }
568 : }
569 : }
570 : }
571 :
572 5253 : Copy( mixing_matrix_exp, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old_fx, CLDFB_NO_CHANNELS_MAX );
573 :
574 5253 : return;
575 : }
576 :
577 :
578 : /*-------------------------------------------------------------------------*
579 : * ivas_param_ism_dec_open()
580 : *
581 : * Open Param ISM handle
582 : *-------------------------------------------------------------------------*/
583 168 : ivas_error ivas_param_ism_dec_open_fx(
584 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
585 : )
586 : {
587 : Word16 i;
588 : PARAM_ISM_DEC_HANDLE hParamIsmDec;
589 : IVAS_OUTPUT_SETUP hOutSetup;
590 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
591 : AUDIO_CONFIG output_config;
592 : Word32 output_Fs;
593 : ivas_error error;
594 :
595 168 : error = IVAS_ERR_OK;
596 168 : move32();
597 168 : push_wmops( "ivas_param_ism_dec_open" );
598 :
599 : /*-----------------------------------------------------------------*
600 : * prepare library opening
601 : *-----------------------------------------------------------------*/
602 :
603 168 : IF( ( hParamIsmDec = (PARAM_ISM_DEC_HANDLE) malloc( sizeof( PARAM_ISM_DEC_DATA ) ) ) == NULL )
604 : {
605 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) );
606 : }
607 :
608 168 : IF( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL )
609 : {
610 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
611 : }
612 :
613 : /* Assign memory to Param Object handle */
614 168 : IF( ( hParamIsmDec->hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL )
615 : {
616 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) );
617 : }
618 :
619 168 : IF( ( hParamIsmDec->hParamIsmRendering = (PARAM_ISM_RENDERING_HANDLE) malloc( sizeof( PARAM_ISM_RENDERING_DATA ) ) ) == NULL )
620 : {
621 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM Rendering handle\n" ) );
622 : }
623 :
624 168 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
625 168 : move32();
626 168 : output_config = st_ivas->hDecoderConfig->output_config;
627 168 : move32();
628 168 : ivas_param_ism_config_fx( hParamIsmDec->hParamIsm, st_ivas->nchan_ism ); // assuming Q14 for gains;
629 :
630 : /*-----------------------------------------------------------------*
631 : * set input parameters
632 : *-----------------------------------------------------------------*/
633 :
634 : /* hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); */
635 168 : hSpatParamRendCom->slot_size = extract_l( L_shr( Mpy_32_32( output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ), 4 ) );
636 168 : move16();
637 168 : set16_fx( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
638 168 : set16_fx( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
639 168 : hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
640 168 : move16();
641 168 : hSpatParamRendCom->subframes_rendered = 0;
642 168 : move16();
643 168 : hSpatParamRendCom->slots_rendered = 0;
644 168 : move16();
645 168 : hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
646 168 : move16();
647 : /* hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); */
648 168 : hSpatParamRendCom->num_freq_bands = extract_l( Mpy_32_32( output_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) );
649 168 : move16();
650 :
651 168 : hParamIsmDec->hParamIsm->nbands = MAX_PARAM_ISM_NBANDS;
652 168 : move16();
653 :
654 2184 : FOR( i = 0; i < ( hParamIsmDec->hParamIsm->nbands + 1 ); i++ )
655 : {
656 2016 : hParamIsmDec->hParamIsm->band_grouping[i] = Param_ISM_band_grouping[i];
657 2016 : move16();
658 :
659 2016 : IF( GT_16( hParamIsmDec->hParamIsm->band_grouping[i], hSpatParamRendCom->num_freq_bands ) )
660 : {
661 75 : hParamIsmDec->hParamIsm->band_grouping[i] = hSpatParamRendCom->num_freq_bands;
662 75 : move16();
663 : }
664 : }
665 :
666 : /*-----------------------------------------------------------------*
667 : * output setup
668 : *-----------------------------------------------------------------*/
669 :
670 : /* hIntSetup and hOutSetup differs only for Binaural rendering */
671 168 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
672 : {
673 : /* nchan_out is essential for memory initialization for CLDFB Synthesis */
674 47 : st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->nchan_ism;
675 47 : move16();
676 47 : st_ivas->hIntSetup.is_loudspeaker_setup = 1;
677 47 : move16();
678 : }
679 :
680 168 : hOutSetup = st_ivas->hIntSetup;
681 :
682 168 : test();
683 168 : IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) )
684 : {
685 : /* Initialize Param ISM Rendering handle */
686 166 : IF( st_ivas->hDecoderConfig->Opt_tsm )
687 : {
688 76 : IF( NE_32( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, MAX_JBM_CLDFB_TIMESLOTS, output_config ) ), IVAS_ERR_OK ) )
689 : {
690 0 : return error;
691 : }
692 : }
693 : ELSE
694 : {
695 90 : IF( NE_32( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, CLDFB_NO_COL_MAX, output_config ) ), IVAS_ERR_OK ) )
696 : {
697 0 : return error;
698 : }
699 : }
700 : }
701 :
702 168 : test();
703 168 : test();
704 168 : test();
705 168 : test();
706 168 : test();
707 168 : IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ||
708 : EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) )
709 : {
710 : /* Initialize efap handle */
711 21 : IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), hOutSetup.ls_azimuth_fx, hOutSetup.ls_elevation_fx, hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) )
712 : {
713 0 : return error;
714 : }
715 : }
716 :
717 : /* Azi and Ele values are transmitted once per frame per object */
718 :
719 168 : set32_fx( hParamIsmDec->azimuth_values_fx, 0, MAX_NUM_OBJECTS );
720 168 : set32_fx( hParamIsmDec->elevation_values_fx, 0, MAX_NUM_OBJECTS );
721 :
722 168 : hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES;
723 168 : move16();
724 168 : hSpatParamRendCom->dirac_bs_md_write_idx = 0;
725 168 : move16();
726 168 : hSpatParamRendCom->dirac_read_idx = 0;
727 168 : move16();
728 :
729 168 : test();
730 168 : test();
731 168 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
732 : {
733 98 : IF( NE_32( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 1 ) ), IVAS_ERR_OK ) )
734 : {
735 0 : return error;
736 : }
737 :
738 98 : IF( NE_32( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ), IVAS_ERR_OK ) )
739 : {
740 0 : return error;
741 : }
742 : }
743 :
744 168 : st_ivas->hISMDTX.dtx_flag = 0;
745 168 : move16();
746 :
747 168 : st_ivas->hParamIsmDec = hParamIsmDec;
748 168 : st_ivas->hSpatParamRendCom = hSpatParamRendCom;
749 :
750 :
751 168 : test();
752 168 : IF( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) )
753 166 : {
754 166 : Word16 nchan_transport = st_ivas->nchan_transport;
755 166 : move16();
756 166 : Word16 nchan_full = 0;
757 166 : move16();
758 :
759 166 : test();
760 166 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
761 : {
762 98 : nchan_full = nchan_transport;
763 98 : move16();
764 98 : hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = NULL;
765 98 : hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = NULL;
766 : }
767 : ELSE
768 : {
769 : Word16 n_slots_to_alloc;
770 68 : IF( EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) )
771 : {
772 1 : n_slots_to_alloc = MAX_JBM_CLDFB_TIMESLOTS;
773 1 : move16();
774 : }
775 : ELSE
776 : {
777 67 : n_slots_to_alloc = CLDFB_SLOTS_PER_SUBFRAME * MAX_PARAM_SPATIAL_SUBFRAMES;
778 67 : move16();
779 : }
780 :
781 68 : IF( ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
782 : {
783 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) );
784 : }
785 68 : set32_fx( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx, 0, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands );
786 :
787 68 : IF( ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
788 : {
789 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) );
790 : }
791 68 : set32_fx( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx, 0, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands );
792 : }
793 :
794 166 : IF( st_ivas->hTcBuffer == NULL )
795 : {
796 12 : IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
797 :
798 : {
799 0 : return error;
800 : }
801 : }
802 : }
803 : ELSE
804 : {
805 2 : hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = NULL;
806 2 : hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = NULL;
807 2 : IF( st_ivas->hTcBuffer == NULL )
808 : {
809 2 : Word16 nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out;
810 2 : move16(); // NS2SA
811 2 : IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
812 : {
813 0 : return error;
814 : }
815 : }
816 : }
817 :
818 168 : pop_wmops();
819 168 : return error;
820 : }
821 :
822 : /*-------------------------------------------------------------------------*
823 : * ivas_param_ism_dec_close()
824 : *
825 : * Close Param ISM handle
826 : *-------------------------------------------------------------------------*/
827 :
828 225 : void ivas_param_ism_dec_close_fx(
829 : PARAM_ISM_DEC_HANDLE *hParamIsmDec_out, /* i/o: decoder DirAC handle */
830 : SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */
831 : AUDIO_CONFIG output_config /* i : output audio configuration */
832 : )
833 : {
834 225 : test();
835 225 : IF( hParamIsmDec_out != NULL && *hParamIsmDec_out != NULL )
836 : {
837 : PARAM_ISM_DEC_HANDLE hParamIsmDec;
838 168 : hParamIsmDec = *hParamIsmDec_out;
839 :
840 : /* Config & CLDFB */
841 168 : IF( hParamIsmDec->hParamIsm != NULL )
842 : {
843 168 : free( hParamIsmDec->hParamIsm );
844 168 : hParamIsmDec->hParamIsm = NULL;
845 : }
846 :
847 168 : test();
848 168 : IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) )
849 : {
850 : /* Param ISM Rendering */
851 166 : IF( hParamIsmDec->hParamIsmRendering->interpolator_fx != NULL )
852 : {
853 166 : free( hParamIsmDec->hParamIsmRendering->interpolator_fx );
854 166 : hParamIsmDec->hParamIsmRendering->interpolator_fx = NULL;
855 : }
856 166 : IF( hParamIsmDec->hParamIsmRendering->proto_matrix_fx != NULL )
857 : {
858 166 : free( hParamIsmDec->hParamIsmRendering->proto_matrix_fx );
859 166 : hParamIsmDec->hParamIsmRendering->proto_matrix_fx = NULL;
860 : }
861 : }
862 168 : IF( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx != NULL )
863 : {
864 68 : free( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx );
865 68 : hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = NULL;
866 : }
867 168 : IF( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx != NULL )
868 : {
869 68 : free( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx );
870 68 : hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = NULL;
871 : }
872 168 : IF( hParamIsmDec->hParamIsmRendering != NULL )
873 : {
874 168 : free( hParamIsmDec->hParamIsmRendering );
875 168 : hParamIsmDec->hParamIsmRendering = NULL;
876 : }
877 :
878 168 : free( *hParamIsmDec_out );
879 168 : *hParamIsmDec_out = NULL;
880 : }
881 :
882 225 : test();
883 225 : IF( hSpatParamRendCom_out != NULL && *hSpatParamRendCom_out != NULL )
884 : {
885 168 : test();
886 168 : test();
887 168 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
888 : {
889 98 : ivas_dirac_deallocate_parameters_fx( *hSpatParamRendCom_out, 1 );
890 98 : ivas_dirac_deallocate_parameters_fx( *hSpatParamRendCom_out, 2 );
891 : }
892 :
893 168 : free( *hSpatParamRendCom_out );
894 168 : *hSpatParamRendCom_out = NULL;
895 : }
896 :
897 225 : return;
898 : }
899 :
900 :
901 : /*-------------------------------------------------------------------------*
902 : * ivas_ism_dec_digest_tc()
903 : *
904 : *
905 : *-------------------------------------------------------------------------*/
906 76480 : void ivas_ism_dec_digest_tc_fx(
907 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
908 : )
909 : {
910 76480 : ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
911 :
912 76480 : test();
913 76480 : test();
914 76480 : test();
915 76480 : test();
916 76480 : test();
917 76480 : test();
918 76480 : test();
919 76480 : test();
920 76480 : IF( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) ||
921 : EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ||
922 : EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
923 : EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
924 : EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) ||
925 : EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) ||
926 : EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) ||
927 : ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && st_ivas->hDecoderConfig->Opt_Headrotation == 0 ) )
928 : {
929 : Word16 i;
930 : Word32 azimuth_fx, elevation_fx;
931 :
932 : /* we have a full frame interpolator, adapt it */
933 : /* for BE testing */
934 38327 : i = extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) );
935 38327 : IF( EQ_16( i, st_ivas->hTcBuffer->n_samples_available ) )
936 : {
937 38325 : Word16 interpolator_length = i;
938 :
939 38325 : test();
940 38325 : test();
941 38325 : test();
942 38325 : test();
943 38325 : test();
944 38325 : IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ||
945 : EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) ||
946 : EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
947 : ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) && EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) )
948 : {
949 17776 : st_ivas->hIsmRendererData->interpolator_fx[0] = 0;
950 17776 : move16();
951 15560960 : FOR( i = 1; i < interpolator_length; i++ )
952 : {
953 15543184 : Word16 tmp = div_s( 1, sub( interpolator_length, 1 ) );
954 15543184 : st_ivas->hIsmRendererData->interpolator_fx[i] = add( st_ivas->hIsmRendererData->interpolator_fx[i - 1], tmp ); // Q15
955 15543184 : move16();
956 : }
957 : }
958 : ELSE
959 : {
960 18418629 : FOR( i = 0; i < interpolator_length; i++ )
961 : {
962 18398080 : st_ivas->hIsmRendererData->interpolator_fx[i] = div_s( i, sub( interpolator_length, 1 ) ); // Q15
963 18398080 : move16();
964 : }
965 : }
966 : }
967 : ELSE
968 : {
969 2 : ivas_jbm_dec_get_adapted_linear_interpolator_fx( extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator_fx );
970 2 : move16();
971 : }
972 38327 : st_ivas->hIsmRendererData->interp_offset_fx = 0;
973 38327 : move16();
974 :
975 : /* also get the gains here */
976 156420 : FOR( i = 0; i < st_ivas->nchan_ism; i++ )
977 : {
978 118093 : Copy32( st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIsmRendererData->prev_gains_fx[i], MAX_OUTPUT_CHANNELS );
979 :
980 118093 : IF( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_STEREO ) )
981 : {
982 : #ifdef OBJ_EDITING_API
983 : Word16 gains_fx[2];
984 16400 : ivas_ism_get_stereo_gains_fx( (Word16) L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, 22 ), (Word16) L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, 22 ), &gains_fx[0], &gains_fx[1] );
985 16400 : st_ivas->hIsmRendererData->gains_fx[i][0] = L_shr( L_deposit_h( gains_fx[0] ), 1 ); // Q31 -> Q30
986 16400 : move32();
987 16400 : st_ivas->hIsmRendererData->gains_fx[i][1] = L_shr( L_deposit_h( gains_fx[1] ), 1 ); // Q31 -> Q30
988 16400 : move32();
989 : // TODO: Enable gain editing feature
990 : // v_multc_fixed( st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIsmMetaData[i]->edited_gain_fx, st_ivas->hIsmRendererData->gains_fx[i], CPE_CHANNELS ); // Q30, Q30 --> Q30
991 : #else
992 : Word16 gains_fx[2];
993 : ivas_ism_get_stereo_gains_fx( (Word16) L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, 22 ), (Word16) L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, 22 ), &gains_fx[0], &gains_fx[1] );
994 : st_ivas->hIsmRendererData->gains_fx[i][0] = L_shr( L_deposit_h( gains_fx[0] ), 1 ); // Q31 -> Q30
995 : move32();
996 : st_ivas->hIsmRendererData->gains_fx[i][1] = L_shr( L_deposit_h( gains_fx[1] ), 1 ); // Q31 -> Q30
997 : move32();
998 : #endif
999 : }
1000 : ELSE
1001 : {
1002 : // TODO tmu review when #215 is resolved
1003 : #ifdef OBJ_EDITING_API
1004 101693 : azimuth_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->edited_azimuth_fx, 2097152 ), Q22 ); // Q0 ,2097152 = .5f in Q22
1005 101693 : elevation_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->edited_elevation_fx, 2097152 ), Q22 ); // Q0 ,2097152 = .5f in Q22
1006 : #else
1007 : azimuth_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->azimuth_fx, 2097152 ), Q22 ); // Q0 ,2097152 = .5f in Q22
1008 : elevation_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->elevation_fx, 2097152 ), Q22 ); // Q0 ,2097152 = .5f in Q22
1009 : #endif
1010 :
1011 101693 : test();
1012 101693 : test();
1013 101693 : test();
1014 101693 : test();
1015 101693 : test();
1016 101693 : test();
1017 101693 : test();
1018 101693 : test();
1019 101693 : IF( ( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) ||
1020 : EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) ||
1021 : EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ||
1022 : ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) && EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) ) &&
1023 : st_ivas->hCombinedOrientationData == NULL )
1024 : {
1025 55449 : if ( st_ivas->hIntSetup.is_planar_setup )
1026 : {
1027 : /* If no elevation support in output format, then rendering should be done with zero elevation */
1028 11000 : elevation_fx = 0;
1029 11000 : move32();
1030 : }
1031 :
1032 55449 : IF( st_ivas->hEFAPdata != NULL )
1033 : {
1034 55449 : azimuth_fx = L_shl( azimuth_fx, Q22 ); // Q22
1035 55449 : elevation_fx = L_shl( elevation_fx, Q22 ); // Q22
1036 55449 : efap_determine_gains_fx( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], azimuth_fx, elevation_fx, EFAP_MODE_EFAP );
1037 : #ifdef OBJ_EDITING_API
1038 : // TODO: Enable gain editing feature
1039 : // v_multc_fixed( st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIsmMetaData[i]->edited_gain_fx, st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hEFAPdata->numSpk );
1040 : #endif
1041 : }
1042 : }
1043 46244 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ||
1044 : EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) ||
1045 : EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
1046 : {
1047 : /*get HOA gets for direction (ACN/SN3D)*/
1048 46244 : Word16 azi = shr( extract_h( st_ivas->hIsmMetaData[i]->azimuth_fx ), 22 - 16 ); // Q0
1049 46244 : Word16 ele = shr( extract_h( st_ivas->hIsmMetaData[i]->elevation_fx ), 22 - 16 ); // Q0
1050 46244 : ivas_dirac_dec_get_response_fx( azi, ele, st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIntSetup.ambisonics_order, Q30 );
1051 : #ifdef OBJ_EDITING_API
1052 : // TODO: Enable gain editing feature
1053 : // v_multc_fixed( st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIsmMetaData[i]->edited_gain_fx, st_ivas->hIsmRendererData->gains_fx[i], ivas_sba_get_nchan_fx( st_ivas->hIntSetup.ambisonics_order, 0 ) ); // Q30, Q30 --> Q30
1054 : #endif
1055 : }
1056 : }
1057 : }
1058 : }
1059 :
1060 76480 : return;
1061 : }
1062 :
1063 : /*-------------------------------------------------------------------------*
1064 : * ivas_param_ism_dec_digest_tc()
1065 : *
1066 : *
1067 : *-------------------------------------------------------------------------*/
1068 5253 : void ivas_param_ism_dec_digest_tc_fx(
1069 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
1070 : const UWord16 nCldfbSlots, /* i : number of CLFBS slots in the transport channels */
1071 : Word32 *transport_channels[], /* i : synthesized core-coder transport channels/DirAC output q_tc_in*/
1072 : Word16 q_tc_in )
1073 : {
1074 5253 : move16();
1075 5253 : move16();
1076 5253 : move16();
1077 5253 : move16();
1078 : #ifndef OBJ_EDITING_API
1079 : Word32 cx_diag_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX];
1080 : Word16 exp_cx_diag[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX];
1081 : Word16 exp_real_tmp = 0, exp_imag_tmp = 0;
1082 : #endif
1083 :
1084 5253 : Word16 q_tc = q_tc_in;
1085 5253 : move16();
1086 : #ifndef OBJ_EDITING_API
1087 : Word16 ch, nchan_transport, nchan_out, nchan_out_woLFE, i;
1088 : Word16 slot_idx, bin_idx;
1089 : Word32 ivas_total_brate;
1090 : #else
1091 : Word16 ch, nchan_transport, i;
1092 : Word16 slot_idx;
1093 : #endif
1094 :
1095 : Word16 output_frame;
1096 : #ifndef OBJ_EDITING_API
1097 : /* Direct Response/EFAP Gains */
1098 : Word32 direct_response_fx[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN];
1099 : #endif
1100 : PARAM_ISM_DEC_HANDLE hParamIsmDec;
1101 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1102 : Word16 fade_len;
1103 :
1104 : /* Initialization */
1105 : #ifndef OBJ_EDITING_API
1106 : set32_fx( &direct_response_fx[0][0], 0, MAX_NUM_OBJECTS * PARAM_ISM_MAX_CHAN );
1107 : #endif
1108 5253 : hParamIsmDec = st_ivas->hParamIsmDec;
1109 5253 : assert( hParamIsmDec );
1110 5253 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1111 5253 : assert( hSpatParamRendCom );
1112 5253 : output_frame = imult1616( nCldfbSlots, hSpatParamRendCom->num_freq_bands );
1113 5253 : fade_len = shr( output_frame, 1 );
1114 :
1115 5253 : nchan_transport = st_ivas->nchan_transport;
1116 5253 : move16();
1117 : #ifndef OBJ_EDITING_API
1118 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
1119 : move32();
1120 :
1121 : hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp = 25;
1122 : move16();
1123 : hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp = 25;
1124 : move16();
1125 : IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
1126 : {
1127 : nchan_out = st_ivas->nchan_ism;
1128 : move16();
1129 : nchan_out_woLFE = nchan_out;
1130 : move16();
1131 : st_ivas->hDecoderConfig->nchan_out = nchan_out;
1132 : move16();
1133 : }
1134 : ELSE
1135 : {
1136 : nchan_out = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
1137 : nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
1138 : move16();
1139 : }
1140 : #endif
1141 :
1142 5253 : push_wmops( "ivas_param_ism_dec" );
1143 :
1144 : #ifndef OBJ_EDITING_API
1145 : /* general setup */
1146 : ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hParamIsmDec->hParamIsmRendering->interpolator_fx );
1147 :
1148 : ivas_dirac_dec_set_md_map_fx( st_ivas, nCldfbSlots );
1149 : /* set buffers to zero */
1150 :
1151 : set_zero_fx( &cx_diag_fx[0][0], CLDFB_NO_CHANNELS_MAX * PARAM_ISM_MAX_DMX );
1152 : set16_zero_fx( &exp_cx_diag[0][0], CLDFB_NO_CHANNELS_MAX * PARAM_ISM_MAX_DMX );
1153 :
1154 : /* Frame-level Processing */
1155 : /* De-quantization */
1156 : test();
1157 : IF( !( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) )
1158 : {
1159 : ivas_param_ism_dec_dequant_DOA_fx( hParamIsmDec, st_ivas->nchan_ism );
1160 : ivas_param_ism_dec_dequant_powrat_fx( hParamIsmDec );
1161 : st_ivas->hISMDTX.dtx_flag = 0;
1162 : move16();
1163 : }
1164 : ELSE
1165 : {
1166 : st_ivas->hISMDTX.dtx_flag = 1;
1167 : move16();
1168 : }
1169 :
1170 : /* obtain the direct response using EFAP */
1171 : IF( !( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) )
1172 : {
1173 : FOR( i = 0; i < st_ivas->nchan_ism; i++ )
1174 : {
1175 : efap_determine_gains_fx( st_ivas->hEFAPdata, direct_response_fx[i], hParamIsmDec->azimuth_values_fx[i], hParamIsmDec->elevation_values_fx[i], EFAP_MODE_EFAP );
1176 : }
1177 : }
1178 : ELSE
1179 : {
1180 : Word16 j;
1181 :
1182 : FOR( i = 0; i < st_ivas->nchan_ism; i++ )
1183 : {
1184 : FOR( j = 0; j < nchan_out_woLFE; j++ )
1185 : {
1186 : IF( EQ_16( i, j ) )
1187 : {
1188 : direct_response_fx[i][j] = ONE_IN_Q30;
1189 : move32();
1190 : }
1191 : ELSE
1192 : {
1193 : direct_response_fx[i][j] = 0;
1194 : move32();
1195 : }
1196 : }
1197 : }
1198 :
1199 : FOR( j = 0; j < nchan_out_woLFE; j++ )
1200 : {
1201 : IF( hParamIsmDec->azimuth_values_fx[j] > 0 )
1202 : {
1203 : hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = 32767; // (1.0f in Q15) - 1
1204 : move16();
1205 : hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = 0;
1206 : move16();
1207 : }
1208 : ELSE
1209 : {
1210 : IF( hParamIsmDec->azimuth_values_fx[j] < 0 )
1211 : {
1212 : hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = 0;
1213 : move16();
1214 : hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = 32767; // (1.0f in Q15) - 1
1215 : move16();
1216 : }
1217 : ELSE /* == 0.0f */
1218 : {
1219 : hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = ONE_IN_Q14; // Q15
1220 : move16();
1221 : hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = ONE_IN_Q14; // Q15
1222 : move16();
1223 : }
1224 : }
1225 : }
1226 : }
1227 : #endif
1228 :
1229 5253 : IF( st_ivas->hDecoderConfig->Opt_tsm )
1230 : {
1231 : /*TODO : FhG to check*/
1232 1506 : ivas_ism_param_dec_tc_gain_ajust_fx( st_ivas, output_frame, fade_len, transport_channels, &q_tc );
1233 1506 : IF( NE_16( q_tc, q_tc_in ) )
1234 : {
1235 4518 : FOR( i = 0; i < 2; i++ )
1236 : {
1237 3012 : scale_sig32( transport_channels[i], output_frame, sub( q_tc_in, q_tc ) ); // q_tc_in
1238 : }
1239 1506 : q_tc = q_tc_in;
1240 1506 : move16();
1241 : }
1242 : }
1243 :
1244 15759 : FOR( ch = 0; ch < nchan_transport; ch++ )
1245 : {
1246 : /* CLDFB Analysis */
1247 178602 : FOR( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
1248 : {
1249 168096 : IF( st_ivas->hDecoderConfig->Opt_tsm )
1250 : {
1251 : Word32 RealBuffer_fx[CLDFB_NO_CHANNELS_MAX];
1252 : Word32 ImagBuffer_fx[CLDFB_NO_CHANNELS_MAX];
1253 48192 : q_tc = q_tc_in;
1254 48192 : move16();
1255 48192 : cldfbAnalysis_ts_fx_fixed_q( &( transport_channels[ch][hSpatParamRendCom->num_freq_bands * slot_idx] ), RealBuffer_fx, ImagBuffer_fx, hSpatParamRendCom->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_tc );
1256 48192 : Copy32( RealBuffer_fx, &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands );
1257 48192 : Copy32( ImagBuffer_fx, &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands );
1258 48192 : hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp = sub( 31, q_tc );
1259 48192 : move16();
1260 48192 : hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp = sub( 31, q_tc );
1261 48192 : move16();
1262 : }
1263 :
1264 : #ifndef OBJ_EDITING_API
1265 : Word16 scale_factor_real, scale_factor_imag;
1266 : Word16 current_idx;
1267 : exp_real_tmp = hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp;
1268 : move16();
1269 : exp_imag_tmp = hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp;
1270 : move16();
1271 : current_idx = add( imult1616( imult1616( slot_idx, hSpatParamRendCom->num_freq_bands ), nchan_transport ), imult1616( ch, hSpatParamRendCom->num_freq_bands ) );
1272 : scale_factor_real = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands );
1273 : scale_factor_imag = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands );
1274 : scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_real ); // Q(31-(exp_real_tmp-scale_factor_real))
1275 : scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_imag ); // Q(31-(exp_imag_tmp-scale_factor_imag))
1276 : exp_real_tmp = sub( exp_real_tmp, scale_factor_real );
1277 : exp_imag_tmp = sub( exp_imag_tmp, scale_factor_imag );
1278 : ivas_param_ism_collect_slot_fx( hParamIsmDec,
1279 : &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx],
1280 : exp_real_tmp,
1281 : &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx],
1282 : exp_imag_tmp,
1283 : ch,
1284 : cx_diag_fx, exp_cx_diag );
1285 :
1286 : exp_real_tmp = add( exp_real_tmp, scale_factor_real );
1287 : exp_imag_tmp = add( exp_imag_tmp, scale_factor_imag );
1288 : scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_real ); // Q(31-(exp_real_tmp))
1289 : scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_imag ); // Q(31-(exp_imag_tmp))
1290 : #endif
1291 : }
1292 : }
1293 :
1294 : #ifndef OBJ_EDITING_API
1295 : /* Obtain Mixing Matrix on a frame-level */
1296 : FOR( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ )
1297 : {
1298 : set32_fx( hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_fx[bin_idx], 0, PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX );
1299 : }
1300 :
1301 : /* Compute mixing matrix */
1302 : ivas_param_ism_compute_mixing_matrix_fx( st_ivas->nchan_ism, hParamIsmDec, st_ivas->hISMDTX, direct_response_fx, nchan_transport, nchan_out_woLFE, cx_diag_fx, exp_cx_diag,
1303 : hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_fx, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_fx );
1304 :
1305 : #endif
1306 5253 : pop_wmops();
1307 :
1308 5253 : return;
1309 : }
1310 :
1311 :
1312 : #ifdef OBJ_EDITING_API
1313 :
1314 :
1315 : /*-------------------------------------------------------------------------*
1316 : * ivas_param_ism_dec_prepare_renderer_fx()
1317 : *
1318 : *
1319 : *-------------------------------------------------------------------------*/
1320 :
1321 18033 : void ivas_param_ism_dec_dequant_md_fx(
1322 : Decoder_Struct *st_ivas )
1323 : {
1324 : /* De-quantization */
1325 18033 : IF( !( EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, FRAME_NO_DATA ) ) )
1326 : {
1327 15920 : ivas_param_ism_dec_dequant_DOA_fx( st_ivas->hParamIsmDec, st_ivas->nchan_ism );
1328 15920 : ivas_param_ism_dec_dequant_powrat_fx( st_ivas->hParamIsmDec );
1329 15920 : st_ivas->hISMDTX.dtx_flag = 0;
1330 15920 : move16();
1331 : }
1332 : ELSE
1333 : {
1334 2113 : st_ivas->hISMDTX.dtx_flag = 1;
1335 2113 : move16();
1336 : }
1337 :
1338 18033 : return;
1339 : }
1340 :
1341 : /*-------------------------------------------------------------------------*
1342 : * ivas_param_ism_dec_prepare_renderer_fx()
1343 : *
1344 : *
1345 : *-------------------------------------------------------------------------*/
1346 :
1347 5253 : void ivas_param_ism_dec_prepare_renderer_fx(
1348 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
1349 : const Word16 nCldfbSlots /* i : number of CLFBS slots in the transport channels */
1350 : )
1351 : {
1352 : int16_t ch, nchan_transport, nchan_out, nchan_out_woLFE, i;
1353 : int16_t slot_idx, bin_idx;
1354 : Word32 cx_diag_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX];
1355 : Word16 exp_cx_diag[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX];
1356 5253 : Word16 exp_real_tmp = 0, exp_imag_tmp = 0;
1357 : Word32 ivas_total_brate;
1358 : /* Direct Response/EFAP Gains */
1359 : Word32 direct_response_fx[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN];
1360 : PARAM_ISM_DEC_HANDLE hParamIsmDec;
1361 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1362 :
1363 : /* Initialization */
1364 5253 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1365 5253 : assert( hSpatParamRendCom );
1366 5253 : move32();
1367 5253 : hParamIsmDec = st_ivas->hParamIsmDec;
1368 5253 : assert( hParamIsmDec );
1369 5253 : move32();
1370 5253 : nchan_transport = st_ivas->nchan_transport;
1371 5253 : move16();
1372 5253 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
1373 :
1374 : /* Initialization */
1375 :
1376 5253 : hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp = 25;
1377 5253 : move16();
1378 5253 : hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp = 25;
1379 5253 : move16();
1380 5253 : IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
1381 : {
1382 543 : nchan_out = st_ivas->nchan_ism;
1383 543 : move16();
1384 543 : nchan_out_woLFE = nchan_out;
1385 543 : move16();
1386 543 : st_ivas->hDecoderConfig->nchan_out = nchan_out;
1387 543 : move16();
1388 : }
1389 : ELSE
1390 : {
1391 4710 : nchan_out = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
1392 4710 : nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
1393 4710 : move16();
1394 : }
1395 5253 : push_wmops( "ivas_param_ism_dec_digest_tc" );
1396 :
1397 : /* general setup */
1398 5253 : ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hParamIsmDec->hParamIsmRendering->interpolator_fx );
1399 :
1400 5253 : ivas_dirac_dec_set_md_map_fx( st_ivas, nCldfbSlots );
1401 : /* set buffers to zero */
1402 :
1403 5253 : set_zero_fx( &cx_diag_fx[0][0], CLDFB_NO_CHANNELS_MAX * PARAM_ISM_MAX_DMX );
1404 5253 : set16_zero_fx( &exp_cx_diag[0][0], CLDFB_NO_CHANNELS_MAX * PARAM_ISM_MAX_DMX );
1405 :
1406 : /* Frame-level Processing */
1407 : /* De-quantization */
1408 5253 : test();
1409 5253 : IF( !( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) )
1410 : {
1411 5193 : ivas_param_ism_dec_dequant_DOA_fx( hParamIsmDec, st_ivas->nchan_ism );
1412 5193 : ivas_param_ism_dec_dequant_powrat_fx( hParamIsmDec );
1413 5193 : st_ivas->hISMDTX.dtx_flag = 0;
1414 5193 : move16();
1415 : }
1416 : ELSE
1417 : {
1418 60 : st_ivas->hISMDTX.dtx_flag = 1;
1419 60 : move16();
1420 : }
1421 :
1422 : /* obtain the direct response using EFAP */
1423 5253 : IF( !( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) )
1424 : {
1425 22050 : FOR( i = 0; i < st_ivas->nchan_ism; i++ )
1426 : {
1427 17340 : efap_determine_gains_fx( st_ivas->hEFAPdata, direct_response_fx[i], hParamIsmDec->azimuth_values_fx[i], hParamIsmDec->elevation_values_fx[i], EFAP_MODE_EFAP );
1428 : }
1429 : }
1430 : ELSE
1431 : {
1432 : Word16 j;
1433 :
1434 2715 : FOR( i = 0; i < st_ivas->nchan_ism; i++ )
1435 : {
1436 10860 : FOR( j = 0; j < nchan_out_woLFE; j++ )
1437 : {
1438 8688 : IF( EQ_16( i, j ) )
1439 : {
1440 2172 : direct_response_fx[i][j] = ONE_IN_Q30;
1441 2172 : move32();
1442 : }
1443 : ELSE
1444 : {
1445 6516 : direct_response_fx[i][j] = 0;
1446 6516 : move32();
1447 : }
1448 : }
1449 : }
1450 :
1451 2715 : FOR( j = 0; j < nchan_out_woLFE; j++ )
1452 : {
1453 2172 : IF( hParamIsmDec->azimuth_values_fx[j] > 0 )
1454 : {
1455 875 : hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = 32767; // (1.0f in Q15) - 1
1456 875 : move16();
1457 875 : hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = 0;
1458 875 : move16();
1459 : }
1460 : ELSE
1461 : {
1462 1297 : IF( hParamIsmDec->azimuth_values_fx[j] < 0 )
1463 : {
1464 945 : hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = 0;
1465 945 : move16();
1466 945 : hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = 32767; // (1.0f in Q15) - 1
1467 945 : move16();
1468 : }
1469 : ELSE /* == 0.0f */
1470 : {
1471 352 : hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = ONE_IN_Q14; // Q15
1472 352 : move16();
1473 352 : hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = ONE_IN_Q14; // Q15
1474 352 : move16();
1475 : }
1476 : }
1477 : }
1478 : }
1479 :
1480 15759 : FOR( ch = 0; ch < nchan_transport; ch++ )
1481 : {
1482 : /* CLDFB Analysis */
1483 178602 : FOR( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
1484 : {
1485 : Word16 scale_factor_real, scale_factor_imag;
1486 : Word16 current_idx;
1487 168096 : exp_real_tmp = hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp;
1488 168096 : move16();
1489 168096 : exp_imag_tmp = hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp;
1490 168096 : move16();
1491 168096 : current_idx = add( imult1616( imult1616( slot_idx, hSpatParamRendCom->num_freq_bands ), nchan_transport ), imult1616( ch, hSpatParamRendCom->num_freq_bands ) );
1492 168096 : scale_factor_real = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands );
1493 168096 : scale_factor_imag = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands );
1494 168096 : scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_real ); // Q(31-(exp_real_tmp-scale_factor_real))
1495 168096 : scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_imag ); // Q(31-(exp_imag_tmp-scale_factor_imag))
1496 168096 : exp_real_tmp = sub( exp_real_tmp, scale_factor_real );
1497 168096 : exp_imag_tmp = sub( exp_imag_tmp, scale_factor_imag );
1498 168096 : ivas_param_ism_collect_slot_fx( hParamIsmDec,
1499 168096 : &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx],
1500 : exp_real_tmp,
1501 168096 : &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx],
1502 : exp_imag_tmp,
1503 : ch,
1504 : cx_diag_fx, exp_cx_diag );
1505 :
1506 168096 : exp_real_tmp = add( exp_real_tmp, scale_factor_real );
1507 168096 : exp_imag_tmp = add( exp_imag_tmp, scale_factor_imag );
1508 168096 : scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_real ); // Q(31-(exp_real_tmp))
1509 168096 : scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_imag ); // Q(31-(exp_imag_tmp))
1510 : }
1511 : }
1512 :
1513 : /* Obtain Mixing Matrix on a frame-level */
1514 320433 : FOR( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ )
1515 : {
1516 315180 : set32_fx( hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_fx[bin_idx], 0, PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX );
1517 : }
1518 :
1519 : /* Compute mixing matrix */
1520 5253 : ivas_param_ism_compute_mixing_matrix_fx( st_ivas->nchan_ism, hParamIsmDec, st_ivas->hISMDTX, direct_response_fx, nchan_transport, nchan_out_woLFE, cx_diag_fx, exp_cx_diag,
1521 5253 : hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_fx, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_fx );
1522 :
1523 :
1524 5253 : pop_wmops();
1525 :
1526 5253 : return;
1527 : }
1528 : #endif
1529 :
1530 : /*-------------------------------------------------------------------------*
1531 : * ivas_ism_param_dec_tc_gain_ajust()
1532 : *
1533 : *
1534 : *-------------------------------------------------------------------------*/
1535 :
1536 5253 : void ivas_ism_param_dec_tc_gain_ajust_fx(
1537 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
1538 : const UWord16 nSamples, /* i : number of samples to be compensate */
1539 : const UWord16 nFadeLength, /* i : length of the crossfade in samples */
1540 : Word32 *transport_channels_f[], /* i : synthesized core-coder transport channels/DirAC output Q_tc*/
1541 : Word16 *Q_tc /* i/o : Q of input tc buffer */
1542 : )
1543 :
1544 : {
1545 : Word16 i, tmp_e1, tmp_e2, tmp, tmp2, invFade;
1546 : Word32 L_tmp1, L_tmp2;
1547 :
1548 : Word16 gain_fx, last_gain_fx;
1549 : Word32 ene_tc_fx, ene_sum_fx;
1550 :
1551 : Word16 ene_tc_e, ene_sum_e;
1552 :
1553 5253 : ene_tc_fx = 0;
1554 5253 : move32();
1555 5253 : ene_tc_e = 0;
1556 5253 : move16();
1557 5253 : ene_sum_fx = 0;
1558 5253 : move32();
1559 5253 : ene_sum_e = 0;
1560 5253 : move16();
1561 :
1562 :
1563 5253 : last_gain_fx = st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain_fx;
1564 5253 : move16();
1565 :
1566 : Word32 ch0, ch1;
1567 : Word16 ch0_e, ch1_e;
1568 5253 : ch0_e = 0;
1569 5253 : move16();
1570 5253 : ch1_e = 0;
1571 5253 : move16();
1572 :
1573 5048133 : FOR( i = 0; i < nSamples; i++ )
1574 : {
1575 5042880 : ch0_e = 0;
1576 5042880 : move16();
1577 5042880 : ch1_e = 0;
1578 5042880 : move16();
1579 5042880 : ch0 = transport_channels_f[0][i];
1580 5042880 : move16();
1581 5042880 : ch1 = transport_channels_f[1][i];
1582 5042880 : move16();
1583 5042880 : ch0 = BASOP_Util_Add_Mant32Exp( ch0, ch0_e, 0, 0, &ch0_e );
1584 5042880 : ch1 = BASOP_Util_Add_Mant32Exp( ch1, ch1_e, 0, 0, &ch1_e );
1585 :
1586 :
1587 5042880 : L_tmp1 = Mpy_32_32( ch0, ch0 ); /*L*L*/
1588 5042880 : tmp_e1 = add( ch0_e, ch0_e );
1589 5042880 : L_tmp2 = Mpy_32_32( ch1, ch1 ); /*R*R*/
1590 5042880 : tmp_e2 = add( ch1_e, ch1_e );
1591 : /*L*LL + R*R*/
1592 5042880 : ene_tc_fx = BASOP_Util_Add_Mant32Exp( ene_tc_fx, ene_tc_e, L_tmp1, tmp_e1, &ene_tc_e );
1593 5042880 : ene_tc_fx = BASOP_Util_Add_Mant32Exp( ene_tc_fx, ene_tc_e, L_tmp2, tmp_e2, &ene_tc_e );
1594 :
1595 :
1596 5042880 : L_tmp1 = BASOP_Util_Add_Mant32Exp( ch0, ch0_e, ch1, ch1_e, &tmp_e1 ); /*L + R*/
1597 5042880 : L_tmp1 = Mpy_32_32( L_tmp1, L_tmp1 ); // Q(31-(tmp_e1+tmp_e1 /*(L + R)*(L + R)*/
1598 5042880 : tmp_e1 = add( tmp_e1, tmp_e1 );
1599 :
1600 5042880 : ene_sum_fx = BASOP_Util_Add_Mant32Exp( ene_sum_fx, ene_sum_e, L_tmp1, tmp_e1, &ene_sum_e );
1601 : }
1602 :
1603 5253 : IF( ene_sum_fx != 0 )
1604 : {
1605 5253 : gain_fx = BASOP_Util_Divide3232_Scale( ene_tc_fx, ene_sum_fx, &tmp_e1 );
1606 : }
1607 : ELSE
1608 : {
1609 0 : IF( ene_tc_fx == 0 ) /*handling numerator equals to zero*/
1610 : {
1611 0 : gain_fx = 0;
1612 0 : move16();
1613 0 : tmp_e1 = 0;
1614 0 : move16();
1615 : }
1616 : ELSE /*handling denominator equals to zero*/
1617 : {
1618 0 : gain_fx = 32767; //(max value of Word16 in Q0)
1619 0 : move16();
1620 0 : tmp_e1 = 15;
1621 0 : move16();
1622 : }
1623 : }
1624 5253 : tmp_e1 = add( tmp_e1, sub( ene_tc_e, ene_sum_e ) ); /* tmp_e1 + (ene_tc_e - ene_sum_e)*/
1625 5253 : gain_fx = Sqrt16( gain_fx, &tmp_e1 );
1626 :
1627 5253 : tmp_e2 = st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain_e;
1628 5253 : move16();
1629 :
1630 5253 : IF( GT_16( tmp_e2, tmp_e1 ) )
1631 : {
1632 4971 : gain_fx = shr( gain_fx, sub( tmp_e2, tmp_e1 ) ); // Q(15-tmp_e2)
1633 4971 : tmp_e1 = tmp_e2;
1634 4971 : move16();
1635 : }
1636 : ELSE
1637 : {
1638 282 : last_gain_fx = shr( last_gain_fx, sub( tmp_e1, tmp_e2 ) ); // Q(15-tmp_e1)
1639 : }
1640 :
1641 5253 : IF( st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame > 1 )
1642 : {
1643 : /* Smoothing */
1644 5247 : gain_fx = add( mult_r( 24574, gain_fx ), mult_r( 8192, last_gain_fx ) ); // 24574 =.75f in Q15 , 8192=.25f in Q15
1645 : /* 10ms ramp */
1646 : /* slope between two consecutive gains, 480 samples length */
1647 5247 : invFade = div_s( 1, nFadeLength ); // Q15
1648 5247 : tmp = 0;
1649 5247 : move16();
1650 2523807 : FOR( i = 0; i < ( nFadeLength ); i++ )
1651 : {
1652 : /* tmp2 = ( last_gain_fx + i * grad_fx )*/
1653 2518560 : tmp2 = add( mult_r( sub( 32767, tmp ), last_gain_fx ), mult_r( tmp, gain_fx ) ); // 32767= 1.0f in Q15,
1654 :
1655 2518560 : transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], tmp2 ); // Q(Q_tc-tmp_e1)
1656 2518560 : move32();
1657 2518560 : transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], tmp2 ); // Q(Q_tc-tmp_e1)
1658 2518560 : move32();
1659 :
1660 2518560 : tmp = add( tmp, invFade );
1661 : }
1662 2523807 : FOR( ; i < nSamples; i++ )
1663 : {
1664 2518560 : transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], gain_fx ); // Q(Q_tc-tmp_e1)
1665 2518560 : move32();
1666 2518560 : transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], gain_fx ); // Q(Q_tc-tmp_e1)
1667 2518560 : move32();
1668 : }
1669 : }
1670 : ELSE
1671 : {
1672 5766 : FOR( i = 0; i < nSamples; i++ )
1673 : {
1674 5760 : transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], gain_fx ); // Q(Q_tc-tmp_e1)
1675 5760 : move32();
1676 5760 : transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], gain_fx ); // Q(Q_tc-tmp_e1)
1677 5760 : move32();
1678 : }
1679 : }
1680 :
1681 5253 : st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain_fx = gain_fx;
1682 5253 : move16();
1683 5253 : st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain_e = tmp_e1;
1684 5253 : move16();
1685 :
1686 5253 : *Q_tc = sub( *Q_tc, tmp_e1 );
1687 5253 : move16();
1688 5253 : return;
1689 : }
1690 :
1691 : /*-------------------------------------------------------------------------*
1692 : * ivas_ism_param_dec_render_sf()
1693 : *
1694 : *
1695 : *-------------------------------------------------------------------------*/
1696 22297 : static void ivas_ism_param_dec_render_sf_fx(
1697 : Decoder_Struct *st_ivas,
1698 : IVAS_OUTPUT_SETUP hSetup,
1699 : const Word16 nchan_transport,
1700 : const Word16 nchan_out,
1701 : const Word16 nchan_out_woLFE,
1702 : Word32 *output_f_fx[], /*Q_output*/
1703 : Word16 Q_output[] )
1704 : {
1705 : Word16 ch, slot_idx, i, index_slot;
1706 : /* CLDFB Output Buffers */
1707 : Word32 Cldfb_RealBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; // Q(31-real_exp)
1708 : Word32 Cldfb_ImagBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; // Q(31-imag_exp)
1709 : Word32 *Cldfb_RealBuffer_in_fx[PARAM_ISM_MAX_DMX]; // Q11
1710 : Word32 *Cldfb_ImagBuffer_in_fx[PARAM_ISM_MAX_DMX]; // Q11
1711 : PARAM_ISM_DEC_HANDLE hParamIsmDec;
1712 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1713 : Word16 slot_idx_start;
1714 : Word16 idx_in;
1715 : Word16 idx_lfe;
1716 : Word16 subframe_idx;
1717 : Word16 samplesProcessed, no_col_cldfb, size_cldfb;
1718 22297 : hParamIsmDec = st_ivas->hParamIsmDec;
1719 22297 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1720 22297 : slot_idx_start = hSpatParamRendCom->slots_rendered;
1721 22297 : move16();
1722 22297 : subframe_idx = hSpatParamRendCom->subframes_rendered;
1723 22297 : move16();
1724 : /* Set some memories to zero */
1725 228360 : FOR( ch = 0; ch < nchan_out_woLFE; ch++ )
1726 : {
1727 973775 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
1728 : {
1729 767712 : set32_fx( Cldfb_RealBuffer_fx[ch][slot_idx], 0, hSpatParamRendCom->num_freq_bands );
1730 767712 : set32_fx( Cldfb_ImagBuffer_fx[ch][slot_idx], 0, hSpatParamRendCom->num_freq_bands );
1731 : }
1732 : }
1733 :
1734 :
1735 : Word16 real_exp[JBM_CLDFB_SLOTS_IN_SUBFRAME];
1736 : Word16 imag_exp[JBM_CLDFB_SLOTS_IN_SUBFRAME];
1737 106345 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
1738 : {
1739 84048 : index_slot = add( slot_idx_start, slot_idx );
1740 :
1741 :
1742 252144 : FOR( ch = 0; ch < nchan_transport; ch++ )
1743 : {
1744 168096 : Word16 cldfb_idx = add( imult1616( imult1616( index_slot, hSpatParamRendCom->num_freq_bands ), nchan_transport ), imult1616( ch, hSpatParamRendCom->num_freq_bands ) );
1745 168096 : Cldfb_RealBuffer_in_fx[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[cldfb_idx]; // Q11
1746 168096 : Cldfb_ImagBuffer_in_fx[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[cldfb_idx]; // Q11
1747 : }
1748 :
1749 : /* Compute bandwise rendering to target LS using covariance rendering */
1750 84048 : real_exp[slot_idx] = 0;
1751 84048 : move16();
1752 84048 : imag_exp[slot_idx] = 0;
1753 84048 : move16();
1754 84048 : ivas_param_ism_render_slot_fx( hParamIsmDec, hSpatParamRendCom,
1755 84048 : Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, &real_exp[slot_idx], &imag_exp[slot_idx],
1756 84048 : hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_fx,
1757 : index_slot, slot_idx, nchan_out_woLFE, nchan_transport );
1758 : }
1759 :
1760 : /* CLDFB Synthesis */
1761 22297 : idx_in = 0;
1762 22297 : move16();
1763 22297 : idx_lfe = 0;
1764 22297 : move16();
1765 : // Word16 tmp_buff_Q[MAX_OUTPUT_CHANNELS];
1766 :
1767 248485 : FOR( ch = 0; ch < nchan_out; ch++ )
1768 : {
1769 226188 : test();
1770 226188 : IF( ( hSetup.num_lfe > 0 ) && EQ_16( hSetup.index_lfe[idx_lfe], ch ) )
1771 : {
1772 20125 : set32_fx( output_f_fx[ch], 0, i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) );
1773 :
1774 20125 : if ( LT_16( idx_lfe, sub( hSetup.num_lfe, 1 ) ) )
1775 : {
1776 0 : idx_lfe = add( idx_lfe, 1 );
1777 : }
1778 : }
1779 : ELSE
1780 : {
1781 :
1782 : Word32 *RealBuffer_fx[16];
1783 : Word32 *ImagBuffer_fx[16];
1784 :
1785 206063 : Word16 Q_real = 31;
1786 206063 : move16();
1787 :
1788 973775 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
1789 : {
1790 767712 : RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i];
1791 767712 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i];
1792 767712 : Q_real = s_min( Q_real, sub( 31, imag_exp[i] ) );
1793 767712 : Q_real = s_min( Q_real, sub( 31, real_exp[i] ) );
1794 : }
1795 :
1796 206063 : Q_real = sub( Q_real, 3 ); // guarded bits
1797 :
1798 973775 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
1799 : {
1800 767712 : Scale_sig32( RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add( sub( Q_real, 31 ), real_exp[i] ) ); // Q_real
1801 767712 : Scale_sig32( ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add( sub( Q_real, 31 ), imag_exp[i] ) ); // Q_real
1802 : }
1803 :
1804 206063 : Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( sub( Q_real, 1 ), Q11 ) ); // Q_real-1
1805 206063 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = sub( Q_real, 1 );
1806 206063 : move16();
1807 206063 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, output_f_fx[ch], i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), 0, 0, st_ivas->cldfbSynDec[ch] );
1808 206063 : Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( Q11, sub( Q_real, 1 ) ) ); // Q11
1809 206063 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11;
1810 206063 : move16();
1811 :
1812 : /*scaling the output_f buffer to have common Q accross the buffer*/
1813 206063 : samplesProcessed = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
1814 206063 : no_col_cldfb = st_ivas->cldfbSynDec[ch]->no_col;
1815 206063 : move16();
1816 206063 : IF( GT_16( samplesProcessed, -1 ) )
1817 : {
1818 : Word32 res_dec, res_frac;
1819 206063 : iDiv_and_mod_32( sub( add( samplesProcessed, st_ivas->cldfbSynDec[ch]->no_channels ), 1 ), st_ivas->cldfbSynDec[ch]->no_channels, &res_dec, &res_frac, 0 );
1820 206063 : no_col_cldfb = s_min( no_col_cldfb, extract_l( res_dec ) );
1821 : }
1822 :
1823 206063 : size_cldfb = imult1616( st_ivas->cldfbSynDec[ch]->no_channels, no_col_cldfb );
1824 206063 : Scale_sig32( output_f_fx[ch], size_cldfb, sub( Q11, sub( Q_real, 1 ) ) ); // Q11
1825 :
1826 206063 : Q_output[ch] = 11;
1827 206063 : move16();
1828 206063 : idx_in = add( idx_in, 1 );
1829 : }
1830 : }
1831 :
1832 22297 : hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
1833 22297 : move16();
1834 22297 : hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 );
1835 22297 : move16();
1836 :
1837 22297 : return;
1838 : }
1839 :
1840 :
1841 : /*-------------------------------------------------------------------------*
1842 : * ivas_param_ism_dec_render()
1843 : *
1844 : *
1845 : *-------------------------------------------------------------------------*/
1846 6539 : void ivas_param_ism_dec_render_fx(
1847 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
1848 : const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */
1849 : UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */
1850 : UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */
1851 : Word32 *output_f_fx[] /*Q11*/
1852 : )
1853 : {
1854 :
1855 : Word16 ch, slots_to_render, first_sf, last_sf, subframe_idx;
1856 : UWord16 slot_size, n_samples_sf;
1857 : PARAM_ISM_DEC_HANDLE hParamIsmDec;
1858 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1859 : IVAS_OUTPUT_SETUP hSetup;
1860 : Word16 nchan_transport, nchan_out, nchan_out_woLFE;
1861 : Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS];
1862 : Word16 Q_output[MAX_OUTPUT_CHANNELS];
1863 :
1864 6539 : set16_fx( Q_output, 0, MAX_OUTPUT_CHANNELS );
1865 :
1866 6539 : hParamIsmDec = st_ivas->hParamIsmDec;
1867 6539 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1868 6539 : hSetup = st_ivas->hIntSetup;
1869 6539 : nchan_transport = st_ivas->nchan_transport;
1870 6539 : move16();
1871 :
1872 6539 : IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
1873 : {
1874 543 : nchan_out = st_ivas->nchan_ism;
1875 543 : move16();
1876 543 : nchan_out_woLFE = nchan_out;
1877 543 : move16();
1878 543 : st_ivas->hDecoderConfig->nchan_out = nchan_out;
1879 543 : move16();
1880 : }
1881 : ELSE
1882 : {
1883 5996 : nchan_out = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
1884 5996 : move16();
1885 5996 : nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
1886 5996 : move16();
1887 : }
1888 6539 : slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS );
1889 :
1890 : /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
1891 : Word32 res_dec, res_frac;
1892 6539 : iDiv_and_mod_32( nSamplesAsked, slot_size, &res_dec, &res_frac, 0 );
1893 :
1894 6539 : slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), extract_l( res_dec ) );
1895 6539 : *nSamplesRendered = imult1616( slots_to_render, extract_l( slot_size ) );
1896 6539 : move16();
1897 6539 : first_sf = hSpatParamRendCom->subframes_rendered;
1898 6539 : move16();
1899 6539 : last_sf = first_sf;
1900 6539 : move16();
1901 :
1902 28836 : WHILE( slots_to_render > 0 )
1903 : {
1904 22297 : slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] );
1905 22297 : last_sf = add( last_sf, 1 );
1906 : }
1907 :
1908 74663 : FOR( ch = 0; ch < nchan_out; ch++ )
1909 : {
1910 68124 : output_f_local_fx[ch] = &output_f_fx[ch][0];
1911 : }
1912 :
1913 28836 : FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
1914 : {
1915 22297 : ivas_ism_param_dec_render_sf_fx( st_ivas, hSetup, nchan_transport, nchan_out, nchan_out_woLFE, output_f_local_fx, Q_output );
1916 :
1917 22297 : n_samples_sf = i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slot_size );
1918 248485 : FOR( ch = 0; ch < nchan_out; ch++ )
1919 : {
1920 226188 : output_f_local_fx[ch] += n_samples_sf;
1921 : }
1922 : }
1923 :
1924 6539 : IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) )
1925 : {
1926 : /* copy the memories */
1927 : /* store mixing matrix for next subframe */
1928 5253 : ivas_param_ism_update_mixing_matrix_fx( hParamIsmDec, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_fx, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_fx, nchan_transport, nchan_out_woLFE );
1929 :
1930 : /* store MetaData parameters */
1931 24765 : FOR( ch = 0; ch < st_ivas->nchan_ism; ch++ )
1932 : {
1933 : #ifdef OBJ_EDITING_API
1934 19512 : IF( GT_32( st_ivas->hParamIsmDec->azimuth_values_fx[ch], 754974720 ) /*180.f in Q22*/ )
1935 : {
1936 0 : st_ivas->hIsmMetaData[ch]->azimuth_fx = L_sub( st_ivas->hParamIsmDec->edited_azimuth_values_fx[ch], 1509949440 ) /*360.0F in Q22*/;
1937 0 : move32();
1938 : }
1939 : ELSE
1940 : {
1941 19512 : st_ivas->hIsmMetaData[ch]->azimuth_fx = st_ivas->hParamIsmDec->edited_azimuth_values_fx[ch];
1942 19512 : move32();
1943 : }
1944 19512 : st_ivas->hIsmMetaData[ch]->elevation_fx = st_ivas->hParamIsmDec->edited_elevation_values_fx[ch];
1945 19512 : move32();
1946 : #else
1947 : IF( GT_32( st_ivas->hParamIsmDec->azimuth_values_fx[ch], 754974720 ) /*180.f in Q22*/ )
1948 : {
1949 : st_ivas->hIsmMetaData[ch]->azimuth_fx = L_sub( st_ivas->hParamIsmDec->azimuth_values_fx[ch], 1509949440 ) /*360.0F in Q22*/;
1950 : move32();
1951 : }
1952 : ELSE
1953 : {
1954 : st_ivas->hIsmMetaData[ch]->azimuth_fx = st_ivas->hParamIsmDec->azimuth_values_fx[ch];
1955 : move32();
1956 : }
1957 : #endif
1958 :
1959 19512 : st_ivas->hIsmMetaData[ch]->elevation_fx = st_ivas->hParamIsmDec->elevation_values_fx[ch];
1960 19512 : move32();
1961 : }
1962 : }
1963 :
1964 6539 : *nSamplesAvailableNext = imult1616( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), (Word16) slot_size );
1965 6539 : move16();
1966 6539 : return;
1967 : }
1968 :
1969 :
1970 : /*-------------------------------------------------------------------------*
1971 : * ivas_param_ism_params_to_masa_param_mapping()
1972 : *
1973 : *
1974 : *-------------------------------------------------------------------------*/
1975 7955 : void ivas_param_ism_params_to_masa_param_mapping_fx(
1976 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
1977 : )
1978 : {
1979 : PARAM_ISM_DEC_HANDLE hParamIsmDec;
1980 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1981 : Word16 nBins;
1982 : Word16 band_idx, bin_idx, sf_idx;
1983 : Word16 brange[2];
1984 : Word16 azimuth[2];
1985 : Word16 elevation[2];
1986 : Word16 power_ratio_fx[2]; /* Q15 */
1987 : #ifndef OBJ_EDITING_API
1988 : Word32 ivas_total_brate;
1989 : #endif
1990 :
1991 :
1992 7955 : hParamIsmDec = st_ivas->hParamIsmDec;
1993 7955 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1994 7955 : nBins = hSpatParamRendCom->num_freq_bands;
1995 7955 : move16();
1996 : #ifndef OBJ_EDITING_API
1997 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
1998 : move32();
1999 :
2000 : test();
2001 : IF( !( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || ivas_total_brate == FRAME_NO_DATA ) )
2002 : {
2003 : ivas_param_ism_dec_dequant_DOA_fx( hParamIsmDec, st_ivas->nchan_ism );
2004 : ivas_param_ism_dec_dequant_powrat_fx( hParamIsmDec );
2005 : st_ivas->hISMDTX.dtx_flag = 0;
2006 : move16();
2007 : }
2008 : ELSE
2009 : {
2010 : st_ivas->hISMDTX.dtx_flag = 1;
2011 : move16();
2012 : }
2013 : #endif
2014 :
2015 7955 : IF( GT_16( st_ivas->nchan_ism, 1 ) )
2016 : {
2017 7955 : IF( st_ivas->hISMDTX.dtx_flag )
2018 : {
2019 : Word32 energy_ratio_fx; /* Q30 */
2020 228 : energy_ratio_fx = L_mult0( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx, st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx ); /* Q15 + Q15 -> Q30 */
2021 :
2022 228 : hSpatParamRendCom->numSimultaneousDirections = 1;
2023 228 : move16();
2024 228 : azimuth[0] = extract_l( L_shr( L_add( hParamIsmDec->azimuth_values_fx[0], ONE_IN_Q21 ), 22 ) ); // Q0
2025 228 : move16();
2026 228 : elevation[0] = extract_l( L_shr( L_add( hParamIsmDec->elevation_values_fx[0], ONE_IN_Q21 ), 22 ) ); // Q0
2027 228 : move16();
2028 :
2029 1140 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
2030 : {
2031 55632 : FOR( bin_idx = 0; bin_idx < nBins; bin_idx++ )
2032 : {
2033 54720 : hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
2034 54720 : move16();
2035 54720 : hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
2036 54720 : move16();
2037 54720 : hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = energy_ratio_fx;
2038 54720 : move16();
2039 54720 : hSpatParamRendCom->spreadCoherence_fx[sf_idx][bin_idx] = 0;
2040 54720 : move16();
2041 54720 : hSpatParamRendCom->surroundingCoherence_fx[sf_idx][bin_idx] = 0;
2042 54720 : move16();
2043 : }
2044 : }
2045 : }
2046 : ELSE
2047 : {
2048 7727 : hSpatParamRendCom->numSimultaneousDirections = 2;
2049 7727 : move16();
2050 92724 : FOR( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
2051 : {
2052 84997 : brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
2053 84997 : move16();
2054 : #ifdef OBJ_EDITING_API
2055 84997 : brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
2056 84997 : move16();
2057 :
2058 84997 : azimuth[0] = extract_l( L_shr( L_add( hParamIsmDec->edited_azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]], ( 1 << 21 ) ), 22 ) ); // Q0
2059 84997 : move16();
2060 84997 : elevation[0] = extract_l( L_shr( L_add( hParamIsmDec->edited_elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]], ( 1 << 21 ) ), 22 ) ); // Q0
2061 84997 : move16();
2062 : #else
2063 : brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
2064 : move16();
2065 :
2066 : azimuth[0] = extract_l( L_shr( L_add( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]], ( 1 << 21 ) ), 22 ) ); // Q0
2067 : move16();
2068 : elevation[0] = extract_l( L_shr( L_add( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]], ( 1 << 21 ) ), 22 ) ); // Q0
2069 : move16();
2070 : #endif
2071 84997 : power_ratio_fx[0] = hParamIsmDec->power_ratios_fx[band_idx][0][0];
2072 84997 : move16();
2073 :
2074 : #ifdef OBJ_EDITING_API
2075 84997 : azimuth[1] = extract_l( L_shr( L_add( hParamIsmDec->edited_azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]], ( 1 << 21 ) ), 22 ) ); // Q0
2076 84997 : move16();
2077 84997 : elevation[1] = extract_l( L_shr( L_add( hParamIsmDec->edited_elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]], ( 1 << 21 ) ), 22 ) ); // Q0
2078 84997 : move16();
2079 : #else
2080 : azimuth[1] = extract_l( L_shr( L_add( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]], ( 1 << 21 ) ), 22 ) ); // Q0
2081 : move16();
2082 : elevation[1] = extract_l( L_shr( L_add( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]], ( 1 << 21 ) ), 22 ) ); // Q0
2083 : move16();
2084 : #endif
2085 84997 : power_ratio_fx[1] = hParamIsmDec->power_ratios_fx[band_idx][0][1];
2086 84997 : move16();
2087 :
2088 424985 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
2089 : {
2090 2134388 : FOR( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
2091 : {
2092 1794400 : hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
2093 1794400 : move16();
2094 1794400 : hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
2095 1794400 : move16();
2096 1794400 : hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[0], Q15 ); // Q30
2097 1794400 : move32();
2098 1794400 : hSpatParamRendCom->azimuth2[sf_idx][bin_idx] = azimuth[1];
2099 1794400 : move16();
2100 1794400 : hSpatParamRendCom->elevation2[sf_idx][bin_idx] = elevation[1];
2101 1794400 : move16();
2102 1794400 : hSpatParamRendCom->energy_ratio2_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[1], Q15 ); // Q30
2103 1794400 : move32();
2104 : }
2105 : }
2106 : }
2107 :
2108 38635 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
2109 : {
2110 1825308 : FOR( bin_idx = 0; bin_idx < nBins; bin_idx++ )
2111 : {
2112 1794400 : hSpatParamRendCom->spreadCoherence_fx[sf_idx][bin_idx] = 0;
2113 1794400 : move16();
2114 1794400 : hSpatParamRendCom->spreadCoherence2_fx[sf_idx][bin_idx] = 0;
2115 1794400 : move16();
2116 1794400 : hSpatParamRendCom->surroundingCoherence_fx[sf_idx][bin_idx] = 0;
2117 1794400 : move16();
2118 : }
2119 : }
2120 : }
2121 : }
2122 : ELSE
2123 : {
2124 0 : hSpatParamRendCom->numSimultaneousDirections = 1;
2125 0 : move16();
2126 0 : azimuth[0] = extract_l( L_shr( ( L_add( hParamIsmDec->azimuth_values_fx[0], ( 1 << 21 ) ) ), 22 ) ); // Q0
2127 0 : move16();
2128 0 : elevation[0] = extract_l( L_shr( L_add( hParamIsmDec->elevation_values_fx[0], ( 1 << 21 ) ), 22 ) ); // Q0
2129 0 : move16();
2130 :
2131 0 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
2132 : {
2133 0 : FOR( bin_idx = 0; bin_idx < nBins; bin_idx++ )
2134 : {
2135 0 : hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
2136 0 : move16();
2137 0 : hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
2138 0 : move16();
2139 0 : hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = ONE_IN_Q30; /* 1.0f in Q30 */
2140 0 : move32();
2141 0 : hSpatParamRendCom->spreadCoherence_fx[sf_idx][bin_idx] = 0;
2142 0 : move16();
2143 0 : hSpatParamRendCom->surroundingCoherence_fx[sf_idx][bin_idx] = 0;
2144 0 : move16();
2145 : }
2146 : }
2147 : }
2148 7955 : return;
2149 : }
|