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