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 5622 : 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 5622 : output_config = IVAS_AUDIO_CONFIG_HOA3;
72 :
73 5622 : switch ( sba_order )
74 : {
75 1870 : case SBA_FOA_ORDER:
76 1870 : output_config = IVAS_AUDIO_CONFIG_FOA;
77 1870 : break;
78 1872 : case SBA_HOA2_ORDER:
79 1872 : output_config = IVAS_AUDIO_CONFIG_HOA2;
80 1872 : break;
81 1880 : case SBA_HOA3_ORDER:
82 1880 : output_config = IVAS_AUDIO_CONFIG_HOA3;
83 1880 : break;
84 0 : default:
85 0 : output_config = IVAS_AUDIO_CONFIG_INVALID;
86 0 : break;
87 : }
88 :
89 5622 : 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 5262628 : 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 5262628 : num_bits_read = 0;
114 5262628 : element_mode_flag = 0;
115 :
116 5262628 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
117 5262628 : bit_stream_orig = st_ivas->bit_stream;
118 :
119 : /*-------------------------------------------------------------------*
120 : * Read IVAS format
121 : *-------------------------------------------------------------------*/
122 :
123 5262628 : if ( ( error = ivas_read_format( st_ivas, &num_bits_read ) ) != IVAS_ERR_OK )
124 : {
125 0 : return error;
126 : }
127 :
128 5262628 : if ( st_ivas->ini_frame > 0 && st_ivas->ivas_format != st_ivas->last_ivas_format &&
129 4236 : !( st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format == MASA_ISM_FORMAT ) &&
130 2121 : !( 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 5262628 : 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 5207483 : if ( st_ivas->ivas_format == STEREO_FORMAT )
153 : {
154 251183 : element_mode_flag = 1;
155 : }
156 4956300 : else if ( st_ivas->ivas_format == ISM_FORMAT )
157 : {
158 : /* read the number of objects */
159 1072545 : nchan_ism = 1;
160 1072545 : k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 );
161 2953157 : while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS )
162 : {
163 1880612 : nchan_ism++;
164 1880612 : k--;
165 : }
166 :
167 1072545 : 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 1072545 : st_ivas->nchan_ism = nchan_ism;
176 1072545 : st_ivas->ism_mode = ivas_ism_mode_select( nchan_ism, ivas_total_brate );
177 :
178 1072545 : st_ivas->nchan_transport = nchan_ism;
179 1072545 : if ( st_ivas->ism_mode == ISM_MODE_PARAM )
180 : {
181 140993 : st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE;
182 : }
183 : }
184 3883755 : else if ( st_ivas->ivas_format == SBA_FORMAT )
185 : {
186 : /* read Ambisonic (SBA) planar flag */
187 921637 : sba_planar = st_ivas->bit_stream[num_bits_read];
188 921637 : num_bits_read += SBA_PLANAR_BITS;
189 :
190 921637 : 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 921637 : sba_order = st_ivas->bit_stream[num_bits_read + 1];
200 921637 : sba_order += 2 * st_ivas->bit_stream[num_bits_read];
201 :
202 921637 : 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 921637 : sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, sba_order );
211 921637 : st_ivas->nchan_transport = ivas_get_sba_num_TCs( ivas_total_brate, sba_analysis_order );
212 : }
213 2962118 : else if ( st_ivas->ivas_format == MASA_FORMAT )
214 : {
215 : /* read number of MASA transport channels */
216 453091 : if ( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] )
217 : {
218 197037 : st_ivas->nchan_transport = 2;
219 197037 : element_mode_flag = 1;
220 : }
221 : else
222 : {
223 256054 : st_ivas->nchan_transport = 1;
224 : }
225 :
226 : /* this should be non-zero if original input format was MASA_ISM_FORMAT */
227 453091 : st_ivas->ism_mode = ISM_MODE_NONE;
228 453091 : 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 453091 : 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 125438 : nchan_ism = 5 - nchan_ism;
241 125438 : if ( st_ivas->nchan_transport == 1 && nchan_ism == 2 )
242 : {
243 27769 : 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 125438 : st_ivas->nchan_transport = 2;
248 125438 : element_mode_flag = 1;
249 : }
250 :
251 453091 : 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 453091 : st_ivas->nchan_ism = nchan_ism;
260 : }
261 2509027 : else if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
262 : {
263 423830 : 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 423830 : 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 423830 : st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, nchan_ism );
268 :
269 423830 : 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 423830 : st_ivas->nchan_ism = nchan_ism;
278 : }
279 2085197 : 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 1559268 : 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 1559268 : 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 1559268 : st_ivas->nchan_ism = nchan_ism;
293 :
294 : /* read Ambisonic (SBA) planar flag */
295 : /*sba_planar = st_ivas->bit_stream[num_bits_read];*/
296 1559268 : num_bits_read += SBA_PLANAR_BITS;
297 :
298 : /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/
299 1559268 : sba_order = st_ivas->bit_stream[num_bits_read + 1];
300 1559268 : sba_order += 2 * st_ivas->bit_stream[num_bits_read];
301 1559268 : num_bits_read += SBA_ORDER_BITS;
302 :
303 : /* read the real Ambisonic order when the above bits are used to signal OSBA format */
304 1559268 : if ( ivas_total_brate < IVAS_24k4 )
305 : {
306 250869 : sba_order = st_ivas->bit_stream[num_bits_read + 1];
307 250869 : sba_order += 2 * st_ivas->bit_stream[num_bits_read];
308 250869 : num_bits_read += SBA_ORDER_BITS;
309 : }
310 :
311 1559268 : 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 1559268 : st_ivas->ism_mode = ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism );
320 :
321 1559268 : sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, sba_order );
322 1559268 : st_ivas->nchan_transport = ivas_get_sba_num_TCs( ivas_total_brate, sba_analysis_order );
323 : }
324 525929 : else if ( st_ivas->ivas_format == MC_FORMAT )
325 : {
326 : /* read MC configuration */
327 525929 : idx = 0;
328 2103716 : for ( k = 0; k < MC_LS_SETUP_BITS; k++ )
329 : {
330 1577787 : if ( st_ivas->bit_stream[num_bits_read + k] )
331 : {
332 341391 : idx += 1 << ( MC_LS_SETUP_BITS - 1 - k );
333 : }
334 : }
335 525929 : num_bits_read += MC_LS_SETUP_BITS;
336 :
337 525929 : signaled_config = ivas_mc_map_ls_setup_to_output_config( idx );
338 :
339 525929 : 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 525929 : 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 525929 : st_ivas->transport_config = signaled_config;
349 : }
350 :
351 : /*-------------------------------------------------------------------*
352 : * Read element mode
353 : *-------------------------------------------------------------------*/
354 :
355 5207483 : if ( st_ivas->ini_frame == 0 && element_mode_flag )
356 : {
357 : /* read stereo technology info */
358 7120 : if ( ivas_total_brate < MIN_BRATE_MDCT_STEREO )
359 : {
360 : /* 1 bit */
361 4354 : 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 4354 : st_ivas->element_mode_init = 0 + IVAS_CPE_DFT;
368 : }
369 : }
370 : else
371 : {
372 2766 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
373 : }
374 : }
375 : }
376 55145 : else if ( ivas_total_brate == IVAS_SID_5k2 )
377 : {
378 9257 : switch ( st_ivas->sid_format )
379 : {
380 4299 : case SID_DFT_STEREO:
381 4299 : st_ivas->element_mode_init = IVAS_CPE_DFT;
382 4299 : break;
383 1313 : case SID_MDCT_STEREO:
384 1313 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
385 1313 : break;
386 1984 : case SID_ISM:
387 1984 : st_ivas->element_mode_init = IVAS_SCE;
388 1984 : break;
389 393 : case SID_MASA_1TC:
390 393 : st_ivas->element_mode_init = IVAS_SCE;
391 393 : st_ivas->nchan_transport = 1;
392 393 : break;
393 222 : case SID_MASA_2TC:
394 222 : if ( st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS] == 1 )
395 : {
396 0 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
397 : }
398 : else
399 : {
400 222 : st_ivas->element_mode_init = IVAS_CPE_DFT;
401 : }
402 222 : st_ivas->nchan_transport = 2;
403 222 : break;
404 497 : case SID_SBA_1TC:
405 497 : st_ivas->element_mode_init = IVAS_SCE;
406 497 : break;
407 549 : case SID_SBA_2TC:
408 549 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
409 549 : break;
410 : }
411 :
412 9257 : if ( st_ivas->ivas_format == ISM_FORMAT )
413 : {
414 : /* read the number of objects */
415 1984 : nchan_ism = 1;
416 1984 : k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 - SID_FORMAT_NBITS );
417 6829 : while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS )
418 : {
419 4845 : nchan_ism++;
420 4845 : k--;
421 : }
422 1984 : k--;
423 :
424 1984 : 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 1984 : st_ivas->nchan_ism = nchan_ism;
433 :
434 : /* read ism_mode */
435 1984 : st_ivas->ism_mode = ISM_MODE_DISC;
436 1984 : if ( nchan_ism > 2 )
437 : {
438 1504 : k -= nchan_ism; /* SID metadata flags */
439 1504 : idx = st_ivas->bit_stream[k];
440 1504 : st_ivas->ism_mode = (ISM_MODE) ( idx + 1 );
441 : }
442 :
443 1984 : st_ivas->nchan_transport = nchan_ism;
444 1984 : if ( st_ivas->ism_mode == ISM_MODE_PARAM )
445 : {
446 661 : st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE;
447 : }
448 : }
449 : }
450 :
451 5262628 : st_ivas->bit_stream = bit_stream_orig;
452 :
453 5262628 : return IVAS_ERR_OK;
454 : }
455 :
456 :
457 : /*-------------------------------------------------------------------*
458 : * ivas_dec_setup()
459 : *
460 : * IVAS decoder setup
461 : *-------------------------------------------------------------------*/
462 :
463 5267191 : 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 5267191 : error = IVAS_ERR_OK;
474 :
475 5267191 : num_bits_read = 0;
476 5267191 : element_mode_flag = 0;
477 :
478 5267191 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
479 :
480 : /*-------------------------------------------------------------------*
481 : * Read IVAS format
482 : *-------------------------------------------------------------------*/
483 :
484 5267191 : 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 5267191 : 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 5207483 : if ( st_ivas->ivas_format == STEREO_FORMAT )
504 : {
505 251183 : element_mode_flag = 1;
506 : }
507 4956300 : else if ( st_ivas->ivas_format == ISM_FORMAT )
508 : {
509 : /* read the number of objects */
510 1072545 : st_ivas->nchan_transport = 1;
511 1072545 : nchan_ism = 1;
512 1072545 : k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 );
513 2953157 : while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS )
514 : {
515 1880612 : nchan_ism++;
516 1880612 : k--;
517 : }
518 :
519 1072545 : st_ivas->nchan_ism = nchan_ism;
520 :
521 1072545 : if ( ( error = ivas_ism_dec_config( st_ivas, st_ivas->ism_mode ) ) != IVAS_ERR_OK )
522 : {
523 0 : return error;
524 : }
525 : }
526 3883755 : else if ( st_ivas->ivas_format == SBA_FORMAT )
527 : {
528 : /* read Ambisonic (SBA) planar flag */
529 921637 : st_ivas->sba_planar = st_ivas->bit_stream[num_bits_read];
530 921637 : num_bits_read += SBA_PLANAR_BITS;
531 :
532 : /* read Ambisonic (SBA) order */
533 921637 : st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1];
534 921637 : st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read];
535 :
536 921637 : num_bits_read += SBA_ORDER_BITS;
537 921637 : if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->last_active_ivas_total_brate && ivas_total_brate > IVAS_SID_5k2 )
538 : {
539 5007 : 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 916630 : st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order );
548 :
549 916630 : 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 2962118 : else if ( st_ivas->ivas_format == MASA_FORMAT )
553 : {
554 : /* read number of MASA transport channels */
555 453091 : if ( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] )
556 : {
557 197037 : st_ivas->nchan_transport = 2;
558 197037 : element_mode_flag = 1;
559 : }
560 : else
561 : {
562 256054 : st_ivas->nchan_transport = 1;
563 : }
564 :
565 : /* this should be non-zero if original input format was MASA_ISM_FORMAT */
566 453091 : st_ivas->ism_mode = ISM_MODE_NONE;
567 453091 : 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 453091 : 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 125438 : st_ivas->nchan_ism = 5 - st_ivas->nchan_ism;
580 125438 : if ( st_ivas->nchan_transport == 1 && st_ivas->nchan_ism == 2 )
581 : {
582 27769 : 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 125438 : st_ivas->nchan_transport = 2;
587 125438 : element_mode_flag = 1;
588 : }
589 :
590 453091 : if ( st_ivas->ini_frame > 0 )
591 : {
592 : /* reconfigure in case a change of operation mode is detected */
593 444964 : 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 6666 : if ( st_ivas->last_ivas_format == MASA_FORMAT )
596 : {
597 4551 : 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 4551 : if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK )
604 : {
605 0 : return error;
606 : }
607 : }
608 : }
609 : else
610 : {
611 2115 : if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK )
612 : {
613 0 : return error;
614 : }
615 : }
616 : }
617 : }
618 : }
619 2509027 : else if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
620 : {
621 423830 : 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 423830 : 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 423830 : st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism );
626 :
627 423830 : if ( st_ivas->ini_frame > 0 )
628 : {
629 : /* reconfigure in case a change of operation mode is detected */
630 415668 : 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 5157 : if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK )
633 : {
634 0 : return error;
635 : }
636 : }
637 : }
638 : }
639 2085197 : 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 1559268 : 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 1559268 : st_ivas->sba_planar = st_ivas->bit_stream[num_bits_read];
646 1559268 : num_bits_read += SBA_PLANAR_BITS;
647 :
648 : /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/
649 1559268 : st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1];
650 1559268 : st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read];
651 1559268 : num_bits_read += SBA_ORDER_BITS;
652 :
653 : /* read the real Ambisonic order when the above bits are used to signal OSBA format */
654 1559268 : if ( ivas_total_brate < IVAS_24k4 )
655 : {
656 250869 : st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1];
657 250869 : st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read];
658 250869 : num_bits_read += SBA_ORDER_BITS;
659 : }
660 :
661 1559268 : if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->last_active_ivas_total_brate )
662 : {
663 8928 : 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 1550340 : st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order );
672 :
673 1550340 : 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 1550340 : if ( st_ivas->ini_frame > 0 && st_ivas->ism_mode == ISM_SBA_MODE_DISC )
677 : {
678 : {
679 : int16_t n;
680 :
681 675910 : n = st_ivas->nchan_transport + st_ivas->nchan_ism;
682 675910 : st_ivas->nCPE = ( n + 1 ) >> 1;
683 : }
684 : }
685 : }
686 1559268 : if ( ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ) == ISM_SBA_MODE_DISC )
687 : {
688 693300 : st_ivas->ism_mode = ISM_SBA_MODE_DISC;
689 : }
690 : else
691 : {
692 865968 : st_ivas->ism_mode = ISM_MODE_NONE;
693 : }
694 : }
695 525929 : else if ( st_ivas->ivas_format == MC_FORMAT )
696 : {
697 : /* read MC configuration */
698 525929 : idx = 0;
699 2103716 : for ( k = 0; k < MC_LS_SETUP_BITS; k++ )
700 : {
701 1577787 : if ( st_ivas->bit_stream[num_bits_read + k] )
702 : {
703 341391 : idx += 1 << ( MC_LS_SETUP_BITS - 1 - k );
704 : }
705 : }
706 525929 : num_bits_read += MC_LS_SETUP_BITS;
707 :
708 : /* select MC format mode; reconfigure the MC format decoder */
709 525929 : 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 5207483 : if ( st_ivas->ini_frame == 0 && element_mode_flag )
720 : {
721 : /* read stereo technology info */
722 7120 : if ( ivas_total_brate < MIN_BRATE_MDCT_STEREO )
723 : {
724 : /* 1 bit */
725 4354 : 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 4354 : st_ivas->element_mode_init = 0 + IVAS_CPE_DFT;
732 : }
733 : }
734 : else
735 : {
736 2766 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
737 : }
738 : }
739 : }
740 59708 : else if ( ivas_total_brate == IVAS_SID_5k2 )
741 : {
742 9257 : switch ( st_ivas->sid_format )
743 : {
744 4299 : case SID_DFT_STEREO:
745 4299 : st_ivas->element_mode_init = IVAS_CPE_DFT;
746 4299 : break;
747 1313 : case SID_MDCT_STEREO:
748 1313 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
749 1313 : break;
750 1984 : case SID_ISM:
751 1984 : st_ivas->element_mode_init = IVAS_SCE;
752 1984 : break;
753 393 : case SID_MASA_1TC:
754 393 : st_ivas->element_mode_init = IVAS_SCE;
755 393 : st_ivas->nchan_transport = 1;
756 393 : break;
757 222 : case SID_MASA_2TC:
758 222 : if ( st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS] == 1 )
759 : {
760 0 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
761 : }
762 : else
763 : {
764 222 : st_ivas->element_mode_init = IVAS_CPE_DFT;
765 : }
766 222 : st_ivas->nchan_transport = 2;
767 222 : break;
768 497 : case SID_SBA_1TC:
769 497 : st_ivas->element_mode_init = IVAS_SCE;
770 497 : break;
771 549 : case SID_SBA_2TC:
772 549 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
773 549 : break;
774 : }
775 :
776 9257 : if ( st_ivas->ini_frame > 0 && st_ivas->ivas_format == SBA_FORMAT )
777 : {
778 : int16_t nchan_transport_old, nchan_transport;
779 1046 : nchan_transport_old = st_ivas->nchan_transport;
780 1046 : nchan_transport = ( st_ivas->sid_format == SID_SBA_2TC ) ? 2 : 1;
781 :
782 1046 : 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 9257 : if ( st_ivas->ini_frame > 0 && st_ivas->ivas_format == MASA_FORMAT )
805 : {
806 615 : st_ivas->nchan_ism = 0;
807 615 : st_ivas->ism_mode = ISM_MODE_NONE;
808 : }
809 :
810 9257 : if ( st_ivas->ivas_format == ISM_FORMAT )
811 : {
812 1984 : ISM_MODE last_ism_mode = st_ivas->ism_mode;
813 :
814 : /* read the number of objects */
815 1984 : st_ivas->nchan_transport = 1;
816 1984 : nchan_ism = 1;
817 1984 : k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ) - SID_FORMAT_NBITS;
818 6829 : while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS )
819 : {
820 4845 : nchan_ism++;
821 4845 : k--;
822 : }
823 1984 : k--;
824 :
825 1984 : 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 1984 : st_ivas->nchan_ism = nchan_ism;
831 :
832 : /* read ism_mode */
833 1984 : st_ivas->ism_mode = ISM_MODE_DISC;
834 1984 : if ( nchan_ism > 2 )
835 : {
836 1504 : k -= nchan_ism; /* SID metadata flags */
837 1504 : idx = st_ivas->bit_stream[k];
838 1504 : st_ivas->ism_mode = (ISM_MODE) ( idx + 1 );
839 : }
840 :
841 1984 : if ( st_ivas->ini_frame == 0 )
842 : {
843 0 : last_ism_mode = st_ivas->ism_mode;
844 : }
845 :
846 1984 : 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 5267191 : if ( st_ivas->ini_frame == 0 && st_ivas->ivas_format != UNDEFINED_FORMAT )
859 : {
860 85532 : if ( ( error = doSanityChecks_IVAS( st_ivas ) ) != IVAS_ERR_OK )
861 : {
862 0 : return IVAS_ERROR( error, "Sanity checks failed" );
863 : }
864 :
865 85532 : 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 5267191 : ivas_set_bitstream_pointers( st_ivas );
876 :
877 5267191 : reset_elements( st_ivas );
878 :
879 : /* update bitstream buffer pointer -> take into account already read bits */
880 5267191 : if ( ( st_ivas->nSCE > 0 ) || ( st_ivas->nCPE > 0 ) )
881 : {
882 5267191 : st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0];
883 5267191 : st->next_bit_pos = num_bits_read;
884 5267191 : 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 5267191 : return error;
888 : }
889 :
890 :
891 : /*-------------------------------------------------------------------*
892 : * ivas_read_format()
893 : *
894 : * Read IVAS format signaling
895 : *-------------------------------------------------------------------*/
896 :
897 10529819 : 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 10529819 : error = IVAS_ERR_OK;
907 :
908 10529819 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
909 :
910 10529819 : *num_bits_read = 0;
911 :
912 10529819 : if ( !st_ivas->bfi && is_DTXrate( ivas_total_brate ) == 0 )
913 : {
914 : /* read IVAS format */
915 10414966 : k = 0;
916 10414966 : if ( st_ivas->bit_stream[*num_bits_read] )
917 : {
918 8860742 : k = 1;
919 : }
920 10414966 : k <<= 1;
921 10414966 : ( *num_bits_read )++;
922 :
923 10414966 : if ( st_ivas->bit_stream[*num_bits_read] )
924 : {
925 4303052 : k += 1;
926 : }
927 10414966 : ( *num_bits_read )++;
928 :
929 10414966 : switch ( k )
930 : {
931 502366 : case 0:
932 502366 : st_ivas->ivas_format = STEREO_FORMAT;
933 502366 : break;
934 1051858 : case 1:
935 1051858 : st_ivas->ivas_format = MC_FORMAT;
936 1051858 : break;
937 5609548 : case 2:
938 5609548 : st_ivas->ivas_format = ISM_FORMAT;
939 :
940 5609548 : if ( ivas_total_brate >= IVAS_24k4 )
941 : {
942 5486282 : if ( st_ivas->bit_stream[*num_bits_read] )
943 : {
944 3464458 : ( *num_bits_read )++;
945 3464458 : if ( st_ivas->bit_stream[*num_bits_read] )
946 : {
947 2616798 : st_ivas->ivas_format = SBA_ISM_FORMAT;
948 : }
949 : else
950 : {
951 847660 : st_ivas->ivas_format = MASA_ISM_FORMAT;
952 : }
953 : }
954 5486282 : ( *num_bits_read )++;
955 : }
956 5609548 : break;
957 3251194 : case 3:
958 3251194 : if ( st_ivas->bit_stream[*num_bits_read] )
959 : {
960 906182 : st_ivas->ivas_format = MASA_FORMAT;
961 : }
962 : else
963 : {
964 2345012 : st_ivas->ivas_format = SBA_FORMAT;
965 : /* read Ambisonic (SBA) planar flag */
966 2345012 : st_ivas->sba_planar = st_ivas->bit_stream[( *num_bits_read ) + 1];
967 :
968 : /* read Ambisonic (SBA) order */
969 2345012 : st_ivas->sba_order = st_ivas->bit_stream[( *num_bits_read ) + 2 + SBA_PLANAR_BITS];
970 2345012 : st_ivas->sba_order += 2 * st_ivas->bit_stream[( *num_bits_read ) + 1 + SBA_PLANAR_BITS];
971 2345012 : if ( st_ivas->sba_order == 0 )
972 : {
973 501738 : 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 501738 : if ( ivas_total_brate < IVAS_24k4 )
977 : {
978 501738 : st_ivas->sba_order = st_ivas->bit_stream[*num_bits_read + 2 + SBA_PLANAR_BITS + SBA_ORDER_BITS];
979 501738 : st_ivas->sba_order += 2 * st_ivas->bit_stream[*num_bits_read + 1 + SBA_PLANAR_BITS + SBA_ORDER_BITS];
980 : }
981 : }
982 : }
983 3251194 : ( *num_bits_read )++;
984 :
985 3251194 : break;
986 : }
987 10414966 : }
988 114853 : else if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_5k2 )
989 : {
990 : /* read IVAS format in SID frame */
991 18514 : idx = 0;
992 74056 : for ( k = 0; k < SID_FORMAT_NBITS; k++ )
993 : {
994 55542 : idx += st_ivas->bit_stream[k] << ( SID_FORMAT_NBITS - 1 - k );
995 : }
996 :
997 18514 : ( *num_bits_read ) += SID_FORMAT_NBITS;
998 18514 : st_ivas->sid_format = idx;
999 :
1000 18514 : switch ( idx )
1001 : {
1002 11224 : case SID_DFT_STEREO:
1003 : case SID_MDCT_STEREO:
1004 11224 : st_ivas->ivas_format = STEREO_FORMAT;
1005 11224 : break;
1006 3968 : case SID_ISM:
1007 3968 : st_ivas->ivas_format = ISM_FORMAT;
1008 3968 : break;
1009 994 : case SID_SBA_1TC:
1010 994 : st_ivas->ivas_format = SBA_FORMAT;
1011 994 : st_ivas->element_mode_init = IVAS_SCE;
1012 994 : break;
1013 1098 : case SID_SBA_2TC:
1014 1098 : st_ivas->ivas_format = SBA_FORMAT;
1015 1098 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
1016 1098 : break;
1017 786 : case SID_MASA_1TC:
1018 786 : st_ivas->ivas_format = MASA_FORMAT;
1019 786 : st_ivas->element_mode_init = IVAS_SCE;
1020 786 : break;
1021 444 : case SID_MASA_2TC:
1022 444 : st_ivas->ivas_format = MASA_FORMAT;
1023 444 : if ( st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] == 1 )
1024 : {
1025 0 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
1026 : }
1027 : else
1028 : {
1029 444 : st_ivas->element_mode_init = IVAS_CPE_DFT;
1030 : }
1031 444 : 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 18514 : if ( st_ivas->ivas_format == SBA_FORMAT )
1037 : {
1038 : /* read Ambisonic (SBA) planar flag */
1039 2092 : st_ivas->sba_planar = st_ivas->bit_stream[*num_bits_read];
1040 2092 : *num_bits_read += SBA_PLANAR_BITS;
1041 :
1042 : /* read Ambisonic (SBA) order */
1043 2092 : st_ivas->sba_order = st_ivas->bit_stream[*num_bits_read + 1];
1044 2092 : st_ivas->sba_order += 2 * st_ivas->bit_stream[*num_bits_read];
1045 2092 : *num_bits_read += SBA_ORDER_BITS;
1046 2092 : 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 18514 : st_ivas->bit_stream += ( *num_bits_read );
1054 18514 : ( *num_bits_read ) = 0;
1055 : }
1056 : else
1057 : {
1058 : /* In SID/NO_DATA frames, use the previous frame IVAS format */
1059 : }
1060 :
1061 10529819 : 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 10866094 : int16_t getNumChanSynthesis(
1074 : Decoder_Struct *st_ivas /* i : IVAS decoder structure */
1075 : )
1076 : {
1077 : int16_t n;
1078 :
1079 10866094 : n = st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE;
1080 :
1081 10866094 : if ( st_ivas->sba_dirac_stereo_flag )
1082 : {
1083 367171 : n = CPE_CHANNELS;
1084 : }
1085 10498923 : else if ( ( st_ivas->hMCT != NULL || st_ivas->ivas_format == SBA_FORMAT ) && st_ivas->ivas_format != SBA_ISM_FORMAT )
1086 : {
1087 97144 : n = st_ivas->nchan_transport;
1088 : }
1089 10401779 : else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
1090 : {
1091 7584014 : if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
1092 : {
1093 5239841 : n = st_ivas->nchan_transport + st_ivas->nchan_ism;
1094 : }
1095 : else
1096 : {
1097 2344173 : n = st_ivas->nchan_transport;
1098 : }
1099 : }
1100 :
1101 10866094 : return n;
1102 : }
1103 :
1104 :
1105 : /*-------------------------------------------------------------------*
1106 : * copy_decoder_config()
1107 : *
1108 : * Copy IVAS configuration structure to the CoreCoder state structure
1109 : *-------------------------------------------------------------------*/
1110 :
1111 314871 : void copy_decoder_config(
1112 : Decoder_Struct *st_ivas, /* i : IVAS decoder structure */
1113 : Decoder_State *st /* o : decoder state structure */
1114 : )
1115 : {
1116 314871 : st->output_Fs = st_ivas->hDecoderConfig->output_Fs;
1117 314871 : st->Opt_AMR_WB = st_ivas->hDecoderConfig->Opt_AMR_WB;
1118 314871 : st->codec_mode = st_ivas->codec_mode;
1119 314871 : st->ini_frame = st_ivas->ini_frame;
1120 :
1121 314871 : st->bfi = st_ivas->bfi;
1122 :
1123 314871 : st->writeFECoffset = st_ivas->writeFECoffset;
1124 :
1125 314871 : st->element_mode = st_ivas->element_mode_init;
1126 :
1127 314871 : return;
1128 : }
1129 :
1130 :
1131 : /*-------------------------------------------------------------------*
1132 : * ivas_init_decoder_front()
1133 : *
1134 : * Set decoder parameters to initial values
1135 : *-------------------------------------------------------------------*/
1136 :
1137 86027 : ivas_error ivas_init_decoder_front(
1138 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
1139 : )
1140 : {
1141 : ivas_error error;
1142 :
1143 86027 : error = IVAS_ERR_OK;
1144 :
1145 : /*-----------------------------------------------------------------*
1146 : * Resets
1147 : *-----------------------------------------------------------------*/
1148 :
1149 86027 : st_ivas->nSCE = 0;
1150 86027 : st_ivas->nCPE = 0;
1151 86027 : st_ivas->nchan_ism = 0;
1152 86027 : st_ivas->nchan_transport = -1;
1153 :
1154 86027 : st_ivas->ism_mode = ISM_MODE_NONE;
1155 86027 : st_ivas->mc_mode = MC_MODE_NONE;
1156 :
1157 86027 : st_ivas->sid_format = SID_FORMAT_NONE;
1158 86027 : st_ivas->sba_dirac_stereo_flag = 0;
1159 :
1160 : /* HRTF binauralization latency in ns */
1161 86027 : 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 86027 : if ( st_ivas->hDecoderConfig->Opt_LsCustom )
1171 : {
1172 9 : 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 86027 : if ( st_ivas->hDecoderConfig->Opt_Headrotation )
1183 : {
1184 2345 : if ( ( error = ivas_headTrack_open( &( st_ivas->hHeadTrackData ) ) ) != IVAS_ERR_OK )
1185 : {
1186 0 : return error;
1187 : }
1188 2345 : 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 86027 : if ( st_ivas->hDecoderConfig->Opt_ExternalOrientation )
1199 : {
1200 93 : 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 86027 : if ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation )
1211 : {
1212 2345 : 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 86027 : 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 60069 : ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->Opt_non_diegetic_pan ) )
1224 : {
1225 25964 : if ( ( error = ivas_render_config_open( &( st_ivas->hRenderConfig ) ) ) != IVAS_ERR_OK )
1226 : {
1227 0 : return error;
1228 : }
1229 :
1230 25964 : 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 86027 : st_ivas->flushing = 0;
1238 : #endif
1239 :
1240 86027 : return error;
1241 : }
1242 :
1243 :
1244 : /*-------------------------------------------------------------------*
1245 : * ivas_init_decoder()
1246 : *
1247 : * Initialize IVAS decoder state structure
1248 : *-------------------------------------------------------------------*/
1249 :
1250 86027 : 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 86027 : error = IVAS_ERR_OK;
1267 :
1268 86027 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
1269 86027 : hDecoderConfig = st_ivas->hDecoderConfig;
1270 86027 : output_config = hDecoderConfig->output_config;
1271 86027 : ivas_total_brate = hDecoderConfig->ivas_total_brate;
1272 :
1273 86027 : hDecoderConfig->last_ivas_total_brate = ivas_total_brate;
1274 86027 : 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 86027 : if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
1281 : {
1282 5615 : if ( st_ivas->ivas_format == STEREO_FORMAT )
1283 : {
1284 186 : hDecoderConfig->nchan_out = CPE_CHANNELS;
1285 : }
1286 5429 : else if ( st_ivas->ivas_format == MC_FORMAT )
1287 : {
1288 508 : hDecoderConfig->nchan_out = audioCfg2channels( st_ivas->transport_config );
1289 : }
1290 4921 : else if ( st_ivas->ivas_format == SBA_ISM_FORMAT || st_ivas->ivas_format == SBA_FORMAT )
1291 : {
1292 2811 : hDecoderConfig->nchan_out = audioCfg2channels( ivas_set_audio_config_from_sba_order( st_ivas->sba_order ) );
1293 2811 : hDecoderConfig->nchan_out += st_ivas->nchan_ism;
1294 : }
1295 2110 : else if ( st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
1296 : {
1297 1041 : hDecoderConfig->nchan_out = st_ivas->nchan_transport + st_ivas->nchan_ism;
1298 : }
1299 1069 : else if ( !( st_ivas->ism_mode == ISM_MODE_PARAM ) )
1300 : {
1301 967 : hDecoderConfig->nchan_out = st_ivas->nchan_transport;
1302 : }
1303 :
1304 5615 : st_ivas->hOutSetup.nchan_out_woLFE = hDecoderConfig->nchan_out;
1305 : }
1306 :
1307 : /*-----------------------------------------------------------------*
1308 : * Set output and intern setup & renderer selection
1309 : *-----------------------------------------------------------------*/
1310 :
1311 86027 : st_ivas->intern_config = output_config;
1312 :
1313 86027 : if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL && st_ivas->ivas_format == MC_FORMAT )
1314 : {
1315 508 : ivas_output_init( &( st_ivas->hOutSetup ), st_ivas->transport_config );
1316 508 : st_ivas->intern_config = st_ivas->transport_config;
1317 : }
1318 85519 : else if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL && ( st_ivas->ivas_format == SBA_ISM_FORMAT || st_ivas->ivas_format == SBA_FORMAT ) )
1319 : {
1320 2811 : st_ivas->intern_config = ivas_set_audio_config_from_sba_order( st_ivas->sba_order );
1321 2811 : ivas_output_init( &( st_ivas->hOutSetup ), st_ivas->intern_config );
1322 : }
1323 : else
1324 : {
1325 82708 : ivas_output_init( &( st_ivas->hOutSetup ), output_config );
1326 : }
1327 :
1328 86027 : if ( st_ivas->ivas_format == SBA_ISM_FORMAT && output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
1329 : {
1330 3038 : st_ivas->hOutSetup.ambisonics_order = SBA_HOA3_ORDER;
1331 3038 : st_ivas->intern_config = IVAS_AUDIO_CONFIG_7_1_4;
1332 3038 : st_ivas->hOutSetup.output_config = st_ivas->intern_config;
1333 3038 : st_ivas->hOutSetup.nchan_out_woLFE = audioCfg2channels( st_ivas->intern_config );
1334 : }
1335 :
1336 : /* Only initialize transport setup if it is used */
1337 86027 : if ( st_ivas->transport_config != IVAS_AUDIO_CONFIG_INVALID )
1338 : {
1339 23652 : ivas_output_init( &( st_ivas->hTransSetup ), st_ivas->transport_config );
1340 : }
1341 :
1342 86027 : if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA )
1343 : {
1344 2667 : ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate );
1345 :
1346 2667 : ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hOutSetup.separateChannelEnabled ), &( st_ivas->hOutSetup.separateChannelIndex ), ivas_total_brate );
1347 : }
1348 :
1349 86027 : ivas_renderer_select( st_ivas );
1350 :
1351 86027 : if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM )
1352 : {
1353 9 : if ( ( error = ivas_ls_custom_output_init( st_ivas ) ) != IVAS_ERR_OK )
1354 : {
1355 0 : return error;
1356 : }
1357 : }
1358 :
1359 86027 : ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config );
1360 :
1361 86027 : if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA )
1362 : {
1363 2667 : ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate );
1364 :
1365 2667 : 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 86027 : if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
1389 : {
1390 7891 : 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 86027 : if ( st_ivas->ivas_format == MONO_FORMAT )
1401 : {
1402 495 : st_ivas->nSCE = 1; /* in mono, there is always only one SCE */
1403 495 : st_ivas->nCPE = 0;
1404 495 : st_ivas->nchan_transport = 1;
1405 495 : sce_id = 0;
1406 :
1407 495 : if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK )
1408 : {
1409 0 : return error;
1410 : }
1411 :
1412 495 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1413 : }
1414 85532 : else if ( st_ivas->ivas_format == STEREO_FORMAT )
1415 : {
1416 1559 : st_ivas->nchan_transport = CPE_CHANNELS;
1417 1559 : st_ivas->intern_config = IVAS_AUDIO_CONFIG_STEREO;
1418 :
1419 1559 : st_ivas->nSCE = 0;
1420 1559 : st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */
1421 1559 : cpe_id = 0;
1422 :
1423 1559 : if ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate ) ) != IVAS_ERR_OK )
1424 : {
1425 0 : return error;
1426 : }
1427 :
1428 4677 : for ( n = 0; n < st_ivas->nchan_transport; n++ )
1429 : {
1430 3118 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1431 : }
1432 :
1433 : /* init EFAP for custom LS output and set hTransSetup */
1434 1559 : 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 83973 : else if ( st_ivas->ivas_format == ISM_FORMAT )
1445 : {
1446 : int32_t element_brate_tmp[MAX_NUM_OBJECTS];
1447 :
1448 16209 : st_ivas->nSCE = st_ivas->nchan_transport; /* "st_ivas->nchan_transport" is known from ivas_dec_setup */
1449 16209 : st_ivas->nCPE = 0;
1450 16209 : st_ivas->ism_extmeta_active = -1;
1451 16209 : st_ivas->ism_extmeta_cnt = 0;
1452 :
1453 16209 : if ( st_ivas->ism_mode == ISM_MODE_PARAM )
1454 : {
1455 1558 : st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE;
1456 1558 : st_ivas->nSCE = MAX_PARAM_ISM_WAVE;
1457 :
1458 1558 : if ( ( error = ivas_param_ism_dec_open( st_ivas ) ) != IVAS_ERR_OK )
1459 : {
1460 0 : return error;
1461 : }
1462 : }
1463 :
1464 16209 : 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 56724 : for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
1470 : {
1471 40515 : 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 40515 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1477 :
1478 40515 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->is_ism_format = 1;
1479 : }
1480 :
1481 16209 : st_ivas->hISMDTX.sce_id_dtx = 0;
1482 :
1483 16209 : if ( st_ivas->ism_mode == ISM_MODE_PARAM )
1484 : {
1485 1558 : st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2 = st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed3;
1486 :
1487 1558 : 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 463 : if ( ( error = ivas_omasa_data_open( st_ivas ) ) != IVAS_ERR_OK )
1491 : {
1492 0 : return error;
1493 : }
1494 : }
1495 : }
1496 14651 : else if ( st_ivas->ism_mode == ISM_MODE_DISC )
1497 : {
1498 52050 : for ( sce_id = 0; sce_id < st_ivas->nSCE; ++sce_id )
1499 : {
1500 37399 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2 = 2 + sce_id;
1501 : }
1502 : }
1503 : }
1504 67764 : else if ( st_ivas->ivas_format == SBA_FORMAT )
1505 : {
1506 12386 : if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
1507 : {
1508 0 : return error;
1509 : }
1510 :
1511 12386 : if ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK )
1512 : {
1513 0 : return error;
1514 : }
1515 :
1516 12386 : if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order,
1517 12386 : 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 12386 : 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 9459 : if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK )
1526 : {
1527 0 : return error;
1528 : }
1529 :
1530 9459 : 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 2927 : st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND );
1537 2927 : if ( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) )
1538 : {
1539 147 : st_ivas->hSpar->enc_param_start_band = 0;
1540 :
1541 147 : set_c( (int8_t *) st_ivas->hQMetaData->twoDirBands, (int8_t) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands );
1542 147 : st_ivas->hQMetaData->numTwoDirBands = (uint8_t) st_ivas->hQMetaData->q_direction[0].cfg.nbands;
1543 : }
1544 :
1545 2927 : ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ),
1546 2927 : st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0, 1 );
1547 : }
1548 12386 : st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
1549 :
1550 16620 : for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
1551 : {
1552 4234 : 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 4234 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1558 : }
1559 :
1560 24994 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1561 : {
1562 12608 : 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 37824 : for ( n = 0; n < CPE_CHANNELS; n++ )
1568 : {
1569 25216 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1570 : }
1571 : }
1572 :
1573 : /* create CPE element for DFT Stereo like upmix */
1574 12386 : if ( st_ivas->sba_dirac_stereo_flag && st_ivas->nCPE == 0 )
1575 : {
1576 523 : 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 523 : 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 523 : st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
1583 : }
1584 :
1585 12386 : if ( st_ivas->nCPE > 1 )
1586 : {
1587 4456 : if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK )
1588 : {
1589 0 : return error;
1590 : }
1591 : }
1592 :
1593 : /* set CNA/CNG flags */
1594 12386 : ivas_sba_set_cna_cng_flag( st_ivas );
1595 : }
1596 55378 : 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 8127 : st_ivas->ism_extmeta_active = -1;
1600 8127 : st_ivas->ism_extmeta_cnt = 0;
1601 8127 : if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
1602 : {
1603 0 : return error;
1604 : }
1605 :
1606 8127 : if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK )
1607 : {
1608 0 : return error;
1609 : }
1610 :
1611 8127 : 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 7264 : if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK )
1614 : {
1615 0 : return error;
1616 : }
1617 : }
1618 :
1619 10693 : for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
1620 : {
1621 2566 : 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 2566 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1627 : }
1628 :
1629 13688 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1630 : {
1631 5561 : 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 16683 : for ( n = 0; n < CPE_CHANNELS; n++ )
1637 : {
1638 11122 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1639 : }
1640 : }
1641 :
1642 : /* set CNA/CNG flags */
1643 8127 : ivas_sba_set_cna_cng_flag( st_ivas );
1644 : }
1645 47251 : else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
1646 : {
1647 : int32_t temp_brate[MAX_SCE];
1648 31646 : st_ivas->ism_extmeta_active = -1;
1649 31646 : st_ivas->ism_extmeta_cnt = 0;
1650 :
1651 31646 : st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
1652 :
1653 31646 : if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
1654 : {
1655 0 : return error;
1656 : }
1657 :
1658 31646 : if ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK )
1659 : {
1660 0 : return error;
1661 : }
1662 :
1663 31646 : if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order,
1664 31646 : 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 31646 : if ( output_config != IVAS_AUDIO_CONFIG_FOA && output_config != IVAS_AUDIO_CONFIG_STEREO && output_config != IVAS_AUDIO_CONFIG_MONO )
1671 : {
1672 25575 : if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK )
1673 : {
1674 0 : return error;
1675 : }
1676 :
1677 25575 : 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 6071 : st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND );
1684 6071 : if ( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) )
1685 : {
1686 579 : st_ivas->hSpar->enc_param_start_band = 0;
1687 :
1688 579 : set_c( (int8_t *) st_ivas->hQMetaData->twoDirBands, (int8_t) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands );
1689 579 : st_ivas->hQMetaData->numTwoDirBands = (uint8_t) st_ivas->hQMetaData->q_direction[0].cfg.nbands;
1690 : }
1691 :
1692 6071 : ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ),
1693 6071 : st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0, 1 );
1694 : }
1695 :
1696 42847 : for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
1697 : {
1698 11201 : 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 11201 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1704 : }
1705 :
1706 31646 : if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
1707 : {
1708 : {
1709 : int16_t n_all;
1710 :
1711 12053 : n_all = st_ivas->nchan_transport + st_ivas->nchan_ism;
1712 12053 : st_ivas->nCPE = ( n_all + 1 ) >> 1;
1713 : }
1714 12053 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
1715 : }
1716 :
1717 80836 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1718 : {
1719 49190 : 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 147570 : for ( n = 0; n < CPE_CHANNELS; n++ )
1725 : {
1726 98380 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1727 : }
1728 : }
1729 :
1730 : /* create CPE element for DFT Stereo like upmix */
1731 31646 : if ( st_ivas->sba_dirac_stereo_flag && st_ivas->nCPE == 0 )
1732 : {
1733 723 : 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 723 : 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 723 : st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
1740 : }
1741 :
1742 31646 : if ( st_ivas->nCPE > 1 )
1743 : {
1744 13732 : if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK )
1745 : {
1746 0 : return error;
1747 : }
1748 : }
1749 :
1750 31646 : if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
1751 : {
1752 12053 : 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 12053 : 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 31646 : ivas_sba_set_cna_cng_flag( st_ivas );
1765 : }
1766 15605 : else if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
1767 : {
1768 8162 : st_ivas->ism_extmeta_active = -1;
1769 8162 : st_ivas->ism_extmeta_cnt = 0;
1770 :
1771 8162 : if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
1772 : {
1773 0 : return error;
1774 : }
1775 :
1776 8162 : k = 0;
1777 8162 : ism_total_brate = 0;
1778 87427 : while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] )
1779 : {
1780 79265 : k++;
1781 : }
1782 :
1783 8162 : 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 2062 : st_ivas->nSCE = 1;
1787 :
1788 2062 : ism_total_brate = sep_object_brate[k - 2][0];
1789 2062 : if ( ( error = create_sce_dec( st_ivas, 0, ism_total_brate ) ) != IVAS_ERR_OK )
1790 : {
1791 0 : return error;
1792 : }
1793 :
1794 2062 : reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] );
1795 :
1796 2062 : 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 6100 : else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
1802 : {
1803 : int32_t temp_brate[MAX_SCE];
1804 6100 : st_ivas->nSCE = st_ivas->nchan_ism; /* number of objects */
1805 :
1806 19210 : for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
1807 : {
1808 13110 : temp_brate[sce_id] = sep_object_brate[k - 2][st_ivas->nSCE - 1];
1809 13110 : ism_total_brate += temp_brate[sce_id];
1810 :
1811 13110 : if ( ( error = create_sce_dec( st_ivas, sce_id, temp_brate[sce_id] ) ) != IVAS_ERR_OK )
1812 : {
1813 0 : return error;
1814 : }
1815 :
1816 13110 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
1817 : }
1818 :
1819 6100 : 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 8162 : if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK )
1826 : {
1827 0 : return error;
1828 : }
1829 :
1830 8162 : if ( ( error = ivas_omasa_data_open( st_ivas ) ) != IVAS_ERR_OK )
1831 : {
1832 0 : return error;
1833 : }
1834 :
1835 8162 : 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 7149 : if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK )
1838 : {
1839 0 : return error;
1840 : }
1841 : }
1842 :
1843 8162 : 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 24486 : for ( n = 0; n < CPE_CHANNELS; n++ )
1849 : {
1850 16324 : reset_indices_dec( st_ivas->hCPE[0]->hCoreCoder[n] );
1851 : }
1852 : }
1853 7443 : else if ( st_ivas->ivas_format == MC_FORMAT )
1854 : {
1855 7443 : if ( st_ivas->mc_mode == MC_MODE_MCT )
1856 : {
1857 : /* init EFAP for custom LS setup */
1858 3162 : if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM )
1859 : {
1860 3 : 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 3162 : 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 3162 : st_ivas->nSCE = 0;
1868 3162 : st_ivas->nCPE = st_ivas->nchan_transport / CPE_CHANNELS;
1869 :
1870 3162 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
1871 :
1872 16215 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1873 : {
1874 13053 : 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 39159 : for ( n = 0; n < CPE_CHANNELS; n++ )
1880 : {
1881 26106 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1882 : }
1883 : }
1884 :
1885 3162 : if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK )
1886 : {
1887 0 : return error;
1888 : }
1889 : }
1890 4281 : else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
1891 : {
1892 : /* init EFAP for custom LS setup */
1893 180 : 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 180 : st_ivas->nSCE = 0;
1902 180 : st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / CPE_CHANNELS;
1903 180 : st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
1904 :
1905 180 : if ( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ) != IVAS_ERR_OK )
1906 : {
1907 0 : return error;
1908 : }
1909 :
1910 180 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
1911 :
1912 900 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1913 : {
1914 720 : 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 2160 : for ( n = 0; n < CPE_CHANNELS; n++ )
1920 : {
1921 1440 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1922 : }
1923 : }
1924 :
1925 180 : if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK )
1926 : {
1927 0 : return error;
1928 : }
1929 : }
1930 4101 : else if ( st_ivas->mc_mode == MC_MODE_PARAMMC )
1931 : {
1932 : /* init EFAP for custom LS setup */
1933 1434 : 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 1434 : if ( ( error = ivas_param_mc_dec_open( st_ivas ) ) != IVAS_ERR_OK )
1942 : {
1943 0 : return error;
1944 : }
1945 :
1946 3413 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1947 : {
1948 1979 : 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 5937 : for ( n = 0; n < CPE_CHANNELS; n++ )
1954 : {
1955 3958 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
1956 : }
1957 : }
1958 :
1959 1434 : if ( st_ivas->nCPE > 1 )
1960 : {
1961 545 : if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK )
1962 : {
1963 0 : return error;
1964 : }
1965 : }
1966 : }
1967 2667 : else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
1968 : {
1969 : int32_t brate_sce, brate_cpe;
1970 :
1971 2667 : ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate );
1972 :
1973 2667 : if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
1974 : {
1975 0 : return error;
1976 : }
1977 :
1978 2667 : if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK )
1979 : {
1980 0 : return error;
1981 : }
1982 :
1983 2667 : st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
1984 :
1985 2667 : if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MCMASA_MONO_STEREO )
1986 : {
1987 2320 : if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK )
1988 : {
1989 0 : return error;
1990 : }
1991 : }
1992 :
1993 2667 : 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 2667 : ivas_mcmasa_split_brate( st_ivas->hOutSetup.separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe );
2008 :
2009 5138 : for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
2010 : {
2011 2471 : if ( ( error = create_sce_dec( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK )
2012 : {
2013 0 : return error;
2014 : }
2015 :
2016 2471 : reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
2017 : }
2018 :
2019 3349 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
2020 : {
2021 682 : st_ivas->element_mode_init = IVAS_CPE_MDCT; /* element_mode_init was IVAS_SCE for SCE initialization */
2022 :
2023 682 : if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK )
2024 : {
2025 0 : return error;
2026 : }
2027 :
2028 2046 : for ( n = 0; n < CPE_CHANNELS; n++ )
2029 : {
2030 1364 : reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
2031 : }
2032 : }
2033 :
2034 : /* create CPE element for DFT Stereo like upmix */
2035 2667 : if ( st_ivas->sba_dirac_stereo_flag )
2036 : {
2037 129 : 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 129 : 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 129 : st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
2044 : }
2045 :
2046 : /* set CNA/CNG flags */
2047 2667 : if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) )
2048 : {
2049 587 : st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1;
2050 587 : 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 86027 : n = getNumChanSynthesis( st_ivas );
2068 :
2069 86027 : if ( n > 0 )
2070 : {
2071 86027 : 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 337226 : for ( i = 0; i < n; i++ )
2082 : {
2083 251199 : 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 251199 : 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 86027 : if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
2096 : {
2097 :
2098 6215 : 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 79812 : 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 463 : if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC )
2108 : {
2109 463 : if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
2110 : {
2111 0 : return error;
2112 : }
2113 : }
2114 :
2115 463 : if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, &( st_ivas->hHrtfParambin ) ) ) != IVAS_ERR_OK )
2116 : {
2117 0 : return error;
2118 : }
2119 : }
2120 79349 : else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD )
2121 : {
2122 3262 : if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK )
2123 : {
2124 0 : return error;
2125 : }
2126 :
2127 3262 : if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
2128 : {
2129 1401 : 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 76087 : else if ( st_ivas->renderer_type == RENDERER_MC )
2136 : {
2137 1894 : if ( ( error = ivas_ls_setup_conversion_open( st_ivas ) ) != IVAS_ERR_OK )
2138 : {
2139 0 : return error;
2140 : }
2141 : }
2142 74193 : else if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX )
2143 : {
2144 2303 : if ( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ) != IVAS_ERR_OK )
2145 : {
2146 0 : return error;
2147 : }
2148 : }
2149 71890 : else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM )
2150 : {
2151 2312 : 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 ) )
2152 : {
2153 12 : 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 )
2154 : {
2155 0 : return error;
2156 : }
2157 : }
2158 :
2159 2312 : if ( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, output_config,
2160 2312 : 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 )
2161 : {
2162 0 : return error;
2163 : }
2164 :
2165 2312 : st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns;
2166 : }
2167 :
2168 86027 : if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
2169 : {
2170 8162 : if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC )
2171 : {
2172 : /* Allocate TD renderer for the objects in DISC mode */
2173 850 : if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK )
2174 : {
2175 0 : return error;
2176 : }
2177 :
2178 850 : if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
2179 : {
2180 0 : if ( ( error = ivas_reverb_open( &st_ivas->hReverb, st_ivas->hHrtfStatistics, st_ivas->hRenderConfig, output_Fs ) ) != IVAS_ERR_OK )
2181 : {
2182 0 : return error;
2183 : }
2184 : }
2185 :
2186 : /* Allocate memory for delay buffer within 'hMasaIsmData' */
2187 850 : if ( ( error = ivas_omasa_objects_delay_open( st_ivas ) ) != IVAS_ERR_OK )
2188 : {
2189 0 : return error;
2190 : }
2191 : }
2192 :
2193 8162 : if ( ( st_ivas->renderer_type == RENDERER_DIRAC ) &&
2194 3970 : ( 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 ) )
2195 : {
2196 : /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */
2197 3970 : if ( ( error = ivas_omasa_objects_delay_open( st_ivas ) ) != IVAS_ERR_OK )
2198 : {
2199 0 : return error;
2200 : }
2201 3970 : if ( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK )
2202 : {
2203 0 : return error;
2204 : }
2205 : }
2206 :
2207 8162 : if ( st_ivas->renderer_type == RENDERER_OMASA_OBJECT_EXT )
2208 : {
2209 : /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */
2210 77 : if ( ( error = ivas_omasa_objects_delay_open( st_ivas ) ) != IVAS_ERR_OK )
2211 : {
2212 0 : return error;
2213 : }
2214 :
2215 77 : if ( ( error = ivas_spat_hSpatParamRendCom_config( &st_ivas->hSpatParamRendCom, DIRAC_OPEN, 0,
2216 : st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, 0, 0 ) ) != IVAS_ERR_OK )
2217 : {
2218 0 : return error;
2219 : }
2220 : }
2221 :
2222 8162 : if ( st_ivas->renderer_type == RENDERER_OMASA_MIX_EXT )
2223 : {
2224 : /* Allocate 'hIsmRendererData' handle */
2225 48 : if ( ( error = ivas_omasa_combine_separate_ism_with_masa_open( st_ivas ) ) != IVAS_ERR_OK )
2226 : {
2227 0 : return error;
2228 : }
2229 : }
2230 : }
2231 :
2232 86027 : if ( ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) &&
2233 47855 : ( st_ivas->ism_mode == ISM_MODE_DISC || st_ivas->ism_mode == ISM_SBA_MODE_DISC ) &&
2234 26704 : ( st_ivas->renderer_type == RENDERER_TD_PANNING ||
2235 21111 : st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX ||
2236 21108 : st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ||
2237 18308 : st_ivas->renderer_type == RENDERER_OSBA_STEREO ||
2238 17549 : st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
2239 15275 : st_ivas->renderer_type == RENDERER_OSBA_LS ||
2240 11489 : st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ||
2241 8924 : st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ||
2242 7778 : st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
2243 : {
2244 20339 : if ( ( error = ivas_ism_renderer_open( st_ivas ) ) != IVAS_ERR_OK )
2245 : {
2246 0 : return error;
2247 : }
2248 : }
2249 :
2250 86027 : if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
2251 : {
2252 31646 : if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) && st_ivas->ism_mode == ISM_SBA_MODE_DISC )
2253 : {
2254 : /* Allocate TD renderer for the objects in DISC mode */
2255 2565 : if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK )
2256 : {
2257 0 : return error;
2258 : }
2259 :
2260 2565 : if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
2261 : {
2262 1142 : if ( ( error = ivas_reverb_open( &st_ivas->hReverb, st_ivas->hHrtfStatistics, st_ivas->hRenderConfig, output_Fs ) ) != IVAS_ERR_OK )
2263 : {
2264 0 : return error;
2265 : }
2266 : }
2267 : }
2268 : }
2269 :
2270 : /*-----------------------------------------------------------------*
2271 : * CLDFB handles for rendering
2272 : *-----------------------------------------------------------------*/
2273 :
2274 86027 : ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses );
2275 :
2276 307345 : for ( i = 0; i < numCldfbAnalyses; i++ )
2277 : {
2278 221318 : if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
2279 : {
2280 0 : return error;
2281 : }
2282 : }
2283 1241141 : for ( ; i < MAX_INTERN_CHANNELS; i++ )
2284 : {
2285 1155114 : st_ivas->cldfbAnaDec[i] = NULL;
2286 : }
2287 :
2288 596476 : for ( i = 0; i < numCldfbSyntheses; i++ )
2289 : {
2290 510449 : if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
2291 : {
2292 0 : return error;
2293 : }
2294 : }
2295 952010 : for ( ; i < MAX_OUTPUT_CHANNELS; i++ )
2296 : {
2297 865983 : st_ivas->cldfbSynDec[i] = NULL;
2298 : }
2299 :
2300 : /* CLDFB Interpolation weights */
2301 86027 : 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 )
2302 : {
2303 38512 : ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig );
2304 : }
2305 :
2306 : /*-----------------------------------------------------------------*
2307 : * LFE handles for rendering after rendering to adjust LFE delay to filter delay
2308 : *-----------------------------------------------------------------*/
2309 :
2310 86027 : if ( st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
2311 : {
2312 3342 : if ( st_ivas->hIntSetup.index_lfe[0] != -1 )
2313 : {
2314 3190 : delay_ns = st_ivas->binaural_latency_ns;
2315 : }
2316 : else
2317 : {
2318 152 : delay_ns = 0;
2319 : }
2320 :
2321 3342 : if ( st_ivas->hBinRenderer != NULL )
2322 : {
2323 107 : if ( st_ivas->hBinRenderer->render_lfe )
2324 : {
2325 30 : if ( output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
2326 : {
2327 : /* Account for filterbank delay */
2328 30 : delay_ns += IVAS_FB_DEC_DELAY_NS;
2329 : }
2330 : }
2331 : else
2332 : {
2333 77 : delay_ns = 0;
2334 : }
2335 : }
2336 : else
2337 : {
2338 3235 : if ( ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) && ( st_ivas->cldfbSynDec[0] != NULL ) )
2339 : {
2340 59 : delay_ns += IVAS_FB_DEC_DELAY_NS;
2341 : }
2342 : }
2343 :
2344 3342 : if ( ( error = ivas_create_lfe_dec( &st_ivas->hLFE, output_Fs, delay_ns ) ) != IVAS_ERR_OK )
2345 : {
2346 0 : return error;
2347 : }
2348 :
2349 3342 : set_zero( st_ivas->hLFE->prevsynth_buf, LFE_PLC_BUFLEN );
2350 3342 : set_zero( st_ivas->hLFE->prior_out_buffer, L_FRAME48k );
2351 : }
2352 :
2353 : /*-----------------------------------------------------------------*
2354 : * Allocate and initialize limiter struct
2355 : *-----------------------------------------------------------------*/
2356 :
2357 86027 : if ( ( error = ivas_limiter_open( &st_ivas->hLimiter, hDecoderConfig->nchan_out, output_Fs ) ) != IVAS_ERR_OK )
2358 : {
2359 0 : return error;
2360 : }
2361 :
2362 : /*-----------------------------------------------------------------*
2363 : * Allocate and initialize JBM struct + buffer
2364 : *-----------------------------------------------------------------*/
2365 :
2366 86027 : if ( st_ivas->hTcBuffer == NULL )
2367 : {
2368 : /* no module has yet open the TC buffer, open a default one */
2369 21543 : granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, ivas_renderer_secondary_select( st_ivas ), output_Fs );
2370 21543 : n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels( st_ivas );
2371 :
2372 21543 : 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 )
2373 : {
2374 0 : return error;
2375 : }
2376 : }
2377 :
2378 86027 : if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && hDecoderConfig->Opt_tsm )
2379 : {
2380 7296 : if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
2381 : {
2382 498 : if ( ( error = ivas_jbm_dec_metadata_open( st_ivas ) ) != IVAS_ERR_OK )
2383 : {
2384 0 : return error;
2385 : }
2386 : }
2387 : }
2388 :
2389 : /*-----------------------------------------------------------------*
2390 : * Allocate floating-point output audio buffers
2391 : *-----------------------------------------------------------------*/
2392 :
2393 86027 : nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, ivas_total_brate );
2394 86027 : if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff, hDecoderConfig->Opt_tsm, st_ivas->hTcBuffer ) ) != IVAS_ERR_OK )
2395 : {
2396 0 : return error;
2397 : }
2398 :
2399 86027 : return IVAS_ERR_OK;
2400 : }
2401 :
2402 :
2403 : /*-------------------------------------------------------------------------
2404 : * destroy_core_dec()
2405 : *
2406 : * Close core decoder handles
2407 : *-------------------------------------------------------------------------*/
2408 :
2409 314871 : void destroy_core_dec(
2410 : DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */
2411 : )
2412 : {
2413 314871 : destroy_cldfb_decoder( hCoreCoder );
2414 :
2415 314871 : if ( hCoreCoder->hGSCDec != NULL )
2416 : {
2417 97181 : free( hCoreCoder->hGSCDec );
2418 97181 : hCoreCoder->hGSCDec = NULL;
2419 : }
2420 :
2421 314871 : if ( hCoreCoder->hPFstat != NULL )
2422 : {
2423 97181 : free( hCoreCoder->hPFstat );
2424 97181 : hCoreCoder->hPFstat = NULL;
2425 : }
2426 :
2427 314871 : if ( hCoreCoder->hMusicPF != NULL )
2428 : {
2429 97181 : free( hCoreCoder->hMusicPF );
2430 97181 : hCoreCoder->hMusicPF = NULL;
2431 : }
2432 :
2433 314871 : if ( hCoreCoder->hBPF != NULL )
2434 : {
2435 97181 : free( hCoreCoder->hBPF );
2436 97181 : hCoreCoder->hBPF = NULL;
2437 : }
2438 :
2439 314871 : if ( hCoreCoder->hBWE_zero != NULL )
2440 : {
2441 97181 : free( hCoreCoder->hBWE_zero );
2442 97181 : hCoreCoder->hBWE_zero = NULL;
2443 : }
2444 :
2445 314871 : if ( hCoreCoder->hTdCngDec != NULL )
2446 : {
2447 59834 : free( hCoreCoder->hTdCngDec );
2448 59834 : hCoreCoder->hTdCngDec = NULL;
2449 : }
2450 :
2451 314871 : if ( hCoreCoder->hSC_VBR != NULL )
2452 : {
2453 495 : free( hCoreCoder->hSC_VBR );
2454 495 : hCoreCoder->hSC_VBR = NULL;
2455 : }
2456 :
2457 314871 : if ( hCoreCoder->hAmrwb_IO != NULL )
2458 : {
2459 495 : free( hCoreCoder->hAmrwb_IO );
2460 495 : hCoreCoder->hAmrwb_IO = NULL;
2461 : }
2462 :
2463 314871 : if ( hCoreCoder->hBWE_TD != NULL )
2464 : {
2465 97305 : free( hCoreCoder->hBWE_TD );
2466 97305 : hCoreCoder->hBWE_TD = NULL;
2467 : }
2468 :
2469 314871 : if ( hCoreCoder->hBWE_FD != NULL )
2470 : {
2471 97305 : free( hCoreCoder->hBWE_FD );
2472 97305 : hCoreCoder->hBWE_FD = NULL;
2473 : }
2474 :
2475 314871 : if ( hCoreCoder->hBWE_FD_HR != NULL )
2476 : {
2477 495 : free( hCoreCoder->hBWE_FD_HR );
2478 495 : hCoreCoder->hBWE_FD_HR = NULL;
2479 : }
2480 :
2481 314871 : if ( hCoreCoder->hWIDec != NULL )
2482 : {
2483 240 : free( hCoreCoder->hWIDec );
2484 240 : hCoreCoder->hWIDec = NULL;
2485 : }
2486 :
2487 314871 : if ( hCoreCoder->hTECDec != NULL )
2488 : {
2489 495 : free( hCoreCoder->hTECDec );
2490 495 : hCoreCoder->hTECDec = NULL;
2491 : }
2492 :
2493 314871 : if ( hCoreCoder->hTcxLtpDec != NULL )
2494 : {
2495 308112 : free( hCoreCoder->hTcxLtpDec );
2496 308112 : hCoreCoder->hTcxLtpDec = NULL;
2497 : }
2498 :
2499 314871 : if ( hCoreCoder->hTcxDec != NULL )
2500 : {
2501 308112 : free( hCoreCoder->hTcxDec );
2502 308112 : hCoreCoder->hTcxDec = NULL;
2503 : }
2504 :
2505 314871 : if ( hCoreCoder->hTcxCfg != NULL )
2506 : {
2507 308112 : free( hCoreCoder->hTcxCfg );
2508 308112 : hCoreCoder->hTcxCfg = NULL;
2509 : }
2510 :
2511 314871 : if ( hCoreCoder->hTonalMDCTConc != NULL )
2512 : {
2513 308112 : free( hCoreCoder->hTonalMDCTConc );
2514 308112 : hCoreCoder->hTonalMDCTConc = NULL;
2515 : }
2516 :
2517 314871 : if ( hCoreCoder->hIGFDec != NULL )
2518 : {
2519 308112 : free( hCoreCoder->hIGFDec );
2520 308112 : hCoreCoder->hIGFDec = NULL;
2521 : }
2522 :
2523 314871 : if ( hCoreCoder->hPlcInfo != NULL )
2524 : {
2525 495 : free( hCoreCoder->hPlcInfo );
2526 495 : hCoreCoder->hPlcInfo = NULL;
2527 : }
2528 :
2529 314871 : if ( hCoreCoder->hHQ_core != NULL )
2530 : {
2531 308112 : free( hCoreCoder->hHQ_core );
2532 308112 : hCoreCoder->hHQ_core = NULL;
2533 : }
2534 :
2535 314871 : if ( hCoreCoder->hHQ_nbfec != NULL )
2536 : {
2537 495 : free( hCoreCoder->hHQ_nbfec );
2538 495 : hCoreCoder->hHQ_nbfec = NULL;
2539 : }
2540 :
2541 314871 : return;
2542 : }
2543 :
2544 :
2545 : /*-------------------------------------------------------------------------
2546 : * ivas_initialize_handles_dec()
2547 : *
2548 : * NULL initialization of handles
2549 : *-------------------------------------------------------------------------*/
2550 :
2551 86027 : void ivas_initialize_handles_dec(
2552 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
2553 : )
2554 : {
2555 : int16_t i;
2556 :
2557 1462459 : for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
2558 : {
2559 1376432 : st_ivas->cldfbAnaDec[i] = NULL;
2560 : }
2561 :
2562 1462459 : for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2563 : {
2564 1376432 : st_ivas->cldfbSynDec[i] = NULL;
2565 : }
2566 :
2567 : /* SCE handles */
2568 430135 : for ( i = 0; i < MAX_SCE; i++ )
2569 : {
2570 344108 : st_ivas->hSCE[i] = NULL;
2571 : }
2572 :
2573 : /* CPE handles */
2574 602189 : for ( i = 0; i < MAX_CPE; i++ )
2575 : {
2576 516162 : st_ivas->hCPE[i] = NULL;
2577 : }
2578 :
2579 86027 : st_ivas->bit_stream = NULL;
2580 86027 : st_ivas->mem_hp20_out = NULL;
2581 86027 : st_ivas->hLimiter = NULL;
2582 :
2583 : /* ISM metadata handles */
2584 430135 : for ( i = 0; i < MAX_NUM_OBJECTS; i++ )
2585 : {
2586 344108 : st_ivas->hIsmMetaData[i] = NULL;
2587 : }
2588 :
2589 : /* spatial coding handles */
2590 86027 : st_ivas->hDirAC = NULL;
2591 86027 : st_ivas->hParamIsmDec = NULL;
2592 86027 : st_ivas->hSpar = NULL;
2593 86027 : st_ivas->hMasa = NULL;
2594 86027 : st_ivas->hQMetaData = NULL;
2595 86027 : st_ivas->hMCT = NULL;
2596 86027 : st_ivas->hMCParamUpmix = NULL;
2597 86027 : st_ivas->hParamMC = NULL;
2598 86027 : st_ivas->hLFE = NULL;
2599 :
2600 : /* rendering handles */
2601 86027 : st_ivas->hBinRenderer = NULL;
2602 774243 : for ( i = 0; i < MAX_HEAD_ROT_POSES; i++ )
2603 : {
2604 688216 : st_ivas->hDiracDecBin[i] = NULL;
2605 : }
2606 86027 : st_ivas->hDirACRend = NULL;
2607 86027 : st_ivas->hSpatParamRendCom = NULL;
2608 86027 : st_ivas->hLsSetUpConversion = NULL;
2609 86027 : st_ivas->hEFAPdata = NULL;
2610 86027 : st_ivas->hVBAPdata = NULL;
2611 86027 : st_ivas->hIsmRendererData = NULL;
2612 86027 : st_ivas->hBinRendererTd = NULL;
2613 86027 : st_ivas->hMonoDmxRenderer = NULL;
2614 86027 : st_ivas->hCrendWrapper = NULL;
2615 86027 : st_ivas->hReverb = NULL;
2616 86027 : st_ivas->hHrtfCrend = NULL;
2617 86027 : st_ivas->hHrtfFastConv = NULL;
2618 86027 : st_ivas->hHrtfParambin = NULL;
2619 86027 : st_ivas->hHrtfStatistics = NULL;
2620 86027 : st_ivas->hoa_dec_mtx = NULL;
2621 86027 : st_ivas->hMasaIsmData = NULL;
2622 86027 : st_ivas->hSbaIsmData = NULL;
2623 :
2624 86027 : st_ivas->hHeadTrackData = NULL;
2625 86027 : st_ivas->hHrtfTD = NULL;
2626 86027 : st_ivas->hLsSetupCustom = NULL;
2627 86027 : st_ivas->hRenderConfig = NULL;
2628 86027 : st_ivas->hExtOrientationData = NULL;
2629 86027 : st_ivas->hCombinedOrientationData = NULL;
2630 :
2631 86027 : st_ivas->hSplitBinRend = NULL;
2632 688216 : for ( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i )
2633 : {
2634 602189 : st_ivas->hTdRendHandles[i] = NULL;
2635 : }
2636 :
2637 : /* JBM handles */
2638 86027 : st_ivas->hTcBuffer = NULL;
2639 86027 : st_ivas->hJbmMetadata = NULL;
2640 :
2641 : /* floating-point output audio buffers */
2642 1806567 : for ( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ )
2643 : {
2644 1720540 : st_ivas->p_output_f[i] = NULL;
2645 : }
2646 :
2647 86027 : return;
2648 : }
2649 :
2650 :
2651 : /*-------------------------------------------------------------------------
2652 : * ivas_destroy_dec()
2653 : *
2654 : * Close IVAS decoder handles
2655 : *-------------------------------------------------------------------------*/
2656 :
2657 86027 : void ivas_destroy_dec(
2658 : Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */
2659 : )
2660 : {
2661 : int16_t i;
2662 :
2663 : /* CLDFB handles */
2664 1462459 : for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
2665 : {
2666 1376432 : if ( st_ivas->cldfbAnaDec[i] != NULL )
2667 : {
2668 221636 : deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) );
2669 : }
2670 : }
2671 :
2672 1462459 : for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2673 : {
2674 1376432 : if ( st_ivas->cldfbSynDec[i] != NULL )
2675 : {
2676 511228 : deleteCldfb( &( st_ivas->cldfbSynDec[i] ) );
2677 : }
2678 : }
2679 :
2680 : /* SCE handles */
2681 430135 : for ( i = 0; i < MAX_SCE; i++ )
2682 : {
2683 344108 : if ( st_ivas->hSCE[i] != NULL )
2684 : {
2685 76402 : destroy_sce_dec( st_ivas->hSCE[i] );
2686 76402 : st_ivas->hSCE[i] = NULL;
2687 : }
2688 : }
2689 :
2690 : /* CPE handles */
2691 602189 : for ( i = 0; i < MAX_CPE; i++ )
2692 : {
2693 516162 : if ( st_ivas->hCPE[i] != NULL )
2694 : {
2695 : /* set pointer to NULL as core coder already deallocated in destroy_sce_dec() */
2696 95231 : if ( st_ivas->sba_dirac_stereo_flag && st_ivas->nchan_transport == 1 )
2697 : {
2698 1363 : st_ivas->hCPE[i]->hCoreCoder[0] = NULL;
2699 1363 : st_ivas->hCPE[i]->hCoreCoder[1] = NULL;
2700 : }
2701 95231 : destroy_cpe_dec( st_ivas->hCPE[i] );
2702 95231 : st_ivas->hCPE[i] = NULL;
2703 : }
2704 : }
2705 :
2706 : /* HP20 filter handles */
2707 86027 : if ( st_ivas->mem_hp20_out != NULL )
2708 : {
2709 337631 : for ( i = 0; i < getNumChanSynthesis( st_ivas ); i++ )
2710 : {
2711 251604 : free( st_ivas->mem_hp20_out[i] );
2712 251604 : st_ivas->mem_hp20_out[i] = NULL;
2713 : }
2714 86027 : free( st_ivas->mem_hp20_out );
2715 86027 : st_ivas->mem_hp20_out = NULL;
2716 : }
2717 :
2718 : /* ISM metadata handles */
2719 86027 : ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 );
2720 :
2721 : /* ISM renderer handle */
2722 86027 : ivas_ism_renderer_close( &( st_ivas->hIsmRendererData ) );
2723 :
2724 : /* DirAC handle */
2725 86027 : if ( st_ivas->ivas_format == ISM_FORMAT )
2726 : {
2727 16209 : ivas_param_ism_dec_close( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config );
2728 : }
2729 : else
2730 : {
2731 69818 : ivas_dirac_rend_close( &( st_ivas->hDirACRend ) );
2732 69818 : ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) );
2733 69818 : ivas_dirac_dec_close( &( st_ivas->hDirAC ) );
2734 : }
2735 :
2736 : /* SPAR handle */
2737 86027 : ivas_spar_dec_close( &( st_ivas->hSpar ), st_ivas->hDecoderConfig->output_Fs, 0 );
2738 :
2739 : /* HOA decoder matrix */
2740 86027 : if ( st_ivas->hoa_dec_mtx != NULL )
2741 : {
2742 15884 : free( st_ivas->hoa_dec_mtx );
2743 15884 : st_ivas->hoa_dec_mtx = NULL;
2744 : }
2745 :
2746 : /* MASA decoder structure */
2747 86027 : ivas_masa_dec_close( &( st_ivas->hMasa ) );
2748 :
2749 : /* Qmetadata handle */
2750 86027 : ivas_qmetadata_close( &st_ivas->hQMetaData );
2751 :
2752 : /* MCT handle */
2753 86027 : ivas_mct_dec_close( &st_ivas->hMCT );
2754 :
2755 : /* LFE handle */
2756 86027 : ivas_lfe_dec_close( &( st_ivas->hLFE ) );
2757 :
2758 : /* Param-Upmix MC handle */
2759 86027 : ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) );
2760 :
2761 : /* Parametric MC handle */
2762 86027 : ivas_param_mc_dec_close( &st_ivas->hParamMC );
2763 :
2764 : /* EFAP handle */
2765 86027 : efap_free_data( &st_ivas->hEFAPdata );
2766 :
2767 : /* VBAP handle */
2768 86027 : vbap_free_data( &( st_ivas->hVBAPdata ) );
2769 :
2770 : /* Fastconv binaural renderer handle */
2771 86027 : ivas_binRenderer_close( &st_ivas->hBinRenderer );
2772 :
2773 : /* TD binaural renderer handles */
2774 688216 : for ( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i )
2775 : {
2776 602189 : if ( st_ivas->hTdRendHandles[i] != NULL )
2777 : {
2778 2664 : st_ivas->hTdRendHandles[i]->HrFiltSet_p = NULL;
2779 2664 : ivas_td_binaural_close( &st_ivas->hTdRendHandles[i] );
2780 : }
2781 : }
2782 :
2783 : /* Parametric binaural renderer handle */
2784 86027 : ivas_dirac_dec_close_binaural_data( st_ivas->hDiracDecBin );
2785 :
2786 : /* Crend handle */
2787 86027 : ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) );
2788 :
2789 : /* Reverb handle */
2790 86027 : ivas_reverb_close( &st_ivas->hReverb );
2791 :
2792 : /* LS config converter handle */
2793 86027 : ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion );
2794 :
2795 : /* Custom LS configuration handle */
2796 86027 : if ( st_ivas->hLsSetupCustom != NULL )
2797 : {
2798 9 : free( st_ivas->hLsSetupCustom );
2799 9 : st_ivas->hLsSetupCustom = NULL;
2800 : }
2801 :
2802 : /* Mono downmix structure */
2803 86027 : ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer );
2804 :
2805 : /* OSBA structure */
2806 86027 : ivas_osba_data_close( &st_ivas->hSbaIsmData );
2807 :
2808 : /* OMASA structure */
2809 86027 : ivas_omasa_data_close( &st_ivas->hMasaIsmData );
2810 :
2811 : /* Head track data handle */
2812 86027 : ivas_headTrack_close( &st_ivas->hHeadTrackData );
2813 :
2814 : /* External orientation data handle */
2815 86027 : ivas_external_orientation_close( &st_ivas->hExtOrientationData );
2816 :
2817 : /* Combined orientation data handle */
2818 86027 : ivas_combined_orientation_close( &st_ivas->hCombinedOrientationData );
2819 :
2820 : /* Time Domain binaural renderer handle */
2821 86027 : if ( st_ivas->hBinRendererTd != NULL )
2822 : {
2823 6668 : ivas_td_binaural_close( &st_ivas->hBinRendererTd );
2824 : }
2825 :
2826 86027 : if ( st_ivas->hHrtfTD != NULL )
2827 : {
2828 0 : BSplineModelEvalDealloc( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval );
2829 :
2830 0 : ivas_HRTF_binary_close( &st_ivas->hHrtfTD );
2831 : }
2832 :
2833 : /* CRend binaural renderer handle */
2834 86027 : ivas_HRTF_CRend_binary_close( &st_ivas->hHrtfCrend );
2835 :
2836 : /* Fastconv HRTF memories */
2837 86027 : ivas_binaural_hrtf_close( &st_ivas->hHrtfFastConv );
2838 :
2839 : /* Fastconv HRTF filters */
2840 86027 : ivas_HRTF_fastconv_binary_close( &st_ivas->hHrtfFastConv );
2841 :
2842 : /* Parametric binauralizer HRTF filters */
2843 86027 : ivas_HRTF_parambin_binary_close( &st_ivas->hHrtfParambin );
2844 :
2845 : /* HRTF statistics */
2846 86027 : ivas_HRTF_statistics_close( &st_ivas->hHrtfStatistics );
2847 :
2848 : /* Config. Renderer */
2849 86027 : ivas_render_config_close( &( st_ivas->hRenderConfig ) );
2850 :
2851 : /* Limiter struct */
2852 86027 : ivas_limiter_close( &( st_ivas->hLimiter ) );
2853 :
2854 : /* Decoder configuration structure */
2855 86027 : if ( st_ivas->hDecoderConfig != NULL )
2856 : {
2857 86027 : free( st_ivas->hDecoderConfig );
2858 86027 : st_ivas->hDecoderConfig = NULL;
2859 : }
2860 :
2861 : /* JBM TC buffer structure */
2862 86027 : ivas_jbm_dec_tc_buffer_close( &st_ivas->hTcBuffer );
2863 :
2864 86027 : if ( st_ivas->hJbmMetadata != NULL )
2865 : {
2866 498 : free( st_ivas->hJbmMetadata );
2867 498 : st_ivas->hJbmMetadata = NULL;
2868 : }
2869 :
2870 : /* floating-point output audio buffers */
2871 1806567 : for ( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ )
2872 : {
2873 1720540 : st_ivas->p_output_f[i] = NULL;
2874 : }
2875 :
2876 : /* main IVAS handle */
2877 86027 : free( st_ivas );
2878 :
2879 86027 : return;
2880 : }
2881 :
2882 :
2883 : /*-------------------------------------------------------------------*
2884 : * ivas_init_dec_get_num_cldfb_instances()
2885 : *
2886 : * Return number of CLDFB analysis & synthesis instances
2887 : *-------------------------------------------------------------------*/
2888 :
2889 : /*! r: number of cldfb instances */
2890 169646 : void ivas_init_dec_get_num_cldfb_instances(
2891 : Decoder_Struct *st_ivas, /* i : IVAS decoder structure */
2892 : int16_t *numCldfbAnalyses, /* o : number of needed CLDFB analysis instances */
2893 : int16_t *numCldfbSyntheses /* o : number of needed CLDFB synthesis instances */
2894 : )
2895 : {
2896 : IVAS_FORMAT ivas_format;
2897 169646 : *numCldfbAnalyses = st_ivas->nchan_transport;
2898 169646 : *numCldfbSyntheses = st_ivas->hDecoderConfig->nchan_out;
2899 :
2900 169646 : 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 */
2901 :
2902 169646 : switch ( st_ivas->renderer_type )
2903 : {
2904 36456 : case RENDERER_BINAURAL_PARAMETRIC:
2905 : case RENDERER_BINAURAL_PARAMETRIC_ROOM:
2906 : case RENDERER_STEREO_PARAMETRIC:
2907 36456 : if ( st_ivas->nchan_transport == 1 )
2908 : {
2909 12382 : *numCldfbAnalyses = st_ivas->nchan_transport + 1;
2910 : }
2911 :
2912 36456 : if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hOutSetup.separateChannelEnabled )
2913 : {
2914 183 : *numCldfbAnalyses = st_ivas->nchan_transport + 1;
2915 : }
2916 :
2917 36456 : if ( ivas_format == SBA_ISM_FORMAT )
2918 : {
2919 0 : if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
2920 : {
2921 0 : *numCldfbAnalyses += st_ivas->nchan_ism;
2922 : }
2923 : }
2924 :
2925 36456 : if ( ivas_format == MASA_ISM_FORMAT )
2926 : {
2927 9662 : if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
2928 : {
2929 5695 : *numCldfbAnalyses += st_ivas->nchan_ism;
2930 : }
2931 3967 : else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ )
2932 : {
2933 3967 : *numCldfbAnalyses = st_ivas->nchan_transport + 1;
2934 : }
2935 : }
2936 :
2937 36456 : if ( st_ivas->hDiracDecBin[0]->useTdDecorr )
2938 : {
2939 14500 : *numCldfbAnalyses += 2;
2940 : }
2941 36456 : break;
2942 4474 : case RENDERER_NON_DIEGETIC_DOWNMIX:
2943 : case RENDERER_MONO_DOWNMIX:
2944 4474 : if ( ivas_format == ISM_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == SBA_ISM_FORMAT )
2945 : {
2946 : /* CLDFB not used in rendering */
2947 4309 : *numCldfbAnalyses = 0;
2948 4309 : *numCldfbSyntheses = 0;
2949 : }
2950 4474 : break;
2951 36466 : case RENDERER_DIRAC:
2952 36466 : if ( ivas_format == SBA_FORMAT )
2953 : {
2954 12982 : *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans;
2955 :
2956 12982 : if ( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC )
2957 : {
2958 12982 : *numCldfbSyntheses = st_ivas->hOutSetup.nchan_out_woLFE;
2959 : }
2960 0 : else if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA )
2961 : {
2962 0 : *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans;
2963 : }
2964 : else
2965 : {
2966 0 : *numCldfbSyntheses = MAX_OUTPUT_CHANNELS;
2967 : }
2968 : }
2969 36466 : if ( ivas_format != SBA_FORMAT )
2970 : {
2971 23484 : if ( st_ivas->nchan_transport > 2 && st_ivas->sba_planar )
2972 : {
2973 0 : *numCldfbAnalyses = st_ivas->nchan_transport + 1;
2974 : }
2975 23484 : else if ( st_ivas->nchan_transport == 1 && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
2976 : {
2977 1707 : *numCldfbAnalyses = st_ivas->nchan_transport + 1;
2978 : }
2979 : }
2980 36466 : break;
2981 1224 : case RENDERER_MC_PARAMMC:
2982 1224 : if ( st_ivas->hDecoderConfig->nchan_out <= 2 )
2983 : {
2984 : /* CLDFB not used in rendering */
2985 180 : *numCldfbAnalyses = 0;
2986 180 : *numCldfbSyntheses = 0;
2987 : }
2988 : else
2989 : {
2990 1044 : *numCldfbSyntheses = param_mc_get_num_cldfb_syntheses( st_ivas );
2991 : }
2992 1224 : break;
2993 1477 : case RENDERER_PARAM_ISM:
2994 : /* Already correct with no exception */
2995 1477 : break;
2996 15647 : case RENDERER_DISABLE:
2997 : /* CLDFB not used */
2998 15647 : *numCldfbAnalyses = 0;
2999 15647 : *numCldfbSyntheses = 0;
3000 15647 : break;
3001 65436 : case RENDERER_MC:
3002 : case RENDERER_SBA_LINEAR_DEC:
3003 : case RENDERER_TD_PANNING:
3004 : case RENDERER_BINAURAL_OBJECTS_TD:
3005 : case RENDERER_MCMASA_MONO_STEREO:
3006 : case RENDERER_BINAURAL_MIXER_CONV:
3007 : case RENDERER_BINAURAL_MIXER_CONV_ROOM:
3008 : case RENDERER_BINAURAL_FASTCONV:
3009 : case RENDERER_BINAURAL_FASTCONV_ROOM:
3010 : case RENDERER_OSBA_STEREO:
3011 : case RENDERER_OSBA_AMBI:
3012 : case RENDERER_OSBA_LS:
3013 65436 : if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT )
3014 : {
3015 39704 : if ( st_ivas->sba_dirac_stereo_flag )
3016 : {
3017 1548 : *numCldfbAnalyses = 0;
3018 1548 : *numCldfbSyntheses = 0;
3019 : }
3020 : else
3021 : {
3022 38156 : *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans;
3023 :
3024 38156 : if ( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC )
3025 : {
3026 0 : *numCldfbSyntheses = st_ivas->hOutSetup.nchan_out_woLFE;
3027 : }
3028 38156 : else if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA )
3029 : {
3030 6050 : *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans;
3031 : }
3032 : else
3033 : {
3034 32106 : *numCldfbSyntheses = MAX_OUTPUT_CHANNELS;
3035 : }
3036 :
3037 38156 : if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
3038 : {
3039 2172 : *numCldfbAnalyses = st_ivas->nchan_ism + st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans;
3040 : }
3041 : }
3042 : }
3043 25732 : else if ( st_ivas->mc_mode == MC_MODE_PARAMMC )
3044 : {
3045 : /* do nothing for ParamMC */
3046 : }
3047 : else
3048 : {
3049 : /* CLDFB not used in rendering */
3050 23799 : *numCldfbAnalyses = 0;
3051 23799 : *numCldfbSyntheses = 0;
3052 : }
3053 65436 : break;
3054 8008 : case RENDERER_SBA_LINEAR_ENC:
3055 8008 : if ( st_ivas->mc_mode == MC_MODE_PARAMMC )
3056 : {
3057 686 : *numCldfbSyntheses = param_mc_get_num_cldfb_syntheses( st_ivas );
3058 : }
3059 7322 : else if ( st_ivas->ism_mode == ISM_MODE_PARAM )
3060 : {
3061 547 : *numCldfbSyntheses = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
3062 : }
3063 6775 : else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
3064 : {
3065 1014 : *numCldfbAnalyses = st_ivas->nchan_transport;
3066 1014 : *numCldfbSyntheses = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
3067 : }
3068 : else
3069 : {
3070 : /* CLDFB not used in rendering */
3071 5761 : *numCldfbAnalyses = 0;
3072 5761 : *numCldfbSyntheses = 0;
3073 : }
3074 8008 : break;
3075 248 : case RENDERER_OMASA_OBJECT_EXT:
3076 248 : *numCldfbAnalyses = st_ivas->nchan_transport;
3077 248 : *numCldfbSyntheses = st_ivas->hDecoderConfig->nchan_out;
3078 248 : break;
3079 210 : case RENDERER_OMASA_MIX_EXT:
3080 210 : *numCldfbAnalyses = st_ivas->nchan_transport + 1;
3081 210 : *numCldfbSyntheses = 0;
3082 210 : break;
3083 0 : default:
3084 0 : assert( 0 && "Renderer not handled for CLDFB reservation." );
3085 : }
3086 :
3087 169646 : 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 )
3088 : {
3089 193 : if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
3090 : {
3091 116 : *numCldfbAnalyses = max( MC_PARAMUPMIX_MAX_INPUT_CHANS, *numCldfbAnalyses );
3092 : }
3093 : else
3094 : {
3095 77 : *numCldfbAnalyses = max( MC_PARAMUPMIX_MIN_CLDFB, *numCldfbAnalyses );
3096 : }
3097 193 : *numCldfbSyntheses = max( MC_PARAMUPMIX_MIN_CLDFB, *numCldfbSyntheses );
3098 : }
3099 :
3100 169646 : return;
3101 : }
3102 :
3103 :
3104 : /*---------------------------------------------------------------------*
3105 : * doSanityChecks_IVAS()
3106 : *
3107 : * Sanity checks - verify if the decoder set-up parameters are
3108 : * not in conflict with the IVAS format
3109 : *---------------------------------------------------------------------*/
3110 :
3111 85532 : static ivas_error doSanityChecks_IVAS(
3112 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
3113 : )
3114 : {
3115 : int32_t output_Fs;
3116 : AUDIO_CONFIG output_config;
3117 :
3118 85532 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
3119 85532 : output_config = st_ivas->hDecoderConfig->output_config;
3120 :
3121 : /*-----------------------------------------------------------------*
3122 : * Sanity checks
3123 : *-----------------------------------------------------------------*/
3124 :
3125 85532 : if ( output_Fs == 8000 )
3126 : {
3127 0 : return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "8kHz output sampling rate is not supported in IVAS." );
3128 : }
3129 :
3130 85532 : assert( st_ivas->ivas_format != UNDEFINED_FORMAT && "\n IVAS format undefined" );
3131 85532 : assert( st_ivas->ivas_format != MONO_FORMAT && "\n Wrong IVAS format: MONO" );
3132 :
3133 : /* Verify output configuration compatible with non-diegetic panning */
3134 85532 : if ( st_ivas->hDecoderConfig->Opt_non_diegetic_pan && ( st_ivas->ivas_format != MONO_FORMAT ) && ( st_ivas->transport_config != IVAS_AUDIO_CONFIG_ISM1 ) )
3135 : {
3136 0 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Error: Non-diegetic panning not supported in this IVAS format" );
3137 : }
3138 :
3139 : /* Verify stereo output configuration */
3140 85532 : if ( st_ivas->ivas_format == STEREO_FORMAT )
3141 : {
3142 1559 : 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 )
3143 : {
3144 0 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Wrong output configuration specified for Stereo!" );
3145 : }
3146 : }
3147 : /* Verify output configuration for other formats */
3148 : else
3149 : {
3150 83973 : if ( output_config == IVAS_AUDIO_CONFIG_INVALID )
3151 : {
3152 0 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified!" );
3153 : }
3154 : }
3155 :
3156 85532 : if ( ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) && output_Fs != 48000 )
3157 : {
3158 0 : return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Error: Only 48kHz output sampling rate is supported for split rendering." );
3159 : }
3160 :
3161 85532 : if ( st_ivas->hDecoderConfig->Opt_Headrotation )
3162 : {
3163 2345 : 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 ) )
3164 : {
3165 0 : return IVAS_ERROR( IVAS_ERR_HEAD_ROTATION_NOT_SUPPORTED, "Wrong set-up: Head-rotation not supported in this configuration" );
3166 : }
3167 : }
3168 :
3169 85532 : if ( st_ivas->hDecoderConfig->Opt_ExternalOrientation )
3170 : {
3171 93 : if ( !( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
3172 : {
3173 0 : return IVAS_ERROR( IVAS_ERR_EXT_ORIENTATION_NOT_SUPPORTED, "Wrong set-up: External orientation not supported in this configuration" );
3174 : }
3175 : }
3176 :
3177 85532 : if ( st_ivas->hDecoderConfig->Opt_dpid_on )
3178 : {
3179 6 : if ( !( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
3180 : {
3181 0 : return IVAS_ERROR( IVAS_ERR_DIRECTIVITY_NOT_SUPPORTED, "Wrong set-up: Directivity is not supported in this output configuration." );
3182 : }
3183 : }
3184 :
3185 85532 : if ( st_ivas->hDecoderConfig->Opt_aeid_on )
3186 : {
3187 12 : if ( output_config != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
3188 : {
3189 0 : return IVAS_ERROR( IVAS_ERR_ACOUSTIC_ENVIRONMENT_NOT_SUPPORTED, "Wrong set-up: Acoustic environment is not supported in this output configuration." );
3190 : }
3191 : }
3192 :
3193 85532 : if ( st_ivas->hDecoderConfig->Opt_ObjEdit_on )
3194 : {
3195 39 : 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 ) ) )
3196 : {
3197 0 : return IVAS_ERROR( IVAS_ERR_OBJECTS_EDITING_NOT_SUPPORTED, "Wrong set-up: Object editing is not supported in this IVAS format." );
3198 : }
3199 : }
3200 :
3201 85532 : if ( st_ivas->hDecoderConfig->Opt_ObjEdit_on && st_ivas->hDecoderConfig->Opt_non_diegetic_pan )
3202 : {
3203 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." );
3204 : }
3205 :
3206 85532 : return IVAS_ERR_OK;
3207 : }
|