Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : #include <assert.h>
34 : #include <stdint.h>
35 : #include "options.h"
36 : #include <math.h>
37 : #include "cnst.h"
38 : #include "prot_fx.h"
39 : #include "ivas_prot_rend_fx.h"
40 : #include "ivas_cnst.h"
41 : #include "ivas_rom_com.h"
42 : #include "ivas_rom_dec.h"
43 : #include "ivas_rom_rend.h"
44 : #include "wmc_auto.h"
45 : #include "ivas_rom_com_fx.h"
46 : #include "ivas_prot_fx.h"
47 :
48 : /*-----------------------------------------------------------------------*
49 : * Local function prototypes
50 : *-----------------------------------------------------------------------*/
51 4466 : static ivas_error ivas_dirac_dec_config_internal_fx(
52 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
53 : const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
54 : )
55 : {
56 : DIRAC_DEC_HANDLE hDirAC;
57 : ivas_error error;
58 : DIRAC_CONFIG_FLAG flag_config;
59 :
60 4466 : IF( EQ_32( flag_config_inp, DIRAC_RECONFIGURE_MODE ) )
61 : {
62 0 : flag_config = DIRAC_RECONFIGURE;
63 0 : move32();
64 : }
65 : ELSE
66 : {
67 4466 : flag_config = flag_config_inp;
68 4466 : move32();
69 : }
70 4466 : error = IVAS_ERR_OK;
71 4466 : move32();
72 :
73 4466 : hDirAC = NULL;
74 :
75 4466 : IF( EQ_32( flag_config, DIRAC_RECONFIGURE ) )
76 : {
77 3955 : hDirAC = st_ivas->hDirAC;
78 : }
79 511 : ELSE IF( EQ_32( flag_config, DIRAC_OPEN ) )
80 : {
81 : /*-----------------------------------------------------------------*
82 : * prepare library opening
83 : *-----------------------------------------------------------------*/
84 :
85 511 : IF( ( hDirAC = (DIRAC_DEC_HANDLE) malloc( sizeof( DIRAC_DEC_DATA ) ) ) == NULL )
86 : {
87 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
88 : }
89 :
90 511 : IF( ( hDirAC->hConfig = (DIRAC_CONFIG_DATA_HANDLE) malloc( sizeof( DIRAC_CONFIG_DATA ) ) ) == NULL )
91 : {
92 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC Config\n" ) );
93 : }
94 :
95 511 : st_ivas->hDirAC = hDirAC;
96 : }
97 :
98 : /*-----------------------------------------------------------------*
99 : * DirAC main configuration
100 : *-----------------------------------------------------------------*/
101 :
102 4466 : IF( NE_32( ( error = ivas_dirac_config_fx( (void *) st_ivas, DEC ) ), IVAS_ERR_OK ) )
103 : {
104 0 : return error;
105 : }
106 :
107 4466 : IF( EQ_32( flag_config, DIRAC_OPEN ) )
108 : {
109 511 : test();
110 511 : IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
111 : {
112 136 : hDirAC->spar_to_dirac_write_idx = DELAY_DIRAC_PARAM_DEC_SFR;
113 136 : move16();
114 : }
115 : ELSE
116 : {
117 375 : hDirAC->spar_to_dirac_write_idx = 0;
118 375 : move16();
119 : }
120 511 : hDirAC->dithering_seed = DIRAC_DITH_SEED;
121 511 : move16();
122 511 : st_ivas->hDirAC = hDirAC;
123 : }
124 :
125 4466 : return error;
126 : }
127 :
128 2243 : static ivas_error ivas_dirac_rend_config_fx(
129 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
130 : const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
131 : const Word16 dec_param_estim_old )
132 : {
133 : DIRAC_DEC_HANDLE hDirAC;
134 : Word16 nchan_out_woLFE;
135 : Word16 nchan_transport;
136 : Word16 nchan_transport_old;
137 : Word16 num_outputs_dir_old;
138 : Word16 num_outputs_diff_old;
139 : Word16 num_protos_diff_old;
140 : Word32 *proto_frame_f_old_fx;
141 : Word16 proto_signal_decorr_on_old;
142 : UWord16 i, j, k;
143 : Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS];
144 : Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS];
145 : Word32 output_Fs, ivas_total_brate;
146 : ivas_error error;
147 : Word16 nchan_transport_orig;
148 : Word16 hodirac_flag;
149 : DIRAC_CONFIG_FLAG flag_config;
150 : DIRAC_REND_HANDLE hDirACRend;
151 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
152 :
153 38131 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
154 : {
155 35888 : ls_azimuth_fx[i] = 0;
156 35888 : move32();
157 35888 : ls_elevation_fx[i] = 0;
158 35888 : move32();
159 : }
160 :
161 2243 : IF( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) )
162 : {
163 690 : flag_config = DIRAC_RECONFIGURE;
164 690 : move32();
165 : }
166 : ELSE
167 : {
168 1553 : flag_config = flag_config_inp;
169 1553 : move32();
170 : }
171 2243 : error = IVAS_ERR_OK;
172 2243 : move32();
173 :
174 2243 : hDirACRend = NULL;
175 2243 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
176 2243 : move32();
177 2243 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
178 2243 : move32();
179 2243 : hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order );
180 :
181 2243 : hDirAC = st_ivas->hDirAC;
182 2243 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
183 :
184 2243 : IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) )
185 : {
186 1840 : hDirACRend = st_ivas->hDirACRend;
187 : }
188 403 : ELSE IF( EQ_16( flag_config, DIRAC_OPEN ) )
189 : {
190 : /*-----------------------------------------------------------------*
191 : * prepare library opening
192 : *-----------------------------------------------------------------*/
193 :
194 403 : IF( ( hDirACRend = (DIRAC_REND_HANDLE) malloc( sizeof( DIRAC_REND_DATA ) ) ) == NULL )
195 : {
196 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC renderer\n" ) );
197 : }
198 :
199 403 : nchan_transport_old = 0;
200 403 : move16();
201 : }
202 :
203 2243 : nchan_transport_old = 0;
204 2243 : move16();
205 2243 : num_outputs_dir_old = 0;
206 2243 : move16();
207 2243 : num_outputs_diff_old = 0;
208 2243 : move16();
209 2243 : num_protos_diff_old = 0;
210 2243 : move16();
211 :
212 2243 : nchan_transport_orig = st_ivas->nchan_transport;
213 2243 : move16();
214 2243 : test();
215 2243 : IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
216 : {
217 895 : st_ivas->nchan_transport = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate );
218 895 : move16();
219 : }
220 :
221 2243 : nchan_transport = st_ivas->nchan_transport;
222 2243 : move16();
223 2243 : test();
224 2243 : test();
225 2243 : if ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
226 : {
227 273 : nchan_transport = 1;
228 273 : move16();
229 : }
230 2243 : test();
231 2243 : test();
232 2243 : IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
233 : {
234 : Word16 tmp1, tmp2, tmp3;
235 690 : ivas_sba_config_fx( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3 );
236 : }
237 :
238 : /*-----------------------------------------------------------------*
239 : * output setup: for parametric binaural renderer, use output setup, otherwise internal setup
240 : *-----------------------------------------------------------------*/
241 :
242 2243 : hDirACRend->hOutSetup = st_ivas->hIntSetup;
243 2243 : nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE;
244 2243 : move16();
245 :
246 2243 : test();
247 2243 : IF( hDirACRend->hOutSetup.ls_azimuth_fx != NULL && hDirACRend->hOutSetup.ls_elevation_fx != NULL )
248 : {
249 933 : Copy32( hDirACRend->hOutSetup.ls_azimuth_fx, ls_azimuth_fx, nchan_out_woLFE );
250 933 : Copy32( hDirACRend->hOutSetup.ls_elevation_fx, ls_elevation_fx, nchan_out_woLFE );
251 : }
252 :
253 2243 : IF( EQ_16( hDirACRend->hOutSetup.ambisonics_order, -1 ) )
254 : {
255 1042 : hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */
256 1042 : move16();
257 1042 : test();
258 1042 : if ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) )
259 : {
260 109 : hDirACRend->hOutSetup.ambisonics_order = SBA_FOA_ORDER;
261 109 : move16();
262 : }
263 : }
264 1201 : ELSE IF( GE_16( hDirACRend->hOutSetup.ambisonics_order, SBA_FOA_ORDER ) )
265 : {
266 1201 : Copy32( ls_azimuth_4d4_fx, ls_azimuth_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS );
267 1201 : Copy32( ls_elevation_4d4_fx, ls_elevation_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS );
268 : }
269 :
270 2243 : test();
271 2243 : test();
272 2243 : test();
273 2243 : test();
274 2243 : test();
275 2243 : test();
276 2243 : test();
277 2243 : IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
278 : {
279 : /* Remove the channel of the separated signal from the output setup of the spatial synthesis */
280 25 : hDirACRend->hOutSetup.nchan_out_woLFE = sub( hDirACRend->hOutSetup.nchan_out_woLFE, 1 );
281 25 : move16();
282 25 : nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE;
283 25 : move16();
284 25 : Copy32( &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) );
285 25 : Copy32( &ls_elevation_fx[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_elevation_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) );
286 : }
287 :
288 : /*-----------------------------------------------------------------*
289 : * set input parameters
290 : *-----------------------------------------------------------------*/
291 :
292 2243 : st_ivas->nchan_transport = nchan_transport_orig;
293 2243 : move16();
294 :
295 2243 : test();
296 2243 : test();
297 2243 : test();
298 2243 : test();
299 2243 : test();
300 2243 : test();
301 2243 : test();
302 2243 : test();
303 2243 : test();
304 2243 : test();
305 2243 : test();
306 2243 : IF( GT_16( nchan_transport_orig, 2 ) && hDirACRend->hOutSetup.is_loudspeaker_setup && EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && !hodirac_flag )
307 : {
308 46 : hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS;
309 46 : move32();
310 46 : hDirACRend->panningConf = DIRAC_PANNING_VBAP;
311 46 : move32();
312 : }
313 2197 : ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) )
314 : {
315 109 : hDirACRend->synthesisConf = DIRAC_SYNTHESIS_MONO;
316 109 : move32();
317 109 : hDirACRend->panningConf = DIRAC_PANNING_HOA3;
318 109 : move32();
319 109 : nchan_out_woLFE = 1;
320 109 : move16();
321 : }
322 2088 : ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && hDirACRend->hOutSetup.is_loudspeaker_setup )
323 : {
324 830 : hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS;
325 830 : move32();
326 830 : hDirACRend->panningConf = DIRAC_PANNING_VBAP;
327 830 : move32();
328 : }
329 1258 : ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && !hDirACRend->hOutSetup.is_loudspeaker_setup && GT_32( st_ivas->nchan_transport, 1 ) )
330 : {
331 406 : hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD;
332 406 : move32();
333 406 : hDirACRend->panningConf = DIRAC_PANNING_HOA3;
334 406 : move32();
335 : }
336 : ELSE
337 : {
338 852 : hDirACRend->synthesisConf = DIRAC_SYNTHESIS_GAIN_SHD;
339 852 : move32();
340 852 : hDirACRend->panningConf = DIRAC_PANNING_HOA3;
341 852 : move32();
342 : }
343 :
344 2243 : IF( EQ_16( flag_config, DIRAC_OPEN ) )
345 : {
346 403 : IF( ( hDirACRend->frequency_axis_fx = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL )
347 : {
348 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
349 : }
350 403 : set16_fx( hDirACRend->frequency_axis_fx, 0, hSpatParamRendCom->num_freq_bands );
351 403 : ivas_dirac_dec_get_frequency_axis_fx( hDirACRend->frequency_axis_fx, output_Fs, hSpatParamRendCom->num_freq_bands );
352 : }
353 :
354 2243 : test();
355 2243 : test();
356 2243 : test();
357 2243 : IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) && EQ_16( nchan_transport, 2 ) )
358 : {
359 136 : test();
360 136 : test();
361 136 : IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->masa_stereo_type_detect == NULL ) || EQ_16( flag_config, DIRAC_OPEN ) )
362 : {
363 82 : IF( ( hDirACRend->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL )
364 : {
365 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
366 : }
367 : }
368 136 : ivas_masa_init_stereotype_detection_fx( hDirACRend->masa_stereo_type_detect );
369 : }
370 : ELSE
371 : {
372 2107 : test();
373 2107 : IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->masa_stereo_type_detect != NULL )
374 : {
375 24 : free( hDirACRend->masa_stereo_type_detect );
376 : }
377 2107 : hDirACRend->masa_stereo_type_detect = NULL;
378 : }
379 :
380 2243 : hSpatParamRendCom->numIsmDirections = 0; /* By default, no ism directions, set correct number runtime when needed */
381 2243 : move16();
382 :
383 : /*-----------------------------------------------------------------*
384 : * (re)configure sub-modules
385 : *-----------------------------------------------------------------*/
386 :
387 : /* prototype signal computation */
388 2243 : IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) )
389 : {
390 1840 : num_outputs_dir_old = hDirACRend->num_outputs_dir;
391 1840 : move16();
392 1840 : num_outputs_diff_old = hDirACRend->num_outputs_diff;
393 1840 : move16();
394 1840 : num_protos_diff_old = hDirACRend->num_protos_diff;
395 1840 : move16();
396 : }
397 :
398 : /* allocate output setup related arrays */
399 2243 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
400 : {
401 : /* Directional and diffuses components in output LS format */
402 876 : hDirACRend->num_outputs_diff = nchan_out_woLFE;
403 876 : move16();
404 876 : hDirACRend->num_outputs_dir = nchan_out_woLFE;
405 876 : move16();
406 : }
407 1367 : ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
408 : {
409 : /* Directional and diffuses components in SHD */
410 : /* Diffuseness components up to 1st order */
411 852 : hDirACRend->num_outputs_diff = mult0( ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ), ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ) );
412 852 : move16();
413 852 : hDirACRend->num_outputs_dir = ivas_sba_get_nchan_fx( hDirACRend->hOutSetup.ambisonics_order, 0 );
414 852 : move16();
415 : }
416 515 : ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) )
417 : {
418 406 : hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS;
419 406 : move16();
420 406 : hDirACRend->num_outputs_dir = nchan_out_woLFE;
421 406 : move16();
422 : }
423 109 : ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
424 : {
425 109 : hDirACRend->num_outputs_diff = 1; /* There is one output channel in mono */
426 109 : move16();
427 109 : hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */
428 109 : move16();
429 : }
430 : ELSE
431 : {
432 0 : assert( 0 && "DirAC: not existing synthesis methods!" );
433 : }
434 :
435 2243 : IF( EQ_16( flag_config, DIRAC_OPEN ) )
436 : {
437 403 : num_outputs_dir_old = hDirACRend->num_outputs_dir;
438 403 : move16();
439 403 : IF( ( hDirACRend->proto_index_dir = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL )
440 : {
441 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
442 : }
443 403 : num_outputs_diff_old = hDirACRend->num_outputs_diff;
444 403 : move16();
445 403 : IF( ( hDirACRend->proto_index_diff = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_diff ) ) == NULL )
446 : {
447 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
448 : }
449 : }
450 :
451 2243 : test();
452 2243 : IF( NE_16( hDirACRend->num_outputs_dir, num_outputs_dir_old ) && EQ_16( flag_config, DIRAC_RECONFIGURE ) )
453 : {
454 61 : free( hDirACRend->proto_index_dir );
455 61 : IF( ( hDirACRend->proto_index_dir = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL )
456 : {
457 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
458 : }
459 : }
460 2243 : set16_fx( hDirACRend->proto_index_dir, 0, hDirACRend->num_outputs_dir );
461 :
462 2243 : test();
463 2243 : IF( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) && EQ_16( flag_config, DIRAC_RECONFIGURE ) )
464 : {
465 61 : free( hDirACRend->proto_index_diff );
466 61 : IF( ( hDirACRend->proto_index_diff = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_diff ) ) == NULL )
467 : {
468 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
469 : }
470 : }
471 2243 : set16_fx( hDirACRend->proto_index_diff, 0, hDirACRend->num_outputs_diff );
472 :
473 2243 : hDirACRend->sba_map_tc = sba_map_tc;
474 :
475 2243 : test();
476 2243 : IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) || ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
477 : {
478 895 : test();
479 895 : if ( GT_16( st_ivas->sba_order, SBA_FOA_ORDER ) && GE_32( ivas_total_brate, IVAS_512k ) )
480 : {
481 59 : hDirACRend->sba_map_tc = sba_map_tc_512;
482 : }
483 : }
484 :
485 2243 : IF( EQ_16( nchan_transport, 1 ) )
486 : {
487 480 : hDirACRend->num_protos_ambi = 1;
488 480 : move16();
489 480 : hDirACRend->num_protos_dir = 1;
490 480 : move16();
491 480 : hDirACRend->num_protos_diff = 1;
492 480 : move16();
493 : }
494 1763 : ELSE IF( EQ_16( nchan_transport, 2 ) )
495 : {
496 868 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
497 : {
498 0 : hDirACRend->num_protos_ambi = 2;
499 0 : move16();
500 0 : hDirACRend->num_protos_diff = 1;
501 0 : move16();
502 0 : hDirACRend->num_protos_dir = 2;
503 0 : move16();
504 0 : hDirACRend->proto_index_dir[1] = 1;
505 0 : move16();
506 : }
507 868 : ELSE IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) )
508 : {
509 : /* Following the foa rendering for code compatibility */
510 109 : hDirACRend->num_protos_ambi = 2;
511 109 : move16();
512 109 : hDirACRend->num_protos_dir = 2;
513 109 : move16();
514 109 : hDirACRend->num_protos_diff = 3;
515 109 : move16();
516 109 : hDirACRend->proto_index_dir[0] = 0;
517 109 : move16();
518 109 : hDirACRend->proto_index_diff[0] = 0;
519 109 : move16();
520 : }
521 : ELSE
522 : {
523 759 : hDirACRend->num_protos_ambi = 2;
524 759 : move16();
525 759 : hDirACRend->num_protos_diff = 3;
526 759 : move16();
527 :
528 6820 : FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ )
529 : {
530 6061 : IF( ls_azimuth_fx[k] > 0 )
531 : {
532 2813 : hDirACRend->proto_index_diff[k] = 1;
533 2813 : move16();
534 : }
535 3248 : ELSE IF( ls_azimuth_fx[k] < 0 )
536 : {
537 2813 : hDirACRend->proto_index_diff[k] = 2;
538 2813 : move16();
539 : }
540 : ELSE
541 : {
542 435 : hDirACRend->proto_index_diff[k] = 0;
543 435 : move16();
544 : }
545 : }
546 :
547 759 : IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
548 : {
549 460 : hDirACRend->num_protos_dir = 3;
550 460 : move16();
551 460 : Copy( hDirACRend->proto_index_diff, hDirACRend->proto_index_dir, nchan_out_woLFE );
552 : }
553 : ELSE
554 : {
555 299 : hDirACRend->num_protos_dir = 2;
556 299 : move16();
557 299 : hDirACRend->proto_index_dir[1] = 1;
558 299 : move16();
559 : }
560 : }
561 : }
562 : ELSE /* nchan_transport > 2 */
563 : {
564 895 : hDirACRend->num_protos_ambi = 4;
565 895 : move16();
566 895 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
567 : {
568 46 : hDirACRend->num_protos_diff = hDirACRend->num_outputs_diff;
569 46 : move16();
570 547 : FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ )
571 : {
572 501 : hDirACRend->proto_index_diff[k] = k;
573 501 : move16();
574 : }
575 :
576 46 : hDirACRend->num_protos_dir = hDirACRend->num_outputs_dir;
577 46 : move16();
578 547 : FOR( k = 0; k < hDirACRend->num_outputs_dir; k++ )
579 : {
580 501 : hDirACRend->proto_index_dir[k] = k;
581 501 : move16();
582 : }
583 : }
584 : ELSE
585 : {
586 849 : hDirACRend->num_protos_diff = 1;
587 849 : move16();
588 849 : hDirACRend->num_protos_dir = nchan_transport;
589 849 : move16();
590 :
591 4974 : FOR( k = 0; k < s_min( hDirACRend->num_outputs_dir, hDirACRend->num_protos_dir ); k++ )
592 : {
593 4125 : if ( LT_16( hDirACRend->sba_map_tc[k], hDirACRend->num_outputs_dir ) )
594 : {
595 4125 : hDirACRend->proto_index_dir[hDirACRend->sba_map_tc[k]] = k;
596 4125 : move16();
597 : }
598 : }
599 : }
600 : }
601 :
602 2243 : test();
603 : /* direct/diffuse responses */
604 2243 : IF( EQ_16( flag_config, DIRAC_OPEN ) )
605 : {
606 403 : IF( ( hDirACRend->diffuse_response_function_fx = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL )
607 : {
608 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
609 : }
610 : }
611 : /* reallocate static memory */
612 1840 : ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && NE_16( hDirACRend->num_outputs_dir, num_outputs_dir_old ) )
613 : {
614 61 : free( hDirACRend->diffuse_response_function_fx );
615 61 : hDirACRend->diffuse_response_function_fx = NULL;
616 61 : IF( ( hDirACRend->diffuse_response_function_fx = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL )
617 : {
618 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
619 : }
620 : }
621 :
622 2243 : test();
623 2243 : test();
624 2243 : IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) || ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) || ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) )
625 : {
626 1391 : initDiffuseResponses_fx( hDirACRend->diffuse_response_function_fx, nchan_out_woLFE, hDirACRend->hOutSetup.output_config,
627 1391 : hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, st_ivas->transport_config );
628 : }
629 : ELSE
630 : {
631 852 : initDiffuseResponses_fx( hDirACRend->diffuse_response_function_fx, hDirACRend->num_outputs_dir, IVAS_AUDIO_CONFIG_FOA,
632 852 : hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, IVAS_AUDIO_CONFIG_INVALID );
633 : }
634 :
635 2243 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) )
636 : {
637 406 : test();
638 406 : test();
639 406 : IF( EQ_16( flag_config, DIRAC_OPEN ) )
640 : {
641 9 : IF( ( hDirACRend->hoa_encoder_fx = (Word32 *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL )
642 : {
643 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
644 : }
645 : }
646 397 : ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->hoa_encoder_fx && ( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) ) )
647 : {
648 0 : free( hDirACRend->hoa_encoder_fx );
649 0 : hDirACRend->hoa_encoder_fx = NULL;
650 0 : IF( ( hDirACRend->hoa_encoder_fx = (Word32 *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL )
651 : {
652 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
653 : }
654 : }
655 406 : set32_fx( hDirACRend->hoa_encoder_fx, 0, nchan_out_woLFE * hDirACRend->num_outputs_diff );
656 406 : compute_hoa_encoder_mtx_fx( ls_azimuth_fx, ls_elevation_fx, hDirACRend->hoa_encoder_fx, hDirACRend->num_outputs_diff, hDirACRend->hOutSetup.ambisonics_order );
657 : }
658 : ELSE
659 : {
660 1837 : test();
661 1837 : IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->hoa_encoder_fx )
662 : {
663 0 : free( hDirACRend->hoa_encoder_fx );
664 : }
665 1837 : hDirACRend->hoa_encoder_fx = NULL;
666 : }
667 :
668 : /* VBAP */
669 2243 : if ( EQ_16( flag_config, DIRAC_OPEN ) )
670 : {
671 403 : st_ivas->hVBAPdata = NULL;
672 : }
673 :
674 2243 : test();
675 2243 : IF( EQ_32( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) )
676 : {
677 876 : test();
678 876 : IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL )
679 : {
680 718 : vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
681 : }
682 876 : IF( NE_32( ( error = vbap_init_data_fx( &( st_ivas->hVBAPdata ), ls_azimuth_fx, ls_elevation_fx, nchan_out_woLFE, st_ivas->ivas_format ) ), IVAS_ERR_OK ) )
683 : {
684 0 : return error;
685 : }
686 : }
687 1367 : ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
688 : {
689 109 : test();
690 109 : IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL )
691 : {
692 0 : vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
693 : }
694 109 : hDirACRend->hoa_decoder = NULL;
695 : }
696 1258 : ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL )
697 : {
698 24 : vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
699 : }
700 :
701 : /* HOA panning/dec */
702 2243 : IF( EQ_16( flag_config, DIRAC_OPEN ) )
703 : {
704 403 : hDirACRend->hoa_decoder = NULL;
705 403 : test();
706 403 : test();
707 403 : IF( ( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) ) || EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || ( GT_16( nchan_transport, 2 ) ) )
708 : {
709 272 : IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
710 : {
711 70 : IF( st_ivas->hoa_dec_mtx != NULL )
712 : {
713 50 : free( st_ivas->hoa_dec_mtx );
714 50 : st_ivas->hoa_dec_mtx = NULL;
715 : }
716 70 : IF( NE_32( ( error = ivas_sba_get_hoa_dec_matrix_fx( hDirACRend->hOutSetup, &st_ivas->hoa_dec_mtx, hDirACRend->hOutSetup.ambisonics_order ) ), IVAS_ERR_OK ) )
717 : {
718 0 : return error;
719 : }
720 :
721 70 : hDirACRend->hoa_decoder = st_ivas->hoa_dec_mtx;
722 : }
723 : }
724 : }
725 :
726 : /* decorrelation */
727 2243 : IF( flag_config == DIRAC_RECONFIGURE )
728 : {
729 1840 : proto_signal_decorr_on_old = hDirACRend->proto_signal_decorr_on;
730 1840 : move16();
731 : }
732 : ELSE
733 : {
734 403 : proto_signal_decorr_on_old = 0;
735 403 : move16();
736 : }
737 2243 : hDirACRend->proto_signal_decorr_on = 1;
738 2243 : move16();
739 2243 : test();
740 2243 : if ( ( GT_16( nchan_transport, 2 ) ) && ( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) ) )
741 : {
742 : /*switch off decorrelation for 4 transport channels*/
743 46 : hDirACRend->proto_signal_decorr_on = 0;
744 46 : move16();
745 : }
746 2243 : if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
747 : {
748 109 : hDirACRend->proto_signal_decorr_on = 0;
749 109 : move16();
750 : }
751 :
752 2243 : test();
753 2243 : test();
754 2243 : test();
755 2243 : test();
756 2243 : test();
757 2243 : test();
758 2243 : test();
759 2243 : test();
760 2243 : IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirACRend->proto_signal_decorr_on ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) )
761 369 : {
762 : Word16 nchan_transport_tmp;
763 369 : IF( GT_16( nchan_transport, 2 ) )
764 : {
765 226 : nchan_transport_tmp = 4;
766 226 : move16();
767 : }
768 : ELSE
769 : {
770 143 : nchan_transport_tmp = nchan_transport;
771 143 : move16();
772 : }
773 369 : IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff,
774 : hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport_tmp, output_Fs ) ),
775 : IVAS_ERR_OK ) )
776 : {
777 0 : return error;
778 : }
779 : }
780 1874 : ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( !hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) )
781 : {
782 24 : ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state );
783 : }
784 1850 : ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old )
785 : {
786 1719 : test();
787 1719 : test();
788 1719 : IF( NE_16( nchan_transport, nchan_transport_old ) || NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) || EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) )
789 : {
790 : Word16 nchan_transport_tmp;
791 1719 : IF( GT_16( nchan_transport, 2 ) )
792 : {
793 623 : nchan_transport_tmp = 4;
794 623 : move16();
795 : }
796 : ELSE
797 : {
798 1096 : nchan_transport_tmp = nchan_transport;
799 1096 : move16();
800 : }
801 :
802 : /* close and reopen the decorrelator */
803 1719 : ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state );
804 :
805 1719 : IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff,
806 : hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport_tmp, output_Fs ) ),
807 : IVAS_ERR_OK ) )
808 : {
809 0 : return error;
810 : }
811 : }
812 : }
813 :
814 : /* output synthesis */
815 2243 : test();
816 2243 : test();
817 2243 : IF( EQ_16( flag_config, DIRAC_OPEN ) )
818 : {
819 403 : IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ), IVAS_ERR_OK ) )
820 : {
821 0 : return error;
822 : }
823 403 : hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on;
824 403 : move16();
825 : }
826 1840 : ELSE IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) ) && ( ( NE_16( nchan_transport, nchan_transport_old ) ) || ( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) ) ) )
827 : {
828 1817 : ivas_dirac_dec_output_synthesis_close_fx( hDirACRend );
829 :
830 1817 : IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ), IVAS_ERR_OK ) )
831 : {
832 0 : return error;
833 : }
834 1817 : hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on;
835 1817 : move16();
836 : }
837 :
838 2243 : test();
839 2243 : if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
840 : {
841 1258 : hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0;
842 1258 : move16();
843 : }
844 :
845 : /*-----------------------------------------------------------------*
846 : * memory allocation
847 : *-----------------------------------------------------------------*/
848 :
849 2243 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
850 : {
851 852 : test();
852 852 : IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx )
853 : {
854 24 : free( hDirACRend->proto_frame_f_fx );
855 : }
856 852 : hDirACRend->proto_frame_f_fx = NULL;
857 : }
858 : ELSE
859 : {
860 1391 : test();
861 1391 : test();
862 1391 : test();
863 1391 : IF( EQ_16( flag_config, DIRAC_OPEN ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx == NULL ) )
864 : {
865 222 : IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL )
866 : {
867 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
868 : }
869 : }
870 1169 : ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( NE_16( hDirACRend->num_protos_diff, num_protos_diff_old ) ) )
871 : {
872 297 : proto_frame_f_old_fx = hDirACRend->proto_frame_f_fx;
873 297 : free( proto_frame_f_old_fx );
874 297 : IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL )
875 : {
876 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
877 : }
878 : }
879 1391 : hDirACRend->proto_frame_f_len = imult1616( 2, imult1616( hDirACRend->num_protos_diff, hSpatParamRendCom->num_freq_bands ) );
880 1391 : move16();
881 : }
882 :
883 2243 : if ( EQ_16( flag_config, DIRAC_OPEN ) )
884 : {
885 403 : hDirACRend->buffer_energy_fx = NULL;
886 : }
887 :
888 2243 : test();
889 2243 : test();
890 2243 : test();
891 2243 : test();
892 2243 : test();
893 2243 : test();
894 2243 : test();
895 2243 : test();
896 2243 : IF( ( EQ_16( flag_config, DIRAC_OPEN ) && EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && ( dec_param_estim_old == FALSE ) ) ) )
897 : {
898 220 : hDirACRend->index_buffer_intensity = 0;
899 220 : move16();
900 880 : FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
901 : {
902 21780 : FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ )
903 : {
904 21120 : IF( ( hDirACRend->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL )
905 : {
906 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
907 : }
908 21120 : set32_fx( hDirACRend->buffer_intensity_real_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
909 : }
910 : }
911 220 : set16_fx( hDirACRend->q_buffer_intensity_real, Q31, DIRAC_NO_COL_AVG_DIFF );
912 220 : IF( hDirACRend->buffer_energy_fx == NULL )
913 : {
914 220 : IF( ( hDirACRend->buffer_energy_fx = (Word32 *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL )
915 : {
916 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
917 : }
918 : }
919 220 : set32_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX );
920 220 : set16_fx( hDirACRend->q_buffer_energy, Q31, DIRAC_NO_COL_AVG_DIFF );
921 : }
922 2023 : ELSE IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == FALSE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( ( hDirAC->hConfig->dec_param_estim == FALSE ) && EQ_16( dec_param_estim_old, TRUE ) ) ) )
923 : {
924 1184 : FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
925 : {
926 29304 : FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ )
927 : {
928 28416 : test();
929 28416 : IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->buffer_intensity_real_fx[i][j] )
930 : {
931 5760 : free( hDirACRend->buffer_intensity_real_fx[i][j] );
932 : }
933 28416 : hDirACRend->buffer_intensity_real_fx[i][j] = NULL;
934 : }
935 : }
936 296 : IF( hDirACRend->buffer_energy_fx != NULL )
937 : {
938 60 : free( hDirACRend->buffer_energy_fx );
939 60 : hDirACRend->buffer_energy_fx = NULL;
940 : }
941 : }
942 : /* output synthesis */
943 2243 : ivas_dirac_dec_output_synthesis_init_fx( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag );
944 :
945 : /* Allocate stack memory */
946 2243 : IF( NE_16( flag_config, DIRAC_OPEN ) )
947 : {
948 1840 : ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) );
949 : }
950 2243 : IF( NE_32( ( error = ivas_dirac_alloc_mem_fx( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ), IVAS_ERR_OK ) )
951 : {
952 0 : return error;
953 : }
954 :
955 2243 : if ( EQ_16( flag_config, DIRAC_OPEN ) )
956 : {
957 403 : st_ivas->hDirACRend = hDirACRend;
958 : }
959 :
960 2243 : return error;
961 : }
962 : /*-------------------------------------------------------------------------
963 : * ivas_dirac_dec_config()
964 : *
965 : * Open or reconfigure decoder DirAC/MASA handle
966 : *-------------------------------------------------------------------------*/
967 4466 : ivas_error ivas_dirac_dec_config_fx(
968 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
969 : const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
970 : )
971 : {
972 : ivas_error error;
973 : Word32 output_Fs;
974 : Word16 hodirac_flag;
975 : Word16 sparfoa_flag;
976 : DIRAC_CONFIG_FLAG dec_config_flag;
977 : DIRAC_CONFIG_FLAG rend_config_flag;
978 : DIRAC_CONFIG_FLAG common_rend_config_flag;
979 : Word16 need_dirac_rend;
980 : Word16 need_parambin;
981 : Word16 dec_param_estim_old;
982 : Word16 dec_param_estim_new;
983 : Word16 num_poses, pos_idx;
984 :
985 4466 : error = IVAS_ERR_OK;
986 4466 : move32();
987 :
988 : /* Solve and setup flags for inits */
989 4466 : IF( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) )
990 : {
991 1116 : dec_config_flag = DIRAC_RECONFIGURE;
992 1116 : move32();
993 : }
994 : ELSE
995 : {
996 3350 : dec_config_flag = flag_config_inp;
997 3350 : move32();
998 : }
999 :
1000 4466 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
1001 4466 : move32();
1002 4466 : hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
1003 4466 : IF( EQ_32( dec_config_flag, DIRAC_RECONFIGURE ) )
1004 : {
1005 3955 : dec_param_estim_old = st_ivas->hDirAC->hConfig->dec_param_estim;
1006 3955 : move16();
1007 : }
1008 : ELSE
1009 : {
1010 511 : dec_param_estim_old = FALSE;
1011 511 : move16();
1012 : }
1013 :
1014 4466 : num_poses = 1;
1015 4466 : move16();
1016 4466 : IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
1017 : {
1018 0 : num_poses = st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses;
1019 0 : move16();
1020 : }
1021 :
1022 4466 : sparfoa_flag = 0;
1023 4466 : move16();
1024 4466 : test();
1025 4466 : test();
1026 4466 : if ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && !hodirac_flag )
1027 : {
1028 0 : sparfoa_flag = 1;
1029 0 : move16();
1030 : }
1031 :
1032 4466 : IF( NE_32( ( error = ivas_dirac_dec_config_internal_fx( st_ivas, dec_config_flag ) ), IVAS_ERR_OK ) )
1033 : {
1034 0 : return error;
1035 : }
1036 :
1037 : /* This is required for parambin */
1038 4466 : test();
1039 4466 : test();
1040 4466 : if ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
1041 : {
1042 2187 : st_ivas->hDirAC->hConfig->dec_param_estim = FALSE;
1043 2187 : move16();
1044 : }
1045 :
1046 4466 : dec_param_estim_new = st_ivas->hDirAC->hConfig->dec_param_estim;
1047 4466 : move16();
1048 :
1049 : /* Setup renderers and meta */
1050 : /* First, free everything if in reconfig and not the active renderer */
1051 4466 : need_parambin = 0;
1052 4466 : move16();
1053 4466 : SWITCH( st_ivas->renderer_type )
1054 : {
1055 2187 : case RENDERER_BINAURAL_PARAMETRIC:
1056 : case RENDERER_BINAURAL_PARAMETRIC_ROOM:
1057 : case RENDERER_STEREO_PARAMETRIC:
1058 2187 : need_parambin = 1;
1059 2187 : move16();
1060 2187 : BREAK;
1061 2279 : default:
1062 2279 : need_parambin = 0;
1063 2279 : move16();
1064 : }
1065 :
1066 4466 : IF( !need_parambin )
1067 : {
1068 2279 : ivas_dirac_dec_close_binaural_data( st_ivas->hDiracDecBin );
1069 : }
1070 :
1071 4466 : need_dirac_rend = 0;
1072 4466 : move16();
1073 4466 : SWITCH( st_ivas->renderer_type )
1074 : {
1075 2243 : case RENDERER_DIRAC:
1076 : case RENDERER_BINAURAL_FASTCONV:
1077 : case RENDERER_BINAURAL_FASTCONV_ROOM:
1078 : case RENDERER_SBA_LINEAR_ENC:
1079 : case RENDERER_SBA_LINEAR_DEC:
1080 : case RENDERER_OSBA_AMBI:
1081 : case RENDERER_OSBA_LS:
1082 2243 : need_dirac_rend = 1;
1083 2243 : move16();
1084 2243 : BREAK;
1085 2223 : default:
1086 2223 : need_dirac_rend = 0;
1087 2223 : move16();
1088 : }
1089 :
1090 4466 : IF( !need_dirac_rend )
1091 : {
1092 2223 : ivas_dirac_rend_close_fx( &st_ivas->hDirACRend );
1093 : }
1094 :
1095 4466 : IF( !sparfoa_flag )
1096 : {
1097 4466 : IF( st_ivas->hSpatParamRendCom == NULL )
1098 : {
1099 511 : common_rend_config_flag = DIRAC_OPEN;
1100 511 : move32();
1101 : }
1102 : ELSE
1103 : {
1104 3955 : common_rend_config_flag = flag_config_inp;
1105 3955 : move32();
1106 : }
1107 :
1108 4466 : IF( NE_32( ( error = ivas_spat_hSpatParamRendCom_config_fx( &st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new,
1109 : st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag, 0 ) ),
1110 : IVAS_ERR_OK ) )
1111 : {
1112 0 : return error;
1113 : }
1114 :
1115 4466 : IF( need_dirac_rend )
1116 : {
1117 2243 : IF( st_ivas->hDirACRend == NULL )
1118 : {
1119 403 : rend_config_flag = DIRAC_OPEN;
1120 403 : move32();
1121 : }
1122 : ELSE
1123 : {
1124 1840 : rend_config_flag = flag_config_inp;
1125 1840 : move32();
1126 : }
1127 2243 : IF( NE_32( ( error = ivas_dirac_rend_config_fx( st_ivas, rend_config_flag, dec_param_estim_old ) ), IVAS_ERR_OK ) )
1128 : {
1129 0 : return error;
1130 : }
1131 : }
1132 :
1133 4466 : IF( need_parambin )
1134 : {
1135 2187 : IF( NE_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
1136 : {
1137 1522 : IF( NE_32( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) )
1138 : {
1139 0 : return error;
1140 : }
1141 : }
1142 :
1143 2187 : IF( st_ivas->hDiracDecBin[0] == NULL )
1144 : {
1145 : #ifdef NONBE_FIX_991_PARAMBIN_BINARY_HRTF
1146 364 : IF( NE_32( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, &( st_ivas->hHrtfParambin ) ) ), IVAS_ERR_OK ) )
1147 : #else
1148 : IF( NE_32( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) )
1149 : #endif
1150 : {
1151 0 : return error;
1152 : }
1153 : }
1154 : ELSE
1155 : {
1156 : /* This is required to keep BE in rate switching. This probably means that 1TC and 2TC MASA perform differently. */
1157 1823 : test();
1158 1823 : test();
1159 1823 : IF( st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_params != NULL && !( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && st_ivas->nSCE > 0 ) )
1160 : {
1161 796 : ivas_dirac_dec_decorr_close_fx( &st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_state ); // done
1162 : }
1163 :
1164 1823 : IF( NE_32( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin[0]->hTdDecorr ), &( st_ivas->hDiracDecBin[0]->useTdDecorr ) ) ), IVAS_ERR_OK ) )
1165 : {
1166 0 : return error;
1167 : }
1168 :
1169 : /* copy td-decorr flag to split renderer side rendereres */
1170 1823 : FOR( pos_idx = 1; pos_idx < num_poses; pos_idx++ )
1171 : {
1172 0 : st_ivas->hDiracDecBin[pos_idx]->useTdDecorr = st_ivas->hDiracDecBin[0]->useTdDecorr;
1173 : }
1174 :
1175 1823 : IF( !st_ivas->hDiracDecBin[0]->useTdDecorr )
1176 : {
1177 1044 : IF( st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_params == NULL )
1178 : {
1179 : Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX];
1180 :
1181 801 : ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands );
1182 :
1183 801 : IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_params ), &( st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_state ), st_ivas->hSpatParamRendCom->num_freq_bands, BINAURAL_CHANNELS, BINAURAL_CHANNELS,
1184 : DIRAC_SYNTHESIS_PSD_LS, frequency_axis_fx, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs ) ),
1185 : IVAS_ERR_OK ) )
1186 : {
1187 0 : return error;
1188 : }
1189 : }
1190 : }
1191 :
1192 3646 : FOR( pos_idx = 0; pos_idx < num_poses; pos_idx++ )
1193 : {
1194 1823 : st_ivas->hDiracDecBin[pos_idx]->reqularizationFactor_fx = configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate );
1195 1823 : move16();
1196 : }
1197 : }
1198 : }
1199 : }
1200 :
1201 :
1202 4466 : return error;
1203 : }
1204 :
1205 : /*-------------------------------------------------------------------------
1206 : * ivas_dirac_dec_close()
1207 : *
1208 : * Close DirAC memories
1209 : *------------------------------------------------------------------------*/
1210 1058 : void ivas_dirac_dec_close_fx(
1211 : DIRAC_DEC_HANDLE *hDirAC_out )
1212 : {
1213 : DIRAC_DEC_HANDLE hDirAC;
1214 :
1215 1058 : test();
1216 1058 : IF( hDirAC_out == NULL || *hDirAC_out == NULL )
1217 : {
1218 547 : return;
1219 : }
1220 :
1221 511 : hDirAC = *hDirAC_out;
1222 :
1223 : /* Config & CLDFB */
1224 511 : IF( hDirAC->hConfig != NULL )
1225 : {
1226 511 : free( hDirAC->hConfig );
1227 511 : hDirAC->hConfig = NULL;
1228 : }
1229 :
1230 511 : free( *hDirAC_out );
1231 511 : *hDirAC_out = NULL;
1232 :
1233 511 : return;
1234 : }
1235 : /*-------------------------------------------------------------------------
1236 : * ivas_dirac_dec_read_BS_fx()
1237 : *
1238 : * Read DirAC parameters from the bitstream
1239 : *------------------------------------------------------------------------*/
1240 154022 : void ivas_dirac_dec_read_BS_fx(
1241 : const Word32 ivas_total_brate, /* i : IVAS total bitrate */
1242 : Decoder_State *st, /* i/o: decoder state structure */
1243 : DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */
1244 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial rendering data handle */
1245 : IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata */
1246 : Word16 *nb_bits, /* o : number of bits read */
1247 : const Word16 last_bit_pos, /* i : last read bitstream position */
1248 : const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */
1249 : #ifdef NONBE_FIX_1052_SBA_EXT
1250 : const Word16 nchan_transport, /* i : number of transport channels */
1251 : #endif
1252 : Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */
1253 : )
1254 : {
1255 : Word16 i, j, b, dir, orig_dirac_bands;
1256 : Word16 next_bit_pos_orig;
1257 : Word32 quo, rem;
1258 :
1259 154022 : test();
1260 154022 : test();
1261 154022 : IF( !st->bfi && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
1262 : {
1263 145509 : next_bit_pos_orig = st->next_bit_pos;
1264 145509 : move16();
1265 145509 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
1266 145509 : st->next_bit_pos = extract_l( L_sub( quo, 1 ) );
1267 145509 : move16();
1268 145509 : if ( last_bit_pos > 0 )
1269 : {
1270 33885 : st->next_bit_pos = last_bit_pos;
1271 33885 : move16();
1272 : }
1273 : /* 1 bit flag for signaling metadata to read */
1274 145509 : b = st->bit_stream[( st->next_bit_pos )--];
1275 145509 : move16();
1276 145509 : ( *nb_bits )++;
1277 :
1278 145509 : IF( EQ_16( b, 1 ) ) /* WB 4TCs condition, no other metadata to read*/
1279 : {
1280 233 : orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands;
1281 233 : move16();
1282 :
1283 233 : hQMetaData->sba_inactive_mode = 1;
1284 233 : move16();
1285 :
1286 : /* if we start with a SID frame, we need to init the azi/ele arrays.*/
1287 233 : IF( st->ini_frame == 0 )
1288 : {
1289 0 : FOR( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ )
1290 : {
1291 0 : set32_fx( hQMetaData->q_direction[0].band_data[b].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
1292 0 : set32_fx( hQMetaData->q_direction[0].band_data[b].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
1293 : }
1294 : }
1295 :
1296 : #ifdef NONBE_FIX_1052_SBA_EXT
1297 233 : *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), nchan_transport, NULL, SBA_FORMAT ) );
1298 233 : move16();
1299 : #else
1300 : *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT ) );
1301 : move16();
1302 : #endif
1303 1165 : FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
1304 : {
1305 932 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0];
1306 932 : move32();
1307 932 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0];
1308 932 : move32();
1309 932 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[0];
1310 932 : move32();
1311 932 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_index[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio_index[0];
1312 932 : move16();
1313 : }
1314 1165 : FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
1315 : {
1316 2756 : FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- )
1317 : {
1318 1824 : hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0];
1319 1824 : move32();
1320 1824 : hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0];
1321 1824 : move32();
1322 1824 : hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[0];
1323 1824 : move32();
1324 1824 : hQMetaData->q_direction[0].band_data[j].energy_ratio_index[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_index[0];
1325 1824 : move16();
1326 : }
1327 : }
1328 :
1329 233 : hQMetaData->q_direction->cfg.nbands = orig_dirac_bands;
1330 233 : move16();
1331 : }
1332 : ELSE
1333 : {
1334 145276 : hQMetaData->sba_inactive_mode = 0;
1335 145276 : move16();
1336 145276 : hQMetaData->is_masa_ivas_format = 0;
1337 145276 : move16();
1338 145276 : IF( hQMetaData->useLowerRes )
1339 : {
1340 11127 : hQMetaData->q_direction[0].cfg.nblocks = 1;
1341 11127 : move16();
1342 : }
1343 : ELSE
1344 : {
1345 134149 : hQMetaData->q_direction[0].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES;
1346 134149 : move16();
1347 : }
1348 145276 : *nb_bits = add( *nb_bits, ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), hodirac_flag ) );
1349 145276 : move16();
1350 : }
1351 :
1352 145509 : st->next_bit_pos = next_bit_pos_orig;
1353 145509 : move16();
1354 : }
1355 8513 : ELSE IF( !st->bfi && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
1356 : {
1357 324 : next_bit_pos_orig = st->next_bit_pos;
1358 324 : move16();
1359 :
1360 : /* subtract mode signaling bits, since bitstream was moved after mode reading */
1361 324 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
1362 : #ifdef NONBE_FIX_1052_SBA_EXT
1363 324 : st->next_bit_pos = extract_l( L_sub( L_sub( quo, 1 ), SID_FORMAT_NBITS + SBA_PLANAR_BITS + SBA_ORDER_BITS ) );
1364 : #else
1365 : st->next_bit_pos = extract_l( L_sub( L_sub( quo, 1 ), SID_FORMAT_NBITS ) );
1366 : #endif
1367 :
1368 324 : move16();
1369 : /* 1 bit flag for signaling metadata to read */
1370 324 : b = st->bit_stream[( st->next_bit_pos )--];
1371 324 : move16();
1372 324 : ( *nb_bits )++;
1373 324 : hQMetaData->sba_inactive_mode = 1;
1374 324 : move16();
1375 324 : orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands;
1376 324 : move16();
1377 :
1378 : /* if we start with a SID frame, we need to init the azi/ele arrays.*/
1379 324 : IF( st->ini_frame == 0 )
1380 : {
1381 0 : FOR( dir = 0; dir < hQMetaData->no_directions; dir++ )
1382 : {
1383 0 : FOR( b = 0; b < hQMetaData->q_direction[dir].cfg.nbands; b++ )
1384 : {
1385 0 : set32_fx( hQMetaData->q_direction[dir].band_data[b].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
1386 0 : set32_fx( hQMetaData->q_direction[dir].band_data[b].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
1387 : }
1388 : }
1389 : }
1390 : #ifdef NONBE_FIX_1052_SBA_EXT
1391 324 : *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), nchan_transport, NULL, SBA_FORMAT ) );
1392 324 : move16();
1393 : #else
1394 : *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT ) );
1395 : move16();
1396 : #endif
1397 :
1398 1620 : FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
1399 : {
1400 1296 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0];
1401 1296 : move32();
1402 1296 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0];
1403 1296 : move32();
1404 1296 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[0];
1405 1296 : move32();
1406 1296 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_index[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio_index[0];
1407 1296 : move16();
1408 : }
1409 1620 : FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
1410 : {
1411 3840 : FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- )
1412 : {
1413 2544 : hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0];
1414 2544 : move32();
1415 2544 : hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0];
1416 2544 : move32();
1417 2544 : hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[0];
1418 2544 : move32();
1419 2544 : hQMetaData->q_direction[0].band_data[j].energy_ratio_index[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_index[0];
1420 2544 : move16();
1421 : }
1422 : }
1423 :
1424 324 : hQMetaData->q_direction->cfg.nbands = orig_dirac_bands;
1425 324 : move16();
1426 :
1427 324 : st->next_bit_pos = next_bit_pos_orig;
1428 324 : move16();
1429 : }
1430 :
1431 154022 : test();
1432 154022 : IF( hDirAC != NULL && hSpatParamRendCom != NULL )
1433 : {
1434 99102 : ivas_qmetadata_to_dirac_fx( hQMetaData, hDirAC, NULL, hSpatParamRendCom, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands );
1435 : }
1436 :
1437 154022 : return;
1438 : }
1439 : /*-----------------------------------------------------------------------*
1440 : * ivas_qmetadata_to_dirac()
1441 : *
1442 : * Copy qmetedata to DirAC parameters for rendering
1443 : *-----------------------------------------------------------------------*/
1444 139673 : void ivas_qmetadata_to_dirac_fx(
1445 : const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */
1446 : DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */
1447 : MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */
1448 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
1449 : const Word32 ivas_total_brate, /* i : IVAS total bitrate */
1450 : const IVAS_FORMAT ivas_format, /* i : IVAS format */
1451 : const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */
1452 : Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands Q0*/
1453 : )
1454 : {
1455 : Word16 block, band;
1456 : Word16 *seed_ptr;
1457 : Word16 band_start, band_end, diff_idx;
1458 : Word16 b, ele, azi;
1459 : Word32 azimuth_fx, elevation_fx;
1460 : Word32 diffuseness_fx;
1461 : IVAS_QDIRECTION *q_direction;
1462 : Word16 *band_mapping;
1463 : Word16 *band_grouping;
1464 : Word16 start_band;
1465 139673 : Word16 nbands = 0;
1466 139673 : move16();
1467 139673 : Word16 nblocks = 0;
1468 139673 : move16();
1469 : Word16 qBand_idx;
1470 139673 : Word16 idx_sec = 0;
1471 139673 : move16();
1472 139673 : Word16 no_secs = 1;
1473 139673 : move16();
1474 139673 : q_direction = &( hQMetaData->q_direction[0] );
1475 :
1476 139673 : hSpatParamRendCom->numParametricDirections = hQMetaData->no_directions;
1477 139673 : move16();
1478 139673 : hSpatParamRendCom->numSimultaneousDirections = add( hSpatParamRendCom->numParametricDirections, hSpatParamRendCom->numIsmDirections );
1479 139673 : move16();
1480 139673 : test();
1481 139673 : IF( hMasa != NULL && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
1482 39429 : {
1483 : Word16 meta_write_index;
1484 39429 : band_mapping = hMasa->data.band_mapping;
1485 39429 : move16();
1486 :
1487 197145 : FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
1488 : {
1489 157716 : meta_write_index = add( hSpatParamRendCom->dirac_bs_md_write_idx, block ) % hSpatParamRendCom->dirac_md_buffer_length;
1490 :
1491 1345076 : FOR( band = 0; band < hMasa->config.numCodingBands; ++band )
1492 : {
1493 9964160 : FOR( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b )
1494 : {
1495 : /* Right shifting -1 -> -1, Hence this change is done */
1496 8776800 : Word32 L_tmp = L_abs( q_direction->band_data[band].azimuth_fx[block] );
1497 8776800 : hSpatParamRendCom->azimuth[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
1498 8776800 : move16();
1499 :
1500 8776800 : IF( q_direction->band_data[band].azimuth_fx[block] < 0 )
1501 : {
1502 4663322 : hSpatParamRendCom->azimuth[meta_write_index][b] = negate( hSpatParamRendCom->azimuth[meta_write_index][b] );
1503 4663322 : move16();
1504 : }
1505 :
1506 8776800 : L_tmp = L_abs( q_direction->band_data[band].elevation_fx[block] );
1507 8776800 : hSpatParamRendCom->elevation[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
1508 8776800 : move16();
1509 :
1510 8776800 : IF( q_direction->band_data[band].elevation_fx[block] < 0 )
1511 : {
1512 2783308 : hSpatParamRendCom->elevation[meta_write_index][b] = negate( hSpatParamRendCom->elevation[meta_write_index][b] );
1513 2783308 : move16();
1514 : }
1515 :
1516 8776800 : hSpatParamRendCom->energy_ratio1_fx[meta_write_index][b] = q_direction->band_data[band].energy_ratio_fx[block];
1517 8776800 : move32();
1518 8776800 : hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_sub( ONE_IN_Q30, q_direction->band_data[band].energy_ratio_fx[block] );
1519 8776800 : move32();
1520 :
1521 8776800 : IF( q_direction->coherence_band_data != NULL )
1522 : {
1523 5085120 : hSpatParamRendCom->spreadCoherence_fx[meta_write_index][b] = ivas_divde_255[q_direction->coherence_band_data[band].spread_coherence[block]];
1524 5085120 : move16();
1525 : }
1526 : ELSE
1527 : {
1528 3691680 : hSpatParamRendCom->spreadCoherence_fx[meta_write_index][b] = 0;
1529 3691680 : move16();
1530 : }
1531 :
1532 8776800 : IF( hQMetaData->surcoh_band_data != NULL )
1533 : {
1534 5085120 : hSpatParamRendCom->surroundingCoherence_fx[meta_write_index][b] = ivas_divde_255[hQMetaData->surcoh_band_data[band].surround_coherence[block]]; /*q15*/
1535 5085120 : move16();
1536 : }
1537 : ELSE
1538 : {
1539 3691680 : hSpatParamRendCom->surroundingCoherence_fx[meta_write_index][b] = 0;
1540 3691680 : move16();
1541 : }
1542 : }
1543 : }
1544 : }
1545 :
1546 39429 : test();
1547 39429 : test();
1548 39429 : test();
1549 39429 : IF( EQ_32( hQMetaData->no_directions, 2 ) )
1550 : {
1551 3472 : q_direction = &( hQMetaData->q_direction[1] );
1552 17360 : FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
1553 : {
1554 13888 : meta_write_index = ( add( hSpatParamRendCom->dirac_bs_md_write_idx, block ) ) % hSpatParamRendCom->dirac_md_buffer_length;
1555 :
1556 193320 : FOR( band = 0; band < hMasa->config.numCodingBands; ++band )
1557 : {
1558 951512 : FOR( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b )
1559 : {
1560 : /* Right shifting -1 -> -1, Hence this change is done */
1561 772080 : Word32 L_tmp = L_abs( q_direction->band_data[band].azimuth_fx[block] );
1562 772080 : hSpatParamRendCom->azimuth2[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
1563 772080 : move16();
1564 772080 : IF( q_direction->band_data[band].azimuth_fx[block] < 0 )
1565 : {
1566 179382 : hSpatParamRendCom->azimuth2[meta_write_index][b] = negate( hSpatParamRendCom->azimuth2[meta_write_index][b] );
1567 179382 : move16();
1568 : }
1569 :
1570 772080 : L_tmp = L_abs( q_direction->band_data[band].elevation_fx[block] );
1571 772080 : hSpatParamRendCom->elevation2[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
1572 772080 : move16();
1573 772080 : IF( q_direction->band_data[band].elevation_fx[block] < 0 )
1574 : {
1575 38678 : hSpatParamRendCom->elevation2[meta_write_index][b] = negate( hSpatParamRendCom->elevation2[meta_write_index][b] );
1576 38678 : move16();
1577 : }
1578 :
1579 772080 : hSpatParamRendCom->energy_ratio2_fx[meta_write_index][b] = q_direction->band_data[band].energy_ratio_fx[block];
1580 772080 : move32();
1581 772080 : hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_sub( hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b], q_direction->band_data[band].energy_ratio_fx[block] );
1582 772080 : move32();
1583 :
1584 : /* Sanitize diffuseness for rare cases where floating point inaccuracy could result in negative diffuseness. */
1585 772080 : if ( hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] < 0 )
1586 : {
1587 0 : hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = 0;
1588 0 : move32();
1589 : }
1590 :
1591 772080 : IF( q_direction->coherence_band_data != NULL )
1592 : {
1593 772080 : hSpatParamRendCom->spreadCoherence2_fx[meta_write_index][b] = ivas_divde_255[q_direction->coherence_band_data[band].spread_coherence[block]];
1594 772080 : move16();
1595 : }
1596 : ELSE
1597 : {
1598 0 : hSpatParamRendCom->spreadCoherence2_fx[meta_write_index][b] = 0;
1599 0 : move16();
1600 : }
1601 : }
1602 : }
1603 : }
1604 : }
1605 35957 : ELSE IF( hSpatParamRendCom->azimuth2 != NULL && hSpatParamRendCom->elevation2 != NULL && hSpatParamRendCom->energy_ratio2_fx != NULL && hSpatParamRendCom->spreadCoherence2_fx != NULL )
1606 : {
1607 : /* zero out old dir2 data */
1608 135290 : FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
1609 : {
1610 108232 : meta_write_index = add( hSpatParamRendCom->dirac_bs_md_write_idx, block ) % hSpatParamRendCom->dirac_md_buffer_length;
1611 108232 : set16_fx( hSpatParamRendCom->azimuth2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
1612 108232 : set16_fx( hSpatParamRendCom->elevation2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
1613 :
1614 108232 : set32_fx( hSpatParamRendCom->energy_ratio2_fx[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
1615 108232 : set16_fx( hSpatParamRendCom->spreadCoherence2_fx[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
1616 : }
1617 : }
1618 : }
1619 : ELSE /* SBA mode/SID/Zero frame*/
1620 : {
1621 : Word16 tmp_write_idx_param_band;
1622 : Word16 tmp_write_idx_band;
1623 :
1624 100244 : Word32 diffuseness_sec_fx = 0;
1625 100244 : move32();
1626 :
1627 : /* ungroup */
1628 100244 : seed_ptr = &hDirAC->dithering_seed;
1629 100244 : nblocks = q_direction->cfg.nblocks;
1630 100244 : move16();
1631 100244 : nbands = hDirAC->band_grouping[hDirAC->hConfig->nbands];
1632 100244 : move16();
1633 100244 : band_grouping = hDirAC->band_grouping;
1634 :
1635 100244 : test();
1636 100244 : IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_format, SBA_FORMAT ) )
1637 : {
1638 : /* SID/zero-frame: 1 direction, 5 bands, nblocks re-generated out of SID decoder*/
1639 1142 : start_band = 0;
1640 1142 : move16();
1641 1142 : hDirAC->hConfig->nbands = 5;
1642 1142 : move16();
1643 :
1644 1142 : ivas_dirac_config_bands_fx( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, NULL, 0, 0, NULL, 1 );
1645 :
1646 1142 : nbands = 5;
1647 1142 : move16();
1648 : }
1649 : ELSE
1650 : {
1651 99102 : start_band = hDirAC->hConfig->enc_param_start_band;
1652 99102 : move16();
1653 99102 : IF( EQ_32( ivas_format, SBA_FORMAT ) )
1654 : {
1655 99102 : hDirAC->hConfig->nbands = IVAS_MAX_NUM_BANDS;
1656 99102 : move16();
1657 : }
1658 : ELSE
1659 : {
1660 0 : hDirAC->hConfig->nbands = q_direction->cfg.nbands;
1661 0 : move16();
1662 : }
1663 :
1664 99102 : ivas_dirac_config_bands_fx( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hDirAC->hConfig->enc_param_start_band, hDirAC->hFbMdft, 0 );
1665 :
1666 99102 : nbands = hDirAC->hConfig->nbands;
1667 99102 : move16();
1668 99102 : if ( hQMetaData->q_direction[0].cfg.nblocks == 0 )
1669 : {
1670 : /* No transmission -> no copy from qmetadata buffers*/
1671 0 : nbands = start_band;
1672 0 : move16();
1673 : }
1674 : }
1675 :
1676 : /* Low-Bands with no spatial data transmitted, analysis at decoder side */
1677 785388 : FOR( band = 0; band < start_band; band++ )
1678 : {
1679 685144 : band_start = band_grouping[band];
1680 685144 : move16();
1681 685144 : band_end = band_grouping[band + 1];
1682 685144 : move16();
1683 685144 : tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx;
1684 685144 : move16();
1685 :
1686 3425720 : FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
1687 : {
1688 6508868 : FOR( b = band_start; b < band_end; b++ )
1689 : {
1690 3768292 : tmp_write_idx_band = tmp_write_idx_param_band;
1691 3768292 : move16();
1692 :
1693 3768292 : hSpatParamRendCom->spreadCoherence_fx[block][b] = 0;
1694 3768292 : move16();
1695 3768292 : hSpatParamRendCom->surroundingCoherence_fx[block][b] = 0;
1696 3768292 : move16();
1697 3768292 : hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = 0;
1698 3768292 : move32();
1699 3768292 : hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0;
1700 3768292 : move16();
1701 3768292 : hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0;
1702 3768292 : move16();
1703 3768292 : hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0;
1704 3768292 : move32();
1705 3768292 : hSpatParamRendCom->elevation[tmp_write_idx_band][b] = 0;
1706 3768292 : move16();
1707 3768292 : hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = 0;
1708 3768292 : move16();
1709 :
1710 3768292 : tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
1711 : }
1712 : }
1713 : }
1714 :
1715 : /* Bands with spatial data transmitted */
1716 100244 : if ( hodirac_flag )
1717 : {
1718 13459 : no_secs = DIRAC_HO_NUMSECTORS;
1719 13459 : move16();
1720 : }
1721 :
1722 213947 : FOR( idx_sec = 0; idx_sec < no_secs; idx_sec++ )
1723 : {
1724 785001 : FOR( band = start_band; band < nbands; band++ )
1725 : {
1726 671298 : band_start = band_grouping[band];
1727 671298 : move16();
1728 671298 : band_end = band_grouping[band + 1];
1729 671298 : move16();
1730 671298 : tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx;
1731 671298 : move16();
1732 :
1733 671298 : IF( EQ_32( ivas_format, SBA_FORMAT ) )
1734 : {
1735 665588 : qBand_idx = sub( dirac_to_spar_md_bands[band], start_band );
1736 : }
1737 : ELSE
1738 : {
1739 5710 : qBand_idx = band;
1740 5710 : move16();
1741 : }
1742 671298 : diff_idx = q_direction->band_data[qBand_idx].energy_ratio_index[0];
1743 671298 : move16();
1744 :
1745 671298 : diffuseness_fx = L_sub( ONE_IN_Q30, q_direction->band_data[qBand_idx].energy_ratio_fx[0] );
1746 :
1747 3356490 : FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
1748 : {
1749 : Word16 block_qmetadata;
1750 :
1751 2685192 : block_qmetadata = s_min( block, sub( nblocks, 1 ) );
1752 2685192 : block_qmetadata = s_max( block_qmetadata, 0 );
1753 :
1754 :
1755 2685192 : if ( q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] < 0 )
1756 : {
1757 1164967 : q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] = L_add( q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata], 1509949440 /*360.0F in Q22*/ );
1758 1164967 : move32();
1759 : }
1760 :
1761 2685192 : test();
1762 2685192 : IF( hMasa == NULL && hodirac_flag )
1763 : {
1764 1292064 : azimuth_fx = q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata];
1765 1292064 : move32();
1766 1292064 : elevation_fx = q_direction[idx_sec].band_data[qBand_idx].elevation_fx[block_qmetadata];
1767 1292064 : move32();
1768 1292064 : diffuseness_fx = L_sub( ONE_IN_Q30, q_direction[0].band_data[qBand_idx].energy_ratio_fx[block_qmetadata] );
1769 1292064 : diffuseness_sec_fx = q_direction[1].band_data[qBand_idx].energy_ratio_fx[block_qmetadata];
1770 1292064 : move32();
1771 1292064 : assert( diffuseness_sec_fx < 1073849216 /*1.0001f in Q30*/ && diffuseness_sec_fx > -107374 /*-0.0001f in Q30*/ );
1772 : }
1773 : ELSE
1774 : {
1775 1393128 : azimuth_fx = q_direction->band_data[qBand_idx].azimuth_fx[block_qmetadata];
1776 1393128 : move32();
1777 1393128 : elevation_fx = q_direction->band_data[qBand_idx].elevation_fx[block_qmetadata];
1778 1393128 : move32();
1779 : }
1780 21917300 : FOR( b = band_start; b < band_end; b++ )
1781 : {
1782 19232108 : tmp_write_idx_band = tmp_write_idx_param_band;
1783 19232108 : move16();
1784 :
1785 19232108 : IF( hodirac_flag )
1786 : {
1787 6378720 : azi = extract_h( L_shr( ( L_add( azimuth_fx, ONE_IN_Q21 ) ), 6 ) );
1788 6378720 : ele = extract_h( L_shr( ( L_add( elevation_fx, ONE_IN_Q21 ) ), 6 ) );
1789 : /*addition of one to compensate precision loss*/
1790 6378720 : if ( azi < 0 )
1791 : {
1792 0 : azi = add( azi, 1 );
1793 : }
1794 6378720 : if ( ele < 0 )
1795 : {
1796 871188 : ele = add( ele, 1 );
1797 : }
1798 : }
1799 : ELSE
1800 : {
1801 : Word16 a, b_tmp;
1802 :
1803 12853388 : Word16 exp_factor = 0;
1804 12853388 : move16();
1805 12853388 : a = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor
1806 :
1807 12853388 : Word32 tmp1_32 = L_mult( a, dirac_dithering_azi_scale_fx[diff_idx] ); // exp_factor + 5
1808 : Word16 final_1_exp;
1809 : Word32 final_1_32;
1810 12853388 : Word16 norm_op1 = norm_l( azimuth_fx );
1811 12853388 : Word16 norm_op2 = norm_l( tmp1_32 );
1812 12853388 : Word16 op2_e = add( exp_factor, 5 );
1813 12853388 : final_1_exp = add( s_max( s_max( sub( 9, norm_op1 ), sub( op2_e, norm_op2 ) ), 0 ), 2 ); // 2 for headroom
1814 12853388 : final_1_32 = L_add( L_shr( azimuth_fx, sub( final_1_exp, 9 ) ), L_shr( tmp1_32, sub( final_1_exp, op2_e ) ) );
1815 :
1816 12853388 : b_tmp = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor
1817 12853388 : Word32 tmp4_32 = L_mult( b_tmp, dirac_dithering_ele_scale_fx[diff_idx] ); // exp_factor + 4
1818 :
1819 : Word16 final_2_exp;
1820 : Word32 final_2_32;
1821 12853388 : norm_op1 = norm_l( elevation_fx );
1822 12853388 : norm_op2 = norm_l( tmp4_32 );
1823 12853388 : op2_e = add( exp_factor, 4 );
1824 12853388 : final_2_exp = add( s_max( s_max( sub( 9, norm_op1 ), sub( op2_e, norm_op2 ) ), 0 ), 2 ); // 2 for headroom
1825 12853388 : final_2_32 = L_add( L_shr( elevation_fx, sub( final_2_exp, 9 ) ), L_shr( tmp4_32, sub( final_2_exp, op2_e ) ) );
1826 :
1827 12853388 : final_1_32 = L_add( final_1_32, L_shl( 1, sub( 30, final_1_exp ) ) ); /*0.5 in q31*/
1828 12853388 : final_2_32 = L_add( final_2_32, L_shl( 1, sub( 30, final_2_exp ) ) );
1829 12853388 : azi = extract_h( L_shr( final_1_32, sub( 15, final_1_exp ) ) );
1830 12853388 : ele = extract_h( L_shr( final_2_32, sub( 15, final_2_exp ) ) );
1831 :
1832 :
1833 : /*addition of one to compensate precision loss*/
1834 12853388 : if ( azi < 0 )
1835 : {
1836 1358281 : azi = add( azi, 1 );
1837 : }
1838 12853388 : if ( ele < 0 )
1839 : {
1840 4833395 : ele = add( ele, 1 );
1841 : }
1842 : /* limit the elevation to [-90, 90] */
1843 12853388 : ele = s_min( 90, ele );
1844 12853388 : ele = s_max( -90, ele );
1845 : }
1846 :
1847 19232108 : test();
1848 19232108 : IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && q_direction->coherence_band_data != NULL )
1849 : {
1850 0 : hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = ivas_divde_255[q_direction->coherence_band_data[qBand_idx].spread_coherence[block]];
1851 0 : move16();
1852 : }
1853 : ELSE
1854 : {
1855 19232108 : hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0;
1856 19232108 : move16();
1857 : }
1858 :
1859 19232108 : test();
1860 19232108 : IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && q_direction->coherence_band_data != NULL )
1861 : {
1862 0 : hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = ivas_divde_255[hQMetaData->surcoh_band_data[qBand_idx].surround_coherence[0]];
1863 0 : move16();
1864 : }
1865 : ELSE
1866 : {
1867 19232108 : hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0;
1868 19232108 : move16();
1869 : }
1870 :
1871 :
1872 19232108 : hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = q_direction->band_data[qBand_idx].energy_ratio_fx[0];
1873 19232108 : move32();
1874 19232108 : hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx;
1875 19232108 : move32();
1876 :
1877 19232108 : IF( hodirac_flag )
1878 : {
1879 6378720 : IF( idx_sec == 0 )
1880 : {
1881 3189360 : hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele;
1882 3189360 : move16();
1883 3189360 : hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi;
1884 3189360 : move16();
1885 3189360 : hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0;
1886 3189360 : move32();
1887 : }
1888 : ELSE
1889 : {
1890 3189360 : assert( idx_sec == 1 );
1891 3189360 : hSpatParamRendCom->elevation2[tmp_write_idx_band][b] = ele;
1892 3189360 : move16();
1893 3189360 : hSpatParamRendCom->azimuth2[tmp_write_idx_band][b] = azi;
1894 3189360 : move16();
1895 3189360 : hSpatParamRendCom->energy_ratio2_fx[tmp_write_idx_band][b] = L_sub( ONE_IN_Q30, diffuseness_sec_fx );
1896 3189360 : move32();
1897 : }
1898 : }
1899 : ELSE
1900 : {
1901 12853388 : hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele;
1902 12853388 : move16();
1903 12853388 : hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi;
1904 12853388 : move16();
1905 : }
1906 : }
1907 2685192 : tmp_write_idx_param_band = add( tmp_write_idx_param_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
1908 :
1909 :
1910 : } /* for ( block =...) */
1911 : } /* for ( band = ...) */
1912 : } /* for ( idx_sec = ...)*/
1913 :
1914 : /* Bands not transmitted -> zeroed*/
1915 100244 : FOR( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ )
1916 : {
1917 0 : tmp_write_idx_band = hSpatParamRendCom->dirac_bs_md_write_idx;
1918 0 : move16();
1919 :
1920 0 : FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
1921 : {
1922 0 : hSpatParamRendCom->spreadCoherence_fx[block][b] = 0;
1923 0 : move16();
1924 0 : hSpatParamRendCom->surroundingCoherence_fx[block][b] = 0;
1925 0 : move16();
1926 0 : hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = 0;
1927 0 : move32();
1928 0 : hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0;
1929 0 : move16();
1930 0 : hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0;
1931 0 : move16();
1932 0 : hSpatParamRendCom->energy_ratio1_fx[block][b] = 0;
1933 0 : move32();
1934 0 : hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0;
1935 0 : move32();
1936 0 : hSpatParamRendCom->elevation[tmp_write_idx_band][b] = 0;
1937 0 : move16();
1938 0 : hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = 0;
1939 0 : move16();
1940 :
1941 0 : tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
1942 : }
1943 : }
1944 : }
1945 : /* update buffer write index */
1946 139673 : hSpatParamRendCom->dirac_bs_md_write_idx = add( hSpatParamRendCom->dirac_bs_md_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length;
1947 139673 : move16();
1948 139673 : return;
1949 : }
1950 : /*-------------------------------------------------------------------------
1951 : * ivas_dirac_dec_set_md_map()
1952 : *
1953 : * Set metadata index mapping for DirAC
1954 : *------------------------------------------------------------------------*/
1955 0 : void ivas_dirac_dec_set_md_map(
1956 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
1957 : const Word16 nCldfbTs /* i : number of CLDFB time slots */
1958 : )
1959 : {
1960 : Word16 num_slots_in_subfr;
1961 : DIRAC_DEC_HANDLE hDirAC;
1962 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1963 :
1964 0 : hDirAC = st_ivas->hDirAC;
1965 0 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1966 :
1967 : /* adapt subframes */
1968 0 : hSpatParamRendCom->num_slots = nCldfbTs;
1969 0 : move16();
1970 0 : hSpatParamRendCom->slots_rendered = 0;
1971 0 : move16();
1972 0 : num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
1973 0 : move16();
1974 0 : hSpatParamRendCom->subframes_rendered = 0;
1975 0 : move16();
1976 :
1977 0 : ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes );
1978 :
1979 : /* copy also to tc buffer */
1980 : /* only for non-combined formats and combinded formats w/o discrete objects */
1981 0 : test();
1982 0 : test();
1983 0 : test();
1984 0 : IF( ( NE_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) || NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) && !( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) )
1985 : {
1986 0 : st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes;
1987 0 : move16();
1988 0 : Copy( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes );
1989 : }
1990 :
1991 : /* set mapping according to dirac_read_idx */
1992 :
1993 0 : set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
1994 :
1995 0 : test();
1996 0 : test();
1997 0 : IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
1998 : {
1999 0 : ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map );
2000 : }
2001 0 : ELSE IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
2002 : {
2003 0 : ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map );
2004 : }
2005 : ELSE
2006 : {
2007 0 : ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map );
2008 : }
2009 :
2010 0 : test();
2011 0 : test();
2012 0 : IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
2013 : {
2014 : Word64 tmp_fx;
2015 : Word16 sf_idx, slot_idx, slot_idx_abs;
2016 : Word32 quo, rem;
2017 :
2018 0 : slot_idx_abs = 0;
2019 0 : move16();
2020 0 : FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ )
2021 : {
2022 0 : tmp_fx = 0;
2023 0 : move64();
2024 0 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ )
2025 : {
2026 0 : tmp_fx = W_add_nosat( tmp_fx, W_deposit32_l( L_deposit_l( hSpatParamRendCom->render_to_md_map[slot_idx_abs] ) ) );
2027 0 : slot_idx_abs = add( slot_idx_abs, 1 );
2028 : }
2029 0 : iDiv_and_mod_32( W_shl_sat_l( tmp_fx, 16 ), hSpatParamRendCom->subframe_nbslots[sf_idx], &quo, &rem, 0 );
2030 0 : hSpatParamRendCom->render_to_md_map[sf_idx] = add( round_fx( quo ), hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length;
2031 0 : move16();
2032 : }
2033 :
2034 0 : set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) );
2035 : }
2036 :
2037 0 : return;
2038 : }
2039 :
2040 152481 : void ivas_dirac_dec_set_md_map_fx(
2041 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
2042 : const Word16 nCldfbTs /* i : number of CLDFB time slots */
2043 : )
2044 : {
2045 : Word16 num_slots_in_subfr;
2046 : DIRAC_DEC_HANDLE hDirAC;
2047 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
2048 :
2049 152481 : hDirAC = st_ivas->hDirAC;
2050 152481 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
2051 :
2052 : /* adapt subframes */
2053 152481 : hSpatParamRendCom->num_slots = nCldfbTs;
2054 152481 : move16();
2055 152481 : hSpatParamRendCom->slots_rendered = 0;
2056 152481 : move16();
2057 152481 : num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
2058 152481 : move16();
2059 152481 : hSpatParamRendCom->subframes_rendered = 0;
2060 152481 : move16();
2061 :
2062 152481 : ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes );
2063 :
2064 : /* copy also to tc buffer */
2065 : /* only for non-combined formats and combinded formats w/o discrete objects */
2066 152481 : test();
2067 152481 : test();
2068 152481 : test();
2069 152481 : IF( ( NE_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) || NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) && !( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) )
2070 : {
2071 133418 : st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes;
2072 133418 : move16();
2073 133418 : Copy( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes );
2074 : }
2075 :
2076 : /* set mapping according to dirac_read_idx */
2077 :
2078 152481 : set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
2079 :
2080 152481 : test();
2081 152481 : test();
2082 152481 : IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
2083 : {
2084 26832 : ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map );
2085 : }
2086 125649 : ELSE IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
2087 : {
2088 77816 : ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map );
2089 : }
2090 : ELSE
2091 : {
2092 47833 : ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map );
2093 : }
2094 :
2095 152481 : test();
2096 152481 : test();
2097 152481 : IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
2098 : {
2099 : Word16 sf_idx, slot_idx, slot_idx_abs;
2100 : Word32 tmp_fx;
2101 : Word32 num;
2102 : Word16 denom, norm_denom, exp_denom, exp_num, norm_num, exp;
2103 : Word32 ans, ans_fix_32;
2104 : Word16 ans_fix_16, exp_final;
2105 :
2106 104648 : slot_idx_abs = 0;
2107 104648 : move16();
2108 526224 : FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ )
2109 : {
2110 421576 : tmp_fx = 0;
2111 421576 : move32();
2112 2096097 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ )
2113 : {
2114 1674521 : tmp_fx = L_add( tmp_fx, L_deposit_h( hSpatParamRendCom->render_to_md_map[slot_idx_abs] ) );
2115 1674521 : slot_idx_abs = add( slot_idx_abs, 1 );
2116 : }
2117 :
2118 421576 : exp_denom = 15, exp_num = 31;
2119 421576 : move16();
2120 421576 : move16();
2121 421576 : norm_num = norm_l( tmp_fx );
2122 421576 : num = L_shl( tmp_fx, norm_num );
2123 421576 : exp_num = sub( exp_num, norm_num );
2124 :
2125 421576 : norm_denom = norm_s( hSpatParamRendCom->subframe_nbslots[sf_idx] );
2126 421576 : denom = shl( hSpatParamRendCom->subframe_nbslots[sf_idx], norm_denom );
2127 421576 : exp_denom = sub( exp_denom, norm_denom );
2128 :
2129 421576 : exp = sub( exp_num, exp_denom );
2130 :
2131 421576 : IF( GT_32( num, L_deposit_l( denom ) ) )
2132 : {
2133 316914 : num = L_shr( num, 1 );
2134 316914 : exp = add( exp, 1 );
2135 : }
2136 :
2137 421576 : ans = div_l( num, denom );
2138 421576 : ans_fix_32 = BASOP_Util_Add_Mant32Exp( ans, exp, L_deposit_h( hSpatParamRendCom->dirac_read_idx ), 15 /*31 - 16*/, &exp_final );
2139 421576 : ans_fix_16 = round_fx( L_shr( ans_fix_32, sub( sub( Q31, exp_final ), Q16 ) ) );
2140 :
2141 421576 : hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; // Q0
2142 421576 : move16();
2143 : }
2144 104648 : set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) );
2145 : }
2146 :
2147 152481 : return;
2148 : }
2149 : /*-------------------------------------------------------------------------
2150 : * ivas_dirac_dec_render_fx()
2151 : *
2152 : * DirAC decoding renderer process
2153 : *------------------------------------------------------------------------*/
2154 :
2155 20544 : void ivas_dirac_dec_render_fx(
2156 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
2157 : const Word16 nchan_transport, /* i : number of transport channels */
2158 : const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */
2159 : UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */
2160 : UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */
2161 : Word32 *output_fx[] /* o : rendered time signal Q(6-1)*/
2162 : )
2163 : {
2164 : Word16 slots_to_render, first_sf, last_sf, subframe_idx;
2165 : UWord16 slot_size, n_samples_sf, ch, nchan_intern;
2166 20544 : Word16 temp = 0;
2167 20544 : move16();
2168 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
2169 : Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS];
2170 20544 : Word32 output_f_local_buff_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; // VE2SB: TBV
2171 :
2172 20544 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
2173 :
2174 20544 : nchan_intern = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
2175 150991 : FOR( ch = 0; ch < nchan_intern; ch++ )
2176 : {
2177 130447 : output_f_local_fx[ch] = output_f_local_buff_fx[ch];
2178 130447 : set_zero_fx( output_f_local_fx[ch], nSamplesAsked );
2179 : }
2180 20544 : slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // cL
2181 :
2182 :
2183 : /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
2184 20544 : slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) );
2185 :
2186 20544 : *nSamplesRendered = i_mult( slots_to_render, slot_size );
2187 20544 : move16();
2188 :
2189 20544 : first_sf = hSpatParamRendCom->subframes_rendered;
2190 20544 : move16();
2191 20544 : last_sf = first_sf;
2192 20544 : move16();
2193 :
2194 91322 : WHILE( slots_to_render > 0 )
2195 : {
2196 70778 : slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] );
2197 70778 : last_sf = add( last_sf, 1 );
2198 : }
2199 :
2200 91322 : FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
2201 : {
2202 70778 : ivas_dirac_dec_render_sf_fx( st_ivas, output_f_local_fx, nchan_transport, NULL, NULL );
2203 :
2204 70778 : n_samples_sf = i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slot_size );
2205 :
2206 542469 : FOR( ch = 0; ch < nchan_intern; ch++ )
2207 : {
2208 471691 : output_f_local_fx[ch] += n_samples_sf;
2209 : }
2210 :
2211 : /* update combined orientation access index */
2212 70778 : ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
2213 : }
2214 :
2215 150991 : FOR( ch = 0; ch < nchan_intern; ch++ )
2216 : {
2217 130447 : test();
2218 130447 : test();
2219 130447 : IF( !( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ) && ( ( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ) || EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) )
2220 : {
2221 130007 : Copy32( output_f_local_buff_fx[ch], output_fx[ch], *nSamplesRendered );
2222 : }
2223 : }
2224 :
2225 20544 : IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) ){
2226 17504 : IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) ){
2227 0 : temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS );
2228 0 : hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0
2229 : }
2230 : ELSE
2231 : {
2232 17504 : temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS );
2233 17504 : hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0
2234 : }
2235 : }
2236 :
2237 20544 : *nSamplesAvailableNext = i_mult( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), slot_size ); // Q0
2238 20544 : move16();
2239 :
2240 20544 : return;
2241 : }
2242 :
2243 : /*-------------------------------------------------------------------------
2244 : * ivas_dirac_dec_render_sf_fx()
2245 : *
2246 : * DirAC decoding renderer process
2247 : *------------------------------------------------------------------------*/
2248 :
2249 307931 : void ivas_dirac_dec_render_sf_fx(
2250 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
2251 : Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output Q(6-1)*/
2252 : const Word16 nchan_transport, /* i : number of transport channels */
2253 : Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], /*Q6*/
2254 : Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] /*Q6*/
2255 : )
2256 : {
2257 : Word16 i, ch, idx_in, idx_lfe;
2258 : DIRAC_DEC_HANDLE hDirAC;
2259 : DIRAC_REND_HANDLE hDirACRend;
2260 : Word16 subframe_idx;
2261 : Word16 slot_idx, index_slot;
2262 : Word16 hodirac_flag;
2263 : Word16 slot_idx_start, slot_idx_start_cldfb_synth, md_idx;
2264 :
2265 : /*CLDFB: last output channels reserved to LFT for CICPx*/
2266 : Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
2267 : Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
2268 : Word32 Cldfb_RealBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
2269 : Word32 Cldfb_ImagBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
2270 307931 : Word16 index = 0, num_freq_bands = 0;
2271 307931 : move16();
2272 307931 : move16();
2273 :
2274 : /* local copies of azi, ele, diffuseness */
2275 : Word16 azimuth[CLDFB_NO_CHANNELS_MAX];
2276 : Word16 elevation[CLDFB_NO_CHANNELS_MAX];
2277 : Word32 diffuseness_vector_fx[CLDFB_NO_CHANNELS_MAX];
2278 : Word32 *p_Rmat_fx;
2279 : Word32 *reference_power_fx, *reference_power_smooth_fx, *onset_filter_fx, *onset_filter_subframe_fx;
2280 : Word32 dirEne_fx;
2281 : Word32 surCohEner_fx;
2282 : Word32 surCohRatio_fx[CLDFB_NO_CHANNELS_MAX];
2283 307931 : Word16 surCohRatio_q_fx = 0, temp_q = 0;
2284 307931 : move16();
2285 307931 : move16();
2286 : Word32 Cldfb_RealBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2287 : Word32 Cldfb_ImagBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2288 : Word16 cldfb_buf_q;
2289 307931 : Word16 offset = 0, buff_len = 0;
2290 307931 : move16();
2291 307931 : move16();
2292 307931 : Word16 q_cldfb, q_temp_cldfb = 0;
2293 307931 : move16();
2294 307931 : Word16 proto_length = 0;
2295 307931 : move16();
2296 : Word16 q_proto_direct_buffer[CLDFB_SLOTS_PER_SUBFRAME + 1];
2297 : Word16 q_proto_diffuse_buffer[CLDFB_SLOTS_PER_SUBFRAME + 1];
2298 : Word16 size, size_ho;
2299 :
2300 : DIRAC_DEC_STACK_MEM DirAC_mem;
2301 307931 : Word32 *p_onset_filter_fx = NULL;
2302 : UWord16 coherence_flag;
2303 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
2304 307931 : Word16 scale = 0;
2305 307931 : move16();
2306 : DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params;
2307 : DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state;
2308 : Word16 num_channels_dir, exp;
2309 307931 : Word16 q_diffuseness_vector = Q31, q_reference_power_smooth[2] = { Q31, Q31 };
2310 307931 : move16();
2311 307931 : move16();
2312 307931 : move16();
2313 307931 : Word16 proto_power_smooth_len = 0;
2314 307931 : move16();
2315 : Word16 tmp1;
2316 :
2317 307931 : push_wmops( "ivas_dirac_dec_render" );
2318 :
2319 : /* Initialize aux buffers */
2320 5234827 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2321 : {
2322 24634480 : FOR( Word16 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
2323 : {
2324 19707584 : set32_fx( Cldfb_RealBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
2325 19707584 : set32_fx( Cldfb_ImagBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
2326 : }
2327 : }
2328 :
2329 :
2330 307931 : hDirAC = st_ivas->hDirAC;
2331 307931 : hDirACRend = st_ivas->hDirACRend;
2332 307931 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
2333 :
2334 307931 : DirAC_mem = hDirACRend->stack_mem;
2335 :
2336 307931 : reference_power_fx = DirAC_mem.reference_power_fx;
2337 307931 : IF( DirAC_mem.reference_power_fx == NULL )
2338 : {
2339 8651 : reference_power_smooth_fx = NULL;
2340 : }
2341 : ELSE
2342 : {
2343 299280 : reference_power_smooth_fx = DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands;
2344 : }
2345 307931 : onset_filter_fx = DirAC_mem.onset_filter_fx;
2346 307931 : IF( DirAC_mem.onset_filter_fx == NULL )
2347 : {
2348 22217 : onset_filter_subframe_fx = NULL;
2349 : }
2350 : ELSE
2351 : {
2352 285714 : onset_filter_subframe_fx = DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands;
2353 : }
2354 307931 : q_cldfb = Q11;
2355 307931 : move16();
2356 307931 : set16_fx( q_proto_direct_buffer, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME + 1 );
2357 307931 : set16_fx( q_proto_diffuse_buffer, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME + 1 );
2358 307931 : set_zero_fx( surCohRatio_fx, CLDFB_NO_CHANNELS_MAX );
2359 :
2360 307931 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
2361 : {
2362 8217 : IF( hDirACRend->masa_stereo_type_detect )
2363 : {
2364 8217 : hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = 0;
2365 8217 : move32();
2366 8217 : hDirACRend->masa_stereo_type_detect->q_subtract_power_y = Q31;
2367 8217 : move16();
2368 : }
2369 : }
2370 :
2371 307931 : test();
2372 307931 : IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) )
2373 : {
2374 67910 : IF( hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0 )
2375 : {
2376 53910 : DIRAC_OUTPUT_SYNTHESIS_STATE *state = &( hDirACRend->h_output_synthesis_psd_state );
2377 53910 : tmp1 = L_norm_arr( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len );
2378 :
2379 53910 : scale_sig32( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len, tmp1 ); // Q(proto_power_diff_smooth_q + tmp1)
2380 53910 : state->proto_power_diff_smooth_q = add( state->proto_power_diff_smooth_q, tmp1 );
2381 53910 : move16();
2382 : }
2383 : }
2384 :
2385 307931 : h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
2386 307931 : h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
2387 307931 : num_channels_dir = hDirACRend->num_outputs_dir;
2388 307931 : move16();
2389 307931 : hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
2390 307931 : if ( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
2391 : {
2392 55475 : num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE;
2393 55475 : move16();
2394 : }
2395 :
2396 307931 : test();
2397 307931 : test();
2398 307931 : IF( h_dirac_output_synthesis_params->use_onset_filters && ( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) )
2399 : {
2400 41475 : tmp1 = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
2401 41475 : scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( tmp1, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); // tmp1
2402 41475 : h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = tmp1;
2403 41475 : move16();
2404 : }
2405 :
2406 307931 : test();
2407 307931 : IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2408 : {
2409 : Word16 shift;
2410 14000 : shift = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
2411 14000 : scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + shift
2412 14000 : h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, shift );
2413 14000 : move16();
2414 14000 : shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
2415 14000 : scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + shift
2416 14000 : h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, shift );
2417 14000 : move16();
2418 14000 : tmp1 = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
2419 14000 : scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + tmp1
2420 14000 : h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp1 );
2421 14000 : move16();
2422 : }
2423 :
2424 :
2425 307931 : test();
2426 307931 : test();
2427 307931 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
2428 : {
2429 360606 : FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
2430 : {
2431 240404 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11;
2432 240404 : move16();
2433 : }
2434 : }
2435 187729 : ELSE IF( !( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
2436 : {
2437 : Word16 outchannels;
2438 70778 : idx_lfe = 0;
2439 70778 : move16();
2440 70778 : idx_in = 0;
2441 70778 : move16();
2442 70778 : outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
2443 :
2444 70778 : test();
2445 70778 : test();
2446 70778 : test();
2447 70778 : test();
2448 70778 : test();
2449 70778 : test();
2450 70778 : test();
2451 70778 : IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
2452 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
2453 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
2454 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
2455 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
2456 : ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
2457 : {
2458 880 : outchannels = add( outchannels, 1 );
2459 : }
2460 :
2461 70778 : test();
2462 70778 : IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) )
2463 : {
2464 0 : FOR( ch = 0; ch < outchannels; ch++ )
2465 : {
2466 0 : test();
2467 0 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
2468 : {
2469 0 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
2470 : {
2471 0 : idx_lfe = add( idx_lfe, 1 );
2472 : }
2473 : }
2474 : }
2475 : }
2476 : ELSE
2477 : {
2478 542469 : FOR( ch = 0; ch < outchannels; ch++ )
2479 : {
2480 :
2481 471691 : test();
2482 471691 : test();
2483 471691 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
2484 : {
2485 41475 : test();
2486 41475 : IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
2487 : {
2488 : Word16 cldfbSynIdx;
2489 6640 : cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
2490 6640 : st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11;
2491 6640 : move16();
2492 : }
2493 : }
2494 430216 : ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
2495 : {
2496 : }
2497 : ELSE
2498 : {
2499 429336 : st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11;
2500 429336 : move16();
2501 429336 : idx_in = add( idx_in, 1 );
2502 : }
2503 : }
2504 : }
2505 : }
2506 :
2507 307931 : size = imult1616( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands );
2508 307931 : IF( hodirac_flag )
2509 : {
2510 53156 : size_ho = imult1616( size, DIRAC_HO_NUMSECTORS );
2511 : }
2512 : ELSE
2513 : {
2514 254775 : size_ho = size;
2515 254775 : move16();
2516 : }
2517 307931 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26
2518 307931 : hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26;
2519 307931 : move16();
2520 :
2521 307931 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2522 : {
2523 : Word16 shift;
2524 231804 : shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho );
2525 231804 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, shift ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth + shift)
2526 231804 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, shift );
2527 231804 : move16();
2528 :
2529 231804 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); // Q26
2530 231804 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26;
2531 231804 : move16();
2532 :
2533 231804 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); // Q26
2534 231804 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26;
2535 231804 : move16();
2536 :
2537 231804 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); // Q26
2538 231804 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26;
2539 231804 : move16();
2540 : }
2541 : ELSE
2542 : {
2543 : Word16 shift;
2544 76127 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26
2545 76127 : hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26;
2546 76127 : move16();
2547 :
2548 76127 : shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho );
2549 76127 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho, shift ); // Q( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev+ shift)
2550 76127 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, shift );
2551 76127 : move16();
2552 76127 : shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho );
2553 76127 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, shift ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev + shift)
2554 76127 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, shift );
2555 76127 : move16();
2556 76127 : tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ) );
2557 76127 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev+ tmp1)
2558 76127 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, tmp1 );
2559 76127 : move16();
2560 76127 : tmp1 = 31;
2561 76127 : move16();
2562 324131 : FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
2563 : {
2564 248004 : tmp1 = s_min( tmp1, L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + i, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
2565 : }
2566 324131 : FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
2567 : {
2568 248004 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + i, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q tmp1)
2569 : }
2570 76127 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0], tmp1 );
2571 76127 : move16();
2572 76127 : tmp1 = 31;
2573 76127 : move16();
2574 324131 : FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
2575 : {
2576 248004 : tmp1 = s_min( tmp1, L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + CLDFB_NO_CHANNELS_HALF + i, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) ) );
2577 : }
2578 324131 : FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
2579 : {
2580 248004 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + CLDFB_NO_CHANNELS_HALF + i, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q tmp1)
2581 : }
2582 76127 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1], tmp1 );
2583 76127 : move16();
2584 76127 : IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 )
2585 : {
2586 53910 : tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) );
2587 53910 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q+ tmp1)
2588 53910 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, tmp1 );
2589 53910 : move16();
2590 : }
2591 : }
2592 :
2593 307931 : hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
2594 :
2595 307931 : test();
2596 307931 : test();
2597 307931 : IF( st_ivas->hQMetaData != NULL && NE_32( st_ivas->ivas_format, SBA_FORMAT ) && NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
2598 : {
2599 70778 : coherence_flag = st_ivas->hQMetaData->coherence_flag;
2600 70778 : move16();
2601 : }
2602 : ELSE
2603 : {
2604 237153 : coherence_flag = 0;
2605 237153 : move16();
2606 : }
2607 : /* Subframe loop */
2608 307931 : slot_idx_start = hSpatParamRendCom->slots_rendered;
2609 307931 : move16();
2610 307931 : slot_idx_start_cldfb_synth = 0;
2611 307931 : move16();
2612 :
2613 307931 : subframe_idx = hSpatParamRendCom->subframes_rendered;
2614 307931 : move16();
2615 307931 : IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
2616 : {
2617 123934 : md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
2618 123934 : move16();
2619 : }
2620 : ELSE
2621 : {
2622 183997 : md_idx = hSpatParamRendCom->render_to_md_map[slot_idx_start];
2623 183997 : move16();
2624 : }
2625 :
2626 : /* copy parameters into local buffers*/
2627 307931 : IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
2628 : {
2629 123934 : Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands );
2630 123934 : q_diffuseness_vector = Q30;
2631 123934 : move16();
2632 123934 : Copy( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands );
2633 123934 : Copy( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands );
2634 : }
2635 : ELSE
2636 : {
2637 183997 : set32_fx( diffuseness_vector_fx, 0, hSpatParamRendCom->num_freq_bands );
2638 183997 : q_diffuseness_vector = Q31;
2639 183997 : move16();
2640 : }
2641 :
2642 307931 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2643 : {
2644 76127 : set_zero_fx( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands );
2645 : }
2646 : ELSE
2647 : {
2648 231804 : set_zero_fx( onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands );
2649 : }
2650 :
2651 307931 : test();
2652 307931 : IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] )
2653 : {
2654 41400 : p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0];
2655 :
2656 41400 : IF( st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
2657 : {
2658 36800 : num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
2659 36800 : move16();
2660 36800 : IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
2661 : {
2662 0 : rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx );
2663 : }
2664 : }
2665 : }
2666 : ELSE
2667 : {
2668 266531 : p_Rmat_fx = 0;
2669 266531 : move32();
2670 : }
2671 :
2672 307931 : IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
2673 : {
2674 : Word16 *masa_band_mapping;
2675 : /* compute response */
2676 123934 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2677 : {
2678 62127 : ivas_dirac_dec_compute_power_factors_fx( hSpatParamRendCom->num_freq_bands,
2679 : diffuseness_vector_fx,
2680 62127 : hDirACRend->h_output_synthesis_psd_params.max_band_decorr,
2681 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
2682 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx );
2683 :
2684 62127 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q29;
2685 62127 : move16();
2686 62127 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q29;
2687 62127 : move16();
2688 :
2689 62127 : IF( coherence_flag )
2690 : {
2691 1602014 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
2692 : {
2693 1573040 : dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; // Q29
2694 1573040 : move32();
2695 1573040 : surCohEner_fx = Mpy_32_16_1( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); // Q29 + Q15 - Q15 = Q29
2696 :
2697 1573040 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i] = L_sub( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], surCohEner_fx ); // Q29
2698 1573040 : move32();
2699 1573040 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i] = L_add( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], surCohEner_fx ); // Q29
2700 1573040 : move32();
2701 :
2702 1573040 : surCohRatio_fx[i] = BASOP_Util_Divide3232_Scale_newton( surCohEner_fx, ( L_add( EPSILLON_FX, L_add( dirEne_fx, surCohEner_fx ) ) ), &temp_q );
2703 1573040 : move32();
2704 1573040 : surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], sub( temp_q, 16 ) ); // Q15
2705 1573040 : move32();
2706 : }
2707 : }
2708 : ELSE
2709 : {
2710 33153 : set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands );
2711 : }
2712 62127 : surCohRatio_q_fx = Q15;
2713 62127 : move16();
2714 : }
2715 : ELSE
2716 : {
2717 : Word16 max_exp_direct, max_exp_diffusion;
2718 61807 : max_exp_direct = 0;
2719 61807 : move16();
2720 61807 : max_exp_diffusion = 0;
2721 61807 : move16();
2722 61807 : ivas_dirac_dec_compute_gain_factors_fx( hSpatParamRendCom->num_freq_bands,
2723 61807 : hSpatParamRendCom->diffuseness_vector_fx[md_idx],
2724 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
2725 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx,
2726 : &max_exp_direct, &max_exp_diffusion );
2727 :
2728 61807 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub( Q31, max_exp_direct );
2729 61807 : move16();
2730 61807 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub( Q31, max_exp_diffusion );
2731 61807 : move16();
2732 :
2733 61807 : IF( coherence_flag )
2734 : {
2735 263947 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
2736 : {
2737 259620 : surCohRatio_fx[i] = L_deposit_l( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] );
2738 259620 : move32();
2739 : }
2740 : }
2741 : ELSE
2742 : {
2743 57480 : set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands );
2744 : }
2745 61807 : surCohRatio_q_fx = Q15;
2746 61807 : move16();
2747 : }
2748 :
2749 123934 : IF( st_ivas->hMasa == NULL )
2750 : {
2751 53156 : masa_band_mapping = NULL;
2752 : }
2753 : ELSE
2754 : {
2755 70778 : masa_band_mapping = st_ivas->hMasa->data.band_mapping;
2756 : }
2757 123934 : ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom,
2758 : hDirACRend,
2759 : st_ivas->hVBAPdata,
2760 : masa_band_mapping,
2761 : st_ivas->hMasaIsmData,
2762 : azimuth,
2763 : elevation,
2764 : md_idx,
2765 : surCohRatio_fx,
2766 : surCohRatio_q_fx,
2767 : hodirac_flag );
2768 : }
2769 :
2770 307931 : test();
2771 307931 : IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) )
2772 : {
2773 47326 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
2774 : {
2775 37849 : index_slot = add( slot_idx_start, slot_idx );
2776 37849 : offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot );
2777 : /* CLDFB Analysis*/
2778 113547 : FOR( ch = 0; ch < nchan_transport; ch++ )
2779 : {
2780 75698 : q_temp_cldfb = Q11;
2781 75698 : move16();
2782 75698 : cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset],
2783 75698 : Cldfb_RealBuffer_Temp_fx[ch][slot_idx],
2784 75698 : Cldfb_ImagBuffer_Temp_fx[ch][slot_idx],
2785 75698 : hSpatParamRendCom->num_freq_bands,
2786 : st_ivas->cldfbAnaDec[ch], &q_temp_cldfb );
2787 : }
2788 37849 : q_cldfb = q_temp_cldfb;
2789 37849 : move16();
2790 : }
2791 :
2792 9477 : test();
2793 9477 : IF( ( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) )
2794 : {
2795 2635 : ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( st_ivas, Cldfb_RealBuffer_Temp_fx, Cldfb_ImagBuffer_Temp_fx, &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx );
2796 : }
2797 : }
2798 :
2799 1530986 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
2800 : {
2801 1223055 : index_slot = add( slot_idx_start, slot_idx );
2802 1223055 : IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) )
2803 : {
2804 730303 : md_idx = hSpatParamRendCom->render_to_md_map[index_slot];
2805 730303 : move16();
2806 : }
2807 : ELSE
2808 : {
2809 492752 : md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
2810 492752 : move16();
2811 : }
2812 1223055 : test();
2813 1223055 : test();
2814 1223055 : IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
2815 : {
2816 6144011 : FOR( ch = 0; ch < nchan_transport; ch++ )
2817 : {
2818 5201084 : Copy32( pppQMfFrame_ts_re_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2819 5201084 : Copy32( pppQMfFrame_ts_im_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2820 : }
2821 942927 : q_cldfb = Q6;
2822 942927 : move16();
2823 : }
2824 280128 : ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) )
2825 : {
2826 113547 : FOR( ch = 0; ch < nchan_transport; ch++ )
2827 : {
2828 75698 : Copy32( Cldfb_RealBuffer_Temp_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2829 75698 : Copy32( Cldfb_ImagBuffer_Temp_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2830 : }
2831 : }
2832 : ELSE
2833 : {
2834 : /* CLDFB Analysis*/
2835 242279 : offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot );
2836 579941 : FOR( ch = 0; ch < nchan_transport; ch++ )
2837 : {
2838 337662 : q_temp_cldfb = Q11;
2839 337662 : move16();
2840 337662 : cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset],
2841 337662 : Cldfb_RealBuffer_fx[ch][0],
2842 337662 : Cldfb_ImagBuffer_fx[ch][0],
2843 337662 : hSpatParamRendCom->num_freq_bands,
2844 : st_ivas->cldfbAnaDec[ch], &q_temp_cldfb );
2845 : }
2846 242279 : q_cldfb = q_temp_cldfb;
2847 242279 : move16();
2848 : }
2849 :
2850 : /* CNG in DirAC, extra CLDFB ana for CNA*/
2851 1223055 : test();
2852 1223055 : test();
2853 1223055 : test();
2854 1223055 : test();
2855 1223055 : IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) )
2856 : {
2857 34604 : Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0];
2858 34604 : Word16 Q_input = Q11;
2859 34604 : move16();
2860 34604 : q_temp_cldfb = Q11;
2861 34604 : move16();
2862 34604 : test();
2863 34604 : test();
2864 34604 : test();
2865 103812 : generate_masking_noise_dirac_ivas_fx( st->hFdCngDec->hFdCngCom,
2866 : st_ivas->cldfbAnaDec[1],
2867 34604 : &st_ivas->hTcBuffer->tc_fx[1][hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->slots_rendered],
2868 : Cldfb_RealBuffer_fx[1][0],
2869 : Cldfb_ImagBuffer_fx[1][0],
2870 : slot_idx,
2871 34604 : st->cna_dirac_flag && st->flag_cna,
2872 34604 : ( ( ( st->core_brate == FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) ) && EQ_16( st->cng_type, FD_CNG ) && st->cng_sba_flag, Q_input, &q_temp_cldfb );
2873 34604 : Scale_sig32( Cldfb_RealBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6
2874 34604 : Scale_sig32( Cldfb_ImagBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6
2875 : }
2876 :
2877 : /* LFE synthesis */
2878 1223055 : test();
2879 1223055 : test();
2880 1223055 : test();
2881 1223055 : IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled && !( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && hDirACRend->hOutSetup.num_lfe == 0 ) )
2882 : {
2883 26560 : ivas_lfe_synth_with_cldfb_fx( st_ivas->hMasa->hMasaLfeSynth,
2884 : Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
2885 : Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1], Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1],
2886 : slot_idx,
2887 : md_idx,
2888 : nchan_transport, q_cldfb );
2889 : }
2890 :
2891 : /*-----------------------------------------------------------------*
2892 : * protoype signal computation
2893 : *-----------------------------------------------------------------*/
2894 1223055 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2895 : {
2896 921531 : test();
2897 921531 : test();
2898 921531 : IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
2899 : {
2900 147200 : protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
2901 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
2902 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
2903 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx,
2904 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
2905 : reference_power_fx, DirAC_mem.reference_power_q,
2906 : slot_idx, nchan_transport,
2907 147200 : hDirACRend->num_outputs_diff,
2908 147200 : hSpatParamRendCom->num_freq_bands,
2909 : p_Rmat_fx, q_cldfb );
2910 : }
2911 : ELSE
2912 : {
2913 774331 : protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
2914 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
2915 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
2916 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx,
2917 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
2918 : reference_power_fx, DirAC_mem.reference_power_q,
2919 : slot_idx, nchan_transport,
2920 774331 : hDirACRend->num_outputs_diff,
2921 774331 : hSpatParamRendCom->num_freq_bands,
2922 : 0, q_cldfb );
2923 : }
2924 :
2925 921531 : q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
2926 921531 : move16();
2927 921531 : q_proto_diffuse_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q;
2928 921531 : move16();
2929 : }
2930 301524 : ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
2931 : {
2932 29975 : protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx,
2933 : &hDirACRend->proto_frame_f_q,
2934 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
2935 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
2936 : reference_power_fx,
2937 : DirAC_mem.reference_power_q,
2938 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
2939 29975 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
2940 29975 : 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect,
2941 : q_cldfb );
2942 :
2943 29975 : q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
2944 29975 : move16();
2945 :
2946 29975 : proto_length = i_mult( 6, hSpatParamRendCom->num_freq_bands );
2947 29975 : proto_power_smooth_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
2948 : }
2949 : ELSE
2950 : {
2951 271549 : SWITCH( nchan_transport )
2952 : {
2953 56000 : case 11:
2954 : case 8:
2955 : case 6:
2956 : case 4:
2957 56000 : protoSignalComputation4_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
2958 : hDirACRend->proto_frame_f_fx,
2959 : &hDirACRend->proto_frame_f_q,
2960 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
2961 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
2962 : reference_power_fx,
2963 : DirAC_mem.reference_power_q,
2964 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
2965 56000 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
2966 56000 : slot_idx, hDirACRend->num_outputs_diff,
2967 56000 : hSpatParamRendCom->num_freq_bands,
2968 : hDirACRend->hoa_decoder,
2969 : nchan_transport,
2970 : hDirACRend->sba_map_tc, q_cldfb );
2971 56000 : proto_length = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
2972 56000 : proto_power_smooth_len = i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff );
2973 56000 : BREAK;
2974 103257 : case 2:
2975 103257 : protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx,
2976 : &hDirACRend->proto_frame_f_q,
2977 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
2978 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
2979 : reference_power_fx,
2980 : DirAC_mem.reference_power_q,
2981 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
2982 103257 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
2983 103257 : hDirACRend->hOutSetup.is_loudspeaker_setup,
2984 : slot_idx,
2985 103257 : hSpatParamRendCom->num_freq_bands,
2986 : hDirACRend->masa_stereo_type_detect,
2987 : q_cldfb );
2988 103257 : proto_length = i_mult( 6, hSpatParamRendCom->num_freq_bands );
2989 103257 : IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
2990 : {
2991 71233 : proto_power_smooth_len = i_mult( 3, hSpatParamRendCom->num_freq_bands );
2992 : }
2993 : ELSE
2994 : {
2995 32024 : proto_power_smooth_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
2996 : }
2997 103257 : BREAK;
2998 112292 : case 1:
2999 112292 : protoSignalComputation1_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
3000 : hDirACRend->proto_frame_f_fx,
3001 : &hDirACRend->proto_frame_f_q,
3002 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
3003 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
3004 : reference_power_fx,
3005 : DirAC_mem.reference_power_q,
3006 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
3007 112292 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
3008 : slot_idx,
3009 112292 : hDirACRend->num_protos_diff,
3010 112292 : hSpatParamRendCom->num_freq_bands, q_cldfb );
3011 112292 : proto_length = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_diff ) );
3012 112292 : proto_power_smooth_len = hSpatParamRendCom->num_freq_bands;
3013 112292 : move16();
3014 112292 : BREAK;
3015 0 : default:
3016 0 : return;
3017 : }
3018 271549 : q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
3019 271549 : move16();
3020 : }
3021 :
3022 : /*-----------------------------------------------------------------*
3023 : * Compute DirAC parameters at decoder side
3024 : *-----------------------------------------------------------------*/
3025 1223055 : IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) )
3026 : {
3027 730303 : Copy( &hSpatParamRendCom->azimuth[md_idx][hDirAC->hConfig->enc_param_start_band], &azimuth[hDirAC->hConfig->enc_param_start_band], sub( hSpatParamRendCom->num_freq_bands, hDirAC->hConfig->enc_param_start_band ) );
3028 730303 : Copy( &hSpatParamRendCom->elevation[md_idx][hDirAC->hConfig->enc_param_start_band], &elevation[hDirAC->hConfig->enc_param_start_band], sub( hSpatParamRendCom->num_freq_bands, hDirAC->hConfig->enc_param_start_band ) );
3029 :
3030 730303 : test();
3031 730303 : test();
3032 730303 : IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
3033 : {
3034 147200 : num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
3035 147200 : move16();
3036 147200 : rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx );
3037 : }
3038 :
3039 : /*hDirACRend->index_buffer_intensity = ( hDirACRend->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1 */
3040 730303 : IF( hDirACRend->index_buffer_intensity == 0 )
3041 : {
3042 217 : hDirACRend->index_buffer_intensity = 1;
3043 217 : move16();
3044 : }
3045 : ELSE
3046 : {
3047 730086 : hDirACRend->index_buffer_intensity = add( sub( hDirACRend->index_buffer_intensity, i_mult( shr( hDirACRend->index_buffer_intensity, DIRAC_NO_COL_AVG_DIFF_LOG2 ), DIRAC_NO_COL_AVG_DIFF ) ), 1 ); /* averaging_length = 32 */
3048 730086 : move16();
3049 : }
3050 :
3051 730303 : index = hDirACRend->index_buffer_intensity;
3052 730303 : move16();
3053 730303 : num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
3054 730303 : move16();
3055 :
3056 730303 : computeIntensityVector_dec_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
3057 : q_cldfb, num_freq_bands,
3058 730303 : hDirACRend->buffer_intensity_real_fx[0][index - 1],
3059 730303 : hDirACRend->buffer_intensity_real_fx[1][index - 1],
3060 730303 : hDirACRend->buffer_intensity_real_fx[2][index - 1],
3061 730303 : &hDirACRend->q_buffer_intensity_real[index - 1] );
3062 :
3063 730303 : computeDirectionAngles_fx( hDirACRend->buffer_intensity_real_fx[0][index - 1],
3064 730303 : hDirACRend->buffer_intensity_real_fx[1][index - 1],
3065 730303 : hDirACRend->buffer_intensity_real_fx[2][index - 1],
3066 730303 : hDirACRend->q_buffer_intensity_real[index - 1],
3067 : num_freq_bands, azimuth, elevation );
3068 :
3069 730303 : Copy32( reference_power_fx, &( hDirACRend->buffer_energy_fx[i_mult( sub( index, 1 ), num_freq_bands )] ), num_freq_bands );
3070 730303 : Scale_sig32( &( hDirACRend->buffer_energy_fx[add( i_mult( sub( index, 1 ), num_freq_bands ), CLDFB_NO_CHANNELS_HALF )] ), s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_q[1] ) );
3071 730303 : hDirACRend->q_buffer_energy[index - 1] = DirAC_mem.reference_power_q[0];
3072 730303 : move16();
3073 :
3074 730303 : computeDiffuseness_fixed( hDirACRend->buffer_intensity_real_fx, hDirACRend->buffer_energy_fx, num_freq_bands, hSpatParamRendCom->diffuseness_vector_fx[md_idx], hDirACRend->q_buffer_intensity_real, hDirACRend->q_buffer_energy, &hSpatParamRendCom->q_diffuseness_vector );
3075 : }
3076 :
3077 : /*-----------------------------------------------------------------*
3078 : * frequency domain decorrelation
3079 : *-----------------------------------------------------------------*/
3080 1223055 : IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) )
3081 : {
3082 : /* decorrelate prototype frame */
3083 1137080 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3084 : {
3085 2764593 : ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
3086 921531 : hDirACRend->num_outputs_diff,
3087 921531 : hDirACRend->num_protos_diff,
3088 : hDirACRend->synthesisConf,
3089 : nchan_transport,
3090 921531 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx[imult1616( imult1616( imult1616( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), hDirACRend->num_outputs_diff )],
3091 921531 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
3092 921531 : hDirACRend->num_protos_diff,
3093 921531 : hDirACRend->proto_index_diff,
3094 921531 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx[( ( ( slot_idx * 2 ) * hSpatParamRendCom->num_freq_bands ) * hDirACRend->num_outputs_diff ) + ( ( 2 * hSpatParamRendCom->num_freq_bands ) * s_min( 4, nchan_transport ) )],
3095 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
3096 : onset_filter_fx,
3097 : hDirACRend->h_freq_domain_decorr_ap_params,
3098 : hDirACRend->h_freq_domain_decorr_ap_state );
3099 :
3100 921531 : v_multc_fixed( onset_filter_fx, 536870912 /* 0.25f in Q31 */, onset_filter_fx, hSpatParamRendCom->num_freq_bands );
3101 :
3102 921531 : v_add_fixed_no_hdrm( onset_filter_fx, onset_filter_subframe_fx, onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands ); /* Q31 */
3103 921531 : p_onset_filter_fx = onset_filter_subframe_fx;
3104 : }
3105 : ELSE
3106 : {
3107 215549 : scale = L_norm_arr( hDirACRend->proto_frame_f_fx, proto_length );
3108 215549 : Scale_sig32( hDirACRend->proto_frame_f_fx, proto_length, scale ); // Q(proto_frame_f_q+scale)
3109 215549 : hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, scale );
3110 215549 : move16();
3111 215549 : ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
3112 215549 : hDirACRend->num_outputs_diff,
3113 215549 : hDirACRend->num_protos_diff,
3114 : hDirACRend->synthesisConf,
3115 : nchan_transport,
3116 215549 : hDirACRend->proto_frame_f_fx,
3117 215549 : hDirACRend->proto_frame_f_q,
3118 215549 : hDirACRend->num_protos_diff,
3119 215549 : hDirACRend->proto_index_diff,
3120 : DirAC_mem.frame_dec_f_fx,
3121 : &DirAC_mem.frame_dec_f_q,
3122 : onset_filter_fx,
3123 : hDirACRend->h_freq_domain_decorr_ap_params,
3124 : hDirACRend->h_freq_domain_decorr_ap_state );
3125 :
3126 215549 : hDirACRend->proto_frame_dec_f_fx = DirAC_mem.frame_dec_f_fx;
3127 215549 : hDirACRend->proto_frame_dec_f_q = DirAC_mem.frame_dec_f_q;
3128 215549 : move16();
3129 215549 : hDirACRend->proto_frame_dec_f_len = DirAC_mem.frame_dec_f_len;
3130 215549 : move16();
3131 215549 : p_onset_filter_fx = onset_filter_fx;
3132 : }
3133 : }
3134 : ELSE
3135 : {
3136 85975 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3137 : {
3138 0 : set32_fx( onset_filter_subframe_fx, ONE_IN_Q31, hSpatParamRendCom->num_freq_bands );
3139 0 : p_onset_filter_fx = onset_filter_subframe_fx;
3140 : }
3141 : ELSE
3142 : {
3143 : /* no frequency domain decorrelation: use prototype frame */
3144 85975 : hDirACRend->proto_frame_dec_f_fx = hDirACRend->proto_frame_f_fx;
3145 85975 : hDirACRend->proto_frame_dec_f_len = hDirACRend->proto_frame_f_len;
3146 85975 : move16();
3147 85975 : hDirACRend->proto_frame_dec_f_q = hDirACRend->proto_frame_f_q;
3148 85975 : move16();
3149 85975 : p_onset_filter_fx = NULL;
3150 : }
3151 : }
3152 :
3153 : /*-----------------------------------------------------------------*
3154 : * output synthesis
3155 : *-----------------------------------------------------------------*/
3156 1223055 : test();
3157 1223055 : IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) )
3158 : {
3159 : DIRAC_OUTPUT_SYNTHESIS_STATE *state;
3160 : Word16 diffuse_start;
3161 271549 : state = &( hDirACRend->h_output_synthesis_psd_state );
3162 271549 : diffuse_start = i_mult( i_mult( slot_idx, 2 ), i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) );
3163 :
3164 271549 : exp = getScaleFactor32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len );
3165 271549 : scale_sig32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len, exp ); // hDirACRend->proto_frame_dec_f_q + exp
3166 271549 : hDirACRend->proto_frame_dec_f_q = add( hDirACRend->proto_frame_dec_f_q, exp );
3167 271549 : move16();
3168 271549 : exp = getScaleFactor32( state->proto_diffuse_buffer_f_fx, diffuse_start );
3169 271549 : scale_sig32( state->proto_diffuse_buffer_f_fx, diffuse_start, exp ); // state->proto_diffuse_buffer_f_q + exp
3170 271549 : state->proto_diffuse_buffer_f_q = add( state->proto_diffuse_buffer_f_q, exp );
3171 271549 : move16();
3172 : /*Compute diffuse prototypes*/
3173 271549 : ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx );
3174 : }
3175 :
3176 : /*Compute PSDs*/
3177 1223055 : h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
3178 1223055 : h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
3179 1223055 : num_channels_dir = hDirACRend->num_outputs_dir;
3180 1223055 : move16();
3181 :
3182 1223055 : if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
3183 : {
3184 221809 : num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE;
3185 221809 : move16();
3186 : }
3187 :
3188 1223055 : test();
3189 1223055 : test();
3190 1223055 : IF( ( h_dirac_output_synthesis_params->use_onset_filters && ( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) )
3191 : {
3192 165809 : Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // Q31
3193 165809 : h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
3194 165809 : move16();
3195 :
3196 165809 : exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
3197 165809 : scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_diff_smooth + exp
3198 165809 : h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp );
3199 165809 : move16();
3200 : }
3201 :
3202 1223055 : test();
3203 1223055 : IF( ( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) )
3204 : {
3205 56000 : scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->direct_power_factor_q ) ); // Q31
3206 56000 : h_dirac_output_synthesis_state->direct_power_factor_q = Q31;
3207 56000 : move16();
3208 :
3209 56000 : scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // Q31
3210 56000 : h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
3211 56000 : move16();
3212 :
3213 56000 : scale_sig32( h_dirac_output_synthesis_state->direct_responses_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_q ) ); // Q31
3214 56000 : h_dirac_output_synthesis_state->direct_responses_q = Q31;
3215 56000 : move16();
3216 :
3217 56000 : scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); // Q31
3218 56000 : h_dirac_output_synthesis_state->direct_responses_square_q = Q31;
3219 56000 : move16();
3220 :
3221 56000 : exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
3222 56000 : scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, exp
3223 56000 : h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, exp );
3224 56000 : move16();
3225 56000 : exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
3226 56000 : scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth+ exp
3227 56000 : h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, exp );
3228 56000 : move16();
3229 56000 : exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
3230 56000 : scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_diff_smooth+ exp
3231 56000 : h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp );
3232 56000 : move16();
3233 : }
3234 :
3235 1223055 : ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fx,
3236 : DirAC_mem.reference_power_q,
3237 : p_onset_filter_fx,
3238 : azimuth,
3239 : elevation,
3240 1223055 : hSpatParamRendCom->diffuseness_vector_fx[md_idx],
3241 1223055 : hSpatParamRendCom->q_diffuseness_vector,
3242 : hSpatParamRendCom,
3243 : hDirACRend,
3244 : st_ivas->hVBAPdata,
3245 : hDirACRend->hOutSetup,
3246 : nchan_transport,
3247 : md_idx,
3248 : hodirac_flag,
3249 1223055 : hDirAC->hConfig->dec_param_estim );
3250 :
3251 :
3252 1223055 : IF( hDirAC->hConfig->dec_param_estim )
3253 : {
3254 : Word16 fac;
3255 : #ifndef ISSUE_1796_replace_shl_o
3256 : Flag flag = 0;
3257 : move32();
3258 : #endif
3259 730303 : fac = BASOP_Util_Divide3232_Scale( 1, hSpatParamRendCom->subframe_nbslots[subframe_idx], &exp );
3260 : #ifdef ISSUE_1796_replace_shl_o
3261 730303 : fac = shl_sat( fac, exp );
3262 : #else
3263 : fac = shl_o( fac, exp, &flag );
3264 : #endif
3265 :
3266 730303 : IF( LT_16( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) )
3267 : {
3268 0 : scale_sig32( hSpatParamRendCom->diffuseness_vector_fx[md_idx], hSpatParamRendCom->num_freq_bands, sub( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ); // q_diffuseness_vector
3269 0 : hSpatParamRendCom->q_diffuseness_vector = q_diffuseness_vector;
3270 0 : move16();
3271 : }
3272 : ELSE
3273 : {
3274 730303 : scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( hSpatParamRendCom->q_diffuseness_vector, q_diffuseness_vector ) ); // q_diffuseness_vector
3275 730303 : q_diffuseness_vector = hSpatParamRendCom->q_diffuseness_vector;
3276 730303 : move16();
3277 : }
3278 730303 : v_multc_acc_32_16( hSpatParamRendCom->diffuseness_vector_fx[md_idx], fac, diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands );
3279 : }
3280 :
3281 1223055 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3282 : {
3283 301524 : v_add_fixed_me( reference_power_fx, sub( 31, DirAC_mem.reference_power_q[0] ),
3284 301524 : reference_power_smooth_fx, sub( 31, q_reference_power_smooth[0] ),
3285 : reference_power_smooth_fx, &temp_q,
3286 301524 : s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), 1 );
3287 301524 : q_reference_power_smooth[0] = sub( 31, temp_q );
3288 301524 : v_add_fixed_me( reference_power_fx + CLDFB_NO_CHANNELS_HALF, sub( 31, DirAC_mem.reference_power_q[1] ),
3289 301524 : reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, sub( 31, q_reference_power_smooth[1] ),
3290 : reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, &temp_q,
3291 301524 : s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), 1 );
3292 301524 : q_reference_power_smooth[1] = sub( 31, temp_q );
3293 : }
3294 : }
3295 :
3296 307931 : minimum_s( q_proto_direct_buffer, add( hSpatParamRendCom->subframe_nbslots[subframe_idx], 1 ), &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q );
3297 307931 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3298 : {
3299 231804 : minimum_s( q_proto_diffuse_buffer, add( hSpatParamRendCom->subframe_nbslots[subframe_idx], 1 ), &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q );
3300 : }
3301 1530986 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3302 : {
3303 1223055 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3304 : {
3305 921531 : offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
3306 921531 : buff_len = i_mult( 2, i_mult( hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands ) );
3307 921531 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, q_proto_diffuse_buffer[slot_idx] ) ); // proto_diffuse_buffer_f_q
3308 921531 : offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) );
3309 921531 : buff_len = i_mult( 2, i_mult( nchan_transport, hSpatParamRendCom->num_freq_bands ) );
3310 921531 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
3311 : }
3312 301524 : ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
3313 : {
3314 29975 : offset = i_mult( slot_idx, i_mult( 4, hSpatParamRendCom->num_freq_bands ) );
3315 29975 : buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands );
3316 29975 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
3317 : }
3318 : ELSE
3319 : {
3320 271549 : SWITCH( nchan_transport )
3321 : {
3322 56000 : case 11:
3323 : case 8:
3324 : case 6:
3325 : case 4:
3326 56000 : offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
3327 56000 : buff_len = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
3328 56000 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
3329 56000 : BREAK;
3330 103257 : case 2:
3331 103257 : IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
3332 : {
3333 71233 : offset = i_mult( i_mult( i_mult( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), 3 );
3334 71233 : buff_len = i_mult( 6, hSpatParamRendCom->num_freq_bands );
3335 : }
3336 : ELSE
3337 : {
3338 32024 : offset = i_mult( i_mult( i_mult( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), 2 );
3339 32024 : buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands );
3340 : }
3341 103257 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
3342 103257 : BREAK;
3343 112292 : case 1:
3344 112292 : offset = i_mult( slot_idx, i_mult( 2, hSpatParamRendCom->num_freq_bands ) );
3345 112292 : buff_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
3346 112292 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
3347 112292 : BREAK;
3348 : }
3349 1223055 : }
3350 : }
3351 307931 : test();
3352 307931 : IF( EQ_16( slot_idx, hSpatParamRendCom->subframe_nbslots[subframe_idx] ) && sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, add( offset, buff_len ) ) > 0 )
3353 : {
3354 4335 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + add( offset, buff_len ), sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, add( offset, buff_len ) ), sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
3355 4335 : offset = i_mult( i_mult( sub( slot_idx, 1 ), 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
3356 4335 : buff_len = i_mult( 2, i_mult( hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands ) );
3357 4335 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) && sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, add( offset, buff_len ) ) > 0 )
3358 : {
3359 2843 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + add( offset, buff_len ), sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, add( offset, buff_len ) ), sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, q_proto_diffuse_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
3360 : }
3361 : }
3362 307931 : ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
3363 :
3364 307931 : size = i_mult( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands );
3365 307931 : IF( hodirac_flag )
3366 : {
3367 53156 : size_ho = i_mult( size, DIRAC_HO_NUMSECTORS );
3368 : }
3369 : ELSE
3370 : {
3371 254775 : size_ho = size;
3372 254775 : move16();
3373 : }
3374 :
3375 307931 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3376 : {
3377 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, Q26 ) )
3378 : {
3379 214489 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth ) ); // Q26
3380 214489 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26;
3381 214489 : move16();
3382 : }
3383 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, Q26 ) )
3384 : {
3385 0 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); // Q26
3386 : }
3387 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) )
3388 : {
3389 94097 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // Q31
3390 : }
3391 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) )
3392 : {
3393 8651 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size_ho, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // Q31
3394 : }
3395 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) )
3396 : {
3397 93606 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); // Q31
3398 : }
3399 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, Q26 ) )
3400 : {
3401 0 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); // Q26
3402 : }
3403 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, Q26 ) )
3404 : {
3405 0 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); // Q26
3406 : }
3407 231804 : IF( NE_16( q_diffuseness_vector, Q30 ) )
3408 : {
3409 0 : scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q30, q_diffuseness_vector ) ); // Q30
3410 : }
3411 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) )
3412 : {
3413 0 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26
3414 : }
3415 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) )
3416 : {
3417 756 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26
3418 : }
3419 :
3420 231804 : ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer_fx,
3421 : Cldfb_ImagBuffer_fx,
3422 : hSpatParamRendCom,
3423 : hDirACRend,
3424 : nchan_transport,
3425 231804 : hSpatParamRendCom->subframe_nbslots[subframe_idx],
3426 : p_onset_filter_fx,
3427 : diffuseness_vector_fx,
3428 : hodirac_flag,
3429 231804 : hDirAC->hConfig->dec_param_estim,
3430 : &hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev,
3431 : &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev );
3432 :
3433 231804 : test();
3434 231804 : IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL )
3435 : {
3436 446000 : FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
3437 : {
3438 2015000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3439 : {
3440 1612000 : scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6
3441 1612000 : scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6
3442 : }
3443 : }
3444 : }
3445 : ELSE
3446 : {
3447 2966056 : FOR( ch = 0; ch < hDirACRend->num_outputs_dir; ch++ )
3448 : {
3449 13795300 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3450 : {
3451 11018048 : scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6
3452 11018048 : scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6
3453 : }
3454 : }
3455 : }
3456 : }
3457 : ELSE
3458 : {
3459 : /* Determine encoding quality based additional smoothing factor */
3460 76127 : Word32 qualityBasedSmFactor_fx = ONE_IN_Q31;
3461 76127 : move32();
3462 76127 : Word16 q_Cldfb = 0;
3463 76127 : move16();
3464 :
3465 76127 : IF( st_ivas->hMasa != NULL )
3466 : {
3467 62127 : qualityBasedSmFactor_fx = L_mult( st_ivas->hMasa->data.dir_decode_quality_fx, st_ivas->hMasa->data.dir_decode_quality_fx ); /* (Q15, Q15) -> Q31 */
3468 : }
3469 :
3470 76127 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) )
3471 : {
3472 62127 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // Q31
3473 : }
3474 76127 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) )
3475 : {
3476 62127 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // Q31
3477 : }
3478 76127 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) )
3479 : {
3480 20652 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); // Q31
3481 : }
3482 76127 : IF( NE_16( q_diffuseness_vector, Q31 ) )
3483 : {
3484 76127 : Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, q_diffuseness_vector ) ); // Q31
3485 : }
3486 76127 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, Q31 ) )
3487 : {
3488 62127 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, i_mult( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q ) ); // Q31
3489 : }
3490 :
3491 76127 : exp = L_norm_arr( reference_power_smooth_fx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) );
3492 76127 : scale_sig32( reference_power_smooth_fx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), exp ); // q_reference_power_smooth[0] + exp
3493 76127 : q_reference_power_smooth[0] = add( q_reference_power_smooth[0], exp );
3494 76127 : IF( LT_16( q_reference_power_smooth[0], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] ) )
3495 : {
3496 2829 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( q_reference_power_smooth[0], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] ) ); // q_reference_power_smooth[0]
3497 2829 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] = q_reference_power_smooth[0];
3498 2829 : move16();
3499 : }
3500 : ELSE
3501 : {
3502 : Word32 temp;
3503 2253368 : FOR( i = 0; i < s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ); i++ )
3504 : {
3505 2180070 : temp = L_shl( reference_power_smooth_fx[i], sub( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0], q_reference_power_smooth[0] ) );
3506 2180070 : reference_power_smooth_fx[i] = L_max( temp, L_min( reference_power_smooth_fx[i], 1 ) );
3507 2180070 : move32();
3508 : }
3509 73298 : q_reference_power_smooth[0] = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0];
3510 73298 : move16();
3511 : }
3512 :
3513 76127 : exp = L_norm_arr( reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
3514 76127 : scale_sig32( reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), exp ); // q_reference_power_smooth + exp
3515 76127 : q_reference_power_smooth[1] = add( q_reference_power_smooth[1], exp );
3516 76127 : IF( LT_16( q_reference_power_smooth[1], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] ) )
3517 : {
3518 2558 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( q_reference_power_smooth[1], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] ) ); // q_reference_power_smooth
3519 2558 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] = q_reference_power_smooth[1];
3520 2558 : move16();
3521 : }
3522 : ELSE
3523 : {
3524 : Word32 temp;
3525 2037339 : FOR( i = CLDFB_NO_CHANNELS_HALF; i < hSpatParamRendCom->num_freq_bands; i++ )
3526 : {
3527 1963770 : temp = L_shl( reference_power_smooth_fx[i], sub( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1], q_reference_power_smooth[1] ) );
3528 1963770 : reference_power_smooth_fx[i] = L_max( temp, L_min( reference_power_smooth_fx[i], 1 ) );
3529 1963770 : move32();
3530 : }
3531 73569 : q_reference_power_smooth[1] = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1];
3532 73569 : move16();
3533 : }
3534 :
3535 76127 : IF( hDirACRend->masa_stereo_type_detect != NULL )
3536 : {
3537 11409 : IF( LT_16( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) )
3538 : {
3539 11409 : hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) ); // q_subtract_power_y
3540 11409 : move32();
3541 11409 : hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = hDirACRend->masa_stereo_type_detect->q_subtract_power_y;
3542 11409 : move16();
3543 : }
3544 : ELSE
3545 : {
3546 0 : hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ); // q_subtract_power_y
3547 0 : move32();
3548 0 : hDirACRend->masa_stereo_type_detect->q_subtract_power_y = hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth;
3549 0 : move16();
3550 : }
3551 : }
3552 :
3553 76127 : exp = 31;
3554 76127 : move16();
3555 324131 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3556 : {
3557 248004 : exp = s_min( exp, L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + i, s_min( CLDFB_NO_CHANNELS_HALF, hSpatParamRendCom->num_freq_bands ) ) );
3558 : }
3559 324131 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3560 : {
3561 248004 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + i, s_min( CLDFB_NO_CHANNELS_HALF, hSpatParamRendCom->num_freq_bands ), exp ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + exp)
3562 : }
3563 76127 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0], exp );
3564 76127 : move16();
3565 76127 : exp = 31;
3566 76127 : move16();
3567 324131 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3568 : {
3569 248004 : exp = s_min( exp, L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF + i, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) ) );
3570 : }
3571 324131 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3572 : {
3573 248004 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF + i, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), exp ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + exp)
3574 : }
3575 76127 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], exp );
3576 76127 : move16();
3577 :
3578 76127 : IF( LT_16( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] ) )
3579 : {
3580 111863 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3581 : {
3582 85039 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + i, s_min( CLDFB_NO_CHANNELS_HALF, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] ) ); // proto_power_smooth_q
3583 : }
3584 26824 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0];
3585 26824 : move16();
3586 : }
3587 : ELSE
3588 : {
3589 212268 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3590 : {
3591 162965 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + i, s_min( CLDFB_NO_CHANNELS_HALF, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] ) ); // proto_power_smooth_prev_q
3592 : }
3593 49303 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0];
3594 49303 : move16();
3595 : }
3596 76127 : IF( LT_16( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] ) )
3597 : {
3598 138356 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3599 : {
3600 106190 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + CLDFB_NO_CHANNELS_HALF + i, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] ) ); // proto_power_smooth_q
3601 : }
3602 32166 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1];
3603 32166 : move16();
3604 : }
3605 : ELSE
3606 : {
3607 185775 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3608 : {
3609 141814 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF + i, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] ) ); // proto_power_smooth_prev_q
3610 : }
3611 43961 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1];
3612 43961 : move16();
3613 : }
3614 :
3615 76127 : exp = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) );
3616 76127 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), exp ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q + exp)
3617 76127 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, exp );
3618 76127 : move16();
3619 76127 : IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 )
3620 : {
3621 53910 : IF( LT_16( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) )
3622 : {
3623 23968 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ); // proto_power_diff_smooth_q
3624 23968 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q;
3625 23968 : move16();
3626 : }
3627 : ELSE
3628 : {
3629 29942 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ) ); // proto_power_diff_smooth_prev_q
3630 29942 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q;
3631 29942 : move16();
3632 : }
3633 : }
3634 :
3635 76127 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) )
3636 : {
3637 0 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26
3638 : }
3639 76127 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) )
3640 : {
3641 0 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26
3642 : }
3643 76127 : IF( hDirACRend->proto_signal_decorr_on )
3644 : {
3645 53910 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ) ); // proto_direct_buffer_f_q
3646 53910 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
3647 53910 : move16();
3648 : }
3649 :
3650 76127 : ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Cldfb_RealBuffer_fx,
3651 : Cldfb_ImagBuffer_fx,
3652 : hSpatParamRendCom,
3653 : hDirACRend,
3654 76127 : hSpatParamRendCom->subframe_nbslots[subframe_idx],
3655 : diffuseness_vector_fx,
3656 : reference_power_smooth_fx,
3657 : q_reference_power_smooth,
3658 : qualityBasedSmFactor_fx,
3659 76127 : hDirAC->hConfig->enc_param_start_band,
3660 : &q_Cldfb );
3661 :
3662 76127 : Word16 allZero = 1;
3663 76127 : move16();
3664 14489867 : FOR( i = 0; i < proto_power_smooth_len; i++ )
3665 : {
3666 14413740 : if ( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx[i] != 0 )
3667 : {
3668 0 : allZero = 0;
3669 0 : move16();
3670 : }
3671 : }
3672 76127 : if ( allZero )
3673 : {
3674 76127 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = 31;
3675 76127 : move16();
3676 : }
3677 76127 : if ( allZero )
3678 : {
3679 76127 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = 31;
3680 76127 : move16();
3681 : }
3682 :
3683 597659 : FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
3684 : {
3685 2604130 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3686 : {
3687 2082598 : scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6
3688 2082598 : scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6
3689 : }
3690 : }
3691 : }
3692 :
3693 : /*-----------------------------------------------------------------*
3694 : * CLDFB synthesis (and binaural rendering)
3695 : *-----------------------------------------------------------------*/
3696 :
3697 307931 : index_slot = slot_idx_start_cldfb_synth;
3698 307931 : move16();
3699 :
3700 307931 : test();
3701 307931 : test();
3702 307931 : IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
3703 120202 : {
3704 : /* render objects in combined format onto the CICP19 channels for BINAURAL_ROOM_IR */
3705 120202 : test();
3706 120202 : test();
3707 120202 : IF( ( ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
3708 : {
3709 : #ifndef NONBE_FIX_1141_OSBA_ROOM_RENDERING
3710 : Word16 in_ch;
3711 : FOR( in_ch = 0; in_ch < st_ivas->nchan_ism; in_ch++ )
3712 : {
3713 : #endif
3714 : Word16 j, k, l;
3715 : #ifndef NONBE_FIX_1141_OSBA_ROOM_RENDERING
3716 : Word16 j2, lfe_index;
3717 : #endif
3718 : Word16 num_objects, nchan_out_woLFE;
3719 : Word16 n_slots_to_render;
3720 : Word16 n_samples_to_render;
3721 : #ifndef NONBE_FIX_1141_OSBA_ROOM_RENDERING
3722 : Word16 interp_offset;
3723 : #endif
3724 : Word32 gain_fx, prev_gain_fx;
3725 :
3726 12000 : num_objects = st_ivas->nchan_ism;
3727 12000 : move16();
3728 12000 : nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
3729 12000 : move16();
3730 12000 : n_slots_to_render = st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->subframes_rendered];
3731 12000 : move16();
3732 12000 : n_samples_to_render = imult1616( hSpatParamRendCom->num_freq_bands, n_slots_to_render );
3733 : #ifndef NONBE_FIX_1141_OSBA_ROOM_RENDERING
3734 : interp_offset = st_ivas->hTcBuffer->n_samples_rendered;
3735 : move16();
3736 : #endif
3737 :
3738 12000 : test();
3739 12000 : IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[0] )
3740 : {
3741 0 : ivas_jbm_dec_get_adapted_linear_interpolator_fx( n_samples_to_render, n_samples_to_render, st_ivas->hIsmRendererData->interpolator_fx );
3742 : #ifdef NONBE_FIX_1141_OSBA_ROOM_RENDERING
3743 0 : st_ivas->hIsmRendererData->interp_offset_fx = 0;
3744 : #else
3745 : interp_offset = 0;
3746 : #endif
3747 0 : move16();
3748 : }
3749 :
3750 56000 : FOR( i = 0; i < num_objects; i++ )
3751 : {
3752 : /* Combined rotation: rotate the object positions depending the head and external orientations */
3753 44000 : test();
3754 44000 : IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) )
3755 : {
3756 0 : Word16 az_q0 = extract_l( L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, Q22 ) );
3757 0 : Word16 el_q0 = extract_l( L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, Q22 ) );
3758 : Word32 az1_32, el1_32;
3759 0 : rotateAziEle_fixed( az_q0, el_q0, &az1_32, &el1_32, st_ivas->hCombinedOrientationData->Rmat_fx[0], st_ivas->hIntSetup.is_planar_setup );
3760 :
3761 0 : IF( st_ivas->hEFAPdata != NULL )
3762 : {
3763 0 : const Word32 azi_fx = L_shl( az1_32, Q22 - Q16 ); // Q16 -> Q22
3764 0 : const Word32 ele_fx = L_shl( el1_32, Q22 - Q16 ); // Q16 -> Q22
3765 0 : efap_determine_gains_fx( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], azi_fx, ele_fx, EFAP_MODE_EFAP );
3766 : }
3767 : }
3768 :
3769 : #ifdef NONBE_FIX_1141_OSBA_ROOM_RENDERING
3770 528000 : FOR( j = 0; j < nchan_out_woLFE; j++ )
3771 : #else
3772 : lfe_index = 0;
3773 : move16();
3774 : for ( j = 0, j2 = 0; j < nchan_out_woLFE; j++, j2++ )
3775 : #endif
3776 : {
3777 : #ifndef NONBE_FIX_1141_OSBA_ROOM_RENDERING
3778 : test();
3779 : IF( ( st_ivas->hIntSetup.num_lfe > 0 && ( EQ_16( st_ivas->hIntSetup.index_lfe[lfe_index], j ) ) ) )
3780 : {
3781 : IF( LT_16( lfe_index, sub( st_ivas->hIntSetup.num_lfe, 1 ) ) )
3782 : {
3783 : lfe_index = add( lfe_index, 1 );
3784 : j2 = add( j2, 1 );
3785 : }
3786 : ELSE
3787 : {
3788 : j2 = add( j2, 1 );
3789 : }
3790 : }
3791 : #endif
3792 484000 : gain_fx = st_ivas->hIsmRendererData->gains_fx[i][j];
3793 484000 : move32();
3794 484000 : prev_gain_fx = st_ivas->hIsmRendererData->prev_gains_fx[i][j];
3795 484000 : move32();
3796 484000 : test();
3797 484000 : IF( ( L_abs( gain_fx ) > 0 || L_abs( prev_gain_fx ) > 0 ) )
3798 : {
3799 : Word32 *tc_re_fx, *tc_im_fx;
3800 : Word16 *w1_fx, w2_fx;
3801 :
3802 : #ifdef NONBE_FIX_1141_OSBA_ROOM_RENDERING
3803 253076 : w1_fx = &st_ivas->hIsmRendererData->interpolator_fx[st_ivas->hIsmRendererData->interp_offset_fx];
3804 : #else
3805 : w1_fx = &st_ivas->hIsmRendererData->interpolator_fx[interp_offset];
3806 : #endif
3807 253076 : tc_re_fx = pppQMfFrame_ts_re_fx[nchan_transport + i][0];
3808 253076 : move32();
3809 253076 : tc_im_fx = pppQMfFrame_ts_im_fx[nchan_transport + i][0];
3810 253076 : move32();
3811 1265380 : FOR( k = 0; k < n_slots_to_render; k++ )
3812 : {
3813 : Word32 g_fx;
3814 1012304 : w2_fx = sub( MAX16B, *w1_fx );
3815 1012304 : g_fx = Madd_32_16( Mpy_32_16_1( gain_fx, *w1_fx ), prev_gain_fx, w2_fx ); // Q15
3816 54436304 : FOR( l = 0; l < hSpatParamRendCom->num_freq_bands; l++ )
3817 : {
3818 : #ifdef NONBE_FIX_1141_OSBA_ROOM_RENDERING
3819 : #ifdef FIX_CDLFB_BUFFER_SCALING
3820 53424000 : Cldfb_RealBuffer_fx[j][k][l] = Madd_32_32( Cldfb_RealBuffer_fx[j][k][l], g_fx, L_shl( *tc_re_fx, 1 ) );
3821 : #else
3822 : Cldfb_RealBuffer_fx[j][k][l] = Madd_32_32( Cldfb_RealBuffer_fx[j][k][l], g_fx, *tc_re_fx );
3823 : #endif
3824 : #else
3825 : #ifdef FIX_CDLFB_BUFFER_SCALING
3826 : Cldfb_RealBuffer_fx[j2][k][l] = Madd_32_32( Cldfb_RealBuffer_fx[j2][k][l], g_fx, L_shl( *tc_re_fx, 1 ) );
3827 : #else
3828 : Cldfb_RealBuffer_fx[j2][k][l] = Madd_32_32( Cldfb_RealBuffer_fx[j2][k][l], g_fx, *tc_re_fx );
3829 : #endif
3830 : #endif
3831 53424000 : move32();
3832 53424000 : tc_re_fx++;
3833 : #ifdef NONBE_FIX_1141_OSBA_ROOM_RENDERING
3834 : #ifdef FIX_CDLFB_BUFFER_SCALING
3835 53424000 : Cldfb_ImagBuffer_fx[j][k][l] = Madd_32_32( Cldfb_ImagBuffer_fx[j][k][l], g_fx, L_shl( *tc_im_fx, 1 ) );
3836 : #else
3837 : Cldfb_ImagBuffer_fx[j][k][l] = Madd_32_32( Cldfb_ImagBuffer_fx[j][k][l], g_fx, *tc_im_fx );
3838 : #endif
3839 : #else
3840 : #ifdef FIX_CDLFB_BUFFER_SCALING
3841 : Cldfb_ImagBuffer_fx[j2][k][l] = Madd_32_32( Cldfb_ImagBuffer_fx[j2][k][l], g_fx, L_shl( *tc_im_fx, 1 ) );
3842 : #else
3843 : Cldfb_ImagBuffer_fx[j2][k][l] = Madd_32_32( Cldfb_ImagBuffer_fx[j2][k][l], g_fx, *tc_im_fx );
3844 : #endif
3845 : #endif
3846 53424000 : move32();
3847 : #ifdef FIX_1917_DIRAC_RENDER_PTR_INCR
3848 53424000 : tc_im_fx++;
3849 : #else
3850 : tc_re_fx++;
3851 : #endif
3852 : }
3853 1012304 : w1_fx += hSpatParamRendCom->num_freq_bands;
3854 : }
3855 : }
3856 : /* update here only in case of head rotation */
3857 484000 : test();
3858 484000 : IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) )
3859 : {
3860 0 : st_ivas->hIsmRendererData->prev_gains_fx[i][j] = gain_fx;
3861 0 : move32();
3862 : }
3863 : }
3864 : }
3865 : #ifndef NONBE_FIX_1141_OSBA_ROOM_RENDERING
3866 : }
3867 : #endif
3868 : #ifdef NONBE_FIX_1141_OSBA_ROOM_RENDERING
3869 12000 : st_ivas->hIsmRendererData->interp_offset_fx = add( st_ivas->hIsmRendererData->interp_offset_fx, i_mult( hSpatParamRendCom->num_freq_bands, st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->subframes_rendered] ) );
3870 : #endif
3871 : }
3872 :
3873 : /* Perform binaural rendering */
3874 : Word16 input_q;
3875 120202 : input_q = Q6;
3876 120202 : move16();
3877 :
3878 120202 : IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
3879 : {
3880 0 : IF( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
3881 : {
3882 0 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3883 : {
3884 0 : FOR( ch = 0; ch < st_ivas->hBinRenderer->nInChannels; ch++ )
3885 : {
3886 0 : Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer_fx[ch][add( slot_idx_start, slot_idx )], hSpatParamRendCom->num_freq_bands );
3887 0 : Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer_fx[ch][add( slot_idx_start, slot_idx )], hSpatParamRendCom->num_freq_bands );
3888 : }
3889 : }
3890 0 : st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
3891 0 : move16();
3892 : }
3893 : }
3894 :
3895 : /*Binaural output in Q6 format*/
3896 120202 : ivas_binRenderer_fx( st_ivas->hBinRenderer,
3897 0 : ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData,
3898 : st_ivas->hCombinedOrientationData,
3899 120202 : hSpatParamRendCom->subframe_nbslots[subframe_idx],
3900 : Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx,
3901 : Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, &input_q );
3902 :
3903 : Word16 pos_idx;
3904 120202 : IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
3905 : {
3906 0 : FOR( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
3907 : {
3908 0 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3909 : {
3910 0 : FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
3911 : {
3912 0 : Copy32( Cldfb_RealBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_idx_start, slot_idx )], hSpatParamRendCom->num_freq_bands ); // Q6
3913 0 : Copy32( Cldfb_ImagBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_idx_start, slot_idx )], hSpatParamRendCom->num_freq_bands ); // Q6
3914 : }
3915 : }
3916 : }
3917 : }
3918 :
3919 : /* Inverse CLDFB*/
3920 360606 : FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
3921 : {
3922 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
3923 240404 : Word32 *synth_fx = &output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands];
3924 : Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
3925 : Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
3926 1198100 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
3927 : {
3928 957696 : RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[0][ch][i];
3929 957696 : move32();
3930 957696 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[0][ch][i];
3931 957696 : move32();
3932 : }
3933 :
3934 240404 : scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); // Q6-1
3935 240404 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = ( Q6 - 1 );
3936 240404 : move16();
3937 :
3938 240404 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, synth_fx, i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), 0, 0, st_ivas->cldfbSynDec[ch] );
3939 :
3940 240404 : Word16 no_col = st_ivas->cldfbSynDec[ch]->no_col;
3941 240404 : move16();
3942 240404 : Word16 no_channels = st_ivas->cldfbSynDec[ch]->no_channels;
3943 240404 : move16();
3944 240404 : Word16 samplesToProcess = i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
3945 240404 : move16();
3946 240404 : IF( GT_16( samplesToProcess, -1 ) )
3947 : {
3948 : Word16 tmp, tmp_e;
3949 240404 : tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[ch]->no_channels, 1 ) ), st_ivas->cldfbSynDec[ch]->no_channels, &tmp_e );
3950 240404 : tmp = shr( tmp, 15 - tmp_e );
3951 240404 : no_col = s_min( no_col, tmp );
3952 : }
3953 240404 : Word16 synth_len = imult1616( no_col, no_channels );
3954 :
3955 240404 : scale_sig32( synth_fx, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11
3956 : }
3957 : }
3958 187729 : ELSE IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
3959 : {
3960 1526167 : FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
3961 : {
3962 6986480 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3963 : {
3964 5577264 : Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], pppQMfFrame_ts_re_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands ); // Q6
3965 5577264 : Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], pppQMfFrame_ts_im_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands ); // Q6
3966 : }
3967 : }
3968 : }
3969 : ELSE
3970 : {
3971 : Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
3972 : Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
3973 : Word16 outchannels;
3974 :
3975 70778 : idx_in = 0;
3976 70778 : move16();
3977 70778 : idx_lfe = 0;
3978 70778 : move16();
3979 :
3980 70778 : outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
3981 :
3982 70778 : test();
3983 70778 : test();
3984 70778 : test();
3985 70778 : test();
3986 70778 : test();
3987 70778 : test();
3988 70778 : test();
3989 70778 : IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
3990 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
3991 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
3992 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
3993 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
3994 : ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
3995 : {
3996 880 : outchannels = add( outchannels, 1 );
3997 : }
3998 :
3999 70778 : test();
4000 70778 : IF( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
4001 0 : {
4002 : Word32 tmp_separated_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
4003 : Word32 tmp_lfe_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
4004 0 : const Word16 subframe_start_sample = imult1616( index_slot, hSpatParamRendCom->num_freq_bands );
4005 0 : const Word16 num_samples_subframe = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4006 :
4007 : /* Move the separated and the LFE channels to temporary variables as spatial synthesis may overwrite current channels */
4008 0 : Copy32( &( output_buf_fx[st_ivas->hOutSetup.separateChannelIndex][subframe_start_sample] ), tmp_separated_fx, num_samples_subframe );
4009 : #ifdef NONBE_1250_MCMASA_LS_OUTPUT
4010 0 : if ( hDirACRend->hOutSetup.num_lfe > 0 )
4011 : {
4012 0 : Copy32( &( output_buf_fx[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe_fx, num_samples_subframe );
4013 : }
4014 : #else
4015 : Copy32( &( output_buf_fx[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe_fx, num_samples_subframe );
4016 : #endif
4017 :
4018 0 : FOR( ch = 0; ch < outchannels; ch++ )
4019 : {
4020 :
4021 0 : test();
4022 0 : test();
4023 0 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
4024 : {
4025 : /* Move the LFE channel to the correct place */
4026 0 : Copy32( tmp_lfe_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe );
4027 :
4028 0 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
4029 : {
4030 0 : idx_lfe = add( idx_lfe, 1 );
4031 : }
4032 : }
4033 0 : ELSE IF( ( st_ivas->hLsSetupCustom->separate_ch_found ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
4034 : {
4035 : /* Move the separated channel to the correct place. Thus, the separated channel is
4036 : * combined with the synthesized channels here when there is a matching channel. */
4037 0 : Copy32( tmp_separated_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe );
4038 : }
4039 : ELSE
4040 : {
4041 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
4042 0 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
4043 : {
4044 0 : RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i];
4045 0 : move32();
4046 0 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i];
4047 0 : move32();
4048 : }
4049 0 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe, 0, 0, st_ivas->cldfbSynDec[idx_in] );
4050 :
4051 0 : IF( !st_ivas->hLsSetupCustom->separate_ch_found )
4052 : {
4053 : /* Pan the separated channel and mix with the synthesized channels. Thus, the separated channel
4054 : * is combined with the synthesized channels here when there is no matching channel. */
4055 0 : v_multc_acc_32_16( tmp_separated_fx, st_ivas->hLsSetupCustom->separate_ch_gains_fx[idx_in], &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe );
4056 : }
4057 :
4058 0 : idx_in = add( idx_in, 1 );
4059 : }
4060 : }
4061 : }
4062 : ELSE
4063 : {
4064 542469 : FOR( ch = 0; ch < outchannels; ch++ )
4065 : {
4066 :
4067 471691 : test();
4068 471691 : test();
4069 471691 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
4070 : {
4071 41475 : test();
4072 41475 : test();
4073 41475 : IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
4074 6640 : {
4075 33200 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
4076 : {
4077 26560 : RealBuffer_fx[i] = Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i];
4078 26560 : move32();
4079 26560 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i];
4080 26560 : move32();
4081 : }
4082 6640 : Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
4083 6640 : Word16 samplesToProcess = i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4084 6640 : Word32 *p_out = &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] );
4085 :
4086 6640 : scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); // Q6-1
4087 6640 : st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = ( Q6 - 1 );
4088 6640 : move16();
4089 6640 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, 0, 0, st_ivas->cldfbSynDec[cldfbSynIdx] );
4090 :
4091 : // Calculating length of output
4092 6640 : Word16 no_col = st_ivas->cldfbSynDec[cldfbSynIdx]->no_col;
4093 6640 : move16();
4094 6640 : Word16 no_channels = st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels;
4095 6640 : move16();
4096 6640 : IF( GT_16( samplesToProcess, -1 ) )
4097 : {
4098 : Word16 tmp, tmp_e;
4099 6640 : tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, 1 ) ), st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, &tmp_e );
4100 6640 : tmp = shr( tmp, 15 - tmp_e );
4101 6640 : no_col = s_min( no_col, tmp );
4102 : }
4103 6640 : Word16 synth_len = imult1616( no_col, no_channels );
4104 :
4105 6640 : scale_sig32( p_out, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11
4106 : }
4107 34835 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && hDirACRend->hOutSetup.separateChannelEnabled )
4108 : {
4109 : /* LFE has been synthesized in the time domain, do nothing. */
4110 : }
4111 : ELSE
4112 : {
4113 33955 : set32_fx( &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) );
4114 : }
4115 41475 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
4116 : {
4117 0 : idx_lfe = add( idx_lfe, 1 );
4118 : }
4119 : }
4120 430216 : ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
4121 : {
4122 : /* The separated channel is already set to output_f[hOutSetup.separateChannelIndex]. Thus, the separated
4123 : * channel is combined with the synthesized channels here. */
4124 : }
4125 : ELSE
4126 : {
4127 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
4128 429336 : Word32 *p_out = &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] );
4129 : Word16 samplesToProcess, out_len;
4130 2143150 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
4131 : {
4132 1713814 : RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i]; // Q6
4133 1713814 : move32();
4134 1713814 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i]; // Q6
4135 1713814 : move32();
4136 : }
4137 429336 : samplesToProcess = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4138 :
4139 : // Calculating length of processed output
4140 429336 : Word16 no_col = st_ivas->cldfbSynDec[idx_in]->no_col;
4141 429336 : move16();
4142 429336 : Word16 no_channels = st_ivas->cldfbSynDec[idx_in]->no_channels;
4143 429336 : move16();
4144 429336 : IF( GT_16( samplesToProcess, -1 ) )
4145 : {
4146 : Word16 tmp, tmp_e;
4147 429336 : tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[idx_in]->no_channels, 1 ) ), st_ivas->cldfbSynDec[idx_in]->no_channels, &tmp_e );
4148 429336 : tmp = shr( tmp, 15 - tmp_e );
4149 429336 : no_col = s_min( no_col, tmp );
4150 : }
4151 429336 : out_len = imult1616( no_col, no_channels );
4152 :
4153 : // Scaling cldfb_state to Q6-1
4154 429336 : scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) );
4155 429336 : st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = ( Q6 - 1 );
4156 429336 : move16();
4157 429336 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, 0, 0, st_ivas->cldfbSynDec[idx_in] );
4158 :
4159 : // Scaling output from Q6-1 to Q11
4160 429336 : Scale_sig32( p_out, out_len, ( Q11 - ( Q6 - 1 ) ) );
4161 :
4162 429336 : idx_in = add( idx_in, 1 );
4163 : }
4164 : }
4165 : }
4166 : }
4167 :
4168 307931 : hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4169 307931 : move16();
4170 307931 : hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 );
4171 307931 : move16();
4172 :
4173 :
4174 307931 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4175 : {
4176 231804 : hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev;
4177 231804 : move16();
4178 231804 : hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev;
4179 231804 : move16();
4180 : }
4181 :
4182 307931 : test();
4183 307931 : test();
4184 307931 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
4185 : {
4186 360606 : FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ )
4187 : {
4188 240404 : scale_sig32( st_ivas->cldfbSynDec[i]->cldfb_state_fx, st_ivas->cldfbSynDec[i]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[i]->Q_cldfb_state ) ); // Q11
4189 240404 : st_ivas->cldfbSynDec[i]->Q_cldfb_state = Q11;
4190 240404 : move16();
4191 : }
4192 : }
4193 187729 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
4194 : {
4195 : }
4196 : ELSE
4197 : {
4198 : Word16 outchannels;
4199 70778 : idx_lfe = 0;
4200 70778 : move16();
4201 70778 : idx_in = 0;
4202 70778 : move16();
4203 70778 : outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
4204 :
4205 70778 : test();
4206 70778 : test();
4207 70778 : test();
4208 70778 : test();
4209 70778 : test();
4210 70778 : test();
4211 70778 : test();
4212 70778 : IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
4213 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
4214 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
4215 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
4216 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
4217 : ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
4218 : {
4219 880 : outchannels = add( outchannels, 1 );
4220 : }
4221 :
4222 70778 : test();
4223 70778 : IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) )
4224 : {
4225 0 : FOR( ch = 0; ch < outchannels; ch++ )
4226 : {
4227 0 : test();
4228 0 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
4229 : {
4230 0 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
4231 : {
4232 0 : idx_lfe = add( idx_lfe, 1 );
4233 : }
4234 : }
4235 : }
4236 : }
4237 : ELSE
4238 : {
4239 542469 : FOR( ch = 0; ch < outchannels; ch++ )
4240 : {
4241 :
4242 471691 : test();
4243 471691 : test();
4244 471691 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
4245 : {
4246 41475 : test();
4247 41475 : IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
4248 : {
4249 6640 : Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
4250 6640 : scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); // Q11
4251 6640 : st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11;
4252 6640 : move16();
4253 : }
4254 : }
4255 430216 : ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled == 0 ) || NE_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
4256 : {
4257 429336 : scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); // Q11
4258 429336 : st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11;
4259 429336 : move16();
4260 429336 : idx_in = add( idx_in, 1 );
4261 : }
4262 : }
4263 : }
4264 70778 : test();
4265 70778 : IF( !hDirACRend->hOutSetup.separateChannelEnabled || NE_32( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
4266 : {
4267 70778 : Word16 tmp_lfe_idx = 0;
4268 70778 : move16();
4269 542469 : FOR( ch = 0; ch < outchannels; ch++ )
4270 : {
4271 471691 : test();
4272 471691 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( EQ_16( hDirACRend->hOutSetup.index_lfe[tmp_lfe_idx], ch ) ) )
4273 : {
4274 41475 : IF( LT_16( tmp_lfe_idx, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
4275 : {
4276 0 : tmp_lfe_idx = add( tmp_lfe_idx, 1 );
4277 : }
4278 : }
4279 : }
4280 : }
4281 : }
4282 :
4283 307931 : pop_wmops();
4284 :
4285 307931 : return;
4286 : }
|