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 : #ifdef NONBE_FIX_1052_SBA_EXT
56 : #ifdef NONBE_FIX_1128_OSBA_EXT_OUTPUT_ORDER
57 : static AUDIO_CONFIG ivas_set_audio_config_from_sba_order( const Word16 sba_order );
58 : #else
59 : static AUDIO_CONFIG ivas_set_output_config_from_sba_order( const Word16 sba_order );
60 : #endif
61 : #endif
62 :
63 :
64 : #ifdef NONBE_FIX_1052_SBA_EXT
65 : #ifdef NONBE_FIX_1128_OSBA_EXT_OUTPUT_ORDER
66 : /*-------------------------------------------------------------------*
67 : * ivas_set_audio_config_from_sba_order()
68 : *
69 : *
70 : *-------------------------------------------------------------------*/
71 :
72 : /*! r: audio configuration */
73 18 : static AUDIO_CONFIG ivas_set_audio_config_from_sba_order(
74 : const Word16 sba_order /* i : Ambisonic (SBA) order */
75 : )
76 : #else
77 : static AUDIO_CONFIG ivas_set_output_config_from_sba_order( const Word16 sba_order )
78 : #endif
79 : {
80 : AUDIO_CONFIG output_config;
81 :
82 18 : output_config = IVAS_AUDIO_CONFIG_HOA3;
83 18 : move32();
84 :
85 18 : SWITCH( sba_order )
86 : {
87 6 : case SBA_FOA_ORDER:
88 6 : output_config = IVAS_AUDIO_CONFIG_FOA;
89 6 : move32();
90 6 : BREAK;
91 4 : case SBA_HOA2_ORDER:
92 4 : output_config = IVAS_AUDIO_CONFIG_HOA2;
93 4 : move32();
94 4 : BREAK;
95 8 : case SBA_HOA3_ORDER:
96 8 : output_config = IVAS_AUDIO_CONFIG_HOA3;
97 8 : move32();
98 8 : BREAK;
99 0 : default:
100 : #ifdef NONBE_FIX_1128_OSBA_EXT_OUTPUT_ORDER
101 0 : output_config = IVAS_AUDIO_CONFIG_INVALID;
102 0 : move32();
103 0 : BREAK;
104 : #else
105 : assert( 0 );
106 : #endif
107 : }
108 :
109 18 : return output_config;
110 : }
111 : #endif
112 :
113 :
114 : #ifdef FIX_1209_SID_SIGNALING
115 : /*---------------------------------------------------------------------*
116 : * ivas_dec_get_format( )
117 : *
118 : * Read main parameters from the bitstream to set-up the decoder:
119 : * - IVAS format
120 : * - IVAS format specific signaling
121 : *---------------------------------------------------------------------*/
122 :
123 0 : ivas_error ivas_dec_get_format_fx(
124 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
125 : )
126 : {
127 : Word16 k, idx, num_bits_read;
128 : Word16 nchan_ism, element_mode_flag;
129 : Word16 sba_order, sba_planar, sba_analysis_order;
130 : Word32 ivas_total_brate;
131 : UWord16 *bit_stream_orig;
132 : AUDIO_CONFIG signaled_config;
133 : ivas_error error;
134 :
135 0 : num_bits_read = 0;
136 0 : move16();
137 0 : element_mode_flag = 0;
138 0 : move16();
139 :
140 0 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
141 0 : move32();
142 0 : bit_stream_orig = st_ivas->bit_stream;
143 :
144 : /*-------------------------------------------------------------------*
145 : * Read IVAS format
146 : *-------------------------------------------------------------------*/
147 :
148 0 : IF( ( error = ivas_read_format( st_ivas, &num_bits_read ) ) != IVAS_ERR_OK )
149 : {
150 0 : return error;
151 : }
152 :
153 0 : test();
154 0 : test();
155 0 : test();
156 0 : test();
157 0 : test();
158 0 : IF( st_ivas->ini_frame > 0 && NE_32( st_ivas->ivas_format, st_ivas->last_ivas_format ) &&
159 : !( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && EQ_32( st_ivas->last_ivas_format, MASA_ISM_FORMAT ) ) &&
160 : !( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->last_ivas_format, MASA_FORMAT ) ) )
161 : {
162 : #ifdef DEBUGGING
163 : fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" );
164 : #endif
165 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" );
166 : }
167 :
168 : /*-------------------------------------------------------------------*
169 : * Read other signaling (ISM/MC mode, number of channels, etc.)
170 : *-------------------------------------------------------------------*/
171 :
172 0 : k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
173 :
174 0 : IF( is_DTXrate( ivas_total_brate ) == 0 )
175 : {
176 : /*-------------------------------------------------------------------*
177 : * Read IVAS format related signaling:
178 : * - in ISM : read number of objects
179 : * - in SBA : read SBA planar flag and SBA order
180 : * - in MASA : read number of TC
181 : * - in MC : read LS setup
182 : *-------------------------------------------------------------------*/
183 :
184 0 : IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
185 : {
186 0 : element_mode_flag = 1;
187 0 : move16();
188 : }
189 0 : ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
190 : {
191 : /* read the number of objects */
192 0 : nchan_ism = 1;
193 0 : move16();
194 0 : WHILE( st_ivas->bit_stream[k - 1] && nchan_ism < MAX_NUM_OBJECTS )
195 : {
196 0 : nchan_ism = add( nchan_ism, 1 );
197 0 : k = sub( k, 1 );
198 : }
199 :
200 0 : test();
201 0 : IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) )
202 : {
203 : #ifdef DEBUGGING
204 : fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" );
205 : #endif
206 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" );
207 : }
208 :
209 0 : st_ivas->nchan_ism = nchan_ism;
210 0 : move16();
211 0 : st_ivas->ism_mode = ivas_ism_mode_select( nchan_ism, ivas_total_brate );
212 :
213 0 : st_ivas->nchan_transport = nchan_ism;
214 0 : move16();
215 0 : if ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
216 : {
217 0 : st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE;
218 0 : move16();
219 : }
220 : }
221 0 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
222 : {
223 : /* read Ambisonic (SBA) planar flag */
224 0 : sba_planar = st_ivas->bit_stream[num_bits_read];
225 0 : num_bits_read = add( num_bits_read, SBA_PLANAR_BITS );
226 :
227 0 : test();
228 0 : IF( st_ivas->ini_frame > 0 && NE_16( sba_planar, st_ivas->sba_planar ) )
229 : {
230 : #ifdef DEBUGGING
231 : fprintf( stderr, "\nError: Changing the SBA planar/3D layout is not supported!\n" );
232 : #endif
233 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA planar flag signalled!" );
234 : }
235 :
236 : /* read Ambisonic (SBA) order */
237 0 : sba_order = st_ivas->bit_stream[num_bits_read + 1];
238 0 : move16();
239 0 : sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) );
240 :
241 0 : test();
242 0 : IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) )
243 : {
244 : #ifdef DEBUGGING
245 : fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" );
246 : #endif
247 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" );
248 : }
249 :
250 0 : sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, sba_order );
251 0 : st_ivas->nchan_transport = ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_analysis_order );
252 : }
253 0 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
254 : {
255 : /* read number of MASA transport channels */
256 0 : IF( st_ivas->bit_stream[k - 1] )
257 : {
258 0 : st_ivas->nchan_transport = 2;
259 0 : move16();
260 0 : element_mode_flag = 1;
261 0 : move16();
262 : }
263 : ELSE
264 : {
265 0 : st_ivas->nchan_transport = 1;
266 0 : move16();
267 : }
268 :
269 : /* this should be non-zero if original input format was MASA_ISM_FORMAT */
270 0 : st_ivas->ism_mode = ISM_MODE_NONE;
271 0 : move16();
272 0 : nchan_ism = st_ivas->bit_stream[k - 3] + shl( st_ivas->bit_stream[k - 2], 1 );
273 :
274 0 : IF( nchan_ism > 0 )
275 : {
276 : /* the input_ivas_format should be MASA_ISM_FORMAT, but we cannot initialize it now */
277 : /* info about the number of objects:
278 : '00' - MASA format at the encoder
279 : '01' - MASA_ISM_FORMAT at the encoder, with 4 objects
280 : '10' - MASA_ISM_FORMAT at the encoder, with 3 objects
281 : '11' - MASA_ISM_FORMAT at the encoder, with 1 or 2 objects
282 : reading if 1 or 2 objects is performed later
283 : */
284 0 : nchan_ism = sub( 5, nchan_ism );
285 0 : test();
286 0 : IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( st_ivas->nchan_ism, 2 ) )
287 : {
288 0 : st_ivas->nchan_ism = 1;
289 0 : move16();
290 : }
291 :
292 : /* for MASA_ISM_FORMAT at input the number of MASA transport channels is always 2 and the corresponding bit is not used here*/
293 0 : st_ivas->nchan_transport = 2;
294 0 : move16();
295 0 : element_mode_flag = 1;
296 0 : move16();
297 : }
298 :
299 0 : test();
300 0 : IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) )
301 : {
302 : #ifdef DEBUGGING
303 : fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" );
304 : #endif
305 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" );
306 : }
307 :
308 0 : st_ivas->nchan_ism = nchan_ism;
309 0 : move16();
310 : }
311 0 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
312 : {
313 0 : st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */
314 0 : move16();
315 :
316 : /* the number of objects are written at the end of the bitstream */
317 0 : nchan_ism = add( add( shl( st_ivas->bit_stream[k - 1], 1 ), st_ivas->bit_stream[k - 2] ), 1 );
318 0 : st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, nchan_ism );
319 :
320 0 : test();
321 0 : IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) )
322 : {
323 : #ifdef DEBUGGING
324 : fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" );
325 : #endif
326 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" );
327 : }
328 :
329 0 : st_ivas->nchan_ism = nchan_ism;
330 0 : move16();
331 : }
332 0 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
333 : {
334 : /* the number of objects is written at the end of the bitstream, in the SBA metadata */
335 0 : nchan_ism = add( add( shl( st_ivas->bit_stream[k - 1], 1 ), st_ivas->bit_stream[k - 2] ), 1 );
336 :
337 0 : test();
338 0 : IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) )
339 : {
340 : #ifdef DEBUGGING
341 : fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" );
342 : #endif
343 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" );
344 : }
345 :
346 0 : st_ivas->nchan_ism = nchan_ism;
347 0 : move16();
348 :
349 : /* read Ambisonic (SBA) planar flag */
350 : /*sba_planar = st_ivas->bit_stream[num_bits_read];*/
351 0 : num_bits_read = add( num_bits_read, SBA_PLANAR_BITS );
352 :
353 : /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/
354 0 : sba_order = st_ivas->bit_stream[num_bits_read + 1];
355 0 : move16();
356 0 : sba_order = shl( st_ivas->bit_stream[num_bits_read], 1 );
357 0 : num_bits_read = add( num_bits_read, SBA_ORDER_BITS );
358 :
359 : /* read the real Ambisonic order when the above bits are used to signal OSBA format */
360 0 : IF( LT_32( ivas_total_brate, IVAS_24k4 ) )
361 : {
362 0 : sba_order = st_ivas->bit_stream[num_bits_read + 1];
363 0 : move16();
364 0 : sba_order = shl( st_ivas->bit_stream[num_bits_read], 1 );
365 0 : num_bits_read = add( num_bits_read, SBA_ORDER_BITS );
366 : }
367 :
368 0 : test();
369 0 : IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) )
370 : {
371 : #ifdef DEBUGGING
372 : fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" );
373 : #endif
374 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" );
375 : }
376 :
377 0 : st_ivas->ism_mode = ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism );
378 :
379 0 : sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, sba_order );
380 0 : st_ivas->nchan_transport = ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_analysis_order );
381 : }
382 0 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
383 : {
384 : /* read MC configuration */
385 0 : idx = 0;
386 0 : move16();
387 0 : FOR( k = 0; k < MC_LS_SETUP_BITS; k++ )
388 : {
389 0 : IF( st_ivas->bit_stream[num_bits_read + k] )
390 : {
391 0 : idx = add( idx, shl( 1, sub( ( MC_LS_SETUP_BITS - 1 ), k ) ) );
392 : }
393 : }
394 0 : num_bits_read = add( num_bits_read, MC_LS_SETUP_BITS );
395 :
396 0 : signaled_config = ivas_mc_map_ls_setup_to_output_config_fx( idx );
397 :
398 0 : test();
399 0 : IF( st_ivas->ini_frame > 0 && NE_32( st_ivas->transport_config, signaled_config ) )
400 : {
401 : #ifdef DEBUGGING
402 : fprintf( stderr, "\nError: Switching of MC configurations is not supported!\n" );
403 : #endif
404 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong MC configuration signalled!" );
405 : }
406 :
407 0 : st_ivas->mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( signaled_config ), st_ivas->hDecoderConfig->ivas_total_brate );
408 0 : st_ivas->transport_config = signaled_config;
409 0 : move16();
410 : }
411 :
412 : /*-------------------------------------------------------------------*
413 : * Read element mode
414 : *-------------------------------------------------------------------*/
415 :
416 0 : test();
417 0 : IF( st_ivas->ini_frame == 0 && element_mode_flag )
418 : {
419 : /* read stereo technology info */
420 0 : if ( LT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) )
421 : {
422 : /* 1 bit */
423 0 : IF( st_ivas->bit_stream[num_bits_read] )
424 : {
425 0 : st_ivas->element_mode_init = add( 1, IVAS_CPE_DFT );
426 : }
427 : ELSE
428 : {
429 0 : st_ivas->element_mode_init = add( 0, IVAS_CPE_DFT );
430 : }
431 : }
432 : ELSE
433 : {
434 0 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
435 0 : move16();
436 : }
437 : }
438 : }
439 0 : ELSE IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
440 : {
441 0 : SWITCH( st_ivas->sid_format )
442 : {
443 0 : case SID_DFT_STEREO:
444 0 : st_ivas->element_mode_init = IVAS_CPE_DFT;
445 0 : move16();
446 0 : BREAK;
447 0 : case SID_MDCT_STEREO:
448 0 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
449 0 : move16();
450 0 : BREAK;
451 0 : case SID_ISM:
452 0 : st_ivas->element_mode_init = IVAS_SCE;
453 0 : move16();
454 0 : BREAK;
455 0 : case SID_MASA_1TC:
456 0 : st_ivas->element_mode_init = IVAS_SCE;
457 0 : move16();
458 0 : st_ivas->nchan_transport = 1;
459 0 : move16();
460 0 : BREAK;
461 0 : case SID_MASA_2TC:
462 0 : IF( st_ivas->bit_stream[k - 1 - SID_FORMAT_NBITS] == 1 )
463 : {
464 0 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
465 0 : move16();
466 : }
467 : ELSE
468 : {
469 0 : st_ivas->element_mode_init = IVAS_CPE_DFT;
470 0 : move16();
471 : }
472 0 : st_ivas->nchan_transport = 2;
473 0 : move16();
474 0 : BREAK;
475 0 : case SID_SBA_1TC:
476 0 : st_ivas->element_mode_init = IVAS_SCE;
477 0 : move16();
478 0 : BREAK;
479 0 : case SID_SBA_2TC:
480 0 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
481 0 : move16();
482 0 : BREAK;
483 : }
484 :
485 0 : if ( st_ivas->ivas_format == ISM_FORMAT )
486 : {
487 : /* read the number of objects */
488 0 : nchan_ism = 1;
489 0 : move16();
490 0 : WHILE( st_ivas->bit_stream[k - 1 - SID_FORMAT_NBITS] && nchan_ism < MAX_NUM_OBJECTS )
491 : {
492 0 : nchan_ism = add( nchan_ism, 1 );
493 0 : k = sub( k, 1 );
494 : }
495 0 : k = sub( k, 1 );
496 :
497 0 : test();
498 0 : IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) )
499 : {
500 : #ifdef DEBUGGING
501 : fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" );
502 : #endif
503 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" );
504 : }
505 :
506 0 : st_ivas->nchan_ism = nchan_ism;
507 0 : move16();
508 :
509 : /* read ism_mode */
510 0 : st_ivas->ism_mode = ISM_MODE_DISC;
511 0 : move32();
512 0 : IF( GT_16( nchan_ism, 2 ) )
513 : {
514 0 : k = sub( k, nchan_ism ); /* SID metadata flags */
515 0 : idx = st_ivas->bit_stream[k];
516 0 : move16();
517 0 : st_ivas->ism_mode = (ISM_MODE) add( idx, 1 );
518 0 : move32();
519 : }
520 :
521 0 : st_ivas->nchan_transport = nchan_ism;
522 0 : move16();
523 0 : if ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
524 : {
525 0 : st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE;
526 0 : move16();
527 : }
528 : }
529 : }
530 :
531 0 : st_ivas->bit_stream = bit_stream_orig;
532 :
533 0 : return IVAS_ERR_OK;
534 : }
535 : #endif
536 :
537 :
538 : /*-------------------------------------------------------------------*
539 : * ivas_dec_setup()
540 : *
541 : * IVAS decoder setup
542 : *-------------------------------------------------------------------*/
543 :
544 400461 : ivas_error ivas_dec_setup(
545 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
546 : UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */
547 : Word16 *data /* o : output synthesis signal */
548 : )
549 : {
550 : Word16 k, idx, num_bits_read;
551 : Word16 nchan_ism, element_mode_flag;
552 : Decoder_State *st;
553 : Word32 ivas_total_brate;
554 : ivas_error error;
555 : Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
556 400461 : Word16 num_src = 0;
557 400461 : move16();
558 :
559 400461 : error = IVAS_ERR_OK;
560 400461 : move32();
561 400461 : num_bits_read = 0;
562 400461 : move16();
563 400461 : element_mode_flag = 0;
564 400461 : move16();
565 :
566 400461 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
567 400461 : move32();
568 :
569 : /*-------------------------------------------------------------------*
570 : * Read IVAS format
571 : *-------------------------------------------------------------------*/
572 :
573 : #ifdef FIX_1209_SID_SIGNALING
574 400461 : IF( ( error = ivas_read_format( st_ivas, &num_bits_read ) ) != IVAS_ERR_OK )
575 : {
576 0 : return error;
577 : }
578 : #else
579 : ivas_read_format( st_ivas, &num_bits_read );
580 : #endif
581 :
582 : /*-------------------------------------------------------------------*
583 : * Read other signling (ISM/MC mode, number of channels, etc.)
584 : *-------------------------------------------------------------------*/
585 :
586 400461 : IF( is_DTXrate( ivas_total_brate ) == 0 )
587 : {
588 : /*-------------------------------------------------------------------*
589 : * Read IVAS format related signaling:
590 : * - in ISM : read number of objects
591 : * - in SBA : read SBA planar flag and SBA order
592 : * - in MASA : read number of TC
593 : * - in MC : read LS setup
594 : *-------------------------------------------------------------------*/
595 :
596 381710 : IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
597 : {
598 58715 : element_mode_flag = 1;
599 58715 : move16();
600 : }
601 322995 : ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
602 : {
603 : /* read the number of objects */
604 91951 : st_ivas->nchan_transport = 1;
605 91951 : move16();
606 91951 : nchan_ism = 1;
607 91951 : move16();
608 : Word32 res_dec, res_frac;
609 91951 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
610 91951 : k = extract_l( L_sub( res_dec, 1 ) );
611 :
612 262757 : WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) )
613 : {
614 170806 : nchan_ism = add( nchan_ism, 1 );
615 170806 : k = sub( k, 1 );
616 : }
617 :
618 91951 : st_ivas->nchan_ism = nchan_ism;
619 91951 : move16();
620 :
621 91951 : IF( NE_32( ( error = ivas_ism_dec_config_fx( st_ivas, st_ivas->ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
622 : {
623 0 : return error;
624 : }
625 : }
626 231044 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
627 : {
628 : /* read Ambisonic (SBA) planar flag */
629 111624 : st_ivas->sba_planar = st_ivas->bit_stream[num_bits_read];
630 111624 : move16();
631 111624 : num_bits_read = add( num_bits_read, SBA_PLANAR_BITS );
632 :
633 : /* read Ambisonic (SBA) order */
634 111624 : st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1];
635 111624 : move16();
636 111624 : st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) );
637 111624 : move16();
638 : #ifndef NONBE_FIX_1052_SBA_EXT_FIX
639 : #ifdef NONBE_FIX_1052_SBA_EXT
640 : IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
641 : {
642 : #ifdef NONBE_FIX_1128_OSBA_EXT_OUTPUT_ORDER
643 : st_ivas->hDecoderConfig->output_config = ivas_set_audio_config_from_sba_order( st_ivas->sba_order );
644 : #else
645 : st_ivas->hDecoderConfig->output_config = ivas_set_output_config_from_sba_order( st_ivas->sba_order );
646 : #endif
647 : st_ivas->hDecoderConfig->nchan_out = audioCfg2channels( st_ivas->hDecoderConfig->output_config );
648 : }
649 : #endif
650 : #endif
651 111624 : num_bits_read = add( num_bits_read, SBA_ORDER_BITS );
652 :
653 111624 : test();
654 111624 : test();
655 111624 : 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 ) )
656 : {
657 1020 : IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
658 : {
659 0 : return error;
660 : }
661 : }
662 : ELSE
663 : {
664 : /* set Ambisonic (SBA) order used for analysis and coding */
665 110604 : st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order );
666 110604 : move16();
667 110604 : 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 );
668 : }
669 : }
670 119420 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
671 : {
672 : /* read number of MASA transport channels */
673 : Word32 res_dec, res_frac;
674 30644 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
675 30644 : IF( st_ivas->bit_stream[res_dec - 1] )
676 : {
677 16012 : st_ivas->nchan_transport = 2;
678 16012 : move16();
679 16012 : element_mode_flag = 1;
680 16012 : move16();
681 : }
682 : ELSE
683 : {
684 14632 : st_ivas->nchan_transport = 1;
685 14632 : move16();
686 : }
687 : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
688 : /* this should be non-zero if original input format was MASA_ISM_FORMAT */
689 30644 : st_ivas->nchan_ism = add( st_ivas->bit_stream[L_sub( res_dec, 3 )], shl( st_ivas->bit_stream[L_sub( res_dec, 2 )], 1 ) );
690 :
691 30644 : IF( GT_16( st_ivas->nchan_ism, 0 ) )
692 : {
693 : #ifdef NONBE_FIX_1074_NOBJ_SIGNAL_OMASA_LBR
694 : /* the input_ivas_format should be MASA_ISM_FORMAT, but we cannot initialize it now */
695 : /* info about the number of objects:
696 : '00' - MASA format at the encoder
697 : '01' - MASA_ISM_FORMAT at the encoder, with 4 objects
698 : '10' - MASA_ISM_FORMAT at the encoder, with 3 objects
699 : '11' - MASA_ISM_FORMAT at the encoder, with 1 or 2 objects
700 : reading if 1 or 2 objects is performed later
701 : */
702 1859 : st_ivas->nchan_ism = sub( 5, st_ivas->nchan_ism );
703 :
704 1859 : test();
705 1859 : IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( st_ivas->nchan_ism, 2 ) )
706 : {
707 221 : st_ivas->nchan_ism = 1;
708 221 : move16();
709 : }
710 :
711 : /* for MASA_ISM_FORMAT at input the number of MASA transport channels is always 2 and the corresponding bit is not used here*/
712 : #else
713 : /* the input_ivas_format should be MASA_ISM_FORMAT, but we cannot initialize it now */
714 : test();
715 : IF( EQ_16( st_ivas->nchan_transport, 2 ) && EQ_16( st_ivas->nchan_ism, 3 ) )
716 : {
717 : st_ivas->nchan_ism = 4;
718 : move16();
719 : }
720 : /* for MASA_ISM_FORMAT at input the number of MASA transport channels is always 2 */
721 : #endif
722 1859 : st_ivas->nchan_transport = 2;
723 1859 : element_mode_flag = 1;
724 1859 : move16();
725 1859 : move16();
726 : }
727 : #endif
728 :
729 30644 : IF( st_ivas->ini_frame > 0 )
730 : {
731 : /* reconfigure in case a change of operation mode is detected */
732 30562 : test();
733 30562 : test();
734 30562 : 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 ) )
735 : {
736 1731 : IF( EQ_32( st_ivas->last_ivas_format, MASA_FORMAT ) )
737 : {
738 1318 : test();
739 1318 : test();
740 1318 : test();
741 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 ) )
742 : {
743 0 : st_ivas->hCPE[0]->nchan_out = 1;
744 0 : move16();
745 : }
746 : ELSE
747 : {
748 1318 : IF( NE_32( ( error = ivas_masa_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
749 : {
750 0 : return error;
751 : }
752 : }
753 : }
754 : ELSE
755 : {
756 413 : IF( NE_32( ( error = ivas_omasa_dec_config_fx( st_ivas, nSamplesRendered, &num_src, SrcInd, data ) ), IVAS_ERR_OK ) )
757 : {
758 0 : return error;
759 : }
760 : }
761 : }
762 : }
763 : }
764 88776 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
765 : {
766 6423 : st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */
767 6423 : move16();
768 :
769 : /* for the DISC mode the number of objects are written at the end of the bitstream, in the MASA metadata */
770 : Word32 res_dec, res_frac;
771 6423 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
772 6423 : st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[res_dec - 1], 1 ), st_ivas->bit_stream[res_dec - 2] ), 1 );
773 6423 : move16();
774 6423 : st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, st_ivas->nchan_ism );
775 6423 : move16();
776 6423 : IF( st_ivas->ini_frame > 0 )
777 : {
778 : /* reconfigure in case a change of operation mode is detected */
779 6390 : test();
780 6390 : test();
781 6390 : 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 ) )
782 : {
783 1121 : IF( NE_32( ( error = ivas_omasa_dec_config_fx( st_ivas, nSamplesRendered, &num_src, SrcInd, data ) ), IVAS_ERR_OK ) )
784 : {
785 0 : return error;
786 : }
787 : }
788 : }
789 : }
790 82353 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
791 : {
792 : /* the number of objects is written at the end of the bitstream, in the SBA metadata */
793 : Word32 res_dec, res_frac;
794 33885 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
795 33885 : st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[res_dec - 1], 1 ), st_ivas->bit_stream[res_dec - 2] ), 1 );
796 33885 : move16();
797 :
798 : /* read Ambisonic (SBA) planar flag */
799 33885 : st_ivas->sba_planar = st_ivas->bit_stream[num_bits_read];
800 33885 : move16();
801 33885 : num_bits_read = add( num_bits_read, SBA_PLANAR_BITS );
802 :
803 : /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/
804 33885 : st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1];
805 33885 : move16();
806 33885 : st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) );
807 33885 : move16();
808 33885 : num_bits_read = add( num_bits_read, SBA_ORDER_BITS );
809 :
810 : /* read Ambisonic (SBA) order */
811 : /* read the real Ambisonic order when the above bits are used to signal OSBA format */
812 33885 : IF( LT_32( ivas_total_brate, IVAS_24k4 ) )
813 : {
814 2641 : st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1];
815 2641 : move16();
816 2641 : st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) );
817 2641 : num_bits_read = add( num_bits_read, SBA_ORDER_BITS );
818 : }
819 :
820 33885 : test();
821 33885 : IF( st_ivas->ini_frame > 0 && NE_32( ivas_total_brate, st_ivas->last_active_ivas_total_brate ) )
822 : {
823 562 : IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
824 : {
825 0 : return error;
826 : }
827 : }
828 : ELSE
829 : {
830 : /* set Ambisonic (SBA) order used for analysis and coding */
831 33323 : st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order );
832 33323 : move16();
833 :
834 33323 : 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 );
835 :
836 : /*correct number of CPEs for discrete ISM coding*/
837 33323 : test();
838 33323 : IF( st_ivas->ini_frame > 0 && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
839 : #ifdef NONBE_FIX_ISM_XOVER_BR
840 : {
841 : Word16 n;
842 :
843 19397 : n = add( st_ivas->nchan_transport, st_ivas->nchan_ism );
844 19397 : st_ivas->nCPE = shr_r( n, 1 );
845 : }
846 : #else
847 : {
848 : st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) );
849 : move16();
850 : }
851 : #endif
852 : }
853 :
854 : #ifdef NONBE_FIX_ISM_XOVER_BR
855 33885 : IF( EQ_16( ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ), ISM_SBA_MODE_DISC ) )
856 : #else
857 : IF( GE_32( ivas_total_brate, IVAS_256k ) )
858 : #endif
859 : {
860 19633 : st_ivas->ism_mode = ISM_SBA_MODE_DISC;
861 19633 : move32();
862 : }
863 : ELSE
864 : {
865 14252 : st_ivas->ism_mode = ISM_MODE_NONE;
866 14252 : move32();
867 : }
868 : }
869 48468 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
870 : {
871 : /* read MC configuration */
872 48468 : idx = 0;
873 48468 : move16();
874 193872 : FOR( k = 0; k < MC_LS_SETUP_BITS; k++ )
875 : {
876 145404 : IF( st_ivas->bit_stream[num_bits_read + k] )
877 : {
878 6570 : idx = add( idx, shl( 1, sub( ( MC_LS_SETUP_BITS - 1 ), k ) ) );
879 : }
880 : }
881 48468 : num_bits_read = add( num_bits_read, MC_LS_SETUP_BITS );
882 :
883 : /* select MC format mode; reconfigure the MC format decoder */
884 48468 : IF( NE_32( ( error = ivas_mc_dec_config_fx( st_ivas, idx, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
885 : {
886 0 : return error;
887 : }
888 : }
889 :
890 : /*-------------------------------------------------------------------*
891 : * Read element mode
892 : *-------------------------------------------------------------------*/
893 :
894 381710 : IF( st_ivas->ini_frame == 0 && element_mode_flag )
895 : {
896 : /* read stereo technology info */
897 119 : IF( LT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) )
898 : {
899 : /* 1 bit */
900 79 : IF( st_ivas->bit_stream[num_bits_read] )
901 : {
902 0 : st_ivas->element_mode_init = add( 1, IVAS_CPE_DFT );
903 0 : move16();
904 : }
905 : ELSE
906 : {
907 79 : st_ivas->element_mode_init = add( 0, IVAS_CPE_DFT );
908 79 : move16();
909 : }
910 : }
911 : ELSE
912 : {
913 40 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
914 40 : move16();
915 : }
916 : }
917 : }
918 18751 : ELSE IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
919 : {
920 2907 : SWITCH( st_ivas->sid_format )
921 : {
922 1418 : case SID_DFT_STEREO:
923 1418 : st_ivas->element_mode_init = IVAS_CPE_DFT;
924 1418 : move16();
925 1418 : BREAK;
926 410 : case SID_MDCT_STEREO:
927 410 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
928 410 : move16();
929 410 : BREAK;
930 550 : case SID_ISM:
931 550 : st_ivas->element_mode_init = IVAS_SCE;
932 550 : move16();
933 550 : BREAK;
934 131 : case SID_MASA_1TC:
935 131 : st_ivas->element_mode_init = IVAS_SCE;
936 131 : move16();
937 131 : st_ivas->nchan_transport = 1;
938 131 : move16();
939 131 : BREAK;
940 74 : case SID_MASA_2TC:; // empyt statement for declaration
941 : Word32 res_dec, res_frac;
942 74 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
943 74 : IF( EQ_16( st_ivas->bit_stream[( res_dec - 1 ) - SID_FORMAT_NBITS], 1 ) )
944 : {
945 0 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
946 0 : move16();
947 : }
948 : ELSE
949 : {
950 74 : st_ivas->element_mode_init = IVAS_CPE_DFT;
951 74 : move16();
952 : }
953 74 : st_ivas->nchan_transport = 2;
954 74 : move16();
955 74 : BREAK;
956 157 : case SID_SBA_1TC:
957 157 : st_ivas->element_mode_init = IVAS_SCE;
958 157 : move16();
959 157 : BREAK;
960 167 : case SID_SBA_2TC:
961 167 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
962 167 : move16();
963 167 : BREAK;
964 : }
965 :
966 : #ifndef NONBE_FIX_1052_SBA_EXT_FIX
967 : #ifdef NONBE_FIX_1052_SBA_EXT
968 : IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) && EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
969 : {
970 : #ifdef NONBE_FIX_1128_OSBA_EXT_OUTPUT_ORDER
971 : st_ivas->hDecoderConfig->output_config = ivas_set_audio_config_from_sba_order( st_ivas->sba_order );
972 : #else
973 : st_ivas->hDecoderConfig->output_config = ivas_set_output_config_from_sba_order( st_ivas->sba_order );
974 : #endif
975 : st_ivas->hDecoderConfig->nchan_out = audioCfg2channels( st_ivas->hDecoderConfig->output_config );
976 : }
977 : #endif
978 : #endif
979 2907 : test();
980 2907 : IF( st_ivas->ini_frame > 0 && EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
981 : {
982 : Word16 nchan_transport_old, nchan_transport;
983 324 : nchan_transport_old = st_ivas->nchan_transport;
984 324 : move16();
985 324 : IF( ( EQ_16( st_ivas->sid_format, SID_SBA_2TC ) ) )
986 : {
987 167 : nchan_transport = 2;
988 : }
989 : ELSE
990 : {
991 157 : nchan_transport = 1;
992 : }
993 324 : move16();
994 :
995 324 : IF( NE_16( nchan_transport_old, nchan_transport ) )
996 : {
997 : /*Setting the default bitrate for the reconfig function*/
998 0 : IF( EQ_16( st_ivas->sid_format, SID_SBA_2TC ) )
999 : {
1000 0 : st_ivas->hDecoderConfig->ivas_total_brate = IVAS_48k;
1001 0 : move16();
1002 : }
1003 : ELSE
1004 : {
1005 0 : st_ivas->hDecoderConfig->ivas_total_brate = IVAS_24k4;
1006 0 : move16();
1007 : }
1008 :
1009 0 : IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
1010 : {
1011 0 : return error;
1012 : }
1013 :
1014 0 : st_ivas->last_active_ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
1015 0 : move32();
1016 0 : st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate;
1017 0 : move32();
1018 : }
1019 : }
1020 :
1021 2907 : IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
1022 : {
1023 550 : ISM_MODE last_ism_mode = st_ivas->ism_mode;
1024 550 : move32();
1025 : /* read the number of objects */
1026 550 : st_ivas->nchan_transport = 1;
1027 550 : move16();
1028 550 : nchan_ism = 1;
1029 550 : move16();
1030 : Word32 res_dec, res_frac;
1031 550 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
1032 550 : k = extract_l( L_sub( L_sub( res_dec, 1 ), SID_FORMAT_NBITS ) );
1033 550 : move16();
1034 :
1035 1816 : WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) )
1036 : {
1037 1266 : nchan_ism = add( nchan_ism, 1 );
1038 1266 : k = sub( k, 1 );
1039 : }
1040 550 : k = sub( k, 1 );
1041 :
1042 550 : test();
1043 550 : IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) )
1044 : {
1045 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong number of objects signalled!" );
1046 : }
1047 :
1048 550 : st_ivas->nchan_ism = nchan_ism;
1049 550 : move16();
1050 :
1051 : /* read ism_mode */
1052 550 : st_ivas->ism_mode = ISM_MODE_DISC;
1053 550 : move32();
1054 550 : IF( GT_16( nchan_ism, 2 ) )
1055 : {
1056 385 : k = sub( k, nchan_ism ); /* SID metadata flags */
1057 385 : idx = st_ivas->bit_stream[k];
1058 385 : move16();
1059 385 : st_ivas->ism_mode = (ISM_MODE) add( idx, 1 );
1060 385 : move32();
1061 : }
1062 :
1063 550 : if ( st_ivas->ini_frame == 0 )
1064 : {
1065 0 : last_ism_mode = st_ivas->ism_mode;
1066 0 : move32();
1067 : }
1068 :
1069 550 : IF( NE_32( ( error = ivas_ism_dec_config_fx( st_ivas, last_ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
1070 : {
1071 0 : return error;
1072 : }
1073 : }
1074 : }
1075 :
1076 : /*-------------------------------------------------------------------*
1077 : * Initialize decoder in the first good frame based on IVAS format
1078 : * and number of transport channels
1079 : *-------------------------------------------------------------------*/
1080 400461 : test();
1081 400461 : IF( st_ivas->ini_frame == 0 && NE_32( st_ivas->ivas_format, UNDEFINED_FORMAT ) )
1082 : {
1083 610 : IF( NE_32( ( error = doSanityChecks_IVAS( st_ivas ) ), IVAS_ERR_OK ) )
1084 : {
1085 0 : return IVAS_ERROR( error, "Sanity checks failed" );
1086 : }
1087 :
1088 610 : IF( NE_32( ( error = ivas_init_decoder_fx( st_ivas ) ), IVAS_ERR_OK ) )
1089 : {
1090 0 : return error;
1091 : }
1092 : }
1093 :
1094 : /*----------------------------------------------------------------*
1095 : * Reset bitstream pointers
1096 : *----------------------------------------------------------------*/
1097 :
1098 400461 : ivas_set_bitstream_pointers( st_ivas );
1099 :
1100 400461 : reset_elements( st_ivas );
1101 :
1102 : /* update bitstream buffer pointer -> take into account already read bits */
1103 400461 : test();
1104 400461 : IF( ( st_ivas->nSCE > 0 ) || ( st_ivas->nCPE > 0 ) )
1105 : {
1106 400461 : IF( st_ivas->nSCE > 0 )
1107 : {
1108 164441 : st = st_ivas->hSCE[0]->hCoreCoder[0];
1109 : }
1110 : ELSE
1111 : {
1112 236020 : st = st_ivas->hCPE[0]->hCoreCoder[0];
1113 : }
1114 400461 : st->next_bit_pos = num_bits_read;
1115 400461 : move16();
1116 400461 : st->total_brate = ACELP_8k00; /* only temporary initialization - this is needed for get_next_indice() in the frame following NO_DATA frame */
1117 400461 : move32();
1118 : }
1119 :
1120 400461 : return error;
1121 : }
1122 :
1123 :
1124 : /*-------------------------------------------------------------------*
1125 : * ivas_read_format()
1126 : *
1127 : * Read IVAS format signaling
1128 : *-------------------------------------------------------------------*/
1129 :
1130 400461 : static ivas_error ivas_read_format(
1131 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
1132 : Word16 *num_bits_read /* o : number of IVAS signaling bits read from the bitstream */
1133 : )
1134 : {
1135 : Word16 k, idx;
1136 : Word32 ivas_total_brate;
1137 : ivas_error error;
1138 :
1139 400461 : error = IVAS_ERR_OK;
1140 400461 : move32();
1141 :
1142 400461 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
1143 400461 : move32();
1144 :
1145 400461 : *num_bits_read = 0;
1146 400461 : move16();
1147 400461 : test();
1148 400461 : test();
1149 400461 : IF( !st_ivas->bfi && is_DTXrate( ivas_total_brate ) == 0 )
1150 : {
1151 : /* read IVAS format */
1152 381710 : k = 0;
1153 381710 : move16();
1154 381710 : if ( st_ivas->bit_stream[*num_bits_read] )
1155 : {
1156 274527 : k = 1;
1157 274527 : move16();
1158 : }
1159 381710 : k = shl( k, 1 );
1160 381710 : ( *num_bits_read ) = add( ( *num_bits_read ), 1 );
1161 381710 : move16();
1162 381710 : if ( st_ivas->bit_stream[*num_bits_read] )
1163 : {
1164 193377 : k = add( k, 1 );
1165 : }
1166 381710 : ( *num_bits_read ) = add( ( *num_bits_read ), 1 );
1167 381710 : move16();
1168 381710 : SWITCH( k )
1169 : {
1170 58715 : case 0:
1171 58715 : st_ivas->ivas_format = STEREO_FORMAT;
1172 58715 : move32();
1173 58715 : BREAK;
1174 48468 : case 1:
1175 48468 : st_ivas->ivas_format = MC_FORMAT;
1176 48468 : move32();
1177 48468 : BREAK;
1178 129618 : case 2:
1179 129618 : st_ivas->ivas_format = ISM_FORMAT;
1180 129618 : move32();
1181 :
1182 129618 : IF( GE_32( ivas_total_brate, IVAS_24k4 ) )
1183 : {
1184 121277 : IF( st_ivas->bit_stream[*num_bits_read] )
1185 : {
1186 37667 : ( *num_bits_read ) = add( ( *num_bits_read ), 1 );
1187 37667 : move16();
1188 37667 : IF( st_ivas->bit_stream[*num_bits_read] )
1189 : {
1190 31244 : st_ivas->ivas_format = SBA_ISM_FORMAT;
1191 31244 : move32();
1192 : }
1193 : ELSE
1194 : {
1195 6423 : st_ivas->ivas_format = MASA_ISM_FORMAT;
1196 6423 : move32();
1197 : }
1198 : }
1199 :
1200 121277 : ( *num_bits_read ) = add( ( *num_bits_read ), 1 );
1201 121277 : move16();
1202 : }
1203 129618 : BREAK;
1204 144909 : case 3:
1205 144909 : IF( st_ivas->bit_stream[*num_bits_read] )
1206 : {
1207 30644 : st_ivas->ivas_format = MASA_FORMAT;
1208 30644 : move32();
1209 : }
1210 : ELSE
1211 : {
1212 114265 : st_ivas->ivas_format = SBA_FORMAT;
1213 114265 : move32();
1214 : /* read Ambisonic (SBA) planar flag */
1215 114265 : st_ivas->sba_planar = st_ivas->bit_stream[( *num_bits_read ) + 1];
1216 114265 : move16();
1217 :
1218 : /* read Ambisonic (SBA) order */
1219 114265 : st_ivas->sba_order = st_ivas->bit_stream[( *num_bits_read ) + 2 + SBA_PLANAR_BITS];
1220 114265 : move16();
1221 114265 : st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[( *num_bits_read ) + 1 + SBA_PLANAR_BITS], 1 ) );
1222 114265 : move16();
1223 114265 : if ( st_ivas->sba_order == 0 )
1224 : {
1225 2641 : st_ivas->ivas_format = SBA_ISM_FORMAT;
1226 2641 : move32();
1227 : }
1228 : }
1229 144909 : ( *num_bits_read ) = add( ( *num_bits_read ), 1 );
1230 144909 : move16();
1231 :
1232 144909 : BREAK;
1233 : }
1234 381710 : }
1235 18751 : ELSE IF( ( st_ivas->bfi == 0 ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
1236 : {
1237 : /* read IVAS format in SID frame */
1238 2907 : idx = 0;
1239 2907 : move16();
1240 11628 : FOR( k = 0; k < SID_FORMAT_NBITS; k++ )
1241 : {
1242 8721 : idx += st_ivas->bit_stream[k] << ( SID_FORMAT_NBITS - 1 - k );
1243 : }
1244 :
1245 2907 : ( *num_bits_read ) = add( *num_bits_read, SID_FORMAT_NBITS );
1246 2907 : move16();
1247 2907 : st_ivas->sid_format = idx;
1248 2907 : move16();
1249 :
1250 2907 : SWITCH( idx )
1251 : {
1252 1828 : case SID_DFT_STEREO:
1253 : case SID_MDCT_STEREO:
1254 1828 : st_ivas->ivas_format = STEREO_FORMAT;
1255 1828 : move32();
1256 1828 : BREAK;
1257 550 : case SID_ISM:
1258 550 : st_ivas->ivas_format = ISM_FORMAT;
1259 550 : move32();
1260 550 : BREAK;
1261 : #ifndef FIX_1209_SID_SIGNALING
1262 : case SID_MULTICHANNEL:
1263 : st_ivas->ivas_format = MC_FORMAT;
1264 : move32();
1265 : BREAK;
1266 : #endif
1267 157 : case SID_SBA_1TC:
1268 157 : st_ivas->ivas_format = SBA_FORMAT;
1269 157 : move32();
1270 157 : st_ivas->element_mode_init = IVAS_SCE;
1271 157 : move16();
1272 157 : BREAK;
1273 167 : case SID_SBA_2TC:
1274 167 : st_ivas->ivas_format = SBA_FORMAT;
1275 167 : move32();
1276 167 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
1277 167 : move16();
1278 167 : BREAK;
1279 131 : case SID_MASA_1TC:
1280 131 : st_ivas->ivas_format = MASA_FORMAT;
1281 131 : move32();
1282 131 : st_ivas->element_mode_init = IVAS_SCE;
1283 131 : move16();
1284 131 : BREAK;
1285 74 : case SID_MASA_2TC:
1286 74 : st_ivas->ivas_format = MASA_FORMAT;
1287 74 : move32();
1288 : Word32 res_dec, res_frac;
1289 74 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 );
1290 74 : IF( EQ_32( st_ivas->bit_stream[res_dec - 1], 1 ) )
1291 : {
1292 0 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
1293 0 : move16();
1294 : }
1295 : ELSE
1296 : {
1297 74 : st_ivas->element_mode_init = IVAS_CPE_DFT;
1298 74 : move16();
1299 : }
1300 74 : BREAK;
1301 0 : default:
1302 : #ifndef FIX_1209_SID_SIGNALING
1303 : /* This should actually be impossible, since only 3 bits are read, so if this happens something is broken */
1304 : #endif
1305 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Invalid value %c found in SID format field.", st_ivas->sid_format );
1306 : }
1307 :
1308 2907 : IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
1309 : {
1310 : #ifdef NONBE_FIX_1052_SBA_EXT
1311 : /* read Ambisonic (SBA) planar flag */
1312 324 : st_ivas->sba_planar = st_ivas->bit_stream[*num_bits_read];
1313 324 : move16();
1314 324 : *num_bits_read = add( *num_bits_read, SBA_PLANAR_BITS );
1315 324 : move16();
1316 :
1317 : /* read Ambisonic (SBA) order */
1318 324 : st_ivas->sba_order = st_ivas->bit_stream[*num_bits_read + 1];
1319 324 : move16();
1320 324 : st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[*num_bits_read], 1 ) );
1321 324 : move16();
1322 324 : *num_bits_read = add( *num_bits_read, SBA_ORDER_BITS );
1323 324 : move16();
1324 : #endif
1325 :
1326 324 : if ( st_ivas->sba_analysis_order == 0 )
1327 : {
1328 0 : st_ivas->sba_analysis_order = SBA_FOA_ORDER;
1329 0 : move16();
1330 : }
1331 : }
1332 :
1333 : /* reset bitstream handle to avoid BER detection after reading the 2400 kbps for ch0 */
1334 2907 : st_ivas->bit_stream = st_ivas->bit_stream + ( *num_bits_read );
1335 2907 : ( *num_bits_read ) = 0;
1336 2907 : move16();
1337 : }
1338 : ELSE
1339 : {
1340 : /* In SID/NO_DATA frames, use the previous frame IVAS format */
1341 : }
1342 :
1343 400461 : return error;
1344 : }
1345 :
1346 :
1347 : /*-------------------------------------------------------------------*
1348 : * getNumChanSynthesis()
1349 : *
1350 : * get number of output channels used for synthesis/decoding
1351 : * (often different from number of output channels!)
1352 : *-------------------------------------------------------------------*/
1353 :
1354 : /*! r: number of channels to be synthesised */
1355 :
1356 257546 : Word16 getNumChanSynthesis(
1357 : Decoder_Struct *st_ivas /* i : IVAS decoder structure */
1358 : )
1359 : {
1360 : Word16 n;
1361 :
1362 257546 : n = add( st_ivas->nSCE, imult1616( CPE_CHANNELS, st_ivas->nCPE ) );
1363 257546 : test();
1364 257546 : test();
1365 257546 : IF( st_ivas->sba_dirac_stereo_flag )
1366 : {
1367 13026 : n = CPE_CHANNELS;
1368 13026 : move16();
1369 : }
1370 244520 : ELSE IF( ( st_ivas->hMCT != NULL || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) && NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
1371 : {
1372 3820 : n = st_ivas->nchan_transport;
1373 3820 : move16();
1374 : }
1375 240700 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
1376 : {
1377 176707 : IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
1378 : {
1379 143717 : n = add( st_ivas->nchan_transport, st_ivas->nchan_ism );
1380 : }
1381 : ELSE
1382 : {
1383 32990 : n = st_ivas->nchan_transport;
1384 32990 : move16();
1385 : }
1386 : }
1387 :
1388 257546 : return n;
1389 : }
1390 :
1391 : /*-------------------------------------------------------------------*
1392 : * copy_decoder_config()
1393 : *
1394 : * Copy IVAS configuration structure to the CoreCoder state structure
1395 : *-------------------------------------------------------------------*/
1396 :
1397 8160 : void copy_decoder_config(
1398 : Decoder_Struct *st_ivas, /* i : IVAS decoder structure */
1399 : Decoder_State *st /* o : decoder state structure */
1400 : )
1401 : {
1402 8160 : st->output_Fs = st_ivas->hDecoderConfig->output_Fs;
1403 8160 : move32();
1404 8160 : st->Opt_AMR_WB = st_ivas->hDecoderConfig->Opt_AMR_WB;
1405 8160 : move16();
1406 8160 : st->codec_mode = st_ivas->codec_mode;
1407 8160 : move16();
1408 8160 : st->ini_frame = st_ivas->ini_frame;
1409 8160 : move16();
1410 :
1411 8160 : st->bfi = st_ivas->bfi;
1412 8160 : move16();
1413 :
1414 8160 : st->writeFECoffset = st_ivas->writeFECoffset;
1415 8160 : move16();
1416 :
1417 8160 : st->element_mode = st_ivas->element_mode_init;
1418 8160 : move16();
1419 :
1420 8160 : return;
1421 : }
1422 :
1423 :
1424 : /*-------------------------------------------------------------------*
1425 : * ivas_init_decoder_front()
1426 : *
1427 : * Set decoder parameters to initial values
1428 : *-------------------------------------------------------------------*/
1429 :
1430 613 : ivas_error ivas_init_decoder_front(
1431 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
1432 : )
1433 : {
1434 : ivas_error error;
1435 :
1436 613 : error = IVAS_ERR_OK;
1437 613 : move32();
1438 : /*-----------------------------------------------------------------*
1439 : * Resets
1440 : *-----------------------------------------------------------------*/
1441 :
1442 613 : st_ivas->nSCE = 0;
1443 613 : move16();
1444 613 : st_ivas->nCPE = 0;
1445 613 : move16();
1446 : #ifdef NONBE_FIX_1052_SBA_EXT_FIX
1447 613 : st_ivas->nchan_ism = 0;
1448 613 : move16();
1449 : #endif
1450 613 : st_ivas->nCPE_old = 0;
1451 613 : move16();
1452 613 : st_ivas->nchan_transport = -1;
1453 613 : move16();
1454 613 : st_ivas->ism_mode = ISM_MODE_NONE;
1455 613 : move32();
1456 613 : st_ivas->mc_mode = MC_MODE_NONE;
1457 613 : move32();
1458 613 : st_ivas->sba_dirac_stereo_flag = 0;
1459 613 : move16();
1460 :
1461 : /* HRTF binauralization latency in ns */
1462 613 : st_ivas->binaural_latency_ns = 0;
1463 613 : move32();
1464 :
1465 : /*-------------------------------------------------------------------*
1466 : * Allocate and initialize Custom loudspeaker layout handle
1467 : *--------------------------------------------------------------------*/
1468 :
1469 613 : IF( st_ivas->hDecoderConfig->Opt_LsCustom )
1470 : {
1471 3 : IF( EQ_32( ( error = ivas_ls_custom_open_fx( &( st_ivas->hLsSetupCustom ) ) ), IVAS_ERR_OK ) )
1472 : {
1473 3 : set_zero_fx( ( st_ivas->hLsSetupCustom )->ls_azimuth_fx, MAX_OUTPUT_CHANNELS );
1474 3 : set_zero_fx( ( st_ivas->hLsSetupCustom )->ls_elevation_fx, MAX_OUTPUT_CHANNELS );
1475 : }
1476 : ELSE
1477 : {
1478 0 : return error;
1479 : }
1480 : }
1481 :
1482 : /*-------------------------------------------------------------------*
1483 : * Allocate and initialize Head-Tracking handle
1484 : *--------------------------------------------------------------------*/
1485 :
1486 613 : IF( st_ivas->hDecoderConfig->Opt_Headrotation )
1487 : {
1488 82 : IF( NE_32( ( error = ivas_headTrack_open_fx( &( st_ivas->hHeadTrackData ) ) ), IVAS_ERR_OK ) )
1489 : {
1490 0 : return error;
1491 : }
1492 82 : error = ivas_orient_trk_SetTrackingType_fx( st_ivas->hHeadTrackData->OrientationTracker, st_ivas->hDecoderConfig->orientation_tracking );
1493 82 : IF( NE_32( ( error ), IVAS_ERR_OK ) )
1494 : {
1495 0 : return error;
1496 : }
1497 : }
1498 : /*-------------------------------------------------------------------*
1499 : * Allocate and initialize external orientation handle
1500 : *--------------------------------------------------------------------*/
1501 :
1502 613 : IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation )
1503 : {
1504 31 : IF( NE_32( ( error = ivas_external_orientation_open( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_framesize ) ), IVAS_ERR_OK ) )
1505 : {
1506 0 : return error;
1507 : }
1508 : }
1509 :
1510 : /*-------------------------------------------------------------------*
1511 : * Allocate and initialize combined orientation handle
1512 : *--------------------------------------------------------------------*/
1513 613 : test();
1514 613 : IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation )
1515 : {
1516 82 : IF( NE_32( ( error = ivas_combined_orientation_open( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_framesize ) ), IVAS_ERR_OK ) )
1517 : {
1518 0 : return error;
1519 : }
1520 : }
1521 :
1522 : /*-------------------------------------------------------------------*
1523 : * Allocate HRTF binary handle
1524 : *--------------------------------------------------------------------*/
1525 :
1526 613 : IF( st_ivas->hDecoderConfig->Opt_HRTF_binary )
1527 : {
1528 24 : IF( NE_32( ( error = ivas_HRTF_binary_open_fx( &( st_ivas->hHrtfTD ) ) ), IVAS_ERR_OK ) )
1529 : {
1530 0 : return error;
1531 : }
1532 :
1533 24 : IF( NE_32( ( error = ivas_HRTF_CRend_binary_open_fx( &( st_ivas->hSetOfHRTF ) ) ), IVAS_ERR_OK ) )
1534 : {
1535 0 : return error;
1536 : }
1537 :
1538 24 : IF( NE_32( ( error = ivas_HRTF_fastconv_binary_open_fx( &st_ivas->hHrtfFastConv ) ), IVAS_ERR_OK ) )
1539 : {
1540 0 : return error;
1541 : }
1542 :
1543 24 : IF( NE_32( ( error = ivas_HRTF_parambin_binary_open_fx( &st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) )
1544 : {
1545 0 : return error;
1546 : }
1547 :
1548 24 : IF( NE_32( ( error = ivas_HRTF_statistics_binary_open( &st_ivas->hHrtfStatistics ) ), IVAS_ERR_OK ) )
1549 : {
1550 0 : return error;
1551 : }
1552 : }
1553 :
1554 : /*-------------------------------------------------------------------*
1555 : * Allocate and initialize Binaural Renderer configuration handle
1556 : *--------------------------------------------------------------------*/
1557 613 : test();
1558 613 : test();
1559 613 : 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 ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ||
1560 : ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && st_ivas->hDecoderConfig->Opt_non_diegetic_pan ) )
1561 : {
1562 203 : IF( NE_32( ( error = ivas_render_config_open( &( st_ivas->hRenderConfig ) ) ), IVAS_ERR_OK ) )
1563 : {
1564 0 : return error;
1565 : }
1566 :
1567 203 : IF( NE_32( ( error = ivas_render_config_init_from_rom_fx( &st_ivas->hRenderConfig ) ), IVAS_ERR_OK ) )
1568 : {
1569 0 : return error;
1570 : }
1571 : }
1572 :
1573 613 : return error;
1574 : }
1575 :
1576 :
1577 : /*-------------------------------------------------------------------*
1578 : * ivas_init_decoder()
1579 : *
1580 : * Initialize IVAS decoder state structure
1581 : *-------------------------------------------------------------------*/
1582 613 : ivas_error ivas_init_decoder_fx(
1583 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
1584 : )
1585 : {
1586 : Word16 i, n, k;
1587 : Word16 sce_id, cpe_id;
1588 : Word16 numCldfbAnalyses, numCldfbSyntheses;
1589 : Word16 granularity, n_channels_transport_jbm;
1590 : Word32 output_Fs, ivas_total_brate;
1591 : #ifdef NONBE_FIX_MC_LFE_LPF
1592 : Word32 delay_ns;
1593 : #else
1594 : Word32 binauralization_delay_ns;
1595 : #endif
1596 : AUDIO_CONFIG output_config;
1597 : DECODER_CONFIG_HANDLE hDecoderConfig;
1598 : ivas_error error;
1599 : Word32 ism_total_brate;
1600 :
1601 613 : error = IVAS_ERR_OK;
1602 613 : move32();
1603 613 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
1604 613 : move32();
1605 613 : hDecoderConfig = st_ivas->hDecoderConfig;
1606 613 : output_config = hDecoderConfig->output_config;
1607 613 : ivas_total_brate = hDecoderConfig->ivas_total_brate;
1608 613 : move32();
1609 613 : hDecoderConfig->last_ivas_total_brate = ivas_total_brate;
1610 613 : move32();
1611 613 : st_ivas->last_active_ivas_total_brate = ivas_total_brate;
1612 613 : move32();
1613 :
1614 : /*-----------------------------------------------------------------*
1615 : * Set number of output channels for EXTERNAL output config.
1616 : *-----------------------------------------------------------------*/
1617 :
1618 613 : test();
1619 613 : test();
1620 613 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
1621 : {
1622 : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
1623 50 : test();
1624 : #endif
1625 : #ifdef FIX_1052_EXT_OUTPUT
1626 50 : IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
1627 : {
1628 1 : hDecoderConfig->nchan_out = CPE_CHANNELS;
1629 : }
1630 49 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
1631 : {
1632 4 : hDecoderConfig->nchan_out = audioCfg2channels( st_ivas->transport_config );
1633 : }
1634 : #ifdef NONBE_FIX_1052_SBA_EXT_FIX
1635 45 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
1636 : #else
1637 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
1638 : #endif
1639 : #else
1640 : IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
1641 : #endif
1642 : {
1643 : #ifdef NONBE_FIX_1128_OSBA_EXT_OUTPUT_ORDER
1644 9 : hDecoderConfig->nchan_out = audioCfg2channels( ivas_set_audio_config_from_sba_order( st_ivas->sba_order ) );
1645 : #else
1646 : hDecoderConfig->nchan_out = audioCfg2channels( IVAS_AUDIO_CONFIG_HOA3 );
1647 : #endif
1648 9 : move16();
1649 9 : hDecoderConfig->nchan_out = add( hDecoderConfig->nchan_out, st_ivas->nchan_ism );
1650 9 : move16();
1651 : }
1652 : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
1653 36 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
1654 : #else
1655 : ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
1656 : #endif
1657 : {
1658 21 : hDecoderConfig->nchan_out = add( st_ivas->nchan_transport, st_ivas->nchan_ism );
1659 21 : move16();
1660 : }
1661 15 : ELSE IF( !EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
1662 : {
1663 13 : hDecoderConfig->nchan_out = st_ivas->nchan_transport;
1664 13 : move16();
1665 : }
1666 :
1667 50 : st_ivas->hOutSetup.nchan_out_woLFE = hDecoderConfig->nchan_out;
1668 50 : move16();
1669 : }
1670 :
1671 : /*-----------------------------------------------------------------*
1672 : * Set output and intern setup & renderer selection
1673 : *-----------------------------------------------------------------*/
1674 :
1675 613 : st_ivas->intern_config = output_config;
1676 613 : move32();
1677 :
1678 613 : test();
1679 613 : test();
1680 : #ifdef FIX_1052_EXT_OUTPUT
1681 613 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
1682 : {
1683 4 : ivas_output_init( &( st_ivas->hOutSetup ), st_ivas->transport_config );
1684 4 : st_ivas->intern_config = st_ivas->transport_config;
1685 4 : move32();
1686 : }
1687 : #ifdef NONBE_FIX_1128_OSBA_EXT_OUTPUT_ORDER
1688 : #ifdef NONBE_FIX_1052_SBA_EXT_FIX
1689 609 : ELSE IF( output_config == IVAS_AUDIO_CONFIG_EXTERNAL && ( st_ivas->ivas_format == SBA_ISM_FORMAT || st_ivas->ivas_format == SBA_FORMAT ) )
1690 : #else
1691 : ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
1692 : #endif
1693 : {
1694 9 : st_ivas->intern_config = ivas_set_audio_config_from_sba_order( st_ivas->sba_order );
1695 9 : ivas_output_init( &( st_ivas->hOutSetup ), st_ivas->intern_config );
1696 : }
1697 : #endif
1698 : ELSE
1699 : {
1700 600 : ivas_output_init( &( st_ivas->hOutSetup ), output_config );
1701 : }
1702 : #else
1703 : ivas_output_init( &( st_ivas->hOutSetup ), output_config );
1704 : #endif
1705 :
1706 613 : test();
1707 613 : IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
1708 : {
1709 3 : st_ivas->hOutSetup.ambisonics_order = SBA_HOA3_ORDER;
1710 3 : move16();
1711 3 : st_ivas->intern_config = IVAS_AUDIO_CONFIG_7_1_4;
1712 3 : move32();
1713 3 : st_ivas->hOutSetup.output_config = st_ivas->intern_config;
1714 3 : move32();
1715 3 : st_ivas->hOutSetup.nchan_out_woLFE = audioCfg2channels( st_ivas->intern_config );
1716 3 : move16();
1717 : }
1718 : #ifndef NONBE_FIX_1128_OSBA_EXT_OUTPUT_ORDER
1719 : test();
1720 : IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
1721 : {
1722 : st_ivas->hOutSetup.ambisonics_order = SBA_HOA3_ORDER;
1723 : move32();
1724 : st_ivas->intern_config = IVAS_AUDIO_CONFIG_HOA3;
1725 : move32();
1726 : st_ivas->hOutSetup.output_config = IVAS_AUDIO_CONFIG_HOA3;
1727 : move32();
1728 : st_ivas->hOutSetup.nchan_out_woLFE = audioCfg2channels( IVAS_AUDIO_CONFIG_HOA3 );
1729 : move16();
1730 : }
1731 : #endif
1732 :
1733 : /* Only initialize transport setup if it is used */
1734 613 : IF( NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_INVALID ) )
1735 : {
1736 149 : ivas_output_init( &( st_ivas->hTransSetup ), st_ivas->transport_config );
1737 : }
1738 :
1739 613 : test();
1740 613 : IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
1741 : {
1742 30 : ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate );
1743 :
1744 30 : ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hOutSetup.separateChannelEnabled ), &( st_ivas->hOutSetup.separateChannelIndex ), ivas_total_brate );
1745 : }
1746 :
1747 613 : ivas_renderer_select( st_ivas );
1748 :
1749 613 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
1750 : {
1751 3 : IF( EQ_16( ( error = ivas_ls_custom_output_init_fx( st_ivas ) ), IVAS_ERR_OK ) )
1752 : {
1753 3 : st_ivas->hOutSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx;
1754 3 : move32();
1755 3 : st_ivas->hOutSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx;
1756 3 : move32();
1757 3 : st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx;
1758 3 : move32();
1759 3 : st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx;
1760 3 : move32();
1761 : }
1762 : ELSE
1763 : {
1764 0 : return error;
1765 : }
1766 : }
1767 :
1768 613 : ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config );
1769 :
1770 613 : test();
1771 613 : IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
1772 : {
1773 30 : ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate );
1774 :
1775 30 : test();
1776 30 : IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.separateChannelEnabled )
1777 : {
1778 0 : st_ivas->hLsSetupCustom->separate_ch_found = 0;
1779 0 : move16();
1780 0 : IF( GE_16( st_ivas->hOutSetup.nchan_out_woLFE, MCMASA_MIN_SPEAKERS_SEPARATE_CENTER ) )
1781 : {
1782 : /* check for a speaker at (0, 0) if minimum speaker count is available */
1783 0 : FOR( i = 0; i < st_ivas->hOutSetup.nchan_out_woLFE; i++ )
1784 : {
1785 0 : test();
1786 0 : IF( ( L_shr( st_ivas->hOutSetup.ls_azimuth_fx[i], Q22 ) == 0 ) && ( L_shr( st_ivas->hOutSetup.ls_elevation_fx[i], Q22 ) == 0 ) )
1787 : {
1788 0 : st_ivas->hIntSetup.separateChannelIndex = i;
1789 0 : move16();
1790 0 : st_ivas->hLsSetupCustom->separate_ch_found = 1;
1791 0 : move16();
1792 0 : BREAK;
1793 : }
1794 : }
1795 : }
1796 : }
1797 : }
1798 :
1799 : /*--------------------------------------------------------------------*
1800 : * Allocate and initialize HRTF Statistics handle
1801 : *--------------------------------------------------------------------*/
1802 :
1803 613 : IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
1804 : {
1805 51 : IF( NE_32( ( error = ivas_HRTF_statistics_init( &st_ivas->hHrtfStatistics, output_Fs ) ), IVAS_ERR_OK ) )
1806 : {
1807 0 : return error;
1808 : }
1809 : }
1810 :
1811 : /*-----------------------------------------------------------------*
1812 : * Allocate and initialize SCE/CPE and other handles
1813 : *-----------------------------------------------------------------*/
1814 :
1815 613 : IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) )
1816 : {
1817 3 : st_ivas->nSCE = 1; /* in mono, there is always only one SCE */
1818 3 : move16();
1819 3 : st_ivas->nCPE = 0;
1820 3 : move16();
1821 3 : st_ivas->nCPE_old = 0;
1822 3 : move16();
1823 3 : st_ivas->nchan_transport = 1;
1824 3 : move16();
1825 3 : sce_id = 0;
1826 3 : move16();
1827 :
1828 3 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) )
1829 : {
1830 0 : return error;
1831 : }
1832 :
1833 3 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1834 : }
1835 610 : ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
1836 : {
1837 68 : st_ivas->nchan_transport = CPE_CHANNELS;
1838 68 : move16();
1839 68 : st_ivas->intern_config = IVAS_AUDIO_CONFIG_STEREO;
1840 68 : move32();
1841 :
1842 68 : st_ivas->nSCE = 0;
1843 68 : move16();
1844 68 : st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */
1845 68 : move16();
1846 68 : st_ivas->nCPE_old = 0;
1847 68 : move16();
1848 68 : cpe_id = 0;
1849 68 : move16();
1850 :
1851 68 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate ) ), IVAS_ERR_OK ) )
1852 : {
1853 0 : return error;
1854 : }
1855 :
1856 204 : FOR( n = 0; n < st_ivas->nchan_transport; n++ )
1857 : {
1858 136 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1859 : }
1860 :
1861 : /* init EFAP for custom LS output and set hTransSetup */
1862 68 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
1863 : {
1864 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 ) )
1865 : {
1866 0 : return error;
1867 : }
1868 :
1869 0 : ivas_output_init( &( st_ivas->hTransSetup ), IVAS_AUDIO_CONFIG_STEREO );
1870 : }
1871 : }
1872 542 : ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
1873 : {
1874 : Word32 element_brate_tmp[MAX_NUM_OBJECTS];
1875 :
1876 68 : st_ivas->nSCE = st_ivas->nchan_transport; /* "st_ivas->nchan_transport" is known from ivas_dec_setup */
1877 68 : move16();
1878 68 : st_ivas->nCPE = 0;
1879 68 : move16();
1880 68 : st_ivas->nCPE_old = 0;
1881 68 : move16();
1882 68 : st_ivas->ism_extmeta_active = -1;
1883 68 : move16();
1884 68 : st_ivas->ism_extmeta_cnt = 0;
1885 68 : move16();
1886 68 : IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
1887 : {
1888 14 : st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE;
1889 14 : move16();
1890 14 : st_ivas->nSCE = MAX_PARAM_ISM_WAVE;
1891 14 : move16();
1892 :
1893 14 : IF( NE_32( ( error = ivas_param_ism_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
1894 : {
1895 0 : return error;
1896 : }
1897 : }
1898 :
1899 68 : IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK )
1900 : {
1901 0 : return error;
1902 : }
1903 :
1904 238 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
1905 : {
1906 170 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, element_brate_tmp[sce_id] ) ), IVAS_ERR_OK ) )
1907 : {
1908 0 : return error;
1909 : }
1910 :
1911 170 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1912 :
1913 170 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->is_ism_format = 1;
1914 170 : move16();
1915 : }
1916 :
1917 68 : st_ivas->hISMDTX.sce_id_dtx = 0;
1918 68 : move16();
1919 :
1920 68 : IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
1921 : {
1922 14 : st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2 = st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed3;
1923 14 : move16();
1924 : }
1925 54 : ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) )
1926 : {
1927 196 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; ++sce_id )
1928 : {
1929 142 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2 = add( 2, sce_id );
1930 142 : move16();
1931 : }
1932 : }
1933 : }
1934 474 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
1935 : {
1936 244 : IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) )
1937 : {
1938 0 : return error;
1939 : }
1940 :
1941 244 : IF( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) )
1942 : {
1943 0 : return error;
1944 : }
1945 244 : set16_fx( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 0, CLDFB_NO_COL_MAX );
1946 :
1947 : #ifndef FIX_1249_REMOVE_OBSOLETE_ALLRAD_MATRIX
1948 : test();
1949 : IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) && st_ivas->hOutSetup.is_loudspeaker_setup )
1950 : {
1951 : 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 ) )
1952 : {
1953 : return error;
1954 : }
1955 : }
1956 : #endif
1957 244 : Word16 hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order );
1958 244 : IF( hodirac_flag )
1959 : {
1960 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 ) )
1961 : {
1962 0 : return error;
1963 : }
1964 : }
1965 : ELSE
1966 : {
1967 236 : 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 ) )
1968 : {
1969 0 : return error;
1970 : }
1971 : }
1972 :
1973 244 : test();
1974 244 : test();
1975 : #ifdef NONBE_FIX_1052_SBA_EXT_FIX
1976 244 : test();
1977 244 : 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 ) && !( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) ) )
1978 : #else
1979 : 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 ) )
1980 : #endif
1981 : {
1982 80 : IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) )
1983 : {
1984 0 : return error;
1985 : }
1986 :
1987 80 : st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band;
1988 80 : move16();
1989 : }
1990 : ELSE
1991 : {
1992 : Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1];
1993 :
1994 164 : st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND );
1995 164 : move16();
1996 164 : IF( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) )
1997 : {
1998 1 : st_ivas->hSpar->enc_param_start_band = 0;
1999 1 : move16();
2000 1 : set8_fx( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands );
2001 1 : st_ivas->hQMetaData->numTwoDirBands = (UWord8) st_ivas->hQMetaData->q_direction[0].cfg.nbands;
2002 1 : move16();
2003 : }
2004 :
2005 164 : 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 ) ),
2006 164 : st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0, 1 );
2007 : }
2008 244 : st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
2009 244 : move16();
2010 :
2011 343 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
2012 : {
2013 : Word32 res_dec, res_frac;
2014 99 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
2015 99 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) )
2016 : {
2017 0 : return error;
2018 : }
2019 :
2020 99 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
2021 : }
2022 :
2023 472 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
2024 : {
2025 : Word32 res_dec, res_frac;
2026 228 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
2027 228 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, (res_dec) *CPE_CHANNELS ) ), IVAS_ERR_OK ) )
2028 : {
2029 0 : return error;
2030 : }
2031 :
2032 684 : FOR( n = 0; n < CPE_CHANNELS; n++ )
2033 : {
2034 456 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
2035 : }
2036 : }
2037 :
2038 : /* create CPE element for DFT Stereo like upmix */
2039 244 : test();
2040 244 : IF( st_ivas->sba_dirac_stereo_flag && ( st_ivas->nCPE == 0 ) )
2041 : {
2042 : Word32 res_dec, res_frac;
2043 5 : iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 );
2044 :
2045 5 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) )
2046 : {
2047 0 : return error;
2048 : }
2049 :
2050 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 */
2051 5 : st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
2052 : }
2053 :
2054 244 : IF( GT_16( st_ivas->nCPE, 1 ) )
2055 : {
2056 83 : IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) )
2057 : {
2058 0 : return error;
2059 : }
2060 : }
2061 :
2062 : /* set CNA/CNG flags */
2063 244 : ivas_sba_set_cna_cng_flag( st_ivas );
2064 : }
2065 230 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
2066 : {
2067 : /* if we start in ISM_MODE_NONE in MASA_ISM, that appears as normal MASA, but we may change to a mode with ISMs */
2068 82 : st_ivas->ism_extmeta_active = -1;
2069 82 : move16();
2070 82 : st_ivas->ism_extmeta_cnt = 0;
2071 82 : move16();
2072 82 : IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) )
2073 : {
2074 0 : return error;
2075 : }
2076 :
2077 82 : IF( NE_32( ( error = ivas_masa_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2078 : {
2079 0 : return error;
2080 : }
2081 :
2082 82 : test();
2083 82 : test();
2084 82 : test();
2085 82 : 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 ) )
2086 : {
2087 61 : IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) )
2088 : {
2089 0 : return error;
2090 : }
2091 : }
2092 :
2093 113 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
2094 : {
2095 : Word32 res_dec, res_frac;
2096 31 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
2097 31 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) )
2098 : {
2099 0 : return error;
2100 : }
2101 :
2102 31 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
2103 : }
2104 :
2105 133 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
2106 : {
2107 : Word32 res_dec, res_frac;
2108 51 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
2109 51 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) )
2110 : {
2111 0 : return error;
2112 : }
2113 :
2114 153 : FOR( n = 0; n < CPE_CHANNELS; n++ )
2115 : {
2116 102 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
2117 : }
2118 : }
2119 :
2120 : /* set CNA/CNG flags */
2121 82 : ivas_sba_set_cna_cng_flag( st_ivas );
2122 : }
2123 148 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
2124 : {
2125 : Word32 temp_brate[MAX_SCE];
2126 34 : st_ivas->ism_extmeta_active = -1;
2127 34 : move16();
2128 34 : st_ivas->ism_extmeta_cnt = 0;
2129 34 : move16();
2130 :
2131 34 : st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
2132 34 : move16();
2133 34 : IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) )
2134 : {
2135 0 : return error;
2136 : }
2137 :
2138 34 : IF( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) )
2139 : {
2140 0 : return error;
2141 : }
2142 :
2143 : #ifndef FIX_1249_REMOVE_OBSOLETE_ALLRAD_MATRIX
2144 : test();
2145 : IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) && st_ivas->hOutSetup.is_loudspeaker_setup )
2146 : {
2147 : 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 ) )
2148 : {
2149 : return error;
2150 : }
2151 : }
2152 : #endif
2153 34 : Word16 hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order );
2154 34 : IF( hodirac_flag )
2155 : {
2156 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 ) )
2157 : {
2158 0 : return error;
2159 : }
2160 : }
2161 : ELSE
2162 : {
2163 28 : 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 ) )
2164 : {
2165 0 : return error;
2166 : }
2167 : }
2168 :
2169 34 : test();
2170 34 : test();
2171 34 : 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 ) )
2172 : {
2173 28 : IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) )
2174 : {
2175 0 : return error;
2176 : }
2177 :
2178 28 : st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band;
2179 28 : move16();
2180 : }
2181 : ELSE
2182 : {
2183 : Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1];
2184 :
2185 6 : st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND );
2186 6 : move16();
2187 6 : IF( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) )
2188 : {
2189 1 : st_ivas->hSpar->enc_param_start_band = 0;
2190 1 : move16();
2191 1 : set8_fx( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands );
2192 1 : st_ivas->hQMetaData->numTwoDirBands = (UWord8) st_ivas->hQMetaData->q_direction[0].cfg.nbands;
2193 1 : move16();
2194 : }
2195 :
2196 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 ) ),
2197 6 : st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0, 1 );
2198 : }
2199 :
2200 45 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
2201 : {
2202 : Word32 res_dec, res_frac;
2203 11 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
2204 11 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) )
2205 : {
2206 0 : return error;
2207 : }
2208 :
2209 11 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
2210 : }
2211 :
2212 34 : IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
2213 : {
2214 17 : st_ivas->nCPE_old = st_ivas->nCPE;
2215 17 : move16();
2216 : #ifdef NONBE_FIX_ISM_XOVER_BR
2217 : {
2218 : Word16 n_all;
2219 :
2220 17 : n_all = add( st_ivas->nchan_transport, st_ivas->nchan_ism );
2221 17 : st_ivas->nCPE = shr( add( n_all, 1 ), 1 );
2222 : }
2223 : #else
2224 : st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) );
2225 : move16();
2226 : #endif
2227 17 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
2228 17 : move16();
2229 : }
2230 :
2231 101 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
2232 : {
2233 : Word32 res_dec, res_frac;
2234 67 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
2235 67 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) )
2236 : {
2237 0 : return error;
2238 : }
2239 :
2240 201 : FOR( n = 0; n < CPE_CHANNELS; n++ )
2241 : {
2242 134 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
2243 : }
2244 : }
2245 :
2246 : /* create CPE element for DFT Stereo like upmix */
2247 34 : test();
2248 34 : IF( st_ivas->sba_dirac_stereo_flag && st_ivas->nCPE == 0 )
2249 : {
2250 : Word32 res_dec, res_frac;
2251 1 : iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 );
2252 1 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) )
2253 : {
2254 0 : return error;
2255 : }
2256 :
2257 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 */
2258 1 : st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
2259 : }
2260 :
2261 34 : IF( GT_16( st_ivas->nCPE, 1 ) )
2262 : {
2263 18 : IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) )
2264 : {
2265 0 : return error;
2266 : }
2267 : }
2268 :
2269 34 : IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
2270 : {
2271 17 : IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ), IVAS_ERR_OK ) )
2272 : {
2273 0 : return error;
2274 : }
2275 :
2276 17 : IF( NE_32( ( error = ivas_osba_data_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2277 : {
2278 0 : return error;
2279 : }
2280 : }
2281 :
2282 : /* set CNA/CNG flags */
2283 34 : ivas_sba_set_cna_cng_flag( st_ivas );
2284 : }
2285 114 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
2286 : {
2287 33 : st_ivas->ism_extmeta_active = -1;
2288 33 : move16();
2289 33 : st_ivas->ism_extmeta_cnt = 0;
2290 33 : move16();
2291 :
2292 33 : IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) )
2293 : {
2294 0 : return error;
2295 : }
2296 :
2297 33 : k = 0;
2298 33 : move16();
2299 33 : ism_total_brate = 0;
2300 33 : move32();
2301 :
2302 293 : WHILE( ( k < SIZE_IVAS_BRATE_TBL ) && ( ivas_total_brate != ivas_brate_tbl[k] ) )
2303 : {
2304 260 : k = add( k, 1 );
2305 : }
2306 :
2307 33 : test();
2308 33 : 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 ) )
2309 : {
2310 : /* one separated object */
2311 19 : st_ivas->nSCE = 1;
2312 19 : move16();
2313 19 : ism_total_brate = sep_object_brate[k - 2][0];
2314 19 : move32();
2315 :
2316 19 : IF( NE_32( ( error = create_sce_dec( st_ivas, 0, ism_total_brate ) ), IVAS_ERR_OK ) )
2317 : {
2318 0 : return error;
2319 : }
2320 :
2321 19 : reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] );
2322 :
2323 19 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
2324 : {
2325 1 : if ( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, NULL ) ) != IVAS_ERR_OK )
2326 : {
2327 0 : return error;
2328 : }
2329 : }
2330 : else
2331 : {
2332 18 : IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, 1, NULL ) ), IVAS_ERR_OK ) )
2333 : {
2334 0 : return error;
2335 : }
2336 : }
2337 : }
2338 14 : ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
2339 : {
2340 : Word32 temp_brate[MAX_SCE];
2341 14 : st_ivas->nSCE = st_ivas->nchan_ism; /* number of objects */
2342 14 : move16();
2343 53 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
2344 : {
2345 39 : temp_brate[sce_id] = sep_object_brate[k - 2][st_ivas->nSCE - 1];
2346 39 : move32();
2347 39 : ism_total_brate = L_add( ism_total_brate, temp_brate[sce_id] );
2348 :
2349 39 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, temp_brate[sce_id] ) ), IVAS_ERR_OK ) )
2350 : {
2351 0 : return error;
2352 : }
2353 :
2354 39 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
2355 : }
2356 :
2357 14 : IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ), IVAS_ERR_OK ) )
2358 : {
2359 0 : return error;
2360 : }
2361 : }
2362 :
2363 33 : IF( NE_32( ( error = ivas_masa_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2364 : {
2365 0 : return error;
2366 : }
2367 :
2368 33 : IF( NE_32( ( error = ivas_omasa_data_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2369 : {
2370 0 : return error;
2371 : }
2372 :
2373 33 : test();
2374 33 : test();
2375 33 : test();
2376 33 : 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 ) )
2377 : {
2378 24 : IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) )
2379 : {
2380 0 : return error;
2381 : }
2382 : }
2383 :
2384 33 : IF( NE_32( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate - ism_total_brate ) ), IVAS_ERR_OK ) )
2385 : {
2386 0 : return error;
2387 : }
2388 :
2389 99 : FOR( n = 0; n < CPE_CHANNELS; n++ )
2390 : {
2391 66 : reset_indices_dec( st_ivas->hCPE[0]->hCoreCoder[n] );
2392 : }
2393 : }
2394 81 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
2395 : {
2396 81 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) )
2397 : {
2398 : /* init EFAP for custom LS setup */
2399 36 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
2400 : {
2401 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 ) )
2402 : {
2403 0 : return error;
2404 : }
2405 : }
2406 :
2407 36 : 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 ) );
2408 36 : move16();
2409 36 : st_ivas->nSCE = 0;
2410 36 : move16();
2411 36 : st_ivas->nCPE = shr( st_ivas->nchan_transport, 1 );
2412 36 : move16();
2413 36 : st_ivas->nCPE_old = 0;
2414 36 : move16();
2415 36 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
2416 36 : move16();
2417 181 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
2418 : {
2419 : Word32 res_dec, res_frac;
2420 145 : iDiv_and_mod_32( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 );
2421 145 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) )
2422 : {
2423 0 : return error;
2424 : }
2425 :
2426 435 : FOR( n = 0; n < CPE_CHANNELS; n++ )
2427 : {
2428 290 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
2429 : }
2430 : }
2431 :
2432 36 : IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) )
2433 : {
2434 0 : return error;
2435 : }
2436 : }
2437 45 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
2438 : {
2439 : /* init EFAP for custom LS setup */
2440 5 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
2441 : {
2442 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 ) )
2443 : {
2444 0 : return error;
2445 : }
2446 : }
2447 :
2448 5 : st_ivas->nSCE = 0;
2449 5 : move16();
2450 5 : st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS >> 1;
2451 5 : move16();
2452 5 : st_ivas->nCPE_old = 0;
2453 5 : move16();
2454 5 : st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
2455 5 : move16();
2456 :
2457 5 : IF( NE_32( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ), IVAS_ERR_OK ) )
2458 : {
2459 0 : return error;
2460 : }
2461 :
2462 5 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
2463 5 : move16();
2464 25 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
2465 : {
2466 : Word32 res_dec, res_frac;
2467 20 : iDiv_and_mod_32( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 );
2468 20 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) )
2469 : {
2470 0 : return error;
2471 : }
2472 :
2473 60 : FOR( n = 0; n < CPE_CHANNELS; n++ )
2474 : {
2475 40 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
2476 : }
2477 : }
2478 :
2479 5 : IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) )
2480 : {
2481 0 : return error;
2482 : }
2483 : }
2484 40 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
2485 : {
2486 : /* init EFAP for custom LS setup */
2487 10 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
2488 : {
2489 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 ) )
2490 : {
2491 0 : return error;
2492 : }
2493 : }
2494 10 : IF( NE_32( ( error = ivas_param_mc_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2495 : {
2496 0 : return error;
2497 : }
2498 :
2499 10 : st_ivas->hParamMC->proto_matrix_int_e = 0;
2500 10 : move16();
2501 20 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
2502 : {
2503 : Word32 res_dec, res_frac;
2504 10 : iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 );
2505 :
2506 10 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) )
2507 : {
2508 0 : return error;
2509 : }
2510 :
2511 30 : FOR( n = 0; n < CPE_CHANNELS; n++ )
2512 : {
2513 20 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
2514 : }
2515 : }
2516 :
2517 10 : IF( GT_16( st_ivas->nCPE, 1 ) )
2518 : {
2519 0 : IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) )
2520 : {
2521 0 : return error;
2522 : }
2523 : }
2524 : }
2525 30 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
2526 : {
2527 : Word32 brate_sce, brate_cpe;
2528 :
2529 30 : ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate );
2530 :
2531 30 : IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) )
2532 : {
2533 0 : return error;
2534 : }
2535 :
2536 30 : IF( NE_32( ( error = ivas_masa_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2537 :
2538 : {
2539 0 : return error;
2540 : }
2541 :
2542 30 : st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
2543 30 : move16();
2544 30 : test();
2545 30 : IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && NE_32( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) )
2546 : {
2547 23 : IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) )
2548 : {
2549 0 : return error;
2550 : }
2551 : }
2552 30 : test();
2553 30 : test();
2554 30 : IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.separateChannelEnabled && !st_ivas->hLsSetupCustom->separate_ch_found )
2555 : {
2556 : /* If no speaker matching the separated channel, compute panning gains for the separated channel. */
2557 0 : IF( st_ivas->hVBAPdata == NULL )
2558 : {
2559 : /* Distribute signal to all channels if VBAP is not properly initialized. */
2560 0 : Word16 inv_sqr, sqr, exp = 15, exp_sqr;
2561 0 : move16();
2562 0 : IF( EQ_16( st_ivas->hLsSetupCustom->num_spk, 1 ) )
2563 : {
2564 0 : inv_sqr = 32767; // (1.0f in Q15)-1
2565 0 : move16();
2566 : }
2567 : ELSE
2568 : {
2569 0 : sqr = Sqrt16( st_ivas->hLsSetupCustom->num_spk, &exp );
2570 0 : inv_sqr = BASOP_Util_Divide1616_Scale( 32767, sqr, &exp_sqr );
2571 0 : exp_sqr = sub( exp_sqr, exp );
2572 0 : IF( ( exp < 0 ) )
2573 : {
2574 0 : inv_sqr = shr( inv_sqr, exp ); // exp_sqr
2575 : }
2576 : ELSE
2577 : {
2578 0 : inv_sqr = shl( inv_sqr, exp ); // exp_sqr
2579 : }
2580 : }
2581 0 : set16_fx( st_ivas->hLsSetupCustom->separate_ch_gains_fx, inv_sqr, st_ivas->hLsSetupCustom->num_spk );
2582 : }
2583 : }
2584 :
2585 :
2586 30 : ivas_mcmasa_split_brate_fx( st_ivas->hOutSetup.separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe );
2587 :
2588 58 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
2589 : {
2590 28 : IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, brate_sce ) ), IVAS_ERR_OK ) )
2591 : {
2592 0 : return error;
2593 : }
2594 :
2595 28 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
2596 : }
2597 :
2598 35 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
2599 : {
2600 5 : st_ivas->element_mode_init = IVAS_CPE_MDCT; /* element_mode_init was IVAS_SCE for SCE initialization */
2601 5 : move16();
2602 5 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, brate_cpe ) ), IVAS_ERR_OK ) )
2603 : {
2604 0 : return error;
2605 : }
2606 :
2607 15 : FOR( n = 0; n < CPE_CHANNELS; n++ )
2608 : {
2609 10 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
2610 : }
2611 : }
2612 :
2613 : /* create CPE element for DFT Stereo like upmix */
2614 30 : IF( st_ivas->sba_dirac_stereo_flag )
2615 : {
2616 : Word32 res_dec, res_frac;
2617 3 : iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 );
2618 3 : IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) )
2619 : {
2620 0 : return error;
2621 : }
2622 :
2623 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 */
2624 3 : st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
2625 : }
2626 :
2627 : /* set CNA/CNG flags */
2628 30 : test();
2629 30 : test();
2630 30 : 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 ) ) ) )
2631 : {
2632 13 : st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1;
2633 13 : move16();
2634 13 : st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1;
2635 13 : move16();
2636 : }
2637 : }
2638 : }
2639 :
2640 : /*-----------------------------------------------------------------*
2641 : * Allocate and initialize HP20 filter memories
2642 : *-----------------------------------------------------------------*/
2643 :
2644 : /* set number of output channels used for synthesis/decoding */
2645 613 : n = getNumChanSynthesis( st_ivas );
2646 :
2647 613 : IF( n > 0 )
2648 : {
2649 613 : IF( ( st_ivas->mem_hp20_out_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL )
2650 : {
2651 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
2652 : }
2653 : }
2654 : ELSE
2655 : {
2656 0 : st_ivas->mem_hp20_out_fx = NULL;
2657 : }
2658 :
2659 2224 : FOR( i = 0; i < n; i++ )
2660 : {
2661 1611 : IF( ( st_ivas->mem_hp20_out_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL )
2662 : {
2663 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
2664 : }
2665 1611 : set32_fx( st_ivas->mem_hp20_out_fx[i], 0, L_HP20_MEM + 2 );
2666 : }
2667 :
2668 : /*-------------------------------------------------------------------*
2669 : * Allocate and initialize rendering handles
2670 : *--------------------------------------------------------------------*/
2671 613 : test();
2672 613 : test();
2673 613 : test();
2674 613 : test();
2675 613 : test();
2676 613 : test();
2677 613 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
2678 : {
2679 39 : IF( NE_32( ( error = ivas_binRenderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2680 : {
2681 0 : return error;
2682 : }
2683 : }
2684 : /* ParamISM is handled separately from other common config */
2685 574 : 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 ) ) )
2686 : {
2687 6 : IF( NE_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
2688 : {
2689 6 : IF( NE_32( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) )
2690 : {
2691 0 : return error;
2692 : }
2693 : }
2694 :
2695 : #ifdef NONBE_FIX_991_PARAMBIN_BINARY_HRTF
2696 6 : IF( NE_32( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, &( st_ivas->hHrtfParambin ) ) ), IVAS_ERR_OK ) )
2697 : #else
2698 : IF( NE_32( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) )
2699 : #endif
2700 : {
2701 0 : return error;
2702 : }
2703 : }
2704 568 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
2705 : {
2706 : Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
2707 : Word16 num_src;
2708 24 : IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) )
2709 : {
2710 0 : return error;
2711 : }
2712 24 : Word16 nchan_rend = num_src;
2713 24 : move16();
2714 24 : test();
2715 24 : IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
2716 : {
2717 3 : nchan_rend = sub( nchan_rend, 1 ); /* Skip LFE channel -- added to the others */
2718 : }
2719 98 : FOR( Word16 nS = 0; nS < nchan_rend; nS++ )
2720 : {
2721 74 : TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]];
2722 74 : if ( Src_p->SrcSpatial_p != NULL )
2723 : {
2724 74 : Src_p->SrcSpatial_p->q_Pos_p = Q31;
2725 74 : move16();
2726 : }
2727 74 : TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p;
2728 74 : SrcSpatial_p->q_Pos_p = Q31;
2729 74 : move16();
2730 : }
2731 :
2732 24 : IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
2733 : {
2734 3 : if ( NE_32( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hHrtfStatistics, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) )
2735 : {
2736 0 : return error;
2737 : }
2738 : }
2739 :
2740 24 : granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES );
2741 :
2742 24 : n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas );
2743 :
2744 :
2745 24 : 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 ) )
2746 : {
2747 0 : return error;
2748 : }
2749 : }
2750 544 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
2751 : {
2752 6 : IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2753 : {
2754 0 : return error;
2755 : }
2756 : }
2757 538 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
2758 : {
2759 9 : IF( NE_32( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ), IVAS_ERR_OK ) )
2760 : {
2761 0 : return error;
2762 : }
2763 : }
2764 529 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
2765 : {
2766 30 : test();
2767 30 : test();
2768 30 : test();
2769 30 : 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 ) )
2770 : {
2771 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 ) )
2772 : {
2773 0 : return error;
2774 : }
2775 : }
2776 :
2777 30 : IF( NE_32( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config,
2778 : st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hHrtfStatistics, st_ivas->hDecoderConfig->output_Fs, ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ) ),
2779 : IVAS_ERR_OK ) )
2780 : {
2781 0 : return error;
2782 : }
2783 :
2784 30 : st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns;
2785 30 : move32();
2786 :
2787 30 : test();
2788 30 : IF( ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) && ( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) )
2789 : {
2790 0 : granularity = NS2SA_FX2( output_Fs, CLDFB_SLOT_NS );
2791 0 : n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas );
2792 :
2793 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 ) )
2794 : {
2795 0 : return error;
2796 : }
2797 : }
2798 : ELSE
2799 : {
2800 30 : granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES );
2801 :
2802 30 : n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas );
2803 :
2804 30 : 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 ) )
2805 : {
2806 0 : return error;
2807 : }
2808 : }
2809 : }
2810 :
2811 613 : IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
2812 : {
2813 33 : test();
2814 33 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
2815 : {
2816 : /* Allocate TD renderer for the objects in DISC mode */
2817 : Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
2818 : Word16 num_src;
2819 :
2820 1 : IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) )
2821 : {
2822 0 : return error;
2823 : }
2824 :
2825 1 : Word16 nchan_rend = num_src;
2826 1 : move16();
2827 1 : test();
2828 1 : if ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
2829 : {
2830 0 : nchan_rend = sub( nchan_rend, 1 ); /* Skip LFE channel -- added to the others */
2831 : }
2832 5 : FOR( Word16 nS = 0; nS < nchan_rend; nS++ )
2833 : {
2834 4 : TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]];
2835 4 : if ( Src_p->SrcSpatial_p != NULL )
2836 : {
2837 4 : Src_p->SrcSpatial_p->q_Pos_p = Q31;
2838 4 : move16();
2839 : }
2840 4 : TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p;
2841 4 : SrcSpatial_p->q_Pos_p = Q31;
2842 4 : move16();
2843 : }
2844 :
2845 1 : IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
2846 : {
2847 0 : IF( NE_32( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hHrtfStatistics, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) )
2848 : {
2849 0 : return error;
2850 : }
2851 : }
2852 :
2853 : #ifdef FIX_1161_REDUCE_OMASA_HEAP
2854 : /* Allocate memory for delay buffer within 'hMasaIsmData' */
2855 1 : IF( NE_32( ( error = ivas_omasa_objects_delay_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2856 : {
2857 0 : return error;
2858 : }
2859 : #else
2860 : /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */
2861 : IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) )
2862 : {
2863 : return error;
2864 : }
2865 : #endif
2866 : }
2867 :
2868 33 : test();
2869 33 : test();
2870 33 : test();
2871 33 : 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 ) ) )
2872 : {
2873 : /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */
2874 : #ifdef FIX_1161_REDUCE_OMASA_HEAP
2875 9 : IF( NE_32( ( error = ivas_omasa_objects_delay_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2876 : {
2877 0 : return error;
2878 : }
2879 : #endif
2880 :
2881 9 : IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) )
2882 : {
2883 0 : return error;
2884 : }
2885 : }
2886 :
2887 : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
2888 33 : IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) )
2889 : {
2890 : /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */
2891 : #ifdef FIX_1161_REDUCE_OMASA_HEAP
2892 1 : IF( NE_32( ( error = ivas_omasa_objects_delay_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2893 : {
2894 0 : return error;
2895 : }
2896 : #else
2897 : error = ivas_omasa_render_objects_from_mix_open_fx( st_ivas );
2898 : move32();
2899 :
2900 : IF( NE_32( error, IVAS_ERR_OK ) )
2901 : {
2902 : return error;
2903 : }
2904 : #endif
2905 :
2906 1 : IF( ( ( error = ivas_spat_hSpatParamRendCom_config_fx( &st_ivas->hSpatParamRendCom, DIRAC_OPEN, 0, st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, 0, 0 ) ), IVAS_ERR_OK ) )
2907 : {
2908 : return error;
2909 : }
2910 : }
2911 :
2912 33 : IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) )
2913 : {
2914 : /* Allocate 'hIsmRendererData' handle */
2915 0 : IF( ( ( error = ivas_omasa_combine_separate_ism_with_masa_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2916 : {
2917 : return error;
2918 : }
2919 : }
2920 : #endif
2921 : }
2922 :
2923 613 : test();
2924 613 : test();
2925 613 : test();
2926 613 : test();
2927 613 : test();
2928 613 : test();
2929 613 : test();
2930 613 : test();
2931 613 : test();
2932 613 : test();
2933 613 : test();
2934 613 : test();
2935 613 : IF( ( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) &&
2936 : ( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) &&
2937 : ( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) ||
2938 : EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ||
2939 : EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ||
2940 : EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) ||
2941 : EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) ||
2942 : EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) ||
2943 : EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
2944 : EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
2945 : EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) )
2946 : {
2947 32 : IF( NE_32( ( error = ivas_ism_renderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
2948 : {
2949 0 : return error;
2950 : }
2951 : }
2952 :
2953 613 : IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
2954 : {
2955 34 : test();
2956 34 : test();
2957 34 : 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 ) )
2958 : {
2959 : /* Allocate TD renderer for the objects in DISC mode */
2960 : Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
2961 : Word16 num_src;
2962 7 : IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) )
2963 : {
2964 0 : return error;
2965 : }
2966 7 : Word16 nchan_rend = num_src;
2967 7 : move16();
2968 :
2969 7 : test();
2970 7 : if ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
2971 : {
2972 0 : nchan_rend = sub( nchan_rend, 1 ); /* Skip LFE channel -- added to the others */
2973 : }
2974 29 : FOR( Word16 nS = 0; nS < nchan_rend; nS++ )
2975 : {
2976 22 : TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]];
2977 22 : if ( Src_p->SrcSpatial_p != NULL )
2978 : {
2979 22 : Src_p->SrcSpatial_p->q_Pos_p = Q31;
2980 22 : move16();
2981 : }
2982 22 : TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p;
2983 22 : SrcSpatial_p->q_Pos_p = Q31;
2984 22 : move16();
2985 : }
2986 7 : IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
2987 : {
2988 2 : IF( NE_32( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hHrtfStatistics, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) )
2989 : {
2990 0 : return error;
2991 : }
2992 : }
2993 : }
2994 : }
2995 :
2996 : #ifndef NONBE_FIX_MC_LFE_LPF
2997 : /*-----------------------------------------------------------------*
2998 : * LFE handles for rendering after rendering to adjust LFE delay to binaural filter delay
2999 : * LFE handles for rendering after rendering to adjust LFE delay to filter delay
3000 : *-----------------------------------------------------------------*/
3001 : test();
3002 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
3003 : {
3004 : binauralization_delay_ns = st_ivas->binaural_latency_ns;
3005 : move32();
3006 : IF( st_ivas->hBinRenderer != NULL )
3007 : {
3008 : IF( st_ivas->hBinRenderer->render_lfe )
3009 : {
3010 : IF( NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
3011 : {
3012 : /* Account for filterbank delay */
3013 : binauralization_delay_ns = L_add( binauralization_delay_ns, IVAS_FB_DEC_DELAY_NS );
3014 : }
3015 : }
3016 : ELSE
3017 : {
3018 : binauralization_delay_ns = 0;
3019 : move32();
3020 : }
3021 : }
3022 :
3023 : IF( NE_32( ( error = ivas_create_lfe_dec_fx( &st_ivas->hLFE, output_Fs, binauralization_delay_ns ) ), IVAS_ERR_OK ) )
3024 : {
3025 : return error;
3026 : }
3027 :
3028 : set32_fx( st_ivas->hLFE->prevsynth_buf_fx, 0, LFE_PLC_BUFLEN );
3029 : set32_fx( st_ivas->hLFE->prior_out_buffer_fx, 0, L_FRAME48k );
3030 : }
3031 : #endif
3032 : /*-----------------------------------------------------------------*
3033 : * CLDFB handles for rendering
3034 : *-----------------------------------------------------------------*/
3035 :
3036 613 : ivas_init_dec_get_num_cldfb_instances_fx( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses );
3037 :
3038 2099 : FOR( i = 0; i < numCldfbAnalyses; i++ )
3039 : {
3040 1486 : IF( NE_32( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, output_Fs, CLDFB_PROTOTYPE_5_00MS, DEC ) ), IVAS_ERR_OK ) )
3041 : {
3042 0 : return error;
3043 : }
3044 : }
3045 8935 : FOR( ; i < MAX_INTERN_CHANNELS; i++ )
3046 : {
3047 8322 : st_ivas->cldfbAnaDec[i] = NULL;
3048 : }
3049 :
3050 2868 : FOR( i = 0; i < numCldfbSyntheses; i++ )
3051 : {
3052 2255 : IF( NE_32( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, output_Fs, CLDFB_PROTOTYPE_5_00MS, DEC ) ), IVAS_ERR_OK ) )
3053 : {
3054 0 : return error;
3055 : }
3056 : }
3057 8166 : FOR( ; i < MAX_OUTPUT_CHANNELS; i++ )
3058 : {
3059 7553 : st_ivas->cldfbSynDec[i] = NULL;
3060 : }
3061 :
3062 : /* CLDFB Interpolation weights */
3063 613 : test();
3064 613 : test();
3065 613 : test();
3066 613 : 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 ) )
3067 : {
3068 264 : Word16 Q_cldfbSynDec = Q11;
3069 264 : move16();
3070 264 : ivas_spar_get_cldfb_gains_fx( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig );
3071 :
3072 109164 : FOR( i = 0; i < st_ivas->cldfbAnaDec[0]->cldfb_state_length; i++ )
3073 : {
3074 108900 : 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
3075 108900 : move32();
3076 : }
3077 264 : st_ivas->cldfbAnaDec[0]->Q_cldfb_state = Q11;
3078 264 : move16();
3079 121264 : FOR( i = 0; i < st_ivas->cldfbSynDec[0]->cldfb_state_length; i++ )
3080 : {
3081 121000 : 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
3082 121000 : move32();
3083 : }
3084 264 : st_ivas->cldfbSynDec[0]->Q_cldfb_state = Q11;
3085 264 : move16();
3086 : }
3087 :
3088 : #ifdef NONBE_FIX_MC_LFE_LPF
3089 : /*-----------------------------------------------------------------*
3090 : * LFE handles for rendering after rendering to adjust LFE delay to filter delay
3091 : *-----------------------------------------------------------------*/
3092 :
3093 613 : test();
3094 613 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
3095 : {
3096 : #ifdef NONBE_1360_LFE_DELAY
3097 41 : IF( NE_16( st_ivas->hIntSetup.index_lfe[0], -1 ) )
3098 : {
3099 37 : delay_ns = st_ivas->binaural_latency_ns;
3100 : }
3101 : ELSE
3102 : {
3103 4 : delay_ns = 0;
3104 : }
3105 : #else
3106 : delay_ns = st_ivas->binaural_latency_ns;
3107 : #endif
3108 41 : move32();
3109 41 : IF( st_ivas->hBinRenderer != NULL )
3110 : {
3111 4 : IF( st_ivas->hBinRenderer->render_lfe )
3112 : {
3113 1 : IF( NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
3114 : {
3115 : /* Account for filterbank delay */
3116 1 : delay_ns = L_add( delay_ns, IVAS_FB_DEC_DELAY_NS );
3117 : }
3118 : }
3119 : ELSE
3120 : {
3121 3 : delay_ns = 0;
3122 3 : move32();
3123 : }
3124 : }
3125 : ELSE
3126 : {
3127 37 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) && ( st_ivas->cldfbSynDec[0] != NULL ) )
3128 : {
3129 1 : delay_ns = L_add( delay_ns, IVAS_FB_DEC_DELAY_NS );
3130 : }
3131 : }
3132 :
3133 41 : IF( NE_32( ( error = ivas_create_lfe_dec_fx( &st_ivas->hLFE, output_Fs, delay_ns ) ), IVAS_ERR_OK ) )
3134 : {
3135 0 : return error;
3136 : }
3137 :
3138 41 : set32_fx( st_ivas->hLFE->prevsynth_buf_fx, 0, LFE_PLC_BUFLEN );
3139 41 : set32_fx( st_ivas->hLFE->prior_out_buffer_fx, 0, L_FRAME48k );
3140 : }
3141 : #endif
3142 :
3143 : /*-----------------------------------------------------------------*
3144 : * Allocate and initialize limiter struct
3145 : *-----------------------------------------------------------------*/
3146 :
3147 613 : IF( NE_32( ( error = ivas_limiter_open_fx( &st_ivas->hLimiter, hDecoderConfig->nchan_out, output_Fs ) ), IVAS_ERR_OK ) )
3148 : {
3149 0 : return error;
3150 : }
3151 :
3152 : /*-----------------------------------------------------------------*
3153 : * Allocate and initialize JBM struct + buffer
3154 : *-----------------------------------------------------------------*/
3155 :
3156 613 : IF( st_ivas->hTcBuffer == NULL )
3157 : {
3158 : /* no module has yet open the TC buffer, open a default one */
3159 135 : n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas );
3160 :
3161 135 : 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 ) )
3162 : {
3163 0 : return error;
3164 : }
3165 : }
3166 :
3167 : #ifndef FIX_1101_CLEANING_JBM_CALL
3168 : IF( st_ivas->hTcBuffer == NULL )
3169 : {
3170 : /* we need the handle anyway, but without the buffer*/
3171 : IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_NONE, 0, 0, 0, 1 ) ), IVAS_ERR_OK ) )
3172 : {
3173 : return error;
3174 : }
3175 : }
3176 : #endif
3177 613 : test();
3178 : #ifdef FIX_1099_JBM_MD_HANDLE_ALLOC
3179 613 : test();
3180 613 : IF( ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && st_ivas->hDecoderConfig->Opt_tsm )
3181 : #else
3182 : IF( st_ivas->hJbmMetadata == NULL && st_ivas->hDecoderConfig->Opt_tsm )
3183 : #endif
3184 : {
3185 16 : IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
3186 : {
3187 3 : IF( NE_32( ( error = ivas_jbm_dec_metadata_open( st_ivas ) ), IVAS_ERR_OK ) )
3188 : {
3189 0 : return error;
3190 : }
3191 : }
3192 : }
3193 :
3194 : /*-----------------------------------------------------------------*
3195 : * Allocate floating-point output audio buffers
3196 : *-----------------------------------------------------------------*/
3197 :
3198 4273 : FOR( n = 0; n < ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ )
3199 : {
3200 : /* note: these are intra-frame heap memories */
3201 3660 : IF( ( st_ivas->p_output_fx[n] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ) ) == NULL )
3202 : {
3203 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) );
3204 : }
3205 3660 : set32_fx( st_ivas->p_output_fx[n], 0, 48000 / FRAMES_PER_SEC );
3206 : }
3207 9213 : FOR( ; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ )
3208 : {
3209 8600 : st_ivas->p_output_fx[n] = NULL;
3210 : }
3211 :
3212 613 : return error;
3213 : }
3214 :
3215 :
3216 : /*-------------------------------------------------------------------------
3217 : * destroy_core_dec()
3218 : *
3219 : * Close core decoder handles
3220 : *-------------------------------------------------------------------------*/
3221 :
3222 8160 : void destroy_core_dec_fx(
3223 : DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */
3224 : )
3225 : {
3226 8160 : IF( EQ_16( hCoreCoder->element_mode, EVS_MONO ) )
3227 : {
3228 3 : destroy_cldfb_decoder_fx( hCoreCoder );
3229 : }
3230 : ELSE
3231 : {
3232 8157 : destroy_cldfb_decoder_ivas_fx( hCoreCoder );
3233 : }
3234 :
3235 8160 : IF( hCoreCoder->hGSCDec != NULL )
3236 : {
3237 2663 : free( hCoreCoder->hGSCDec );
3238 2663 : hCoreCoder->hGSCDec = NULL;
3239 : }
3240 :
3241 8160 : IF( hCoreCoder->hPFstat != NULL )
3242 : {
3243 2663 : free( hCoreCoder->hPFstat );
3244 2663 : hCoreCoder->hPFstat = NULL;
3245 : }
3246 :
3247 8160 : IF( hCoreCoder->hMusicPF != NULL )
3248 : {
3249 2663 : free( hCoreCoder->hMusicPF );
3250 2663 : hCoreCoder->hMusicPF = NULL;
3251 : }
3252 :
3253 8160 : IF( hCoreCoder->hBPF != NULL )
3254 : {
3255 2663 : free( hCoreCoder->hBPF );
3256 2663 : hCoreCoder->hBPF = NULL;
3257 : }
3258 :
3259 8160 : IF( hCoreCoder->hBWE_zero != NULL )
3260 : {
3261 2663 : free( hCoreCoder->hBWE_zero );
3262 2663 : hCoreCoder->hBWE_zero = NULL;
3263 : }
3264 :
3265 8160 : IF( hCoreCoder->hTdCngDec != NULL )
3266 : {
3267 1433 : free( hCoreCoder->hTdCngDec );
3268 1433 : hCoreCoder->hTdCngDec = NULL;
3269 : }
3270 :
3271 8160 : IF( hCoreCoder->hSC_VBR != NULL )
3272 : {
3273 3 : free( hCoreCoder->hSC_VBR );
3274 3 : hCoreCoder->hSC_VBR = NULL;
3275 : }
3276 :
3277 8160 : IF( hCoreCoder->hAmrwb_IO != NULL )
3278 : {
3279 3 : free( hCoreCoder->hAmrwb_IO );
3280 3 : hCoreCoder->hAmrwb_IO = NULL;
3281 : }
3282 :
3283 8160 : IF( hCoreCoder->hBWE_TD != NULL )
3284 : {
3285 2692 : free( hCoreCoder->hBWE_TD );
3286 2692 : hCoreCoder->hBWE_TD = NULL;
3287 : }
3288 :
3289 8160 : IF( hCoreCoder->hBWE_FD != NULL )
3290 : {
3291 2692 : free( hCoreCoder->hBWE_FD );
3292 2692 : hCoreCoder->hBWE_FD = NULL;
3293 : }
3294 :
3295 8160 : IF( hCoreCoder->hBWE_FD_HR != NULL )
3296 : {
3297 3 : free( hCoreCoder->hBWE_FD_HR );
3298 3 : hCoreCoder->hBWE_FD_HR = NULL;
3299 : }
3300 :
3301 8160 : IF( hCoreCoder->hWIDec != NULL )
3302 : {
3303 0 : free( hCoreCoder->hWIDec );
3304 0 : hCoreCoder->hWIDec = NULL;
3305 : }
3306 :
3307 8160 : IF( hCoreCoder->hTECDec != NULL )
3308 : {
3309 3 : free( hCoreCoder->hTECDec );
3310 3 : hCoreCoder->hTECDec = NULL;
3311 : }
3312 :
3313 8160 : IF( hCoreCoder->hTcxLtpDec != NULL )
3314 : {
3315 8079 : free( hCoreCoder->hTcxLtpDec );
3316 8079 : hCoreCoder->hTcxLtpDec = NULL;
3317 : }
3318 :
3319 8160 : IF( hCoreCoder->hTcxDec != NULL )
3320 : {
3321 8079 : free( hCoreCoder->hTcxDec );
3322 8079 : hCoreCoder->hTcxDec = NULL;
3323 : }
3324 :
3325 8160 : IF( hCoreCoder->hTcxCfg != NULL )
3326 : {
3327 8079 : free( hCoreCoder->hTcxCfg );
3328 8079 : hCoreCoder->hTcxCfg = NULL;
3329 : }
3330 :
3331 8160 : IF( hCoreCoder->hTonalMDCTConc != NULL )
3332 : {
3333 8079 : free( hCoreCoder->hTonalMDCTConc );
3334 8079 : hCoreCoder->hTonalMDCTConc = NULL;
3335 : }
3336 :
3337 8160 : IF( hCoreCoder->hIGFDec != NULL )
3338 : {
3339 8079 : free( hCoreCoder->hIGFDec );
3340 8079 : hCoreCoder->hIGFDec = NULL;
3341 : }
3342 :
3343 8160 : IF( hCoreCoder->hPlcInfo != NULL )
3344 : {
3345 3 : free( hCoreCoder->hPlcInfo );
3346 3 : hCoreCoder->hPlcInfo = NULL;
3347 : }
3348 :
3349 8160 : IF( hCoreCoder->hHQ_core != NULL )
3350 : {
3351 8079 : free( hCoreCoder->hHQ_core );
3352 8079 : hCoreCoder->hHQ_core = NULL;
3353 : }
3354 :
3355 8160 : IF( hCoreCoder->hHQ_nbfec != NULL )
3356 : {
3357 3 : free( hCoreCoder->hHQ_nbfec );
3358 3 : hCoreCoder->hHQ_nbfec = NULL;
3359 : }
3360 :
3361 8160 : return;
3362 : }
3363 :
3364 : /*-------------------------------------------------------------------------
3365 : * ivas_initialize_handles_dec()
3366 : *
3367 : * NULL initialization of handles
3368 : *-------------------------------------------------------------------------*/
3369 :
3370 613 : void ivas_initialize_handles_dec(
3371 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
3372 : )
3373 : {
3374 : Word16 i;
3375 :
3376 10421 : FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ )
3377 : {
3378 9808 : st_ivas->cldfbAnaDec[i] = NULL;
3379 : }
3380 :
3381 10421 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
3382 : {
3383 9808 : st_ivas->cldfbSynDec[i] = NULL;
3384 : }
3385 :
3386 : /* SCE handles */
3387 3065 : FOR( i = 0; i < MAX_SCE; i++ )
3388 : {
3389 2452 : st_ivas->hSCE[i] = NULL;
3390 : }
3391 :
3392 : /* CPE handles */
3393 4291 : FOR( i = 0; i < MAX_CPE; i++ )
3394 : {
3395 3678 : st_ivas->hCPE[i] = NULL;
3396 : }
3397 :
3398 613 : st_ivas->bit_stream = NULL;
3399 613 : st_ivas->mem_hp20_out_fx = NULL;
3400 613 : st_ivas->hLimiter = NULL;
3401 :
3402 : /* ISM metadata handles */
3403 3065 : FOR( i = 0; i < MAX_NUM_OBJECTS; i++ )
3404 : {
3405 2452 : st_ivas->hIsmMetaData[i] = NULL;
3406 : }
3407 :
3408 : /* spatial coding handles */
3409 613 : st_ivas->hDirAC = NULL;
3410 613 : st_ivas->hParamIsmDec = NULL;
3411 613 : st_ivas->hSpar = NULL;
3412 613 : st_ivas->hMasa = NULL;
3413 613 : st_ivas->hQMetaData = NULL;
3414 613 : st_ivas->hMCT = NULL;
3415 613 : st_ivas->hMCParamUpmix = NULL;
3416 613 : st_ivas->hParamMC = NULL;
3417 613 : st_ivas->hLFE = NULL;
3418 :
3419 : /* rendering handles */
3420 613 : st_ivas->hBinRenderer = NULL;
3421 5517 : for ( i = 0; i < MAX_HEAD_ROT_POSES; i++ )
3422 : {
3423 4904 : st_ivas->hDiracDecBin[i] = NULL;
3424 : }
3425 613 : st_ivas->hDirACRend = NULL;
3426 613 : st_ivas->hSpatParamRendCom = NULL;
3427 613 : st_ivas->hLsSetUpConversion = NULL;
3428 613 : st_ivas->hEFAPdata = NULL;
3429 613 : st_ivas->hVBAPdata = NULL;
3430 613 : st_ivas->hIsmRendererData = NULL;
3431 613 : st_ivas->hBinRendererTd = NULL;
3432 613 : st_ivas->hMonoDmxRenderer = NULL;
3433 613 : st_ivas->hCrendWrapper = NULL;
3434 613 : st_ivas->hReverb = NULL;
3435 613 : st_ivas->hSetOfHRTF = NULL;
3436 613 : st_ivas->hHrtfFastConv = NULL;
3437 613 : st_ivas->hHrtfParambin = NULL;
3438 613 : st_ivas->hHrtfStatistics = NULL;
3439 613 : st_ivas->hoa_dec_mtx = NULL;
3440 613 : st_ivas->hMasaIsmData = NULL;
3441 613 : st_ivas->hSbaIsmData = NULL;
3442 :
3443 613 : st_ivas->hHeadTrackData = NULL;
3444 613 : st_ivas->hHrtfTD = NULL;
3445 613 : st_ivas->hLsSetupCustom = NULL;
3446 613 : st_ivas->hRenderConfig = NULL;
3447 613 : st_ivas->hExtOrientationData = NULL;
3448 613 : st_ivas->hCombinedOrientationData = NULL;
3449 :
3450 613 : st_ivas->hSplitBinRend = NULL;
3451 4904 : for ( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i )
3452 : {
3453 4291 : st_ivas->hTdRendHandles[i] = NULL;
3454 : }
3455 : /* JBM handles */
3456 613 : st_ivas->hTcBuffer = NULL;
3457 613 : st_ivas->hJbmMetadata = NULL;
3458 :
3459 : /* floating-point output audio buffers */
3460 12873 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ )
3461 : {
3462 12260 : st_ivas->p_output_fx[i] = NULL;
3463 : }
3464 :
3465 613 : return;
3466 : }
3467 :
3468 :
3469 : /*-------------------------------------------------------------------------
3470 : * ivas_destroy_dec()
3471 : *
3472 : * Close IVAS decoder handles
3473 : *-------------------------------------------------------------------------*/
3474 :
3475 613 : void ivas_destroy_dec_fx(
3476 : Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */
3477 : )
3478 : {
3479 : Word16 i;
3480 :
3481 : /* CLDFB handles */
3482 10421 : FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ )
3483 : {
3484 9808 : IF( st_ivas->cldfbAnaDec[i] != NULL )
3485 : {
3486 1521 : deleteCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ) );
3487 : }
3488 : }
3489 :
3490 10421 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
3491 : {
3492 9808 : IF( st_ivas->cldfbSynDec[i] != NULL )
3493 : {
3494 2244 : deleteCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ) );
3495 : }
3496 : }
3497 :
3498 : /* SCE handles */
3499 3065 : FOR( i = 0; i < MAX_SCE; i++ )
3500 : {
3501 2452 : IF( st_ivas->hSCE[i] != NULL )
3502 : {
3503 384 : destroy_sce_dec( st_ivas->hSCE[i] );
3504 384 : st_ivas->hSCE[i] = NULL;
3505 : }
3506 : }
3507 :
3508 : /* CPE handles */
3509 4291 : FOR( i = 0; i < MAX_CPE; i++ )
3510 : {
3511 3678 : IF( st_ivas->hCPE[i] != NULL )
3512 : {
3513 : /* set pointer to NULL as core coder already deallocated in destroy_sce_dec() */
3514 732 : test();
3515 732 : IF( st_ivas->sba_dirac_stereo_flag && EQ_16( st_ivas->nchan_transport, 1 ) )
3516 : {
3517 5 : st_ivas->hCPE[i]->hCoreCoder[0] = NULL;
3518 5 : st_ivas->hCPE[i]->hCoreCoder[1] = NULL;
3519 : }
3520 732 : destroy_cpe_dec( st_ivas->hCPE[i] );
3521 732 : st_ivas->hCPE[i] = NULL;
3522 : }
3523 : }
3524 :
3525 : /* HP20 filter handles */
3526 613 : IF( st_ivas->mem_hp20_out_fx != NULL )
3527 : {
3528 2392 : FOR( i = 0; i < getNumChanSynthesis( st_ivas ); i++ )
3529 : {
3530 1779 : free( st_ivas->mem_hp20_out_fx[i] );
3531 1779 : st_ivas->mem_hp20_out_fx[i] = NULL;
3532 : }
3533 613 : free( st_ivas->mem_hp20_out_fx );
3534 613 : st_ivas->mem_hp20_out_fx = NULL;
3535 : }
3536 :
3537 : /* ISM metadata handles */
3538 613 : ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 );
3539 :
3540 : /* ISM renderer handle */
3541 613 : ivas_ism_renderer_close( &( st_ivas->hIsmRendererData ) );
3542 :
3543 : /* DirAC handle */
3544 613 : IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
3545 : {
3546 68 : ivas_param_ism_dec_close_fx( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config );
3547 : }
3548 : ELSE
3549 : {
3550 545 : ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) );
3551 545 : ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) );
3552 545 : ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) );
3553 : }
3554 :
3555 : /* SPAR handle */
3556 613 : ivas_spar_dec_close_fx( &( st_ivas->hSpar ), st_ivas->hDecoderConfig->output_Fs, 0 );
3557 :
3558 : /* HOA decoder matrix */
3559 613 : IF( st_ivas->hoa_dec_mtx != NULL )
3560 : {
3561 27 : free( st_ivas->hoa_dec_mtx );
3562 27 : st_ivas->hoa_dec_mtx = NULL;
3563 : }
3564 :
3565 : /* MASA decoder structure */
3566 613 : ivas_masa_dec_close_fx( &( st_ivas->hMasa ) );
3567 :
3568 : /* Qmetadata handle */
3569 613 : ivas_qmetadata_close_fx( &st_ivas->hQMetaData );
3570 :
3571 : /* MCT handle */
3572 613 : ivas_mct_dec_close( &st_ivas->hMCT );
3573 :
3574 : /* LFE handle */
3575 613 : ivas_lfe_dec_close_fx( &( st_ivas->hLFE ) );
3576 :
3577 : /* Param-Upmix MC handle */
3578 613 : ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) );
3579 :
3580 : /* Parametric MC handle */
3581 613 : ivas_param_mc_dec_close_fx( &st_ivas->hParamMC );
3582 :
3583 : /* EFAP handle */
3584 613 : efap_free_data_fx( &st_ivas->hEFAPdata );
3585 :
3586 : /* VBAP handle */
3587 613 : vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
3588 :
3589 : /* Fastconv binaural renderer handle */
3590 613 : ivas_binRenderer_close_fx( &st_ivas->hBinRenderer );
3591 :
3592 : /* TD binaural renderer handles */
3593 4904 : for ( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i )
3594 : {
3595 4291 : if ( st_ivas->hTdRendHandles[i] != NULL )
3596 : {
3597 0 : st_ivas->hTdRendHandles[i]->HrFiltSet_p = NULL;
3598 0 : ivas_td_binaural_close_fx( &st_ivas->hTdRendHandles[i] );
3599 : }
3600 : }
3601 :
3602 : /* Parametric binaural renderer handle */
3603 613 : ivas_dirac_dec_close_binaural_data( st_ivas->hDiracDecBin );
3604 :
3605 : /* Crend handle */
3606 613 : ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ), ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses );
3607 :
3608 : /* Reverb handle */
3609 613 : ivas_reverb_close( &st_ivas->hReverb );
3610 :
3611 : /* LS config converter handle */
3612 :
3613 613 : ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
3614 : /* Custom LS configuration handle */
3615 613 : IF( st_ivas->hLsSetupCustom != NULL )
3616 : {
3617 3 : free( st_ivas->hLsSetupCustom );
3618 3 : st_ivas->hLsSetupCustom = NULL;
3619 : }
3620 :
3621 : /* Mono downmix structure */
3622 613 : ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer );
3623 :
3624 : /* OSBA structure */
3625 613 : ivas_osba_data_close_fx( &st_ivas->hSbaIsmData );
3626 :
3627 : /* OMASA structure */
3628 613 : ivas_omasa_data_close_fx( &st_ivas->hMasaIsmData );
3629 :
3630 : /* Head track data handle */
3631 613 : ivas_headTrack_close_fx( &st_ivas->hHeadTrackData );
3632 :
3633 : /* External orientation data handle */
3634 613 : ivas_external_orientation_close_fx( &st_ivas->hExtOrientationData );
3635 :
3636 : /* Combined orientation data handle */
3637 613 : ivas_combined_orientation_close_fx( &st_ivas->hCombinedOrientationData );
3638 :
3639 : /* Time Domain binaural renderer handle */
3640 613 : IF( st_ivas->hBinRendererTd != NULL )
3641 : {
3642 37 : ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd );
3643 : }
3644 576 : ELSE IF( st_ivas->hHrtfTD != NULL )
3645 : {
3646 0 : BSplineModelEvalDealloc_fx( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval );
3647 0 : ivas_HRTF_binary_close_fx( &st_ivas->hHrtfTD );
3648 : }
3649 :
3650 : /* CRend binaural renderer handle */
3651 613 : ivas_HRTF_CRend_binary_close_fx( &st_ivas->hSetOfHRTF );
3652 :
3653 : /* Fastconv HRTF memories */
3654 613 : ivas_binaural_hrtf_close( &st_ivas->hHrtfFastConv );
3655 :
3656 : /* Fastconv HRTF filters */
3657 613 : ivas_HRTF_fastconv_binary_close_fx( &st_ivas->hHrtfFastConv );
3658 :
3659 : /* Parametric binauralizer HRTF filters */
3660 613 : ivas_HRTF_parambin_binary_close_fx( &st_ivas->hHrtfParambin );
3661 :
3662 : /* HRTF statistics */
3663 613 : ivas_HRTF_statistics_close( &st_ivas->hHrtfStatistics );
3664 :
3665 : /* Config. Renderer */
3666 613 : ivas_render_config_close( &( st_ivas->hRenderConfig ) );
3667 :
3668 : /* Limiter struct */
3669 613 : ivas_limiter_close_fx( &( st_ivas->hLimiter ) );
3670 :
3671 613 : IF( st_ivas->hDecoderConfig != NULL )
3672 : {
3673 613 : free( st_ivas->hDecoderConfig );
3674 613 : st_ivas->hDecoderConfig = NULL;
3675 : }
3676 :
3677 613 : ivas_jbm_dec_tc_buffer_close( &st_ivas->hTcBuffer );
3678 :
3679 613 : IF( st_ivas->hJbmMetadata != NULL )
3680 : {
3681 3 : free( st_ivas->hJbmMetadata );
3682 3 : st_ivas->hJbmMetadata = NULL;
3683 : }
3684 :
3685 : /* floating-point output audio buffers */
3686 12873 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ )
3687 : {
3688 :
3689 12260 : IF( st_ivas->p_output_fx[i] != NULL )
3690 : {
3691 3754 : free( st_ivas->p_output_fx[i] );
3692 3754 : st_ivas->p_output_fx[i] = NULL;
3693 : }
3694 : }
3695 :
3696 : /* main IVAS handle */
3697 613 : free( st_ivas );
3698 :
3699 613 : return;
3700 : }
3701 :
3702 :
3703 : /*-------------------------------------------------------------------*
3704 : * ivas_init_dec_get_num_cldfb_instances()
3705 : *
3706 : * Return number of CLDFB analysis & synthesis instances
3707 : *-------------------------------------------------------------------*/
3708 :
3709 : /*! r: number of cldfb instances */
3710 15170 : void ivas_init_dec_get_num_cldfb_instances_fx(
3711 : Decoder_Struct *st_ivas, /* i : IVAS decoder structure */
3712 : Word16 *numCldfbAnalyses, /* o : number of needed CLDFB analysis instances */
3713 : Word16 *numCldfbSyntheses /* o : number of needed CLDFB synthesis instances */
3714 : )
3715 : {
3716 : IVAS_FORMAT ivas_format;
3717 15170 : *numCldfbAnalyses = st_ivas->nchan_transport;
3718 15170 : move16();
3719 15170 : *numCldfbSyntheses = st_ivas->hDecoderConfig->nchan_out;
3720 15170 : move16();
3721 :
3722 15170 : test();
3723 15170 : IF( ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) )
3724 : {
3725 708 : ivas_format = SBA_FORMAT;
3726 708 : move32();
3727 : }
3728 : ELSE
3729 : {
3730 14462 : ivas_format = st_ivas->ivas_format;
3731 14462 : move32();
3732 : }
3733 :
3734 15170 : SWITCH( st_ivas->renderer_type )
3735 : {
3736 4459 : case RENDERER_BINAURAL_PARAMETRIC:
3737 : case RENDERER_BINAURAL_PARAMETRIC_ROOM:
3738 : case RENDERER_STEREO_PARAMETRIC:
3739 4459 : IF( EQ_16( st_ivas->nchan_transport, 1 ) )
3740 : {
3741 1247 : *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 );
3742 1247 : move16();
3743 : }
3744 :
3745 4459 : test();
3746 4459 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->hOutSetup.separateChannelEnabled )
3747 : {
3748 10 : *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 );
3749 10 : move16();
3750 : }
3751 :
3752 4459 : IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) )
3753 : {
3754 0 : IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
3755 : {
3756 0 : *numCldfbAnalyses = add( *numCldfbAnalyses, st_ivas->nchan_ism );
3757 0 : move16();
3758 : }
3759 : }
3760 :
3761 4459 : IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) )
3762 : {
3763 1430 : test();
3764 1430 : IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
3765 : {
3766 553 : *numCldfbAnalyses = add( *numCldfbAnalyses, st_ivas->nchan_ism );
3767 553 : move16();
3768 : }
3769 877 : 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 ) )
3770 : {
3771 877 : *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 );
3772 877 : move16();
3773 : }
3774 : }
3775 4459 : IF( st_ivas->hDiracDecBin[0]->useTdDecorr )
3776 : {
3777 1484 : *numCldfbAnalyses = add( *numCldfbAnalyses, 2 );
3778 1484 : move16();
3779 : }
3780 4459 : BREAK;
3781 338 : case RENDERER_NON_DIEGETIC_DOWNMIX:
3782 : case RENDERER_MONO_DOWNMIX:
3783 338 : test();
3784 338 : test();
3785 338 : IF( EQ_32( ivas_format, ISM_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) )
3786 : {
3787 : /* CLDFB not used in rendering */
3788 299 : *numCldfbAnalyses = 0;
3789 299 : move16();
3790 299 : *numCldfbSyntheses = 0;
3791 299 : move16();
3792 : }
3793 338 : BREAK;
3794 3675 : case RENDERER_DIRAC:
3795 3675 : IF( EQ_32( ivas_format, SBA_FORMAT ) )
3796 : {
3797 186 : *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans;
3798 186 : move16();
3799 :
3800 186 : test();
3801 186 : IF( st_ivas->hOutSetup.is_loudspeaker_setup && EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) )
3802 : {
3803 186 : *numCldfbSyntheses = st_ivas->hOutSetup.nchan_out_woLFE;
3804 186 : move16();
3805 : }
3806 0 : ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) )
3807 : {
3808 0 : *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans;
3809 0 : move16();
3810 : }
3811 : ELSE
3812 : {
3813 0 : *numCldfbSyntheses = MAX_OUTPUT_CHANNELS;
3814 0 : move16();
3815 : }
3816 : }
3817 3675 : IF( NE_32( ivas_format, SBA_FORMAT ) )
3818 : {
3819 3489 : test();
3820 3489 : test();
3821 3489 : IF( GT_16( st_ivas->nchan_transport, 2 ) && ( st_ivas->sba_planar != 0 ) )
3822 : {
3823 0 : *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 );
3824 0 : move16();
3825 : }
3826 3489 : ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_32( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
3827 : {
3828 383 : *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 );
3829 383 : move16();
3830 : }
3831 : }
3832 3675 : BREAK;
3833 174 : case RENDERER_MC_PARAMMC:
3834 174 : IF( LE_16( st_ivas->hDecoderConfig->nchan_out, 2 ) )
3835 : {
3836 : /* CLDFB not used in rendering */
3837 4 : *numCldfbAnalyses = 0;
3838 4 : move16();
3839 4 : *numCldfbSyntheses = 0;
3840 4 : move16();
3841 : }
3842 : ELSE
3843 : {
3844 170 : *numCldfbSyntheses = param_mc_get_num_cldfb_syntheses_fx( st_ivas );
3845 170 : move16();
3846 : }
3847 174 : BREAK;
3848 107 : case RENDERER_PARAM_ISM:
3849 : /* Already correct with no exception */
3850 107 : BREAK;
3851 1808 : case RENDERER_DISABLE:
3852 : /* CLDFB not used */
3853 1808 : *numCldfbAnalyses = 0;
3854 1808 : move16();
3855 1808 : *numCldfbSyntheses = 0;
3856 1808 : move16();
3857 1808 : BREAK;
3858 3837 : case RENDERER_MC:
3859 : case RENDERER_SBA_LINEAR_DEC:
3860 : case RENDERER_TD_PANNING:
3861 : case RENDERER_BINAURAL_OBJECTS_TD:
3862 : case RENDERER_MCMASA_MONO_STEREO:
3863 : case RENDERER_BINAURAL_MIXER_CONV:
3864 : case RENDERER_BINAURAL_MIXER_CONV_ROOM:
3865 : case RENDERER_BINAURAL_FASTCONV:
3866 : case RENDERER_BINAURAL_FASTCONV_ROOM:
3867 : case RENDERER_OSBA_STEREO:
3868 : case RENDERER_OSBA_AMBI:
3869 : case RENDERER_OSBA_LS:
3870 3837 : test();
3871 3837 : IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) )
3872 : {
3873 2170 : IF( st_ivas->sba_dirac_stereo_flag != 0 )
3874 : {
3875 72 : *numCldfbAnalyses = 0;
3876 72 : move16();
3877 72 : *numCldfbSyntheses = 0;
3878 72 : move16();
3879 : }
3880 : ELSE
3881 : {
3882 2098 : *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans;
3883 2098 : move16();
3884 :
3885 2098 : test();
3886 2098 : IF( st_ivas->hOutSetup.is_loudspeaker_setup && EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) )
3887 : {
3888 0 : *numCldfbSyntheses = st_ivas->hOutSetup.nchan_out_woLFE;
3889 0 : move16();
3890 : }
3891 2098 : ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) )
3892 : {
3893 556 : *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans;
3894 556 : move16();
3895 : }
3896 : ELSE
3897 : {
3898 1542 : *numCldfbSyntheses = MAX_OUTPUT_CHANNELS;
3899 1542 : move16();
3900 : }
3901 2098 : test();
3902 2098 : IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
3903 : {
3904 3 : *numCldfbAnalyses = add( st_ivas->nchan_ism, st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans );
3905 3 : move16();
3906 : }
3907 : }
3908 : }
3909 1667 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
3910 : {
3911 : /* do nothing for ParamMC */
3912 : }
3913 : ELSE
3914 : {
3915 : /* CLDFB not used in rendering */
3916 1308 : *numCldfbAnalyses = 0;
3917 1308 : move16();
3918 1308 : *numCldfbSyntheses = 0;
3919 1308 : move16();
3920 : }
3921 3837 : BREAK;
3922 660 : case RENDERER_SBA_LINEAR_ENC:
3923 660 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
3924 : {
3925 144 : *numCldfbSyntheses = param_mc_get_num_cldfb_syntheses_fx( st_ivas );
3926 144 : move16();
3927 : }
3928 516 : ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
3929 : {
3930 44 : *numCldfbSyntheses = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
3931 44 : move16();
3932 : }
3933 472 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
3934 : {
3935 116 : *numCldfbAnalyses = st_ivas->nchan_transport;
3936 116 : move16();
3937 116 : *numCldfbSyntheses = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
3938 116 : move16();
3939 : }
3940 : ELSE
3941 : {
3942 : /* CLDFB not used in rendering */
3943 356 : *numCldfbAnalyses = 0;
3944 356 : move16();
3945 356 : *numCldfbSyntheses = 0;
3946 356 : move16();
3947 : }
3948 660 : BREAK;
3949 : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
3950 58 : case RENDERER_OMASA_OBJECT_EXT:
3951 58 : *numCldfbAnalyses = st_ivas->nchan_transport;
3952 58 : *numCldfbSyntheses = st_ivas->hDecoderConfig->nchan_out;
3953 58 : move16();
3954 58 : move16();
3955 58 : BREAK;
3956 54 : case RENDERER_OMASA_MIX_EXT:
3957 54 : *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 );
3958 54 : *numCldfbSyntheses = 0;
3959 54 : move16();
3960 54 : BREAK;
3961 : #endif
3962 0 : default:
3963 0 : assert( 0 && "Renderer not handled for CLDFB reservation." );
3964 : }
3965 :
3966 15170 : test();
3967 15170 : test();
3968 15170 : 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 ) )
3969 : {
3970 14 : test();
3971 14 : test();
3972 14 : 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 ) )
3973 : {
3974 7 : *numCldfbAnalyses = s_max( MC_PARAMUPMIX_MAX_INPUT_CHANS, *numCldfbAnalyses );
3975 7 : move16();
3976 : }
3977 : ELSE
3978 : {
3979 7 : *numCldfbAnalyses = s_max( MC_PARAMUPMIX_MIN_CLDFB, *numCldfbAnalyses );
3980 7 : move16();
3981 : }
3982 14 : *numCldfbSyntheses = s_max( MC_PARAMUPMIX_MIN_CLDFB, *numCldfbSyntheses );
3983 14 : move16();
3984 : }
3985 :
3986 15170 : return;
3987 : }
3988 :
3989 :
3990 : /*---------------------------------------------------------------------*
3991 : * doSanityChecks_IVAS()
3992 : *
3993 : * Sanity checks - verify if the decoder set-up parameters are
3994 : * not in conflict with the IVAS format
3995 : *---------------------------------------------------------------------*/
3996 :
3997 610 : static ivas_error doSanityChecks_IVAS(
3998 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
3999 : )
4000 : {
4001 : Word32 output_Fs;
4002 : AUDIO_CONFIG output_config;
4003 :
4004 610 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
4005 610 : move32();
4006 610 : output_config = st_ivas->hDecoderConfig->output_config;
4007 610 : move32();
4008 : /*-----------------------------------------------------------------*
4009 : * Sanity checks
4010 : *-----------------------------------------------------------------*/
4011 :
4012 610 : IF( EQ_32( output_Fs, 8000 ) )
4013 : {
4014 0 : return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "8kHz output sampling rate is not supported in IVAS." );
4015 : }
4016 :
4017 610 : assert( st_ivas->ivas_format != UNDEFINED_FORMAT && "\n IVAS format undefined" );
4018 610 : assert( st_ivas->ivas_format != MONO_FORMAT && "\n Wrong IVAS format: MONO" );
4019 :
4020 : /* Verify output configuration compatible with non-diegetic panning */
4021 610 : test();
4022 610 : test();
4023 610 : 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 ) )
4024 : {
4025 0 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Error: Non-diegetic panning not supported in this IVAS format" );
4026 : }
4027 :
4028 : /* Verify stereo output configuration */
4029 610 : IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
4030 : {
4031 68 : test();
4032 68 : test();
4033 68 : test();
4034 68 : test();
4035 68 : test();
4036 68 : test();
4037 68 : test();
4038 : #ifdef FIX_1052_EXT_OUTPUT
4039 68 : test();
4040 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 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
4041 : #else
4042 : 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 ) )
4043 : #endif
4044 : {
4045 0 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Wrong output configuration specified for Stereo!" );
4046 : }
4047 : }
4048 : #ifdef FIX_1052_EXT_OUTPUT
4049 : /* Verify output configuration for other formats */
4050 : ELSE
4051 : {
4052 542 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) )
4053 : {
4054 0 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified!" );
4055 : }
4056 : }
4057 : #else
4058 : ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
4059 : {
4060 : /* Verify ISM output configuration */
4061 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) )
4062 : {
4063 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for ISM" );
4064 : }
4065 : }
4066 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
4067 : {
4068 : /* Verify SBA output coniguration */
4069 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) )
4070 : {
4071 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for SBA" );
4072 : }
4073 : }
4074 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
4075 : {
4076 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) )
4077 : {
4078 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for MASA!" );
4079 : }
4080 : }
4081 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
4082 : {
4083 : /* Verify MC output configuration */
4084 : test();
4085 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
4086 : {
4087 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for Multi-channel" );
4088 : }
4089 : }
4090 : #endif
4091 :
4092 610 : IF( ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) && NE_32( output_Fs, 48000 ) )
4093 : {
4094 0 : return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Error: Only 48kHz output sampling rate is supported for split rendering." );
4095 : }
4096 :
4097 610 : IF( st_ivas->hDecoderConfig->Opt_Headrotation )
4098 : {
4099 82 : test();
4100 82 : test();
4101 82 : 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 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) )
4102 : {
4103 0 : return IVAS_ERROR( IVAS_ERR_HEAD_ROTATION_NOT_SUPPORTED, "Wrong set-up: Head-rotation not supported in this configuration" );
4104 : }
4105 : }
4106 :
4107 610 : IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation )
4108 : {
4109 31 : test();
4110 31 : test();
4111 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 ) ) )
4112 : {
4113 0 : return IVAS_ERROR( IVAS_ERR_EXT_ORIENTATION_NOT_SUPPORTED, "Wrong set-up: External orientation not supported in this configuration" );
4114 : }
4115 : }
4116 :
4117 610 : IF( st_ivas->hDecoderConfig->Opt_dpid_on )
4118 : {
4119 2 : test();
4120 2 : IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) )
4121 : {
4122 0 : return IVAS_ERROR( IVAS_ERR_DIRECTIVITY_NOT_SUPPORTED, "Wrong set-up: Directivity is not supported in this output configuration." );
4123 : }
4124 : }
4125 :
4126 610 : IF( st_ivas->hDecoderConfig->Opt_aeid_on )
4127 : {
4128 4 : IF( NE_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
4129 : {
4130 0 : return IVAS_ERROR( IVAS_ERR_ACOUSTIC_ENVIRONMENT_NOT_SUPPORTED, "Wrong set-up: Acoustic environment is not supported in this output configuration." );
4131 : }
4132 : }
4133 :
4134 : #ifndef NONBE_FIX_984_OMASA_EXT_OUTPUT
4135 : IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
4136 : {
4137 : test();
4138 : IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
4139 : {
4140 :
4141 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for combined MASA and ISM format" );
4142 : }
4143 : }
4144 : #endif
4145 610 : return IVAS_ERR_OK;
4146 : }
|