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.h"
38 : #include "ivas_prot_rend.h"
39 : #include "prot.h"
40 : #include "ivas_rom_com.h"
41 : #include "ivas_rom_dec.h"
42 : #ifdef DEBUGGING
43 : #include "debug.h"
44 : #endif
45 : #include "wmc_auto.h"
46 :
47 :
48 : /*-----------------------------------------------------------------------*
49 : * Local function declarations
50 : *-----------------------------------------------------------------------*/
51 :
52 : static void ivas_ism_param_dec_tc_gain_adjust( Decoder_Struct *st_ivas, const int16_t nSamples, const int16_t nFadeLength, float *p_data_f[] );
53 :
54 : /*-----------------------------------------------------------------------*
55 : * Local function definitions
56 : *-----------------------------------------------------------------------*/
57 :
58 148488 : static void ivas_param_ism_dec_dequant_DOA(
59 : PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */
60 : const int16_t nchan_ism /* i : number of ISM channels */
61 : )
62 : {
63 : int16_t i;
64 : PARAM_ISM_CONFIG_HANDLE hParamIsm;
65 :
66 148488 : hParamIsm = hParamIsmDec->hParamIsm;
67 :
68 148488 : assert( nchan_ism <= MAX_NUM_OBJECTS );
69 :
70 : /* Get the azimuth and elevation values */
71 676503 : for ( i = 0; i < nchan_ism; i++ )
72 : {
73 528015 : hParamIsmDec->azimuth_values[i] = ism_dequant_meta( hParamIsm->azi_index[i], ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS );
74 528015 : hParamIsmDec->elevation_values[i] = ism_dequant_meta( hParamIsm->ele_index[i], ism_elevation_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_ELEVATION_NBITS );
75 : }
76 :
77 148488 : return;
78 : }
79 :
80 :
81 148488 : static void ivas_param_ism_dec_dequant_powrat(
82 : PARAM_ISM_DEC_HANDLE hParamIsmDec /* i/o: decoder ParamISM handle */
83 : )
84 : {
85 : int16_t band_idx, slot_idx;
86 : PARAM_ISM_CONFIG_HANDLE hParamIsm;
87 :
88 148488 : hParamIsm = hParamIsmDec->hParamIsm;
89 :
90 : /* Get the power ratio values */
91 1781856 : for ( band_idx = 0; band_idx < hParamIsm->nbands; band_idx++ )
92 : {
93 3266736 : for ( slot_idx = 0; slot_idx < hParamIsm->nblocks[band_idx]; slot_idx++ )
94 : {
95 1633368 : hParamIsmDec->power_ratios[band_idx][slot_idx][0] = (float) ( hParamIsm->power_ratios_idx[band_idx][slot_idx] ) / (float) ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) / 2.0f + 0.5f;
96 1633368 : hParamIsmDec->power_ratios[band_idx][slot_idx][1] = 1.0f - hParamIsmDec->power_ratios[band_idx][slot_idx][0];
97 : }
98 : }
99 :
100 148488 : return;
101 : }
102 :
103 :
104 2670 : static void ivas_ism_get_interpolator(
105 : const int16_t subframe_nbslots,
106 : float *interpolator )
107 : {
108 2670 : int16_t interp_idx = 0;
109 :
110 65646 : for ( interp_idx = 0; interp_idx < subframe_nbslots; interp_idx++ )
111 : {
112 62976 : interpolator[interp_idx] = (float) ( interp_idx + 1 ) / (float) subframe_nbslots;
113 : }
114 :
115 2670 : return;
116 : }
117 :
118 :
119 1034 : static void ivas_ism_get_proto_matrix(
120 : IVAS_OUTPUT_SETUP hOutSetup,
121 : const int16_t nchan_transport,
122 : float *proto_matrix )
123 : {
124 : int16_t idx;
125 :
126 : /* compute proto_matrix */
127 1034 : switch ( nchan_transport )
128 : {
129 1034 : case 2:
130 : {
131 1034 : if ( hOutSetup.nchan_out_woLFE )
132 : {
133 10460 : for ( idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ )
134 : {
135 9426 : if ( hOutSetup.ls_azimuth[idx] > 0.0f )
136 : {
137 4196 : proto_matrix[idx] = 1.0f;
138 4196 : proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0.0f;
139 : }
140 5230 : else if ( hOutSetup.ls_azimuth[idx] < 0.0f )
141 : {
142 4196 : proto_matrix[idx] = 0.0f;
143 4196 : proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 1.0f;
144 : }
145 : else
146 : {
147 1034 : proto_matrix[idx] = 0.5f;
148 1034 : proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0.5f;
149 : }
150 : }
151 : }
152 : else
153 : {
154 0 : assert( 0 && "Error: number of output channels not supported" );
155 : }
156 1034 : break;
157 : }
158 :
159 0 : default:
160 0 : assert( 0 && "Error: number of transport channels not supported" );
161 : }
162 :
163 1034 : return;
164 : }
165 :
166 :
167 2218188 : static void ivas_param_ism_collect_slot(
168 : PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */
169 : float *Cldfb_RealBuffer_in,
170 : float *Cldfb_ImagBuffer_in,
171 : const int16_t ch,
172 : float ref_power[],
173 : float cx_diag[][PARAM_ISM_MAX_DMX] )
174 : {
175 :
176 : int16_t band_idx, bin_idx;
177 : int16_t brange[2];
178 : float tmp;
179 :
180 : /* loop over parameter bands to collect transport channel energies */
181 26618256 : for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
182 : {
183 24400068 : brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
184 24400068 : brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
185 127493268 : for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
186 : {
187 103093200 : tmp = 0.0f;
188 103093200 : tmp += ( Cldfb_RealBuffer_in[bin_idx] * Cldfb_RealBuffer_in[bin_idx] );
189 103093200 : tmp += ( Cldfb_ImagBuffer_in[bin_idx] * Cldfb_ImagBuffer_in[bin_idx] );
190 103093200 : cx_diag[bin_idx][ch] += tmp;
191 103093200 : ref_power[bin_idx] += tmp;
192 : }
193 : }
194 :
195 2218188 : return;
196 : }
197 :
198 :
199 69318 : static void ivas_param_ism_compute_mixing_matrix(
200 : const int16_t nchan_ism, /* i : number of ISM channels */
201 : PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */
202 : ISM_DTX_DATA_DEC hISMDTX, /* i : ISM DTX handle */
203 : float direct_response[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN],
204 : const int16_t nchan_transport,
205 : const int16_t nchan_out_woLFE,
206 : float cx_diag[][PARAM_ISM_MAX_DMX],
207 : float ref_power[],
208 : float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX] )
209 : {
210 : int16_t band_idx, bin_idx;
211 : int16_t i, w, obj_indx;
212 : int16_t brange[2];
213 : float direct_power[MAX_NUM_OBJECTS];
214 : float cy_diag[PARAM_ISM_MAX_CHAN];
215 : float cy_diag_tmp[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN];
216 : float *dir_res_ptr;
217 : float *proto_matrix;
218 : float response_matrix[PARAM_ISM_MAX_CHAN * MAX_NUM_OBJECTS];
219 : int16_t num_wave;
220 :
221 69318 : proto_matrix = hParamIsmDec->hParamIsmRendering->proto_matrix;
222 :
223 69318 : assert( ( nchan_ism == 3 ) || ( nchan_ism == 4 ) );
224 69318 : assert( nchan_transport == 2 );
225 :
226 69318 : if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
227 : {
228 634 : num_wave = nchan_ism;
229 : }
230 : else
231 : {
232 68684 : num_wave = MAX_PARAM_ISM_WAVE;
233 : }
234 69318 : set_zero( response_matrix, PARAM_ISM_MAX_CHAN * MAX_NUM_OBJECTS );
235 :
236 : /* loop over parameter bands to compute the mixing matrix */
237 831816 : for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
238 : {
239 762498 : brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
240 762498 : brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
241 :
242 : /* Compute covaraince matrix from direct response*/
243 2301442 : for ( w = 0; w < num_wave; w++ )
244 : {
245 1538944 : set_zero( cy_diag_tmp[w], nchan_out_woLFE );
246 :
247 1538944 : if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
248 : {
249 27896 : dir_res_ptr = direct_response[w];
250 : }
251 : else
252 : {
253 1511048 : obj_indx = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][w];
254 1511048 : dir_res_ptr = direct_response[obj_indx];
255 : }
256 1538944 : mvr2r( dir_res_ptr, response_matrix + w * nchan_out_woLFE, nchan_out_woLFE );
257 : /* we only need the diagonal of Cy*/
258 1538944 : matrix_product_diag( dir_res_ptr, nchan_out_woLFE, 1, 0, dir_res_ptr, 1, nchan_out_woLFE, 0, cy_diag_tmp[w] );
259 : }
260 :
261 3984138 : for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
262 : {
263 :
264 3221640 : set_zero( cy_diag, nchan_out_woLFE );
265 9741000 : for ( w = 0; w < num_wave; w++ )
266 : {
267 6519360 : if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
268 : {
269 152160 : direct_power[w] = ( 1.0f / nchan_ism ) * ref_power[bin_idx];
270 : }
271 : else
272 : {
273 6367200 : direct_power[w] = hParamIsmDec->power_ratios[band_idx][0][w] * ref_power[bin_idx];
274 : }
275 :
276 6519360 : if ( direct_power[w] != 0.f )
277 : {
278 53041837 : for ( i = 0; i < nchan_out_woLFE; i++ )
279 : {
280 47716846 : cy_diag[i] += direct_power[w] * cy_diag_tmp[w][i];
281 : }
282 : }
283 6519360 : direct_power[w] = sqrtf( direct_power[w] );
284 : }
285 :
286 : /* Compute mixing matrix */
287 3221640 : computeMixingMatricesISM( nchan_transport, num_wave, nchan_out_woLFE, response_matrix, direct_power, cx_diag[bin_idx], cy_diag, proto_matrix, 1,
288 3221640 : PARAM_MC_REG_SX, PARAM_MC_REG_GHAT, mixing_matrix[bin_idx] );
289 : }
290 : }
291 :
292 69318 : return;
293 : }
294 :
295 :
296 1109094 : static void ivas_param_ism_render_slot(
297 : PARAM_ISM_DEC_HANDLE hParamIsmDec,
298 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom,
299 : float *Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX],
300 : float *Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX],
301 : float Cldfb_RealBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
302 : float Cldfb_ImagBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
303 : float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX],
304 : const int16_t interpolator_idx,
305 : const int16_t out_slot_idx,
306 : const int16_t num_ch_LS,
307 : const int16_t nchan_transport )
308 : {
309 : int16_t outchIdx, inchIdx, bin_idx;
310 : float tmp_1, mixing_matrix_smooth;
311 :
312 1109094 : tmp_1 = hParamIsmDec->hParamIsmRendering->interpolator[interpolator_idx];
313 :
314 52655694 : for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
315 : {
316 : /* smooth the mixing matrix */
317 516277920 : for ( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ )
318 : {
319 1394193960 : for ( inchIdx = 0; inchIdx < nchan_transport; inchIdx++ )
320 : {
321 929462640 : mixing_matrix_smooth = tmp_1 * mixing_matrix[bin_idx][outchIdx + inchIdx * num_ch_LS] +
322 929462640 : ( 1 - tmp_1 ) * hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][outchIdx + inchIdx * num_ch_LS];
323 :
324 929462640 : Cldfb_RealBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_RealBuffer_in[inchIdx][bin_idx];
325 929462640 : Cldfb_ImagBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_ImagBuffer_in[inchIdx][bin_idx];
326 : }
327 : }
328 : }
329 :
330 1109094 : return;
331 : }
332 :
333 :
334 2670 : static ivas_error ivas_param_ism_rendering_init(
335 : PARAM_ISM_RENDERING_HANDLE hParamIsmRendering,
336 : IVAS_OUTPUT_SETUP hOutSetup,
337 : const int16_t nchan_transport,
338 : const int16_t subframe_nbslots,
339 : AUDIO_CONFIG output_config )
340 : {
341 : int16_t bin_idx;
342 :
343 : /* initialization of mixing matrix buffer for smoothing */
344 162870 : for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ )
345 : {
346 160200 : set_zero( hParamIsmRendering->mixing_matrix_lin_old[bin_idx], PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX );
347 : }
348 :
349 : /* memory allocation for proto matrix and interpolator */
350 2670 : if ( ( hParamIsmRendering->proto_matrix = (float *) malloc( hOutSetup.nchan_out_woLFE * nchan_transport * sizeof( float ) ) ) == NULL )
351 : {
352 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for proto matrix\n" ) );
353 : }
354 2670 : if ( ( hParamIsmRendering->interpolator = (float *) malloc( subframe_nbslots * sizeof( float ) ) ) == NULL )
355 : {
356 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) );
357 : }
358 :
359 2670 : if ( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
360 : {
361 : /* computation of proto matrix */
362 1034 : ivas_ism_get_proto_matrix( hOutSetup, nchan_transport, hParamIsmRendering->proto_matrix );
363 : }
364 :
365 : /* computation of interpolator*/
366 2670 : ivas_ism_get_interpolator( subframe_nbslots, hParamIsmRendering->interpolator );
367 :
368 2670 : return IVAS_ERR_OK;
369 : }
370 :
371 :
372 69318 : static void ivas_param_ism_update_mixing_matrix(
373 : PARAM_ISM_DEC_HANDLE hParamIsmDec,
374 : float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX],
375 : const int16_t nchan_in,
376 : const int16_t nchan_out )
377 : {
378 : int16_t inchIdx, outchIdx, bin_idx, band_idx;
379 : int16_t brange[2];
380 :
381 831816 : for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
382 : {
383 762498 : brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
384 762498 : brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
385 :
386 3984138 : for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
387 : {
388 9664920 : for ( inchIdx = 0; inchIdx < nchan_in; inchIdx++ )
389 : {
390 64534200 : for ( outchIdx = 0; outchIdx < nchan_out; outchIdx++ )
391 : {
392 58090920 : hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][outchIdx + inchIdx * nchan_out] = mixing_matrix[bin_idx][outchIdx + inchIdx * nchan_out];
393 : }
394 : }
395 : }
396 : }
397 :
398 69318 : return;
399 : }
400 :
401 :
402 : /*-------------------------------------------------------------------------*
403 : * ivas_param_ism_dec_open()
404 : *
405 : * Open Param ISM handle
406 : *-------------------------------------------------------------------------*/
407 :
408 2920 : ivas_error ivas_param_ism_dec_open(
409 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
410 : )
411 : {
412 : int16_t i, granularity;
413 : PARAM_ISM_DEC_HANDLE hParamIsmDec;
414 : IVAS_OUTPUT_SETUP hOutSetup;
415 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
416 : AUDIO_CONFIG output_config;
417 : int32_t output_Fs;
418 : ivas_error error;
419 :
420 2920 : error = IVAS_ERR_OK;
421 :
422 2920 : push_wmops( "ivas_param_ism_dec_open" );
423 :
424 : /*-----------------------------------------------------------------*
425 : * prepare library opening
426 : *-----------------------------------------------------------------*/
427 :
428 2920 : if ( ( hParamIsmDec = (PARAM_ISM_DEC_HANDLE) malloc( sizeof( PARAM_ISM_DEC_DATA ) ) ) == NULL )
429 : {
430 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) );
431 : }
432 :
433 2920 : if ( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL )
434 : {
435 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
436 : }
437 :
438 : /* Assign memory to Param Object handle */
439 2920 : if ( ( hParamIsmDec->hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL )
440 : {
441 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) );
442 : }
443 :
444 2920 : if ( ( hParamIsmDec->hParamIsmRendering = (PARAM_ISM_RENDERING_HANDLE) malloc( sizeof( PARAM_ISM_RENDERING_DATA ) ) ) == NULL )
445 : {
446 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM Rendering handle\n" ) );
447 : }
448 :
449 2920 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
450 2920 : output_config = st_ivas->hDecoderConfig->output_config;
451 :
452 2920 : ivas_param_ism_config( hParamIsmDec->hParamIsm, st_ivas->nchan_ism );
453 :
454 : /*-----------------------------------------------------------------*
455 : * set input parameters
456 : *-----------------------------------------------------------------*/
457 :
458 2920 : hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );
459 2920 : set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
460 2920 : set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
461 2920 : hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
462 2920 : hSpatParamRendCom->subframes_rendered = 0;
463 2920 : hSpatParamRendCom->slots_rendered = 0;
464 2920 : hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
465 2920 : hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f );
466 :
467 2920 : hParamIsmDec->hParamIsm->nbands = MAX_PARAM_ISM_NBANDS;
468 :
469 37960 : for ( i = 0; i < ( hParamIsmDec->hParamIsm->nbands + 1 ); i++ )
470 : {
471 35040 : hParamIsmDec->hParamIsm->band_grouping[i] = Param_ISM_band_grouping[i];
472 :
473 35040 : if ( hParamIsmDec->hParamIsm->band_grouping[i] > hSpatParamRendCom->num_freq_bands )
474 : {
475 3201 : hParamIsmDec->hParamIsm->band_grouping[i] = hSpatParamRendCom->num_freq_bands;
476 : }
477 : }
478 :
479 : /*-----------------------------------------------------------------*
480 : * output setup
481 : *-----------------------------------------------------------------*/
482 :
483 : /* hIntSetup and hOutSetup differs only for Binaural rendering */
484 2920 : if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
485 : {
486 : /* nchan_out is essential for memory initialization for CLDFB Synthesis */
487 261 : st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->nchan_ism;
488 261 : st_ivas->hIntSetup.is_loudspeaker_setup = 1;
489 : }
490 :
491 2920 : hOutSetup = st_ivas->hIntSetup;
492 :
493 2920 : if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) )
494 : {
495 : /* Initialize Param ISM Rendering handle */
496 2670 : if ( st_ivas->hDecoderConfig->Opt_tsm )
497 : {
498 1266 : if ( ( error = ivas_param_ism_rendering_init( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, MAX_JBM_CLDFB_TIMESLOTS, output_config ) ) != IVAS_ERR_OK )
499 : {
500 0 : return error;
501 : }
502 : }
503 : else
504 : {
505 1404 : if ( ( error = ivas_param_ism_rendering_init( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, CLDFB_NO_COL_MAX, output_config ) ) != IVAS_ERR_OK )
506 : {
507 0 : return error;
508 : }
509 : }
510 : }
511 :
512 3954 : if ( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ||
513 1161 : output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
514 : {
515 : /* Initialize efap handle */
516 1034 : if ( ( error = efap_init_data( &( st_ivas->hEFAPdata ), hOutSetup.ls_azimuth, hOutSetup.ls_elevation, hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK )
517 : {
518 0 : return error;
519 : }
520 : }
521 :
522 : /* Azi and Ele values are transmitted once per frame per object */
523 2920 : set_zero( hParamIsmDec->azimuth_values, MAX_NUM_OBJECTS );
524 2920 : set_zero( hParamIsmDec->elevation_values, MAX_NUM_OBJECTS );
525 :
526 2920 : hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES;
527 2920 : hSpatParamRendCom->dirac_bs_md_write_idx = 0;
528 2920 : hSpatParamRendCom->dirac_read_idx = 0;
529 :
530 2920 : if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
531 : {
532 1375 : if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK )
533 : {
534 0 : return error;
535 : }
536 :
537 1375 : if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK )
538 : {
539 0 : return error;
540 : }
541 : }
542 :
543 2920 : st_ivas->hISMDTX.dtx_flag = 0;
544 :
545 2920 : st_ivas->hParamIsmDec = hParamIsmDec;
546 2920 : st_ivas->hSpatParamRendCom = hSpatParamRendCom;
547 :
548 2920 : granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs );
549 :
550 2920 : if ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE )
551 2670 : {
552 2670 : int16_t nchan_transport = st_ivas->nchan_transport;
553 2670 : int16_t nchan_full = 0;
554 :
555 2670 : if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
556 : {
557 1375 : nchan_full = nchan_transport;
558 1375 : hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
559 1375 : hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
560 : }
561 : else
562 : {
563 : int16_t n_slots_to_alloc;
564 1295 : if ( st_ivas->hDecoderConfig->Opt_tsm == 1 )
565 : {
566 550 : n_slots_to_alloc = MAX_JBM_CLDFB_TIMESLOTS;
567 : }
568 : else
569 : {
570 745 : n_slots_to_alloc = CLDFB_SLOTS_PER_SUBFRAME * MAX_PARAM_SPATIAL_SUBFRAMES;
571 : }
572 1295 : if ( ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
573 :
574 : {
575 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) );
576 : }
577 1295 : set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands );
578 :
579 1295 : if ( ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
580 : {
581 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) );
582 : }
583 1295 : set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands );
584 : }
585 :
586 2670 : if ( st_ivas->hTcBuffer == NULL )
587 : {
588 1356 : if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, granularity ) ) != IVAS_ERR_OK )
589 : {
590 0 : return error;
591 : }
592 : }
593 : }
594 : else
595 : {
596 250 : hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
597 250 : hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
598 250 : if ( st_ivas->hTcBuffer == NULL )
599 : {
600 202 : int16_t nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out;
601 :
602 202 : if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK )
603 : {
604 0 : return error;
605 : }
606 : }
607 : }
608 :
609 2920 : pop_wmops();
610 2920 : return error;
611 : }
612 :
613 :
614 : /*-------------------------------------------------------------------------*
615 : * ivas_param_ism_dec_close()
616 : *
617 : * Close Param ISM handle
618 : *-------------------------------------------------------------------------*/
619 :
620 17456 : void ivas_param_ism_dec_close(
621 : PARAM_ISM_DEC_HANDLE *hParamIsmDec_out, /* i/o: decoder DirAC handle */
622 : SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */
623 : AUDIO_CONFIG output_config /* i : output audio configuration */
624 : )
625 : {
626 17456 : if ( hParamIsmDec_out != NULL && *hParamIsmDec_out != NULL )
627 : {
628 : PARAM_ISM_DEC_HANDLE hParamIsmDec;
629 2920 : hParamIsmDec = *hParamIsmDec_out;
630 :
631 : /* Config & CLDFB */
632 2920 : if ( hParamIsmDec->hParamIsm != NULL )
633 : {
634 2920 : free( hParamIsmDec->hParamIsm );
635 2920 : hParamIsmDec->hParamIsm = NULL;
636 : }
637 :
638 2920 : if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) )
639 : {
640 : /* Param ISM Rendering */
641 2670 : if ( hParamIsmDec->hParamIsmRendering->interpolator != NULL )
642 : {
643 2670 : free( hParamIsmDec->hParamIsmRendering->interpolator );
644 2670 : hParamIsmDec->hParamIsmRendering->interpolator = NULL;
645 : }
646 2670 : if ( hParamIsmDec->hParamIsmRendering->proto_matrix != NULL )
647 : {
648 2670 : free( hParamIsmDec->hParamIsmRendering->proto_matrix );
649 2670 : hParamIsmDec->hParamIsmRendering->proto_matrix = NULL;
650 : }
651 : }
652 :
653 2920 : if ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc != NULL )
654 : {
655 1295 : free( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc );
656 1295 : hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
657 : }
658 2920 : if ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc != NULL )
659 : {
660 1295 : free( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc );
661 1295 : hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
662 : }
663 :
664 2920 : if ( hParamIsmDec->hParamIsmRendering != NULL )
665 : {
666 2920 : free( hParamIsmDec->hParamIsmRendering );
667 2920 : hParamIsmDec->hParamIsmRendering = NULL;
668 : }
669 :
670 2920 : free( *hParamIsmDec_out );
671 2920 : *hParamIsmDec_out = NULL;
672 : }
673 :
674 17456 : if ( hSpatParamRendCom_out != NULL && *hSpatParamRendCom_out != NULL )
675 : {
676 2920 : if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
677 : {
678 1375 : ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 );
679 1375 : ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 );
680 : }
681 :
682 2920 : free( *hSpatParamRendCom_out );
683 2920 : *hSpatParamRendCom_out = NULL;
684 : }
685 :
686 17456 : return;
687 : }
688 :
689 :
690 : /*-------------------------------------------------------------------------*
691 : * ivas_ism_dec_digest_tc()
692 : *
693 : *
694 : *-------------------------------------------------------------------------*/
695 :
696 1871295 : void ivas_ism_dec_digest_tc(
697 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
698 : )
699 : {
700 1871295 : ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
701 :
702 1871295 : if ( st_ivas->renderer_type == RENDERER_TD_PANNING ||
703 1556873 : st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ||
704 1394607 : st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ||
705 1193461 : st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ||
706 1118587 : st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
707 987133 : st_ivas->renderer_type == RENDERER_OSBA_LS ||
708 772063 : st_ivas->renderer_type == RENDERER_OSBA_STEREO ||
709 726049 : ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->hDecoderConfig->Opt_Headrotation == 0 ) )
710 : {
711 : int16_t i;
712 : #ifndef NONBE_1412_AVOID_ROUNDING_AZ_ELEV
713 : int16_t azimuth, elevation;
714 : #endif
715 : /* we have a full frame interpolator, adapt it */
716 : /* for BE testing */
717 1238395 : if ( ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ) == st_ivas->hTcBuffer->n_samples_available )
718 : {
719 1238133 : int16_t interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
720 :
721 1238133 : if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ||
722 1075879 : st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
723 944431 : st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) )
724 : {
725 569484 : st_ivas->hIsmRendererData->interpolator[0] = 0.0f;
726 395375040 : for ( i = 1; i < interpolator_length; i++ )
727 : {
728 394805556 : st_ivas->hIsmRendererData->interpolator[i] = st_ivas->hIsmRendererData->interpolator[i - 1] + 1.f / ( interpolator_length - 1 );
729 : }
730 : }
731 : else
732 : {
733 442423209 : for ( i = 0; i < interpolator_length; i++ )
734 : {
735 441754560 : st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length - 1 );
736 : }
737 : }
738 : }
739 : else
740 : {
741 262 : ivas_jbm_dec_get_adapted_linear_interpolator( (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator );
742 : }
743 1238395 : st_ivas->hIsmRendererData->interp_offset = 0;
744 :
745 : /* also get the gains here */
746 4410875 : for ( i = 0; i < st_ivas->nchan_ism; i++ )
747 : {
748 3172480 : mvr2r( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmRendererData->prev_gains[i], MAX_OUTPUT_CHANNELS );
749 :
750 3172480 : if ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_STEREO )
751 : {
752 269338 : ivas_ism_get_stereo_gains( st_ivas->hIsmMetaData[i]->edited_azimuth, st_ivas->hIsmMetaData[i]->edited_elevation, &st_ivas->hIsmRendererData->gains[i][0], &st_ivas->hIsmRendererData->gains[i][1] );
753 269338 : v_multc( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmMetaData[i]->edited_gain, st_ivas->hIsmRendererData->gains[i], CPE_CHANNELS );
754 : }
755 : else
756 : {
757 : #ifndef NONBE_1412_AVOID_ROUNDING_AZ_ELEV
758 : // TODO tmu review when #215 is resolved
759 : azimuth = (int16_t) floorf( st_ivas->hIsmMetaData[i]->edited_azimuth + 0.5f );
760 : elevation = (int16_t) floorf( st_ivas->hIsmMetaData[i]->edited_elevation + 0.5f );
761 : #endif
762 2903142 : if ( ( st_ivas->renderer_type == RENDERER_TD_PANNING ||
763 2241242 : st_ivas->renderer_type == RENDERER_OSBA_LS ||
764 1716932 : st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM || ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) ) &&
765 1631174 : st_ivas->hCombinedOrientationData == NULL )
766 1631174 : {
767 : #ifdef NONBE_1412_AVOID_ROUNDING_AZ_ELEV
768 1631174 : float elevation = st_ivas->hIsmMetaData[i]->edited_elevation;
769 : #endif
770 1631174 : if ( st_ivas->hIntSetup.is_planar_setup )
771 : {
772 : /* If no elevation support in output format, then rendering should be done with zero elevation */
773 : #ifdef NONBE_1412_AVOID_ROUNDING_AZ_ELEV
774 485296 : elevation = 0.f;
775 : #else
776 : elevation = 0;
777 : #endif
778 : }
779 :
780 1631174 : if ( st_ivas->hEFAPdata != NULL )
781 : {
782 : #ifdef NONBE_1412_AVOID_ROUNDING_AZ_ELEV
783 1631174 : efap_determine_gains( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmMetaData[i]->edited_azimuth, elevation, EFAP_MODE_EFAP );
784 : #else
785 : efap_determine_gains( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains[i], azimuth, elevation, EFAP_MODE_EFAP );
786 : #endif
787 1631174 : v_multc( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmMetaData[i]->edited_gain, st_ivas->hIsmRendererData->gains[i], st_ivas->hEFAPdata->numSpk );
788 : }
789 : }
790 1271968 : else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ||
791 839912 : st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
792 519290 : st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
793 : {
794 : #ifdef NONBE_1412_AVOID_ROUNDING_AZ_ELEV
795 : // TODO tmu review when #215 is resolved
796 : int16_t azimuth, elevation;
797 :
798 1271968 : azimuth = (int16_t) floorf( st_ivas->hIsmMetaData[i]->edited_azimuth + 0.5f );
799 1271968 : elevation = (int16_t) floorf( st_ivas->hIsmMetaData[i]->edited_elevation + 0.5f );
800 : #endif
801 : /*get HOA gets for direction (ACN/SN3D)*/
802 1271968 : ivas_dirac_dec_get_response( azimuth, elevation, st_ivas->hIsmRendererData->gains[i], st_ivas->hIntSetup.ambisonics_order );
803 1271968 : v_multc( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmMetaData[i]->edited_gain, st_ivas->hIsmRendererData->gains[i], ivas_sba_get_nchan( st_ivas->hIntSetup.ambisonics_order, 0 ) );
804 : }
805 : }
806 : }
807 : }
808 :
809 1871295 : return;
810 : }
811 :
812 :
813 : /*-------------------------------------------------------------------------*
814 : * ivas_param_ism_dec_digest_tc()
815 : *
816 : *
817 : *-------------------------------------------------------------------------*/
818 :
819 69318 : void ivas_param_ism_dec_digest_tc(
820 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
821 : const uint16_t nCldfbSlots, /* i : number of CLDFB slots in transport channels */
822 : float *p_data_f[] /* i/o: synthesized core-coder transport channels/DirAC output */
823 : )
824 : {
825 : int16_t ch, slot_idx, output_frame;
826 : int16_t num_freq_bands, cldfb_ch, n_ch_cldfb;
827 : float *cldfb_real_buffer, *cldfb_imag_buffer;
828 :
829 : /* Initialization */
830 69318 : num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands;
831 69318 : output_frame = nCldfbSlots * num_freq_bands;
832 69318 : n_ch_cldfb = st_ivas->hTcBuffer->nchan_transport_jbm - st_ivas->hTcBuffer->nchan_buffer_full;
833 :
834 69318 : cldfb_real_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc;
835 69318 : cldfb_imag_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc;
836 :
837 69318 : ivas_ism_param_dec_tc_gain_adjust( st_ivas, output_frame, output_frame / 2, p_data_f );
838 :
839 : /* CLDFB Analysis */
840 207954 : for ( ch = 0, cldfb_ch = 0; cldfb_ch < n_ch_cldfb; cldfb_ch++, ch++ )
841 : {
842 2356824 : for ( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
843 : {
844 2218188 : cldfbAnalysis_ts( &( p_data_f[ch][num_freq_bands * slot_idx] ),
845 2218188 : &cldfb_real_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
846 2218188 : &cldfb_imag_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
847 : num_freq_bands, st_ivas->cldfbAnaDec[cldfb_ch] );
848 : }
849 : }
850 :
851 69318 : return;
852 : }
853 :
854 :
855 : /*-------------------------------------------------------------------------*
856 : * ivas_param_ism_dec_dequant_md()
857 : *
858 : *
859 : *-------------------------------------------------------------------------*/
860 :
861 155841 : void ivas_param_ism_dec_dequant_md(
862 : Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */
863 : )
864 : {
865 : /* De-quantization */
866 155841 : if ( !( st_ivas->hDecoderConfig->ivas_total_brate == IVAS_SID_5k2 || st_ivas->hDecoderConfig->ivas_total_brate == FRAME_NO_DATA ) )
867 : {
868 148488 : ivas_param_ism_dec_dequant_DOA( st_ivas->hParamIsmDec, st_ivas->nchan_ism );
869 148488 : ivas_param_ism_dec_dequant_powrat( st_ivas->hParamIsmDec );
870 148488 : st_ivas->hISMDTX.dtx_flag = 0;
871 : }
872 : else
873 : {
874 7353 : st_ivas->hISMDTX.dtx_flag = 1;
875 : }
876 :
877 155841 : return;
878 : }
879 :
880 :
881 : /*-------------------------------------------------------------------------*
882 : * ivas_param_ism_dec_prepare_renderer()
883 : *
884 : *
885 : *-------------------------------------------------------------------------*/
886 :
887 69318 : void ivas_param_ism_dec_prepare_renderer(
888 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
889 : const uint16_t nCldfbSlots /* i : number of CLDFB slots in transport channels */
890 : )
891 : {
892 : int16_t ch, nchan_transport, nchan_out, nchan_out_woLFE, i;
893 : int16_t slot_idx, bin_idx;
894 : float ref_power[CLDFB_NO_CHANNELS_MAX];
895 : float cx_diag[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX];
896 : /* Direct Response/EFAP Gains */
897 : float direct_response[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN];
898 : PARAM_ISM_DEC_HANDLE hParamIsmDec;
899 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
900 :
901 : /* Initialization */
902 69318 : hParamIsmDec = st_ivas->hParamIsmDec;
903 69318 : assert( hParamIsmDec );
904 69318 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
905 69318 : assert( hSpatParamRendCom );
906 :
907 69318 : nchan_transport = st_ivas->nchan_transport;
908 :
909 69318 : if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
910 : {
911 5965 : nchan_out = st_ivas->nchan_ism;
912 5965 : nchan_out_woLFE = nchan_out;
913 5965 : st_ivas->hDecoderConfig->nchan_out = nchan_out;
914 : }
915 : else
916 : {
917 63353 : nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
918 63353 : nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
919 : }
920 :
921 : /* general setup */
922 69318 : ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hParamIsmDec->hParamIsmRendering->interpolator );
923 :
924 69318 : ivas_dirac_dec_set_md_map( st_ivas, nCldfbSlots );
925 :
926 : /* set buffers to zero */
927 4228398 : for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ )
928 : {
929 4159080 : set_zero( cx_diag[bin_idx], PARAM_ISM_MAX_DMX );
930 : }
931 69318 : set_zero( ref_power, CLDFB_NO_CHANNELS_MAX );
932 :
933 : /* obtain the direct response using EFAP */
934 69318 : if ( !( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) )
935 : {
936 284396 : for ( i = 0; i < st_ivas->nchan_ism; i++ )
937 : {
938 221043 : efap_determine_gains( st_ivas->hEFAPdata, direct_response[i], hParamIsmDec->edited_azimuth_values[i], hParamIsmDec->edited_elevation_values[i], EFAP_MODE_EFAP );
939 : }
940 : }
941 : else
942 : {
943 : int16_t j;
944 :
945 27657 : for ( i = 0; i < st_ivas->nchan_ism; i++ )
946 : {
947 101956 : for ( j = 0; j < nchan_out_woLFE; j++ )
948 : {
949 80264 : if ( i == j )
950 : {
951 21692 : direct_response[i][j] = 1.0f;
952 : }
953 : else
954 : {
955 58572 : direct_response[i][j] = 0.0f;
956 : }
957 : }
958 : }
959 :
960 27657 : for ( j = 0; j < nchan_out_woLFE; j++ )
961 : {
962 21692 : if ( hParamIsmDec->azimuth_values[j] > 0.0f )
963 : {
964 9175 : hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 1.0f;
965 9175 : hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 0.0f;
966 : }
967 : else
968 : {
969 12517 : if ( hParamIsmDec->azimuth_values[j] < 0.0f )
970 : {
971 9189 : hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 0.0f;
972 9189 : hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 1.0f;
973 : }
974 : else /* == 0.0f */
975 : {
976 3328 : hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 0.5f;
977 3328 : hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 0.5f;
978 : }
979 : }
980 : }
981 : }
982 :
983 207954 : for ( ch = 0; ch < nchan_transport; ch++ )
984 : {
985 : /* CLDFB Analysis */
986 2356824 : for ( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
987 : {
988 2218188 : ivas_param_ism_collect_slot( hParamIsmDec, &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], ch, ref_power, cx_diag );
989 : }
990 : }
991 :
992 : /* Obtain Mixing Matrix on a frame-level */
993 3290958 : for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
994 : {
995 3221640 : set_f( hParamIsmDec->hParamIsmRendering->mixing_matrix_lin[bin_idx], 0.0f, nchan_transport * nchan_out_woLFE );
996 : }
997 :
998 : /* Compute mixing matrix */
999 69318 : ivas_param_ism_compute_mixing_matrix( st_ivas->nchan_ism, hParamIsmDec, st_ivas->hISMDTX, direct_response, nchan_transport, nchan_out_woLFE, cx_diag, ref_power, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin );
1000 :
1001 69318 : return;
1002 : }
1003 :
1004 :
1005 : /*-------------------------------------------------------------------------*
1006 : * ivas_ism_param_dec_tc_gain_adjust()
1007 : *
1008 : *
1009 : *-------------------------------------------------------------------------*/
1010 :
1011 69318 : static void ivas_ism_param_dec_tc_gain_adjust(
1012 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
1013 : const int16_t nSamples, /* i : number of samples to be compensate */
1014 : const int16_t nFadeLength, /* i : length of the crossfade in samples */
1015 : float *p_data_f[] /* i : synthesized core-coder transport channels/DirAC output*/
1016 : )
1017 :
1018 : {
1019 : int16_t i;
1020 : float gain, ene_tc, ene_sum, grad;
1021 : float last_gain;
1022 :
1023 69318 : ene_tc = 0.0f;
1024 69318 : ene_sum = 0.0f;
1025 69318 : last_gain = st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain;
1026 :
1027 51615918 : for ( i = 0; i < nSamples; i++ )
1028 : {
1029 51546600 : ene_tc += p_data_f[0][i] * p_data_f[0][i] + p_data_f[1][i] * p_data_f[1][i]; /* L*L + R*R */
1030 51546600 : ene_sum += ( p_data_f[0][i] + p_data_f[1][i] ) * ( p_data_f[0][i] + p_data_f[1][i] ); /* (L+R)*(L+R) */
1031 : }
1032 69318 : gain = sqrtf( ene_tc / ( ene_sum + EPSILON ) );
1033 69318 : if ( st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame > 1 )
1034 : {
1035 : /* Smoothing */
1036 68425 : gain = 0.75f * gain + 0.25f * last_gain;
1037 : /* 10ms ramp */
1038 68425 : grad = ( gain - last_gain ) / (float) nFadeLength; /* slope between two consecutive gains, 480 samples length */
1039 25585885 : for ( i = 0; i < ( nFadeLength ); i++ )
1040 : {
1041 25517460 : p_data_f[0][i] *= ( last_gain + i * grad );
1042 25517460 : p_data_f[1][i] *= ( last_gain + i * grad );
1043 : }
1044 25585885 : for ( ; i < nSamples; i++ )
1045 : {
1046 25517460 : p_data_f[0][i] *= gain;
1047 25517460 : p_data_f[1][i] *= gain;
1048 : }
1049 : }
1050 : else
1051 : {
1052 512573 : for ( i = 0; i < nSamples; i++ )
1053 : {
1054 511680 : p_data_f[0][i] *= gain;
1055 511680 : p_data_f[1][i] *= gain;
1056 : }
1057 : }
1058 :
1059 69318 : st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain = gain;
1060 :
1061 69318 : return;
1062 : }
1063 :
1064 :
1065 : /*-------------------------------------------------------------------------*
1066 : * ivas_ism_param_dec_render_sf()
1067 : *
1068 : *
1069 : *-------------------------------------------------------------------------*/
1070 :
1071 285495 : static void ivas_ism_param_dec_render_sf(
1072 : Decoder_Struct *st_ivas,
1073 : IVAS_OUTPUT_SETUP hSetup,
1074 : const int16_t nchan_transport,
1075 : const int16_t nchan_out,
1076 : const int16_t nchan_out_woLFE,
1077 : float *output_f[] /* o : rendered time signal */
1078 : )
1079 : {
1080 : int16_t ch, slot_idx, i, index_slot;
1081 : /* CLDFB Output Buffers */
1082 : float Cldfb_RealBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
1083 : float Cldfb_ImagBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
1084 : float *Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX];
1085 : float *Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX];
1086 : PARAM_ISM_DEC_HANDLE hParamIsmDec;
1087 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1088 : int16_t slot_idx_start;
1089 : int16_t idx_in;
1090 : int16_t idx_lfe;
1091 : int16_t subframe_idx;
1092 :
1093 285495 : hParamIsmDec = st_ivas->hParamIsmDec;
1094 285495 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1095 285495 : slot_idx_start = hSpatParamRendCom->slots_rendered;
1096 285495 : subframe_idx = hSpatParamRendCom->subframes_rendered;
1097 :
1098 : /* Set some memories to zero */
1099 2836584 : for ( ch = 0; ch < nchan_out_woLFE; ch++ )
1100 : {
1101 12393699 : for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
1102 : {
1103 9842610 : set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands );
1104 9842610 : set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands );
1105 : }
1106 : }
1107 :
1108 1394589 : for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
1109 : {
1110 1109094 : index_slot = slot_idx_start + slot_idx;
1111 :
1112 3327282 : for ( ch = 0; ch < nchan_transport; ch++ )
1113 : {
1114 2218188 : Cldfb_RealBuffer_in[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands];
1115 2218188 : Cldfb_ImagBuffer_in[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands];
1116 : }
1117 :
1118 : /* Compute bandwise rendering to target LS using covariance rendering */
1119 1109094 : ivas_param_ism_render_slot( hParamIsmDec, hSpatParamRendCom, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in,
1120 1109094 : Cldfb_RealBuffer, Cldfb_ImagBuffer, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin, index_slot, slot_idx, nchan_out_woLFE, nchan_transport );
1121 : }
1122 :
1123 : /* CLDFB Synthesis */
1124 285495 : idx_in = 0;
1125 285495 : idx_lfe = 0;
1126 :
1127 3098219 : for ( ch = 0; ch < nchan_out; ch++ )
1128 : {
1129 2812724 : if ( ( hSetup.num_lfe > 0 ) && ( hSetup.index_lfe[idx_lfe] == ch ) )
1130 : {
1131 261635 : set_zero( output_f[ch], hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands );
1132 261635 : if ( idx_lfe < ( hSetup.num_lfe - 1 ) )
1133 : {
1134 0 : idx_lfe++;
1135 : }
1136 : }
1137 : else
1138 : {
1139 : float *RealBuffer[16];
1140 : float *ImagBuffer[16];
1141 :
1142 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
1143 12393699 : for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
1144 : {
1145 9842610 : RealBuffer[i] = Cldfb_RealBuffer[idx_in][i];
1146 9842610 : ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i];
1147 : }
1148 :
1149 2551089 : cldfbSynthesis( RealBuffer, ImagBuffer, output_f[ch], hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] );
1150 2551089 : idx_in++;
1151 : }
1152 : }
1153 :
1154 285495 : hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe_idx];
1155 285495 : hSpatParamRendCom->subframes_rendered++;
1156 :
1157 285495 : return;
1158 : }
1159 :
1160 :
1161 : /*-------------------------------------------------------------------------*
1162 : * ivas_param_ism_dec_render()
1163 : *
1164 : *
1165 : *-------------------------------------------------------------------------*/
1166 :
1167 102405 : void ivas_param_ism_dec_render(
1168 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
1169 : const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */
1170 : uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */
1171 : uint16_t *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */
1172 : float *output_f[] /* o : rendered time signal */
1173 : )
1174 : {
1175 : int16_t ch, slots_to_render, first_sf, last_sf, subframe_idx;
1176 : uint16_t slot_size, n_samples_sf;
1177 : PARAM_ISM_DEC_HANDLE hParamIsmDec;
1178 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1179 : IVAS_OUTPUT_SETUP hSetup;
1180 : int16_t nchan_transport, nchan_out, nchan_out_woLFE;
1181 : float *output_f_local[MAX_OUTPUT_CHANNELS];
1182 :
1183 102405 : hParamIsmDec = st_ivas->hParamIsmDec;
1184 102405 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1185 102405 : hSetup = st_ivas->hIntSetup;
1186 : #ifdef DEBUGGING
1187 : assert( hParamIsmDec );
1188 : assert( hSpatParamRendCom );
1189 : #endif
1190 102405 : nchan_transport = st_ivas->nchan_transport;
1191 102405 : if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
1192 : {
1193 5965 : nchan_out = st_ivas->nchan_ism;
1194 5965 : nchan_out_woLFE = nchan_out;
1195 5965 : st_ivas->hDecoderConfig->nchan_out = nchan_out;
1196 : }
1197 : else
1198 : {
1199 96440 : nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
1200 96440 : nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
1201 : }
1202 102405 : slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS );
1203 :
1204 : /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
1205 102405 : slots_to_render = min( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size );
1206 102405 : *nSamplesRendered = slots_to_render * slot_size;
1207 102405 : first_sf = hSpatParamRendCom->subframes_rendered;
1208 102405 : last_sf = first_sf;
1209 :
1210 387900 : while ( slots_to_render > 0 )
1211 : {
1212 285495 : slots_to_render -= hSpatParamRendCom->subframe_nbslots[last_sf];
1213 285495 : last_sf++;
1214 : }
1215 : #ifdef DEBUGGING
1216 : assert( slots_to_render == 0 );
1217 : #endif
1218 :
1219 1153961 : for ( ch = 0; ch < nchan_out; ch++ )
1220 : {
1221 1051556 : output_f_local[ch] = &output_f[ch][0];
1222 : }
1223 :
1224 387900 : for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
1225 : {
1226 285495 : ivas_ism_param_dec_render_sf( st_ivas, hSetup, nchan_transport, nchan_out, nchan_out_woLFE, output_f_local );
1227 285495 : n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size;
1228 3098219 : for ( ch = 0; ch < nchan_out; ch++ )
1229 : {
1230 2812724 : output_f_local[ch] += n_samples_sf;
1231 : }
1232 : }
1233 :
1234 102405 : if ( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots )
1235 : {
1236 : /* copy the memories */
1237 : /* store mixing matrix for next subframe */
1238 69318 : ivas_param_ism_update_mixing_matrix( hParamIsmDec, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin, nchan_transport, nchan_out_woLFE );
1239 :
1240 : /* store MetaData parameters */
1241 312053 : for ( ch = 0; ch < st_ivas->nchan_ism; ch++ )
1242 : {
1243 242735 : if ( st_ivas->hParamIsmDec->azimuth_values[ch] > 180.0f )
1244 : {
1245 0 : st_ivas->hIsmMetaData[ch]->azimuth = st_ivas->hParamIsmDec->edited_azimuth_values[ch] - 360.0f;
1246 : }
1247 : else
1248 : {
1249 242735 : st_ivas->hIsmMetaData[ch]->azimuth = st_ivas->hParamIsmDec->edited_azimuth_values[ch];
1250 : }
1251 242735 : st_ivas->hIsmMetaData[ch]->elevation = st_ivas->hParamIsmDec->edited_elevation_values[ch];
1252 : }
1253 : }
1254 :
1255 102405 : *nSamplesAvailableNext = ( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered ) * slot_size;
1256 :
1257 102405 : return;
1258 : }
1259 :
1260 :
1261 : /*-------------------------------------------------------------------------*
1262 : * ivas_param_ism_params_to_masa_param_mapping()
1263 : *
1264 : *
1265 : *-------------------------------------------------------------------------*/
1266 :
1267 57383 : void ivas_param_ism_params_to_masa_param_mapping(
1268 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
1269 : )
1270 : {
1271 : PARAM_ISM_DEC_HANDLE hParamIsmDec;
1272 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1273 : int16_t nBins;
1274 : int16_t band_idx, bin_idx, sf_idx;
1275 : int16_t brange[2];
1276 : int16_t azimuth[2];
1277 : int16_t elevation[2];
1278 : float power_ratio[2];
1279 : MASA_ISM_DATA_HANDLE hMasaIsmData;
1280 : int16_t obj;
1281 : int16_t obj_idx;
1282 :
1283 57383 : hParamIsmDec = st_ivas->hParamIsmDec;
1284 57383 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1285 57383 : hMasaIsmData = st_ivas->hMasaIsmData;
1286 57383 : nBins = hSpatParamRendCom->num_freq_bands;
1287 :
1288 57383 : if ( st_ivas->hISMDTX.dtx_flag )
1289 : {
1290 : float energy_ratio;
1291 : #ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG
1292 1258 : energy_ratio = powf( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence[0], 2.0f );
1293 : #else
1294 : energy_ratio = powf( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence, 2.0f );
1295 : #endif
1296 :
1297 1258 : hSpatParamRendCom->numSimultaneousDirections = 1;
1298 1258 : azimuth[0] = (int16_t) roundf( hParamIsmDec->azimuth_values[0] );
1299 1258 : elevation[0] = (int16_t) roundf( hParamIsmDec->elevation_values[0] );
1300 :
1301 6290 : for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
1302 : {
1303 306952 : for ( bin_idx = 0; bin_idx < nBins; bin_idx++ )
1304 : {
1305 301920 : hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
1306 301920 : hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
1307 :
1308 301920 : hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = energy_ratio;
1309 :
1310 301920 : hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f;
1311 301920 : hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0;
1312 : }
1313 : }
1314 : }
1315 : else
1316 : {
1317 56125 : hSpatParamRendCom->numSimultaneousDirections = 2;
1318 673500 : for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
1319 : {
1320 617375 : brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
1321 617375 : brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
1322 :
1323 617375 : azimuth[0] = (int16_t) roundf( hParamIsmDec->edited_azimuth_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] );
1324 617375 : elevation[0] = (int16_t) roundf( hParamIsmDec->edited_elevation_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] );
1325 617375 : power_ratio[0] = hParamIsmDec->power_ratios[band_idx][0][0];
1326 :
1327 617375 : azimuth[1] = (int16_t) roundf( hParamIsmDec->edited_azimuth_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] );
1328 617375 : elevation[1] = (int16_t) roundf( hParamIsmDec->edited_elevation_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] );
1329 617375 : power_ratio[1] = hParamIsmDec->power_ratios[band_idx][0][1];
1330 :
1331 3086875 : for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
1332 : {
1333 13875740 : for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
1334 : {
1335 11406240 : hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
1336 11406240 : hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
1337 11406240 : hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = power_ratio[0];
1338 11406240 : hSpatParamRendCom->azimuth2[sf_idx][bin_idx] = azimuth[1];
1339 11406240 : hSpatParamRendCom->elevation2[sf_idx][bin_idx] = elevation[1];
1340 11406240 : hSpatParamRendCom->energy_ratio2[sf_idx][bin_idx] = power_ratio[1];
1341 : }
1342 : }
1343 : }
1344 :
1345 280625 : for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
1346 : {
1347 11630740 : for ( bin_idx = 0; bin_idx < nBins; bin_idx++ )
1348 : {
1349 11406240 : hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f;
1350 11406240 : hSpatParamRendCom->spreadCoherence2[sf_idx][bin_idx] = 0.0f;
1351 11406240 : hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0;
1352 : }
1353 : }
1354 :
1355 264068 : for ( obj = 0; obj < st_ivas->nchan_ism; obj++ )
1356 : {
1357 1039715 : for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
1358 : {
1359 831772 : hMasaIsmData->azimuth_ism[obj][sf_idx] = (int16_t) roundf( hParamIsmDec->azimuth_values[obj] );
1360 831772 : hMasaIsmData->elevation_ism[obj][sf_idx] = (int16_t) roundf( hParamIsmDec->elevation_values[obj] );
1361 : }
1362 :
1363 207943 : hMasaIsmData->azimuth_ism_edited[obj] = (int16_t) roundf( hParamIsmDec->edited_azimuth_values[obj] );
1364 207943 : hMasaIsmData->elevation_ism_edited[obj] = (int16_t) roundf( hParamIsmDec->edited_elevation_values[obj] );
1365 :
1366 1039715 : for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
1367 : {
1368 831772 : set_zero( hMasaIsmData->energy_ratio_ism[obj][sf_idx], CLDFB_NO_CHANNELS_MAX );
1369 : }
1370 : }
1371 :
1372 168375 : for ( obj = 0; obj < MAX_PARAM_ISM_WAVE; obj++ )
1373 : {
1374 1347000 : for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
1375 : {
1376 1234750 : brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
1377 1234750 : brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
1378 :
1379 1234750 : obj_idx = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][obj];
1380 1234750 : power_ratio[obj] = hParamIsmDec->power_ratios[band_idx][0][obj];
1381 :
1382 6173750 : for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
1383 : {
1384 27751480 : for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
1385 : {
1386 22812480 : hMasaIsmData->energy_ratio_ism[obj_idx][sf_idx][bin_idx] = power_ratio[obj];
1387 : }
1388 : }
1389 : }
1390 : }
1391 : }
1392 :
1393 57383 : return;
1394 : }
|