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