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 : Word16 tmp1, tmp4;
1754 : Word16 a, b_tmp;
1755 :
1756 12019288 : Word16 exp_factor = 0;
1757 12019288 : move16();
1758 12019288 : a = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor
1759 :
1760 12019288 : tmp1 = mult( a, dirac_dithering_azi_scale_fx[diff_idx] ); // exp_factor + 5
1761 :
1762 12019288 : Word32 tmp1_32 = L_deposit_h( tmp1 );
1763 : Word16 final_1_exp;
1764 12019288 : Word32 final_1_32 = BASOP_Util_Add_Mant32Exp( azimuth_fx, 9, tmp1_32, exp_factor + 5, &final_1_exp );
1765 12019288 : b_tmp = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor
1766 12019288 : tmp4 = mult( b_tmp, dirac_dithering_ele_scale_fx[diff_idx] ); // exp_factor + 4
1767 :
1768 12019288 : Word32 tmp4_32 = L_deposit_h( tmp4 );
1769 : Word16 final_2_exp;
1770 12019288 : Word32 final_2_32 = BASOP_Util_Add_Mant32Exp( elevation_fx, 9, tmp4_32, exp_factor + 4, &final_2_exp );
1771 :
1772 :
1773 12019288 : final_1_32 = BASOP_Util_Add_Mant32Exp( final_1_32, final_1_exp, ONE_IN_Q30, 0, &final_1_exp ); /*0.5 in q31*/
1774 12019288 : final_2_32 = BASOP_Util_Add_Mant32Exp( final_2_32, final_2_exp, ONE_IN_Q30, 0, &final_2_exp );
1775 :
1776 12019288 : azi = extract_h( L_shr( final_1_32, sub( sub( 31, final_1_exp ), 16 ) ) );
1777 12019288 : ele = extract_h( L_shr( final_2_32, sub( sub( 31, final_2_exp ), 16 ) ) );
1778 :
1779 : /*addition of one to compensate precision loss*/
1780 12019288 : if ( azi < 0 )
1781 : {
1782 1208380 : azi = add( azi, 1 );
1783 : }
1784 12019288 : if ( ele < 0 )
1785 : {
1786 4640550 : ele = add( ele, 1 );
1787 : }
1788 : /* limit the elevation to [-90, 90] */
1789 12019288 : ele = s_min( 90, ele );
1790 12019288 : ele = s_max( -90, ele );
1791 : }
1792 :
1793 18398008 : test();
1794 18398008 : IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && q_direction->coherence_band_data != NULL )
1795 : {
1796 0 : hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = ivas_divde_255[q_direction->coherence_band_data[qBand_idx].spread_coherence[block]];
1797 0 : move16();
1798 : }
1799 : ELSE
1800 : {
1801 18398008 : hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0;
1802 18398008 : move16();
1803 : }
1804 :
1805 18398008 : test();
1806 18398008 : IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && q_direction->coherence_band_data != NULL )
1807 : {
1808 0 : hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = ivas_divde_255[hQMetaData->surcoh_band_data[qBand_idx].surround_coherence[0]];
1809 0 : move16();
1810 : }
1811 : ELSE
1812 : {
1813 18398008 : hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0;
1814 18398008 : move16();
1815 : }
1816 :
1817 :
1818 18398008 : hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = q_direction->band_data[qBand_idx].energy_ratio_fx[0];
1819 18398008 : move32();
1820 18398008 : hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx;
1821 18398008 : move32();
1822 :
1823 18398008 : IF( hodirac_flag )
1824 : {
1825 6378720 : IF( idx_sec == 0 )
1826 : {
1827 3189360 : hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele;
1828 3189360 : move16();
1829 3189360 : hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi;
1830 3189360 : move16();
1831 3189360 : hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0;
1832 3189360 : move32();
1833 : }
1834 : ELSE
1835 : {
1836 3189360 : assert( idx_sec == 1 );
1837 3189360 : hSpatParamRendCom->elevation2[tmp_write_idx_band][b] = ele;
1838 3189360 : move16();
1839 3189360 : hSpatParamRendCom->azimuth2[tmp_write_idx_band][b] = azi;
1840 3189360 : move16();
1841 3189360 : hSpatParamRendCom->energy_ratio2_fx[tmp_write_idx_band][b] = L_sub( ONE_IN_Q30, diffuseness_sec_fx );
1842 3189360 : move32();
1843 : }
1844 : }
1845 : ELSE
1846 : {
1847 12019288 : hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele;
1848 12019288 : move16();
1849 12019288 : hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi;
1850 12019288 : move16();
1851 : }
1852 : }
1853 2603192 : tmp_write_idx_param_band = add( tmp_write_idx_param_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
1854 :
1855 :
1856 : } /* for ( block =...) */
1857 : } /* for ( band = ...) */
1858 : } /* for ( idx_sec = ...)*/
1859 :
1860 : /* Bands not transmitted -> zeroed*/
1861 95119 : FOR( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ )
1862 : {
1863 0 : tmp_write_idx_band = hSpatParamRendCom->dirac_bs_md_write_idx;
1864 0 : move16();
1865 :
1866 0 : FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
1867 : {
1868 0 : hSpatParamRendCom->spreadCoherence_fx[block][b] = 0;
1869 0 : move16();
1870 0 : hSpatParamRendCom->surroundingCoherence_fx[block][b] = 0;
1871 0 : move16();
1872 0 : hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = 0;
1873 0 : move32();
1874 0 : hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0;
1875 0 : move16();
1876 0 : hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0;
1877 0 : move16();
1878 0 : hSpatParamRendCom->energy_ratio1_fx[block][b] = 0;
1879 0 : move32();
1880 0 : hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0;
1881 0 : move32();
1882 0 : hSpatParamRendCom->elevation[tmp_write_idx_band][b] = 0;
1883 0 : move16();
1884 0 : hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = 0;
1885 0 : move16();
1886 :
1887 0 : tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
1888 : }
1889 : }
1890 : }
1891 : /* update buffer write index */
1892 132749 : hSpatParamRendCom->dirac_bs_md_write_idx = add( hSpatParamRendCom->dirac_bs_md_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length;
1893 132749 : move16();
1894 132749 : return;
1895 : }
1896 : /*-------------------------------------------------------------------------
1897 : * ivas_dirac_dec_set_md_map()
1898 : *
1899 : * Set metadata index mapping for DirAC
1900 : *------------------------------------------------------------------------*/
1901 0 : void ivas_dirac_dec_set_md_map(
1902 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
1903 : const Word16 nCldfbTs /* i : number of CLDFB time slots */
1904 : )
1905 : {
1906 : Word16 num_slots_in_subfr;
1907 : DIRAC_DEC_HANDLE hDirAC;
1908 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1909 :
1910 0 : hDirAC = st_ivas->hDirAC;
1911 0 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1912 :
1913 : /* adapt subframes */
1914 0 : hSpatParamRendCom->num_slots = nCldfbTs;
1915 0 : move16();
1916 0 : hSpatParamRendCom->slots_rendered = 0;
1917 0 : move16();
1918 0 : num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
1919 0 : move16();
1920 0 : hSpatParamRendCom->subframes_rendered = 0;
1921 0 : move16();
1922 :
1923 0 : ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes );
1924 :
1925 : /* copy also to tc buffer */
1926 : /* only for non-combined formats and combinded formats w/o discrete objects */
1927 0 : test();
1928 0 : test();
1929 0 : test();
1930 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 ) ) )
1931 : {
1932 0 : st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes;
1933 0 : move16();
1934 0 : Copy( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes );
1935 : }
1936 :
1937 : /* set mapping according to dirac_read_idx */
1938 :
1939 0 : set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
1940 :
1941 0 : test();
1942 0 : test();
1943 0 : IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
1944 : {
1945 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 );
1946 : }
1947 0 : ELSE IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
1948 : {
1949 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 );
1950 : }
1951 : ELSE
1952 : {
1953 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 );
1954 : }
1955 :
1956 0 : test();
1957 0 : test();
1958 0 : IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
1959 : {
1960 : Word64 tmp_fx;
1961 : Word16 sf_idx, slot_idx, slot_idx_abs;
1962 : Word32 quo, rem;
1963 :
1964 0 : slot_idx_abs = 0;
1965 0 : move16();
1966 0 : FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ )
1967 : {
1968 0 : tmp_fx = 0;
1969 0 : move64();
1970 0 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ )
1971 : {
1972 0 : tmp_fx = W_add_nosat( tmp_fx, W_deposit32_l( L_deposit_l( hSpatParamRendCom->render_to_md_map[slot_idx_abs] ) ) );
1973 0 : slot_idx_abs = add( slot_idx_abs, 1 );
1974 : }
1975 0 : iDiv_and_mod_32( W_extract_l( W_shl_nosat( tmp_fx, 16 ) ), hSpatParamRendCom->subframe_nbslots[sf_idx], &quo, &rem, 0 );
1976 0 : hSpatParamRendCom->render_to_md_map[sf_idx] = add( round_fx( quo ), hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length;
1977 0 : move16();
1978 : }
1979 :
1980 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 ) );
1981 : }
1982 :
1983 0 : return;
1984 : }
1985 :
1986 145747 : void ivas_dirac_dec_set_md_map_fx(
1987 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
1988 : const Word16 nCldfbTs /* i : number of CLDFB time slots */
1989 : )
1990 : {
1991 : Word16 num_slots_in_subfr;
1992 : DIRAC_DEC_HANDLE hDirAC;
1993 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1994 :
1995 145747 : hDirAC = st_ivas->hDirAC;
1996 145747 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1997 :
1998 : /* adapt subframes */
1999 145747 : hSpatParamRendCom->num_slots = nCldfbTs;
2000 145747 : move16();
2001 145747 : hSpatParamRendCom->slots_rendered = 0;
2002 145747 : move16();
2003 145747 : num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
2004 145747 : move16();
2005 145747 : hSpatParamRendCom->subframes_rendered = 0;
2006 145747 : move16();
2007 :
2008 145747 : ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes );
2009 :
2010 : /* copy also to tc buffer */
2011 : /* only for non-combined formats and combinded formats w/o discrete objects */
2012 145747 : test();
2013 145747 : test();
2014 145747 : test();
2015 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 ) ) )
2016 : {
2017 133074 : st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes;
2018 133074 : move16();
2019 133074 : Copy( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes );
2020 : }
2021 :
2022 : /* set mapping according to dirac_read_idx */
2023 :
2024 145747 : set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
2025 :
2026 145747 : test();
2027 145747 : test();
2028 145747 : IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
2029 : {
2030 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 );
2031 : }
2032 119215 : ELSE IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
2033 : {
2034 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 );
2035 : }
2036 : ELSE
2037 : {
2038 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 );
2039 : }
2040 :
2041 145747 : test();
2042 145747 : test();
2043 145747 : IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
2044 : {
2045 : Word16 sf_idx, slot_idx, slot_idx_abs;
2046 : Word32 tmp_fx;
2047 : Word32 num;
2048 : Word16 denom, norm_denom, exp_denom, exp_num, norm_num, exp;
2049 : Word32 ans, ans_fix_32;
2050 : Word16 ans_fix_16, exp_final;
2051 :
2052 102323 : slot_idx_abs = 0;
2053 102323 : move16();
2054 515437 : FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ )
2055 : {
2056 413114 : tmp_fx = 0;
2057 413114 : move32();
2058 2050397 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ )
2059 : {
2060 1637283 : tmp_fx = L_add( tmp_fx, L_deposit_h( hSpatParamRendCom->render_to_md_map[slot_idx_abs] ) );
2061 1637283 : slot_idx_abs = add( slot_idx_abs, 1 );
2062 : }
2063 :
2064 413114 : exp_denom = 15, exp_num = 31;
2065 413114 : move16();
2066 413114 : move16();
2067 413114 : norm_num = norm_l( tmp_fx );
2068 413114 : num = L_shl( tmp_fx, norm_num );
2069 413114 : exp_num = sub( exp_num, norm_num );
2070 :
2071 413114 : norm_denom = norm_s( hSpatParamRendCom->subframe_nbslots[sf_idx] );
2072 413114 : denom = shl( hSpatParamRendCom->subframe_nbslots[sf_idx], norm_denom );
2073 413114 : exp_denom = sub( exp_denom, norm_denom );
2074 :
2075 413114 : exp = sub( exp_num, exp_denom );
2076 :
2077 413114 : IF( GT_32( num, L_deposit_l( denom ) ) )
2078 : {
2079 310779 : num = L_shr( num, 1 );
2080 310779 : exp = add( exp, 1 );
2081 : }
2082 :
2083 413114 : ans = div_l( num, denom );
2084 413114 : ans_fix_32 = BASOP_Util_Add_Mant32Exp( ans, exp, L_deposit_h( hSpatParamRendCom->dirac_read_idx ), 15 /*31 - 16*/, &exp_final );
2085 413114 : ans_fix_16 = round_fx( L_shr( ans_fix_32, sub( sub( Q31, exp_final ), Q16 ) ) );
2086 :
2087 413114 : hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; // Q0
2088 413114 : move16();
2089 : }
2090 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 ) );
2091 : }
2092 :
2093 145747 : return;
2094 : }
2095 : /*-------------------------------------------------------------------------
2096 : * ivas_dirac_dec_render_fx()
2097 : *
2098 : * DirAC decoding renderer process
2099 : *------------------------------------------------------------------------*/
2100 :
2101 20306 : void ivas_dirac_dec_render_fx(
2102 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
2103 : const Word16 nchan_transport, /* i : number of transport channels */
2104 : const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */
2105 : UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */
2106 : UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */
2107 : Word32 *output_fx[] /* o : rendered time signal Q(6-1)*/
2108 : )
2109 : {
2110 : Word16 slots_to_render, first_sf, last_sf, subframe_idx;
2111 : UWord16 slot_size, n_samples_sf, ch, nchan_intern;
2112 20306 : Word16 temp = 0;
2113 20306 : move16();
2114 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
2115 : Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS];
2116 20306 : Word32 output_f_local_buff_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; // VE2SB: TBV
2117 :
2118 20306 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
2119 :
2120 20306 : nchan_intern = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
2121 148326 : FOR( ch = 0; ch < nchan_intern; ch++ )
2122 : {
2123 128020 : output_f_local_fx[ch] = output_f_local_buff_fx[ch];
2124 128020 : set_zero_fx( output_f_local_fx[ch], nSamplesAsked );
2125 : }
2126 20306 : slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // cL
2127 :
2128 :
2129 : /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
2130 20306 : slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) );
2131 :
2132 20306 : *nSamplesRendered = i_mult( slots_to_render, slot_size );
2133 20306 : move16();
2134 :
2135 20306 : first_sf = hSpatParamRendCom->subframes_rendered;
2136 20306 : move16();
2137 20306 : last_sf = first_sf;
2138 20306 : move16();
2139 :
2140 90117 : WHILE( slots_to_render > 0 )
2141 : {
2142 69811 : slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] );
2143 69811 : last_sf = add( last_sf, 1 );
2144 : }
2145 :
2146 90117 : FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
2147 : {
2148 69811 : ivas_dirac_dec_render_sf_fx( st_ivas, output_f_local_fx, nchan_transport, NULL, NULL );
2149 :
2150 69811 : n_samples_sf = i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slot_size );
2151 :
2152 531657 : FOR( ch = 0; ch < nchan_intern; ch++ )
2153 : {
2154 461846 : output_f_local_fx[ch] += n_samples_sf;
2155 : }
2156 :
2157 : /* update combined orientation access index */
2158 69811 : ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
2159 : }
2160 :
2161 148326 : FOR( ch = 0; ch < nchan_intern; ch++ )
2162 : {
2163 128020 : test();
2164 128020 : test();
2165 128020 : IF( !( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ) && ( ( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ) || EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) )
2166 : {
2167 127670 : Copy32( output_f_local_buff_fx[ch], output_fx[ch], *nSamplesRendered );
2168 : }
2169 : }
2170 :
2171 20306 : IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) ){
2172 17258 : IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) ){
2173 0 : temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS );
2174 0 : hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0
2175 : }
2176 : ELSE
2177 : {
2178 17258 : temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS );
2179 17258 : hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0
2180 : }
2181 : }
2182 :
2183 20306 : *nSamplesAvailableNext = i_mult( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), slot_size ); // Q0
2184 20306 : move16();
2185 :
2186 20306 : return;
2187 : }
2188 :
2189 : /*-------------------------------------------------------------------------
2190 : * ivas_dirac_dec_render_sf_fx()
2191 : *
2192 : * DirAC decoding renderer process
2193 : *------------------------------------------------------------------------*/
2194 :
2195 297983 : void ivas_dirac_dec_render_sf_fx(
2196 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
2197 : Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output Q(6-1)*/
2198 : const Word16 nchan_transport, /* i : number of transport channels */
2199 : Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], /*Q6*/
2200 : Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] /*Q6*/
2201 : )
2202 : {
2203 : Word16 i, ch, idx_in, idx_lfe;
2204 : DIRAC_DEC_HANDLE hDirAC;
2205 : DIRAC_REND_HANDLE hDirACRend;
2206 : Word16 subframe_idx;
2207 : Word16 slot_idx, index_slot;
2208 : Word16 hodirac_flag;
2209 : Word16 slot_idx_start, slot_idx_start_cldfb_synth, md_idx;
2210 :
2211 : /*CLDFB: last output channels reserved to LFT for CICPx*/
2212 : Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
2213 : Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
2214 : Word32 Cldfb_RealBuffer_Binaural_fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
2215 : Word32 Cldfb_ImagBuffer_Binaural_fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
2216 297983 : Word16 index = 0, num_freq_bands = 0;
2217 297983 : move16();
2218 297983 : move16();
2219 :
2220 :
2221 5065711 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2222 : {
2223 23838640 : FOR( Word16 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
2224 : {
2225 19070912 : set32_fx( Cldfb_RealBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
2226 19070912 : set32_fx( Cldfb_ImagBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
2227 : }
2228 : }
2229 :
2230 893949 : FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
2231 : {
2232 2979830 : FOR( Word16 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
2233 : {
2234 2383864 : set32_fx( Cldfb_RealBuffer_Binaural_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
2235 2383864 : set32_fx( Cldfb_RealBuffer_Binaural_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
2236 : }
2237 : }
2238 :
2239 : /* local copies of azi, ele, diffuseness */
2240 : Word16 azimuth[CLDFB_NO_CHANNELS_MAX];
2241 : Word16 elevation[CLDFB_NO_CHANNELS_MAX];
2242 : Word32 diffuseness_vector_fx[CLDFB_NO_CHANNELS_MAX];
2243 : Word32 *p_Rmat_fx;
2244 : Word32 *reference_power_fx, *reference_power_smooth_fx, *onset_filter_fx, *onset_filter_subframe_fx;
2245 : Word32 dirEne_fx;
2246 : Word32 surCohEner_fx;
2247 : Word32 surCohRatio_fx[CLDFB_NO_CHANNELS_MAX];
2248 297983 : Word16 surCohRatio_q_fx = 0, temp_q = 0;
2249 297983 : move16();
2250 297983 : move16();
2251 : Word32 Cldfb_RealBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2252 : Word32 Cldfb_ImagBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2253 : Word16 cldfb_buf_q;
2254 297983 : Word16 offset = 0, buff_len = 0;
2255 297983 : move16();
2256 297983 : move16();
2257 297983 : Word16 q_cldfb, q_temp_cldfb = 0;
2258 297983 : move16();
2259 297983 : Word16 proto_length = 0;
2260 297983 : move16();
2261 : Word16 q_proto_direct_buffer[CLDFB_SLOTS_PER_SUBFRAME + 1];
2262 : Word16 q_proto_diffuse_buffer[CLDFB_SLOTS_PER_SUBFRAME + 1];
2263 : Word16 size, size_ho;
2264 :
2265 : DIRAC_DEC_STACK_MEM DirAC_mem;
2266 297983 : Word32 *p_onset_filter_fx = NULL;
2267 : UWord16 coherence_flag;
2268 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
2269 297983 : Word16 scale = 0;
2270 297983 : move16();
2271 : DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params;
2272 : DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state;
2273 : Word16 num_channels_dir, exp;
2274 : #ifdef FIX_867_CLDFB_NRG_SCALE
2275 297983 : Word16 q_diffuseness_vector = Q31, q_reference_power_smooth[2] = { Q31, Q31 };
2276 297983 : move16();
2277 : #else
2278 : Word16 q_diffuseness_vector = Q31, q_reference_power_smooth = Q31;
2279 : #endif
2280 297983 : move16();
2281 297983 : move16();
2282 297983 : Word16 proto_power_smooth_len = 0;
2283 297983 : move16();
2284 : Word16 tmp1;
2285 :
2286 297983 : push_wmops( "ivas_dirac_dec_render" );
2287 :
2288 : /* Initialize aux buffers */
2289 297983 : hDirAC = st_ivas->hDirAC;
2290 297983 : hDirACRend = st_ivas->hDirACRend;
2291 297983 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
2292 :
2293 297983 : DirAC_mem = hDirACRend->stack_mem;
2294 :
2295 297983 : reference_power_fx = DirAC_mem.reference_power_fx;
2296 297983 : IF( DirAC_mem.reference_power_fx == NULL )
2297 : {
2298 8648 : reference_power_smooth_fx = NULL;
2299 : }
2300 : ELSE
2301 : {
2302 289335 : reference_power_smooth_fx = DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands;
2303 : }
2304 297983 : onset_filter_fx = DirAC_mem.onset_filter_fx;
2305 297983 : IF( DirAC_mem.onset_filter_fx == NULL )
2306 : {
2307 26214 : onset_filter_subframe_fx = NULL;
2308 : }
2309 : ELSE
2310 : {
2311 271769 : onset_filter_subframe_fx = DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands;
2312 : }
2313 297983 : q_cldfb = Q11;
2314 297983 : move16();
2315 297983 : set16_fx( q_proto_direct_buffer, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME + 1 );
2316 297983 : set16_fx( q_proto_diffuse_buffer, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME + 1 );
2317 297983 : set_zero_fx( surCohRatio_fx, CLDFB_NO_CHANNELS_MAX );
2318 :
2319 297983 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
2320 : {
2321 8214 : IF( hDirACRend->masa_stereo_type_detect )
2322 : {
2323 8214 : hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = 0;
2324 8214 : move32();
2325 8214 : hDirACRend->masa_stereo_type_detect->q_subtract_power_y = Q31;
2326 8214 : move16();
2327 : }
2328 : }
2329 :
2330 297983 : test();
2331 297983 : IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) )
2332 : {
2333 70949 : IF( hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0 )
2334 : {
2335 52949 : DIRAC_OUTPUT_SYNTHESIS_STATE *state = &( hDirACRend->h_output_synthesis_psd_state );
2336 52949 : tmp1 = L_norm_arr( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len );
2337 :
2338 52949 : scale_sig32( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len, tmp1 ); // Q(proto_power_diff_smooth_q + tmp1)
2339 52949 : state->proto_power_diff_smooth_q = add( state->proto_power_diff_smooth_q, tmp1 );
2340 52949 : move16();
2341 : }
2342 : }
2343 :
2344 297983 : h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
2345 297983 : h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
2346 297983 : num_channels_dir = hDirACRend->num_outputs_dir;
2347 297983 : move16();
2348 297983 : hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
2349 297983 : if ( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
2350 : {
2351 58517 : num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE;
2352 58517 : move16();
2353 : }
2354 :
2355 297983 : test();
2356 297983 : test();
2357 297983 : 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 ) ) )
2358 : {
2359 40517 : tmp1 = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
2360 40517 : 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
2361 40517 : h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = tmp1;
2362 40517 : move16();
2363 : }
2364 :
2365 297983 : test();
2366 297983 : IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2367 : {
2368 : Word16 shift;
2369 18000 : shift = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
2370 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
2371 18000 : h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, shift );
2372 18000 : move16();
2373 18000 : shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
2374 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
2375 18000 : h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, shift );
2376 18000 : move16();
2377 18000 : tmp1 = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
2378 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
2379 18000 : h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp1 );
2380 18000 : move16();
2381 : }
2382 :
2383 :
2384 297983 : test();
2385 297983 : test();
2386 297983 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
2387 : {
2388 318675 : FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
2389 : {
2390 212450 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11;
2391 212450 : move16();
2392 : }
2393 : }
2394 191758 : ELSE IF( !( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
2395 : {
2396 : Word16 outchannels;
2397 69811 : idx_lfe = 0;
2398 69811 : move16();
2399 69811 : idx_in = 0;
2400 69811 : move16();
2401 69811 : outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
2402 :
2403 69811 : test();
2404 69811 : test();
2405 69811 : test();
2406 69811 : test();
2407 69811 : test();
2408 69811 : test();
2409 69811 : test();
2410 69811 : IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
2411 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
2412 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
2413 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
2414 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
2415 : ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
2416 : {
2417 700 : outchannels = add( outchannels, 1 );
2418 : }
2419 :
2420 69811 : test();
2421 69811 : IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) )
2422 : {
2423 0 : FOR( ch = 0; ch < outchannels; ch++ )
2424 : {
2425 0 : test();
2426 0 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
2427 : {
2428 0 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
2429 : {
2430 0 : idx_lfe = add( idx_lfe, 1 );
2431 : }
2432 : }
2433 : }
2434 : }
2435 : ELSE
2436 : {
2437 531657 : FOR( ch = 0; ch < outchannels; ch++ )
2438 : {
2439 :
2440 461846 : test();
2441 461846 : test();
2442 461846 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
2443 : {
2444 40517 : test();
2445 40517 : IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
2446 : {
2447 : Word16 cldfbSynIdx;
2448 5860 : cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
2449 5860 : st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11;
2450 5860 : move16();
2451 : }
2452 : }
2453 421329 : ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
2454 : {
2455 : }
2456 : ELSE
2457 : {
2458 420629 : st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11;
2459 420629 : move16();
2460 420629 : idx_in = add( idx_in, 1 );
2461 : }
2462 : }
2463 : }
2464 : }
2465 :
2466 297983 : size = imult1616( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands );
2467 297983 : IF( hodirac_flag )
2468 : {
2469 53156 : size_ho = imult1616( size, DIRAC_HO_NUMSECTORS );
2470 : }
2471 : ELSE
2472 : {
2473 244827 : size_ho = size;
2474 244827 : move16();
2475 : }
2476 297983 : 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
2477 297983 : hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26;
2478 297983 : move16();
2479 :
2480 297983 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2481 : {
2482 : Word16 shift;
2483 218820 : shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho );
2484 218820 : 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)
2485 218820 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, shift );
2486 218820 : move16();
2487 :
2488 218820 : 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
2489 218820 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26;
2490 218820 : move16();
2491 :
2492 218820 : 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
2493 218820 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26;
2494 218820 : move16();
2495 :
2496 218820 : 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
2497 218820 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26;
2498 218820 : move16();
2499 : }
2500 : ELSE
2501 : {
2502 : Word16 shift;
2503 79163 : 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
2504 79163 : hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26;
2505 79163 : move16();
2506 :
2507 79163 : shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho );
2508 79163 : 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)
2509 79163 : 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 );
2510 79163 : move16();
2511 79163 : shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho );
2512 79163 : 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)
2513 79163 : 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 );
2514 79163 : move16();
2515 79163 : 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 ) );
2516 79163 : 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)
2517 79163 : 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 );
2518 79163 : move16();
2519 : #ifdef FIX_867_CLDFB_NRG_SCALE
2520 79163 : tmp1 = 31;
2521 79163 : move16();
2522 369519 : FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
2523 : {
2524 290356 : 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 ) ) );
2525 : }
2526 369519 : FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
2527 : {
2528 290356 : 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)
2529 : }
2530 79163 : 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 );
2531 79163 : move16();
2532 79163 : tmp1 = 31;
2533 79163 : move16();
2534 369519 : FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
2535 : {
2536 290356 : 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 ) ) ) );
2537 : }
2538 369519 : FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
2539 : {
2540 290356 : 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)
2541 : }
2542 79163 : 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 );
2543 79163 : move16();
2544 : #else
2545 : tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ) );
2546 : 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)
2547 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, tmp1 );
2548 : move16();
2549 : #endif
2550 79163 : IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 )
2551 : {
2552 52949 : 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 ) );
2553 52949 : 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)
2554 52949 : 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 );
2555 52949 : move16();
2556 : }
2557 : }
2558 :
2559 297983 : hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
2560 :
2561 297983 : test();
2562 297983 : test();
2563 297983 : IF( st_ivas->hQMetaData != NULL && NE_32( st_ivas->ivas_format, SBA_FORMAT ) && NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
2564 : {
2565 69811 : coherence_flag = st_ivas->hQMetaData->coherence_flag;
2566 69811 : move16();
2567 : }
2568 : ELSE
2569 : {
2570 228172 : coherence_flag = 0;
2571 228172 : move16();
2572 : }
2573 : /* Subframe loop */
2574 297983 : slot_idx_start = hSpatParamRendCom->slots_rendered;
2575 297983 : move16();
2576 297983 : slot_idx_start_cldfb_synth = 0;
2577 297983 : move16();
2578 :
2579 297983 : subframe_idx = hSpatParamRendCom->subframes_rendered;
2580 297983 : move16();
2581 297983 : IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
2582 : {
2583 122967 : md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
2584 122967 : move16();
2585 : }
2586 : ELSE
2587 : {
2588 175016 : md_idx = hSpatParamRendCom->render_to_md_map[slot_idx_start];
2589 175016 : move16();
2590 : }
2591 :
2592 : /* copy parameters into local buffers*/
2593 297983 : IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
2594 : {
2595 122967 : Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands );
2596 122967 : q_diffuseness_vector = Q30;
2597 122967 : move16();
2598 122967 : Copy( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands );
2599 122967 : Copy( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands );
2600 : }
2601 : ELSE
2602 : {
2603 175016 : set32_fx( diffuseness_vector_fx, 0, hSpatParamRendCom->num_freq_bands );
2604 175016 : q_diffuseness_vector = Q31;
2605 175016 : move16();
2606 : }
2607 :
2608 297983 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2609 : {
2610 79163 : set_zero_fx( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands );
2611 : }
2612 : ELSE
2613 : {
2614 218820 : set_zero_fx( onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands );
2615 : }
2616 :
2617 297983 : test();
2618 297983 : IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] )
2619 : {
2620 41400 : p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0];
2621 :
2622 41400 : IF( st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
2623 : {
2624 36800 : num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
2625 36800 : move16();
2626 36800 : IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
2627 : {
2628 0 : rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx );
2629 : }
2630 : }
2631 : }
2632 : ELSE
2633 : {
2634 256583 : p_Rmat_fx = 0;
2635 256583 : move32();
2636 : }
2637 :
2638 297983 : IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
2639 : {
2640 : Word16 *masa_band_mapping;
2641 : /* compute response */
2642 122967 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2643 : {
2644 61163 : ivas_dirac_dec_compute_power_factors_fx( hSpatParamRendCom->num_freq_bands,
2645 : diffuseness_vector_fx,
2646 61163 : hDirACRend->h_output_synthesis_psd_params.max_band_decorr,
2647 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
2648 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx );
2649 :
2650 61163 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q29;
2651 61163 : move16();
2652 61163 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q29;
2653 61163 : move16();
2654 :
2655 61163 : IF( coherence_flag )
2656 : {
2657 1563308 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
2658 : {
2659 1535140 : dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; // Q29
2660 1535140 : move32();
2661 1535140 : 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
2662 :
2663 1535140 : 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
2664 1535140 : move32();
2665 1535140 : 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
2666 1535140 : move32();
2667 :
2668 1535140 : surCohRatio_fx[i] = BASOP_Util_Divide3232_Scale_newton( surCohEner_fx, ( L_add( EPSILLON_FX, L_add( dirEne_fx, surCohEner_fx ) ) ), &temp_q );
2669 1535140 : move32();
2670 1535140 : surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], sub( temp_q, 16 ) ); // Q15
2671 1535140 : move32();
2672 : }
2673 : }
2674 : ELSE
2675 : {
2676 32995 : set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands );
2677 : }
2678 61163 : surCohRatio_q_fx = Q15;
2679 61163 : move16();
2680 : }
2681 : ELSE
2682 : {
2683 : Word16 max_exp_direct, max_exp_diffusion;
2684 61804 : max_exp_direct = 0;
2685 61804 : move16();
2686 61804 : max_exp_diffusion = 0;
2687 61804 : move16();
2688 61804 : ivas_dirac_dec_compute_gain_factors_fx( hSpatParamRendCom->num_freq_bands,
2689 61804 : hSpatParamRendCom->diffuseness_vector_fx[md_idx],
2690 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
2691 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx,
2692 : &max_exp_direct, &max_exp_diffusion );
2693 :
2694 61804 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub( Q31, max_exp_direct );
2695 61804 : move16();
2696 61804 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub( Q31, max_exp_diffusion );
2697 61804 : move16();
2698 :
2699 61804 : IF( coherence_flag )
2700 : {
2701 263947 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
2702 : {
2703 259620 : surCohRatio_fx[i] = L_deposit_l( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] );
2704 259620 : move32();
2705 : }
2706 : }
2707 : ELSE
2708 : {
2709 57477 : set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands );
2710 : }
2711 61804 : surCohRatio_q_fx = Q15;
2712 61804 : move16();
2713 : }
2714 :
2715 122967 : IF( st_ivas->hMasa == NULL )
2716 : {
2717 53156 : masa_band_mapping = NULL;
2718 : }
2719 : ELSE
2720 : {
2721 69811 : masa_band_mapping = st_ivas->hMasa->data.band_mapping;
2722 : }
2723 122967 : test();
2724 122967 : test();
2725 122967 : IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 1 ) )
2726 : {
2727 0 : ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom,
2728 : hDirACRend,
2729 : st_ivas->hVBAPdata,
2730 : masa_band_mapping,
2731 : st_ivas->hMasaIsmData,
2732 : azimuth,
2733 : elevation,
2734 : md_idx,
2735 : surCohRatio_fx,
2736 : surCohRatio_q_fx,
2737 0 : st_ivas->hCombinedOrientationData->shd_rot_max_order,
2738 : p_Rmat_fx,
2739 : hodirac_flag );
2740 : }
2741 : ELSE
2742 : {
2743 122967 : ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom,
2744 : hDirACRend,
2745 : st_ivas->hVBAPdata,
2746 : masa_band_mapping,
2747 : st_ivas->hMasaIsmData,
2748 : azimuth,
2749 : elevation,
2750 : md_idx,
2751 : surCohRatio_fx,
2752 : surCohRatio_q_fx,
2753 : 0,
2754 : NULL,
2755 : hodirac_flag );
2756 : }
2757 : }
2758 :
2759 297983 : test();
2760 297983 : IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) )
2761 : {
2762 47291 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
2763 : {
2764 37816 : index_slot = add( slot_idx_start, slot_idx );
2765 37816 : offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot );
2766 : /* CLDFB Analysis*/
2767 113448 : FOR( ch = 0; ch < nchan_transport; ch++ )
2768 : {
2769 75632 : q_temp_cldfb = Q11;
2770 75632 : move16();
2771 75632 : cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset],
2772 75632 : Cldfb_RealBuffer_Temp_fx[ch][slot_idx],
2773 75632 : Cldfb_ImagBuffer_Temp_fx[ch][slot_idx],
2774 75632 : hSpatParamRendCom->num_freq_bands,
2775 : st_ivas->cldfbAnaDec[ch], &q_temp_cldfb );
2776 : }
2777 37816 : q_cldfb = q_temp_cldfb;
2778 37816 : move16();
2779 : }
2780 :
2781 9475 : test();
2782 9475 : IF( ( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) )
2783 : {
2784 2635 : ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( st_ivas, Cldfb_RealBuffer_Temp_fx, Cldfb_ImagBuffer_Temp_fx, &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx );
2785 : }
2786 : }
2787 :
2788 1481648 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
2789 : {
2790 1183665 : index_slot = add( slot_idx_start, slot_idx );
2791 1183665 : IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) )
2792 : {
2793 694820 : md_idx = hSpatParamRendCom->render_to_md_map[index_slot];
2794 694820 : move16();
2795 : }
2796 : ELSE
2797 : {
2798 488845 : md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
2799 488845 : move16();
2800 : }
2801 1183665 : test();
2802 1183665 : test();
2803 1183665 : IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
2804 : {
2805 5966668 : FOR( ch = 0; ch < nchan_transport; ch++ )
2806 : {
2807 5059224 : Copy32( pppQMfFrame_ts_re_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2808 5059224 : Copy32( pppQMfFrame_ts_im_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2809 : }
2810 907444 : q_cldfb = Q6;
2811 907444 : move16();
2812 : }
2813 276221 : ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) )
2814 : {
2815 113448 : FOR( ch = 0; ch < nchan_transport; ch++ )
2816 : {
2817 75632 : Copy32( Cldfb_RealBuffer_Temp_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2818 75632 : Copy32( Cldfb_ImagBuffer_Temp_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
2819 : }
2820 : }
2821 : ELSE
2822 : {
2823 : /* CLDFB Analysis*/
2824 238405 : offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot );
2825 570823 : FOR( ch = 0; ch < nchan_transport; ch++ )
2826 : {
2827 332418 : q_temp_cldfb = Q11;
2828 332418 : move16();
2829 332418 : cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset],
2830 332418 : Cldfb_RealBuffer_fx[ch][0],
2831 332418 : Cldfb_ImagBuffer_fx[ch][0],
2832 332418 : hSpatParamRendCom->num_freq_bands,
2833 : st_ivas->cldfbAnaDec[ch], &q_temp_cldfb );
2834 : }
2835 238405 : q_cldfb = q_temp_cldfb;
2836 238405 : move16();
2837 : }
2838 :
2839 : /* CNG in DirAC, extra CLDFB ana for CNA*/
2840 1183665 : test();
2841 1183665 : test();
2842 1183665 : test();
2843 1183665 : test();
2844 1183665 : 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 ) ) ) )
2845 : {
2846 34592 : Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0];
2847 34592 : Word16 Q_input = Q11;
2848 34592 : move16();
2849 34592 : q_temp_cldfb = Q11;
2850 34592 : move16();
2851 34592 : test();
2852 34592 : test();
2853 34592 : test();
2854 103776 : generate_masking_noise_dirac_ivas_fx( st->hFdCngDec->hFdCngCom,
2855 : st_ivas->cldfbAnaDec[1],
2856 34592 : st_ivas->hTcBuffer->tc_fx[1],
2857 : Cldfb_RealBuffer_fx[1][0],
2858 : Cldfb_ImagBuffer_fx[1][0],
2859 : index_slot,
2860 34592 : st->cna_dirac_flag && st->flag_cna,
2861 34592 : ( ( ( 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 );
2862 34592 : Scale_sig32( Cldfb_RealBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6
2863 34592 : Scale_sig32( Cldfb_ImagBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6
2864 : }
2865 :
2866 : /* LFE synthesis */
2867 1183665 : test();
2868 1183665 : test();
2869 1183665 : test();
2870 1183665 : 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 ) )
2871 : {
2872 23440 : ivas_lfe_synth_with_cldfb_fx( st_ivas->hMasa->hMasaLfeSynth,
2873 : Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
2874 : Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1], Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1],
2875 : slot_idx,
2876 : md_idx,
2877 : nchan_transport, q_cldfb );
2878 : }
2879 :
2880 : /*-----------------------------------------------------------------*
2881 : * protoype signal computation
2882 : *-----------------------------------------------------------------*/
2883 1183665 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2884 : {
2885 870036 : test();
2886 870036 : test();
2887 870036 : IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
2888 : {
2889 147200 : protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
2890 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
2891 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
2892 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx,
2893 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
2894 : #ifdef FIX_867_CLDFB_NRG_SCALE
2895 : reference_power_fx, DirAC_mem.reference_power_q,
2896 : #else
2897 : reference_power_fx, &DirAC_mem.reference_power_q,
2898 : #endif
2899 : slot_idx, nchan_transport,
2900 147200 : hDirACRend->num_outputs_diff,
2901 147200 : hSpatParamRendCom->num_freq_bands,
2902 : p_Rmat_fx, q_cldfb );
2903 : }
2904 : ELSE
2905 : {
2906 722836 : protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
2907 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
2908 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
2909 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx,
2910 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
2911 : #ifdef FIX_867_CLDFB_NRG_SCALE
2912 : reference_power_fx, DirAC_mem.reference_power_q,
2913 : #else
2914 : reference_power_fx, &DirAC_mem.reference_power_q,
2915 : #endif
2916 : slot_idx, nchan_transport,
2917 722836 : hDirACRend->num_outputs_diff,
2918 722836 : hSpatParamRendCom->num_freq_bands,
2919 : 0, q_cldfb );
2920 : }
2921 :
2922 870036 : q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
2923 870036 : move16();
2924 870036 : q_proto_diffuse_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q;
2925 870036 : move16();
2926 : }
2927 313629 : ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
2928 : {
2929 29965 : protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx,
2930 : &hDirACRend->proto_frame_f_q,
2931 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
2932 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
2933 : reference_power_fx,
2934 : #ifdef FIX_867_CLDFB_NRG_SCALE
2935 : DirAC_mem.reference_power_q,
2936 : #else
2937 : &DirAC_mem.reference_power_q,
2938 : #endif
2939 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
2940 : #ifdef FIX_867_CLDFB_NRG_SCALE
2941 29965 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
2942 : #else
2943 : &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
2944 : #endif
2945 29965 : 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect,
2946 : q_cldfb );
2947 :
2948 29965 : q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
2949 29965 : move16();
2950 :
2951 29965 : proto_length = i_mult( 6, hSpatParamRendCom->num_freq_bands );
2952 29965 : proto_power_smooth_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
2953 : }
2954 : ELSE
2955 : {
2956 283664 : SWITCH( nchan_transport )
2957 : {
2958 72000 : case 11:
2959 : case 8:
2960 : case 6:
2961 : case 4:
2962 72000 : protoSignalComputation4_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
2963 : hDirACRend->proto_frame_f_fx,
2964 : &hDirACRend->proto_frame_f_q,
2965 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
2966 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
2967 : reference_power_fx,
2968 : #ifdef FIX_867_CLDFB_NRG_SCALE
2969 : DirAC_mem.reference_power_q,
2970 : #else
2971 : &DirAC_mem.reference_power_q,
2972 : #endif
2973 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
2974 : #ifdef FIX_867_CLDFB_NRG_SCALE
2975 72000 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
2976 : #else
2977 : &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
2978 : #endif
2979 72000 : slot_idx, hDirACRend->num_outputs_diff,
2980 72000 : hSpatParamRendCom->num_freq_bands,
2981 : hDirACRend->hoa_decoder,
2982 : nchan_transport,
2983 : hDirACRend->sba_map_tc, q_cldfb );
2984 72000 : proto_length = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
2985 72000 : proto_power_smooth_len = i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff );
2986 72000 : BREAK;
2987 101864 : case 2:
2988 101864 : protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx,
2989 : &hDirACRend->proto_frame_f_q,
2990 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
2991 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
2992 : reference_power_fx,
2993 : #ifdef FIX_867_CLDFB_NRG_SCALE
2994 : DirAC_mem.reference_power_q,
2995 : #else
2996 : &DirAC_mem.reference_power_q,
2997 : #endif
2998 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
2999 : #ifdef FIX_867_CLDFB_NRG_SCALE
3000 101864 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
3001 : #else
3002 : &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
3003 : #endif
3004 101864 : hDirACRend->hOutSetup.is_loudspeaker_setup,
3005 : slot_idx,
3006 101864 : hSpatParamRendCom->num_freq_bands,
3007 : hDirACRend->masa_stereo_type_detect,
3008 : q_cldfb );
3009 101864 : proto_length = i_mult( 6, hSpatParamRendCom->num_freq_bands );
3010 101864 : IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
3011 : {
3012 69852 : proto_power_smooth_len = i_mult( 3, hSpatParamRendCom->num_freq_bands );
3013 : }
3014 : ELSE
3015 : {
3016 32012 : proto_power_smooth_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
3017 : }
3018 101864 : BREAK;
3019 109800 : case 1:
3020 109800 : protoSignalComputation1_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
3021 : hDirACRend->proto_frame_f_fx,
3022 : &hDirACRend->proto_frame_f_q,
3023 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
3024 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
3025 : reference_power_fx,
3026 : #ifdef FIX_867_CLDFB_NRG_SCALE
3027 : DirAC_mem.reference_power_q,
3028 : #else
3029 : &DirAC_mem.reference_power_q,
3030 : #endif
3031 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
3032 : #ifdef FIX_867_CLDFB_NRG_SCALE
3033 109800 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
3034 : #else
3035 : &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
3036 : #endif
3037 : slot_idx,
3038 109800 : hDirACRend->num_protos_diff,
3039 109800 : hSpatParamRendCom->num_freq_bands, q_cldfb );
3040 109800 : proto_length = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_diff ) );
3041 109800 : proto_power_smooth_len = hSpatParamRendCom->num_freq_bands;
3042 109800 : move16();
3043 109800 : BREAK;
3044 0 : default:
3045 0 : return;
3046 : }
3047 283664 : q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
3048 283664 : move16();
3049 : }
3050 :
3051 : /*-----------------------------------------------------------------*
3052 : * Compute DirAC parameters at decoder side
3053 : *-----------------------------------------------------------------*/
3054 1183665 : IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) )
3055 : {
3056 694820 : 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 ) );
3057 694820 : 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 ) );
3058 :
3059 694820 : test();
3060 694820 : test();
3061 694820 : IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
3062 : {
3063 147200 : num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
3064 147200 : move16();
3065 147200 : rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx );
3066 : }
3067 :
3068 : /*hDirACRend->index_buffer_intensity = ( hDirACRend->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1 */
3069 694820 : IF( hDirACRend->index_buffer_intensity == 0 )
3070 : {
3071 189 : hDirACRend->index_buffer_intensity = 1;
3072 189 : move16();
3073 : }
3074 : ELSE
3075 : {
3076 694631 : 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 */
3077 694631 : move16();
3078 : }
3079 :
3080 694820 : index = hDirACRend->index_buffer_intensity;
3081 694820 : move16();
3082 694820 : num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
3083 694820 : move16();
3084 :
3085 694820 : computeIntensityVector_dec_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
3086 : q_cldfb, num_freq_bands,
3087 694820 : hDirACRend->buffer_intensity_real_fx[0][index - 1],
3088 694820 : hDirACRend->buffer_intensity_real_fx[1][index - 1],
3089 694820 : hDirACRend->buffer_intensity_real_fx[2][index - 1],
3090 694820 : &hDirACRend->q_buffer_intensity_real[index - 1] );
3091 :
3092 694820 : computeDirectionAngles_fx( hDirACRend->buffer_intensity_real_fx[0][index - 1],
3093 694820 : hDirACRend->buffer_intensity_real_fx[1][index - 1],
3094 694820 : hDirACRend->buffer_intensity_real_fx[2][index - 1],
3095 694820 : hDirACRend->q_buffer_intensity_real[index - 1],
3096 : num_freq_bands, azimuth, elevation );
3097 :
3098 694820 : Copy32( reference_power_fx, &( hDirACRend->buffer_energy_fx[i_mult( sub( index, 1 ), num_freq_bands )] ), num_freq_bands );
3099 : #ifdef FIX_867_CLDFB_NRG_SCALE
3100 694820 : 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] ) );
3101 694820 : hDirACRend->q_buffer_energy[index - 1] = DirAC_mem.reference_power_q[0];
3102 : #else
3103 : hDirACRend->q_buffer_energy[index - 1] = DirAC_mem.reference_power_q;
3104 : #endif
3105 694820 : move16();
3106 :
3107 694820 : 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 );
3108 : }
3109 :
3110 : /*-----------------------------------------------------------------*
3111 : * frequency domain decorrelation
3112 : *-----------------------------------------------------------------*/
3113 1183665 : IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) )
3114 : {
3115 : /* decorrelate prototype frame */
3116 1081700 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3117 : {
3118 2610108 : ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
3119 870036 : hDirACRend->num_outputs_diff,
3120 870036 : hDirACRend->num_protos_diff,
3121 : hDirACRend->synthesisConf,
3122 : nchan_transport,
3123 870036 : &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 )],
3124 870036 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
3125 870036 : hDirACRend->num_protos_diff,
3126 870036 : hDirACRend->proto_index_diff,
3127 870036 : &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 ) )],
3128 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
3129 : onset_filter_fx,
3130 : hDirACRend->h_freq_domain_decorr_ap_params,
3131 : hDirACRend->h_freq_domain_decorr_ap_state );
3132 :
3133 870036 : v_multc_fixed( onset_filter_fx, 536870912 /* 0.25f in Q31 */, onset_filter_fx, hSpatParamRendCom->num_freq_bands );
3134 :
3135 : #ifdef VEC_ARITH_OPT_v1
3136 870036 : v_add_fixed_no_hdrm( onset_filter_fx, onset_filter_subframe_fx, onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands ); /* Q31 */
3137 : #else /* VEC_ARITH_OPT_v1 */
3138 : v_add_fixed( onset_filter_fx, onset_filter_subframe_fx, onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands, 0 ); /* Q31 */
3139 : #endif /* VEC_ARITH_OPT_v1 */
3140 870036 : p_onset_filter_fx = onset_filter_subframe_fx;
3141 : }
3142 : ELSE
3143 : {
3144 211664 : scale = L_norm_arr( hDirACRend->proto_frame_f_fx, proto_length );
3145 211664 : Scale_sig32( hDirACRend->proto_frame_f_fx, proto_length, scale ); // Q(proto_frame_f_q+scale)
3146 211664 : hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, scale );
3147 211664 : move16();
3148 211664 : ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
3149 211664 : hDirACRend->num_outputs_diff,
3150 211664 : hDirACRend->num_protos_diff,
3151 : hDirACRend->synthesisConf,
3152 : nchan_transport,
3153 211664 : hDirACRend->proto_frame_f_fx,
3154 211664 : hDirACRend->proto_frame_f_q,
3155 211664 : hDirACRend->num_protos_diff,
3156 211664 : hDirACRend->proto_index_diff,
3157 : DirAC_mem.frame_dec_f_fx,
3158 : &DirAC_mem.frame_dec_f_q,
3159 : onset_filter_fx,
3160 : hDirACRend->h_freq_domain_decorr_ap_params,
3161 : hDirACRend->h_freq_domain_decorr_ap_state );
3162 :
3163 211664 : hDirACRend->proto_frame_dec_f_fx = DirAC_mem.frame_dec_f_fx;
3164 211664 : hDirACRend->proto_frame_dec_f_q = DirAC_mem.frame_dec_f_q;
3165 211664 : move16();
3166 211664 : hDirACRend->proto_frame_dec_f_len = DirAC_mem.frame_dec_f_len;
3167 211664 : move16();
3168 211664 : p_onset_filter_fx = onset_filter_fx;
3169 : }
3170 : }
3171 : ELSE
3172 : {
3173 101965 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3174 : {
3175 0 : set32_fx( onset_filter_subframe_fx, ONE_IN_Q31, hSpatParamRendCom->num_freq_bands );
3176 0 : p_onset_filter_fx = onset_filter_subframe_fx;
3177 : }
3178 : ELSE
3179 : {
3180 : /* no frequency domain decorrelation: use prototype frame */
3181 101965 : hDirACRend->proto_frame_dec_f_fx = hDirACRend->proto_frame_f_fx;
3182 101965 : hDirACRend->proto_frame_dec_f_len = hDirACRend->proto_frame_f_len;
3183 101965 : move16();
3184 101965 : hDirACRend->proto_frame_dec_f_q = hDirACRend->proto_frame_f_q;
3185 101965 : move16();
3186 101965 : p_onset_filter_fx = NULL;
3187 : }
3188 : }
3189 :
3190 : /*-----------------------------------------------------------------*
3191 : * output synthesis
3192 : *-----------------------------------------------------------------*/
3193 1183665 : test();
3194 1183665 : IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) )
3195 : {
3196 : DIRAC_OUTPUT_SYNTHESIS_STATE *state;
3197 : Word16 diffuse_start;
3198 283664 : state = &( hDirACRend->h_output_synthesis_psd_state );
3199 283664 : 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 ) );
3200 :
3201 283664 : exp = getScaleFactor32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len );
3202 283664 : scale_sig32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len, exp ); // hDirACRend->proto_frame_dec_f_q + exp
3203 283664 : hDirACRend->proto_frame_dec_f_q = add( hDirACRend->proto_frame_dec_f_q, exp );
3204 283664 : move16();
3205 283664 : exp = getScaleFactor32( state->proto_diffuse_buffer_f_fx, diffuse_start );
3206 283664 : scale_sig32( state->proto_diffuse_buffer_f_fx, diffuse_start, exp ); // state->proto_diffuse_buffer_f_q + exp
3207 283664 : state->proto_diffuse_buffer_f_q = add( state->proto_diffuse_buffer_f_q, exp );
3208 283664 : move16();
3209 : /*Compute diffuse prototypes*/
3210 283664 : ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx );
3211 : }
3212 :
3213 : /*Compute PSDs*/
3214 1183665 : h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
3215 1183665 : h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
3216 1183665 : num_channels_dir = hDirACRend->num_outputs_dir;
3217 1183665 : move16();
3218 :
3219 1183665 : if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
3220 : {
3221 233936 : num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE;
3222 233936 : move16();
3223 : }
3224 :
3225 1183665 : test();
3226 1183665 : test();
3227 1183665 : 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 ) ) ) )
3228 : {
3229 161936 : 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
3230 161936 : h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
3231 161936 : move16();
3232 :
3233 161936 : exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
3234 161936 : 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
3235 161936 : h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp );
3236 161936 : move16();
3237 : }
3238 :
3239 1183665 : test();
3240 1183665 : IF( ( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) )
3241 : {
3242 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
3243 72000 : h_dirac_output_synthesis_state->direct_power_factor_q = Q31;
3244 72000 : move16();
3245 :
3246 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
3247 72000 : h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
3248 72000 : move16();
3249 :
3250 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
3251 72000 : h_dirac_output_synthesis_state->direct_responses_q = Q31;
3252 72000 : move16();
3253 :
3254 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
3255 72000 : h_dirac_output_synthesis_state->direct_responses_square_q = Q31;
3256 72000 : move16();
3257 :
3258 72000 : exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
3259 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
3260 72000 : h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, exp );
3261 72000 : move16();
3262 72000 : exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
3263 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
3264 72000 : h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, exp );
3265 72000 : move16();
3266 72000 : exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
3267 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
3268 72000 : h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp );
3269 72000 : move16();
3270 : }
3271 :
3272 1183665 : test();
3273 1183665 : test();
3274 1183665 : IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order > 0 )
3275 : {
3276 1600 : ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fx,
3277 : DirAC_mem.reference_power_q,
3278 : p_onset_filter_fx,
3279 : azimuth,
3280 : elevation,
3281 1600 : hSpatParamRendCom->diffuseness_vector_fx[md_idx],
3282 1600 : hSpatParamRendCom->q_diffuseness_vector,
3283 : hSpatParamRendCom,
3284 : hDirACRend,
3285 1600 : st_ivas->hCombinedOrientationData->shd_rot_max_order,
3286 : p_Rmat_fx,
3287 : st_ivas->hVBAPdata,
3288 : hDirACRend->hOutSetup,
3289 : nchan_transport,
3290 : md_idx,
3291 : hodirac_flag,
3292 1600 : hDirAC->hConfig->dec_param_estim );
3293 : }
3294 : ELSE
3295 : {
3296 1182065 : ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fx,
3297 : DirAC_mem.reference_power_q,
3298 : p_onset_filter_fx,
3299 : azimuth,
3300 : elevation,
3301 1182065 : hSpatParamRendCom->diffuseness_vector_fx[md_idx],
3302 1182065 : hSpatParamRendCom->q_diffuseness_vector,
3303 : hSpatParamRendCom,
3304 : hDirACRend,
3305 : 0,
3306 : 0,
3307 : st_ivas->hVBAPdata,
3308 : hDirACRend->hOutSetup,
3309 : nchan_transport,
3310 : md_idx,
3311 : hodirac_flag,
3312 1182065 : hDirAC->hConfig->dec_param_estim );
3313 : }
3314 :
3315 1183665 : IF( hDirAC->hConfig->dec_param_estim )
3316 : {
3317 : Word16 fac;
3318 694820 : Flag flag = 0;
3319 694820 : move32();
3320 694820 : fac = BASOP_Util_Divide3232_Scale( 1, hSpatParamRendCom->subframe_nbslots[subframe_idx], &exp );
3321 694820 : fac = shl_o( fac, exp, &flag );
3322 :
3323 694820 : IF( LT_16( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) )
3324 : {
3325 0 : scale_sig32( hSpatParamRendCom->diffuseness_vector_fx[md_idx], hSpatParamRendCom->num_freq_bands, sub( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ); // q_diffuseness_vector
3326 0 : hSpatParamRendCom->q_diffuseness_vector = q_diffuseness_vector;
3327 0 : move16();
3328 : }
3329 : ELSE
3330 : {
3331 694820 : scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( hSpatParamRendCom->q_diffuseness_vector, q_diffuseness_vector ) ); // q_diffuseness_vector
3332 694820 : q_diffuseness_vector = hSpatParamRendCom->q_diffuseness_vector;
3333 694820 : move16();
3334 : }
3335 694820 : v_multc_acc_32_16( hSpatParamRendCom->diffuseness_vector_fx[md_idx], fac, diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands );
3336 : }
3337 :
3338 1183665 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3339 : {
3340 : #ifdef FIX_867_CLDFB_NRG_SCALE
3341 313629 : v_add_fixed_me( reference_power_fx, sub( 31, DirAC_mem.reference_power_q[0] ),
3342 313629 : reference_power_smooth_fx, sub( 31, q_reference_power_smooth[0] ),
3343 : reference_power_smooth_fx, &temp_q,
3344 313629 : s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), 1 );
3345 313629 : q_reference_power_smooth[0] = sub( 31, temp_q );
3346 313629 : v_add_fixed_me( reference_power_fx + CLDFB_NO_CHANNELS_HALF, sub( 31, DirAC_mem.reference_power_q[1] ),
3347 313629 : reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, sub( 31, q_reference_power_smooth[1] ),
3348 : reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, &temp_q,
3349 313629 : s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), 1 );
3350 313629 : q_reference_power_smooth[1] = sub( 31, temp_q );
3351 : #else
3352 : IF( LT_16( q_reference_power_smooth, DirAC_mem.reference_power_q ) )
3353 : {
3354 : Word32 temp;
3355 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
3356 : {
3357 : temp = L_shl( reference_power_fx[i], sub( q_reference_power_smooth, DirAC_mem.reference_power_q ) );
3358 : test();
3359 : IF( temp == 0 && ( reference_power_fx[i] != 0 ) )
3360 : {
3361 : reference_power_fx[i] = 1;
3362 : }
3363 : ELSE
3364 : {
3365 : reference_power_fx[i] = temp;
3366 : }
3367 : move32();
3368 : }
3369 : DirAC_mem.reference_power_q = q_reference_power_smooth;
3370 : move16();
3371 : }
3372 : ELSE
3373 : {
3374 : Word32 temp;
3375 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
3376 : {
3377 : temp = L_shl( reference_power_smooth_fx[i], sub( DirAC_mem.reference_power_q, q_reference_power_smooth ) );
3378 : test();
3379 : IF( temp == 0 && ( reference_power_smooth_fx[i] != 0 ) )
3380 : {
3381 : reference_power_smooth_fx[i] = 1;
3382 : }
3383 : ELSE
3384 : {
3385 : reference_power_smooth_fx[i] = temp;
3386 : }
3387 : move32();
3388 : }
3389 : q_reference_power_smooth = DirAC_mem.reference_power_q;
3390 : move16();
3391 : }
3392 : v_add_fixed( reference_power_fx, reference_power_smooth_fx, reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, 1 );
3393 : q_reference_power_smooth = sub( q_reference_power_smooth, 1 );
3394 : #endif
3395 : }
3396 : }
3397 :
3398 297983 : minimum_s( q_proto_direct_buffer, add( hSpatParamRendCom->subframe_nbslots[subframe_idx], 1 ), &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q );
3399 297983 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3400 : {
3401 218820 : minimum_s( q_proto_diffuse_buffer, add( hSpatParamRendCom->subframe_nbslots[subframe_idx], 1 ), &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q );
3402 : }
3403 1481648 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3404 : {
3405 1183665 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3406 : {
3407 870036 : offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
3408 870036 : buff_len = i_mult( 2, i_mult( hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands ) );
3409 870036 : 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
3410 870036 : offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) );
3411 870036 : buff_len = i_mult( 2, i_mult( nchan_transport, hSpatParamRendCom->num_freq_bands ) );
3412 870036 : 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
3413 : }
3414 313629 : ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
3415 : {
3416 29965 : offset = i_mult( slot_idx, i_mult( 4, hSpatParamRendCom->num_freq_bands ) );
3417 29965 : buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands );
3418 29965 : 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
3419 : }
3420 : ELSE
3421 : {
3422 283664 : SWITCH( nchan_transport )
3423 : {
3424 72000 : case 11:
3425 : case 8:
3426 : case 6:
3427 : case 4:
3428 72000 : offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
3429 72000 : buff_len = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
3430 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
3431 72000 : BREAK;
3432 101864 : case 2:
3433 101864 : IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
3434 : {
3435 69852 : offset = i_mult( i_mult( i_mult( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), 3 );
3436 69852 : buff_len = i_mult( 6, hSpatParamRendCom->num_freq_bands );
3437 : }
3438 : ELSE
3439 : {
3440 32012 : offset = i_mult( i_mult( i_mult( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), 2 );
3441 32012 : buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands );
3442 : }
3443 101864 : 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 101864 : BREAK;
3445 109800 : case 1:
3446 109800 : offset = i_mult( slot_idx, i_mult( 2, hSpatParamRendCom->num_freq_bands ) );
3447 109800 : buff_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
3448 109800 : 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
3449 109800 : BREAK;
3450 : }
3451 1183665 : }
3452 : }
3453 297983 : test();
3454 297983 : 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 )
3455 : {
3456 4134 : 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
3457 4134 : offset = i_mult( i_mult( sub( slot_idx, 1 ), 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
3458 4134 : buff_len = i_mult( 2, i_mult( hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands ) );
3459 4134 : 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 )
3460 : {
3461 2622 : 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
3462 : }
3463 : }
3464 297983 : ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
3465 :
3466 297983 : size = i_mult( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands );
3467 297983 : IF( hodirac_flag )
3468 : {
3469 53156 : size_ho = i_mult( size, DIRAC_HO_NUMSECTORS );
3470 : }
3471 : ELSE
3472 : {
3473 244827 : size_ho = size;
3474 244827 : move16();
3475 : }
3476 :
3477 297983 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3478 : {
3479 218820 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, Q26 ) )
3480 : {
3481 201855 : 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
3482 201855 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26;
3483 201855 : move16();
3484 : }
3485 218820 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, Q26 ) )
3486 : {
3487 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
3488 : }
3489 218820 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) )
3490 : {
3491 133981 : 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
3492 : }
3493 218820 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) )
3494 : {
3495 8648 : 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
3496 : }
3497 218820 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) )
3498 : {
3499 133712 : 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
3500 : }
3501 218820 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, Q26 ) )
3502 : {
3503 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
3504 : }
3505 218820 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, Q26 ) )
3506 : {
3507 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
3508 : }
3509 218820 : IF( NE_16( q_diffuseness_vector, Q30 ) )
3510 : {
3511 0 : scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q30, q_diffuseness_vector ) ); // Q30
3512 : }
3513 218820 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) )
3514 : {
3515 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
3516 : }
3517 218820 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) )
3518 : {
3519 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
3520 : }
3521 :
3522 218820 : ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer_fx,
3523 : Cldfb_ImagBuffer_fx,
3524 : hSpatParamRendCom,
3525 : hDirACRend,
3526 : nchan_transport,
3527 218820 : hSpatParamRendCom->subframe_nbslots[subframe_idx],
3528 : p_onset_filter_fx,
3529 : diffuseness_vector_fx,
3530 : hodirac_flag,
3531 218820 : hDirAC->hConfig->dec_param_estim,
3532 : &hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev,
3533 : &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev );
3534 :
3535 218820 : test();
3536 218820 : IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL )
3537 : {
3538 398000 : FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
3539 : {
3540 1795000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3541 : {
3542 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
3543 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
3544 : }
3545 : }
3546 : }
3547 : ELSE
3548 : {
3549 2848364 : FOR( ch = 0; ch < hDirACRend->num_outputs_dir; ch++ )
3550 : {
3551 13258816 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3552 : {
3553 10590272 : 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
3554 10590272 : 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
3555 : }
3556 : }
3557 : }
3558 : }
3559 : ELSE
3560 : {
3561 : /* Determine encoding quality based additional smoothing factor */
3562 79163 : Word32 qualityBasedSmFactor_fx = ONE_IN_Q31;
3563 79163 : move32();
3564 79163 : Word16 q_Cldfb = 0;
3565 79163 : move16();
3566 :
3567 79163 : IF( st_ivas->hMasa != NULL )
3568 : {
3569 61163 : qualityBasedSmFactor_fx = L_mult( st_ivas->hMasa->data.dir_decode_quality_fx, st_ivas->hMasa->data.dir_decode_quality_fx ); /* (Q15, Q15) -> Q31 */
3570 : }
3571 :
3572 79163 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) )
3573 : {
3574 61163 : 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
3575 : }
3576 79163 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) )
3577 : {
3578 61163 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // Q31
3579 : }
3580 79163 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) )
3581 : {
3582 20646 : 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
3583 : }
3584 79163 : IF( NE_16( q_diffuseness_vector, Q31 ) )
3585 : {
3586 79163 : Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, q_diffuseness_vector ) ); // Q31
3587 : }
3588 79163 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, Q31 ) )
3589 : {
3590 61163 : 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
3591 : }
3592 :
3593 : #ifdef FIX_867_CLDFB_NRG_SCALE
3594 79163 : exp = L_norm_arr( reference_power_smooth_fx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) );
3595 79163 : scale_sig32( reference_power_smooth_fx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), exp ); // q_reference_power_smooth[0] + exp
3596 79163 : q_reference_power_smooth[0] = add( q_reference_power_smooth[0], exp );
3597 79163 : IF( LT_16( q_reference_power_smooth[0], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] ) )
3598 : {
3599 2753 : 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]
3600 2753 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] = q_reference_power_smooth[0];
3601 2753 : move16();
3602 : }
3603 : ELSE
3604 : {
3605 : Word32 temp;
3606 2350940 : FOR( i = 0; i < s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ); i++ )
3607 : {
3608 2274530 : 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] ) );
3609 2274530 : reference_power_smooth_fx[i] = L_max( temp, L_min( reference_power_smooth_fx[i], 1 ) );
3610 2274530 : move32();
3611 : }
3612 76410 : q_reference_power_smooth[0] = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0];
3613 76410 : move16();
3614 : }
3615 :
3616 79163 : exp = L_norm_arr( reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
3617 79163 : 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
3618 79163 : q_reference_power_smooth[1] = add( q_reference_power_smooth[1], exp );
3619 79163 : IF( LT_16( q_reference_power_smooth[1], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] ) )
3620 : {
3621 2474 : 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
3622 2474 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] = q_reference_power_smooth[1];
3623 2474 : move16();
3624 : }
3625 : ELSE
3626 : {
3627 : Word32 temp;
3628 2144059 : FOR( i = CLDFB_NO_CHANNELS_HALF; i < hSpatParamRendCom->num_freq_bands; i++ )
3629 : {
3630 2067370 : 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] ) );
3631 2067370 : reference_power_smooth_fx[i] = L_max( temp, L_min( reference_power_smooth_fx[i], 1 ) );
3632 2067370 : move32();
3633 : }
3634 76689 : q_reference_power_smooth[1] = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1];
3635 76689 : move16();
3636 : }
3637 : #else
3638 : exp = L_norm_arr( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands );
3639 : scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, exp ); // q_reference_power_smooth + exp
3640 : q_reference_power_smooth = add( q_reference_power_smooth, exp );
3641 : IF( LT_16( q_reference_power_smooth, hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) )
3642 : {
3643 : 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
3644 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = q_reference_power_smooth;
3645 : move16();
3646 : }
3647 : ELSE
3648 : {
3649 : Word32 temp;
3650 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
3651 : {
3652 : temp = L_shl( reference_power_smooth_fx[i], sub( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, q_reference_power_smooth ) );
3653 : test();
3654 : IF( temp == 0 && ( reference_power_smooth_fx[i] != 0 ) )
3655 : {
3656 : reference_power_smooth_fx[i] = 1;
3657 : }
3658 : ELSE
3659 : {
3660 : reference_power_smooth_fx[i] = temp;
3661 : }
3662 : move32();
3663 : }
3664 :
3665 : q_reference_power_smooth = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q;
3666 : move16();
3667 : }
3668 : #endif
3669 :
3670 79163 : IF( hDirACRend->masa_stereo_type_detect != NULL )
3671 : {
3672 11406 : IF( LT_16( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) )
3673 : {
3674 11406 : 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
3675 11406 : move32();
3676 11406 : hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = hDirACRend->masa_stereo_type_detect->q_subtract_power_y;
3677 11406 : move16();
3678 : }
3679 : ELSE
3680 : {
3681 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
3682 0 : move32();
3683 0 : hDirACRend->masa_stereo_type_detect->q_subtract_power_y = hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth;
3684 0 : move16();
3685 : }
3686 : }
3687 :
3688 : #ifdef FIX_867_CLDFB_NRG_SCALE
3689 79163 : exp = 31;
3690 79163 : move16();
3691 369519 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3692 : {
3693 290356 : 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 ) ) );
3694 : }
3695 369519 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3696 : {
3697 290356 : 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)
3698 : }
3699 79163 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0], exp );
3700 79163 : move16();
3701 79163 : exp = 31;
3702 79163 : move16();
3703 369519 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3704 : {
3705 290356 : 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 ) ) ) );
3706 : }
3707 369519 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3708 : {
3709 290356 : 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)
3710 : }
3711 79163 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], exp );
3712 79163 : move16();
3713 :
3714 79163 : 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] ) )
3715 : {
3716 125729 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3717 : {
3718 98063 : 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
3719 : }
3720 27666 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0];
3721 27666 : move16();
3722 : }
3723 : ELSE
3724 : {
3725 243790 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3726 : {
3727 192293 : 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
3728 : }
3729 51497 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0];
3730 51497 : move16();
3731 : }
3732 79163 : 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] ) )
3733 : {
3734 157881 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3735 : {
3736 124695 : 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
3737 : }
3738 33186 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1];
3739 33186 : move16();
3740 : }
3741 : ELSE
3742 : {
3743 211638 : FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
3744 : {
3745 165661 : 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
3746 : }
3747 45977 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1];
3748 45977 : move16();
3749 : }
3750 : #else
3751 : exp = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, proto_power_smooth_len );
3752 : 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)
3753 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, exp );
3754 : move16();
3755 : IF( LT_16( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) )
3756 : {
3757 : 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
3758 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q;
3759 : move16();
3760 : }
3761 : ELSE
3762 : {
3763 : 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
3764 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q;
3765 : move16();
3766 : }
3767 : #endif
3768 :
3769 79163 : 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 ) );
3770 79163 : 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)
3771 79163 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, exp );
3772 79163 : move16();
3773 79163 : IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 )
3774 : {
3775 52949 : 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 ) )
3776 : {
3777 23365 : 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
3778 23365 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q;
3779 23365 : move16();
3780 : }
3781 : ELSE
3782 : {
3783 29584 : 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
3784 29584 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q;
3785 29584 : move16();
3786 : }
3787 : }
3788 :
3789 79163 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) )
3790 : {
3791 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
3792 : }
3793 79163 : IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) )
3794 : {
3795 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
3796 : }
3797 79163 : IF( hDirACRend->proto_signal_decorr_on )
3798 : {
3799 52949 : 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
3800 52949 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
3801 52949 : move16();
3802 : }
3803 :
3804 79163 : ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Cldfb_RealBuffer_fx,
3805 : Cldfb_ImagBuffer_fx,
3806 : hSpatParamRendCom,
3807 : hDirACRend,
3808 79163 : hSpatParamRendCom->subframe_nbslots[subframe_idx],
3809 : diffuseness_vector_fx,
3810 : reference_power_smooth_fx,
3811 : #ifdef FIX_867_CLDFB_NRG_SCALE
3812 : q_reference_power_smooth,
3813 : #else
3814 : &q_reference_power_smooth,
3815 : #endif
3816 : qualityBasedSmFactor_fx,
3817 79163 : hDirAC->hConfig->enc_param_start_band,
3818 : &q_Cldfb );
3819 :
3820 : #ifdef FIX_867_CLDFB_NRG_SCALE
3821 79163 : Word16 allZero = 1;
3822 79163 : move16();
3823 17051003 : FOR( i = 0; i < proto_power_smooth_len; i++ )
3824 : {
3825 16971840 : if ( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx[i] != 0 )
3826 : {
3827 0 : allZero = 0;
3828 0 : move16();
3829 : }
3830 : }
3831 79163 : if ( allZero )
3832 : {
3833 79163 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = 31;
3834 79163 : move16();
3835 : }
3836 79163 : if ( allZero )
3837 : {
3838 79163 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = 31;
3839 79163 : move16();
3840 : }
3841 : #else
3842 : Word16 sh = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q;
3843 : move16();
3844 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = 31;
3845 : move16();
3846 : FOR( i = 0; i < proto_power_smooth_len; i++ )
3847 : {
3848 : IF( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx[i] != 0 )
3849 : {
3850 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = sh;
3851 : move16();
3852 : }
3853 : }
3854 : #endif
3855 :
3856 636000 : FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
3857 : {
3858 2780370 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
3859 : {
3860 2223533 : scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6
3861 2223533 : scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6
3862 : }
3863 : }
3864 : }
3865 :
3866 : /*-----------------------------------------------------------------*
3867 : * CLDFB synthesis (and binaural rendering)
3868 : *-----------------------------------------------------------------*/
3869 :
3870 297983 : index_slot = slot_idx_start_cldfb_synth;
3871 297983 : move16();
3872 :
3873 297983 : test();
3874 297983 : test();
3875 297983 : IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
3876 106225 : {
3877 : /* render objects in combined format onto the CICP19 channels for BINAURAL_ROOM_IR */
3878 106225 : test();
3879 106225 : test();
3880 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 ) ) )
3881 : {
3882 : Word16 in_ch;
3883 40000 : FOR( in_ch = 0; in_ch < st_ivas->nchan_ism; in_ch++ )
3884 : {
3885 : Word16 j, k, j2, l;
3886 : Word16 num_objects, nchan_out_woLFE, lfe_index;
3887 : #ifndef FIX_1379_MASA_ANGLE_ROUND
3888 : Word16 az1, el1;
3889 : #endif
3890 : Word16 n_slots_to_render;
3891 : Word16 n_samples_to_render;
3892 : Word16 interp_offset;
3893 :
3894 : Word32 gain_fx, prev_gain_fx;
3895 :
3896 32000 : num_objects = st_ivas->nchan_ism;
3897 32000 : move16();
3898 32000 : nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
3899 32000 : move16();
3900 32000 : n_slots_to_render = st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->subframes_rendered];
3901 32000 : move16();
3902 32000 : n_samples_to_render = imult1616( hSpatParamRendCom->num_freq_bands, n_slots_to_render );
3903 32000 : interp_offset = st_ivas->hTcBuffer->n_samples_rendered;
3904 32000 : move16();
3905 :
3906 32000 : test();
3907 32000 : IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[0] )
3908 : {
3909 0 : ivas_jbm_dec_get_adapted_linear_interpolator_fx( n_samples_to_render, n_samples_to_render, st_ivas->hIsmRendererData->interpolator_fx );
3910 0 : interp_offset = 0;
3911 0 : move16();
3912 : }
3913 160000 : FOR( i = 0; i < num_objects; i++ )
3914 : {
3915 : /* Combined rotation: rotate the object positions depending the head and external orientations */
3916 128000 : test();
3917 128000 : IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) )
3918 : {
3919 0 : Word16 az_q0 = extract_l( L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, Q22 ) );
3920 0 : Word16 el_q0 = extract_l( L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, Q22 ) );
3921 : Word32 az1_32, el1_32;
3922 0 : rotateAziEle_fixed( az_q0, el_q0, &az1_32, &el1_32, st_ivas->hCombinedOrientationData->Rmat_fx[0], st_ivas->hIntSetup.is_planar_setup );
3923 : #ifndef FIX_1379_MASA_ANGLE_ROUND
3924 : az1 = extract_h( az1_32 );
3925 : el1 = extract_h( el1_32 );
3926 : #endif
3927 :
3928 0 : IF( st_ivas->hEFAPdata != NULL )
3929 : {
3930 : #ifdef FIX_1379_MASA_ANGLE_ROUND
3931 0 : const Word32 azi_fx = L_shl( az1_32, Q22 - Q16 ); // Q16 -> Q22
3932 0 : const Word32 ele_fx = L_shl( el1_32, Q22 - Q16 ); // Q16 -> Q22
3933 : #else
3934 : const Word32 azi_fx = L_shl( az1, Q22 ); // Q0 -> Q22
3935 : const Word32 ele_fx = L_shl( el1, Q22 ); // Q0 -> Q22
3936 : #endif
3937 0 : efap_determine_gains_fx( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], azi_fx, ele_fx, EFAP_MODE_EFAP );
3938 : }
3939 : }
3940 :
3941 128000 : lfe_index = 0;
3942 128000 : move16();
3943 1536000 : for ( j = 0, j2 = 0; j < nchan_out_woLFE; j++, j2++ )
3944 : {
3945 1408000 : test();
3946 1408000 : IF( ( st_ivas->hIntSetup.num_lfe > 0 && ( EQ_16( st_ivas->hIntSetup.index_lfe[lfe_index], j ) ) ) )
3947 : {
3948 128000 : IF( LT_16( lfe_index, sub( st_ivas->hIntSetup.num_lfe, 1 ) ) )
3949 : {
3950 0 : lfe_index = add( lfe_index, 1 );
3951 0 : j2 = add( j2, 1 );
3952 : }
3953 : ELSE
3954 : {
3955 128000 : j2 = add( j2, 1 );
3956 : }
3957 : }
3958 1408000 : gain_fx = st_ivas->hIsmRendererData->gains_fx[i][j];
3959 1408000 : move32();
3960 1408000 : prev_gain_fx = st_ivas->hIsmRendererData->prev_gains_fx[i][j];
3961 1408000 : move32();
3962 1408000 : test();
3963 1408000 : IF( ( L_abs( gain_fx ) > 0 || L_abs( prev_gain_fx ) > 0 ) )
3964 : {
3965 : Word32 *tc_re_fx, *tc_im_fx;
3966 : Word16 *w1_fx, w2_fx;
3967 0 : w1_fx = &st_ivas->hIsmRendererData->interpolator_fx[interp_offset];
3968 0 : tc_re_fx = pppQMfFrame_ts_re_fx[nchan_transport + i][0];
3969 0 : move32();
3970 0 : tc_im_fx = pppQMfFrame_ts_im_fx[nchan_transport + i][0];
3971 0 : move32();
3972 0 : FOR( k = 0; k < n_slots_to_render; k++ )
3973 : {
3974 : Word32 g_fx;
3975 0 : w2_fx = sub( MAX16B, *w1_fx );
3976 0 : g_fx = L_add( Mpy_32_16_1( gain_fx, *w1_fx ), Mpy_32_16_1( prev_gain_fx, w2_fx ) ); // Q15
3977 0 : FOR( l = 0; l < hSpatParamRendCom->num_freq_bands; l++ )
3978 : {
3979 : Word32 tmp;
3980 0 : tmp = Mpy_32_32( g_fx, *tc_re_fx );
3981 0 : Cldfb_RealBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l] = L_add( Cldfb_RealBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l], tmp );
3982 0 : move32();
3983 0 : tc_re_fx++;
3984 0 : tmp = Mpy_32_32( g_fx, *tc_im_fx );
3985 0 : Cldfb_ImagBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l] = L_add( Cldfb_ImagBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l], tmp );
3986 0 : move32();
3987 0 : tc_re_fx++;
3988 : }
3989 0 : w1_fx += hSpatParamRendCom->num_freq_bands;
3990 : }
3991 : }
3992 : /* update here only in case of head rotation */
3993 1408000 : test();
3994 1408000 : IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) )
3995 : {
3996 0 : st_ivas->hIsmRendererData->prev_gains_fx[i][j] = gain_fx;
3997 0 : move32();
3998 : }
3999 : }
4000 : }
4001 : }
4002 : }
4003 :
4004 : /* Perform binaural rendering */
4005 : Word16 input_q;
4006 106225 : input_q = Q6;
4007 106225 : move16();
4008 :
4009 106225 : ivas_binRenderer_fx( st_ivas->hBinRenderer,
4010 : st_ivas->hCombinedOrientationData,
4011 106225 : hSpatParamRendCom->subframe_nbslots[subframe_idx],
4012 : Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx,
4013 : Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, &input_q );
4014 :
4015 106225 : Scale_sig32( Cldfb_RealBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); // Q6
4016 106225 : Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); // Q6
4017 :
4018 : /* Inverse CLDFB*/
4019 318675 : FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
4020 : {
4021 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
4022 212450 : Word32 *synth_fx = &output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands];
4023 : Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
4024 : Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
4025 1059210 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
4026 : {
4027 846760 : RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[ch][i];
4028 846760 : move32();
4029 846760 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[ch][i];
4030 846760 : move32();
4031 : }
4032 :
4033 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
4034 212450 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = ( Q6 - 1 );
4035 212450 : move16();
4036 :
4037 : #ifdef OPT_AVOID_STATE_BUF_RESCALE
4038 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] );
4039 : #else /* OPT_AVOID_STATE_BUF_RESCALE */
4040 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, synth_fx, i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), 0, st_ivas->cldfbSynDec[ch] );
4041 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
4042 :
4043 212450 : Word16 no_col = st_ivas->cldfbSynDec[ch]->no_col;
4044 212450 : move16();
4045 212450 : Word16 no_channels = st_ivas->cldfbSynDec[ch]->no_channels;
4046 212450 : move16();
4047 212450 : Word16 samplesToProcess = i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4048 212450 : move16();
4049 212450 : IF( GT_16( samplesToProcess, -1 ) )
4050 : {
4051 : Word16 tmp, tmp_e;
4052 212450 : tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[ch]->no_channels, 1 ) ), st_ivas->cldfbSynDec[ch]->no_channels, &tmp_e );
4053 212450 : tmp = shr( tmp, 15 - tmp_e );
4054 212450 : no_col = s_min( no_col, tmp );
4055 : }
4056 212450 : Word16 synth_len = imult1616( no_col, no_channels );
4057 :
4058 212450 : scale_sig32( synth_fx, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11
4059 : }
4060 : }
4061 191758 : ELSE IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
4062 : {
4063 1646099 : FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
4064 : {
4065 7561176 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4066 : {
4067 6037024 : Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], pppQMfFrame_ts_re_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands ); // Q6
4068 6037024 : Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], pppQMfFrame_ts_im_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands ); // Q6
4069 : }
4070 : }
4071 : }
4072 : ELSE
4073 : {
4074 : Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
4075 : Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
4076 : Word16 outchannels;
4077 :
4078 69811 : idx_in = 0;
4079 69811 : move16();
4080 69811 : idx_lfe = 0;
4081 69811 : move16();
4082 :
4083 69811 : outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
4084 :
4085 69811 : test();
4086 69811 : test();
4087 69811 : test();
4088 69811 : test();
4089 69811 : test();
4090 69811 : test();
4091 69811 : test();
4092 69811 : IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
4093 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
4094 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
4095 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
4096 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
4097 : ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
4098 : {
4099 700 : outchannels = add( outchannels, 1 );
4100 : }
4101 :
4102 69811 : test();
4103 69811 : IF( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
4104 0 : {
4105 : Word32 tmp_separated_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
4106 : Word32 tmp_lfe_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
4107 0 : const Word16 subframe_start_sample = imult1616( index_slot, hSpatParamRendCom->num_freq_bands );
4108 0 : const Word16 num_samples_subframe = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4109 :
4110 : /* Move the separated and the LFE channels to temporary variables as spatial synthesis may overwrite current channels */
4111 0 : Copy32( &( output_buf_fx[st_ivas->hOutSetup.separateChannelIndex][subframe_start_sample] ), tmp_separated_fx, num_samples_subframe );
4112 0 : Copy32( &( output_buf_fx[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe_fx, num_samples_subframe );
4113 0 : FOR( ch = 0; ch < outchannels; ch++ )
4114 : {
4115 :
4116 0 : test();
4117 0 : test();
4118 0 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
4119 : {
4120 : /* Move the LFE channel to the correct place */
4121 0 : Copy32( tmp_lfe_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe );
4122 :
4123 0 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
4124 : {
4125 0 : idx_lfe = add( idx_lfe, 1 );
4126 : }
4127 : }
4128 0 : ELSE IF( ( st_ivas->hLsSetupCustom->separate_ch_found ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
4129 : {
4130 : /* Move the separated channel to the correct place. Thus, the separated channel is
4131 : * combined with the synthesized channels here when there is a matching channel. */
4132 0 : Copy32( tmp_separated_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe );
4133 : }
4134 : ELSE
4135 : {
4136 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
4137 0 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
4138 : {
4139 0 : RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i];
4140 0 : move32();
4141 0 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i];
4142 0 : move32();
4143 : }
4144 : #ifdef OPT_AVOID_STATE_BUF_RESCALE
4145 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] );
4146 : #else /* OPT_AVOID_STATE_BUF_RESCALE */
4147 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe, 0, st_ivas->cldfbSynDec[idx_in] );
4148 : #endif /* OPT_AVOID_STATE_BUF_RESCALE*/
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 531657 : FOR( ch = 0; ch < outchannels; ch++ )
4164 : {
4165 :
4166 461846 : test();
4167 461846 : test();
4168 461846 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
4169 : {
4170 40517 : test();
4171 40517 : test();
4172 40517 : 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 : #ifdef OPT_AVOID_STATE_BUF_RESCALE
4189 5860 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, 0, 0, st_ivas->cldfbSynDec[cldfbSynIdx] );
4190 : #else /* OPT_AVOID_STATE_BUF_RESCALE */
4191 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, 0, st_ivas->cldfbSynDec[cldfbSynIdx] );
4192 : #endif /* OPT_AVOID_STATE_BUF_RESCALE*/
4193 :
4194 : // Calculating length of output
4195 5860 : Word16 no_col = st_ivas->cldfbSynDec[cldfbSynIdx]->no_col;
4196 5860 : move16();
4197 5860 : Word16 no_channels = st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels;
4198 5860 : move16();
4199 5860 : IF( GT_16( samplesToProcess, -1 ) )
4200 : {
4201 : Word16 tmp, tmp_e;
4202 5860 : tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, 1 ) ), st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, &tmp_e );
4203 5860 : tmp = shr( tmp, 15 - tmp_e );
4204 5860 : no_col = s_min( no_col, tmp );
4205 : }
4206 5860 : Word16 synth_len = imult1616( no_col, no_channels );
4207 :
4208 5860 : scale_sig32( p_out, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11
4209 : }
4210 34657 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && hDirACRend->hOutSetup.separateChannelEnabled )
4211 : {
4212 : /* LFE has been synthesized in the time domain, do nothing. */
4213 : }
4214 : ELSE
4215 : {
4216 33957 : set32_fx( &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) );
4217 : }
4218 40517 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
4219 : {
4220 0 : idx_lfe = add( idx_lfe, 1 );
4221 : }
4222 : }
4223 421329 : ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
4224 : {
4225 : /* The separated channel is already set to output_f[hOutSetup.separateChannelIndex]. Thus, the separated
4226 : * channel is combined with the synthesized channels here. */
4227 : }
4228 : ELSE
4229 : {
4230 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
4231 420629 : Word32 *p_out = &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] );
4232 : Word16 samplesToProcess, out_len;
4233 2099330 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
4234 : {
4235 1678701 : RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i]; // Q6
4236 1678701 : move32();
4237 1678701 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i]; // Q6
4238 1678701 : move32();
4239 : }
4240 420629 : samplesToProcess = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4241 :
4242 : // Calculating length of processed output
4243 420629 : Word16 no_col = st_ivas->cldfbSynDec[idx_in]->no_col;
4244 420629 : move16();
4245 420629 : Word16 no_channels = st_ivas->cldfbSynDec[idx_in]->no_channels;
4246 420629 : move16();
4247 420629 : IF( GT_16( samplesToProcess, -1 ) )
4248 : {
4249 : Word16 tmp, tmp_e;
4250 420629 : 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 );
4251 420629 : tmp = shr( tmp, 15 - tmp_e );
4252 420629 : no_col = s_min( no_col, tmp );
4253 : }
4254 420629 : out_len = imult1616( no_col, no_channels );
4255 :
4256 : // Scaling cldfb_state to Q6-1
4257 420629 : 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 ) );
4258 420629 : st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = ( Q6 - 1 );
4259 420629 : move16();
4260 : #ifdef OPT_AVOID_STATE_BUF_RESCALE
4261 420629 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, 0, 0, st_ivas->cldfbSynDec[idx_in] );
4262 : #else /* OPT_AVOID_STATE_BUF_RESCALE */
4263 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, 0, st_ivas->cldfbSynDec[idx_in] );
4264 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
4265 :
4266 : // Scaling output from Q6-1 to Q11
4267 420629 : Scale_sig32( p_out, out_len, ( Q11 - ( Q6 - 1 ) ) );
4268 :
4269 420629 : idx_in = add( idx_in, 1 );
4270 : }
4271 : }
4272 : }
4273 : }
4274 :
4275 297983 : hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4276 297983 : move16();
4277 297983 : hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 );
4278 297983 : move16();
4279 :
4280 :
4281 297983 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4282 : {
4283 218820 : hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev;
4284 218820 : move16();
4285 218820 : hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev;
4286 218820 : move16();
4287 : }
4288 :
4289 297983 : test();
4290 297983 : test();
4291 297983 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
4292 : {
4293 318675 : FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ )
4294 : {
4295 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
4296 212450 : st_ivas->cldfbSynDec[i]->Q_cldfb_state = Q11;
4297 212450 : move16();
4298 : }
4299 : }
4300 191758 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
4301 : {
4302 : }
4303 : ELSE
4304 : {
4305 : Word16 outchannels;
4306 69811 : idx_lfe = 0;
4307 69811 : move16();
4308 69811 : idx_in = 0;
4309 69811 : move16();
4310 69811 : outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
4311 :
4312 69811 : test();
4313 69811 : test();
4314 69811 : test();
4315 69811 : test();
4316 69811 : test();
4317 69811 : test();
4318 69811 : test();
4319 69811 : IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
4320 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
4321 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
4322 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
4323 : EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
4324 : ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
4325 : {
4326 700 : outchannels = add( outchannels, 1 );
4327 : }
4328 :
4329 69811 : test();
4330 69811 : IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) )
4331 : {
4332 0 : FOR( ch = 0; ch < outchannels; ch++ )
4333 : {
4334 0 : test();
4335 0 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
4336 : {
4337 0 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
4338 : {
4339 0 : idx_lfe = add( idx_lfe, 1 );
4340 : }
4341 : }
4342 : }
4343 : }
4344 : ELSE
4345 : {
4346 531657 : FOR( ch = 0; ch < outchannels; ch++ )
4347 : {
4348 :
4349 461846 : test();
4350 461846 : test();
4351 461846 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
4352 : {
4353 40517 : test();
4354 40517 : IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
4355 : {
4356 5860 : Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
4357 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
4358 5860 : st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11;
4359 5860 : move16();
4360 : }
4361 : }
4362 421329 : ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled == 0 ) || NE_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
4363 : {
4364 420629 : 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
4365 420629 : st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11;
4366 420629 : move16();
4367 420629 : idx_in = add( idx_in, 1 );
4368 : }
4369 : }
4370 : }
4371 69811 : test();
4372 69811 : IF( !hDirACRend->hOutSetup.separateChannelEnabled || NE_32( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
4373 : {
4374 69811 : Word16 tmp_lfe_idx = 0;
4375 69811 : move16();
4376 531657 : FOR( ch = 0; ch < outchannels; ch++ )
4377 : {
4378 461846 : test();
4379 461846 : IF( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( EQ_16( hDirACRend->hOutSetup.index_lfe[tmp_lfe_idx], ch ) ) )
4380 : {
4381 40517 : IF( LT_16( tmp_lfe_idx, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
4382 : {
4383 0 : tmp_lfe_idx = add( tmp_lfe_idx, 1 );
4384 : }
4385 : }
4386 : }
4387 : }
4388 : }
4389 :
4390 297983 : pop_wmops();
4391 :
4392 297983 : return;
4393 : }
|