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