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 14542276 : Word16 audioCfg2channels(
51 : AUDIO_CONFIG output_config /* i : output audio configuration */
52 : )
53 : {
54 : Word16 nchan_out;
55 :
56 14542276 : SWITCH( output_config )
57 : {
58 340495 : case IVAS_AUDIO_CONFIG_MONO:
59 340495 : nchan_out = 1;
60 340495 : move16();
61 340495 : BREAK;
62 593867 : case IVAS_AUDIO_CONFIG_STEREO:
63 593867 : nchan_out = 2;
64 593867 : move16();
65 593867 : BREAK;
66 1498419 : case IVAS_AUDIO_CONFIG_5_1:
67 1498419 : nchan_out = 6;
68 1498419 : move16();
69 1498419 : BREAK;
70 221554 : case IVAS_AUDIO_CONFIG_7_1:
71 221554 : nchan_out = 8;
72 221554 : move16();
73 221554 : BREAK;
74 70962 : case IVAS_AUDIO_CONFIG_5_1_2:
75 70962 : nchan_out = 8;
76 70962 : move16();
77 70962 : BREAK;
78 109083 : case IVAS_AUDIO_CONFIG_5_1_4:
79 109083 : nchan_out = 10;
80 109083 : move16();
81 109083 : BREAK;
82 1151745 : case IVAS_AUDIO_CONFIG_7_1_4:
83 1151745 : nchan_out = 12;
84 1151745 : move16();
85 1151745 : BREAK;
86 2767704 : case IVAS_AUDIO_CONFIG_FOA:
87 2767704 : nchan_out = 4;
88 2767704 : move16();
89 2767704 : BREAK;
90 378385 : case IVAS_AUDIO_CONFIG_HOA2:
91 378385 : nchan_out = 9;
92 378385 : move16();
93 378385 : BREAK;
94 2187511 : case IVAS_AUDIO_CONFIG_HOA3:
95 2187511 : nchan_out = 16;
96 2187511 : move16();
97 2187511 : BREAK;
98 0 : case IVAS_AUDIO_CONFIG_OBA:
99 0 : nchan_out = 8;
100 0 : move16();
101 0 : BREAK;
102 3875125 : case IVAS_AUDIO_CONFIG_BINAURAL:
103 : case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR:
104 : case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB:
105 3875125 : nchan_out = 2;
106 3875125 : move16();
107 3875125 : BREAK;
108 433250 : case IVAS_AUDIO_CONFIG_ISM1:
109 433250 : nchan_out = 1;
110 433250 : move16();
111 433250 : BREAK;
112 146395 : case IVAS_AUDIO_CONFIG_ISM2:
113 146395 : nchan_out = 2;
114 146395 : move16();
115 146395 : BREAK;
116 175976 : case IVAS_AUDIO_CONFIG_ISM3:
117 175976 : nchan_out = 3;
118 175976 : move16();
119 175976 : BREAK;
120 459805 : case IVAS_AUDIO_CONFIG_ISM4:
121 459805 : nchan_out = 4;
122 459805 : move16();
123 459805 : BREAK;
124 132000 : default:
125 132000 : IVAS_ERROR( IVAS_ERR_INTERNAL, "Error: illegal output configuration\n" );
126 132000 : nchan_out = -1;
127 132000 : move16();
128 132000 : BREAK;
129 : }
130 :
131 14542276 : return ( nchan_out );
132 : }
133 :
134 : /*-------------------------------------------------------------------------*
135 : * ivas_output_init()
136 : *
137 : * Initialize and configure IVAS output parameters
138 : *-------------------------------------------------------------------------*/
139 5347 : void ivas_output_init(
140 : IVAS_OUTPUT_SETUP *hOutSetup, /* o : IVAS output setup structure */
141 : const AUDIO_CONFIG output_config /* i : output audio configuration */
142 : )
143 : {
144 : Word16 nchan_out;
145 :
146 : /* set general default values */
147 5347 : hOutSetup->output_config = output_config;
148 5347 : move16();
149 5347 : hOutSetup->is_loudspeaker_setup = 0;
150 5347 : move16();
151 5347 : hOutSetup->is_binaural_setup = 0;
152 5347 : move16();
153 5347 : hOutSetup->ambisonics_order = -1;
154 5347 : move16();
155 5347 : hOutSetup->separateChannelEnabled = 0;
156 5347 : move16();
157 5347 : hOutSetup->separateChannelIndex = 0;
158 5347 : move16();
159 :
160 5347 : IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
161 : {
162 5 : hOutSetup->is_loudspeaker_setup = 1;
163 5 : move16();
164 : /* set in ivas_init_decoder: */
165 : /* hOutSetup->ls_azimuth */
166 : /* hOutSetup->ls_elevation */
167 : /* hOutSetup->num_lfe */
168 : /* hOutSetup->index_lfe[0] */
169 : /* hOutSetup->is_planar_setup */
170 : }
171 : ELSE
172 : {
173 : /* Set default values for all other than custom LS setup */
174 5342 : hOutSetup->ls_azimuth_fx = NULL;
175 5342 : hOutSetup->ls_elevation_fx = NULL;
176 5342 : hOutSetup->num_lfe = 0;
177 5342 : move16();
178 5342 : hOutSetup->index_lfe[0] = -1;
179 5342 : move16();
180 5342 : hOutSetup->is_planar_setup = 0;
181 5342 : move16();
182 :
183 : /* set output setup specific values */
184 5342 : SWITCH( output_config )
185 : {
186 101 : case IVAS_AUDIO_CONFIG_MONO:
187 101 : hOutSetup->is_loudspeaker_setup = 1;
188 101 : move16();
189 101 : BREAK;
190 178 : case IVAS_AUDIO_CONFIG_STEREO:
191 178 : hOutSetup->is_loudspeaker_setup = 1;
192 178 : move16();
193 178 : hOutSetup->ls_azimuth_fx = ls_azimuth_CICP2_fx; // Q22
194 178 : hOutSetup->ls_elevation_fx = ls_elevation_CICP2_fx; // Q22
195 178 : BREAK;
196 1564 : case IVAS_AUDIO_CONFIG_FOA:
197 1564 : hOutSetup->ambisonics_order = SBA_FOA_ORDER;
198 1564 : move16();
199 1564 : BREAK;
200 95 : case IVAS_AUDIO_CONFIG_HOA2:
201 95 : hOutSetup->ambisonics_order = SBA_HOA2_ORDER;
202 95 : move16();
203 95 : BREAK;
204 444 : case IVAS_AUDIO_CONFIG_HOA3:
205 444 : hOutSetup->ambisonics_order = SBA_HOA3_ORDER;
206 444 : move16();
207 444 : BREAK;
208 831 : case IVAS_AUDIO_CONFIG_5_1:
209 831 : hOutSetup->num_lfe = 1;
210 831 : move16();
211 831 : hOutSetup->index_lfe[0] = 3;
212 831 : move16();
213 831 : hOutSetup->is_loudspeaker_setup = 1;
214 831 : move16();
215 831 : hOutSetup->ls_azimuth_fx = ls_azimuth_CICP6_fx; // Q22
216 831 : hOutSetup->ls_elevation_fx = ls_elevation_CICP6_fx; // Q22
217 831 : hOutSetup->is_planar_setup = 1;
218 831 : move16();
219 831 : BREAK;
220 32 : case IVAS_AUDIO_CONFIG_7_1:
221 32 : hOutSetup->num_lfe = 1;
222 32 : move16();
223 32 : hOutSetup->index_lfe[0] = 3;
224 32 : move16();
225 32 : hOutSetup->is_loudspeaker_setup = 1;
226 32 : move16();
227 32 : hOutSetup->ls_azimuth_fx = ls_azimuth_CICP12_fx; // Q22
228 32 : hOutSetup->ls_elevation_fx = ls_elevation_CICP12_fx; // Q22
229 32 : hOutSetup->is_planar_setup = 1;
230 32 : move16();
231 32 : BREAK;
232 34 : case IVAS_AUDIO_CONFIG_5_1_2:
233 34 : hOutSetup->num_lfe = 1;
234 34 : move16();
235 34 : hOutSetup->index_lfe[0] = 3;
236 34 : move16();
237 34 : hOutSetup->is_loudspeaker_setup = 1;
238 34 : move16();
239 34 : hOutSetup->ls_azimuth_fx = ls_azimuth_CICP14_fx; // Q22
240 34 : hOutSetup->ls_elevation_fx = ls_elevation_CICP14_fx; // Q22
241 34 : hOutSetup->is_planar_setup = 0;
242 34 : move16();
243 34 : BREAK;
244 29 : case IVAS_AUDIO_CONFIG_5_1_4:
245 29 : hOutSetup->num_lfe = 1;
246 29 : move16();
247 29 : hOutSetup->index_lfe[0] = 3;
248 29 : move16();
249 29 : hOutSetup->is_loudspeaker_setup = 1;
250 29 : move16();
251 29 : hOutSetup->ls_azimuth_fx = ls_azimuth_CICP16_fx; // Q22
252 29 : hOutSetup->ls_elevation_fx = ls_elevation_CICP16_fx; // Q22
253 29 : hOutSetup->is_planar_setup = 0;
254 29 : move16();
255 29 : BREAK;
256 688 : case IVAS_AUDIO_CONFIG_7_1_4:
257 688 : hOutSetup->num_lfe = 1;
258 688 : move16();
259 688 : hOutSetup->index_lfe[0] = 3;
260 688 : move16();
261 688 : hOutSetup->is_loudspeaker_setup = 1;
262 688 : move16();
263 688 : hOutSetup->ls_azimuth_fx = ls_azimuth_CICP19_fx; // Q22
264 688 : hOutSetup->ls_elevation_fx = ls_elevation_CICP19_fx; // Q22
265 688 : hOutSetup->is_planar_setup = 0;
266 688 : move16();
267 688 : BREAK;
268 801 : case IVAS_AUDIO_CONFIG_BINAURAL:
269 : case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR:
270 : case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB:
271 : case IVAS_AUDIO_CONFIG_ISM1:
272 : case IVAS_AUDIO_CONFIG_ISM2:
273 : case IVAS_AUDIO_CONFIG_ISM3:
274 : case IVAS_AUDIO_CONFIG_ISM4:
275 801 : hOutSetup->is_binaural_setup = 1;
276 801 : move16();
277 1346 : case IVAS_AUDIO_CONFIG_EXTERNAL:
278 : /* Default values are used */
279 1346 : BREAK;
280 0 : default:
281 0 : return;
282 : }
283 : }
284 :
285 5347 : test();
286 5347 : IF( NE_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && NE_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
287 : {
288 4797 : nchan_out = audioCfg2channels( output_config );
289 4797 : hOutSetup->nchan_out_woLFE = sub( nchan_out, hOutSetup->num_lfe );
290 4797 : move16();
291 : }
292 :
293 5347 : return;
294 : }
295 :
296 :
297 : /*-----------------------------------------------------------------*
298 : * ivas_get_nchan_buffers_dec()
299 : *
300 : * Return number of decoder audio buffers
301 : *-----------------------------------------------------------------*/
302 :
303 : /*! r: number of decoder buffers */
304 3127752 : Word16 ivas_get_nchan_buffers_dec(
305 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
306 : const Word16 sba_analysis_order, /* i : SBA order evaluated in SBA decoder */
307 : const Word32 ivas_total_brate /* i : total IVAS bitrate */
308 : )
309 : {
310 : Word16 nchan_out_buff;
311 : AUDIO_CONFIG output_config;
312 :
313 3127752 : output_config = st_ivas->hDecoderConfig->output_config;
314 3127752 : move16();
315 :
316 3127752 : nchan_out_buff = MAX_OUTPUT_CHANNELS;
317 3127752 : move16();
318 :
319 3127752 : IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) )
320 : {
321 10 : nchan_out_buff = st_ivas->hDecoderConfig->nchan_out;
322 10 : move16();
323 : }
324 3127742 : ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
325 : {
326 277212 : nchan_out_buff = s_max( st_ivas->hDecoderConfig->nchan_out, CPE_CHANNELS );
327 : }
328 2850530 : ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
329 : {
330 640956 : nchan_out_buff = st_ivas->nchan_ism;
331 640956 : move16();
332 :
333 640956 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
334 : {
335 27018 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
336 : }
337 613938 : ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
338 : {
339 520242 : nchan_out_buff = s_max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) );
340 520242 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
341 : }
342 : }
343 2209574 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
344 : {
345 : Word16 nchan_internal;
346 1106275 : nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate );
347 1106275 : nchan_out_buff = st_ivas->hDecoderConfig->nchan_out;
348 1106275 : move16();
349 :
350 1106275 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
351 : {
352 18018 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
353 : }
354 : ELSE
355 : {
356 1088257 : nchan_out_buff = s_max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) );
357 1088257 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
358 : }
359 1106275 : nchan_out_buff = s_max( nchan_out_buff, nchan_internal );
360 : }
361 1103299 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
362 : {
363 173416 : nchan_out_buff = CPE_CHANNELS;
364 173416 : move16();
365 :
366 173416 : test();
367 173416 : test();
368 173416 : test();
369 173416 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
370 : {
371 0 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
372 : }
373 173416 : 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 ) )
374 : {
375 65850 : nchan_out_buff = shl( CPE_CHANNELS, 1 );
376 : }
377 107566 : ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
378 : {
379 92682 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
380 92682 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
381 : }
382 : }
383 929883 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
384 : {
385 49028 : nchan_out_buff = add( st_ivas->nchan_ism, CPE_CHANNELS );
386 :
387 49028 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
388 : {
389 0 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
390 : }
391 49028 : ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
392 : {
393 46307 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
394 46307 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
395 : }
396 : }
397 880855 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
398 : {
399 : Word16 nchan_internal;
400 444109 : nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate );
401 444109 : nchan_out_buff = add( st_ivas->nchan_ism, st_ivas->nchan_transport );
402 :
403 444109 : IF( st_ivas->hMCT != NULL )
404 : {
405 335727 : nchan_out_buff = shl( shr( add( nchan_out_buff, 1 ), 1 ), 1 ); /* ensure odd number of channels in MCT */
406 : }
407 :
408 444109 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
409 : {
410 0 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
411 : }
412 444109 : ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
413 : {
414 379863 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
415 379863 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
416 :
417 379863 : test();
418 379863 : IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) )
419 : {
420 32032 : nchan_out_buff = s_max( add( nchan_out_buff, st_ivas->nchan_ism ), audioCfg2channels( output_config ) ); /* needed for ivas_sba_upmixer_renderer() */
421 : }
422 : ELSE
423 : {
424 347831 : 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' */
425 : }
426 : }
427 64246 : ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
428 : {
429 64246 : nchan_out_buff = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); /*take into account sba_ch_idx' in ivas_dec() */
430 : }
431 :
432 444109 : test();
433 444109 : IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) )
434 : {
435 387342 : nchan_out_buff = s_max( nchan_out_buff, add( nchan_internal, st_ivas->nchan_ism ) );
436 : }
437 444109 : nchan_out_buff = s_min( nchan_out_buff, MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS );
438 : }
439 436746 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
440 : {
441 436746 : nchan_out_buff = st_ivas->hDecoderConfig->nchan_out;
442 :
443 436746 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
444 : {
445 18018 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
446 : }
447 : ELSE
448 : {
449 418728 : nchan_out_buff = s_max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) );
450 418728 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
451 : }
452 : }
453 :
454 :
455 3127752 : return nchan_out_buff;
456 : }
457 :
458 2739205 : Word16 ivas_get_nchan_buffers_dec_ivas_fx(
459 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
460 : const Word16 sba_analysis_order, /* i : SBA order evaluated in SBA decoder */
461 : const Word32 ivas_total_brate /* i : total IVAS bitrate */
462 : )
463 : {
464 : Word16 nchan_out_buff;
465 : AUDIO_CONFIG output_config;
466 :
467 2739205 : output_config = st_ivas->hDecoderConfig->output_config;
468 2739205 : move16();
469 :
470 2739205 : nchan_out_buff = MAX_OUTPUT_CHANNELS;
471 2739205 : move16();
472 :
473 2739205 : IF( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) )
474 : {
475 0 : nchan_out_buff = st_ivas->hDecoderConfig->nchan_out;
476 0 : move16();
477 : }
478 2739205 : ELSE IF( EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) )
479 : {
480 207708 : nchan_out_buff = s_max( st_ivas->hDecoderConfig->nchan_out, CPE_CHANNELS );
481 : }
482 2531497 : ELSE IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) )
483 : {
484 550555 : nchan_out_buff = st_ivas->nchan_ism;
485 550555 : move16();
486 :
487 550555 : IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
488 : {
489 25500 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
490 : }
491 525055 : ELSE IF( NE_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
492 : {
493 451117 : nchan_out_buff = s_max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) );
494 451117 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
495 : }
496 : }
497 1980942 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) )
498 : {
499 : Word16 nchan_internal;
500 986328 : nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate );
501 986328 : nchan_out_buff = st_ivas->hDecoderConfig->nchan_out;
502 986328 : move16();
503 :
504 986328 : IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
505 : {
506 17000 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
507 : }
508 : ELSE
509 : {
510 969328 : nchan_out_buff = s_max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) );
511 969328 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
512 : }
513 986328 : nchan_out_buff = s_max( nchan_out_buff, nchan_internal );
514 : }
515 994614 : ELSE IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) )
516 : {
517 147462 : nchan_out_buff = CPE_CHANNELS;
518 147462 : move16();
519 :
520 147462 : test();
521 147462 : test();
522 147462 : test();
523 147462 : IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
524 : {
525 0 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
526 : }
527 147462 : ELSE IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
528 : {
529 54736 : nchan_out_buff = shl( CPE_CHANNELS, 1 );
530 54736 : move16();
531 : }
532 92726 : ELSE IF( NE_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
533 : {
534 81614 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
535 81614 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
536 : }
537 : }
538 847152 : ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
539 : {
540 43538 : nchan_out_buff = add( st_ivas->nchan_ism, CPE_CHANNELS );
541 :
542 43538 : IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
543 : {
544 0 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
545 : }
546 43538 : ELSE IF( NE_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
547 : {
548 41288 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
549 41288 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
550 : }
551 : }
552 803614 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
553 : {
554 : Word16 nchan_internal;
555 413580 : nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate );
556 413580 : nchan_out_buff = add( st_ivas->nchan_ism, st_ivas->nchan_transport );
557 :
558 413580 : IF( st_ivas->hMCT != NULL )
559 : {
560 316620 : nchan_out_buff = shl( shr( add( nchan_out_buff, 1 ), 1 ), 1 ); /* ensure odd number of channels in MCT */
561 : }
562 :
563 413580 : IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
564 : {
565 0 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
566 : }
567 413580 : ELSE IF( NE_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
568 : {
569 352580 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
570 352580 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
571 :
572 352580 : move16();
573 352580 : IF( EQ_16( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_16( st_ivas->renderer_type, RENDERER_OSBA_LS ) )
574 : {
575 30000 : nchan_out_buff = s_max( add( nchan_out_buff, st_ivas->nchan_ism ), audioCfg2channels( output_config ) ); /* needed for ivas_sba_upmixer_renderer() */
576 : }
577 : ELSE
578 : {
579 322580 : 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' */
580 : }
581 : }
582 61000 : ELSE IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
583 : {
584 61000 : nchan_out_buff = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); /*take into account sba_ch_idx' in ivas_dec() */
585 : }
586 :
587 413580 : test();
588 413580 : IF( !( EQ_16( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) )
589 : {
590 362050 : nchan_out_buff = s_max( nchan_out_buff, add( nchan_internal, st_ivas->nchan_ism ) );
591 : }
592 413580 : nchan_out_buff = s_min( nchan_out_buff, MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS );
593 : }
594 390034 : ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) )
595 : {
596 390034 : nchan_out_buff = st_ivas->hDecoderConfig->nchan_out;
597 390034 : move16();
598 :
599 390034 : IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
600 : {
601 17000 : nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) );
602 : }
603 : ELSE
604 : {
605 373034 : nchan_out_buff = s_max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) );
606 373034 : nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) );
607 : }
608 : }
609 :
610 :
611 2739205 : return nchan_out_buff;
612 : }
613 :
614 :
615 : /*-------------------------------------------------------------------*
616 : * ivas_output_buff_dec()
617 : *
618 : * Allocate/reallocate output audio buffers
619 : *-------------------------------------------------------------------*/
620 4857 : ivas_error ivas_output_buff_dec_fx(
621 : Word32 *p_output_f[], /* i/o: output audio buffers */
622 : const Word16 nchan_out_buff_old, /* i : previous frame number of output channels */
623 : const Word16 nchan_out_buff /* i : number of output channels */
624 : )
625 : {
626 : Word16 ch;
627 4857 : IF( GT_16( nchan_out_buff, nchan_out_buff_old ) )
628 : {
629 3048 : FOR( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ )
630 : {
631 : /* note: these are intra-frame heap memories */
632 2554 : IF( ( p_output_f[ch] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ) ) == NULL ) /* note: 32000 == max internal sampling rate */
633 : {
634 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) );
635 : }
636 : }
637 : }
638 : ELSE
639 : {
640 6834 : FOR( ch = nchan_out_buff; ch < nchan_out_buff_old; ch++ )
641 : {
642 2471 : free( p_output_f[ch] );
643 2471 : p_output_f[ch] = NULL;
644 : }
645 : }
646 4857 : return IVAS_ERR_OK;
647 : }
648 :
649 :
650 : /*---------------------------------------------------------------------*
651 : * get_channel_config()
652 : *
653 : * Gets a str related to audio configuration
654 : *---------------------------------------------------------------------*/
655 :
656 1996 : ivas_error get_channel_config(
657 : const AUDIO_CONFIG config, /* i : audio configuration */
658 : Word8 *str /* o : string with the configuration name */
659 : )
660 : {
661 1996 : IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_MONO ) )
662 : {
663 114 : strcpy( (char *) str, "Mono" );
664 : }
665 1882 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_STEREO ) )
666 : {
667 171 : strcpy( (char *) str, "Stereo" );
668 : }
669 1711 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_ISM1 ) )
670 : {
671 39 : strcpy( (char *) str, "Object-based audio (1 object)" );
672 : }
673 1672 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_ISM2 ) )
674 : {
675 74 : strcpy( (char *) str, "Object-based audio (2 objects)" );
676 : }
677 1598 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_ISM3 ) )
678 : {
679 34 : strcpy( (char *) str, "Object-based audio (3 objects)" );
680 : }
681 1564 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_ISM4 ) )
682 : {
683 35 : strcpy( (char *) str, "Object-based audio (4 objects)" );
684 : }
685 1529 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_5_1 ) )
686 : {
687 97 : strcpy( (char *) str, "Multichannel 5.1 (CICP6)" );
688 : }
689 1432 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_7_1 ) )
690 : {
691 83 : strcpy( (char *) str, "Multichannel 7.1 (CICP12)" );
692 : }
693 1349 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_5_1_2 ) )
694 : {
695 81 : strcpy( (char *) str, "Multichannel 5.1+2 (CICP14)" );
696 : }
697 1268 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_5_1_4 ) )
698 : {
699 101 : strcpy( (char *) str, "Multichannel 5.1+4 (CICP16)" );
700 : }
701 1167 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_7_1_4 ) )
702 : {
703 92 : strcpy( (char *) str, "Multichannel 7.1+4 (CICP19)" );
704 : }
705 1075 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
706 : {
707 155 : strcpy( (char *) str, "Multichannel (custom loudspeaker layout)" );
708 : }
709 920 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_MASA1 ) )
710 : {
711 24 : strcpy( (char *) str, "Metadata-Assisted Spatial Audio mono (MASA1)" );
712 : }
713 896 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_MASA2 ) )
714 : {
715 26 : strcpy( (char *) str, "Metadata-Assisted Spatial Audio stereo (MASA2)" );
716 : }
717 870 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_FOA ) )
718 : {
719 261 : strcpy( (char *) str, "Ambisonics: First Order (FOA)" );
720 : }
721 609 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_HOA2 ) )
722 : {
723 84 : strcpy( (char *) str, "Ambisonics: Second Order (HOA2)" );
724 : }
725 525 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_HOA3 ) )
726 : {
727 94 : strcpy( (char *) str, "Ambisonics: Third Order (HOA3)" );
728 : }
729 431 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_BINAURAL ) )
730 : {
731 159 : strcpy( (char *) str, "Binaural: no room" );
732 : }
733 272 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
734 : {
735 115 : strcpy( (char *) str, "Binaural: room with impulse responses" );
736 : }
737 157 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
738 : {
739 107 : strcpy( (char *) str, "Binaural: room with reverb" );
740 : }
741 50 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) )
742 : {
743 0 : strcpy( (char *) str, "BINAURAL_SPLIT_CODED" );
744 : }
745 50 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
746 : {
747 0 : strcpy( (char *) str, "Binaural_Split_PCM" );
748 : }
749 50 : ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
750 : {
751 50 : strcpy( (char *) str, "External renderer" );
752 : }
753 : ELSE
754 : {
755 0 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Error: Incorrect Input/Output Configuration" );
756 : }
757 :
758 1996 : return IVAS_ERR_OK;
759 : }
|