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 2245 : 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 38165 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
154 : {
155 35920 : ls_azimuth_fx[i] = 0;
156 35920 : move32();
157 35920 : ls_elevation_fx[i] = 0;
158 35920 : move32();
159 : }
160 :
161 2245 : IF( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) )
162 : {
163 690 : flag_config = DIRAC_RECONFIGURE;
164 690 : move32();
165 : }
166 : ELSE
167 : {
168 1555 : flag_config = flag_config_inp;
169 1555 : move32();
170 : }
171 2245 : error = IVAS_ERR_OK;
172 2245 : move32();
173 :
174 2245 : hDirACRend = NULL;
175 2245 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
176 2245 : move32();
177 2245 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
178 2245 : move32();
179 2245 : hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order );
180 :
181 2245 : hDirAC = st_ivas->hDirAC;
182 2245 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
183 :
184 2245 : IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) )
185 : {
186 1842 : 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 2245 : nchan_transport_old = 0;
204 2245 : move16();
205 2245 : num_outputs_dir_old = 0;
206 2245 : move16();
207 2245 : num_outputs_diff_old = 0;
208 2245 : move16();
209 2245 : num_protos_diff_old = 0;
210 2245 : move16();
211 :
212 2245 : nchan_transport_orig = st_ivas->nchan_transport;
213 2245 : move16();
214 2245 : test();
215 2245 : 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 2245 : nchan_transport = st_ivas->nchan_transport;
222 2245 : move16();
223 2245 : test();
224 2245 : test();
225 2245 : 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 275 : nchan_transport = 1;
228 275 : move16();
229 : }
230 2245 : test();
231 2245 : test();
232 2245 : 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 2245 : hDirACRend->hOutSetup = st_ivas->hIntSetup;
243 2245 : nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE;
244 2245 : move16();
245 :
246 2245 : test();
247 2245 : 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 2245 : 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 1203 : ELSE IF( GE_16( hDirACRend->hOutSetup.ambisonics_order, SBA_FOA_ORDER ) )
265 : {
266 1203 : Copy32( ls_azimuth_4d4_fx, ls_azimuth_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS );
267 1203 : Copy32( ls_elevation_4d4_fx, ls_elevation_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS );
268 : }
269 :
270 2245 : test();
271 2245 : test();
272 2245 : test();
273 2245 : test();
274 2245 : test();
275 2245 : test();
276 2245 : test();
277 2245 : 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 2245 : st_ivas->nchan_transport = nchan_transport_orig;
293 2245 : move16();
294 :
295 2245 : test();
296 2245 : test();
297 2245 : test();
298 2245 : test();
299 2245 : test();
300 2245 : test();
301 2245 : test();
302 2245 : test();
303 2245 : test();
304 2245 : test();
305 2245 : test();
306 2245 : 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 2199 : 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 2090 : 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 1260 : 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 408 : hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD;
332 408 : move32();
333 408 : hDirACRend->panningConf = DIRAC_PANNING_HOA3;
334 408 : 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 2245 : 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 2245 : test();
355 2245 : test();
356 2245 : test();
357 2245 : 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 2109 : test();
373 2109 : IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->masa_stereo_type_detect != NULL )
374 : {
375 24 : free( hDirACRend->masa_stereo_type_detect );
376 : }
377 2109 : hDirACRend->masa_stereo_type_detect = NULL;
378 : }
379 :
380 2245 : hSpatParamRendCom->numIsmDirections = 0; /* By default, no ism directions, set correct number runtime when needed */
381 2245 : move16();
382 :
383 : /*-----------------------------------------------------------------*
384 : * (re)configure sub-modules
385 : *-----------------------------------------------------------------*/
386 :
387 : /* prototype signal computation */
388 2245 : IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) )
389 : {
390 1842 : num_outputs_dir_old = hDirACRend->num_outputs_dir;
391 1842 : move16();
392 1842 : num_outputs_diff_old = hDirACRend->num_outputs_diff;
393 1842 : move16();
394 1842 : num_protos_diff_old = hDirACRend->num_protos_diff;
395 1842 : move16();
396 : }
397 :
398 : /* allocate output setup related arrays */
399 2245 : 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 1369 : 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 517 : ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) )
417 : {
418 408 : hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS;
419 408 : move16();
420 408 : hDirACRend->num_outputs_dir = nchan_out_woLFE;
421 408 : 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 2245 : 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 2245 : test();
452 2245 : 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 2245 : set16_fx( hDirACRend->proto_index_dir, 0, hDirACRend->num_outputs_dir );
461 :
462 2245 : test();
463 2245 : 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 2245 : set16_fx( hDirACRend->proto_index_diff, 0, hDirACRend->num_outputs_diff );
472 :
473 2245 : hDirACRend->sba_map_tc = sba_map_tc;
474 :
475 2245 : test();
476 2245 : 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 2245 : IF( EQ_16( nchan_transport, 1 ) )
486 : {
487 482 : hDirACRend->num_protos_ambi = 1;
488 482 : move16();
489 482 : hDirACRend->num_protos_dir = 1;
490 482 : move16();
491 482 : hDirACRend->num_protos_diff = 1;
492 482 : 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 2245 : test();
603 : /* direct/diffuse responses */
604 2245 : 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 1842 : 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 2245 : test();
623 2245 : test();
624 2245 : 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 1393 : initDiffuseResponses_fx( hDirACRend->diffuse_response_function_fx, nchan_out_woLFE, hDirACRend->hOutSetup.output_config,
627 1393 : 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 2245 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) )
636 : {
637 408 : test();
638 408 : test();
639 408 : 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 399 : 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 408 : set32_fx( hDirACRend->hoa_encoder_fx, 0, nchan_out_woLFE * hDirACRend->num_outputs_diff );
656 408 : 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 2245 : if ( EQ_16( flag_config, DIRAC_OPEN ) )
670 : {
671 403 : st_ivas->hVBAPdata = NULL;
672 : }
673 :
674 2245 : test();
675 2245 : 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 1369 : 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 1260 : 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 2245 : 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 2245 : IF( flag_config == DIRAC_RECONFIGURE )
728 : {
729 1842 : proto_signal_decorr_on_old = hDirACRend->proto_signal_decorr_on;
730 1842 : move16();
731 : }
732 : ELSE
733 : {
734 403 : proto_signal_decorr_on_old = 0;
735 403 : move16();
736 : }
737 2245 : hDirACRend->proto_signal_decorr_on = 1;
738 2245 : move16();
739 2245 : test();
740 2245 : 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 2245 : if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
747 : {
748 109 : hDirACRend->proto_signal_decorr_on = 0;
749 109 : move16();
750 : }
751 :
752 2245 : test();
753 2245 : test();
754 2245 : test();
755 2245 : test();
756 2245 : test();
757 2245 : test();
758 2245 : test();
759 2245 : test();
760 2245 : 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 1876 : 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 1852 : ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old )
785 : {
786 1721 : test();
787 1721 : test();
788 1721 : 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 1721 : IF( GT_16( nchan_transport, 2 ) )
792 : {
793 623 : nchan_transport_tmp = 4;
794 623 : move16();
795 : }
796 : ELSE
797 : {
798 1098 : nchan_transport_tmp = nchan_transport;
799 1098 : move16();
800 : }
801 :
802 : /* close and reopen the decorrelator */
803 1721 : ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state );
804 :
805 1721 : 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 2245 : test();
816 2245 : test();
817 2245 : 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 1842 : 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 1819 : ivas_dirac_dec_output_synthesis_close_fx( hDirACRend );
829 :
830 1819 : 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 1819 : hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on;
835 1819 : move16();
836 : }
837 :
838 2245 : test();
839 2245 : if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
840 : {
841 1260 : hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0;
842 1260 : move16();
843 : }
844 :
845 : /*-----------------------------------------------------------------*
846 : * memory allocation
847 : *-----------------------------------------------------------------*/
848 :
849 2245 : 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 1393 : test();
861 1393 : test();
862 1393 : test();
863 1393 : 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 1171 : 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 1393 : hDirACRend->proto_frame_f_len = imult1616( 2, imult1616( hDirACRend->num_protos_diff, hSpatParamRendCom->num_freq_bands ) );
880 1393 : move16();
881 : }
882 :
883 2245 : if ( EQ_16( flag_config, DIRAC_OPEN ) )
884 : {
885 403 : hDirACRend->buffer_energy_fx = NULL;
886 : }
887 :
888 2245 : test();
889 2245 : test();
890 2245 : test();
891 2245 : test();
892 2245 : test();
893 2245 : test();
894 2245 : test();
895 2245 : test();
896 2245 : 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 2025 : 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 2245 : ivas_dirac_dec_output_synthesis_init_fx( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag );
944 :
945 : /* Allocate stack memory */
946 2245 : IF( NE_16( flag_config, DIRAC_OPEN ) )
947 : {
948 1842 : ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) );
949 : }
950 2245 : 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 2245 : if ( EQ_16( flag_config, DIRAC_OPEN ) )
956 : {
957 403 : st_ivas->hDirACRend = hDirACRend;
958 : }
959 :
960 2245 : 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 2185 : st_ivas->hDirAC->hConfig->dec_param_estim = FALSE;
1043 2185 : 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 2185 : case RENDERER_BINAURAL_PARAMETRIC:
1056 : case RENDERER_BINAURAL_PARAMETRIC_ROOM:
1057 : case RENDERER_STEREO_PARAMETRIC:
1058 2185 : need_parambin = 1;
1059 2185 : move16();
1060 2185 : BREAK;
1061 2281 : default:
1062 2281 : need_parambin = 0;
1063 2281 : move16();
1064 : }
1065 :
1066 4466 : IF( !need_parambin )
1067 : {
1068 2281 : 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 2245 : 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 2245 : need_dirac_rend = 1;
1083 2245 : move16();
1084 2245 : BREAK;
1085 2221 : default:
1086 2221 : need_dirac_rend = 0;
1087 2221 : move16();
1088 : }
1089 :
1090 4466 : IF( !need_dirac_rend )
1091 : {
1092 2221 : 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 2245 : IF( st_ivas->hDirACRend == NULL )
1118 : {
1119 403 : rend_config_flag = DIRAC_OPEN;
1120 403 : move32();
1121 : }
1122 : ELSE
1123 : {
1124 1842 : rend_config_flag = flag_config_inp;
1125 1842 : move32();
1126 : }
1127 2245 : 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 2185 : IF( NE_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
1136 : {
1137 1520 : 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 2185 : IF( st_ivas->hDiracDecBin[0] == NULL )
1144 : {
1145 364 : IF( NE_32( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, &( st_ivas->hHrtfParambin ) ) ), IVAS_ERR_OK ) )
1146 : {
1147 0 : return error;
1148 : }
1149 : }
1150 : ELSE
1151 : {
1152 : /* This is required to keep BE in rate switching. This probably means that 1TC and 2TC MASA perform differently. */
1153 1821 : test();
1154 1821 : test();
1155 1821 : IF( st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_params != NULL && !( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && st_ivas->nSCE > 0 ) )
1156 : {
1157 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
1158 : }
1159 :
1160 1821 : 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 ) )
1161 : {
1162 0 : return error;
1163 : }
1164 :
1165 : /* copy td-decorr flag to split renderer side rendereres */
1166 1821 : FOR( pos_idx = 1; pos_idx < num_poses; pos_idx++ )
1167 : {
1168 0 : st_ivas->hDiracDecBin[pos_idx]->useTdDecorr = st_ivas->hDiracDecBin[0]->useTdDecorr;
1169 : }
1170 :
1171 1821 : IF( !st_ivas->hDiracDecBin[0]->useTdDecorr )
1172 : {
1173 1044 : IF( st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_params == NULL )
1174 : {
1175 : Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX];
1176 :
1177 801 : ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands );
1178 :
1179 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,
1180 : DIRAC_SYNTHESIS_PSD_LS, frequency_axis_fx, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs ) ),
1181 : IVAS_ERR_OK ) )
1182 : {
1183 0 : return error;
1184 : }
1185 : }
1186 : }
1187 :
1188 3642 : FOR( pos_idx = 0; pos_idx < num_poses; pos_idx++ )
1189 : {
1190 1821 : st_ivas->hDiracDecBin[pos_idx]->reqularizationFactor_fx = configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate );
1191 1821 : move16();
1192 : }
1193 : }
1194 : }
1195 : }
1196 :
1197 :
1198 4466 : return error;
1199 : }
1200 :
1201 : /*-------------------------------------------------------------------------
1202 : * ivas_dirac_dec_close()
1203 : *
1204 : * Close DirAC memories
1205 : *------------------------------------------------------------------------*/
1206 1678 : void ivas_dirac_dec_close_fx(
1207 : DIRAC_DEC_HANDLE *hDirAC_out )
1208 : {
1209 : DIRAC_DEC_HANDLE hDirAC;
1210 :
1211 1678 : test();
1212 1678 : IF( hDirAC_out == NULL || *hDirAC_out == NULL )
1213 : {
1214 1167 : return;
1215 : }
1216 :
1217 511 : hDirAC = *hDirAC_out;
1218 :
1219 : /* Config & CLDFB */
1220 511 : IF( hDirAC->hConfig != NULL )
1221 : {
1222 511 : free( hDirAC->hConfig );
1223 511 : hDirAC->hConfig = NULL;
1224 : }
1225 :
1226 511 : free( *hDirAC_out );
1227 511 : *hDirAC_out = NULL;
1228 :
1229 511 : return;
1230 : }
1231 : /*-------------------------------------------------------------------------
1232 : * ivas_dirac_dec_read_BS_fx()
1233 : *
1234 : * Read DirAC parameters from the bitstream
1235 : *------------------------------------------------------------------------*/
1236 154022 : void ivas_dirac_dec_read_BS_fx(
1237 : const Word32 ivas_total_brate, /* i : IVAS total bitrate */
1238 : Decoder_State *st, /* i/o: decoder state structure */
1239 : DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */
1240 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial rendering data handle */
1241 : IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata */
1242 : Word16 *nb_bits, /* o : number of bits read */
1243 : const Word16 last_bit_pos, /* i : last read bitstream position */
1244 : const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */
1245 : const Word16 nchan_transport, /* i : number of transport channels */
1246 : Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */
1247 : )
1248 : {
1249 : Word16 i, j, b, dir, orig_dirac_bands;
1250 : Word16 next_bit_pos_orig;
1251 : Word32 quo, rem;
1252 :
1253 154022 : test();
1254 154022 : test();
1255 154022 : IF( !st->bfi && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
1256 : {
1257 147070 : next_bit_pos_orig = st->next_bit_pos;
1258 147070 : move16();
1259 147070 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
1260 147070 : st->next_bit_pos = extract_l( L_sub( quo, 1 ) );
1261 147070 : move16();
1262 147070 : if ( last_bit_pos > 0 )
1263 : {
1264 33885 : st->next_bit_pos = last_bit_pos;
1265 33885 : move16();
1266 : }
1267 : /* 1 bit flag for signaling metadata to read */
1268 147070 : b = st->bit_stream[( st->next_bit_pos )--];
1269 147070 : move16();
1270 147070 : ( *nb_bits )++;
1271 :
1272 147070 : IF( EQ_16( b, 1 ) ) /* WB 4TCs condition, no other metadata to read*/
1273 : {
1274 388 : orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands;
1275 388 : move16();
1276 :
1277 388 : hQMetaData->sba_inactive_mode = 1;
1278 388 : move16();
1279 :
1280 : /* if we start with a SID frame, we need to init the azi/ele arrays.*/
1281 388 : IF( st->ini_frame == 0 )
1282 : {
1283 0 : FOR( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ )
1284 : {
1285 0 : set32_fx( hQMetaData->q_direction[0].band_data[b].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
1286 0 : set32_fx( hQMetaData->q_direction[0].band_data[b].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
1287 : }
1288 : }
1289 :
1290 388 : *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), nchan_transport, NULL, SBA_FORMAT ) );
1291 388 : move16();
1292 1940 : FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
1293 : {
1294 1552 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0];
1295 1552 : move32();
1296 1552 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0];
1297 1552 : move32();
1298 1552 : 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];
1299 1552 : move32();
1300 1552 : 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];
1301 1552 : move16();
1302 : }
1303 1940 : FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
1304 : {
1305 4656 : FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- )
1306 : {
1307 3104 : hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0];
1308 3104 : move32();
1309 3104 : hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0];
1310 3104 : move32();
1311 3104 : hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[0];
1312 3104 : move32();
1313 3104 : hQMetaData->q_direction[0].band_data[j].energy_ratio_index[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_index[0];
1314 3104 : move16();
1315 : }
1316 : }
1317 :
1318 388 : hQMetaData->q_direction->cfg.nbands = orig_dirac_bands;
1319 388 : move16();
1320 : }
1321 : ELSE
1322 : {
1323 146682 : hQMetaData->sba_inactive_mode = 0;
1324 146682 : move16();
1325 146682 : hQMetaData->is_masa_ivas_format = 0;
1326 146682 : move16();
1327 146682 : IF( hQMetaData->useLowerRes )
1328 : {
1329 11258 : hQMetaData->q_direction[0].cfg.nblocks = 1;
1330 11258 : move16();
1331 : }
1332 : ELSE
1333 : {
1334 135424 : hQMetaData->q_direction[0].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES;
1335 135424 : move16();
1336 : }
1337 146682 : *nb_bits = add( *nb_bits, ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), hodirac_flag ) );
1338 146682 : move16();
1339 : }
1340 :
1341 147070 : st->next_bit_pos = next_bit_pos_orig;
1342 147070 : move16();
1343 : }
1344 6952 : ELSE IF( !st->bfi && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
1345 : {
1346 113 : next_bit_pos_orig = st->next_bit_pos;
1347 113 : move16();
1348 :
1349 : /* subtract mode signaling bits, since bitstream was moved after mode reading */
1350 113 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
1351 113 : st->next_bit_pos = extract_l( L_sub( L_sub( quo, 1 ), SID_FORMAT_NBITS + SBA_PLANAR_BITS + SBA_ORDER_BITS ) );
1352 :
1353 113 : move16();
1354 : /* 1 bit flag for signaling metadata to read */
1355 113 : b = st->bit_stream[( st->next_bit_pos )--];
1356 113 : move16();
1357 113 : ( *nb_bits )++;
1358 113 : hQMetaData->sba_inactive_mode = 1;
1359 113 : move16();
1360 113 : orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands;
1361 113 : move16();
1362 :
1363 : /* if we start with a SID frame, we need to init the azi/ele arrays.*/
1364 113 : IF( st->ini_frame == 0 )
1365 : {
1366 0 : FOR( dir = 0; dir < hQMetaData->no_directions; dir++ )
1367 : {
1368 0 : FOR( b = 0; b < hQMetaData->q_direction[dir].cfg.nbands; b++ )
1369 : {
1370 0 : set32_fx( hQMetaData->q_direction[dir].band_data[b].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
1371 0 : set32_fx( hQMetaData->q_direction[dir].band_data[b].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
1372 : }
1373 : }
1374 : }
1375 113 : *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), nchan_transport, NULL, SBA_FORMAT ) );
1376 113 : move16();
1377 :
1378 565 : FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
1379 : {
1380 452 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0];
1381 452 : move32();
1382 452 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0];
1383 452 : move32();
1384 452 : 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];
1385 452 : move32();
1386 452 : 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];
1387 452 : move16();
1388 : }
1389 565 : FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
1390 : {
1391 1356 : FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- )
1392 : {
1393 904 : hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0];
1394 904 : move32();
1395 904 : hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0];
1396 904 : move32();
1397 904 : hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[0];
1398 904 : move32();
1399 904 : hQMetaData->q_direction[0].band_data[j].energy_ratio_index[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_index[0];
1400 904 : move16();
1401 : }
1402 : }
1403 :
1404 113 : hQMetaData->q_direction->cfg.nbands = orig_dirac_bands;
1405 113 : move16();
1406 :
1407 113 : st->next_bit_pos = next_bit_pos_orig;
1408 113 : move16();
1409 : }
1410 :
1411 154022 : test();
1412 154022 : IF( hDirAC != NULL && hSpatParamRendCom != NULL )
1413 : {
1414 99102 : ivas_qmetadata_to_dirac_fx( hQMetaData, hDirAC, NULL, hSpatParamRendCom, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands );
1415 : }
1416 :
1417 154022 : return;
1418 : }
1419 : /*-----------------------------------------------------------------------*
1420 : * ivas_qmetadata_to_dirac()
1421 : *
1422 : * Copy qmetedata to DirAC parameters for rendering
1423 : *-----------------------------------------------------------------------*/
1424 139672 : void ivas_qmetadata_to_dirac_fx(
1425 : const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */
1426 : DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */
1427 : MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */
1428 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
1429 : const Word32 ivas_total_brate, /* i : IVAS total bitrate */
1430 : const IVAS_FORMAT ivas_format, /* i : IVAS format */
1431 : const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */
1432 : Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands Q0*/
1433 : )
1434 : {
1435 : Word16 block, band;
1436 : Word16 *seed_ptr;
1437 : Word16 band_start, band_end, diff_idx;
1438 : Word16 b, ele, azi;
1439 : Word32 azimuth_fx, elevation_fx;
1440 : Word32 diffuseness_fx;
1441 : IVAS_QDIRECTION *q_direction;
1442 : Word16 *band_mapping;
1443 : Word16 *band_grouping;
1444 : Word16 start_band;
1445 139672 : Word16 nbands = 0;
1446 139672 : move16();
1447 139672 : Word16 nblocks = 0;
1448 139672 : move16();
1449 : Word16 qBand_idx;
1450 139672 : Word16 idx_sec = 0;
1451 139672 : move16();
1452 139672 : Word16 no_secs = 1;
1453 139672 : move16();
1454 139672 : q_direction = &( hQMetaData->q_direction[0] );
1455 :
1456 139672 : hSpatParamRendCom->numParametricDirections = hQMetaData->no_directions;
1457 139672 : move16();
1458 139672 : hSpatParamRendCom->numSimultaneousDirections = add( hSpatParamRendCom->numParametricDirections, hSpatParamRendCom->numIsmDirections );
1459 139672 : move16();
1460 139672 : test();
1461 139672 : IF( hMasa != NULL && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
1462 39459 : {
1463 : Word16 meta_write_index;
1464 39459 : band_mapping = hMasa->data.band_mapping;
1465 39459 : move16();
1466 :
1467 197295 : FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
1468 : {
1469 157836 : meta_write_index = add( hSpatParamRendCom->dirac_bs_md_write_idx, block ) % hSpatParamRendCom->dirac_md_buffer_length;
1470 :
1471 1345796 : FOR( band = 0; band < hMasa->config.numCodingBands; ++band )
1472 : {
1473 9971960 : FOR( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b )
1474 : {
1475 : /* Right shifting -1 -> -1, Hence this change is done */
1476 8784000 : Word32 L_tmp = L_abs( q_direction->band_data[band].azimuth_fx[block] );
1477 8784000 : hSpatParamRendCom->azimuth[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
1478 8784000 : move16();
1479 :
1480 8784000 : IF( q_direction->band_data[band].azimuth_fx[block] < 0 )
1481 : {
1482 4666263 : hSpatParamRendCom->azimuth[meta_write_index][b] = negate( hSpatParamRendCom->azimuth[meta_write_index][b] );
1483 4666263 : move16();
1484 : }
1485 :
1486 8784000 : L_tmp = L_abs( q_direction->band_data[band].elevation_fx[block] );
1487 8784000 : hSpatParamRendCom->elevation[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
1488 8784000 : move16();
1489 :
1490 8784000 : IF( q_direction->band_data[band].elevation_fx[block] < 0 )
1491 : {
1492 2790295 : hSpatParamRendCom->elevation[meta_write_index][b] = negate( hSpatParamRendCom->elevation[meta_write_index][b] );
1493 2790295 : move16();
1494 : }
1495 :
1496 8784000 : hSpatParamRendCom->energy_ratio1_fx[meta_write_index][b] = q_direction->band_data[band].energy_ratio_fx[block];
1497 8784000 : move32();
1498 8784000 : hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_sub( ONE_IN_Q30, q_direction->band_data[band].energy_ratio_fx[block] );
1499 8784000 : move32();
1500 :
1501 8784000 : IF( q_direction->coherence_band_data != NULL )
1502 : {
1503 5084880 : hSpatParamRendCom->spreadCoherence_fx[meta_write_index][b] = ivas_divde_255[q_direction->coherence_band_data[band].spread_coherence[block]];
1504 5084880 : move16();
1505 : }
1506 : ELSE
1507 : {
1508 3699120 : hSpatParamRendCom->spreadCoherence_fx[meta_write_index][b] = 0;
1509 3699120 : move16();
1510 : }
1511 :
1512 8784000 : IF( hQMetaData->surcoh_band_data != NULL )
1513 : {
1514 5084880 : hSpatParamRendCom->surroundingCoherence_fx[meta_write_index][b] = ivas_divde_255[hQMetaData->surcoh_band_data[band].surround_coherence[block]]; /*q15*/
1515 5084880 : move16();
1516 : }
1517 : ELSE
1518 : {
1519 3699120 : hSpatParamRendCom->surroundingCoherence_fx[meta_write_index][b] = 0;
1520 3699120 : move16();
1521 : }
1522 : }
1523 : }
1524 : }
1525 :
1526 39459 : test();
1527 39459 : test();
1528 39459 : test();
1529 39459 : IF( EQ_32( hQMetaData->no_directions, 2 ) )
1530 : {
1531 3472 : q_direction = &( hQMetaData->q_direction[1] );
1532 17360 : FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
1533 : {
1534 13888 : meta_write_index = ( add( hSpatParamRendCom->dirac_bs_md_write_idx, block ) ) % hSpatParamRendCom->dirac_md_buffer_length;
1535 :
1536 193320 : FOR( band = 0; band < hMasa->config.numCodingBands; ++band )
1537 : {
1538 951512 : FOR( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b )
1539 : {
1540 : /* Right shifting -1 -> -1, Hence this change is done */
1541 772080 : Word32 L_tmp = L_abs( q_direction->band_data[band].azimuth_fx[block] );
1542 772080 : hSpatParamRendCom->azimuth2[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
1543 772080 : move16();
1544 772080 : IF( q_direction->band_data[band].azimuth_fx[block] < 0 )
1545 : {
1546 179331 : hSpatParamRendCom->azimuth2[meta_write_index][b] = negate( hSpatParamRendCom->azimuth2[meta_write_index][b] );
1547 179331 : move16();
1548 : }
1549 :
1550 772080 : L_tmp = L_abs( q_direction->band_data[band].elevation_fx[block] );
1551 772080 : hSpatParamRendCom->elevation2[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
1552 772080 : move16();
1553 772080 : IF( q_direction->band_data[band].elevation_fx[block] < 0 )
1554 : {
1555 38681 : hSpatParamRendCom->elevation2[meta_write_index][b] = negate( hSpatParamRendCom->elevation2[meta_write_index][b] );
1556 38681 : move16();
1557 : }
1558 :
1559 772080 : hSpatParamRendCom->energy_ratio2_fx[meta_write_index][b] = q_direction->band_data[band].energy_ratio_fx[block];
1560 772080 : move32();
1561 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] );
1562 772080 : move32();
1563 :
1564 : /* Sanitize diffuseness for rare cases where floating point inaccuracy could result in negative diffuseness. */
1565 772080 : if ( hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] < 0 )
1566 : {
1567 0 : hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = 0;
1568 0 : move32();
1569 : }
1570 :
1571 772080 : IF( q_direction->coherence_band_data != NULL )
1572 : {
1573 772080 : hSpatParamRendCom->spreadCoherence2_fx[meta_write_index][b] = ivas_divde_255[q_direction->coherence_band_data[band].spread_coherence[block]];
1574 772080 : move16();
1575 : }
1576 : ELSE
1577 : {
1578 0 : hSpatParamRendCom->spreadCoherence2_fx[meta_write_index][b] = 0;
1579 0 : move16();
1580 : }
1581 : }
1582 : }
1583 : }
1584 : }
1585 35987 : ELSE IF( hSpatParamRendCom->azimuth2 != NULL && hSpatParamRendCom->elevation2 != NULL && hSpatParamRendCom->energy_ratio2_fx != NULL && hSpatParamRendCom->spreadCoherence2_fx != NULL )
1586 : {
1587 : /* zero out old dir2 data */
1588 135440 : FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
1589 : {
1590 108352 : meta_write_index = add( hSpatParamRendCom->dirac_bs_md_write_idx, block ) % hSpatParamRendCom->dirac_md_buffer_length;
1591 108352 : set16_fx( hSpatParamRendCom->azimuth2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
1592 108352 : set16_fx( hSpatParamRendCom->elevation2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
1593 :
1594 108352 : set32_fx( hSpatParamRendCom->energy_ratio2_fx[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
1595 108352 : set16_fx( hSpatParamRendCom->spreadCoherence2_fx[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
1596 : }
1597 : }
1598 : }
1599 : ELSE /* SBA mode/SID/Zero frame*/
1600 : {
1601 : Word16 tmp_write_idx_param_band;
1602 : Word16 tmp_write_idx_band;
1603 :
1604 100213 : Word32 diffuseness_sec_fx = 0;
1605 100213 : move32();
1606 :
1607 : /* ungroup */
1608 100213 : seed_ptr = &hDirAC->dithering_seed;
1609 100213 : nblocks = q_direction->cfg.nblocks;
1610 100213 : move16();
1611 100213 : nbands = hDirAC->band_grouping[hDirAC->hConfig->nbands];
1612 100213 : move16();
1613 100213 : band_grouping = hDirAC->band_grouping;
1614 :
1615 100213 : test();
1616 100213 : IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_format, SBA_FORMAT ) )
1617 : {
1618 : /* SID/zero-frame: 1 direction, 5 bands, nblocks re-generated out of SID decoder*/
1619 1111 : start_band = 0;
1620 1111 : move16();
1621 1111 : hDirAC->hConfig->nbands = 5;
1622 1111 : move16();
1623 :
1624 1111 : ivas_dirac_config_bands_fx( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, NULL, 0, 0, NULL, 1 );
1625 :
1626 1111 : nbands = 5;
1627 1111 : move16();
1628 : }
1629 : ELSE
1630 : {
1631 99102 : start_band = hDirAC->hConfig->enc_param_start_band;
1632 99102 : move16();
1633 99102 : IF( EQ_32( ivas_format, SBA_FORMAT ) )
1634 : {
1635 99102 : hDirAC->hConfig->nbands = IVAS_MAX_NUM_BANDS;
1636 99102 : move16();
1637 : }
1638 : ELSE
1639 : {
1640 0 : hDirAC->hConfig->nbands = q_direction->cfg.nbands;
1641 0 : move16();
1642 : }
1643 :
1644 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 );
1645 :
1646 99102 : nbands = hDirAC->hConfig->nbands;
1647 99102 : move16();
1648 99102 : if ( hQMetaData->q_direction[0].cfg.nblocks == 0 )
1649 : {
1650 : /* No transmission -> no copy from qmetadata buffers*/
1651 0 : nbands = start_band;
1652 0 : move16();
1653 : }
1654 : }
1655 :
1656 : /* Low-Bands with no spatial data transmitted, analysis at decoder side */
1657 785357 : FOR( band = 0; band < start_band; band++ )
1658 : {
1659 685144 : band_start = band_grouping[band];
1660 685144 : move16();
1661 685144 : band_end = band_grouping[band + 1];
1662 685144 : move16();
1663 685144 : tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx;
1664 685144 : move16();
1665 :
1666 3425720 : FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
1667 : {
1668 6508868 : FOR( b = band_start; b < band_end; b++ )
1669 : {
1670 3768292 : tmp_write_idx_band = tmp_write_idx_param_band;
1671 3768292 : move16();
1672 :
1673 3768292 : hSpatParamRendCom->spreadCoherence_fx[block][b] = 0;
1674 3768292 : move16();
1675 3768292 : hSpatParamRendCom->surroundingCoherence_fx[block][b] = 0;
1676 3768292 : move16();
1677 3768292 : hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = 0;
1678 3768292 : move32();
1679 3768292 : hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0;
1680 3768292 : move16();
1681 3768292 : hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0;
1682 3768292 : move16();
1683 3768292 : hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0;
1684 3768292 : move32();
1685 3768292 : hSpatParamRendCom->elevation[tmp_write_idx_band][b] = 0;
1686 3768292 : move16();
1687 3768292 : hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = 0;
1688 3768292 : move16();
1689 :
1690 3768292 : tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
1691 : }
1692 : }
1693 : }
1694 :
1695 : /* Bands with spatial data transmitted */
1696 100213 : if ( hodirac_flag )
1697 : {
1698 13459 : no_secs = DIRAC_HO_NUMSECTORS;
1699 13459 : move16();
1700 : }
1701 :
1702 213885 : FOR( idx_sec = 0; idx_sec < no_secs; idx_sec++ )
1703 : {
1704 784815 : FOR( band = start_band; band < nbands; band++ )
1705 : {
1706 671143 : band_start = band_grouping[band];
1707 671143 : move16();
1708 671143 : band_end = band_grouping[band + 1];
1709 671143 : move16();
1710 671143 : tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx;
1711 671143 : move16();
1712 :
1713 671143 : IF( EQ_32( ivas_format, SBA_FORMAT ) )
1714 : {
1715 665588 : qBand_idx = sub( dirac_to_spar_md_bands[band], start_band );
1716 : }
1717 : ELSE
1718 : {
1719 5555 : qBand_idx = band;
1720 5555 : move16();
1721 : }
1722 671143 : diff_idx = q_direction->band_data[qBand_idx].energy_ratio_index[0];
1723 671143 : move16();
1724 :
1725 671143 : diffuseness_fx = L_sub( ONE_IN_Q30, q_direction->band_data[qBand_idx].energy_ratio_fx[0] );
1726 :
1727 3355715 : FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
1728 : {
1729 : Word16 block_qmetadata;
1730 :
1731 2684572 : block_qmetadata = s_min( block, sub( nblocks, 1 ) );
1732 2684572 : block_qmetadata = s_max( block_qmetadata, 0 );
1733 :
1734 :
1735 2684572 : if ( q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] < 0 )
1736 : {
1737 1167751 : 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*/ );
1738 1167751 : move32();
1739 : }
1740 :
1741 2684572 : test();
1742 2684572 : IF( hMasa == NULL && hodirac_flag )
1743 : {
1744 1292064 : azimuth_fx = q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata];
1745 1292064 : move32();
1746 1292064 : elevation_fx = q_direction[idx_sec].band_data[qBand_idx].elevation_fx[block_qmetadata];
1747 1292064 : move32();
1748 1292064 : diffuseness_fx = L_sub( ONE_IN_Q30, q_direction[0].band_data[qBand_idx].energy_ratio_fx[block_qmetadata] );
1749 1292064 : diffuseness_sec_fx = q_direction[1].band_data[qBand_idx].energy_ratio_fx[block_qmetadata];
1750 1292064 : move32();
1751 1292064 : assert( diffuseness_sec_fx < 1073849216 /*1.0001f in Q30*/ && diffuseness_sec_fx > -107374 /*-0.0001f in Q30*/ );
1752 : }
1753 : ELSE
1754 : {
1755 1392508 : azimuth_fx = q_direction->band_data[qBand_idx].azimuth_fx[block_qmetadata];
1756 1392508 : move32();
1757 1392508 : elevation_fx = q_direction->band_data[qBand_idx].elevation_fx[block_qmetadata];
1758 1392508 : move32();
1759 : }
1760 21909240 : FOR( b = band_start; b < band_end; b++ )
1761 : {
1762 19224668 : tmp_write_idx_band = tmp_write_idx_param_band;
1763 19224668 : move16();
1764 :
1765 19224668 : IF( hodirac_flag )
1766 : {
1767 6378720 : azi = extract_h( L_shr( ( L_add( azimuth_fx, ONE_IN_Q21 ) ), 6 ) );
1768 6378720 : ele = extract_h( L_shr( ( L_add( elevation_fx, ONE_IN_Q21 ) ), 6 ) );
1769 : /*addition of one to compensate precision loss*/
1770 6378720 : if ( azi < 0 )
1771 : {
1772 0 : azi = add( azi, 1 );
1773 : }
1774 6378720 : if ( ele < 0 )
1775 : {
1776 880670 : ele = add( ele, 1 );
1777 : }
1778 : }
1779 : ELSE
1780 : {
1781 : Word16 a, b_tmp;
1782 :
1783 12845948 : Word16 exp_factor = 0;
1784 12845948 : move16();
1785 12845948 : a = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor
1786 :
1787 12845948 : Word32 tmp1_32 = L_mult( a, dirac_dithering_azi_scale_fx[diff_idx] ); // exp_factor + 5
1788 : Word16 final_1_exp;
1789 : Word32 final_1_32;
1790 12845948 : Word16 norm_op1 = norm_l( azimuth_fx );
1791 12845948 : Word16 norm_op2 = norm_l( tmp1_32 );
1792 12845948 : Word16 op2_e = add( exp_factor, 5 );
1793 12845948 : final_1_exp = add( s_max( s_max( sub( 9, norm_op1 ), sub( op2_e, norm_op2 ) ), 0 ), 2 ); // 2 for headroom
1794 12845948 : final_1_32 = L_add( L_shr( azimuth_fx, sub( final_1_exp, 9 ) ), L_shr( tmp1_32, sub( final_1_exp, op2_e ) ) );
1795 :
1796 12845948 : b_tmp = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor
1797 12845948 : Word32 tmp4_32 = L_mult( b_tmp, dirac_dithering_ele_scale_fx[diff_idx] ); // exp_factor + 4
1798 :
1799 : Word16 final_2_exp;
1800 : Word32 final_2_32;
1801 12845948 : norm_op1 = norm_l( elevation_fx );
1802 12845948 : norm_op2 = norm_l( tmp4_32 );
1803 12845948 : op2_e = add( exp_factor, 4 );
1804 12845948 : final_2_exp = add( s_max( s_max( sub( 9, norm_op1 ), sub( op2_e, norm_op2 ) ), 0 ), 2 ); // 2 for headroom
1805 12845948 : final_2_32 = L_add( L_shr( elevation_fx, sub( final_2_exp, 9 ) ), L_shr( tmp4_32, sub( final_2_exp, op2_e ) ) );
1806 :
1807 12845948 : final_1_32 = L_add( final_1_32, L_shl( 1, sub( 30, final_1_exp ) ) ); /*0.5 in q31*/
1808 12845948 : final_2_32 = L_add( final_2_32, L_shl( 1, sub( 30, final_2_exp ) ) );
1809 12845948 : azi = extract_h( L_shr( final_1_32, sub( 15, final_1_exp ) ) );
1810 12845948 : ele = extract_h( L_shr( final_2_32, sub( 15, final_2_exp ) ) );
1811 :
1812 :
1813 : /*addition of one to compensate precision loss*/
1814 12845948 : if ( azi < 0 )
1815 : {
1816 1370160 : azi = add( azi, 1 );
1817 : }
1818 12845948 : if ( ele < 0 )
1819 : {
1820 4788478 : ele = add( ele, 1 );
1821 : }
1822 : /* limit the elevation to [-90, 90] */
1823 12845948 : ele = s_min( 90, ele );
1824 12845948 : ele = s_max( -90, ele );
1825 : }
1826 :
1827 19224668 : test();
1828 19224668 : IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && q_direction->coherence_band_data != NULL )
1829 : {
1830 0 : hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = ivas_divde_255[q_direction->coherence_band_data[qBand_idx].spread_coherence[block]];
1831 0 : move16();
1832 : }
1833 : ELSE
1834 : {
1835 19224668 : hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0;
1836 19224668 : move16();
1837 : }
1838 :
1839 19224668 : test();
1840 19224668 : IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && q_direction->coherence_band_data != NULL )
1841 : {
1842 0 : hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = ivas_divde_255[hQMetaData->surcoh_band_data[qBand_idx].surround_coherence[0]];
1843 0 : move16();
1844 : }
1845 : ELSE
1846 : {
1847 19224668 : hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0;
1848 19224668 : move16();
1849 : }
1850 :
1851 :
1852 19224668 : hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = q_direction->band_data[qBand_idx].energy_ratio_fx[0];
1853 19224668 : move32();
1854 19224668 : hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx;
1855 19224668 : move32();
1856 :
1857 19224668 : IF( hodirac_flag )
1858 : {
1859 6378720 : IF( idx_sec == 0 )
1860 : {
1861 3189360 : hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele;
1862 3189360 : move16();
1863 3189360 : hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi;
1864 3189360 : move16();
1865 3189360 : hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0;
1866 3189360 : move32();
1867 : }
1868 : ELSE
1869 : {
1870 3189360 : assert( idx_sec == 1 );
1871 3189360 : hSpatParamRendCom->elevation2[tmp_write_idx_band][b] = ele;
1872 3189360 : move16();
1873 3189360 : hSpatParamRendCom->azimuth2[tmp_write_idx_band][b] = azi;
1874 3189360 : move16();
1875 3189360 : hSpatParamRendCom->energy_ratio2_fx[tmp_write_idx_band][b] = L_sub( ONE_IN_Q30, diffuseness_sec_fx );
1876 3189360 : move32();
1877 : }
1878 : }
1879 : ELSE
1880 : {
1881 12845948 : hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele;
1882 12845948 : move16();
1883 12845948 : hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi;
1884 12845948 : move16();
1885 : }
1886 : }
1887 2684572 : tmp_write_idx_param_band = add( tmp_write_idx_param_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
1888 :
1889 :
1890 : } /* for ( block =...) */
1891 : } /* for ( band = ...) */
1892 : } /* for ( idx_sec = ...)*/
1893 :
1894 : /* Bands not transmitted -> zeroed*/
1895 100213 : FOR( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ )
1896 : {
1897 0 : tmp_write_idx_band = hSpatParamRendCom->dirac_bs_md_write_idx;
1898 0 : move16();
1899 :
1900 0 : FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
1901 : {
1902 0 : hSpatParamRendCom->spreadCoherence_fx[block][b] = 0;
1903 0 : move16();
1904 0 : hSpatParamRendCom->surroundingCoherence_fx[block][b] = 0;
1905 0 : move16();
1906 0 : hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = 0;
1907 0 : move32();
1908 0 : hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0;
1909 0 : move16();
1910 0 : hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0;
1911 0 : move16();
1912 0 : hSpatParamRendCom->energy_ratio1_fx[block][b] = 0;
1913 0 : move32();
1914 0 : hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0;
1915 0 : move32();
1916 0 : hSpatParamRendCom->elevation[tmp_write_idx_band][b] = 0;
1917 0 : move16();
1918 0 : hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = 0;
1919 0 : move16();
1920 :
1921 0 : tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
1922 : }
1923 : }
1924 : }
1925 : /* update buffer write index */
1926 139672 : hSpatParamRendCom->dirac_bs_md_write_idx = add( hSpatParamRendCom->dirac_bs_md_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length;
1927 139672 : move16();
1928 139672 : return;
1929 : }
1930 : /*-------------------------------------------------------------------------
1931 : * ivas_dirac_dec_set_md_map()
1932 : *
1933 : * Set metadata index mapping for DirAC
1934 : *------------------------------------------------------------------------*/
1935 0 : void ivas_dirac_dec_set_md_map(
1936 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
1937 : const Word16 nCldfbTs /* i : number of CLDFB time slots */
1938 : )
1939 : {
1940 : Word16 num_slots_in_subfr;
1941 : DIRAC_DEC_HANDLE hDirAC;
1942 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1943 :
1944 0 : hDirAC = st_ivas->hDirAC;
1945 0 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1946 :
1947 : /* adapt subframes */
1948 0 : hSpatParamRendCom->num_slots = nCldfbTs;
1949 0 : move16();
1950 0 : hSpatParamRendCom->slots_rendered = 0;
1951 0 : move16();
1952 0 : num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
1953 0 : move16();
1954 0 : hSpatParamRendCom->subframes_rendered = 0;
1955 0 : move16();
1956 :
1957 0 : ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes );
1958 :
1959 : /* copy also to tc buffer */
1960 : /* only for non-combined formats and combinded formats w/o discrete objects */
1961 0 : test();
1962 0 : test();
1963 0 : test();
1964 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 ) ) )
1965 : {
1966 0 : st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes;
1967 0 : move16();
1968 0 : Copy( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes );
1969 : }
1970 :
1971 : /* set mapping according to dirac_read_idx */
1972 :
1973 0 : set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
1974 :
1975 0 : test();
1976 0 : test();
1977 0 : IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
1978 : {
1979 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 );
1980 : }
1981 0 : ELSE IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
1982 : {
1983 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 );
1984 : }
1985 : ELSE
1986 : {
1987 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 );
1988 : }
1989 :
1990 0 : test();
1991 0 : test();
1992 0 : IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
1993 : {
1994 : Word64 tmp_fx;
1995 : Word16 sf_idx, slot_idx, slot_idx_abs;
1996 : Word32 quo, rem;
1997 :
1998 0 : slot_idx_abs = 0;
1999 0 : move16();
2000 0 : FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ )
2001 : {
2002 0 : tmp_fx = 0;
2003 0 : move64();
2004 0 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ )
2005 : {
2006 0 : tmp_fx = W_add_nosat( tmp_fx, W_deposit32_l( L_deposit_l( hSpatParamRendCom->render_to_md_map[slot_idx_abs] ) ) );
2007 0 : slot_idx_abs = add( slot_idx_abs, 1 );
2008 : }
2009 0 : iDiv_and_mod_32( W_shl_sat_l( tmp_fx, 16 ), hSpatParamRendCom->subframe_nbslots[sf_idx], &quo, &rem, 0 );
2010 0 : hSpatParamRendCom->render_to_md_map[sf_idx] = add( round_fx( quo ), hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length;
2011 0 : move16();
2012 : }
2013 :
2014 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 ) );
2015 : }
2016 :
2017 0 : return;
2018 : }
2019 :
2020 152480 : void ivas_dirac_dec_set_md_map_fx(
2021 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
2022 : const Word16 nCldfbTs /* i : number of CLDFB time slots */
2023 : )
2024 : {
2025 : Word16 num_slots_in_subfr;
2026 : DIRAC_DEC_HANDLE hDirAC;
2027 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
2028 :
2029 152480 : hDirAC = st_ivas->hDirAC;
2030 152480 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
2031 :
2032 : /* adapt subframes */
2033 152480 : hSpatParamRendCom->num_slots = nCldfbTs;
2034 152480 : move16();
2035 152480 : hSpatParamRendCom->slots_rendered = 0;
2036 152480 : move16();
2037 152480 : num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
2038 152480 : move16();
2039 152480 : hSpatParamRendCom->subframes_rendered = 0;
2040 152480 : move16();
2041 :
2042 152480 : ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes );
2043 :
2044 : /* copy also to tc buffer */
2045 : /* only for non-combined formats and combinded formats w/o discrete objects */
2046 152480 : test();
2047 152480 : test();
2048 152480 : test();
2049 152480 : 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 ) ) )
2050 : {
2051 133417 : st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes;
2052 133417 : move16();
2053 133417 : Copy( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes );
2054 : }
2055 :
2056 : /* set mapping according to dirac_read_idx */
2057 :
2058 152480 : set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
2059 :
2060 152480 : test();
2061 152480 : test();
2062 152480 : IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
2063 : {
2064 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 );
2065 : }
2066 125648 : ELSE IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
2067 : {
2068 77815 : 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 );
2069 : }
2070 : ELSE
2071 : {
2072 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 );
2073 : }
2074 :
2075 152480 : test();
2076 152480 : test();
2077 152480 : IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
2078 : {
2079 : Word16 sf_idx, slot_idx, slot_idx_abs;
2080 : Word32 tmp_fx;
2081 : Word32 num;
2082 : Word16 denom, norm_denom, exp_denom, exp_num, norm_num, exp;
2083 : Word32 ans, ans_fix_32;
2084 : Word16 ans_fix_16, exp_final;
2085 :
2086 104647 : slot_idx_abs = 0;
2087 104647 : move16();
2088 528024 : FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ )
2089 : {
2090 423377 : tmp_fx = 0;
2091 423377 : move32();
2092 2097904 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ )
2093 : {
2094 1674527 : tmp_fx = L_add( tmp_fx, L_deposit_h( hSpatParamRendCom->render_to_md_map[slot_idx_abs] ) );
2095 1674527 : slot_idx_abs = add( slot_idx_abs, 1 );
2096 : }
2097 :
2098 423377 : exp_denom = 15, exp_num = 31;
2099 423377 : move16();
2100 423377 : move16();
2101 423377 : norm_num = norm_l( tmp_fx );
2102 423377 : num = L_shl( tmp_fx, norm_num );
2103 423377 : exp_num = sub( exp_num, norm_num );
2104 :
2105 423377 : norm_denom = norm_s( hSpatParamRendCom->subframe_nbslots[sf_idx] );
2106 423377 : denom = shl( hSpatParamRendCom->subframe_nbslots[sf_idx], norm_denom );
2107 423377 : exp_denom = sub( exp_denom, norm_denom );
2108 :
2109 423377 : exp = sub( exp_num, exp_denom );
2110 :
2111 423377 : IF( GT_32( num, L_deposit_l( denom ) ) )
2112 : {
2113 318709 : num = L_shr( num, 1 );
2114 318709 : exp = add( exp, 1 );
2115 : }
2116 :
2117 423377 : ans = div_l( num, denom );
2118 423377 : ans_fix_32 = BASOP_Util_Add_Mant32Exp( ans, exp, L_deposit_h( hSpatParamRendCom->dirac_read_idx ), 15 /*31 - 16*/, &exp_final );
2119 423377 : ans_fix_16 = round_fx( L_shr( ans_fix_32, sub( sub( Q31, exp_final ), Q16 ) ) );
2120 :
2121 423377 : hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; // Q0
2122 423377 : move16();
2123 : }
2124 104647 : set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) );
2125 : }
2126 :
2127 152480 : return;
2128 : }
2129 :
2130 :
2131 : /*-------------------------------------------------------------------------
2132 : * ivas_dirac_dec_render_fx()
2133 : *
2134 : * DirAC decoding renderer process
2135 : *------------------------------------------------------------------------*/
2136 :
2137 20592 : void ivas_dirac_dec_render_fx(
2138 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
2139 : const Word16 nchan_transport, /* i : number of transport channels */
2140 : const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */
2141 : UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */
2142 : UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */
2143 : Word32 *output_fx[] /* o : rendered time signal Q(6-1)*/
2144 : )
2145 : {
2146 : Word16 slots_to_render, first_sf, last_sf, subframe_idx;
2147 : UWord16 slot_size, n_samples_sf, ch, nchan_intern;
2148 20592 : Word16 temp = 0;
2149 20592 : move16();
2150 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
2151 : Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS];
2152 20592 : Word32 output_f_local_buff_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; // VE2SB: TBV
2153 :
2154 20592 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
2155 :
2156 20592 : nchan_intern = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
2157 151423 : FOR( ch = 0; ch < nchan_intern; ch++ )
2158 : {
2159 130831 : output_f_local_fx[ch] = output_f_local_buff_fx[ch];
2160 130831 : set_zero_fx( output_f_local_fx[ch], nSamplesAsked );
2161 : }
2162 20592 : slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // cL
2163 :
2164 :
2165 : /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
2166 20592 : slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) );
2167 :
2168 20592 : *nSamplesRendered = i_mult( slots_to_render, slot_size );
2169 20592 : move16();
2170 :
2171 20592 : first_sf = hSpatParamRendCom->subframes_rendered;
2172 20592 : move16();
2173 20592 : last_sf = first_sf;
2174 20592 : move16();
2175 :
2176 91644 : WHILE( slots_to_render > 0 )
2177 : {
2178 71052 : slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] );
2179 71052 : last_sf = add( last_sf, 1 );
2180 : }
2181 :
2182 91644 : FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
2183 : {
2184 71052 : ivas_dirac_dec_render_sf_fx( st_ivas, output_f_local_fx, nchan_transport, NULL, NULL );
2185 :
2186 71052 : n_samples_sf = i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slot_size );
2187 :
2188 544858 : FOR( ch = 0; ch < nchan_intern; ch++ )
2189 : {
2190 473806 : output_f_local_fx[ch] += n_samples_sf;
2191 : }
2192 :
2193 : /* update combined orientation access index */
2194 71052 : ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
2195 : }
2196 :
2197 151423 : FOR( ch = 0; ch < nchan_intern; ch++ )
2198 : {
2199 130831 : test();
2200 130831 : test();
2201 130831 : IF( !( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ) && ( ( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ) || EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) )
2202 : {
2203 130391 : Copy32( output_f_local_buff_fx[ch], output_fx[ch], *nSamplesRendered );
2204 : }
2205 : }
2206 :
2207 : /* clang-format off */
2208 20592 : IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) )
2209 : {
2210 17503 : IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) )
2211 : {
2212 0 : temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS );
2213 0 : hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0
2214 : }
2215 : ELSE
2216 : {
2217 17503 : temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS );
2218 17503 : hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0
2219 : }
2220 : }
2221 :
2222 20592 : *nSamplesAvailableNext = i_mult( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), slot_size ); // Q0
2223 20592 : move16();
2224 :
2225 20592 : return;
2226 : }
2227 : /* clang-format on */
2228 :
2229 :
2230 : #ifdef FIX_1319_STACK_SBA_DECODER
2231 : /*-------------------------------------------------------------------------
2232 : * Local functions to perform binaural rendering with optimized stack
2233 : *------------------------------------------------------------------------*/
2234 :
2235 0 : static void binRenderer_split_fx(
2236 : BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */
2237 : ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend, /* i/o: ISAR split binaural rendering handle */
2238 : COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle */
2239 : const Word16 numTimeSlots, /* i : number of time slots to render */
2240 : Word32 Cldfb_RealBuffer_Binaural_fx[][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Rotated Binaural signals */
2241 : Word32 Cldfb_ImagBuffer_Binaural_fx[][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Rotated Binaural signals */
2242 : Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */
2243 : Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */
2244 : const Word16 slot_idx_start,
2245 : const Word16 num_freq_bands,
2246 : const Word16 nchan_out )
2247 : {
2248 : Word16 pos_idx, slot_idx, ch, input_q;
2249 : Word32 Cldfb_RealBuffer_Binaural_loc[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2250 : Word32 Cldfb_ImagBuffer_Binaural_loc[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2251 :
2252 0 : input_q = Q6;
2253 0 : move16();
2254 :
2255 : /* Perform binaural rendering */
2256 0 : ivas_binRenderer_fx( hBinRenderer, &hSplitBinRend->splitrend.multiBinPoseData, hCombinedOrientationData, numTimeSlots,
2257 : #ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG
2258 : NULL,
2259 : #endif
2260 : Cldfb_RealBuffer_Binaural_loc, Cldfb_ImagBuffer_Binaural_loc, RealBuffer_fx, ImagBuffer_fx, &input_q );
2261 :
2262 0 : FOR( slot_idx = 0; slot_idx < numTimeSlots; slot_idx++ )
2263 : {
2264 0 : FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
2265 : {
2266 0 : Copy32( Cldfb_RealBuffer_Binaural_loc[0][ch][slot_idx], Cldfb_RealBuffer_Binaural_fx[0][ch][slot_idx], num_freq_bands );
2267 0 : Copy32( Cldfb_ImagBuffer_Binaural_loc[0][ch][slot_idx], Cldfb_ImagBuffer_Binaural_fx[0][ch][slot_idx], num_freq_bands );
2268 : }
2269 : }
2270 :
2271 0 : FOR( pos_idx = 0; pos_idx < hBinRenderer->numPoses; pos_idx++ )
2272 : {
2273 0 : FOR( slot_idx = 0; slot_idx < numTimeSlots; slot_idx++ )
2274 : {
2275 0 : FOR( ch = 0; ch < nchan_out; ch++ )
2276 : {
2277 0 : Copy32( Cldfb_RealBuffer_Binaural_loc[pos_idx][ch][slot_idx], hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], num_freq_bands );
2278 0 : Copy32( Cldfb_ImagBuffer_Binaural_loc[pos_idx][ch][slot_idx], hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], num_freq_bands );
2279 : }
2280 : }
2281 : }
2282 :
2283 0 : return;
2284 : }
2285 :
2286 :
2287 120202 : static void binRenderer_fx(
2288 : BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */
2289 : COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle */
2290 : const Word16 numTimeSlots, /* i : number of time slots to render */
2291 : Word32 Cldfb_RealBuffer_Binaural_fx[][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Rotated Binaural signals */
2292 : Word32 Cldfb_ImagBuffer_Binaural_fx[][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Rotated Binaural signals */
2293 : Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */
2294 : Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX] /* i : LS signals */
2295 : )
2296 : {
2297 : Word16 input_q;
2298 :
2299 120202 : input_q = Q6;
2300 120202 : move16();
2301 :
2302 : /* Perform binaural rendering */
2303 120202 : ivas_binRenderer_fx( hBinRenderer, NULL, hCombinedOrientationData, numTimeSlots,
2304 : #ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG
2305 : NULL,
2306 : #endif
2307 : Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, RealBuffer_fx, ImagBuffer_fx, &input_q );
2308 :
2309 120202 : return;
2310 : }
2311 : #endif
2312 :
2313 :
2314 : /*-------------------------------------------------------------------------
2315 : * ivas_dirac_dec_render_sf_fx()
2316 : *
2317 : * DirAC decoding renderer process
2318 : *------------------------------------------------------------------------*/
2319 :
2320 308205 : void ivas_dirac_dec_render_sf_fx(
2321 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
2322 : Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output Q(6-1)*/
2323 : const Word16 nchan_transport, /* i : number of transport channels */
2324 : #ifdef FIX_1319_STACK_SBA_DECODER
2325 : Word32 *pppQMfFrame_ts_re_fx[HOA3_CHANNELS][CLDFB_NO_COL_MAX],
2326 : Word32 *pppQMfFrame_ts_im_fx[HOA3_CHANNELS][CLDFB_NO_COL_MAX]
2327 : #else
2328 : Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], /*Q6*/
2329 : Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] /*Q6*/
2330 : #endif
2331 : )
2332 : {
2333 : Word16 i, ch, idx_in, idx_lfe;
2334 : DIRAC_DEC_HANDLE hDirAC;
2335 : DIRAC_REND_HANDLE hDirACRend;
2336 : Word16 subframe_idx;
2337 : Word16 slot_idx, index_slot;
2338 : Word16 hodirac_flag;
2339 : Word16 slot_idx_start, slot_idx_start_cldfb_synth, md_idx;
2340 :
2341 : /*CLDFB: last output channels reserved to LFT for CICPx*/
2342 : #ifdef FIX_1319_STACK_SBA_DECODER
2343 : Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2344 : Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2345 : Word32 Cldfb_RealBuffer_Binaural_fx[1][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2346 : Word32 Cldfb_ImagBuffer_Binaural_fx[1][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2347 : #else
2348 : Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
2349 : Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
2350 : Word32 Cldfb_RealBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
2351 : Word32 Cldfb_ImagBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
2352 : #endif
2353 308205 : Word16 index = 0, num_freq_bands = 0;
2354 308205 : move16();
2355 308205 : move16();
2356 :
2357 : /* local copies of azi, ele, diffuseness */
2358 : Word16 azimuth[CLDFB_NO_CHANNELS_MAX];
2359 : Word16 elevation[CLDFB_NO_CHANNELS_MAX];
2360 : Word32 diffuseness_vector_fx[CLDFB_NO_CHANNELS_MAX];
2361 : Word32 *p_Rmat_fx;
2362 : Word32 *reference_power_fx, *reference_power_smooth_fx, *onset_filter_fx, *onset_filter_subframe_fx;
2363 : Word32 dirEne_fx;
2364 : Word32 surCohEner_fx;
2365 : Word32 surCohRatio_fx[CLDFB_NO_CHANNELS_MAX];
2366 308205 : Word16 surCohRatio_q_fx = 0, temp_q = 0;
2367 308205 : move16();
2368 308205 : move16();
2369 : #ifndef FIX_1319_STACK_SBA_DECODER
2370 : Word32 Cldfb_RealBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2371 : Word32 Cldfb_ImagBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2372 : #endif
2373 : Word16 cldfb_buf_q;
2374 308205 : Word16 offset = 0, buff_len = 0;
2375 308205 : move16();
2376 308205 : move16();
2377 308205 : Word16 q_cldfb, q_temp_cldfb = 0;
2378 308205 : move16();
2379 308205 : Word16 proto_length = 0;
2380 308205 : move16();
2381 : Word16 q_proto_direct_buffer[CLDFB_SLOTS_PER_SUBFRAME + 1];
2382 : Word16 q_proto_diffuse_buffer[CLDFB_SLOTS_PER_SUBFRAME + 1];
2383 : Word16 size, size_ho;
2384 :
2385 : DIRAC_DEC_STACK_MEM DirAC_mem;
2386 308205 : Word32 *p_onset_filter_fx = NULL;
2387 : UWord16 coherence_flag;
2388 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
2389 308205 : Word16 scale = 0;
2390 308205 : move16();
2391 : DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params;
2392 : DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state;
2393 : Word16 num_channels_dir, exp;
2394 308205 : Word16 q_diffuseness_vector = Q31, q_reference_power_smooth[2] = { Q31, Q31 };
2395 308205 : move16();
2396 308205 : move16();
2397 308205 : move16();
2398 308205 : Word16 proto_power_smooth_len = 0;
2399 308205 : move16();
2400 : Word16 tmp1;
2401 :
2402 308205 : push_wmops( "ivas_dirac_dec_render" );
2403 :
2404 : /* Initialize aux buffers */
2405 5239485 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2406 : {
2407 24656400 : FOR( Word16 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
2408 : {
2409 19725120 : set32_fx( Cldfb_RealBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
2410 19725120 : set32_fx( Cldfb_ImagBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
2411 : }
2412 : }
2413 :
2414 :
2415 308205 : hDirAC = st_ivas->hDirAC;
2416 308205 : hDirACRend = st_ivas->hDirACRend;
2417 308205 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
2418 :
2419 308205 : DirAC_mem = hDirACRend->stack_mem;
2420 :
2421 308205 : reference_power_fx = DirAC_mem.reference_power_fx;
2422 308205 : IF( DirAC_mem.reference_power_fx == NULL )
2423 : {
2424 8651 : reference_power_smooth_fx = NULL;
2425 : }
2426 : ELSE
2427 : {
2428 299554 : reference_power_smooth_fx = DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands;
2429 : }
2430 308205 : onset_filter_fx = DirAC_mem.onset_filter_fx;
2431 308205 : IF( DirAC_mem.onset_filter_fx == NULL )
2432 : {
2433 22228 : onset_filter_subframe_fx = NULL;
2434 : }
2435 : ELSE
2436 : {
2437 285977 : onset_filter_subframe_fx = DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands;
2438 : }
2439 308205 : q_cldfb = Q11;
2440 308205 : move16();
2441 308205 : set16_fx( q_proto_direct_buffer, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME + 1 );
2442 308205 : set16_fx( q_proto_diffuse_buffer, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME + 1 );
2443 308205 : set_zero_fx( surCohRatio_fx, CLDFB_NO_CHANNELS_MAX );
2444 :
2445 308205 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
2446 : {
2447 8228 : IF( hDirACRend->masa_stereo_type_detect )
2448 : {
2449 8228 : hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = 0;
2450 8228 : move32();
2451 8228 : hDirACRend->masa_stereo_type_detect->q_subtract_power_y = Q31;
2452 8228 : move16();
2453 : }
2454 : }
2455 :
2456 308205 : test();
2457 308205 : IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) )
2458 : {
2459 68173 : IF( hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0 )
2460 : {
2461 54173 : DIRAC_OUTPUT_SYNTHESIS_STATE *state = &( hDirACRend->h_output_synthesis_psd_state );
2462 54173 : tmp1 = L_norm_arr( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len );
2463 :
2464 54173 : scale_sig32( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len, tmp1 ); // Q(proto_power_diff_smooth_q + tmp1)
2465 54173 : state->proto_power_diff_smooth_q = add( state->proto_power_diff_smooth_q, tmp1 );
2466 54173 : move16();
2467 : }
2468 : }
2469 :
2470 308205 : h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
2471 308205 : h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
2472 308205 : num_channels_dir = hDirACRend->num_outputs_dir;
2473 308205 : move16();
2474 308205 : hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
2475 308205 : if ( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
2476 : {
2477 55738 : num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE;
2478 55738 : move16();
2479 : }
2480 :
2481 308205 : test();
2482 308205 : test();
2483 308205 : 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 ) ) )
2484 : {
2485 41738 : tmp1 = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
2486 41738 : 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
2487 41738 : h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = tmp1;
2488 41738 : move16();
2489 : }
2490 :
2491 308205 : test();
2492 308205 : IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2493 : {
2494 : Word16 shift;
2495 14000 : shift = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
2496 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
2497 14000 : h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, shift );
2498 14000 : move16();
2499 14000 : shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
2500 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
2501 14000 : h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, shift );
2502 14000 : move16();
2503 14000 : tmp1 = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
2504 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
2505 14000 : h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp1 );
2506 14000 : move16();
2507 : }
2508 :
2509 :
2510 308205 : test();
2511 308205 : test();
2512 308205 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
2513 : {
2514 360606 : FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
2515 : {
2516 240404 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11;
2517 240404 : move16();
2518 : }
2519 : }
2520 188003 : ELSE IF( !( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
2521 : {
2522 : Word16 outchannels;
2523 71052 : idx_lfe = 0;
2524 71052 : move16();
2525 71052 : idx_in = 0;
2526 71052 : move16();
2527 71052 : outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
2528 :
2529 71052 : test();
2530 71052 : test();
2531 71052 : test();
2532 71052 : test();
2533 71052 : test();
2534 71052 : test();
2535 71052 : test();
2536 71052 : IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
2537 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
2538 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
2539 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
2540 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
2541 : ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
2542 : {
2543 880 : outchannels = add( outchannels, 1 );
2544 : }
2545 :
2546 71052 : test();
2547 71052 : IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) )
2548 : {
2549 0 : FOR( ch = 0; ch < outchannels; ch++ )
2550 : {
2551 0 : test();
2552 0 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
2553 : {
2554 0 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
2555 : {
2556 0 : idx_lfe = add( idx_lfe, 1 );
2557 : }
2558 : }
2559 : }
2560 : }
2561 : ELSE
2562 : {
2563 544858 : FOR( ch = 0; ch < outchannels; ch++ )
2564 : {
2565 :
2566 473806 : test();
2567 473806 : test();
2568 473806 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
2569 : {
2570 41738 : test();
2571 41738 : IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
2572 : {
2573 : Word16 cldfbSynIdx;
2574 6640 : cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
2575 6640 : st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11;
2576 6640 : move16();
2577 : }
2578 : }
2579 432068 : ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
2580 : {
2581 : }
2582 : ELSE
2583 : {
2584 431188 : st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11;
2585 431188 : move16();
2586 431188 : idx_in = add( idx_in, 1 );
2587 : }
2588 : }
2589 : }
2590 : }
2591 :
2592 308205 : size = imult1616( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands );
2593 308205 : IF( hodirac_flag )
2594 : {
2595 53156 : size_ho = imult1616( size, DIRAC_HO_NUMSECTORS );
2596 : }
2597 : ELSE
2598 : {
2599 255049 : size_ho = size;
2600 255049 : move16();
2601 : }
2602 308205 : 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
2603 308205 : hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26;
2604 308205 : move16();
2605 :
2606 308205 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2607 : {
2608 : Word16 shift;
2609 231804 : shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho );
2610 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)
2611 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 );
2612 231804 : move16();
2613 :
2614 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
2615 231804 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26;
2616 231804 : move16();
2617 :
2618 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
2619 231804 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26;
2620 231804 : move16();
2621 :
2622 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
2623 231804 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26;
2624 231804 : move16();
2625 : }
2626 : ELSE
2627 : {
2628 : Word16 shift;
2629 76401 : 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
2630 76401 : hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26;
2631 76401 : move16();
2632 :
2633 76401 : shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho );
2634 76401 : 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)
2635 76401 : 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 );
2636 76401 : move16();
2637 76401 : shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho );
2638 76401 : 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)
2639 76401 : 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 );
2640 76401 : move16();
2641 76401 : 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 ) );
2642 76401 : 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)
2643 76401 : 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 );
2644 76401 : move16();
2645 76401 : tmp1 = 31;
2646 76401 : move16();
2647 325126 : FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
2648 : {
2649 248725 : 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 ) ) );
2650 : }
2651 325126 : FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
2652 : {
2653 248725 : 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)
2654 : }
2655 76401 : 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 );
2656 76401 : move16();
2657 76401 : tmp1 = 31;
2658 76401 : move16();
2659 325126 : FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
2660 : {
2661 248725 : 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 ) ) ) );
2662 : }
2663 325126 : FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
2664 : {
2665 248725 : 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)
2666 : }
2667 76401 : 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 );
2668 76401 : move16();
2669 76401 : IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 )
2670 : {
2671 54173 : 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 ) );
2672 54173 : 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)
2673 54173 : 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 );
2674 54173 : move16();
2675 : }
2676 : }
2677 :
2678 308205 : hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
2679 :
2680 308205 : test();
2681 308205 : test();
2682 308205 : IF( st_ivas->hQMetaData != NULL && NE_32( st_ivas->ivas_format, SBA_FORMAT ) && NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
2683 : {
2684 71052 : coherence_flag = st_ivas->hQMetaData->coherence_flag;
2685 71052 : move16();
2686 : }
2687 : ELSE
2688 : {
2689 237153 : coherence_flag = 0;
2690 237153 : move16();
2691 : }
2692 : /* Subframe loop */
2693 308205 : slot_idx_start = hSpatParamRendCom->slots_rendered;
2694 308205 : move16();
2695 308205 : slot_idx_start_cldfb_synth = 0;
2696 308205 : move16();
2697 :
2698 308205 : subframe_idx = hSpatParamRendCom->subframes_rendered;
2699 308205 : move16();
2700 308205 : IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
2701 : {
2702 124208 : md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
2703 124208 : move16();
2704 : }
2705 : ELSE
2706 : {
2707 183997 : md_idx = hSpatParamRendCom->render_to_md_map[slot_idx_start];
2708 183997 : move16();
2709 : }
2710 :
2711 : /* copy parameters into local buffers*/
2712 308205 : IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
2713 : {
2714 124208 : Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands );
2715 124208 : q_diffuseness_vector = Q30;
2716 124208 : move16();
2717 124208 : Copy( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands );
2718 124208 : Copy( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands );
2719 : }
2720 : ELSE
2721 : {
2722 183997 : set32_fx( diffuseness_vector_fx, 0, hSpatParamRendCom->num_freq_bands );
2723 183997 : q_diffuseness_vector = Q31;
2724 183997 : move16();
2725 : }
2726 :
2727 308205 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2728 : {
2729 76401 : set_zero_fx( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands );
2730 : }
2731 : ELSE
2732 : {
2733 231804 : set_zero_fx( onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands );
2734 : }
2735 :
2736 308205 : test();
2737 308205 : IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] )
2738 : {
2739 41400 : p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0];
2740 :
2741 41400 : IF( st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
2742 : {
2743 36800 : num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
2744 36800 : move16();
2745 36800 : IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
2746 : {
2747 0 : rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx );
2748 : }
2749 : }
2750 : }
2751 : ELSE
2752 : {
2753 266805 : p_Rmat_fx = 0;
2754 266805 : move32();
2755 : }
2756 :
2757 308205 : IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
2758 : {
2759 : Word16 *masa_band_mapping;
2760 : /* compute response */
2761 124208 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2762 : {
2763 62401 : ivas_dirac_dec_compute_power_factors_fx( hSpatParamRendCom->num_freq_bands,
2764 : diffuseness_vector_fx,
2765 62401 : hDirACRend->h_output_synthesis_psd_params.max_band_decorr,
2766 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
2767 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx );
2768 :
2769 62401 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q29;
2770 62401 : move16();
2771 62401 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q29;
2772 62401 : move16();
2773 :
2774 62401 : IF( coherence_flag )
2775 : {
2776 1608948 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
2777 : {
2778 1579860 : dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; // Q29
2779 1579860 : move32();
2780 1579860 : 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
2781 :
2782 1579860 : 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
2783 1579860 : move32();
2784 1579860 : 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
2785 1579860 : move32();
2786 :
2787 1579860 : surCohRatio_fx[i] = BASOP_Util_Divide3232_Scale_newton( surCohEner_fx, ( L_add( EPSILLON_FX, L_add( dirEne_fx, surCohEner_fx ) ) ), &temp_q );
2788 1579860 : move32();
2789 1579860 : surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], sub( temp_q, 16 ) ); // Q15
2790 1579860 : move32();
2791 : }
2792 : }
2793 : ELSE
2794 : {
2795 33313 : set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands );
2796 : }
2797 62401 : surCohRatio_q_fx = Q15;
2798 62401 : move16();
2799 : }
2800 : ELSE
2801 : {
2802 : Word16 max_exp_direct, max_exp_diffusion;
2803 61807 : max_exp_direct = 0;
2804 61807 : move16();
2805 61807 : max_exp_diffusion = 0;
2806 61807 : move16();
2807 61807 : ivas_dirac_dec_compute_gain_factors_fx( hSpatParamRendCom->num_freq_bands,
2808 61807 : hSpatParamRendCom->diffuseness_vector_fx[md_idx],
2809 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
2810 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx,
2811 : &max_exp_direct, &max_exp_diffusion );
2812 :
2813 61807 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub( Q31, max_exp_direct );
2814 61807 : move16();
2815 61807 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub( Q31, max_exp_diffusion );
2816 61807 : move16();
2817 :
2818 61807 : IF( coherence_flag )
2819 : {
2820 263947 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
2821 : {
2822 259620 : surCohRatio_fx[i] = L_deposit_l( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] );
2823 259620 : move32();
2824 : }
2825 : }
2826 : ELSE
2827 : {
2828 57480 : set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands );
2829 : }
2830 61807 : surCohRatio_q_fx = Q15;
2831 61807 : move16();
2832 : }
2833 :
2834 124208 : IF( st_ivas->hMasa == NULL )
2835 : {
2836 53156 : masa_band_mapping = NULL;
2837 : }
2838 : ELSE
2839 : {
2840 71052 : masa_band_mapping = st_ivas->hMasa->data.band_mapping;
2841 : }
2842 124208 : ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom,
2843 : hDirACRend,
2844 : st_ivas->hVBAPdata,
2845 : masa_band_mapping,
2846 : st_ivas->hMasaIsmData,
2847 : azimuth,
2848 : elevation,
2849 : md_idx,
2850 : surCohRatio_fx,
2851 : surCohRatio_q_fx,
2852 : hodirac_flag );
2853 : }
2854 :
2855 308205 : test();
2856 308205 : IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) )
2857 : {
2858 47516 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
2859 : {
2860 37843 : index_slot = add( slot_idx_start, slot_idx );
2861 37843 : offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot );
2862 : /* CLDFB Analysis*/
2863 113529 : FOR( ch = 0; ch < nchan_transport; ch++ )
2864 : {
2865 75686 : q_temp_cldfb = Q11;
2866 75686 : move16();
2867 : #ifdef FIX_1319_STACK_SBA_DECODER
2868 75686 : cldfbAnalysis_ts_fx_fixed_q( &( st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][hSpatParamRendCom->num_freq_bands * index_slot] ),
2869 75686 : Cldfb_RealBuffer_Binaural_fx[0][ch][slot_idx], /* note: it is a tmp. buffer at this point */
2870 75686 : Cldfb_ImagBuffer_Binaural_fx[0][ch][slot_idx], /* note: it is a tmp. buffer at this point */
2871 75686 : hSpatParamRendCom->num_freq_bands,
2872 : st_ivas->cldfbAnaDec[ch], &q_temp_cldfb );
2873 : #else
2874 : cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset],
2875 : Cldfb_RealBuffer_Temp_fx[ch][slot_idx],
2876 : Cldfb_ImagBuffer_Temp_fx[ch][slot_idx],
2877 : hSpatParamRendCom->num_freq_bands,
2878 : st_ivas->cldfbAnaDec[ch], &q_temp_cldfb );
2879 : #endif
2880 : }
2881 37843 : q_cldfb = q_temp_cldfb;
2882 37843 : move16();
2883 : }
2884 :
2885 9673 : test();
2886 9673 : IF( ( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) )
2887 : {
2888 : #ifdef FIX_1319_STACK_SBA_DECODER
2889 2706 : ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( st_ivas, Cldfb_RealBuffer_Binaural_fx[0], Cldfb_ImagBuffer_Binaural_fx[0], &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx );
2890 : #else
2891 : ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( st_ivas, Cldfb_RealBuffer_Temp_fx, Cldfb_ImagBuffer_Temp_fx, &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx );
2892 : #endif
2893 : }
2894 : }
2895 :
2896 1531254 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
2897 : {
2898 1223049 : index_slot = add( slot_idx_start, slot_idx );
2899 1223049 : IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) )
2900 : {
2901 730303 : md_idx = hSpatParamRendCom->render_to_md_map[index_slot];
2902 730303 : move16();
2903 : }
2904 : ELSE
2905 : {
2906 492746 : md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
2907 492746 : move16();
2908 : }
2909 1223049 : test();
2910 1223049 : test();
2911 1223049 : IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
2912 : {
2913 6144011 : FOR( ch = 0; ch < nchan_transport; ch++ )
2914 : {
2915 5201084 : Copy32( pppQMfFrame_ts_re_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2916 5201084 : Copy32( pppQMfFrame_ts_im_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2917 : }
2918 942927 : q_cldfb = Q6;
2919 942927 : move16();
2920 : }
2921 280122 : ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) )
2922 : {
2923 113529 : FOR( ch = 0; ch < nchan_transport; ch++ )
2924 : {
2925 : #ifdef FIX_1319_STACK_SBA_DECODER
2926 75686 : Copy32( Cldfb_RealBuffer_Binaural_fx[0][ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2927 75686 : Copy32( Cldfb_ImagBuffer_Binaural_fx[0][ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2928 : #else
2929 : Copy32( Cldfb_RealBuffer_Temp_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2930 : Copy32( Cldfb_ImagBuffer_Temp_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2931 : #endif
2932 : }
2933 : }
2934 : ELSE
2935 : {
2936 : /* CLDFB Analysis*/
2937 242279 : offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot );
2938 579945 : FOR( ch = 0; ch < nchan_transport; ch++ )
2939 : {
2940 337666 : q_temp_cldfb = Q11;
2941 337666 : move16();
2942 337666 : cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset],
2943 337666 : Cldfb_RealBuffer_fx[ch][0],
2944 337666 : Cldfb_ImagBuffer_fx[ch][0],
2945 337666 : hSpatParamRendCom->num_freq_bands,
2946 : st_ivas->cldfbAnaDec[ch], &q_temp_cldfb );
2947 : }
2948 242279 : q_cldfb = q_temp_cldfb;
2949 242279 : move16();
2950 : }
2951 :
2952 : /* CNG in DirAC, extra CLDFB ana for CNA*/
2953 1223049 : test();
2954 1223049 : test();
2955 1223049 : test();
2956 1223049 : test();
2957 1223049 : 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 ) ) ) )
2958 : {
2959 34604 : Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0];
2960 34604 : Word16 Q_input = Q11;
2961 34604 : move16();
2962 34604 : q_temp_cldfb = Q11;
2963 34604 : move16();
2964 34604 : test();
2965 34604 : test();
2966 34604 : test();
2967 103812 : generate_masking_noise_dirac_ivas_fx( st->hFdCngDec->hFdCngCom,
2968 : st_ivas->cldfbAnaDec[1],
2969 34604 : &st_ivas->hTcBuffer->tc_fx[1][hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->slots_rendered],
2970 : Cldfb_RealBuffer_fx[1][0],
2971 : Cldfb_ImagBuffer_fx[1][0],
2972 : slot_idx,
2973 34604 : st->cna_dirac_flag && st->flag_cna,
2974 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 );
2975 34604 : Scale_sig32( Cldfb_RealBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6
2976 34604 : Scale_sig32( Cldfb_ImagBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6
2977 : }
2978 :
2979 : /* LFE synthesis */
2980 1223049 : test();
2981 1223049 : test();
2982 1223049 : test();
2983 1223049 : 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 ) )
2984 : {
2985 26560 : ivas_lfe_synth_with_cldfb_fx( st_ivas->hMasa->hMasaLfeSynth,
2986 : Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
2987 : Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1], Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1],
2988 : slot_idx,
2989 : md_idx,
2990 : nchan_transport, q_cldfb );
2991 : }
2992 :
2993 : /*-----------------------------------------------------------------*
2994 : * protoype signal computation
2995 : *-----------------------------------------------------------------*/
2996 1223049 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2997 : {
2998 921531 : test();
2999 921531 : test();
3000 921531 : IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
3001 : {
3002 147200 : protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
3003 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
3004 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
3005 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx,
3006 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
3007 : reference_power_fx, DirAC_mem.reference_power_q,
3008 : slot_idx, nchan_transport,
3009 147200 : hDirACRend->num_outputs_diff,
3010 147200 : hSpatParamRendCom->num_freq_bands,
3011 : p_Rmat_fx, q_cldfb );
3012 : }
3013 : ELSE
3014 : {
3015 774331 : protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
3016 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
3017 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
3018 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx,
3019 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
3020 : reference_power_fx, DirAC_mem.reference_power_q,
3021 : slot_idx, nchan_transport,
3022 774331 : hDirACRend->num_outputs_diff,
3023 774331 : hSpatParamRendCom->num_freq_bands,
3024 : 0, q_cldfb );
3025 : }
3026 :
3027 921531 : q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
3028 921531 : move16();
3029 921531 : q_proto_diffuse_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q;
3030 921531 : move16();
3031 : }
3032 301518 : ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
3033 : {
3034 29979 : protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx,
3035 : &hDirACRend->proto_frame_f_q,
3036 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
3037 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
3038 : reference_power_fx,
3039 : DirAC_mem.reference_power_q,
3040 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
3041 29979 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
3042 29979 : 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect,
3043 : q_cldfb );
3044 :
3045 29979 : q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
3046 29979 : move16();
3047 :
3048 29979 : proto_length = i_mult( 6, hSpatParamRendCom->num_freq_bands );
3049 29979 : proto_power_smooth_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
3050 : }
3051 : ELSE
3052 : {
3053 271539 : SWITCH( nchan_transport )
3054 : {
3055 56000 : case 11:
3056 : case 8:
3057 : case 6:
3058 : case 4:
3059 56000 : protoSignalComputation4_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
3060 : hDirACRend->proto_frame_f_fx,
3061 : &hDirACRend->proto_frame_f_q,
3062 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
3063 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
3064 : reference_power_fx,
3065 : DirAC_mem.reference_power_q,
3066 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
3067 56000 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
3068 56000 : slot_idx, hDirACRend->num_outputs_diff,
3069 56000 : hSpatParamRendCom->num_freq_bands,
3070 : hDirACRend->hoa_decoder,
3071 : nchan_transport,
3072 : hDirACRend->sba_map_tc, q_cldfb );
3073 56000 : proto_length = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
3074 56000 : proto_power_smooth_len = i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff );
3075 56000 : BREAK;
3076 103251 : case 2:
3077 103251 : protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx,
3078 : &hDirACRend->proto_frame_f_q,
3079 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
3080 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
3081 : reference_power_fx,
3082 : DirAC_mem.reference_power_q,
3083 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
3084 103251 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
3085 103251 : hDirACRend->hOutSetup.is_loudspeaker_setup,
3086 : slot_idx,
3087 103251 : hSpatParamRendCom->num_freq_bands,
3088 : hDirACRend->masa_stereo_type_detect,
3089 : q_cldfb );
3090 103251 : proto_length = i_mult( 6, hSpatParamRendCom->num_freq_bands );
3091 103251 : IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
3092 : {
3093 71227 : proto_power_smooth_len = i_mult( 3, hSpatParamRendCom->num_freq_bands );
3094 : }
3095 : ELSE
3096 : {
3097 32024 : proto_power_smooth_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
3098 : }
3099 103251 : BREAK;
3100 112288 : case 1:
3101 112288 : protoSignalComputation1_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
3102 : hDirACRend->proto_frame_f_fx,
3103 : &hDirACRend->proto_frame_f_q,
3104 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
3105 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
3106 : reference_power_fx,
3107 : DirAC_mem.reference_power_q,
3108 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
3109 112288 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
3110 : slot_idx,
3111 112288 : hDirACRend->num_protos_diff,
3112 112288 : hSpatParamRendCom->num_freq_bands, q_cldfb );
3113 112288 : proto_length = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_diff ) );
3114 112288 : proto_power_smooth_len = hSpatParamRendCom->num_freq_bands;
3115 112288 : move16();
3116 112288 : BREAK;
3117 0 : default:
3118 0 : return;
3119 : }
3120 271539 : q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
3121 271539 : move16();
3122 : }
3123 :
3124 : /*-----------------------------------------------------------------*
3125 : * Compute DirAC parameters at decoder side
3126 : *-----------------------------------------------------------------*/
3127 1223049 : IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) )
3128 : {
3129 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 ) );
3130 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 ) );
3131 :
3132 730303 : test();
3133 730303 : test();
3134 730303 : IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
3135 : {
3136 147200 : num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
3137 147200 : move16();
3138 147200 : rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx );
3139 : }
3140 :
3141 : /*hDirACRend->index_buffer_intensity = ( hDirACRend->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1 */
3142 730303 : IF( hDirACRend->index_buffer_intensity == 0 )
3143 : {
3144 217 : hDirACRend->index_buffer_intensity = 1;
3145 217 : move16();
3146 : }
3147 : ELSE
3148 : {
3149 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 */
3150 730086 : move16();
3151 : }
3152 :
3153 730303 : index = hDirACRend->index_buffer_intensity;
3154 730303 : move16();
3155 730303 : num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
3156 730303 : move16();
3157 :
3158 730303 : computeIntensityVector_dec_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
3159 : q_cldfb, num_freq_bands,
3160 730303 : hDirACRend->buffer_intensity_real_fx[0][index - 1],
3161 730303 : hDirACRend->buffer_intensity_real_fx[1][index - 1],
3162 730303 : hDirACRend->buffer_intensity_real_fx[2][index - 1],
3163 730303 : &hDirACRend->q_buffer_intensity_real[index - 1] );
3164 :
3165 730303 : computeDirectionAngles_fx( hDirACRend->buffer_intensity_real_fx[0][index - 1],
3166 730303 : hDirACRend->buffer_intensity_real_fx[1][index - 1],
3167 730303 : hDirACRend->buffer_intensity_real_fx[2][index - 1],
3168 730303 : hDirACRend->q_buffer_intensity_real[index - 1],
3169 : num_freq_bands, azimuth, elevation );
3170 :
3171 730303 : Copy32( reference_power_fx, &( hDirACRend->buffer_energy_fx[i_mult( sub( index, 1 ), num_freq_bands )] ), num_freq_bands );
3172 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] ) );
3173 730303 : hDirACRend->q_buffer_energy[index - 1] = DirAC_mem.reference_power_q[0];
3174 730303 : move16();
3175 :
3176 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 );
3177 : }
3178 :
3179 : /*-----------------------------------------------------------------*
3180 : * frequency domain decorrelation
3181 : *-----------------------------------------------------------------*/
3182 1223049 : IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) )
3183 : {
3184 : /* decorrelate prototype frame */
3185 1137070 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3186 : {
3187 2764593 : ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
3188 921531 : hDirACRend->num_outputs_diff,
3189 921531 : hDirACRend->num_protos_diff,
3190 : hDirACRend->synthesisConf,
3191 : nchan_transport,
3192 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 )],
3193 921531 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
3194 921531 : hDirACRend->num_protos_diff,
3195 921531 : hDirACRend->proto_index_diff,
3196 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 ) )],
3197 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
3198 : onset_filter_fx,
3199 : hDirACRend->h_freq_domain_decorr_ap_params,
3200 : hDirACRend->h_freq_domain_decorr_ap_state );
3201 :
3202 921531 : v_multc_fixed( onset_filter_fx, 536870912 /* 0.25f in Q31 */, onset_filter_fx, hSpatParamRendCom->num_freq_bands );
3203 :
3204 921531 : v_add_fixed_no_hdrm( onset_filter_fx, onset_filter_subframe_fx, onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands ); /* Q31 */
3205 921531 : p_onset_filter_fx = onset_filter_subframe_fx;
3206 : }
3207 : ELSE
3208 : {
3209 215539 : scale = L_norm_arr( hDirACRend->proto_frame_f_fx, proto_length );
3210 215539 : Scale_sig32( hDirACRend->proto_frame_f_fx, proto_length, scale ); // Q(proto_frame_f_q+scale)
3211 215539 : hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, scale );
3212 215539 : move16();
3213 215539 : ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
3214 215539 : hDirACRend->num_outputs_diff,
3215 215539 : hDirACRend->num_protos_diff,
3216 : hDirACRend->synthesisConf,
3217 : nchan_transport,
3218 215539 : hDirACRend->proto_frame_f_fx,
3219 215539 : hDirACRend->proto_frame_f_q,
3220 215539 : hDirACRend->num_protos_diff,
3221 215539 : hDirACRend->proto_index_diff,
3222 : DirAC_mem.frame_dec_f_fx,
3223 : &DirAC_mem.frame_dec_f_q,
3224 : onset_filter_fx,
3225 : hDirACRend->h_freq_domain_decorr_ap_params,
3226 : hDirACRend->h_freq_domain_decorr_ap_state );
3227 :
3228 215539 : hDirACRend->proto_frame_dec_f_fx = DirAC_mem.frame_dec_f_fx;
3229 215539 : hDirACRend->proto_frame_dec_f_q = DirAC_mem.frame_dec_f_q;
3230 215539 : move16();
3231 215539 : hDirACRend->proto_frame_dec_f_len = DirAC_mem.frame_dec_f_len;
3232 215539 : move16();
3233 215539 : p_onset_filter_fx = onset_filter_fx;
3234 : }
3235 : }
3236 : ELSE
3237 : {
3238 85979 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3239 : {
3240 0 : set32_fx( onset_filter_subframe_fx, ONE_IN_Q31, hSpatParamRendCom->num_freq_bands );
3241 0 : p_onset_filter_fx = onset_filter_subframe_fx;
3242 : }
3243 : ELSE
3244 : {
3245 : /* no frequency domain decorrelation: use prototype frame */
3246 85979 : hDirACRend->proto_frame_dec_f_fx = hDirACRend->proto_frame_f_fx;
3247 85979 : hDirACRend->proto_frame_dec_f_len = hDirACRend->proto_frame_f_len;
3248 85979 : move16();
3249 85979 : hDirACRend->proto_frame_dec_f_q = hDirACRend->proto_frame_f_q;
3250 85979 : move16();
3251 85979 : p_onset_filter_fx = NULL;
3252 : }
3253 : }
3254 :
3255 : /*-----------------------------------------------------------------*
3256 : * output synthesis
3257 : *-----------------------------------------------------------------*/
3258 1223049 : test();
3259 1223049 : IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) )
3260 : {
3261 : DIRAC_OUTPUT_SYNTHESIS_STATE *state;
3262 : Word16 diffuse_start;
3263 271539 : state = &( hDirACRend->h_output_synthesis_psd_state );
3264 271539 : 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 ) );
3265 :
3266 271539 : exp = getScaleFactor32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len );
3267 271539 : scale_sig32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len, exp ); // hDirACRend->proto_frame_dec_f_q + exp
3268 271539 : hDirACRend->proto_frame_dec_f_q = add( hDirACRend->proto_frame_dec_f_q, exp );
3269 271539 : move16();
3270 271539 : exp = getScaleFactor32( state->proto_diffuse_buffer_f_fx, diffuse_start );
3271 271539 : scale_sig32( state->proto_diffuse_buffer_f_fx, diffuse_start, exp ); // state->proto_diffuse_buffer_f_q + exp
3272 271539 : state->proto_diffuse_buffer_f_q = add( state->proto_diffuse_buffer_f_q, exp );
3273 271539 : move16();
3274 : /*Compute diffuse prototypes*/
3275 271539 : ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx );
3276 : }
3277 :
3278 : /*Compute PSDs*/
3279 1223049 : h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
3280 1223049 : h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
3281 1223049 : num_channels_dir = hDirACRend->num_outputs_dir;
3282 1223049 : move16();
3283 :
3284 1223049 : if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
3285 : {
3286 221799 : num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE;
3287 221799 : move16();
3288 : }
3289 :
3290 1223049 : test();
3291 1223049 : test();
3292 1223049 : 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 ) ) ) )
3293 : {
3294 165799 : 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
3295 165799 : h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
3296 165799 : move16();
3297 :
3298 165799 : exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
3299 165799 : 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
3300 165799 : h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp );
3301 165799 : move16();
3302 : }
3303 :
3304 1223049 : test();
3305 1223049 : IF( ( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) )
3306 : {
3307 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
3308 56000 : h_dirac_output_synthesis_state->direct_power_factor_q = Q31;
3309 56000 : move16();
3310 :
3311 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
3312 56000 : h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
3313 56000 : move16();
3314 :
3315 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
3316 56000 : h_dirac_output_synthesis_state->direct_responses_q = Q31;
3317 56000 : move16();
3318 :
3319 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
3320 56000 : h_dirac_output_synthesis_state->direct_responses_square_q = Q31;
3321 56000 : move16();
3322 :
3323 56000 : exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
3324 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
3325 56000 : h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, exp );
3326 56000 : move16();
3327 56000 : exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
3328 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
3329 56000 : h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, exp );
3330 56000 : move16();
3331 56000 : exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
3332 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
3333 56000 : h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp );
3334 56000 : move16();
3335 : }
3336 :
3337 1223049 : ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fx,
3338 : DirAC_mem.reference_power_q,
3339 : p_onset_filter_fx,
3340 : azimuth,
3341 : elevation,
3342 1223049 : hSpatParamRendCom->diffuseness_vector_fx[md_idx],
3343 1223049 : hSpatParamRendCom->q_diffuseness_vector,
3344 : hSpatParamRendCom,
3345 : hDirACRend,
3346 : st_ivas->hVBAPdata,
3347 : hDirACRend->hOutSetup,
3348 : nchan_transport,
3349 : md_idx,
3350 : hodirac_flag,
3351 1223049 : hDirAC->hConfig->dec_param_estim );
3352 :
3353 :
3354 1223049 : IF( hDirAC->hConfig->dec_param_estim )
3355 : {
3356 : Word16 fac;
3357 730303 : fac = BASOP_Util_Divide3232_Scale( 1, hSpatParamRendCom->subframe_nbslots[subframe_idx], &exp );
3358 730303 : fac = shl_sat( fac, exp );
3359 :
3360 730303 : IF( LT_16( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) )
3361 : {
3362 0 : scale_sig32( hSpatParamRendCom->diffuseness_vector_fx[md_idx], hSpatParamRendCom->num_freq_bands, sub( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ); // q_diffuseness_vector
3363 0 : hSpatParamRendCom->q_diffuseness_vector = q_diffuseness_vector;
3364 0 : move16();
3365 : }
3366 : ELSE
3367 : {
3368 730303 : scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( hSpatParamRendCom->q_diffuseness_vector, q_diffuseness_vector ) ); // q_diffuseness_vector
3369 730303 : q_diffuseness_vector = hSpatParamRendCom->q_diffuseness_vector;
3370 730303 : move16();
3371 : }
3372 730303 : v_multc_acc_32_16( hSpatParamRendCom->diffuseness_vector_fx[md_idx], fac, diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands );
3373 : }
3374 :
3375 1223049 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3376 : {
3377 301518 : v_add_fixed_me( reference_power_fx, sub( 31, DirAC_mem.reference_power_q[0] ),
3378 301518 : reference_power_smooth_fx, sub( 31, q_reference_power_smooth[0] ),
3379 : reference_power_smooth_fx, &temp_q,
3380 301518 : s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), 1 );
3381 301518 : q_reference_power_smooth[0] = sub( 31, temp_q );
3382 301518 : v_add_fixed_me( reference_power_fx + CLDFB_NO_CHANNELS_HALF, sub( 31, DirAC_mem.reference_power_q[1] ),
3383 301518 : reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, sub( 31, q_reference_power_smooth[1] ),
3384 : reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, &temp_q,
3385 301518 : s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), 1 );
3386 301518 : q_reference_power_smooth[1] = sub( 31, temp_q );
3387 : }
3388 : }
3389 :
3390 308205 : minimum_s( q_proto_direct_buffer, add( hSpatParamRendCom->subframe_nbslots[subframe_idx], 1 ), &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q );
3391 308205 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3392 : {
3393 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 );
3394 : }
3395 1531254 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3396 : {
3397 1223049 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3398 : {
3399 921531 : offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
3400 921531 : buff_len = i_mult( 2, i_mult( hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands ) );
3401 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
3402 921531 : offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) );
3403 921531 : buff_len = i_mult( 2, i_mult( nchan_transport, hSpatParamRendCom->num_freq_bands ) );
3404 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
3405 : }
3406 301518 : ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
3407 : {
3408 29979 : offset = i_mult( slot_idx, i_mult( 4, hSpatParamRendCom->num_freq_bands ) );
3409 29979 : buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands );
3410 29979 : 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
3411 : }
3412 : ELSE
3413 : {
3414 271539 : SWITCH( nchan_transport )
3415 : {
3416 56000 : case 11:
3417 : case 8:
3418 : case 6:
3419 : case 4:
3420 56000 : offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
3421 56000 : buff_len = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
3422 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
3423 56000 : BREAK;
3424 103251 : case 2:
3425 103251 : IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
3426 : {
3427 71227 : offset = i_mult( i_mult( i_mult( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), 3 );
3428 71227 : buff_len = i_mult( 6, hSpatParamRendCom->num_freq_bands );
3429 : }
3430 : ELSE
3431 : {
3432 32024 : offset = i_mult( i_mult( i_mult( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), 2 );
3433 32024 : buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands );
3434 : }
3435 103251 : 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
3436 103251 : BREAK;
3437 112288 : case 1:
3438 112288 : offset = i_mult( slot_idx, i_mult( 2, hSpatParamRendCom->num_freq_bands ) );
3439 112288 : buff_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
3440 112288 : 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
3441 112288 : BREAK;
3442 : }
3443 1223049 : }
3444 : }
3445 308205 : test();
3446 308205 : 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 )
3447 : {
3448 4886 : 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
3449 4886 : offset = i_mult( i_mult( sub( slot_idx, 1 ), 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
3450 4886 : buff_len = i_mult( 2, i_mult( hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands ) );
3451 4886 : 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 )
3452 : {
3453 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
3454 : }
3455 : }
3456 308205 : ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
3457 :
3458 308205 : size = i_mult( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands );
3459 308205 : IF( hodirac_flag )
3460 : {
3461 53156 : size_ho = i_mult( size, DIRAC_HO_NUMSECTORS );
3462 : }
3463 : ELSE
3464 : {
3465 255049 : size_ho = size;
3466 255049 : move16();
3467 : }
3468 :
3469 308205 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3470 : {
3471 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, Q26 ) )
3472 : {
3473 214367 : 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
3474 214367 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26;
3475 214367 : move16();
3476 : }
3477 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, Q26 ) )
3478 : {
3479 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
3480 : }
3481 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) )
3482 : {
3483 94398 : 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
3484 : }
3485 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) )
3486 : {
3487 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
3488 : }
3489 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) )
3490 : {
3491 93998 : 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
3492 : }
3493 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, Q26 ) )
3494 : {
3495 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
3496 : }
3497 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, Q26 ) )
3498 : {
3499 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
3500 : }
3501 231804 : IF( NE_16( q_diffuseness_vector, Q30 ) )
3502 : {
3503 0 : scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q30, q_diffuseness_vector ) ); // Q30
3504 : }
3505 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) )
3506 : {
3507 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
3508 : }
3509 231804 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) )
3510 : {
3511 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
3512 : }
3513 :
3514 231804 : ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer_fx,
3515 : Cldfb_ImagBuffer_fx,
3516 : hSpatParamRendCom,
3517 : hDirACRend,
3518 : nchan_transport,
3519 231804 : hSpatParamRendCom->subframe_nbslots[subframe_idx],
3520 : p_onset_filter_fx,
3521 : diffuseness_vector_fx,
3522 : hodirac_flag,
3523 231804 : hDirAC->hConfig->dec_param_estim,
3524 : &hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev,
3525 : &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev );
3526 :
3527 231804 : test();
3528 231804 : IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL )
3529 : {
3530 446000 : FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
3531 : {
3532 2015000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3533 : {
3534 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
3535 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
3536 : }
3537 : }
3538 : }
3539 : ELSE
3540 : {
3541 2966056 : FOR( ch = 0; ch < hDirACRend->num_outputs_dir; ch++ )
3542 : {
3543 13795300 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3544 : {
3545 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
3546 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
3547 : }
3548 : }
3549 : }
3550 : }
3551 : ELSE
3552 : {
3553 : /* Determine encoding quality based additional smoothing factor */
3554 76401 : Word32 qualityBasedSmFactor_fx = ONE_IN_Q31;
3555 76401 : move32();
3556 76401 : Word16 q_Cldfb = 0;
3557 76401 : move16();
3558 :
3559 76401 : IF( st_ivas->hMasa != NULL )
3560 : {
3561 62401 : qualityBasedSmFactor_fx = L_mult( st_ivas->hMasa->data.dir_decode_quality_fx, st_ivas->hMasa->data.dir_decode_quality_fx ); /* (Q15, Q15) -> Q31 */
3562 : }
3563 :
3564 76401 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) )
3565 : {
3566 62401 : 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
3567 : }
3568 76401 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) )
3569 : {
3570 62401 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // Q31
3571 : }
3572 76401 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) )
3573 : {
3574 20663 : 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
3575 : }
3576 76401 : IF( NE_16( q_diffuseness_vector, Q31 ) )
3577 : {
3578 76401 : Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, q_diffuseness_vector ) ); // Q31
3579 : }
3580 76401 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, Q31 ) )
3581 : {
3582 62401 : 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
3583 : }
3584 :
3585 76401 : exp = L_norm_arr( reference_power_smooth_fx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) );
3586 76401 : scale_sig32( reference_power_smooth_fx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), exp ); // q_reference_power_smooth[0] + exp
3587 76401 : q_reference_power_smooth[0] = add( q_reference_power_smooth[0], exp );
3588 76401 : IF( LT_16( q_reference_power_smooth[0], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] ) )
3589 : {
3590 2954 : 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]
3591 2954 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] = q_reference_power_smooth[0];
3592 2954 : move16();
3593 : }
3594 : ELSE
3595 : {
3596 : Word32 temp;
3597 2257987 : FOR( i = 0; i < s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ); i++ )
3598 : {
3599 2184540 : 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] ) );
3600 2184540 : reference_power_smooth_fx[i] = L_max( temp, L_min( reference_power_smooth_fx[i], 1 ) );
3601 2184540 : move32();
3602 : }
3603 73447 : q_reference_power_smooth[0] = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0];
3604 73447 : move16();
3605 : }
3606 :
3607 76401 : exp = L_norm_arr( reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
3608 76401 : 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
3609 76401 : q_reference_power_smooth[1] = add( q_reference_power_smooth[1], exp );
3610 76401 : IF( LT_16( q_reference_power_smooth[1], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] ) )
3611 : {
3612 2640 : 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
3613 2640 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] = q_reference_power_smooth[1];
3614 2640 : move16();
3615 : }
3616 : ELSE
3617 : {
3618 : Word32 temp;
3619 2043351 : FOR( i = CLDFB_NO_CHANNELS_HALF; i < hSpatParamRendCom->num_freq_bands; i++ )
3620 : {
3621 1969590 : 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] ) );
3622 1969590 : reference_power_smooth_fx[i] = L_max( temp, L_min( reference_power_smooth_fx[i], 1 ) );
3623 1969590 : move32();
3624 : }
3625 73761 : q_reference_power_smooth[1] = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1];
3626 73761 : move16();
3627 : }
3628 :
3629 76401 : IF( hDirACRend->masa_stereo_type_detect != NULL )
3630 : {
3631 11420 : IF( LT_16( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) )
3632 : {
3633 11420 : 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
3634 11420 : move32();
3635 11420 : hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = hDirACRend->masa_stereo_type_detect->q_subtract_power_y;
3636 11420 : move16();
3637 : }
3638 : ELSE
3639 : {
3640 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
3641 0 : move32();
3642 0 : hDirACRend->masa_stereo_type_detect->q_subtract_power_y = hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth;
3643 0 : move16();
3644 : }
3645 : }
3646 :
3647 76401 : exp = 31;
3648 76401 : move16();
3649 325126 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3650 : {
3651 248725 : 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 ) ) );
3652 : }
3653 325126 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3654 : {
3655 248725 : 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)
3656 : }
3657 76401 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0], exp );
3658 76401 : move16();
3659 76401 : exp = 31;
3660 76401 : move16();
3661 325126 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3662 : {
3663 248725 : 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 ) ) ) );
3664 : }
3665 325126 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3666 : {
3667 248725 : 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)
3668 : }
3669 76401 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], exp );
3670 76401 : move16();
3671 :
3672 76401 : 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] ) )
3673 : {
3674 112596 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3675 : {
3676 85618 : 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
3677 : }
3678 26978 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0];
3679 26978 : move16();
3680 : }
3681 : ELSE
3682 : {
3683 212530 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3684 : {
3685 163107 : 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
3686 : }
3687 49423 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0];
3688 49423 : move16();
3689 : }
3690 76401 : 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] ) )
3691 : {
3692 138119 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3693 : {
3694 105982 : 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
3695 : }
3696 32137 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1];
3697 32137 : move16();
3698 : }
3699 : ELSE
3700 : {
3701 187007 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3702 : {
3703 142743 : 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
3704 : }
3705 44264 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1];
3706 44264 : move16();
3707 : }
3708 :
3709 76401 : 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 ) );
3710 76401 : 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)
3711 76401 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, exp );
3712 76401 : move16();
3713 76401 : IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 )
3714 : {
3715 54173 : 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 ) )
3716 : {
3717 24153 : 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
3718 24153 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q;
3719 24153 : move16();
3720 : }
3721 : ELSE
3722 : {
3723 30020 : 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
3724 30020 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q;
3725 30020 : move16();
3726 : }
3727 : }
3728 :
3729 76401 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) )
3730 : {
3731 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
3732 : }
3733 76401 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) )
3734 : {
3735 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
3736 : }
3737 76401 : IF( hDirACRend->proto_signal_decorr_on )
3738 : {
3739 54173 : 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
3740 54173 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
3741 54173 : move16();
3742 : }
3743 :
3744 76401 : ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Cldfb_RealBuffer_fx,
3745 : Cldfb_ImagBuffer_fx,
3746 : hSpatParamRendCom,
3747 : hDirACRend,
3748 76401 : hSpatParamRendCom->subframe_nbslots[subframe_idx],
3749 : diffuseness_vector_fx,
3750 : reference_power_smooth_fx,
3751 : q_reference_power_smooth,
3752 : qualityBasedSmFactor_fx,
3753 76401 : hDirAC->hConfig->enc_param_start_band,
3754 : &q_Cldfb );
3755 :
3756 76401 : Word16 allZero = 1;
3757 76401 : move16();
3758 14533361 : FOR( i = 0; i < proto_power_smooth_len; i++ )
3759 : {
3760 14456960 : if ( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx[i] != 0 )
3761 : {
3762 0 : allZero = 0;
3763 0 : move16();
3764 : }
3765 : }
3766 76401 : if ( allZero )
3767 : {
3768 76401 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = 31;
3769 76401 : move16();
3770 : }
3771 76401 : if ( allZero )
3772 : {
3773 76401 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = 31;
3774 76401 : move16();
3775 : }
3776 :
3777 599785 : FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
3778 : {
3779 2605916 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3780 : {
3781 2082532 : scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6
3782 2082532 : scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6
3783 : }
3784 : }
3785 : }
3786 :
3787 : /*-----------------------------------------------------------------*
3788 : * CLDFB synthesis (and binaural rendering)
3789 : *-----------------------------------------------------------------*/
3790 :
3791 308205 : index_slot = slot_idx_start_cldfb_synth;
3792 308205 : move16();
3793 :
3794 308205 : test();
3795 308205 : test();
3796 308205 : IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
3797 : {
3798 : /* render objects in combined format onto the CICP19 channels for BINAURAL_ROOM_IR */
3799 120202 : test();
3800 120202 : test();
3801 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 ) ) )
3802 : {
3803 : Word16 j, k, l;
3804 : Word16 num_objects, nchan_out_woLFE;
3805 : Word16 n_slots_to_render;
3806 : Word16 n_samples_to_render;
3807 : Word32 gain_fx, prev_gain_fx;
3808 :
3809 12000 : num_objects = st_ivas->nchan_ism;
3810 12000 : move16();
3811 12000 : nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
3812 12000 : move16();
3813 12000 : n_slots_to_render = st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->subframes_rendered];
3814 12000 : move16();
3815 12000 : n_samples_to_render = imult1616( hSpatParamRendCom->num_freq_bands, n_slots_to_render );
3816 :
3817 12000 : test();
3818 12000 : IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[0] )
3819 : {
3820 0 : ivas_jbm_dec_get_adapted_linear_interpolator_fx( n_samples_to_render, n_samples_to_render, st_ivas->hIsmRendererData->interpolator_fx );
3821 0 : st_ivas->hIsmRendererData->interp_offset_fx = 0;
3822 0 : move16();
3823 : }
3824 :
3825 56000 : FOR( i = 0; i < num_objects; i++ )
3826 : {
3827 : /* Combined rotation: rotate the object positions depending the head and external orientations */
3828 44000 : test();
3829 44000 : IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) )
3830 : {
3831 0 : Word16 az_q0 = extract_l( L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, Q22 ) );
3832 0 : Word16 el_q0 = extract_l( L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, Q22 ) );
3833 : Word32 az1_32, el1_32;
3834 0 : rotateAziEle_fixed( az_q0, el_q0, &az1_32, &el1_32, st_ivas->hCombinedOrientationData->Rmat_fx[0], st_ivas->hIntSetup.is_planar_setup );
3835 :
3836 0 : IF( st_ivas->hEFAPdata != NULL )
3837 : {
3838 0 : const Word32 azi_fx = L_shl( az1_32, Q22 - Q16 ); // Q16 -> Q22
3839 0 : const Word32 ele_fx = L_shl( el1_32, Q22 - Q16 ); // Q16 -> Q22
3840 0 : efap_determine_gains_fx( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], azi_fx, ele_fx, EFAP_MODE_EFAP );
3841 : }
3842 : }
3843 :
3844 528000 : FOR( j = 0; j < nchan_out_woLFE; j++ )
3845 : {
3846 484000 : gain_fx = st_ivas->hIsmRendererData->gains_fx[i][j];
3847 484000 : move32();
3848 484000 : prev_gain_fx = st_ivas->hIsmRendererData->prev_gains_fx[i][j];
3849 484000 : move32();
3850 484000 : test();
3851 484000 : IF( ( L_abs( gain_fx ) > 0 || L_abs( prev_gain_fx ) > 0 ) )
3852 : {
3853 : Word32 *tc_re_fx, *tc_im_fx;
3854 : Word16 *w1_fx, w2_fx;
3855 :
3856 253076 : w1_fx = &st_ivas->hIsmRendererData->interpolator_fx[st_ivas->hIsmRendererData->interp_offset_fx];
3857 253076 : tc_re_fx = pppQMfFrame_ts_re_fx[nchan_transport + i][0];
3858 253076 : move32();
3859 253076 : tc_im_fx = pppQMfFrame_ts_im_fx[nchan_transport + i][0];
3860 253076 : move32();
3861 1265380 : FOR( k = 0; k < n_slots_to_render; k++ )
3862 : {
3863 : Word32 g_fx;
3864 1012304 : w2_fx = sub( MAX16B, *w1_fx );
3865 1012304 : g_fx = Madd_32_16( Mpy_32_16_1( gain_fx, *w1_fx ), prev_gain_fx, w2_fx ); // Q15
3866 54436304 : FOR( l = 0; l < hSpatParamRendCom->num_freq_bands; l++ )
3867 : {
3868 53424000 : Cldfb_RealBuffer_fx[j][k][l] = Madd_32_32( Cldfb_RealBuffer_fx[j][k][l], g_fx, L_shl( *tc_re_fx, 1 ) );
3869 53424000 : move32();
3870 53424000 : tc_re_fx++;
3871 53424000 : Cldfb_ImagBuffer_fx[j][k][l] = Madd_32_32( Cldfb_ImagBuffer_fx[j][k][l], g_fx, L_shl( *tc_im_fx, 1 ) );
3872 53424000 : move32();
3873 53424000 : tc_im_fx++;
3874 : }
3875 1012304 : w1_fx += hSpatParamRendCom->num_freq_bands;
3876 : }
3877 : }
3878 : /* update here only in case of head rotation */
3879 484000 : test();
3880 484000 : IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) )
3881 : {
3882 0 : st_ivas->hIsmRendererData->prev_gains_fx[i][j] = gain_fx;
3883 0 : move32();
3884 : }
3885 : }
3886 : }
3887 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] ) );
3888 : }
3889 :
3890 : /* Perform binaural rendering, output in Q6 format */
3891 : #ifdef FIX_1319_STACK_SBA_DECODER
3892 120202 : test();
3893 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 ) )
3894 : {
3895 0 : IF( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
3896 : {
3897 0 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3898 : {
3899 0 : FOR( ch = 0; ch < st_ivas->hBinRenderer->nInChannels; ch++ )
3900 : {
3901 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 );
3902 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 );
3903 : }
3904 : }
3905 0 : st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
3906 0 : move16();
3907 : }
3908 :
3909 0 : binRenderer_split_fx( st_ivas->hBinRenderer, st_ivas->hSplitBinRend, st_ivas->hCombinedOrientationData, hSpatParamRendCom->subframe_nbslots[subframe_idx],
3910 0 : Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, slot_idx_start, hSpatParamRendCom->num_freq_bands, st_ivas->hDecoderConfig->nchan_out );
3911 : }
3912 : ELSE
3913 : {
3914 120202 : binRenderer_fx( st_ivas->hBinRenderer, st_ivas->hCombinedOrientationData, hSpatParamRendCom->subframe_nbslots[subframe_idx],
3915 : Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx );
3916 : }
3917 : #else
3918 : 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 ) )
3919 : {
3920 : IF( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
3921 : {
3922 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3923 : {
3924 : FOR( ch = 0; ch < st_ivas->hBinRenderer->nInChannels; ch++ )
3925 : {
3926 : 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 );
3927 : 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 );
3928 : }
3929 : }
3930 : st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
3931 : move16();
3932 : }
3933 : }
3934 :
3935 : /*Binaural output in Q6 format*/
3936 : ivas_binRenderer_fx( st_ivas->hBinRenderer,
3937 : ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData,
3938 : st_ivas->hCombinedOrientationData,
3939 : hSpatParamRendCom->subframe_nbslots[subframe_idx],
3940 : Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx,
3941 : Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, &input_q );
3942 : #endif
3943 :
3944 : /* Inverse CLDFB*/
3945 360606 : FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
3946 : {
3947 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
3948 240404 : Word32 *synth_fx = &output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands];
3949 : #ifdef FIX_1319_STACK_SBA_DECODER
3950 : Word32 *RealBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME];
3951 : Word32 *ImagBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME];
3952 : #else
3953 : Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
3954 : Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
3955 : #endif
3956 1198100 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
3957 : {
3958 957696 : RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[0][ch][i];
3959 957696 : move32();
3960 957696 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[0][ch][i];
3961 957696 : move32();
3962 : }
3963 :
3964 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
3965 240404 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = ( Q6 - 1 );
3966 240404 : move16();
3967 :
3968 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] );
3969 :
3970 240404 : Word16 no_col = st_ivas->cldfbSynDec[ch]->no_col;
3971 240404 : move16();
3972 240404 : Word16 no_channels = st_ivas->cldfbSynDec[ch]->no_channels;
3973 240404 : move16();
3974 240404 : Word16 samplesToProcess = i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
3975 240404 : move16();
3976 240404 : IF( GT_16( samplesToProcess, -1 ) )
3977 : {
3978 : Word16 tmp, tmp_e;
3979 240404 : tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[ch]->no_channels, 1 ) ), st_ivas->cldfbSynDec[ch]->no_channels, &tmp_e );
3980 240404 : tmp = shr( tmp, 15 - tmp_e );
3981 240404 : no_col = s_min( no_col, tmp );
3982 : }
3983 240404 : Word16 synth_len = imult1616( no_col, no_channels );
3984 :
3985 240404 : scale_sig32( synth_fx, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11
3986 : }
3987 : }
3988 188003 : ELSE IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
3989 : {
3990 1526167 : FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
3991 : {
3992 6986480 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3993 : {
3994 5577264 : Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], pppQMfFrame_ts_re_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands ); // Q6
3995 5577264 : Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], pppQMfFrame_ts_im_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands ); // Q6
3996 : }
3997 : }
3998 : }
3999 : ELSE
4000 : {
4001 : #ifdef FIX_1319_STACK_SBA_DECODER
4002 : Word32 *RealBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME];
4003 : Word32 *ImagBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME];
4004 : #else
4005 : Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
4006 : Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
4007 : #endif
4008 : Word16 outchannels;
4009 :
4010 71052 : idx_in = 0;
4011 71052 : move16();
4012 71052 : idx_lfe = 0;
4013 71052 : move16();
4014 :
4015 71052 : outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
4016 :
4017 71052 : test();
4018 71052 : test();
4019 71052 : test();
4020 71052 : test();
4021 71052 : test();
4022 71052 : test();
4023 71052 : test();
4024 71052 : IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
4025 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
4026 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
4027 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
4028 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
4029 : ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
4030 : {
4031 880 : outchannels = add( outchannels, 1 );
4032 : }
4033 :
4034 71052 : test();
4035 71052 : IF( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
4036 0 : {
4037 : Word32 tmp_separated_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
4038 : Word32 tmp_lfe_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
4039 0 : const Word16 subframe_start_sample = imult1616( index_slot, hSpatParamRendCom->num_freq_bands );
4040 0 : const Word16 num_samples_subframe = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4041 :
4042 : /* Move the separated and the LFE channels to temporary variables as spatial synthesis may overwrite current channels */
4043 0 : Copy32( &( output_buf_fx[st_ivas->hOutSetup.separateChannelIndex][subframe_start_sample] ), tmp_separated_fx, num_samples_subframe );
4044 0 : if ( hDirACRend->hOutSetup.num_lfe > 0 )
4045 : {
4046 0 : Copy32( &( output_buf_fx[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe_fx, num_samples_subframe );
4047 : }
4048 :
4049 0 : FOR( ch = 0; ch < outchannels; ch++ )
4050 : {
4051 :
4052 0 : test();
4053 0 : test();
4054 0 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
4055 : {
4056 : /* Move the LFE channel to the correct place */
4057 0 : Copy32( tmp_lfe_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe );
4058 :
4059 0 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
4060 : {
4061 0 : idx_lfe = add( idx_lfe, 1 );
4062 : }
4063 : }
4064 0 : ELSE IF( ( st_ivas->hLsSetupCustom->separate_ch_found ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
4065 : {
4066 : /* Move the separated channel to the correct place. Thus, the separated channel is
4067 : * combined with the synthesized channels here when there is a matching channel. */
4068 0 : Copy32( tmp_separated_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe );
4069 : }
4070 : ELSE
4071 : {
4072 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
4073 0 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
4074 : {
4075 0 : RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i];
4076 0 : move32();
4077 0 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i];
4078 0 : move32();
4079 : }
4080 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] );
4081 :
4082 0 : IF( !st_ivas->hLsSetupCustom->separate_ch_found )
4083 : {
4084 : /* Pan the separated channel and mix with the synthesized channels. Thus, the separated channel
4085 : * is combined with the synthesized channels here when there is no matching channel. */
4086 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 );
4087 : }
4088 :
4089 0 : idx_in = add( idx_in, 1 );
4090 : }
4091 : }
4092 : }
4093 : ELSE
4094 : {
4095 544858 : FOR( ch = 0; ch < outchannels; ch++ )
4096 : {
4097 :
4098 473806 : test();
4099 473806 : test();
4100 473806 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
4101 : {
4102 41738 : test();
4103 41738 : test();
4104 41738 : IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
4105 6640 : {
4106 33200 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
4107 : {
4108 26560 : RealBuffer_fx[i] = Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i];
4109 26560 : move32();
4110 26560 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i];
4111 26560 : move32();
4112 : }
4113 6640 : Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
4114 6640 : Word16 samplesToProcess = i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4115 6640 : Word32 *p_out = &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] );
4116 :
4117 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
4118 6640 : st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = ( Q6 - 1 );
4119 6640 : move16();
4120 6640 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, 0, 0, st_ivas->cldfbSynDec[cldfbSynIdx] );
4121 :
4122 : // Calculating length of output
4123 6640 : Word16 no_col = st_ivas->cldfbSynDec[cldfbSynIdx]->no_col;
4124 6640 : move16();
4125 6640 : Word16 no_channels = st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels;
4126 6640 : move16();
4127 6640 : IF( GT_16( samplesToProcess, -1 ) )
4128 : {
4129 : Word16 tmp, tmp_e;
4130 6640 : tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, 1 ) ), st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, &tmp_e );
4131 6640 : tmp = shr( tmp, 15 - tmp_e );
4132 6640 : no_col = s_min( no_col, tmp );
4133 : }
4134 6640 : Word16 synth_len = imult1616( no_col, no_channels );
4135 :
4136 6640 : scale_sig32( p_out, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11
4137 : }
4138 35098 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && hDirACRend->hOutSetup.separateChannelEnabled )
4139 : {
4140 : /* LFE has been synthesized in the time domain, do nothing. */
4141 : }
4142 : ELSE
4143 : {
4144 34218 : set32_fx( &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) );
4145 : }
4146 41738 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
4147 : {
4148 0 : idx_lfe = add( idx_lfe, 1 );
4149 : }
4150 : }
4151 432068 : ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
4152 : {
4153 : /* The separated channel is already set to output_f[hOutSetup.separateChannelIndex]. Thus, the separated
4154 : * channel is combined with the synthesized channels here. */
4155 : }
4156 : ELSE
4157 : {
4158 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
4159 431188 : Word32 *p_out = &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] );
4160 : Word16 samplesToProcess, out_len;
4161 2144936 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
4162 : {
4163 1713748 : RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i]; // Q6
4164 1713748 : move32();
4165 1713748 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i]; // Q6
4166 1713748 : move32();
4167 : }
4168 431188 : samplesToProcess = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4169 :
4170 : // Calculating length of processed output
4171 431188 : Word16 no_col = st_ivas->cldfbSynDec[idx_in]->no_col;
4172 431188 : move16();
4173 431188 : Word16 no_channels = st_ivas->cldfbSynDec[idx_in]->no_channels;
4174 431188 : move16();
4175 431188 : IF( GT_16( samplesToProcess, -1 ) )
4176 : {
4177 : Word16 tmp, tmp_e;
4178 431188 : 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 );
4179 431188 : tmp = shr( tmp, 15 - tmp_e );
4180 431188 : no_col = s_min( no_col, tmp );
4181 : }
4182 431188 : out_len = imult1616( no_col, no_channels );
4183 :
4184 : // Scaling cldfb_state to Q6-1
4185 431188 : 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 ) );
4186 431188 : st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = ( Q6 - 1 );
4187 431188 : move16();
4188 431188 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, 0, 0, st_ivas->cldfbSynDec[idx_in] );
4189 :
4190 : // Scaling output from Q6-1 to Q11
4191 431188 : Scale_sig32( p_out, out_len, ( Q11 - ( Q6 - 1 ) ) );
4192 :
4193 431188 : idx_in = add( idx_in, 1 );
4194 : }
4195 : }
4196 : }
4197 : }
4198 :
4199 308205 : hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4200 308205 : move16();
4201 308205 : hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 );
4202 308205 : move16();
4203 :
4204 :
4205 308205 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4206 : {
4207 231804 : hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev;
4208 231804 : move16();
4209 231804 : hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev;
4210 231804 : move16();
4211 : }
4212 :
4213 308205 : test();
4214 308205 : test();
4215 308205 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
4216 : {
4217 360606 : FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ )
4218 : {
4219 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
4220 240404 : st_ivas->cldfbSynDec[i]->Q_cldfb_state = Q11;
4221 240404 : move16();
4222 : }
4223 : }
4224 188003 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
4225 : {
4226 : }
4227 : ELSE
4228 : {
4229 : Word16 outchannels;
4230 71052 : idx_lfe = 0;
4231 71052 : move16();
4232 71052 : idx_in = 0;
4233 71052 : move16();
4234 71052 : outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
4235 :
4236 71052 : test();
4237 71052 : test();
4238 71052 : test();
4239 71052 : test();
4240 71052 : test();
4241 71052 : test();
4242 71052 : test();
4243 71052 : IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
4244 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
4245 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
4246 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
4247 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
4248 : ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
4249 : {
4250 880 : outchannels = add( outchannels, 1 );
4251 : }
4252 :
4253 71052 : test();
4254 71052 : IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) )
4255 : {
4256 0 : FOR( ch = 0; ch < outchannels; ch++ )
4257 : {
4258 0 : test();
4259 0 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
4260 : {
4261 0 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
4262 : {
4263 0 : idx_lfe = add( idx_lfe, 1 );
4264 : }
4265 : }
4266 : }
4267 : }
4268 : ELSE
4269 : {
4270 544858 : FOR( ch = 0; ch < outchannels; ch++ )
4271 : {
4272 :
4273 473806 : test();
4274 473806 : test();
4275 473806 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
4276 : {
4277 41738 : test();
4278 41738 : IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
4279 : {
4280 6640 : Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
4281 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
4282 6640 : st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11;
4283 6640 : move16();
4284 : }
4285 : }
4286 432068 : ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled == 0 ) || NE_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
4287 : {
4288 431188 : 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
4289 431188 : st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11;
4290 431188 : move16();
4291 431188 : idx_in = add( idx_in, 1 );
4292 : }
4293 : }
4294 : }
4295 71052 : test();
4296 71052 : IF( !hDirACRend->hOutSetup.separateChannelEnabled || NE_32( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
4297 : {
4298 71052 : Word16 tmp_lfe_idx = 0;
4299 71052 : move16();
4300 544858 : FOR( ch = 0; ch < outchannels; ch++ )
4301 : {
4302 473806 : test();
4303 473806 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( EQ_16( hDirACRend->hOutSetup.index_lfe[tmp_lfe_idx], ch ) ) )
4304 : {
4305 41738 : IF( LT_16( tmp_lfe_idx, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
4306 : {
4307 0 : tmp_lfe_idx = add( tmp_lfe_idx, 1 );
4308 : }
4309 : }
4310 : }
4311 : }
4312 : }
4313 :
4314 308205 : pop_wmops();
4315 :
4316 308205 : return;
4317 : }
|