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 <stdint.h>
34 : #include <string.h>
35 : #include "options.h"
36 : #include "ivas_cnst.h"
37 : #include "prot_fx.h"
38 : #include "ivas_prot_rend_fx.h"
39 : #include "ivas_rom_com.h"
40 : #include "ivas_rom_com_fx.h"
41 : #include "wmc_auto.h"
42 : #include "ivas_prot_fx.h"
43 : /*-------------------------------------------------------------------------*
44 : * audioCfg2channels()
45 : *
46 : * Map Audio configuration to number of channels
47 : *-------------------------------------------------------------------------*/
48 :
49 : /*! r: number of audio channels */
50 14059124 : Word16 audioCfg2channels(
51 : AUDIO_CONFIG output_config /* i : output audio configuration */
52 : )
53 : {
54 : Word16 nchan_out;
55 :
56 14059124 : SWITCH( output_config )
57 : {
58 313402 : case IVAS_AUDIO_CONFIG_MONO:
59 313402 : nchan_out = 1;
60 313402 : move16();
61 313402 : BREAK;
62 531428 : case IVAS_AUDIO_CONFIG_STEREO:
63 531428 : nchan_out = 2;
64 531428 : move16();
65 531428 : BREAK;
66 1515629 : case IVAS_AUDIO_CONFIG_5_1:
67 1515629 : nchan_out = 6;
68 1515629 : move16();
69 1515629 : BREAK;
70 211082 : case IVAS_AUDIO_CONFIG_7_1:
71 211082 : nchan_out = 8;
72 211082 : move16();
73 211082 : BREAK;
74 67529 : case IVAS_AUDIO_CONFIG_5_1_2:
75 67529 : nchan_out = 8;
76 67529 : move16();
77 67529 : BREAK;
78 104541 : case IVAS_AUDIO_CONFIG_5_1_4:
79 104541 : nchan_out = 10;
80 104541 : move16();
81 104541 : BREAK;
82 1114257 : case IVAS_AUDIO_CONFIG_7_1_4:
83 1114257 : nchan_out = 12;
84 1114257 : move16();
85 1114257 : BREAK;
86 2492009 : case IVAS_AUDIO_CONFIG_FOA:
87 2492009 : nchan_out = 4;
88 2492009 : move16();
89 2492009 : BREAK;
90 353338 : case IVAS_AUDIO_CONFIG_HOA2:
91 353338 : nchan_out = 9;
92 353338 : move16();
93 353338 : BREAK;
94 2233260 : case IVAS_AUDIO_CONFIG_HOA3:
95 2233260 : nchan_out = 16;
96 2233260 : move16();
97 2233260 : BREAK;
98 0 : case IVAS_AUDIO_CONFIG_OBA:
99 0 : nchan_out = 8;
100 0 : move16();
101 0 : BREAK;
102 3961908 : case IVAS_AUDIO_CONFIG_BINAURAL:
103 : case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED:
104 : case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM:
105 : case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR:
106 : case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB:
107 3961908 : nchan_out = 2;
108 3961908 : move16();
109 3961908 : BREAK;
110 417799 : case IVAS_AUDIO_CONFIG_ISM1:
111 417799 : nchan_out = 1;
112 417799 : move16();
113 417799 : BREAK;
114 133686 : case IVAS_AUDIO_CONFIG_ISM2:
115 133686 : nchan_out = 2;
116 133686 : move16();
117 133686 : BREAK;
118 165468 : case IVAS_AUDIO_CONFIG_ISM3:
119 165468 : nchan_out = 3;
120 165468 : move16();
121 165468 : BREAK;
122 443788 : case IVAS_AUDIO_CONFIG_ISM4:
123 443788 : nchan_out = 4;
124 443788 : move16();
125 443788 : BREAK;
126 0 : default:
127 0 : IVAS_ERROR( IVAS_ERR_INTERNAL, "Error: illegal output configuration\n" );
128 0 : nchan_out = -1;
129 0 : move16();
130 0 : BREAK;
131 : }
132 :
133 14059124 : return ( nchan_out );
134 : }
135 :
136 : /*-------------------------------------------------------------------------*
137 : * ivas_output_init()
138 : *
139 : * Initialize and configure IVAS output parameters
140 : *-------------------------------------------------------------------------*/
141 5751 : void ivas_output_init(
142 : IVAS_OUTPUT_SETUP *hOutSetup, /* o : IVAS output setup structure */
143 : const AUDIO_CONFIG output_config /* i : output audio configuration */
144 : )
145 : {
146 : Word16 nchan_out;
147 :
148 : /* set general default values */
149 5751 : hOutSetup->output_config = output_config;
150 5751 : move16();
151 5751 : hOutSetup->is_loudspeaker_setup = 0;
152 5751 : move16();
153 5751 : hOutSetup->is_binaural_setup = 0;
154 5751 : move16();
155 5751 : hOutSetup->ambisonics_order = -1;
156 5751 : move16();
157 5751 : hOutSetup->separateChannelEnabled = 0;
158 5751 : move16();
159 5751 : hOutSetup->separateChannelIndex = 0;
160 5751 : move16();
161 :
162 5751 : IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
163 : {
164 5 : hOutSetup->is_loudspeaker_setup = 1;
165 5 : move16();
166 : /* set in ivas_init_decoder: */
167 : /* hOutSetup->ls_azimuth */
168 : /* hOutSetup->ls_elevation */
169 : /* hOutSetup->num_lfe */
170 : /* hOutSetup->index_lfe[0] */
171 : /* hOutSetup->is_planar_setup */
172 : }
173 : ELSE
174 : {
175 : /* Set default values for all other than custom LS setup */
176 5746 : hOutSetup->ls_azimuth_fx = NULL;
177 5746 : hOutSetup->ls_elevation_fx = NULL;
178 5746 : hOutSetup->num_lfe = 0;
179 5746 : move16();
180 5746 : hOutSetup->index_lfe[0] = -1;
181 5746 : move16();
182 5746 : hOutSetup->is_planar_setup = 0;
183 5746 : move16();
184 :
185 : /* set output setup specific values */
186 5746 : SWITCH( output_config )
187 : {
188 101 : case IVAS_AUDIO_CONFIG_MONO:
189 101 : hOutSetup->is_loudspeaker_setup = 1;
190 101 : move16();
191 101 : BREAK;
192 178 : case IVAS_AUDIO_CONFIG_STEREO:
193 178 : hOutSetup->is_loudspeaker_setup = 1;
194 178 : move16();
195 178 : hOutSetup->ls_azimuth_fx = ls_azimuth_CICP2_fx; // Q22
196 178 : hOutSetup->ls_elevation_fx = ls_elevation_CICP2_fx; // Q22
197 178 : BREAK;
198 1651 : case IVAS_AUDIO_CONFIG_FOA:
199 1651 : hOutSetup->ambisonics_order = SBA_FOA_ORDER;
200 1651 : move16();
201 1651 : BREAK;
202 99 : case IVAS_AUDIO_CONFIG_HOA2:
203 99 : hOutSetup->ambisonics_order = SBA_HOA2_ORDER;
204 99 : move16();
205 99 : BREAK;
206 479 : case IVAS_AUDIO_CONFIG_HOA3:
207 479 : hOutSetup->ambisonics_order = SBA_HOA3_ORDER;
208 479 : move16();
209 479 : BREAK;
210 906 : case IVAS_AUDIO_CONFIG_5_1:
211 906 : hOutSetup->num_lfe = 1;
212 906 : move16();
213 906 : hOutSetup->index_lfe[0] = 3;
214 906 : move16();
215 906 : hOutSetup->is_loudspeaker_setup = 1;
216 906 : move16();
217 906 : hOutSetup->ls_azimuth_fx = ls_azimuth_CICP6_fx; // Q22
218 906 : hOutSetup->ls_elevation_fx = ls_elevation_CICP6_fx; // Q22
219 906 : hOutSetup->is_planar_setup = 1;
220 906 : move16();
221 906 : BREAK;
222 58 : case IVAS_AUDIO_CONFIG_7_1:
223 58 : hOutSetup->num_lfe = 1;
224 58 : move16();
225 58 : hOutSetup->index_lfe[0] = 3;
226 58 : move16();
227 58 : hOutSetup->is_loudspeaker_setup = 1;
228 58 : move16();
229 58 : hOutSetup->ls_azimuth_fx = ls_azimuth_CICP12_fx; // Q22
230 58 : hOutSetup->ls_elevation_fx = ls_elevation_CICP12_fx; // Q22
231 58 : hOutSetup->is_planar_setup = 1;
232 58 : move16();
233 58 : BREAK;
234 53 : case IVAS_AUDIO_CONFIG_5_1_2:
235 53 : hOutSetup->num_lfe = 1;
236 53 : move16();
237 53 : hOutSetup->index_lfe[0] = 3;
238 53 : move16();
239 53 : hOutSetup->is_loudspeaker_setup = 1;
240 53 : move16();
241 53 : hOutSetup->ls_azimuth_fx = ls_azimuth_CICP14_fx; // Q22
242 53 : hOutSetup->ls_elevation_fx = ls_elevation_CICP14_fx; // Q22
243 53 : hOutSetup->is_planar_setup = 0;
244 53 : move16();
245 53 : BREAK;
246 53 : case IVAS_AUDIO_CONFIG_5_1_4:
247 53 : hOutSetup->num_lfe = 1;
248 53 : move16();
249 53 : hOutSetup->index_lfe[0] = 3;
250 53 : move16();
251 53 : hOutSetup->is_loudspeaker_setup = 1;
252 53 : move16();
253 53 : hOutSetup->ls_azimuth_fx = ls_azimuth_CICP16_fx; // Q22
254 53 : hOutSetup->ls_elevation_fx = ls_elevation_CICP16_fx; // Q22
255 53 : hOutSetup->is_planar_setup = 0;
256 53 : move16();
257 53 : BREAK;
258 737 : case IVAS_AUDIO_CONFIG_7_1_4:
259 737 : hOutSetup->num_lfe = 1;
260 737 : move16();
261 737 : hOutSetup->index_lfe[0] = 3;
262 737 : move16();
263 737 : hOutSetup->is_loudspeaker_setup = 1;
264 737 : move16();
265 737 : hOutSetup->ls_azimuth_fx = ls_azimuth_CICP19_fx; // Q22
266 737 : hOutSetup->ls_elevation_fx = ls_elevation_CICP19_fx; // Q22
267 737 : hOutSetup->is_planar_setup = 0;
268 737 : move16();
269 737 : BREAK;
270 891 : case IVAS_AUDIO_CONFIG_BINAURAL:
271 : case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED:
272 : case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM:
273 : case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR:
274 : case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB:
275 : case IVAS_AUDIO_CONFIG_ISM1:
276 : case IVAS_AUDIO_CONFIG_ISM2:
277 : case IVAS_AUDIO_CONFIG_ISM3:
278 : case IVAS_AUDIO_CONFIG_ISM4:
279 891 : hOutSetup->is_binaural_setup = 1;
280 891 : move16();
281 1431 : case IVAS_AUDIO_CONFIG_EXTERNAL:
282 : /* Default values are used */
283 1431 : BREAK;
284 0 : default:
285 0 : return;
286 : }
287 : }
288 :
289 5751 : test();
290 5751 : IF( NE_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && NE_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
291 : {
292 5206 : nchan_out = audioCfg2channels( output_config );
293 5206 : hOutSetup->nchan_out_woLFE = sub( nchan_out, hOutSetup->num_lfe );
294 5206 : move16();
295 : }
296 :
297 5751 : return;
298 : }
299 :
300 :
301 : /*-----------------------------------------------------------------*
302 : * ivas_get_nchan_buffers_dec()
303 : *
304 : * Return number of decoder audio buffers
305 : *-----------------------------------------------------------------*/
306 :
307 : /*! r: number of decoder buffers */
308 5699925 : Word16 ivas_get_nchan_buffers_dec_fx(
309 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
310 : const Word16 sba_analysis_order, /* i : SBA order evaluated in SBA decoder */
311 : const Word32 ivas_total_brate /* i : total IVAS bitrate */
312 : )
313 : {
314 : Word16 nchan_out_buff;
315 : AUDIO_CONFIG output_config;
316 :
317 5699925 : output_config = st_ivas->hDecoderConfig->output_config;
318 5699925 : move16();
319 :
320 5699925 : nchan_out_buff = MAX_OUTPUT_CHANNELS;
321 5699925 : move16();
322 :
323 5699925 : IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) )
324 : {
325 7207 : nchan_out_buff = st_ivas->hDecoderConfig->nchan_out;
326 7207 : move16();
327 : }
328 5692718 : ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
329 : {
330 421920 : nchan_out_buff = s_max( st_ivas->hDecoderConfig->nchan_out, CPE_CHANNELS );
331 : }
332 5270798 : ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
333 : {
334 1111623 : nchan_out_buff = st_ivas->nchan_ism;
335 1111623 : move16();
336 :
337 1111623 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
338 : {
339 51017 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
340 : }
341 1060606 : ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
342 : {
343 912673 : nchan_out_buff = s_max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) );
344 912673 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
345 : }
346 : }
347 4159175 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
348 : {
349 : Word16 nchan_internal;
350 1962829 : nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate );
351 1962829 : nchan_out_buff = st_ivas->hDecoderConfig->nchan_out;
352 1962829 : move16();
353 :
354 1962829 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
355 : {
356 34017 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
357 : }
358 : #ifdef FIX_1138_SBA_EXT_ERROR_PRINTOUT
359 1928812 : ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
360 : #else
361 : ELSE
362 : #endif
363 : {
364 1848106 : nchan_out_buff = s_max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) );
365 1848106 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
366 : }
367 1962829 : nchan_out_buff = s_max( nchan_out_buff, nchan_internal );
368 : }
369 2196346 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
370 : {
371 298948 : nchan_out_buff = CPE_CHANNELS;
372 298948 : move16();
373 :
374 298948 : test();
375 298948 : test();
376 298948 : test();
377 298948 : test();
378 298948 : test();
379 298948 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
380 : {
381 0 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
382 : }
383 298948 : ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ||
384 : EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
385 : {
386 112652 : nchan_out_buff = shl( CPE_CHANNELS, 1 );
387 : }
388 186296 : ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
389 : {
390 163451 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
391 163451 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
392 : }
393 : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
394 298948 : test();
395 : #ifdef NONBE_FIX_1074_NOBJ_SIGNAL_OMASA_LBR
396 298948 : test();
397 298948 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && GT_16( st_ivas->nchan_ism, 0 ) && LT_16( st_ivas->nchan_ism, 5 ) ) /* Last condition needed only in BASOP */
398 : #else
399 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && GT_16( st_ivas->nchan_ism, 0 ) )
400 : #endif
401 : {
402 570 : nchan_out_buff = add( st_ivas->nchan_ism, CPE_CHANNELS );
403 : }
404 : #endif
405 : }
406 1897398 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
407 : {
408 89005 : nchan_out_buff = add( st_ivas->nchan_ism, CPE_CHANNELS );
409 :
410 : #ifdef FIX_1222_OMASA_DEC_CHANNEL_BUFFERS
411 89005 : test();
412 89005 : test();
413 : #endif
414 89005 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
415 : {
416 0 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
417 : }
418 : #ifdef FIX_1222_OMASA_DEC_CHANNEL_BUFFERS
419 89005 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
420 : {
421 26729 : nchan_out_buff = s_max( nchan_out_buff, add( BINAURAL_CHANNELS, st_ivas->nchan_ism ) );
422 : }
423 : #endif
424 62276 : ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
425 : {
426 56073 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
427 56073 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
428 : }
429 : }
430 1808393 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
431 : {
432 : Word16 nchan_internal;
433 955406 : nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate );
434 955406 : nchan_out_buff = add( st_ivas->nchan_ism, st_ivas->nchan_transport );
435 :
436 955406 : IF( st_ivas->hMCT != NULL )
437 : {
438 711757 : nchan_out_buff = shl( shr( add( nchan_out_buff, 1 ), 1 ), 1 ); /* ensure odd number of channels in MCT */
439 : }
440 :
441 955406 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
442 : {
443 0 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
444 : }
445 955406 : ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
446 : {
447 849171 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
448 849171 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
449 :
450 849171 : test();
451 849171 : IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) )
452 : {
453 92046 : nchan_out_buff = s_max( add( nchan_out_buff, st_ivas->nchan_ism ), audioCfg2channels( output_config ) ); /* needed for ivas_sba_upmixer_renderer() */
454 : }
455 : ELSE
456 : {
457 757125 : nchan_out_buff = s_max( add( nchan_out_buff, st_ivas->nchan_ism ), audioCfg2channels( output_config ) ); /* needed for ivas_spar_dec_upmixer_sf() which is based on 'nchan_out' */
458 : }
459 : }
460 106235 : ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
461 : {
462 106235 : nchan_out_buff = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); /*take into account sba_ch_idx' in ivas_dec() */
463 : }
464 :
465 955406 : test();
466 955406 : IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) )
467 : {
468 852114 : nchan_out_buff = s_max( nchan_out_buff, add( nchan_internal, st_ivas->nchan_ism ) );
469 : }
470 955406 : nchan_out_buff = s_min( nchan_out_buff, MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS );
471 : }
472 852987 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
473 : {
474 852987 : nchan_out_buff = st_ivas->hDecoderConfig->nchan_out;
475 :
476 852987 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
477 : {
478 34017 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
479 : }
480 : #ifdef FIX_1052_EXT_OUTPUT
481 818970 : ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
482 : #else
483 : ELSE
484 : #endif
485 : {
486 806148 : nchan_out_buff = s_max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) );
487 806148 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
488 : }
489 : }
490 :
491 5699925 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
492 : {
493 0 : nchan_out_buff = max( nchan_out_buff, st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses * BINAURAL_CHANNELS );
494 : }
495 :
496 5699925 : return nchan_out_buff;
497 : }
498 :
499 :
500 : /*-------------------------------------------------------------------*
501 : * ivas_output_buff_dec()
502 : *
503 : * Allocate/reallocate output audio buffers
504 : *-------------------------------------------------------------------*/
505 :
506 5193 : ivas_error ivas_output_buff_dec_fx(
507 : Word32 *p_output_f[], /* i/o: output audio buffers */
508 : const Word16 nchan_out_buff_old, /* i : previous frame number of output channels */
509 : const Word16 nchan_out_buff /* i : number of output channels */
510 : )
511 : {
512 : Word16 ch;
513 :
514 5193 : IF( GT_16( nchan_out_buff, nchan_out_buff_old ) )
515 : {
516 3415 : FOR( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ )
517 : {
518 : /* note: these are intra-frame heap memories */
519 2883 : IF( ( p_output_f[ch] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ) ) == NULL ) /* note: 32000 == max internal sampling rate */
520 : {
521 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) );
522 : }
523 : }
524 : }
525 : ELSE
526 : {
527 7450 : FOR( ch = nchan_out_buff; ch < nchan_out_buff_old; ch++ )
528 : {
529 2789 : free( p_output_f[ch] );
530 2789 : p_output_f[ch] = NULL;
531 : }
532 : }
533 :
534 5193 : return IVAS_ERR_OK;
535 : }
536 :
537 :
538 : /*---------------------------------------------------------------------*
539 : * is_split_rendering_enabled()
540 : *
541 : *
542 : *---------------------------------------------------------------------*/
543 :
544 : /*! r: flag to indicate if split rendering is enabled */
545 426307 : Word16 is_split_rendering_enabled(
546 : const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */
547 : const IVAS_RENDER_CONFIG_HANDLE hRenderConfig /* i : Render config data structure */
548 : )
549 : {
550 426307 : test();
551 426307 : test();
552 426307 : test();
553 426307 : test();
554 426307 : IF( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ||
555 : ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && hDecoderConfig->Opt_non_diegetic_pan && hRenderConfig->split_rend_config.dof == 0 ) )
556 : {
557 0 : return 1;
558 : }
559 : else
560 : {
561 426307 : return 0;
562 : }
563 : }
564 :
565 :
566 : /*---------------------------------------------------------------------*
567 : * get_channel_config()
568 : *
569 : * Gets a str related to audio configuration
570 : *---------------------------------------------------------------------*/
571 :
572 2005 : ivas_error get_channel_config(
573 : const AUDIO_CONFIG config, /* i : audio configuration */
574 : Word8 *str /* o : string with the configuration name */
575 : )
576 : {
577 2005 : IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_MONO ) )
578 : {
579 114 : strcpy( (char *) str, "Mono" );
580 : }
581 1891 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_STEREO ) )
582 : {
583 171 : strcpy( (char *) str, "Stereo" );
584 : }
585 1720 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_ISM1 ) )
586 : {
587 39 : strcpy( (char *) str, "Object-based audio (1 object)" );
588 : }
589 1681 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_ISM2 ) )
590 : {
591 74 : strcpy( (char *) str, "Object-based audio (2 objects)" );
592 : }
593 1607 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_ISM3 ) )
594 : {
595 34 : strcpy( (char *) str, "Object-based audio (3 objects)" );
596 : }
597 1573 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_ISM4 ) )
598 : {
599 35 : strcpy( (char *) str, "Object-based audio (4 objects)" );
600 : }
601 1538 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_5_1 ) )
602 : {
603 97 : strcpy( (char *) str, "Multichannel 5.1 (CICP6)" );
604 : }
605 1441 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_7_1 ) )
606 : {
607 83 : strcpy( (char *) str, "Multichannel 7.1 (CICP12)" );
608 : }
609 1358 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_5_1_2 ) )
610 : {
611 81 : strcpy( (char *) str, "Multichannel 5.1+2 (CICP14)" );
612 : }
613 1277 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_5_1_4 ) )
614 : {
615 101 : strcpy( (char *) str, "Multichannel 5.1+4 (CICP16)" );
616 : }
617 1176 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_7_1_4 ) )
618 : {
619 92 : strcpy( (char *) str, "Multichannel 7.1+4 (CICP19)" );
620 : }
621 1084 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
622 : {
623 155 : strcpy( (char *) str, "Multichannel (custom loudspeaker layout)" );
624 : }
625 929 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_MASA1 ) )
626 : {
627 24 : strcpy( (char *) str, "Metadata-Assisted Spatial Audio mono (MASA1)" );
628 : }
629 905 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_MASA2 ) )
630 : {
631 26 : strcpy( (char *) str, "Metadata-Assisted Spatial Audio stereo (MASA2)" );
632 : }
633 879 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_FOA ) )
634 : {
635 261 : strcpy( (char *) str, "Ambisonics: First Order (FOA)" );
636 : }
637 618 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_HOA2 ) )
638 : {
639 84 : strcpy( (char *) str, "Ambisonics: Second Order (HOA2)" );
640 : }
641 534 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_HOA3 ) )
642 : {
643 95 : strcpy( (char *) str, "Ambisonics: Third Order (HOA3)" );
644 : }
645 439 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_BINAURAL ) )
646 : {
647 163 : strcpy( (char *) str, "Binaural: no room" );
648 : }
649 276 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
650 : {
651 115 : strcpy( (char *) str, "Binaural: room with impulse responses" );
652 : }
653 161 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
654 : {
655 111 : strcpy( (char *) str, "Binaural: room with reverb" );
656 : }
657 50 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) )
658 : {
659 0 : strcpy( (char *) str, "BINAURAL_SPLIT_CODED" );
660 : }
661 50 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
662 : {
663 0 : strcpy( (char *) str, "Binaural_Split_PCM" );
664 : }
665 50 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
666 : {
667 50 : strcpy( (char *) str, "External renderer" );
668 : }
669 : ELSE
670 : {
671 0 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Error: Incorrect Input/Output Configuration" );
672 : }
673 :
674 2005 : return IVAS_ERR_OK;
675 : }
|