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 <math.h>
35 : #include <stdint.h>
36 : #include "options.h"
37 : #include "ivas_cnst.h"
38 : #include "ivas_prot_rend_fx.h"
39 : #include "rom_com.h"
40 : #include "ivas_rom_com.h"
41 : #include "ivas_stat_enc.h"
42 : #include "prot_fx.h"
43 : #include "wmc_auto.h"
44 : #include "ivas_prot_fx.h"
45 :
46 :
47 : /*-------------------------------------------------------------------*
48 : * Local function prototypes
49 : *-------------------------------------------------------------------*/
50 :
51 : static ivas_error ivas_read_format( Decoder_Struct *st_ivas, Word16 *num_bits_read );
52 :
53 : static ivas_error doSanityChecks_IVAS( Decoder_Struct *st_ivas );
54 :
55 :
56 : /*-------------------------------------------------------------------*
57 : * ivas_dec_setup()
58 : *
59 : * IVAS decoder setup
60 : *-------------------------------------------------------------------*/
61 :
62 388320 : ivas_error ivas_dec_setup(
63 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
64 : UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */
65 : Word16 *data /* o : output synthesis signal */
66 : )
67 : {
68 : Word16 k, idx, num_bits_read;
69 : Word16 nchan_ism, element_mode_flag;
70 : Decoder_State *st;
71 : Word32 ivas_total_brate;
72 : ivas_error error;
73 :
74 388320 : error = IVAS_ERR_OK;
75 388320 : move32();
76 388320 : num_bits_read = 0;
77 388320 : move16();
78 388320 : element_mode_flag = 0;
79 388320 : move16();
80 :
81 388320 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
82 388320 : move32();
83 :
84 : /*-------------------------------------------------------------------*
85 : * Read IVAS format
86 : *-------------------------------------------------------------------*/
87 :
88 388320 : ivas_read_format( st_ivas, &num_bits_read );
89 :
90 : Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
91 388320 : Word16 num_src = 0;
92 388320 : move16();
93 :
94 : /*-------------------------------------------------------------------*
95 : * Read other signling (ISM/MC mode, number of channels, etc.)
96 : *-------------------------------------------------------------------*/
97 :
98 388320 : IF( is_DTXrate( ivas_total_brate ) == 0 )
99 : {
100 : /*-------------------------------------------------------------------*
101 : * Read IVAS format related signaling:
102 : * - in ISM : read number of objects
103 : * - in SBA : read SBA planar flag and SBA order
104 : * - in MASA : read number of TC
105 : * - in MC : read LS setup
106 : *-------------------------------------------------------------------*/
107 :
108 369569 : IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
109 : {
110 57666 : element_mode_flag = 1;
111 57666 : move16();
112 : }
113 311903 : ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
114 : {
115 : /* read the number of objects */
116 90951 : st_ivas->nchan_transport = 1;
117 90951 : move16();
118 90951 : nchan_ism = 1;
119 90951 : move16();
120 : Word32 res_dec, res_frac;
121 90951 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
122 90951 : k = extract_l( L_sub( res_dec, 1 ) );
123 :
124 258757 : WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) )
125 : {
126 167806 : nchan_ism = add( nchan_ism, 1 );
127 167806 : k = sub( k, 1 );
128 : }
129 :
130 90951 : st_ivas->nchan_ism = nchan_ism;
131 90951 : move16();
132 :
133 90951 : IF( NE_32( ( error = ivas_ism_dec_config_fx( st_ivas, st_ivas->ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
134 : {
135 0 : return error;
136 : }
137 : }
138 220952 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
139 : {
140 : /* read Ambisonic (SBA) planar flag */
141 110666 : st_ivas->sba_planar = st_ivas->bit_stream[num_bits_read];
142 110666 : move16();
143 110666 : num_bits_read = add( num_bits_read, SBA_PLANAR_BITS );
144 :
145 : /* read Ambisonic (SBA) order */
146 110666 : st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1];
147 110666 : move16();
148 110666 : st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) );
149 110666 : move16();
150 110666 : num_bits_read = add( num_bits_read, SBA_ORDER_BITS );
151 110666 : test();
152 110666 : test();
153 110666 : IF( st_ivas->ini_frame > 0 && NE_32( ivas_total_brate, st_ivas->last_active_ivas_total_brate ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
154 : {
155 1020 : IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
156 : {
157 0 : return error;
158 : }
159 : }
160 : ELSE
161 : {
162 : /* set Ambisonic (SBA) order used for analysis and coding */
163 109646 : st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order );
164 109646 : move16();
165 109646 : ivas_sba_config_fx( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init );
166 : }
167 : }
168 110286 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
169 : {
170 : /* read number of MASA transport channels */
171 : Word32 res_dec, res_frac;
172 30306 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
173 30306 : IF( st_ivas->bit_stream[res_dec - 1] )
174 : {
175 17636 : st_ivas->nchan_transport = 2;
176 17636 : move16();
177 17636 : element_mode_flag = 1;
178 17636 : move16();
179 : }
180 : ELSE
181 : {
182 12670 : st_ivas->nchan_transport = 1;
183 12670 : move16();
184 : }
185 :
186 30306 : IF( st_ivas->ini_frame > 0 )
187 : {
188 : /* reconfigure in case a change of operation mode is detected */
189 30226 : test();
190 30226 : test();
191 30226 : IF( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) || ( st_ivas->ini_active_frame == 0 ) )
192 : {
193 1712 : IF( EQ_32( st_ivas->last_ivas_format, MASA_FORMAT ) )
194 : {
195 1318 : test();
196 1318 : test();
197 1318 : test();
198 1318 : IF( ( st_ivas->ini_active_frame == 0 ) && NE_32( ivas_total_brate, FRAME_NO_DATA ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) )
199 : {
200 0 : st_ivas->hCPE[0]->nchan_out = 1;
201 0 : move16();
202 : }
203 : ELSE
204 : {
205 1318 : IF( NE_32( ( error = ivas_masa_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
206 : {
207 0 : return error;
208 : }
209 : }
210 : }
211 : ELSE
212 : {
213 394 : IF( NE_32( ( error = ivas_omasa_dec_config_fx( st_ivas, nSamplesRendered, &num_src, SrcInd, data ) ), IVAS_ERR_OK ) )
214 : {
215 0 : return error;
216 : }
217 : }
218 : }
219 : }
220 : }
221 79980 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
222 : {
223 6312 : st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */
224 6312 : move16();
225 : /* for the DISC mode the number of objects are written at the end of the bitstream, in the MASA metadata */
226 :
227 : Word32 res_dec, res_frac;
228 6312 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
229 6312 : st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[res_dec - 1], 1 ), st_ivas->bit_stream[res_dec - 2] ), 1 );
230 6312 : move16();
231 6312 : st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, st_ivas->nchan_ism );
232 6312 : move16();
233 6312 : IF( st_ivas->ini_frame > 0 )
234 : {
235 : /* reconfigure in case a change of operation mode is detected */
236 6279 : test();
237 6279 : test();
238 6279 : IF( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) || ( st_ivas->ini_active_frame == 0 ) )
239 : {
240 1066 : IF( NE_32( ( error = ivas_omasa_dec_config_fx( st_ivas, nSamplesRendered, &num_src, SrcInd, data ) ), IVAS_ERR_OK ) )
241 : {
242 0 : return error;
243 : }
244 : }
245 : }
246 : }
247 73668 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
248 : {
249 : /* the number of objects is written at the end of the bitstream, in the SBA metadata */
250 : Word32 res_dec, res_frac;
251 29914 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
252 29914 : st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[res_dec - 1], 1 ), st_ivas->bit_stream[res_dec - 2] ), 1 );
253 29914 : move16();
254 :
255 29914 : test();
256 29914 : IF( LT_32( ivas_total_brate, IVAS_24k4 ) || GE_32( ivas_total_brate, IVAS_256k ) )
257 : {
258 : /* read Ambisonic (SBA) planar flag */
259 15507 : st_ivas->sba_planar = st_ivas->bit_stream[num_bits_read];
260 15507 : move16();
261 15507 : num_bits_read = add( num_bits_read, SBA_PLANAR_BITS );
262 : }
263 :
264 29914 : st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1];
265 29914 : move16();
266 29914 : st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) );
267 29914 : move16();
268 29914 : num_bits_read = add( num_bits_read, SBA_ORDER_BITS );
269 :
270 : /* read Ambisonic (SBA) order */
271 29914 : if ( LT_32( ivas_total_brate, IVAS_256k ) )
272 : {
273 16822 : st_ivas->sba_order = 3;
274 16822 : move16();
275 : }
276 :
277 29914 : test();
278 29914 : IF( st_ivas->ini_frame > 0 && NE_32( ivas_total_brate, st_ivas->last_active_ivas_total_brate ) )
279 : {
280 471 : IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
281 : {
282 0 : return error;
283 : }
284 : }
285 : ELSE
286 : {
287 : /* set Ambisonic (SBA) order used for analysis and coding */
288 29443 : st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order );
289 29443 : move16();
290 :
291 29443 : ivas_sba_config_fx( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init );
292 :
293 : /*correct number of CPEs for discrete ISM coding*/
294 29443 : test();
295 29443 : IF( st_ivas->ini_frame > 0 && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
296 : {
297 12996 : st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) );
298 12996 : move16();
299 : }
300 : }
301 :
302 29914 : IF( GE_32( ivas_total_brate, IVAS_256k ) )
303 : {
304 13092 : st_ivas->ism_mode = ISM_SBA_MODE_DISC;
305 13092 : move32();
306 : }
307 : ELSE
308 : {
309 16822 : st_ivas->ism_mode = ISM_MODE_NONE;
310 16822 : move32();
311 : }
312 : }
313 43754 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
314 : {
315 : /* read MC configuration */
316 43754 : idx = 0;
317 43754 : move16();
318 175016 : FOR( k = 0; k < MC_LS_SETUP_BITS; k++ )
319 : {
320 131262 : IF( st_ivas->bit_stream[num_bits_read + k] )
321 : {
322 5678 : idx = add( idx, shl( 1, sub( ( MC_LS_SETUP_BITS - 1 ), k ) ) );
323 : }
324 : }
325 43754 : num_bits_read = add( num_bits_read, MC_LS_SETUP_BITS );
326 :
327 : /* select MC format mode; reconfigure the MC format decoder */
328 43754 : IF( NE_32( ( error = ivas_mc_dec_config_fx( st_ivas, idx, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
329 : {
330 0 : return error;
331 : }
332 : }
333 :
334 : /*-------------------------------------------------------------------*
335 : * Read element mode
336 : *-------------------------------------------------------------------*/
337 :
338 369569 : IF( st_ivas->ini_frame == 0 && element_mode_flag )
339 : {
340 : /* read stereo technology info */
341 119 : IF( LT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) )
342 : {
343 : /* 1 bit */
344 79 : IF( st_ivas->bit_stream[num_bits_read] )
345 : {
346 0 : st_ivas->element_mode_init = add( 1, IVAS_CPE_DFT );
347 0 : move16();
348 : }
349 : ELSE
350 : {
351 79 : st_ivas->element_mode_init = add( 0, IVAS_CPE_DFT );
352 79 : move16();
353 : }
354 : }
355 : ELSE
356 : {
357 40 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
358 40 : move16();
359 : }
360 : }
361 : }
362 18751 : ELSE IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
363 : {
364 2907 : SWITCH( st_ivas->sid_format )
365 : {
366 1418 : case SID_DFT_STEREO:
367 1418 : st_ivas->element_mode_init = IVAS_CPE_DFT;
368 1418 : move16();
369 1418 : BREAK;
370 410 : case SID_MDCT_STEREO:
371 410 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
372 410 : move16();
373 410 : BREAK;
374 550 : case SID_ISM:
375 550 : st_ivas->element_mode_init = IVAS_SCE;
376 550 : move16();
377 550 : BREAK;
378 131 : case SID_MASA_1TC:
379 131 : st_ivas->element_mode_init = IVAS_SCE;
380 131 : move16();
381 131 : st_ivas->nchan_transport = 1;
382 131 : move16();
383 131 : BREAK;
384 74 : case SID_MASA_2TC:; // empyt statement for declaration
385 : Word32 res_dec, res_frac;
386 74 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
387 74 : IF( EQ_16( st_ivas->bit_stream[( res_dec - 1 ) - SID_FORMAT_NBITS], 1 ) )
388 : {
389 0 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
390 0 : move16();
391 : }
392 : ELSE
393 : {
394 74 : st_ivas->element_mode_init = IVAS_CPE_DFT;
395 74 : move16();
396 : }
397 74 : st_ivas->nchan_transport = 2;
398 74 : move16();
399 74 : BREAK;
400 157 : case SID_SBA_1TC:
401 157 : st_ivas->element_mode_init = IVAS_SCE;
402 157 : move16();
403 157 : BREAK;
404 167 : case SID_SBA_2TC:
405 167 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
406 167 : move16();
407 167 : BREAK;
408 : }
409 :
410 2907 : test();
411 2907 : IF( st_ivas->ini_frame > 0 && EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
412 : {
413 : Word16 nchan_transport_old, nchan_transport;
414 324 : nchan_transport_old = st_ivas->nchan_transport;
415 324 : move16();
416 324 : IF( ( EQ_16( st_ivas->sid_format, SID_SBA_2TC ) ) )
417 : {
418 167 : nchan_transport = 2;
419 : }
420 : ELSE
421 : {
422 157 : nchan_transport = 1;
423 : }
424 324 : move16();
425 :
426 324 : IF( NE_16( nchan_transport_old, nchan_transport ) )
427 : {
428 : /*Setting the default bitrate for the reconfig function*/
429 0 : IF( EQ_16( st_ivas->sid_format, SID_SBA_2TC ) )
430 : {
431 0 : st_ivas->hDecoderConfig->ivas_total_brate = IVAS_48k;
432 0 : move16();
433 : }
434 : ELSE
435 : {
436 0 : st_ivas->hDecoderConfig->ivas_total_brate = IVAS_24k4;
437 0 : move16();
438 : }
439 :
440 0 : IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
441 : {
442 0 : return error;
443 : }
444 :
445 0 : st_ivas->last_active_ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
446 0 : move32();
447 0 : st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate;
448 0 : move32();
449 : }
450 : }
451 :
452 2907 : IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
453 : {
454 550 : ISM_MODE last_ism_mode = st_ivas->ism_mode;
455 550 : move32();
456 : /* read the number of objects */
457 550 : st_ivas->nchan_transport = 1;
458 550 : move16();
459 550 : nchan_ism = 1;
460 550 : move16();
461 : Word32 res_dec, res_frac;
462 550 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
463 550 : k = extract_l( L_sub( L_sub( res_dec, 1 ), SID_FORMAT_NBITS ) );
464 550 : move16();
465 :
466 1816 : WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) )
467 : {
468 1266 : nchan_ism = add( nchan_ism, 1 );
469 1266 : k = sub( k, 1 );
470 : }
471 550 : k = sub( k, 1 );
472 :
473 550 : test();
474 550 : IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) )
475 : {
476 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong number of objects signalled!" );
477 : }
478 :
479 550 : st_ivas->nchan_ism = nchan_ism;
480 550 : move16();
481 : /* read ism_mode */
482 550 : st_ivas->ism_mode = ISM_MODE_DISC;
483 550 : move32();
484 550 : IF( GT_16( nchan_ism, 2 ) )
485 : {
486 385 : k = sub( k, nchan_ism ); /* SID metadata flags */
487 385 : idx = st_ivas->bit_stream[k];
488 385 : move16();
489 385 : st_ivas->ism_mode = (ISM_MODE) add( idx, 1 );
490 385 : move32();
491 : }
492 :
493 550 : if ( st_ivas->ini_frame == 0 )
494 : {
495 0 : last_ism_mode = st_ivas->ism_mode;
496 0 : move32();
497 : }
498 :
499 550 : IF( NE_32( ( error = ivas_ism_dec_config_fx( st_ivas, last_ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
500 : {
501 0 : return error;
502 : }
503 : }
504 : }
505 :
506 : /*-------------------------------------------------------------------*
507 : * Initialize decoder in the first good frame based on IVAS format
508 : * and number of transport channels
509 : *-------------------------------------------------------------------*/
510 388320 : test();
511 388320 : IF( st_ivas->ini_frame == 0 && NE_32( st_ivas->ivas_format, UNDEFINED_FORMAT ) )
512 : {
513 597 : IF( NE_32( ( error = doSanityChecks_IVAS( st_ivas ) ), IVAS_ERR_OK ) )
514 : {
515 6 : return IVAS_ERROR( error, "Sanity checks failed" );
516 : }
517 :
518 591 : IF( NE_32( ( error = ivas_init_decoder_fx( st_ivas ) ), IVAS_ERR_OK ) )
519 : {
520 0 : return error;
521 : }
522 : }
523 :
524 :
525 : /*----------------------------------------------------------------*
526 : * Reset bitstream pointers
527 : *----------------------------------------------------------------*/
528 :
529 388314 : ivas_set_bitstream_pointers( st_ivas );
530 :
531 388314 : reset_elements( st_ivas );
532 :
533 : /* update bitstream buffer pointer -> take into account already read bits */
534 388314 : test();
535 388314 : IF( ( st_ivas->nSCE > 0 ) || ( st_ivas->nCPE > 0 ) )
536 : {
537 388314 : IF( st_ivas->nSCE > 0 )
538 : {
539 161266 : st = st_ivas->hSCE[0]->hCoreCoder[0];
540 : }
541 : ELSE
542 : {
543 227048 : st = st_ivas->hCPE[0]->hCoreCoder[0];
544 : }
545 388314 : st->next_bit_pos = num_bits_read;
546 388314 : move16();
547 388314 : st->total_brate = ACELP_8k00; /* only temporary initialization - this is needed for get_next_indice() in the frame following NO_DATA frame */
548 388314 : move32();
549 : }
550 :
551 388314 : return error;
552 : }
553 :
554 :
555 : /*-------------------------------------------------------------------*
556 : * ivas_read_format()
557 : *
558 : * Read IVAS format signaling
559 : *-------------------------------------------------------------------*/
560 :
561 388320 : static ivas_error ivas_read_format(
562 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
563 : Word16 *num_bits_read /* o : number of IVAS signaling bits read from the bitstream */
564 : )
565 : {
566 : Word16 k, idx;
567 : Word32 ivas_total_brate;
568 : ivas_error error;
569 :
570 388320 : error = IVAS_ERR_OK;
571 388320 : move32();
572 :
573 388320 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
574 388320 : move32();
575 :
576 388320 : *num_bits_read = 0;
577 388320 : move16();
578 388320 : test();
579 388320 : test();
580 388320 : IF( !st_ivas->bfi && is_DTXrate( ivas_total_brate ) == 0 )
581 : {
582 : /* read IVAS format */
583 369569 : k = 0;
584 369569 : move16();
585 369569 : if ( st_ivas->bit_stream[*num_bits_read] )
586 : {
587 268149 : k = 1;
588 268149 : move16();
589 : }
590 369569 : k = shl( k, 1 );
591 369569 : ( *num_bits_read ) = add( ( *num_bits_read ), 1 );
592 369569 : move16();
593 369569 : if ( st_ivas->bit_stream[*num_bits_read] )
594 : {
595 187141 : k = add( k, 1 );
596 : }
597 369569 : ( *num_bits_read ) = add( ( *num_bits_read ), 1 );
598 369569 : move16();
599 369569 : SWITCH( k )
600 : {
601 57666 : case 0:
602 57666 : st_ivas->ivas_format = STEREO_FORMAT;
603 57666 : move32();
604 57666 : BREAK;
605 43754 : case 1:
606 43754 : st_ivas->ivas_format = MC_FORMAT;
607 43754 : move32();
608 43754 : BREAK;
609 124762 : case 2:
610 124762 : st_ivas->ivas_format = ISM_FORMAT;
611 124762 : move32();
612 :
613 124762 : IF( GE_32( ivas_total_brate, IVAS_24k4 ) )
614 : {
615 116421 : IF( st_ivas->bit_stream[*num_bits_read] )
616 : {
617 33811 : ( *num_bits_read ) = add( ( *num_bits_read ), 1 );
618 33811 : move16();
619 33811 : IF( st_ivas->bit_stream[*num_bits_read] )
620 : {
621 27499 : st_ivas->ivas_format = SBA_ISM_FORMAT;
622 27499 : move32();
623 : }
624 : ELSE
625 : {
626 6312 : st_ivas->ivas_format = MASA_ISM_FORMAT;
627 6312 : move32();
628 : }
629 : }
630 :
631 116421 : ( *num_bits_read ) = add( ( *num_bits_read ), 1 );
632 116421 : move16();
633 : }
634 124762 : BREAK;
635 143387 : case 3:
636 143387 : IF( st_ivas->bit_stream[*num_bits_read] )
637 : {
638 30306 : st_ivas->ivas_format = MASA_FORMAT;
639 30306 : move32();
640 : }
641 : ELSE
642 : {
643 113081 : st_ivas->ivas_format = SBA_FORMAT;
644 113081 : move32();
645 : /* read Ambisonic (SBA) planar flag */
646 113081 : st_ivas->sba_planar = st_ivas->bit_stream[( *num_bits_read ) + 1];
647 113081 : move16();
648 :
649 : /* read Ambisonic (SBA) order */
650 113081 : st_ivas->sba_order = st_ivas->bit_stream[( *num_bits_read ) + 2 + SBA_PLANAR_BITS];
651 113081 : move16();
652 113081 : st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[( *num_bits_read ) + 1 + SBA_PLANAR_BITS], 1 ) );
653 113081 : move16();
654 113081 : if ( st_ivas->sba_order == 0 )
655 : {
656 2415 : st_ivas->ivas_format = SBA_ISM_FORMAT;
657 2415 : move32();
658 : }
659 : }
660 143387 : ( *num_bits_read ) = add( ( *num_bits_read ), 1 );
661 143387 : move16();
662 :
663 143387 : BREAK;
664 : }
665 369569 : }
666 18751 : ELSE IF( ( st_ivas->bfi == 0 ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
667 : {
668 : /* read IVAS format in SID frame */
669 2907 : idx = 0;
670 2907 : move16();
671 11628 : FOR( k = 0; k < SID_FORMAT_NBITS; k++ )
672 : {
673 8721 : idx += st_ivas->bit_stream[k] << ( SID_FORMAT_NBITS - 1 - k );
674 : }
675 :
676 2907 : ( *num_bits_read ) = add( *num_bits_read, SID_FORMAT_NBITS );
677 2907 : move16();
678 2907 : st_ivas->sid_format = idx;
679 2907 : move16();
680 :
681 2907 : SWITCH( idx )
682 : {
683 1828 : case SID_DFT_STEREO:
684 : case SID_MDCT_STEREO:
685 1828 : st_ivas->ivas_format = STEREO_FORMAT;
686 1828 : move32();
687 1828 : BREAK;
688 550 : case SID_ISM:
689 550 : st_ivas->ivas_format = ISM_FORMAT;
690 550 : move32();
691 550 : BREAK;
692 0 : case SID_MULTICHANNEL:
693 0 : st_ivas->ivas_format = MC_FORMAT;
694 0 : move32();
695 0 : BREAK;
696 157 : case SID_SBA_1TC:
697 157 : st_ivas->ivas_format = SBA_FORMAT;
698 157 : move32();
699 157 : st_ivas->element_mode_init = IVAS_SCE;
700 157 : move16();
701 157 : BREAK;
702 167 : case SID_SBA_2TC:
703 167 : st_ivas->ivas_format = SBA_FORMAT;
704 167 : move32();
705 167 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
706 167 : move16();
707 167 : BREAK;
708 131 : case SID_MASA_1TC:
709 131 : st_ivas->ivas_format = MASA_FORMAT;
710 131 : move32();
711 131 : st_ivas->element_mode_init = IVAS_SCE;
712 131 : move16();
713 131 : BREAK;
714 74 : case SID_MASA_2TC:
715 74 : st_ivas->ivas_format = MASA_FORMAT;
716 74 : move32();
717 : Word32 res_dec, res_frac;
718 74 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
719 74 : IF( EQ_32( st_ivas->bit_stream[res_dec - 1], 1 ) )
720 : {
721 0 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
722 0 : move16();
723 : }
724 : ELSE
725 : {
726 74 : st_ivas->element_mode_init = IVAS_CPE_DFT;
727 74 : move16();
728 : }
729 74 : BREAK;
730 0 : default:
731 : /* This should actually be impossible, since only 3 bits are read, so if this happens something is broken */
732 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Invalid value %c found in SID format field.", st_ivas->sid_format );
733 : }
734 :
735 2907 : IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
736 : {
737 324 : if ( st_ivas->sba_analysis_order == 0 )
738 : {
739 0 : st_ivas->sba_analysis_order = SBA_FOA_ORDER;
740 0 : move16();
741 : }
742 : }
743 :
744 : /* reset bitstream handle to avoid BER detection after reading the 2400 kbps for ch0 */
745 2907 : st_ivas->bit_stream = st_ivas->bit_stream + ( *num_bits_read );
746 2907 : ( *num_bits_read ) = 0;
747 2907 : move16();
748 : }
749 : ELSE
750 : {
751 : /* In SID/NO_DATA frames, use the previous frame IVAS format */
752 : }
753 :
754 388320 : return error;
755 : }
756 :
757 :
758 : /*-------------------------------------------------------------------*
759 : * getNumChanSynthesis()
760 : *
761 : * get number of output channels used for synthesis/decoding
762 : * (often different from number of output channels!)
763 : *-------------------------------------------------------------------*/
764 :
765 : /*! r: number of channels to be synthesised */
766 :
767 220018 : Word16 getNumChanSynthesis(
768 : Decoder_Struct *st_ivas /* i : IVAS decoder structure */
769 : )
770 : {
771 : Word16 n;
772 :
773 220018 : n = add( st_ivas->nSCE, imult1616( CPE_CHANNELS, st_ivas->nCPE ) );
774 220018 : test();
775 220018 : test();
776 220018 : IF( st_ivas->sba_dirac_stereo_flag )
777 : {
778 13026 : n = CPE_CHANNELS;
779 13026 : move16();
780 : }
781 206992 : ELSE IF( ( st_ivas->hMCT != NULL || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) && NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
782 : {
783 3679 : n = st_ivas->nchan_transport;
784 3679 : move16();
785 : }
786 203313 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
787 : {
788 143336 : IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
789 : {
790 98837 : n = add( st_ivas->nchan_transport, st_ivas->nchan_ism );
791 : }
792 : ELSE
793 : {
794 44499 : n = st_ivas->nchan_transport;
795 44499 : move16();
796 : }
797 : }
798 :
799 220018 : return n;
800 : }
801 :
802 : /*-------------------------------------------------------------------*
803 : * copy_decoder_config()
804 : *
805 : * Copy IVAS configuration structure to the CoreCoder state structure
806 : *-------------------------------------------------------------------*/
807 :
808 7236 : void copy_decoder_config(
809 : Decoder_Struct *st_ivas, /* i : IVAS decoder structure */
810 : Decoder_State *st /* o : decoder state structure */
811 : )
812 : {
813 7236 : st->output_Fs = st_ivas->hDecoderConfig->output_Fs;
814 7236 : move32();
815 7236 : st->Opt_AMR_WB = st_ivas->hDecoderConfig->Opt_AMR_WB;
816 7236 : move16();
817 7236 : st->codec_mode = st_ivas->codec_mode;
818 7236 : move16();
819 7236 : st->ini_frame = st_ivas->ini_frame;
820 7236 : move16();
821 :
822 7236 : st->bfi = st_ivas->bfi;
823 7236 : move16();
824 :
825 7236 : st->writeFECoffset = st_ivas->writeFECoffset;
826 7236 : move16();
827 :
828 7236 : st->element_mode = st_ivas->element_mode_init;
829 7236 : move16();
830 :
831 7236 : return;
832 : }
833 :
834 : /*-------------------------------------------------------------------*
835 : * ivas_init_decoder_front()
836 : *
837 : * Set decoder parameters to initial values
838 : *-------------------------------------------------------------------*/
839 604 : ivas_error ivas_init_decoder_front(
840 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
841 : )
842 : {
843 : ivas_error error;
844 :
845 604 : error = IVAS_ERR_OK;
846 604 : move32();
847 : /*-----------------------------------------------------------------*
848 : * Resets
849 : *-----------------------------------------------------------------*/
850 :
851 604 : st_ivas->nSCE = 0;
852 604 : move16();
853 604 : st_ivas->nCPE = 0;
854 604 : move16();
855 604 : st_ivas->nCPE_old = 0;
856 604 : move16();
857 604 : st_ivas->nchan_transport = -1;
858 604 : move16();
859 604 : st_ivas->ism_mode = ISM_MODE_NONE;
860 604 : move32();
861 604 : st_ivas->mc_mode = MC_MODE_NONE;
862 604 : move32();
863 604 : st_ivas->sba_dirac_stereo_flag = 0;
864 604 : move16();
865 :
866 : /* HRTF binauralization latency in ns */
867 604 : st_ivas->binaural_latency_ns = 0;
868 604 : move32();
869 :
870 : /*-------------------------------------------------------------------*
871 : * Allocate and initialize Custom loudspeaker layout handle
872 : *--------------------------------------------------------------------*/
873 :
874 604 : IF( st_ivas->hDecoderConfig->Opt_LsCustom )
875 : {
876 3 : IF( EQ_32( ( error = ivas_ls_custom_open_fx( &( st_ivas->hLsSetupCustom ) ) ), IVAS_ERR_OK ) )
877 : {
878 3 : set_zero_fx( ( st_ivas->hLsSetupCustom )->ls_azimuth_fx, MAX_OUTPUT_CHANNELS );
879 3 : set_zero_fx( ( st_ivas->hLsSetupCustom )->ls_elevation_fx, MAX_OUTPUT_CHANNELS );
880 : }
881 : ELSE
882 : {
883 0 : return error;
884 : }
885 : }
886 :
887 : /*-------------------------------------------------------------------*
888 : * Allocate and initialize Head-Tracking handle
889 : *--------------------------------------------------------------------*/
890 :
891 604 : IF( st_ivas->hDecoderConfig->Opt_Headrotation )
892 : {
893 81 : IF( NE_32( ( error = ivas_headTrack_open_fx( &( st_ivas->hHeadTrackData ) ) ), IVAS_ERR_OK ) )
894 : {
895 0 : return error;
896 : }
897 81 : error = ivas_orient_trk_SetTrackingType_fx( st_ivas->hHeadTrackData->OrientationTracker, st_ivas->hDecoderConfig->orientation_tracking );
898 81 : IF( NE_32( ( error ), IVAS_ERR_OK ) )
899 : {
900 0 : return error;
901 : }
902 : }
903 : /*-------------------------------------------------------------------*
904 : * Allocate and initialize external orientation handle
905 : *--------------------------------------------------------------------*/
906 :
907 604 : IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation )
908 : {
909 31 : IF( NE_32( ( error = ivas_external_orientation_open( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_framesize ) ), IVAS_ERR_OK ) )
910 : {
911 0 : return error;
912 : }
913 : }
914 :
915 : /*-------------------------------------------------------------------*
916 : * Allocate and initialize combined orientation handle
917 : *--------------------------------------------------------------------*/
918 604 : test();
919 604 : IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation )
920 : {
921 81 : IF( NE_32( ( error = ivas_combined_orientation_open( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_framesize ) ), IVAS_ERR_OK ) )
922 : {
923 0 : return error;
924 : }
925 : }
926 :
927 : /*-------------------------------------------------------------------*
928 : * Allocate HRTF binary handle
929 : *--------------------------------------------------------------------*/
930 :
931 604 : IF( st_ivas->hDecoderConfig->Opt_HRTF_binary )
932 : {
933 23 : IF( NE_32( ( error = ivas_HRTF_binary_open_fx( &( st_ivas->hHrtfTD ) ) ), IVAS_ERR_OK ) )
934 : {
935 0 : return error;
936 : }
937 :
938 23 : IF( NE_32( ( error = ivas_HRTF_CRend_binary_open_fx( &( st_ivas->hSetOfHRTF ) ) ), IVAS_ERR_OK ) )
939 : {
940 0 : return error;
941 : }
942 :
943 23 : IF( NE_32( ( error = ivas_HRTF_fastconv_binary_open_fx( &st_ivas->hHrtfFastConv ) ), IVAS_ERR_OK ) )
944 : {
945 0 : return error;
946 : }
947 :
948 23 : IF( NE_32( ( error = ivas_HRTF_parambin_binary_open_fx( &st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) )
949 : {
950 0 : return error;
951 : }
952 : }
953 :
954 : /*-------------------------------------------------------------------*
955 : * Allocate and initialize Binaural Renderer configuration handle
956 : *--------------------------------------------------------------------*/
957 604 : test();
958 604 : test();
959 604 : IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
960 : {
961 193 : IF( NE_32( ( error = ivas_render_config_open( &( st_ivas->hRenderConfig ) ) ), IVAS_ERR_OK ) )
962 : {
963 0 : return error;
964 : }
965 :
966 193 : IF( NE_32( ( error = ivas_render_config_init_from_rom_fx( &st_ivas->hRenderConfig ) ), IVAS_ERR_OK ) )
967 : {
968 0 : return error;
969 : }
970 : }
971 :
972 604 : return error;
973 : }
974 :
975 :
976 : /*-------------------------------------------------------------------*
977 : * ivas_init_decoder()
978 : *
979 : * Initialize IVAS decoder state structure
980 : *-------------------------------------------------------------------*/
981 594 : ivas_error ivas_init_decoder_fx(
982 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
983 : )
984 : {
985 : Word16 i, n, k;
986 : Word16 sce_id, cpe_id;
987 : Word16 numCldfbAnalyses, numCldfbSyntheses;
988 : Word16 granularity, n_channels_transport_jbm;
989 : Word32 output_Fs, ivas_total_brate;
990 : Word32 binauralization_delay_ns;
991 : AUDIO_CONFIG output_config;
992 : DECODER_CONFIG_HANDLE hDecoderConfig;
993 : ivas_error error;
994 : Word32 ism_total_brate;
995 :
996 594 : error = IVAS_ERR_OK;
997 594 : move32();
998 594 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
999 594 : move32();
1000 594 : hDecoderConfig = st_ivas->hDecoderConfig;
1001 594 : output_config = hDecoderConfig->output_config;
1002 594 : ivas_total_brate = hDecoderConfig->ivas_total_brate;
1003 594 : move32();
1004 594 : hDecoderConfig->last_ivas_total_brate = ivas_total_brate;
1005 594 : move32();
1006 594 : st_ivas->last_active_ivas_total_brate = ivas_total_brate;
1007 594 : move32();
1008 : /*-----------------------------------------------------------------*
1009 : * Set number of output channels for EXTERNAL output config.
1010 : *-----------------------------------------------------------------*/
1011 :
1012 594 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
1013 : {
1014 44 : IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
1015 : {
1016 3 : hDecoderConfig->nchan_out = audioCfg2channels( IVAS_AUDIO_CONFIG_HOA3 );
1017 3 : move16();
1018 3 : hDecoderConfig->nchan_out = add( hDecoderConfig->nchan_out, st_ivas->nchan_ism );
1019 3 : move16();
1020 : }
1021 41 : ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
1022 : {
1023 3 : hDecoderConfig->nchan_out = add( st_ivas->nchan_transport, st_ivas->nchan_ism );
1024 3 : move16();
1025 : }
1026 38 : ELSE IF( !EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
1027 : {
1028 36 : hDecoderConfig->nchan_out = st_ivas->nchan_transport;
1029 36 : move16();
1030 : }
1031 :
1032 44 : st_ivas->hOutSetup.nchan_out_woLFE = hDecoderConfig->nchan_out;
1033 44 : move16();
1034 : }
1035 :
1036 : /*-----------------------------------------------------------------*
1037 : * Set output and intern setup & renderer selection
1038 : *-----------------------------------------------------------------*/
1039 :
1040 594 : st_ivas->intern_config = output_config;
1041 594 : move32();
1042 594 : ivas_output_init( &( st_ivas->hOutSetup ), output_config );
1043 594 : test();
1044 594 : IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
1045 : {
1046 3 : st_ivas->hOutSetup.ambisonics_order = SBA_HOA3_ORDER;
1047 3 : move16();
1048 3 : st_ivas->intern_config = IVAS_AUDIO_CONFIG_7_1_4;
1049 3 : move32();
1050 3 : st_ivas->hOutSetup.output_config = st_ivas->intern_config;
1051 3 : move32();
1052 3 : st_ivas->hOutSetup.nchan_out_woLFE = audioCfg2channels( st_ivas->intern_config );
1053 3 : move16();
1054 : }
1055 594 : test();
1056 594 : IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
1057 : {
1058 3 : st_ivas->hOutSetup.ambisonics_order = SBA_HOA3_ORDER;
1059 3 : move32();
1060 3 : st_ivas->intern_config = IVAS_AUDIO_CONFIG_HOA3;
1061 3 : move32();
1062 3 : st_ivas->hOutSetup.output_config = IVAS_AUDIO_CONFIG_HOA3;
1063 3 : move32();
1064 3 : st_ivas->hOutSetup.nchan_out_woLFE = audioCfg2channels( IVAS_AUDIO_CONFIG_HOA3 );
1065 3 : move16();
1066 : }
1067 :
1068 : /* Only initialize transport setup if it is used */
1069 594 : IF( NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_INVALID ) )
1070 : {
1071 139 : ivas_output_init( &( st_ivas->hTransSetup ), st_ivas->transport_config );
1072 : }
1073 :
1074 594 : test();
1075 594 : IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
1076 : {
1077 23 : ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate );
1078 :
1079 23 : ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hOutSetup.separateChannelEnabled ), &( st_ivas->hOutSetup.separateChannelIndex ), ivas_total_brate );
1080 : }
1081 :
1082 594 : ivas_renderer_select( st_ivas );
1083 :
1084 594 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
1085 : {
1086 3 : IF( EQ_16( ( error = ivas_ls_custom_output_init_fx( st_ivas ) ), IVAS_ERR_OK ) )
1087 : {
1088 3 : st_ivas->hOutSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx;
1089 3 : move32();
1090 3 : st_ivas->hOutSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx;
1091 3 : move32();
1092 3 : st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx;
1093 3 : move32();
1094 3 : st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx;
1095 3 : move32();
1096 : }
1097 : ELSE
1098 : {
1099 0 : return error;
1100 : }
1101 : }
1102 :
1103 594 : ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config );
1104 :
1105 594 : test();
1106 594 : IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
1107 : {
1108 23 : ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate );
1109 :
1110 23 : test();
1111 23 : IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.separateChannelEnabled )
1112 : {
1113 0 : st_ivas->hLsSetupCustom->separate_ch_found = 0;
1114 0 : move16();
1115 0 : IF( GE_16( st_ivas->hOutSetup.nchan_out_woLFE, MCMASA_MIN_SPEAKERS_SEPARATE_CENTER ) )
1116 : {
1117 : /* check for a speaker at (0, 0) if minimum speaker count is available */
1118 0 : FOR( i = 0; i < st_ivas->hOutSetup.nchan_out_woLFE; i++ )
1119 : {
1120 0 : test();
1121 0 : IF( ( L_shr( st_ivas->hOutSetup.ls_azimuth_fx[i], Q22 ) == 0 ) && ( L_shr( st_ivas->hOutSetup.ls_elevation_fx[i], Q22 ) == 0 ) )
1122 : {
1123 0 : st_ivas->hIntSetup.separateChannelIndex = i;
1124 0 : move16();
1125 0 : st_ivas->hLsSetupCustom->separate_ch_found = 1;
1126 0 : move16();
1127 0 : BREAK;
1128 : }
1129 : }
1130 : }
1131 : }
1132 : }
1133 :
1134 :
1135 : /*-----------------------------------------------------------------*
1136 : * Allocate and initialize SCE/CPE and other handles
1137 : *-----------------------------------------------------------------*/
1138 :
1139 594 : IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) )
1140 : {
1141 3 : st_ivas->nSCE = 1; /* in mono, there is always only one SCE */
1142 3 : move16();
1143 3 : st_ivas->nCPE = 0;
1144 3 : move16();
1145 3 : st_ivas->nCPE_old = 0;
1146 3 : move16();
1147 3 : st_ivas->nchan_transport = 1;
1148 3 : move16();
1149 3 : sce_id = 0;
1150 3 : move16();
1151 :
1152 3 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) )
1153 : {
1154 0 : return error;
1155 : }
1156 :
1157 3 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1158 : }
1159 591 : ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
1160 : {
1161 67 : st_ivas->nchan_transport = CPE_CHANNELS;
1162 67 : move16();
1163 67 : st_ivas->intern_config = IVAS_AUDIO_CONFIG_STEREO;
1164 67 : move32();
1165 :
1166 67 : st_ivas->nSCE = 0;
1167 67 : move16();
1168 67 : st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */
1169 67 : move16();
1170 67 : st_ivas->nCPE_old = 0;
1171 67 : move16();
1172 67 : cpe_id = 0;
1173 67 : move16();
1174 :
1175 67 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate ) ), IVAS_ERR_OK ) )
1176 : {
1177 0 : return error;
1178 : }
1179 :
1180 201 : FOR( n = 0; n < st_ivas->nchan_transport; n++ )
1181 : {
1182 134 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1183 : }
1184 :
1185 : /* init EFAP for custom LS output and set hTransSetup */
1186 67 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
1187 : {
1188 0 : IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hOutSetup.ls_azimuth_fx, st_ivas->hOutSetup.ls_elevation_fx, st_ivas->hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) )
1189 : {
1190 0 : return error;
1191 : }
1192 :
1193 0 : ivas_output_init( &( st_ivas->hTransSetup ), IVAS_AUDIO_CONFIG_STEREO );
1194 : }
1195 : }
1196 524 : ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
1197 : {
1198 : Word32 element_brate_tmp[MAX_NUM_OBJECTS];
1199 :
1200 67 : st_ivas->nSCE = st_ivas->nchan_transport; /* "st_ivas->nchan_transport" is known from ivas_dec_setup */
1201 67 : move16();
1202 67 : st_ivas->nCPE = 0;
1203 67 : move16();
1204 67 : st_ivas->nCPE_old = 0;
1205 67 : move16();
1206 67 : st_ivas->ism_extmeta_active = -1;
1207 67 : move16();
1208 67 : st_ivas->ism_extmeta_cnt = 0;
1209 67 : move16();
1210 67 : IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
1211 : {
1212 14 : st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE;
1213 14 : move16();
1214 14 : st_ivas->nSCE = MAX_PARAM_ISM_WAVE;
1215 14 : move16();
1216 :
1217 14 : IF( NE_32( ( error = ivas_param_ism_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
1218 : {
1219 0 : return error;
1220 : }
1221 : }
1222 :
1223 67 : IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nSCE, element_brate_tmp ) ), IVAS_ERR_OK ) )
1224 : {
1225 0 : return error;
1226 : }
1227 :
1228 233 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
1229 : {
1230 166 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, element_brate_tmp[sce_id] ) ), IVAS_ERR_OK ) )
1231 : {
1232 0 : return error;
1233 : }
1234 :
1235 166 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1236 :
1237 166 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->is_ism_format = 1;
1238 166 : move16();
1239 : }
1240 :
1241 67 : st_ivas->hISMDTX.sce_id_dtx = 0;
1242 67 : move16();
1243 :
1244 67 : IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
1245 : {
1246 14 : st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2 = st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed3;
1247 14 : move16();
1248 : }
1249 53 : ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) )
1250 : {
1251 191 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; ++sce_id )
1252 : {
1253 138 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2 = add( 2, sce_id );
1254 138 : move16();
1255 : }
1256 : }
1257 : }
1258 457 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
1259 : {
1260 243 : IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) )
1261 : {
1262 0 : return error;
1263 : }
1264 :
1265 243 : IF( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) )
1266 : {
1267 0 : return error;
1268 : }
1269 243 : set16_fx( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 0, CLDFB_NO_COL_MAX );
1270 243 : test();
1271 243 : IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) && st_ivas->hOutSetup.is_loudspeaker_setup )
1272 : {
1273 0 : IF( NE_32( ( error = ivas_sba_get_hoa_dec_matrix_fx( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ), IVAS_ERR_OK ) )
1274 : {
1275 0 : return error;
1276 : }
1277 : }
1278 :
1279 243 : Word16 hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order );
1280 243 : IF( hodirac_flag )
1281 : {
1282 8 : IF( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, IVAS_MAX_NUM_BANDS, st_ivas->ivas_format ) ), IVAS_ERR_OK ) )
1283 : {
1284 0 : return error;
1285 : }
1286 : }
1287 : ELSE
1288 : {
1289 235 : IF( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ), IVAS_ERR_OK ) )
1290 : {
1291 0 : return error;
1292 : }
1293 : }
1294 :
1295 :
1296 243 : test();
1297 243 : test();
1298 243 : IF( NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) )
1299 : {
1300 81 : IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) )
1301 : {
1302 0 : return error;
1303 : }
1304 :
1305 81 : st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band;
1306 81 : move16();
1307 : }
1308 : ELSE
1309 : {
1310 : Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1];
1311 :
1312 162 : st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND );
1313 162 : move16();
1314 162 : IF( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) )
1315 : {
1316 1 : st_ivas->hSpar->enc_param_start_band = 0;
1317 1 : move16();
1318 1 : set8_fx( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands );
1319 1 : st_ivas->hQMetaData->numTwoDirBands = (UWord8) st_ivas->hQMetaData->q_direction[0].cfg.nbands;
1320 1 : move16();
1321 : }
1322 :
1323 162 : ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, INV_CLDFB_BANDWIDTH_Q31 ) ),
1324 162 : st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 );
1325 : }
1326 243 : st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
1327 243 : move16();
1328 342 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
1329 : {
1330 : Word32 res_dec, res_frac;
1331 99 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
1332 99 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) )
1333 : {
1334 0 : return error;
1335 : }
1336 :
1337 99 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1338 : }
1339 :
1340 469 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1341 : {
1342 : Word32 res_dec, res_frac;
1343 226 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
1344 226 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, (res_dec) *CPE_CHANNELS ) ), IVAS_ERR_OK ) )
1345 : {
1346 0 : return error;
1347 : }
1348 :
1349 678 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1350 : {
1351 452 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1352 : }
1353 : }
1354 :
1355 : /* create CPE element for DFT Stereo like upmix */
1356 243 : test();
1357 243 : IF( st_ivas->sba_dirac_stereo_flag && ( st_ivas->nCPE == 0 ) )
1358 : {
1359 : Word32 res_dec, res_frac;
1360 5 : iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 );
1361 :
1362 5 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) )
1363 : {
1364 0 : return error;
1365 : }
1366 :
1367 5 : st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
1368 5 : st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
1369 : }
1370 :
1371 243 : IF( GT_16( st_ivas->nCPE, 1 ) )
1372 : {
1373 82 : IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) )
1374 : {
1375 0 : return error;
1376 : }
1377 : }
1378 :
1379 : /* set CNA/CNG flags */
1380 243 : ivas_sba_set_cna_cng_flag( st_ivas );
1381 : }
1382 214 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
1383 : {
1384 : /* if we start in ISM_MODE_NONE in MASA_ISM, that appears as normal MASA, but we may change to a mode with ISMs */
1385 80 : st_ivas->ism_extmeta_active = -1;
1386 80 : move16();
1387 80 : st_ivas->ism_extmeta_cnt = 0;
1388 80 : move16();
1389 80 : IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) )
1390 : {
1391 0 : return error;
1392 : }
1393 :
1394 80 : IF( NE_32( ( error = ivas_masa_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
1395 : {
1396 0 : return error;
1397 : }
1398 :
1399 80 : test();
1400 80 : test();
1401 80 : test();
1402 80 : IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
1403 : {
1404 59 : IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) )
1405 : {
1406 0 : return error;
1407 : }
1408 : }
1409 :
1410 109 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
1411 : {
1412 : Word32 res_dec, res_frac;
1413 29 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
1414 29 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) )
1415 : {
1416 0 : return error;
1417 : }
1418 :
1419 29 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1420 : }
1421 :
1422 131 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1423 : {
1424 : Word32 res_dec, res_frac;
1425 51 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
1426 51 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) )
1427 : {
1428 0 : return error;
1429 : }
1430 :
1431 153 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1432 : {
1433 102 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1434 : }
1435 : }
1436 :
1437 : /* set CNA/CNG flags */
1438 80 : ivas_sba_set_cna_cng_flag( st_ivas );
1439 : }
1440 134 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
1441 : {
1442 : Word32 temp_brate[MAX_SCE];
1443 30 : st_ivas->ism_extmeta_active = -1;
1444 30 : move16();
1445 30 : st_ivas->ism_extmeta_cnt = 0;
1446 30 : move16();
1447 :
1448 30 : st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
1449 30 : move16();
1450 30 : IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) )
1451 : {
1452 0 : return error;
1453 : }
1454 :
1455 30 : IF( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) )
1456 : {
1457 0 : return error;
1458 : }
1459 :
1460 30 : test();
1461 30 : IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) && st_ivas->hOutSetup.is_loudspeaker_setup )
1462 : {
1463 0 : IF( NE_32( ( error = ivas_sba_get_hoa_dec_matrix_fx( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ), IVAS_ERR_OK ) )
1464 : {
1465 0 : return error;
1466 : }
1467 : }
1468 :
1469 30 : Word16 hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order );
1470 30 : IF( hodirac_flag )
1471 : {
1472 6 : IF( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, IVAS_MAX_NUM_BANDS, st_ivas->ivas_format ) ), IVAS_ERR_OK ) )
1473 : {
1474 0 : return error;
1475 : }
1476 : }
1477 : ELSE
1478 : {
1479 24 : IF( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ), IVAS_ERR_OK ) )
1480 : {
1481 0 : return error;
1482 : }
1483 : }
1484 :
1485 :
1486 30 : test();
1487 30 : test();
1488 30 : IF( NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) )
1489 : {
1490 24 : IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) )
1491 : {
1492 0 : return error;
1493 : }
1494 :
1495 24 : st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band;
1496 24 : move16();
1497 : }
1498 : ELSE
1499 : {
1500 : Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1];
1501 :
1502 6 : st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND );
1503 6 : move16();
1504 6 : IF( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) )
1505 : {
1506 1 : st_ivas->hSpar->enc_param_start_band = 0;
1507 1 : move16();
1508 1 : set8_fx( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands );
1509 1 : st_ivas->hQMetaData->numTwoDirBands = (UWord8) st_ivas->hQMetaData->q_direction[0].cfg.nbands;
1510 1 : move16();
1511 : }
1512 :
1513 6 : ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, INV_CLDFB_BANDWIDTH_Q31 ) ),
1514 6 : st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 );
1515 : }
1516 :
1517 40 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
1518 : {
1519 : Word32 res_dec, res_frac;
1520 10 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
1521 10 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) )
1522 : {
1523 0 : return error;
1524 : }
1525 :
1526 10 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1527 : }
1528 :
1529 30 : IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
1530 : {
1531 12 : st_ivas->nCPE_old = st_ivas->nCPE;
1532 12 : move16();
1533 12 : st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) );
1534 12 : move16();
1535 12 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
1536 12 : move16();
1537 : }
1538 :
1539 87 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1540 : {
1541 : Word32 res_dec, res_frac;
1542 57 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
1543 57 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) )
1544 : {
1545 0 : return error;
1546 : }
1547 :
1548 171 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1549 : {
1550 114 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1551 : }
1552 : }
1553 :
1554 : /* create CPE element for DFT Stereo like upmix */
1555 30 : test();
1556 30 : IF( st_ivas->sba_dirac_stereo_flag && st_ivas->nCPE == 0 )
1557 : {
1558 : Word32 res_dec, res_frac;
1559 1 : iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 );
1560 1 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) )
1561 : {
1562 0 : return error;
1563 : }
1564 :
1565 1 : st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
1566 1 : st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
1567 : }
1568 :
1569 30 : IF( GT_16( st_ivas->nCPE, 1 ) )
1570 : {
1571 16 : IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) )
1572 : {
1573 0 : return error;
1574 : }
1575 : }
1576 :
1577 30 : IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
1578 : {
1579 12 : IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ), IVAS_ERR_OK ) )
1580 : {
1581 0 : return error;
1582 : }
1583 :
1584 12 : IF( NE_32( ( error = ivas_osba_data_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
1585 : {
1586 0 : return error;
1587 : }
1588 : }
1589 :
1590 : /* set CNA/CNG flags */
1591 30 : ivas_sba_set_cna_cng_flag( st_ivas );
1592 : }
1593 104 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
1594 : {
1595 32 : st_ivas->ism_extmeta_active = -1;
1596 32 : move16();
1597 32 : st_ivas->ism_extmeta_cnt = 0;
1598 32 : move16();
1599 :
1600 32 : IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) )
1601 : {
1602 0 : return error;
1603 : }
1604 :
1605 32 : k = 0;
1606 32 : move16();
1607 32 : ism_total_brate = 0;
1608 32 : move32();
1609 :
1610 285 : WHILE( ( k < SIZE_IVAS_BRATE_TBL ) && ( ivas_total_brate != ivas_brate_tbl[k] ) )
1611 : {
1612 253 : k = add( k, 1 );
1613 : }
1614 32 : test();
1615 32 : IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
1616 : {
1617 : /* one separated object */
1618 18 : st_ivas->nSCE = 1;
1619 18 : move16();
1620 18 : ism_total_brate = sep_object_brate[k - 2][0];
1621 18 : move32();
1622 18 : IF( NE_32( ( error = create_sce_dec( st_ivas, 0, ism_total_brate ) ), IVAS_ERR_OK ) )
1623 : {
1624 0 : return error;
1625 : }
1626 :
1627 18 : reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] );
1628 :
1629 18 : IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, 1, NULL ) ), IVAS_ERR_OK ) )
1630 : {
1631 0 : return error;
1632 : }
1633 : }
1634 14 : ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
1635 : {
1636 : Word32 temp_brate[MAX_SCE];
1637 14 : st_ivas->nSCE = st_ivas->nchan_ism; /* number of objects */
1638 14 : move16();
1639 53 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
1640 : {
1641 39 : temp_brate[sce_id] = sep_object_brate[k - 2][st_ivas->nSCE - 1];
1642 39 : move32();
1643 39 : ism_total_brate = L_add( ism_total_brate, temp_brate[sce_id] );
1644 :
1645 39 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, temp_brate[sce_id] ) ), IVAS_ERR_OK ) )
1646 : {
1647 0 : return error;
1648 : }
1649 :
1650 39 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1651 : }
1652 :
1653 14 : IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ), IVAS_ERR_OK ) )
1654 : {
1655 0 : return error;
1656 : }
1657 : }
1658 :
1659 32 : IF( NE_32( ( error = ivas_masa_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
1660 : {
1661 0 : return error;
1662 : }
1663 :
1664 32 : IF( NE_32( ( error = ivas_omasa_data_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
1665 : {
1666 0 : return error;
1667 : }
1668 :
1669 32 : test();
1670 32 : test();
1671 32 : test();
1672 32 : IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
1673 : {
1674 24 : IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) )
1675 : {
1676 0 : return error;
1677 : }
1678 : }
1679 :
1680 32 : IF( NE_32( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate - ism_total_brate ) ), IVAS_ERR_OK ) )
1681 : {
1682 0 : return error;
1683 : }
1684 :
1685 96 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1686 : {
1687 64 : reset_indices_dec( st_ivas->hCPE[0]->hCoreCoder[n] );
1688 : }
1689 : }
1690 72 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
1691 : {
1692 72 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) )
1693 : {
1694 : /* init EFAP for custom LS setup */
1695 35 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
1696 : {
1697 1 : IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) )
1698 : {
1699 0 : return error;
1700 : }
1701 : }
1702 :
1703 35 : st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ) );
1704 35 : move16();
1705 35 : st_ivas->nSCE = 0;
1706 35 : move16();
1707 35 : st_ivas->nCPE = shr( st_ivas->nchan_transport, 1 );
1708 35 : move16();
1709 35 : st_ivas->nCPE_old = 0;
1710 35 : move16();
1711 35 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
1712 35 : move16();
1713 177 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1714 : {
1715 : Word32 res_dec, res_frac;
1716 142 : iDiv_and_mod_32( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 );
1717 142 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) )
1718 : {
1719 0 : return error;
1720 : }
1721 :
1722 426 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1723 : {
1724 284 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1725 : }
1726 : }
1727 :
1728 35 : IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) )
1729 : {
1730 0 : return error;
1731 : }
1732 : }
1733 37 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
1734 : {
1735 : /* init EFAP for custom LS setup */
1736 5 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
1737 : {
1738 0 : IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) )
1739 : {
1740 0 : return error;
1741 : }
1742 : }
1743 :
1744 5 : st_ivas->nSCE = 0;
1745 5 : move16();
1746 5 : st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS >> 1;
1747 5 : move16();
1748 5 : st_ivas->nCPE_old = 0;
1749 5 : move16();
1750 5 : st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
1751 5 : move16();
1752 :
1753 5 : IF( NE_32( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ), IVAS_ERR_OK ) )
1754 : {
1755 0 : return error;
1756 : }
1757 :
1758 5 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
1759 5 : move16();
1760 25 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1761 : {
1762 : Word32 res_dec, res_frac;
1763 20 : iDiv_and_mod_32( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 );
1764 20 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) )
1765 : {
1766 0 : return error;
1767 : }
1768 :
1769 60 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1770 : {
1771 40 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1772 : }
1773 : }
1774 :
1775 5 : IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) )
1776 : {
1777 0 : return error;
1778 : }
1779 : }
1780 32 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
1781 : {
1782 : /* init EFAP for custom LS setup */
1783 9 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
1784 : {
1785 0 : IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) )
1786 : {
1787 0 : return error;
1788 : }
1789 : }
1790 9 : IF( NE_32( ( error = ivas_param_mc_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
1791 : {
1792 0 : return error;
1793 : }
1794 :
1795 9 : st_ivas->hParamMC->proto_matrix_int_e = 0;
1796 9 : move16();
1797 18 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1798 : {
1799 : Word32 res_dec, res_frac;
1800 9 : iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 );
1801 :
1802 9 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) )
1803 : {
1804 0 : return error;
1805 : }
1806 :
1807 27 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1808 : {
1809 18 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1810 : }
1811 : }
1812 :
1813 9 : IF( GT_16( st_ivas->nCPE, 1 ) )
1814 : {
1815 0 : IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) )
1816 : {
1817 0 : return error;
1818 : }
1819 : }
1820 : }
1821 23 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
1822 : {
1823 : Word32 brate_sce, brate_cpe;
1824 :
1825 23 : ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate );
1826 :
1827 23 : IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) )
1828 : {
1829 0 : return error;
1830 : }
1831 :
1832 23 : IF( NE_32( ( error = ivas_masa_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
1833 :
1834 : {
1835 0 : return error;
1836 : }
1837 :
1838 23 : st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
1839 23 : move16();
1840 23 : test();
1841 23 : IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && NE_32( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) )
1842 : {
1843 16 : IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) )
1844 : {
1845 0 : return error;
1846 : }
1847 : }
1848 23 : test();
1849 23 : test();
1850 23 : IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.separateChannelEnabled && !st_ivas->hLsSetupCustom->separate_ch_found )
1851 : {
1852 : /* If no speaker matching the separated channel, compute panning gains for the separated channel. */
1853 0 : IF( st_ivas->hVBAPdata == NULL )
1854 : {
1855 : /* Distribute signal to all channels if VBAP is not properly initialized. */
1856 0 : Word16 inv_sqr, sqr, exp = 15, exp_sqr;
1857 0 : move16();
1858 0 : IF( EQ_16( st_ivas->hLsSetupCustom->num_spk, 1 ) )
1859 : {
1860 0 : inv_sqr = 32767; // (1.0f in Q15)-1
1861 0 : move16();
1862 : }
1863 : ELSE
1864 : {
1865 0 : sqr = Sqrt16( st_ivas->hLsSetupCustom->num_spk, &exp );
1866 0 : inv_sqr = BASOP_Util_Divide1616_Scale( 32767, sqr, &exp_sqr );
1867 0 : exp_sqr = sub( exp_sqr, exp );
1868 0 : IF( ( exp < 0 ) )
1869 : {
1870 0 : inv_sqr = shr( inv_sqr, exp ); // exp_sqr
1871 : }
1872 : ELSE
1873 : {
1874 0 : inv_sqr = shl( inv_sqr, exp ); // exp_sqr
1875 : }
1876 : }
1877 0 : set16_fx( st_ivas->hLsSetupCustom->separate_ch_gains_fx, inv_sqr, st_ivas->hLsSetupCustom->num_spk );
1878 : }
1879 : }
1880 :
1881 :
1882 23 : ivas_mcmasa_split_brate_fx( st_ivas->hOutSetup.separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe );
1883 :
1884 44 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
1885 : {
1886 21 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, brate_sce ) ), IVAS_ERR_OK ) )
1887 : {
1888 0 : return error;
1889 : }
1890 :
1891 21 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1892 : }
1893 :
1894 28 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1895 : {
1896 5 : st_ivas->element_mode_init = IVAS_CPE_MDCT; /* element_mode_init was IVAS_SCE for SCE initialization */
1897 5 : move16();
1898 5 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, brate_cpe ) ), IVAS_ERR_OK ) )
1899 : {
1900 0 : return error;
1901 : }
1902 :
1903 15 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1904 : {
1905 10 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1906 : }
1907 : }
1908 :
1909 : /* create CPE element for DFT Stereo like upmix */
1910 23 : IF( st_ivas->sba_dirac_stereo_flag )
1911 : {
1912 : Word32 res_dec, res_frac;
1913 3 : iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 );
1914 3 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) )
1915 : {
1916 0 : return error;
1917 : }
1918 :
1919 3 : st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
1920 3 : st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
1921 : }
1922 :
1923 : /* set CNA/CNG flags */
1924 23 : test();
1925 23 : test();
1926 23 : IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) )
1927 : {
1928 10 : st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1;
1929 10 : move16();
1930 10 : st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1;
1931 10 : move16();
1932 : }
1933 : }
1934 : }
1935 :
1936 :
1937 : /*-----------------------------------------------------------------*
1938 : * Allocate and initialize HP20 filter memories
1939 : *-----------------------------------------------------------------*/
1940 :
1941 : /* set number of output channels used for synthesis/decoding */
1942 594 : n = getNumChanSynthesis( st_ivas );
1943 :
1944 594 : IF( n > 0 )
1945 : {
1946 594 : IF( ( st_ivas->mem_hp20_out_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL )
1947 : {
1948 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
1949 : }
1950 : }
1951 : ELSE
1952 : {
1953 0 : st_ivas->mem_hp20_out_fx = NULL;
1954 : }
1955 :
1956 2153 : FOR( i = 0; i < n; i++ )
1957 : {
1958 1559 : IF( ( st_ivas->mem_hp20_out_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL )
1959 : {
1960 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
1961 : }
1962 1559 : set32_fx( st_ivas->mem_hp20_out_fx[i], 0, L_HP20_MEM + 2 );
1963 : }
1964 :
1965 : /*-------------------------------------------------------------------*
1966 : * Allocate and initialize rendering handles
1967 : *--------------------------------------------------------------------*/
1968 594 : test();
1969 594 : test();
1970 594 : test();
1971 594 : test();
1972 594 : test();
1973 594 : test();
1974 594 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
1975 : {
1976 35 : IF( NE_32( ( error = ivas_binRenderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
1977 : {
1978 0 : return error;
1979 : }
1980 : }
1981 : /* ParamISM is handled separately from other common config */
1982 559 : ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) )
1983 : {
1984 6 : IF( NE_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
1985 : {
1986 6 : IF( NE_32( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) )
1987 : {
1988 0 : return error;
1989 : }
1990 : }
1991 :
1992 6 : IF( NE_32( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) )
1993 : {
1994 0 : return error;
1995 : }
1996 : }
1997 553 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
1998 : {
1999 : Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
2000 : Word16 num_src;
2001 23 : IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) )
2002 : {
2003 0 : return error;
2004 : }
2005 23 : Word16 nchan_rend = num_src;
2006 23 : move16();
2007 23 : test();
2008 23 : IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
2009 : {
2010 3 : nchan_rend = sub( nchan_rend, 1 ); /* Skip LFE channel -- added to the others */
2011 : }
2012 93 : FOR( Word16 nS = 0; nS < nchan_rend; nS++ )
2013 : {
2014 70 : TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]];
2015 70 : if ( Src_p->SrcSpatial_p != NULL )
2016 : {
2017 70 : Src_p->SrcSpatial_p->q_Pos_p = Q31;
2018 70 : move16();
2019 : }
2020 70 : TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p;
2021 70 : SrcSpatial_p->q_Pos_p = Q31;
2022 70 : move16();
2023 : }
2024 :
2025 23 : IF( EQ_32( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
2026 : {
2027 1 : IF( NE_32( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hDecoderConfig->output_config, NULL, st_ivas->hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) )
2028 : {
2029 0 : return error;
2030 : }
2031 : }
2032 :
2033 23 : granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES );
2034 :
2035 23 : n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas );
2036 :
2037 :
2038 23 : IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ), IVAS_ERR_OK ) )
2039 : {
2040 0 : return error;
2041 : }
2042 : }
2043 530 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
2044 : {
2045 6 : IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2046 : {
2047 0 : return error;
2048 : }
2049 : }
2050 524 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
2051 : {
2052 9 : IF( NE_32( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ), IVAS_ERR_OK ) )
2053 : {
2054 0 : return error;
2055 : }
2056 : }
2057 515 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
2058 : {
2059 29 : test();
2060 29 : test();
2061 29 : test();
2062 29 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && EQ_32( st_ivas->ivas_format, MC_FORMAT ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) )
2063 : {
2064 4 : IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) )
2065 : {
2066 0 : return error;
2067 : }
2068 : }
2069 :
2070 29 : IF( NE_32( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config,
2071 : st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ),
2072 : IVAS_ERR_OK ) )
2073 : {
2074 0 : return error;
2075 : }
2076 :
2077 29 : st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns;
2078 29 : move32();
2079 :
2080 29 : test();
2081 29 : IF( ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) && ( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) )
2082 : {
2083 0 : granularity = NS2SA_FX2( output_Fs, CLDFB_SLOT_NS );
2084 :
2085 0 : n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas );
2086 :
2087 :
2088 0 : IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, MC_PARAMUPMIX_MAX_INPUT_CHANS, MC_PARAMUPMIX_MAX_INPUT_CHANS, granularity ) ), IVAS_ERR_OK ) )
2089 : {
2090 0 : return error;
2091 : }
2092 : }
2093 : ELSE
2094 : {
2095 29 : granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES );
2096 :
2097 29 : n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas );
2098 :
2099 29 : IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ), IVAS_ERR_OK ) )
2100 : {
2101 0 : return error;
2102 : }
2103 : }
2104 : }
2105 :
2106 594 : IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
2107 : {
2108 32 : test();
2109 32 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
2110 : {
2111 : /* Allocate TD renderer for the objects in DISC mode */
2112 : Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
2113 : Word16 num_src;
2114 1 : IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) )
2115 : {
2116 0 : return error;
2117 : }
2118 1 : Word16 nchan_rend = num_src;
2119 1 : move16();
2120 1 : test();
2121 1 : if ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
2122 : {
2123 0 : nchan_rend = sub( nchan_rend, 1 ); /* Skip LFE channel -- added to the others */
2124 : }
2125 5 : FOR( Word16 nS = 0; nS < nchan_rend; nS++ )
2126 : {
2127 4 : TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]];
2128 4 : if ( Src_p->SrcSpatial_p != NULL )
2129 : {
2130 4 : Src_p->SrcSpatial_p->q_Pos_p = Q31;
2131 4 : move16();
2132 : }
2133 4 : TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p;
2134 4 : SrcSpatial_p->q_Pos_p = Q31;
2135 4 : move16();
2136 : }
2137 :
2138 : /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */
2139 1 : IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) )
2140 : {
2141 0 : return error;
2142 : }
2143 : }
2144 :
2145 32 : test();
2146 32 : test();
2147 32 : test();
2148 32 : IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) )
2149 : {
2150 : /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */
2151 9 : IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) )
2152 : {
2153 0 : return error;
2154 : }
2155 : }
2156 : }
2157 :
2158 594 : test();
2159 594 : test();
2160 594 : test();
2161 594 : test();
2162 594 : test();
2163 594 : test();
2164 594 : test();
2165 594 : test();
2166 594 : test();
2167 594 : test();
2168 594 : test();
2169 594 : test();
2170 594 : IF( ( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) &&
2171 : ( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) &&
2172 : ( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) ||
2173 : EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ||
2174 : EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ||
2175 : EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) ||
2176 : EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) ||
2177 : EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) ||
2178 : EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
2179 : EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
2180 : EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) )
2181 : {
2182 27 : IF( NE_32( ( error = ivas_ism_renderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2183 : {
2184 0 : return error;
2185 : }
2186 : }
2187 :
2188 594 : IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
2189 : {
2190 30 : test();
2191 30 : test();
2192 30 : IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
2193 : {
2194 : /* Allocate TD renderer for the objects in DISC mode */
2195 : Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
2196 : Word16 num_src;
2197 4 : IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) )
2198 : {
2199 0 : return error;
2200 : }
2201 4 : Word16 nchan_rend = num_src;
2202 4 : move16();
2203 :
2204 4 : test();
2205 4 : if ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
2206 : {
2207 0 : nchan_rend = sub( nchan_rend, 1 ); /* Skip LFE channel -- added to the others */
2208 : }
2209 20 : FOR( Word16 nS = 0; nS < nchan_rend; nS++ )
2210 : {
2211 16 : TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]];
2212 16 : if ( Src_p->SrcSpatial_p != NULL )
2213 : {
2214 16 : Src_p->SrcSpatial_p->q_Pos_p = Q31;
2215 16 : move16();
2216 : }
2217 16 : TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p;
2218 16 : SrcSpatial_p->q_Pos_p = Q31;
2219 16 : move16();
2220 : }
2221 : }
2222 : }
2223 :
2224 : /*-----------------------------------------------------------------*
2225 : * LFE handles for rendering after rendering to adjust LFE delay to binaural filter delay
2226 : *-----------------------------------------------------------------*/
2227 594 : test();
2228 594 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
2229 : {
2230 40 : binauralization_delay_ns = st_ivas->binaural_latency_ns;
2231 40 : move32();
2232 40 : IF( st_ivas->hBinRenderer != NULL )
2233 : {
2234 4 : IF( st_ivas->hBinRenderer->render_lfe )
2235 : {
2236 : {
2237 : /* Account for filterbank delay */
2238 1 : binauralization_delay_ns = L_add( binauralization_delay_ns, IVAS_FB_DEC_DELAY_NS );
2239 : }
2240 : }
2241 : ELSE
2242 : {
2243 3 : binauralization_delay_ns = 0;
2244 3 : move32();
2245 : }
2246 : }
2247 :
2248 40 : IF( NE_32( ( error = ivas_create_lfe_dec_fx( &st_ivas->hLFE, output_Fs, binauralization_delay_ns ) ), IVAS_ERR_OK ) )
2249 : {
2250 0 : return error;
2251 : }
2252 :
2253 40 : set32_fx( st_ivas->hLFE->prevsynth_buf_fx, 0, LFE_PLC_BUFLEN );
2254 40 : set32_fx( st_ivas->hLFE->prior_out_buffer_fx, 0, L_FRAME48k );
2255 : }
2256 :
2257 : /*-----------------------------------------------------------------*
2258 : * CLDFB handles for rendering
2259 : *-----------------------------------------------------------------*/
2260 :
2261 594 : ivas_init_dec_get_num_cldfb_instances_ivas_fx( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses );
2262 :
2263 2036 : FOR( i = 0; i < numCldfbAnalyses; i++ )
2264 : {
2265 1442 : IF( NE_32( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, output_Fs, CLDFB_PROTOTYPE_5_00MS, DEC ) ), IVAS_ERR_OK ) )
2266 : {
2267 0 : return error;
2268 : }
2269 : }
2270 8656 : FOR( ; i < MAX_INTERN_CHANNELS; i++ )
2271 : {
2272 8062 : st_ivas->cldfbAnaDec[i] = NULL;
2273 : }
2274 :
2275 2722 : FOR( i = 0; i < numCldfbSyntheses; i++ )
2276 : {
2277 2128 : IF( NE_32( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, output_Fs, CLDFB_PROTOTYPE_5_00MS, DEC ) ), IVAS_ERR_OK ) )
2278 : {
2279 0 : return error;
2280 : }
2281 : }
2282 7970 : FOR( ; i < MAX_OUTPUT_CHANNELS; i++ )
2283 : {
2284 7376 : st_ivas->cldfbSynDec[i] = NULL;
2285 : }
2286 :
2287 : /* CLDFB Interpolation weights */
2288 594 : test();
2289 594 : test();
2290 594 : test();
2291 594 : IF( ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !st_ivas->sba_dirac_stereo_flag && NE_16( st_ivas->hDecoderConfig->nchan_out, 1 ) )
2292 : {
2293 253 : Word16 Q_cldfbSynDec = Q11;
2294 253 : move16();
2295 253 : ivas_spar_get_cldfb_gains_fx( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig );
2296 :
2297 104293 : FOR( i = 0; i < st_ivas->cldfbAnaDec[0]->cldfb_state_length; i++ )
2298 : {
2299 104040 : st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], 16 ); // Scaling down from 27 to 11
2300 104040 : move32();
2301 : }
2302 253 : st_ivas->cldfbAnaDec[0]->Q_cldfb_state = Q11;
2303 253 : move16();
2304 115853 : FOR( i = 0; i < st_ivas->cldfbSynDec[0]->cldfb_state_length; i++ )
2305 : {
2306 115600 : st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], sub( 21, Q_cldfbSynDec ) ); // Scaling down from 21 to Q_cldfbSynDec
2307 115600 : move32();
2308 : }
2309 253 : st_ivas->cldfbSynDec[0]->Q_cldfb_state = Q11;
2310 253 : move16();
2311 : }
2312 :
2313 : /*-----------------------------------------------------------------*
2314 : * Allocate and initialize limiter struct
2315 : *-----------------------------------------------------------------*/
2316 :
2317 594 : IF( NE_32( ( error = ivas_limiter_open_fx( &st_ivas->hLimiter, hDecoderConfig->nchan_out, output_Fs ) ), IVAS_ERR_OK ) )
2318 : {
2319 0 : return error;
2320 : }
2321 :
2322 : /*-----------------------------------------------------------------*
2323 : * Allocate and initialize JBM struct + buffer
2324 : *-----------------------------------------------------------------*/
2325 :
2326 594 : IF( st_ivas->hTcBuffer == NULL )
2327 :
2328 : {
2329 : /* no module has yet open the TC buffer, open a default one */
2330 134 : n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas );
2331 :
2332 134 : IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, ivas_jbm_dec_get_tc_buffer_mode( st_ivas ), n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
2333 : {
2334 0 : return error;
2335 : }
2336 : }
2337 :
2338 594 : IF( st_ivas->hTcBuffer == NULL )
2339 : {
2340 : /* we need the handle anyway, but without the buffer*/
2341 0 : IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_NONE, 0, 0, 0, 1 ) ), IVAS_ERR_OK ) )
2342 : {
2343 0 : return error;
2344 : }
2345 : }
2346 :
2347 594 : IF( st_ivas->hJbmMetadata == NULL )
2348 : {
2349 594 : IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
2350 : {
2351 44 : IF( NE_32( ( error = ivas_jbm_dec_metadata_open( st_ivas ) ), IVAS_ERR_OK ) )
2352 : {
2353 0 : return error;
2354 : }
2355 : }
2356 : }
2357 :
2358 : /*-----------------------------------------------------------------*
2359 : * Allocate floating-point output audio buffers
2360 : *-----------------------------------------------------------------*/
2361 594 : st_ivas->p_out_len = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate );
2362 594 : move16();
2363 4132 : FOR( n = 0; n < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ )
2364 : {
2365 : /* note: these are intra-frame heap memories */
2366 3538 : IF( ( st_ivas->p_output_fx[n] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ) ) == NULL )
2367 : {
2368 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) );
2369 : }
2370 3538 : set32_fx( st_ivas->p_output_fx[n], 0, 48000 / FRAMES_PER_SEC );
2371 : }
2372 :
2373 8936 : FOR( ; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ )
2374 : {
2375 8342 : st_ivas->p_output_fx[n] = NULL;
2376 : }
2377 594 : return error;
2378 : }
2379 :
2380 : /*-------------------------------------------------------------------------
2381 : * destroy_core_dec()
2382 : *
2383 : * Close core decoder handles
2384 : *-------------------------------------------------------------------------*/
2385 :
2386 7236 : void destroy_core_dec_fx(
2387 : DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */
2388 : )
2389 : {
2390 7236 : IF( EQ_16( hCoreCoder->element_mode, EVS_MONO ) )
2391 : {
2392 3 : destroy_cldfb_decoder_fx( hCoreCoder );
2393 : }
2394 : ELSE
2395 : {
2396 7233 : destroy_cldfb_decoder_ivas_fx( hCoreCoder );
2397 : }
2398 :
2399 7236 : IF( hCoreCoder->hGSCDec != NULL )
2400 : {
2401 2516 : free( hCoreCoder->hGSCDec );
2402 2516 : hCoreCoder->hGSCDec = NULL;
2403 : }
2404 :
2405 7236 : IF( hCoreCoder->hPFstat != NULL )
2406 : {
2407 2516 : free( hCoreCoder->hPFstat );
2408 2516 : hCoreCoder->hPFstat = NULL;
2409 : }
2410 :
2411 7236 : IF( hCoreCoder->hMusicPF != NULL )
2412 : {
2413 2516 : free( hCoreCoder->hMusicPF );
2414 2516 : hCoreCoder->hMusicPF = NULL;
2415 : }
2416 :
2417 7236 : IF( hCoreCoder->hBPF != NULL )
2418 : {
2419 2516 : free( hCoreCoder->hBPF );
2420 2516 : hCoreCoder->hBPF = NULL;
2421 : }
2422 :
2423 7236 : IF( hCoreCoder->hBWE_zero != NULL )
2424 : {
2425 2516 : free( hCoreCoder->hBWE_zero );
2426 2516 : hCoreCoder->hBWE_zero = NULL;
2427 : }
2428 :
2429 7236 : IF( hCoreCoder->hTdCngDec != NULL )
2430 : {
2431 1340 : free( hCoreCoder->hTdCngDec );
2432 1340 : hCoreCoder->hTdCngDec = NULL;
2433 : }
2434 :
2435 7236 : IF( hCoreCoder->hSC_VBR != NULL )
2436 : {
2437 3 : free( hCoreCoder->hSC_VBR );
2438 3 : hCoreCoder->hSC_VBR = NULL;
2439 : }
2440 :
2441 7236 : IF( hCoreCoder->hAmrwb_IO != NULL )
2442 : {
2443 3 : free( hCoreCoder->hAmrwb_IO );
2444 3 : hCoreCoder->hAmrwb_IO = NULL;
2445 : }
2446 :
2447 7236 : IF( hCoreCoder->hBWE_TD != NULL )
2448 : {
2449 2541 : free( hCoreCoder->hBWE_TD );
2450 2541 : hCoreCoder->hBWE_TD = NULL;
2451 : }
2452 :
2453 7236 : IF( hCoreCoder->hBWE_FD != NULL )
2454 : {
2455 2541 : free( hCoreCoder->hBWE_FD );
2456 2541 : hCoreCoder->hBWE_FD = NULL;
2457 : }
2458 :
2459 7236 : IF( hCoreCoder->hBWE_FD_HR != NULL )
2460 : {
2461 3 : free( hCoreCoder->hBWE_FD_HR );
2462 3 : hCoreCoder->hBWE_FD_HR = NULL;
2463 : }
2464 :
2465 7236 : IF( hCoreCoder->hWIDec != NULL )
2466 : {
2467 0 : free( hCoreCoder->hWIDec );
2468 0 : hCoreCoder->hWIDec = NULL;
2469 : }
2470 :
2471 7236 : IF( hCoreCoder->hTECDec != NULL )
2472 : {
2473 3 : free( hCoreCoder->hTECDec );
2474 3 : hCoreCoder->hTECDec = NULL;
2475 : }
2476 :
2477 7236 : IF( hCoreCoder->hTcxLtpDec != NULL )
2478 : {
2479 7155 : free( hCoreCoder->hTcxLtpDec );
2480 7155 : hCoreCoder->hTcxLtpDec = NULL;
2481 : }
2482 :
2483 7236 : IF( hCoreCoder->hTcxDec != NULL )
2484 : {
2485 7155 : free( hCoreCoder->hTcxDec );
2486 7155 : hCoreCoder->hTcxDec = NULL;
2487 : }
2488 :
2489 7236 : IF( hCoreCoder->hTcxCfg != NULL )
2490 : {
2491 7155 : free( hCoreCoder->hTcxCfg );
2492 7155 : hCoreCoder->hTcxCfg = NULL;
2493 : }
2494 :
2495 7236 : IF( hCoreCoder->hTonalMDCTConc != NULL )
2496 : {
2497 7155 : free( hCoreCoder->hTonalMDCTConc );
2498 7155 : hCoreCoder->hTonalMDCTConc = NULL;
2499 : }
2500 :
2501 7236 : IF( hCoreCoder->hIGFDec != NULL )
2502 : {
2503 7155 : free( hCoreCoder->hIGFDec );
2504 7155 : hCoreCoder->hIGFDec = NULL;
2505 : }
2506 :
2507 7236 : IF( hCoreCoder->hPlcInfo != NULL )
2508 : {
2509 3 : free( hCoreCoder->hPlcInfo );
2510 3 : hCoreCoder->hPlcInfo = NULL;
2511 : }
2512 :
2513 7236 : IF( hCoreCoder->hHQ_core != NULL )
2514 : {
2515 7155 : free( hCoreCoder->hHQ_core );
2516 7155 : hCoreCoder->hHQ_core = NULL;
2517 : }
2518 :
2519 7236 : IF( hCoreCoder->hHQ_nbfec != NULL )
2520 : {
2521 3 : free( hCoreCoder->hHQ_nbfec );
2522 3 : hCoreCoder->hHQ_nbfec = NULL;
2523 : }
2524 :
2525 7236 : return;
2526 : }
2527 :
2528 : /*-------------------------------------------------------------------------
2529 : * ivas_initialize_handles_dec()
2530 : *
2531 : * NULL initialization of handles
2532 : *-------------------------------------------------------------------------*/
2533 :
2534 604 : void ivas_initialize_handles_dec(
2535 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
2536 : )
2537 : {
2538 : Word16 i;
2539 :
2540 10268 : FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ )
2541 : {
2542 9664 : st_ivas->cldfbAnaDec[i] = NULL;
2543 : }
2544 :
2545 10268 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2546 : {
2547 9664 : st_ivas->cldfbSynDec[i] = NULL;
2548 : }
2549 :
2550 : /* SCE handles */
2551 3020 : FOR( i = 0; i < MAX_SCE; i++ )
2552 : {
2553 2416 : st_ivas->hSCE[i] = NULL;
2554 : }
2555 :
2556 : /* CPE handles */
2557 4228 : FOR( i = 0; i < MAX_CPE; i++ )
2558 : {
2559 3624 : st_ivas->hCPE[i] = NULL;
2560 : }
2561 :
2562 604 : st_ivas->bit_stream = NULL;
2563 604 : st_ivas->mem_hp20_out_fx = NULL;
2564 604 : st_ivas->hLimiter = NULL;
2565 :
2566 : /* ISM metadata handles */
2567 3020 : FOR( i = 0; i < MAX_NUM_OBJECTS; i++ )
2568 : {
2569 2416 : st_ivas->hIsmMetaData[i] = NULL;
2570 : }
2571 :
2572 : /* spatial coding handles */
2573 604 : st_ivas->hDirAC = NULL;
2574 604 : st_ivas->hParamIsmDec = NULL;
2575 604 : st_ivas->hSpar = NULL;
2576 604 : st_ivas->hMasa = NULL;
2577 604 : st_ivas->hQMetaData = NULL;
2578 604 : st_ivas->hMCT = NULL;
2579 604 : st_ivas->hMCParamUpmix = NULL;
2580 604 : st_ivas->hParamMC = NULL;
2581 604 : st_ivas->hLFE = NULL;
2582 :
2583 : /* rendering handles */
2584 604 : st_ivas->hBinRenderer = NULL;
2585 604 : st_ivas->hDiracDecBin = NULL;
2586 604 : st_ivas->hDirACRend = NULL;
2587 604 : st_ivas->hSpatParamRendCom = NULL;
2588 604 : st_ivas->hLsSetUpConversion = NULL;
2589 604 : st_ivas->hEFAPdata = NULL;
2590 604 : st_ivas->hVBAPdata = NULL;
2591 604 : st_ivas->hIsmRendererData = NULL;
2592 604 : st_ivas->hBinRendererTd = NULL;
2593 604 : st_ivas->hMonoDmxRenderer = NULL;
2594 604 : st_ivas->hCrendWrapper = NULL;
2595 604 : st_ivas->hReverb = NULL;
2596 604 : st_ivas->hSetOfHRTF = NULL;
2597 604 : st_ivas->hHrtfFastConv = NULL;
2598 604 : st_ivas->hHrtfParambin = NULL;
2599 604 : st_ivas->hoa_dec_mtx = NULL;
2600 604 : st_ivas->hMasaIsmData = NULL;
2601 604 : st_ivas->hSbaIsmData = NULL;
2602 :
2603 604 : st_ivas->hHeadTrackData = NULL;
2604 604 : st_ivas->hHrtfTD = NULL;
2605 604 : st_ivas->hLsSetupCustom = NULL;
2606 604 : st_ivas->hRenderConfig = NULL;
2607 604 : st_ivas->hExtOrientationData = NULL;
2608 604 : st_ivas->hCombinedOrientationData = NULL;
2609 :
2610 :
2611 : /* JBM handles */
2612 604 : st_ivas->hTcBuffer = NULL;
2613 604 : st_ivas->hJbmMetadata = NULL;
2614 :
2615 : /* floating-point output audio buffers */
2616 12684 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ )
2617 : {
2618 12080 : st_ivas->p_output_fx[i] = NULL;
2619 : }
2620 :
2621 604 : return;
2622 : }
2623 :
2624 :
2625 : /*-------------------------------------------------------------------------
2626 : * ivas_destroy_dec()
2627 : *
2628 : * Close IVAS decoder handles
2629 : *-------------------------------------------------------------------------*/
2630 :
2631 604 : void ivas_destroy_dec_fx(
2632 : Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */
2633 : )
2634 : {
2635 : Word16 i;
2636 :
2637 : /* CLDFB handles */
2638 10268 : FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ )
2639 : {
2640 9664 : IF( st_ivas->cldfbAnaDec[i] != NULL )
2641 : {
2642 1479 : deleteCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ) );
2643 : }
2644 : }
2645 :
2646 10268 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2647 : {
2648 9664 : IF( st_ivas->cldfbSynDec[i] != NULL )
2649 : {
2650 2135 : deleteCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ) );
2651 : }
2652 : }
2653 :
2654 : /* SCE handles */
2655 3020 : FOR( i = 0; i < MAX_SCE; i++ )
2656 : {
2657 2416 : IF( st_ivas->hSCE[i] != NULL )
2658 : {
2659 376 : destroy_sce_dec( st_ivas->hSCE[i] );
2660 376 : st_ivas->hSCE[i] = NULL;
2661 : }
2662 : }
2663 :
2664 : /* CPE handles */
2665 4228 : FOR( i = 0; i < MAX_CPE; i++ )
2666 : {
2667 3624 : IF( st_ivas->hCPE[i] != NULL )
2668 : {
2669 : /* set pointer to NULL as core coder already deallocated in destroy_sce_dec() */
2670 688 : test();
2671 688 : IF( st_ivas->sba_dirac_stereo_flag && EQ_16( st_ivas->nchan_transport, 1 ) )
2672 : {
2673 5 : st_ivas->hCPE[i]->hCoreCoder[0] = NULL;
2674 5 : st_ivas->hCPE[i]->hCoreCoder[1] = NULL;
2675 : }
2676 688 : destroy_cpe_dec( st_ivas->hCPE[i] );
2677 688 : st_ivas->hCPE[i] = NULL;
2678 : }
2679 : }
2680 :
2681 : /* HP20 filter handles */
2682 604 : IF( st_ivas->mem_hp20_out_fx != NULL )
2683 : {
2684 2276 : FOR( i = 0; i < getNumChanSynthesis( st_ivas ); i++ )
2685 : {
2686 1682 : free( st_ivas->mem_hp20_out_fx[i] );
2687 1682 : st_ivas->mem_hp20_out_fx[i] = NULL;
2688 : }
2689 594 : free( st_ivas->mem_hp20_out_fx );
2690 594 : st_ivas->mem_hp20_out_fx = NULL;
2691 : }
2692 :
2693 : /* ISM metadata handles */
2694 604 : ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 );
2695 :
2696 : /* ISM renderer handle */
2697 604 : ivas_ism_renderer_close( &( st_ivas->hIsmRendererData ) );
2698 :
2699 : /* DirAC handle */
2700 604 : IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
2701 : {
2702 67 : ivas_param_ism_dec_close_fx( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config );
2703 : }
2704 : ELSE
2705 : {
2706 537 : ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) );
2707 537 : ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) );
2708 537 : ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) );
2709 : }
2710 :
2711 : /* SPAR handle */
2712 604 : ivas_spar_dec_close_fx( &( st_ivas->hSpar ), st_ivas->hDecoderConfig->output_Fs, 0 );
2713 :
2714 : /* HOA decoder matrix */
2715 604 : IF( st_ivas->hoa_dec_mtx != NULL )
2716 : {
2717 27 : free( st_ivas->hoa_dec_mtx );
2718 27 : st_ivas->hoa_dec_mtx = NULL;
2719 : }
2720 :
2721 : /* MASA decoder structure */
2722 :
2723 604 : ivas_masa_dec_close_fx( &( st_ivas->hMasa ) );
2724 : /* Qmetadata handle */
2725 604 : ivas_qmetadata_close_fx( &st_ivas->hQMetaData );
2726 :
2727 : /* MCT handle */
2728 604 : ivas_mct_dec_close( &st_ivas->hMCT );
2729 :
2730 : /* LFE handle */
2731 604 : ivas_lfe_dec_close_fx( &( st_ivas->hLFE ) );
2732 :
2733 : /* Param-Upmix MC handle */
2734 604 : ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) );
2735 :
2736 : /* Parametric MC handle */
2737 604 : ivas_param_mc_dec_close_fx( &st_ivas->hParamMC );
2738 :
2739 : /* EFAP handle */
2740 604 : efap_free_data_fx( &st_ivas->hEFAPdata );
2741 :
2742 : /* VBAP handle */
2743 604 : vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
2744 : /* Fastconv binaural renderer handle */
2745 604 : ivas_binRenderer_close_fx( &st_ivas->hBinRenderer );
2746 :
2747 : /* Parametric binaural renderer handle */
2748 604 : ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin );
2749 :
2750 : /* Crend handle */
2751 :
2752 604 : ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) );
2753 :
2754 : /* Reverb handle */
2755 604 : ivas_reverb_close( &st_ivas->hReverb );
2756 :
2757 : /* LS config converter handle */
2758 :
2759 604 : ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
2760 : /* Custom LS configuration handle */
2761 604 : IF( st_ivas->hLsSetupCustom != NULL )
2762 : {
2763 3 : free( st_ivas->hLsSetupCustom );
2764 3 : st_ivas->hLsSetupCustom = NULL;
2765 : }
2766 :
2767 : /* Mono downmix structure */
2768 604 : ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer );
2769 :
2770 : /* OSBA structure */
2771 :
2772 604 : ivas_osba_data_close_fx( &st_ivas->hSbaIsmData );
2773 :
2774 : /* OMASA structure */
2775 604 : ivas_omasa_data_close_fx( &st_ivas->hMasaIsmData );
2776 : /* Head track data handle */
2777 604 : ivas_headTrack_close_fx( &st_ivas->hHeadTrackData );
2778 :
2779 : /* External orientation data handle */
2780 604 : ivas_external_orientation_close_fx( &st_ivas->hExtOrientationData );
2781 :
2782 : /* Combined orientation data handle */
2783 604 : ivas_combined_orientation_close_fx( &st_ivas->hCombinedOrientationData );
2784 :
2785 : /* Time Domain binaural renderer handle */
2786 604 : IF( st_ivas->hBinRendererTd != NULL )
2787 : {
2788 31 : ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd );
2789 : }
2790 573 : ELSE IF( st_ivas->hHrtfTD != NULL )
2791 : {
2792 14 : BSplineModelEvalDealloc_fx( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval );
2793 14 : ivas_HRTF_binary_close_fx( &st_ivas->hHrtfTD );
2794 : }
2795 :
2796 : /* CRend binaural renderer handle */
2797 604 : ivas_HRTF_CRend_binary_close_fx( &st_ivas->hSetOfHRTF );
2798 :
2799 : /* Fastconv HRTF memories */
2800 604 : ivas_binaural_hrtf_close( &st_ivas->hHrtfFastConv );
2801 :
2802 : /* Fastconv HRTF filters */
2803 604 : ivas_HRTF_fastconv_binary_close_fx( &st_ivas->hHrtfFastConv );
2804 :
2805 : /* Parametric binauralizer HRTF filters */
2806 604 : ivas_HRTF_parambin_binary_close_fx( &st_ivas->hHrtfParambin );
2807 :
2808 : /* Config. Renderer */
2809 604 : ivas_render_config_close( &( st_ivas->hRenderConfig ) );
2810 :
2811 : /* Limiter struct */
2812 604 : ivas_limiter_close_fx( &( st_ivas->hLimiter ) );
2813 :
2814 604 : IF( st_ivas->hDecoderConfig != NULL )
2815 : {
2816 604 : free( st_ivas->hDecoderConfig );
2817 604 : st_ivas->hDecoderConfig = NULL;
2818 : }
2819 :
2820 604 : ivas_jbm_dec_tc_buffer_close( &st_ivas->hTcBuffer );
2821 :
2822 604 : IF( st_ivas->hJbmMetadata != NULL )
2823 : {
2824 44 : free( st_ivas->hJbmMetadata );
2825 44 : st_ivas->hJbmMetadata = NULL;
2826 : }
2827 :
2828 : /* floating-point output audio buffers */
2829 12684 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ )
2830 : {
2831 :
2832 12080 : IF( st_ivas->p_output_fx[i] != NULL )
2833 : {
2834 3621 : free( st_ivas->p_output_fx[i] );
2835 3621 : st_ivas->p_output_fx[i] = NULL;
2836 : }
2837 : }
2838 :
2839 : /* main IVAS handle */
2840 604 : free( st_ivas );
2841 :
2842 604 : return;
2843 : }
2844 :
2845 :
2846 : /*-------------------------------------------------------------------*
2847 : * ivas_init_dec_get_num_cldfb_instances()
2848 : *
2849 : * Return number of CLDFB analysis & synthesis instances
2850 : *-------------------------------------------------------------------*/
2851 :
2852 : /*! r: number of cldfb instances */
2853 4269 : void ivas_init_dec_get_num_cldfb_instances(
2854 : Decoder_Struct *st_ivas, /* i : IVAS decoder structure */
2855 : Word16 *numCldfbAnalyses, /* o : number of needed CLDFB analysis instances */
2856 : Word16 *numCldfbSyntheses /* o : number of needed CLDFB synthesis instances */
2857 : )
2858 : {
2859 : IVAS_FORMAT ivas_format;
2860 4269 : *numCldfbAnalyses = st_ivas->nchan_transport;
2861 4269 : move16();
2862 4269 : *numCldfbSyntheses = st_ivas->hDecoderConfig->nchan_out;
2863 4269 : move16();
2864 :
2865 4269 : test();
2866 4269 : IF( ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) )
2867 : {
2868 391 : ivas_format = SBA_FORMAT;
2869 391 : move32();
2870 : }
2871 : ELSE
2872 : {
2873 3878 : ivas_format = st_ivas->ivas_format;
2874 3878 : move32();
2875 : }
2876 :
2877 4269 : SWITCH( st_ivas->renderer_type )
2878 : {
2879 1483 : case RENDERER_BINAURAL_PARAMETRIC:
2880 : case RENDERER_BINAURAL_PARAMETRIC_ROOM:
2881 : case RENDERER_STEREO_PARAMETRIC:
2882 1483 : IF( EQ_16( st_ivas->nchan_transport, 1 ) )
2883 : {
2884 445 : *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 );
2885 445 : move16();
2886 : }
2887 :
2888 1483 : test();
2889 1483 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->hOutSetup.separateChannelEnabled )
2890 : {
2891 0 : *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 );
2892 0 : move16();
2893 : }
2894 :
2895 1483 : IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) )
2896 : {
2897 0 : IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
2898 : {
2899 0 : *numCldfbAnalyses = add( *numCldfbAnalyses, st_ivas->nchan_ism );
2900 0 : move16();
2901 : }
2902 : }
2903 :
2904 1483 : IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) )
2905 : {
2906 472 : test();
2907 472 : IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
2908 : {
2909 183 : *numCldfbAnalyses = add( *numCldfbAnalyses, st_ivas->nchan_ism );
2910 183 : move16();
2911 : }
2912 289 : ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
2913 : {
2914 289 : *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 );
2915 289 : move16();
2916 : }
2917 : }
2918 1483 : IF( st_ivas->hDiracDecBin->useTdDecorr )
2919 : {
2920 499 : *numCldfbAnalyses = add( *numCldfbAnalyses, 2 );
2921 499 : move16();
2922 : }
2923 1483 : BREAK;
2924 109 : case RENDERER_NON_DIEGETIC_DOWNMIX:
2925 : case RENDERER_MONO_DOWNMIX:
2926 109 : test();
2927 109 : test();
2928 109 : IF( EQ_32( ivas_format, ISM_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) )
2929 : {
2930 : /* CLDFB not used in rendering */
2931 71 : *numCldfbAnalyses = 0;
2932 71 : move16();
2933 71 : *numCldfbSyntheses = 0;
2934 71 : move16();
2935 : }
2936 109 : BREAK;
2937 1407 : case RENDERER_DIRAC:
2938 1407 : IF( EQ_32( ivas_format, SBA_FORMAT ) )
2939 : {
2940 88 : *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans;
2941 88 : move16();
2942 :
2943 88 : test();
2944 88 : IF( st_ivas->hOutSetup.is_loudspeaker_setup && EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) )
2945 : {
2946 88 : *numCldfbSyntheses = st_ivas->hOutSetup.nchan_out_woLFE;
2947 88 : move16();
2948 : }
2949 0 : ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) )
2950 : {
2951 0 : *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans;
2952 0 : move16();
2953 : }
2954 : ELSE
2955 : {
2956 0 : *numCldfbSyntheses = MAX_OUTPUT_CHANNELS;
2957 0 : move16();
2958 : }
2959 : }
2960 1407 : IF( NE_32( ivas_format, SBA_FORMAT ) )
2961 : {
2962 1319 : test();
2963 1319 : test();
2964 1319 : IF( GT_16( st_ivas->nchan_transport, 2 ) && ( st_ivas->sba_planar != 0 ) )
2965 : {
2966 0 : *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 );
2967 0 : move16();
2968 : }
2969 1319 : ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_32( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
2970 : {
2971 190 : *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 );
2972 190 : move16();
2973 : }
2974 : }
2975 1407 : BREAK;
2976 0 : case RENDERER_MC_PARAMMC:
2977 0 : IF( LE_16( st_ivas->hDecoderConfig->nchan_out, 2 ) )
2978 : {
2979 : /* CLDFB not used in rendering */
2980 0 : *numCldfbAnalyses = 0;
2981 0 : move16();
2982 0 : *numCldfbSyntheses = 0;
2983 0 : move16();
2984 : }
2985 : ELSE
2986 : {
2987 0 : *numCldfbSyntheses = param_mc_get_num_cldfb_syntheses_fx( st_ivas );
2988 0 : move16();
2989 : }
2990 0 : BREAK;
2991 0 : case RENDERER_PARAM_ISM:
2992 : /* Already correct with no exception */
2993 0 : BREAK;
2994 350 : case RENDERER_DISABLE:
2995 : /* CLDFB not used */
2996 350 : *numCldfbAnalyses = 0;
2997 350 : move16();
2998 350 : *numCldfbSyntheses = 0;
2999 350 : move16();
3000 350 : BREAK;
3001 920 : case RENDERER_MC:
3002 : case RENDERER_SBA_LINEAR_DEC:
3003 : case RENDERER_TD_PANNING:
3004 : case RENDERER_BINAURAL_OBJECTS_TD:
3005 : case RENDERER_MCMASA_MONO_STEREO:
3006 : case RENDERER_BINAURAL_MIXER_CONV:
3007 : case RENDERER_BINAURAL_MIXER_CONV_ROOM:
3008 : case RENDERER_BINAURAL_FASTCONV:
3009 : case RENDERER_BINAURAL_FASTCONV_ROOM:
3010 : case RENDERER_OSBA_STEREO:
3011 : case RENDERER_OSBA_AMBI:
3012 : case RENDERER_OSBA_LS:
3013 920 : test();
3014 920 : IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) )
3015 : {
3016 920 : IF( st_ivas->sba_dirac_stereo_flag != 0 )
3017 : {
3018 17 : *numCldfbAnalyses = 0;
3019 17 : move16();
3020 17 : *numCldfbSyntheses = 0;
3021 17 : move16();
3022 : }
3023 : ELSE
3024 : {
3025 903 : *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans;
3026 903 : move16();
3027 :
3028 903 : test();
3029 903 : IF( st_ivas->hOutSetup.is_loudspeaker_setup && EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) )
3030 : {
3031 0 : *numCldfbSyntheses = st_ivas->hOutSetup.nchan_out_woLFE;
3032 0 : move16();
3033 : }
3034 903 : ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) )
3035 : {
3036 201 : *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans;
3037 201 : move16();
3038 : }
3039 : ELSE
3040 : {
3041 702 : *numCldfbSyntheses = MAX_OUTPUT_CHANNELS;
3042 702 : move16();
3043 : }
3044 903 : test();
3045 903 : IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
3046 : {
3047 0 : *numCldfbAnalyses = add( st_ivas->nchan_ism, st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans );
3048 0 : move16();
3049 : }
3050 : }
3051 : }
3052 0 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
3053 : {
3054 : /* do nothing for ParamMC */
3055 : }
3056 : ELSE
3057 : {
3058 : /* CLDFB not used in rendering */
3059 0 : *numCldfbAnalyses = 0;
3060 0 : move16();
3061 0 : *numCldfbSyntheses = 0;
3062 0 : move16();
3063 : }
3064 920 : BREAK;
3065 0 : case RENDERER_SBA_LINEAR_ENC:
3066 0 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
3067 : {
3068 0 : *numCldfbSyntheses = param_mc_get_num_cldfb_syntheses_fx( st_ivas );
3069 0 : move16();
3070 : }
3071 0 : ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
3072 : {
3073 0 : *numCldfbSyntheses = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
3074 0 : move16();
3075 : }
3076 0 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
3077 : {
3078 0 : *numCldfbAnalyses = st_ivas->nchan_transport;
3079 0 : move16();
3080 0 : *numCldfbSyntheses = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
3081 0 : move16();
3082 : }
3083 : ELSE
3084 : {
3085 : /* CLDFB not used in rendering */
3086 0 : *numCldfbAnalyses = 0;
3087 0 : move16();
3088 0 : *numCldfbSyntheses = 0;
3089 0 : move16();
3090 : }
3091 0 : BREAK;
3092 0 : default:
3093 0 : assert( 0 && "Renderer not handled for CLDFB reservation." );
3094 : }
3095 4269 : test();
3096 4269 : test();
3097 4269 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) )
3098 : {
3099 0 : test();
3100 0 : test();
3101 0 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
3102 : {
3103 0 : *numCldfbAnalyses = s_max( MC_PARAMUPMIX_MAX_INPUT_CHANS, *numCldfbAnalyses );
3104 0 : move16();
3105 : }
3106 : ELSE
3107 : {
3108 0 : *numCldfbAnalyses = s_max( MC_PARAMUPMIX_MIN_CLDFB, *numCldfbAnalyses );
3109 0 : move16();
3110 : }
3111 0 : *numCldfbSyntheses = s_max( MC_PARAMUPMIX_MIN_CLDFB, *numCldfbSyntheses );
3112 0 : move16();
3113 : }
3114 :
3115 4269 : return;
3116 : }
3117 :
3118 :
3119 : /*---------------------------------------------------------------------*
3120 : * doSanityChecks_IVAS()
3121 : *
3122 : * Sanity checks - verify if the decoder set-up parameters are
3123 : * not in conflict with the IVAS format
3124 : *---------------------------------------------------------------------*/
3125 :
3126 597 : static ivas_error doSanityChecks_IVAS(
3127 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
3128 : )
3129 : {
3130 : Word32 output_Fs;
3131 : AUDIO_CONFIG output_config;
3132 :
3133 597 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
3134 597 : move32();
3135 597 : output_config = st_ivas->hDecoderConfig->output_config;
3136 597 : move32();
3137 : /*-----------------------------------------------------------------*
3138 : * Sanity checks
3139 : *-----------------------------------------------------------------*/
3140 :
3141 597 : IF( EQ_32( output_Fs, 8000 ) )
3142 : {
3143 0 : return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "8kHz output sampling rate is not supported in IVAS." );
3144 : }
3145 :
3146 597 : assert( st_ivas->ivas_format != UNDEFINED_FORMAT && "\n IVAS format undefined" );
3147 597 : assert( st_ivas->ivas_format != MONO_FORMAT && "\n Wrong IVAS format: MONO" );
3148 :
3149 : /* Verify output configuration compatible with non-diegetic panning */
3150 597 : test();
3151 597 : test();
3152 597 : IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan && NE_32( st_ivas->ivas_format, MONO_FORMAT ) && NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_ISM1 ) )
3153 : {
3154 0 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Error: Non-diegetic panning not supported in this IVAS format" );
3155 : }
3156 :
3157 : /* Verify stereo output configuration */
3158 597 : IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
3159 : {
3160 68 : test();
3161 68 : test();
3162 68 : test();
3163 68 : test();
3164 68 : test();
3165 68 : test();
3166 68 : test();
3167 68 : IF( NE_32( output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
3168 : {
3169 1 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Wrong output configuration specified for Stereo!" );
3170 : }
3171 : }
3172 529 : ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
3173 : {
3174 : /* Verify ISM output configuration */
3175 67 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) )
3176 : {
3177 0 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for ISM" );
3178 : }
3179 : }
3180 462 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
3181 : {
3182 : /* Verify SBA output coniguration */
3183 243 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) )
3184 : {
3185 0 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for SBA" );
3186 : }
3187 : }
3188 219 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
3189 : {
3190 80 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) )
3191 : {
3192 0 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for MASA!" );
3193 : }
3194 : }
3195 139 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
3196 : {
3197 : /* Verify MC output configuration */
3198 76 : test();
3199 76 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
3200 : {
3201 4 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for Multi-channel" );
3202 : }
3203 : }
3204 :
3205 :
3206 592 : IF( st_ivas->hDecoderConfig->Opt_Headrotation )
3207 : {
3208 80 : test();
3209 80 : test();
3210 80 : IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) )
3211 : {
3212 0 : return IVAS_ERROR( IVAS_ERR_HEAD_ROTATION_NOT_SUPPORTED, "Wrong set-up: Head-rotation not supported in this configuration" );
3213 : }
3214 : }
3215 :
3216 592 : IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation )
3217 : {
3218 31 : test();
3219 31 : test();
3220 31 : IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) )
3221 : {
3222 0 : return IVAS_ERROR( IVAS_ERR_EXT_ORIENTATION_NOT_SUPPORTED, "Wrong set-up: External orientation not supported in this configuration" );
3223 : }
3224 : }
3225 :
3226 592 : IF( st_ivas->hDecoderConfig->Opt_dpid_on )
3227 : {
3228 1 : test();
3229 1 : IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) )
3230 : {
3231 0 : return IVAS_ERROR( IVAS_ERR_DIRECTIVITY_NOT_SUPPORTED, "Wrong set-up: Directivity is not supported in this output configuration." );
3232 : }
3233 : }
3234 :
3235 592 : IF( st_ivas->hDecoderConfig->Opt_aeid_on )
3236 : {
3237 0 : IF( NE_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
3238 : {
3239 0 : return IVAS_ERROR( IVAS_ERR_ACOUSTIC_ENVIRONMENT_NOT_SUPPORTED, "Wrong set-up: Acoustic environment is not supported in this output configuration." );
3240 : }
3241 : }
3242 :
3243 592 : IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
3244 : {
3245 33 : test();
3246 33 : IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
3247 : {
3248 :
3249 1 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for combined MASA and ISM format" );
3250 : }
3251 : }
3252 :
3253 :
3254 591 : return IVAS_ERR_OK;
3255 : }
|