LCOV - code coverage report
Current view: top level - lib_rend - ivas_output_init.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 6baab0c613aa6c7100498ed7b93676aa8198a493 Lines: 228 239 95.4 %
Date: 2025-05-29 08:28:55 Functions: 6 6 100.0 %

          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 "options.h"
      35             : #include "ivas_cnst.h"
      36             : #include "prot.h"
      37             : #include "ivas_prot_rend.h"
      38             : #include "ivas_rom_com.h"
      39             : #include "ivas_prot.h"
      40             : #include <string.h>
      41             : #ifdef DEBUGGING
      42             : #include "debug.h"
      43             : #include <assert.h>
      44             : #endif
      45             : #include "wmc_auto.h"
      46             : 
      47             : /*-------------------------------------------------------------------------*
      48             :  * audioCfg2channels()
      49             :  *
      50             :  * Map Audio configuration to number of channels
      51             :  *-------------------------------------------------------------------------*/
      52             : 
      53             : /*! r: number of audio channels */
      54    14614353 : int16_t audioCfg2channels(
      55             :     AUDIO_CONFIG output_config /* i  : output audio configuration  */
      56             : )
      57             : {
      58             :     int16_t nchan_out;
      59             : 
      60    14614353 :     switch ( output_config )
      61             :     {
      62       83036 :         case IVAS_AUDIO_CONFIG_MONO:
      63       83036 :             nchan_out = 1;
      64       83036 :             break;
      65      103815 :         case IVAS_AUDIO_CONFIG_STEREO:
      66      103815 :             nchan_out = 2;
      67      103815 :             break;
      68     1084575 :         case IVAS_AUDIO_CONFIG_5_1:
      69     1084575 :             nchan_out = 6;
      70     1084575 :             break;
      71      238647 :         case IVAS_AUDIO_CONFIG_7_1:
      72      238647 :             nchan_out = 8;
      73      238647 :             break;
      74      165955 :         case IVAS_AUDIO_CONFIG_5_1_2:
      75      165955 :             nchan_out = 8;
      76      165955 :             break;
      77      249682 :         case IVAS_AUDIO_CONFIG_5_1_4:
      78      249682 :             nchan_out = 10;
      79      249682 :             break;
      80     6166687 :         case IVAS_AUDIO_CONFIG_7_1_4:
      81     6166687 :             nchan_out = 12;
      82     6166687 :             break;
      83       79841 :         case IVAS_AUDIO_CONFIG_FOA:
      84       79841 :             nchan_out = 4;
      85       79841 :             break;
      86       26238 :         case IVAS_AUDIO_CONFIG_HOA2:
      87       26238 :             nchan_out = 9;
      88       26238 :             break;
      89     5270410 :         case IVAS_AUDIO_CONFIG_HOA3:
      90     5270410 :             nchan_out = 16;
      91     5270410 :             break;
      92           0 :         case IVAS_AUDIO_CONFIG_OBA:
      93           0 :             nchan_out = 8;
      94           0 :             break;
      95      269082 :         case IVAS_AUDIO_CONFIG_BINAURAL:
      96             :         case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED:
      97             :         case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM:
      98             :         case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR:
      99             :         case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB:
     100      269082 :             nchan_out = 2;
     101      269082 :             break;
     102      544014 :         case IVAS_AUDIO_CONFIG_ISM1:
     103      544014 :             nchan_out = 1;
     104      544014 :             break;
     105       81562 :         case IVAS_AUDIO_CONFIG_ISM2:
     106       81562 :             nchan_out = 2;
     107       81562 :             break;
     108       71010 :         case IVAS_AUDIO_CONFIG_ISM3:
     109       71010 :             nchan_out = 3;
     110       71010 :             break;
     111      171702 :         case IVAS_AUDIO_CONFIG_ISM4:
     112      171702 :             nchan_out = 4;
     113      171702 :             break;
     114        8097 :         default:
     115        8097 :             IVAS_ERROR( IVAS_ERR_INTERNAL, "Error: illegal output configuration\n" );
     116        8097 :             nchan_out = -1;
     117        8097 :             break;
     118             :     }
     119             : 
     120    14614353 :     return ( nchan_out );
     121             : }
     122             : 
     123             : 
     124             : /*-------------------------------------------------------------------------*
     125             :  * ivas_output_init()
     126             :  *
     127             :  * Initialize and configure IVAS output parameters
     128             :  *-------------------------------------------------------------------------*/
     129             : 
     130      312866 : void ivas_output_init(
     131             :     IVAS_OUTPUT_SETUP *hOutSetup,    /* o  : IVAS output setup structure */
     132             :     const AUDIO_CONFIG output_config /* i  : output audio configuration  */
     133             : )
     134             : {
     135             :     int16_t nchan_out;
     136             : 
     137             :     /* set general default values */
     138      312866 :     hOutSetup->output_config = output_config;
     139      312866 :     hOutSetup->is_loudspeaker_setup = 0;
     140      312866 :     hOutSetup->is_binaural_setup = 0;
     141      312866 :     hOutSetup->ambisonics_order = -1;
     142      312866 :     hOutSetup->separateChannelEnabled = 0;
     143      312866 :     hOutSetup->separateChannelIndex = 0;
     144             : 
     145      312866 :     if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM )
     146             :     {
     147          32 :         hOutSetup->is_loudspeaker_setup = 1;
     148             :         /* set in ivas_init_decoder: */
     149             :         /* hOutSetup->ls_azimuth */
     150             :         /* hOutSetup->ls_elevation    */
     151             :         /* hOutSetup->num_lfe         */
     152             :         /* hOutSetup->index_lfe[0]    */
     153             :         /* hOutSetup->is_planar_setup */
     154             :     }
     155             :     else
     156             :     {
     157             :         /* Set default values for all other than custom LS setup */
     158      312834 :         hOutSetup->ls_azimuth = NULL;
     159      312834 :         hOutSetup->ls_elevation = NULL;
     160      312834 :         hOutSetup->num_lfe = 0;
     161      312834 :         hOutSetup->index_lfe[0] = -1;
     162      312834 :         hOutSetup->is_planar_setup = 0;
     163             : 
     164             :         /* set output setup specific values */
     165      312834 :         switch ( output_config )
     166             :         {
     167       12125 :             case IVAS_AUDIO_CONFIG_MONO:
     168       12125 :                 hOutSetup->is_loudspeaker_setup = 1;
     169       12125 :                 break;
     170       12185 :             case IVAS_AUDIO_CONFIG_STEREO:
     171       12185 :                 hOutSetup->is_loudspeaker_setup = 1;
     172       12185 :                 hOutSetup->ls_azimuth = ls_azimuth_CICP2;
     173       12185 :                 hOutSetup->ls_elevation = ls_elevation_CICP2;
     174       12185 :                 break;
     175       70178 :             case IVAS_AUDIO_CONFIG_FOA:
     176       70178 :                 hOutSetup->ambisonics_order = SBA_FOA_ORDER;
     177       70178 :                 break;
     178       17530 :             case IVAS_AUDIO_CONFIG_HOA2:
     179       17530 :                 hOutSetup->ambisonics_order = SBA_HOA2_ORDER;
     180       17530 :                 break;
     181       26818 :             case IVAS_AUDIO_CONFIG_HOA3:
     182       26818 :                 hOutSetup->ambisonics_order = SBA_HOA3_ORDER;
     183       26818 :                 break;
     184       22688 :             case IVAS_AUDIO_CONFIG_5_1:
     185       22688 :                 hOutSetup->num_lfe = 1;
     186       22688 :                 hOutSetup->index_lfe[0] = 3;
     187       22688 :                 hOutSetup->is_loudspeaker_setup = 1;
     188       22688 :                 hOutSetup->ls_azimuth = ls_azimuth_CICP6;
     189       22688 :                 hOutSetup->ls_elevation = ls_elevation_CICP6;
     190       22688 :                 hOutSetup->is_planar_setup = 1;
     191       22688 :                 break;
     192       15046 :             case IVAS_AUDIO_CONFIG_7_1:
     193       15046 :                 hOutSetup->num_lfe = 1;
     194       15046 :                 hOutSetup->index_lfe[0] = 3;
     195       15046 :                 hOutSetup->is_loudspeaker_setup = 1;
     196       15046 :                 hOutSetup->ls_azimuth = ls_azimuth_CICP12;
     197       15046 :                 hOutSetup->ls_elevation = ls_elevation_CICP12;
     198       15046 :                 hOutSetup->is_planar_setup = 1;
     199       15046 :                 break;
     200       15036 :             case IVAS_AUDIO_CONFIG_5_1_2:
     201       15036 :                 hOutSetup->num_lfe = 1;
     202       15036 :                 hOutSetup->index_lfe[0] = 3;
     203       15036 :                 hOutSetup->is_loudspeaker_setup = 1;
     204       15036 :                 hOutSetup->ls_azimuth = ls_azimuth_CICP14;
     205       15036 :                 hOutSetup->ls_elevation = ls_elevation_CICP14;
     206       15036 :                 hOutSetup->is_planar_setup = 0;
     207       15036 :                 break;
     208       14313 :             case IVAS_AUDIO_CONFIG_5_1_4:
     209       14313 :                 hOutSetup->num_lfe = 1;
     210       14313 :                 hOutSetup->index_lfe[0] = 3;
     211       14313 :                 hOutSetup->is_loudspeaker_setup = 1;
     212       14313 :                 hOutSetup->ls_azimuth = ls_azimuth_CICP16;
     213       14313 :                 hOutSetup->ls_elevation = ls_elevation_CICP16;
     214       14313 :                 hOutSetup->is_planar_setup = 0;
     215       14313 :                 break;
     216       30115 :             case IVAS_AUDIO_CONFIG_7_1_4:
     217       30115 :                 hOutSetup->num_lfe = 1;
     218       30115 :                 hOutSetup->index_lfe[0] = 3;
     219       30115 :                 hOutSetup->is_loudspeaker_setup = 1;
     220       30115 :                 hOutSetup->ls_azimuth = ls_azimuth_CICP19;
     221       30115 :                 hOutSetup->ls_elevation = ls_elevation_CICP19;
     222       30115 :                 hOutSetup->is_planar_setup = 0;
     223       30115 :                 break;
     224       68248 :             case IVAS_AUDIO_CONFIG_BINAURAL:
     225             :             case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED:
     226             :             case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM:
     227             :             case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR:
     228             :             case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB:
     229             :             case IVAS_AUDIO_CONFIG_ISM1:
     230             :             case IVAS_AUDIO_CONFIG_ISM2:
     231             :             case IVAS_AUDIO_CONFIG_ISM3:
     232             :             case IVAS_AUDIO_CONFIG_ISM4:
     233       68248 :                 hOutSetup->is_binaural_setup = 1;
     234       76800 :             case IVAS_AUDIO_CONFIG_EXTERNAL:
     235             :                 /* Default values are used */
     236       76800 :                 break;
     237           0 :             default:
     238             : #ifdef DEBUGGING
     239             :                 /* error */
     240             :                 assert( !"Error: Unknown output setup!\n" );
     241             : #endif
     242           0 :                 return;
     243             :         }
     244             :     }
     245             : 
     246      312866 :     if ( output_config != IVAS_AUDIO_CONFIG_EXTERNAL && output_config != IVAS_AUDIO_CONFIG_LS_CUSTOM )
     247             :     {
     248      304282 :         nchan_out = audioCfg2channels( output_config );
     249      304282 :         hOutSetup->nchan_out_woLFE = nchan_out - hOutSetup->num_lfe;
     250             :     }
     251             : 
     252      312866 :     return;
     253             : }
     254             : 
     255             : 
     256             : /*-----------------------------------------------------------------*
     257             :  * ivas_get_nchan_buffers_dec()
     258             :  *
     259             :  * Return number of decoder audio buffers
     260             :  *-----------------------------------------------------------------*/
     261             : 
     262             : /*! r: number of decoder buffers */
     263    37128193 : int16_t ivas_get_nchan_buffers_dec(
     264             :     Decoder_Struct *st_ivas,          /* i/o: IVAS decoder structure                */
     265             :     const int16_t sba_analysis_order, /* i  : SBA order evaluated in SBA decoder    */
     266             :     const int32_t ivas_total_brate    /* i  : total IVAS bitrate                    */
     267             : )
     268             : {
     269             :     int16_t nchan_out_buff;
     270             :     AUDIO_CONFIG output_config;
     271             : 
     272    37128193 :     output_config = st_ivas->hDecoderConfig->output_config;
     273             : 
     274             : #ifdef FIX_NCHAN_BUFFERS
     275    37128193 :     nchan_out_buff = st_ivas->nchan_transport;
     276             : #else
     277             :     nchan_out_buff = MAX_OUTPUT_CHANNELS;
     278             : #endif
     279             : 
     280    37128193 :     if ( st_ivas->ivas_format == MONO_FORMAT )
     281             :     {
     282      105703 :         nchan_out_buff = st_ivas->hDecoderConfig->nchan_out;
     283             :     }
     284    37022490 :     else if ( st_ivas->ivas_format == STEREO_FORMAT )
     285             :     {
     286      925469 :         nchan_out_buff = max( st_ivas->hDecoderConfig->nchan_out, CPE_CHANNELS );
     287             :     }
     288    36097021 :     else if ( st_ivas->ivas_format == ISM_FORMAT )
     289             :     {
     290             : #ifdef FIX_NCHAN_BUFFERS
     291     1364774 :         nchan_out_buff = max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism );
     292             : 
     293     1364774 :         if ( st_ivas->ism_mode == ISM_MODE_PARAM || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
     294             :         {
     295      356101 :             nchan_out_buff = max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
     296             :         }
     297             : #else
     298             :         nchan_out_buff = st_ivas->nchan_ism;
     299             : 
     300             :         if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM )
     301             :         {
     302             :             nchan_out_buff = max( nchan_out_buff, st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe );
     303             :         }
     304             :         else if ( output_config != IVAS_AUDIO_CONFIG_EXTERNAL )
     305             :         {
     306             :             nchan_out_buff = max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) );
     307             :             nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) );
     308             :         }
     309             : #endif
     310             :     }
     311    34732247 :     else if ( st_ivas->ivas_format == SBA_FORMAT )
     312             :     {
     313             : #ifdef FIX_NCHAN_BUFFERS
     314             :         int16_t nchan_internal;
     315    23677729 :         nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate );
     316             : 
     317    23677729 :         nchan_out_buff = max( nchan_internal, st_ivas->hDecoderConfig->nchan_out );
     318             : #else
     319             :         int16_t nchan_internal;
     320             :         nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate );
     321             :         nchan_out_buff = st_ivas->hDecoderConfig->nchan_out;
     322             : 
     323             :         if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM )
     324             :         {
     325             :             nchan_out_buff = max( nchan_out_buff, st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe );
     326             :         }
     327             :         else if ( output_config != IVAS_AUDIO_CONFIG_EXTERNAL )
     328             :         {
     329             :             nchan_out_buff = max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) );
     330             :             nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) );
     331             :         }
     332             :         nchan_out_buff = max( nchan_out_buff, nchan_internal );
     333             : #endif
     334             :     }
     335    11054518 :     else if ( st_ivas->ivas_format == MASA_FORMAT )
     336             :     {
     337             : #ifdef FIX_NCHAN_BUFFERS
     338      899730 :         nchan_out_buff = max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport );
     339             : 
     340      899730 :         if ( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->useTdDecorr )
     341             :         {
     342      107053 :             nchan_out_buff = 2 * BINAURAL_CHANNELS;
     343             :         }
     344             : #else
     345             :         nchan_out_buff = CPE_CHANNELS;
     346             : 
     347             :         if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM )
     348             :         {
     349             :             nchan_out_buff = max( nchan_out_buff, st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe );
     350             :         }
     351             :         else if ( output_config == IVAS_AUDIO_CONFIG_STEREO || 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 )
     352             :         {
     353             :             nchan_out_buff = 2 * CPE_CHANNELS;
     354             :         }
     355             :         else if ( output_config != IVAS_AUDIO_CONFIG_EXTERNAL )
     356             :         {
     357             :             nchan_out_buff = max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
     358             :             nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) );
     359             :         }
     360             : 
     361             :         if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL && st_ivas->nchan_ism > 0 )
     362             :         {
     363             :             nchan_out_buff = st_ivas->nchan_ism + CPE_CHANNELS;
     364             :         }
     365             : #endif
     366             :     }
     367    10154788 :     else if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
     368             :     {
     369             : #ifdef FIX_NCHAN_BUFFERS
     370      528320 :         nchan_out_buff = max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport + st_ivas->nchan_ism );
     371             : #else
     372             :         nchan_out_buff = st_ivas->nchan_ism + CPE_CHANNELS;
     373             : 
     374             :         if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM )
     375             :         {
     376             :             nchan_out_buff = max( nchan_out_buff, st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe );
     377             :         }
     378             :         else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
     379             :         {
     380             :             nchan_out_buff = max( nchan_out_buff, BINAURAL_CHANNELS + st_ivas->nchan_ism );
     381             :         }
     382             :         else if ( output_config != IVAS_AUDIO_CONFIG_EXTERNAL )
     383             :         {
     384             :             nchan_out_buff = max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
     385             :             nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) );
     386             :         }
     387             : #endif
     388             :     }
     389     9626468 :     else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
     390             :     {
     391             : #ifdef FIX_NCHAN_BUFFERS
     392             :         int16_t nchan_internal;
     393             : 
     394     3559650 :         nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate );
     395             : 
     396     3559650 :         if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
     397             :         {
     398     1723886 :             nchan_internal += st_ivas->nchan_ism;
     399             :         }
     400             : 
     401     3559650 :         if ( st_ivas->hMCT != NULL )
     402             :         {
     403     1950308 :             nchan_internal = ( ( nchan_internal + 1 ) >> 1 ) << 1; /* ensure odd number of channels in MCT */
     404             :         }
     405             : 
     406     3559650 :         nchan_out_buff = max( nchan_internal, st_ivas->hDecoderConfig->nchan_out );
     407             : 
     408     3559650 :         if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
     409             :         {
     410      263382 :             nchan_out_buff = max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
     411             :         }
     412             : #else
     413             :         int16_t nchan_internal;
     414             :         nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate );
     415             :         nchan_out_buff = st_ivas->nchan_ism + st_ivas->nchan_transport;
     416             : 
     417             :         if ( st_ivas->hMCT != NULL )
     418             :         {
     419             :             nchan_out_buff = ( ( nchan_out_buff + 1 ) >> 1 ) << 1; /* ensure odd number of channels in MCT */
     420             :         }
     421             : 
     422             :         if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM )
     423             :         {
     424             :             nchan_out_buff = max( nchan_out_buff, st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe );
     425             :         }
     426             :         else if ( output_config != IVAS_AUDIO_CONFIG_EXTERNAL )
     427             :         {
     428             :             nchan_out_buff = max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
     429             :             nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) );
     430             : 
     431             :             if ( st_ivas->renderer_type == RENDERER_OSBA_AMBI || st_ivas->renderer_type == RENDERER_OSBA_LS )
     432             :             {
     433             :                 nchan_out_buff = max( nchan_out_buff + st_ivas->nchan_ism, audioCfg2channels( output_config ) ); /* needed for ivas_sba_upmixer_renderer() */
     434             :             }
     435             :             else
     436             :             {
     437             :                 nchan_out_buff = max( nchan_out_buff + st_ivas->nchan_ism, audioCfg2channels( output_config ) ); /* needed for ivas_spar_dec_upmixer_sf() which is based on 'nchan_out' */
     438             :             }
     439             :         }
     440             :         else if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
     441             :         {
     442             :             nchan_out_buff = st_ivas->hDecoderConfig->nchan_out + st_ivas->nchan_ism; /*take into account sba_ch_idx' in ivas_dec() */
     443             :         }
     444             : 
     445             :         if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) )
     446             :         {
     447             :             nchan_out_buff = max( nchan_out_buff, nchan_internal + st_ivas->nchan_ism );
     448             :         }
     449             :         nchan_out_buff = min( nchan_out_buff, MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS );
     450             : #endif
     451             :     }
     452     6066818 :     else if ( st_ivas->ivas_format == MC_FORMAT )
     453             :     {
     454             : #ifdef FIX_NCHAN_BUFFERS
     455     6066818 :         nchan_out_buff = max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport );
     456             : 
     457     6066818 :         if ( st_ivas->hOutSetup.separateChannelEnabled )
     458             :         {
     459      272675 :             nchan_out_buff = max( nchan_out_buff, st_ivas->nchan_transport + 1 );
     460             :         }
     461             : 
     462     6066818 :         if ( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->useTdDecorr )
     463             :         {
     464      101630 :             nchan_out_buff = 2 * BINAURAL_CHANNELS;
     465             :         }
     466             :         else
     467             :         {
     468     5965188 :             nchan_out_buff = max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) );
     469             :         }
     470             : #else
     471             :         nchan_out_buff = st_ivas->hDecoderConfig->nchan_out;
     472             : 
     473             :         if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM )
     474             :         {
     475             :             nchan_out_buff = max( nchan_out_buff, st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe );
     476             :         }
     477             :         else if ( output_config != IVAS_AUDIO_CONFIG_EXTERNAL )
     478             :         {
     479             :             nchan_out_buff = max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) );
     480             :             nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) );
     481             :         }
     482             : #endif
     483             :     }
     484             : 
     485    37128193 :     if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     486             :     {
     487           0 :         nchan_out_buff = max( nchan_out_buff, st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses * BINAURAL_CHANNELS );
     488             :     }
     489             : 
     490    37128193 :     return nchan_out_buff;
     491             : }
     492             : 
     493             : 
     494             : /*-------------------------------------------------------------------*
     495             :  * ivas_output_buff_dec()
     496             :  *
     497             :  * Allocate/reallocate output audio buffers
     498             :  *-------------------------------------------------------------------*/
     499             : 
     500      134785 : ivas_error ivas_output_buff_dec(
     501             :     float *p_output_f[],              /* i/o: output audio buffers                       */
     502             :     const int16_t nchan_out_buff_old, /* i  : previous frame number of output channels   */
     503             :     const int16_t nchan_out_buff      /* i  : number of output channels                  */
     504             : )
     505             : {
     506             :     int16_t ch;
     507             : 
     508      134785 :     if ( nchan_out_buff > nchan_out_buff_old )
     509             :     {
     510       88097 :         for ( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ )
     511             :         {
     512             : #ifdef FIX_NCHAN_BUFFERS
     513             : #ifdef DEBUGGING
     514             :             if ( p_output_f[ch] != NULL )
     515             :             {
     516             :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Memory for floating-point output audio buffer is already allocated!\n" ) );
     517             :             }
     518             : #endif
     519             : #endif
     520             :             /* note: these are intra-frame heap memories */
     521       67773 :             if ( ( p_output_f[ch] = (float *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL )
     522             :             {
     523           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) );
     524             :             }
     525             :         }
     526             :     }
     527             :     else
     528             :     {
     529      181520 :         for ( ch = nchan_out_buff; ch < nchan_out_buff_old; ch++ )
     530             :         {
     531       67059 :             free( p_output_f[ch] );
     532       67059 :             p_output_f[ch] = NULL;
     533             :         }
     534             :     }
     535             : 
     536      134785 :     return IVAS_ERR_OK;
     537             : }
     538             : 
     539             : 
     540             : /*---------------------------------------------------------------------*
     541             :  * is_split_rendering_enabled()
     542             :  *
     543             :  *
     544             :  *---------------------------------------------------------------------*/
     545             : 
     546             : /*! r: flag to indicate if split rendering is enabled */
     547    19314091 : int16_t is_split_rendering_enabled(
     548             :     const DECODER_CONFIG_HANDLE hDecoderConfig,   /* i  : configuration structure         */
     549             :     const IVAS_RENDER_CONFIG_HANDLE hRenderConfig /* i  : Render config data structure    */
     550             : )
     551             : {
     552    19314091 :     if ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ||
     553    19314091 :          ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO && hDecoderConfig->Opt_non_diegetic_pan && hRenderConfig->split_rend_config.dof == 0 ) )
     554             :     {
     555           0 :         return 1;
     556             :     }
     557             :     else
     558             :     {
     559    19314091 :         return 0;
     560             :     }
     561             : }
     562             : 
     563             : 
     564             : /*---------------------------------------------------------------------*
     565             :  * get_channel_config()
     566             :  *
     567             :  * Gets a str related to input config
     568             :  *---------------------------------------------------------------------*/
     569             : 
     570       86920 : ivas_error get_channel_config(
     571             :     const AUDIO_CONFIG config,
     572             :     char *str )
     573             : {
     574       86920 :     if ( config == IVAS_AUDIO_CONFIG_MONO )
     575             :     {
     576        5646 :         strcpy( str, "Mono" );
     577             :     }
     578       81274 :     else if ( config == IVAS_AUDIO_CONFIG_STEREO )
     579             :     {
     580        5824 :         strcpy( str, "Stereo" );
     581             :     }
     582       75450 :     else if ( config == IVAS_AUDIO_CONFIG_ISM1 )
     583             :     {
     584          80 :         strcpy( str, "Object-based audio (1 object)" );
     585             :     }
     586       75370 :     else if ( config == IVAS_AUDIO_CONFIG_ISM2 )
     587             :     {
     588         150 :         strcpy( str, "Object-based audio (2 objects)" );
     589             :     }
     590       75220 :     else if ( config == IVAS_AUDIO_CONFIG_ISM3 )
     591             :     {
     592          70 :         strcpy( str, "Object-based audio (3 objects)" );
     593             :     }
     594       75150 :     else if ( config == IVAS_AUDIO_CONFIG_ISM4 )
     595             :     {
     596          72 :         strcpy( str, "Object-based audio (4 objects)" );
     597             :     }
     598       75078 :     else if ( config == IVAS_AUDIO_CONFIG_5_1 )
     599             :     {
     600        5558 :         strcpy( str, "Multichannel 5.1 (CICP6)" );
     601             :     }
     602       69520 :     else if ( config == IVAS_AUDIO_CONFIG_7_1 )
     603             :     {
     604        5498 :         strcpy( str, "Multichannel 7.1 (CICP12)" );
     605             :     }
     606       64022 :     else if ( config == IVAS_AUDIO_CONFIG_5_1_2 )
     607             :     {
     608        5490 :         strcpy( str, "Multichannel 5.1+2 (CICP14)" );
     609             :     }
     610       58532 :     else if ( config == IVAS_AUDIO_CONFIG_5_1_4 )
     611             :     {
     612        5528 :         strcpy( str, "Multichannel 5.1+4 (CICP16)" );
     613             :     }
     614       53004 :     else if ( config == IVAS_AUDIO_CONFIG_7_1_4 )
     615             :     {
     616        5538 :         strcpy( str, "Multichannel 7.1+4 (CICP19)" );
     617             :     }
     618       47466 :     else if ( config == IVAS_AUDIO_CONFIG_LS_CUSTOM )
     619             :     {
     620         336 :         strcpy( str, "Multichannel (custom loudspeaker layout)" );
     621             :     }
     622       47130 :     else if ( config == IVAS_AUDIO_CONFIG_MASA1 )
     623             :     {
     624          54 :         strcpy( str, "Metadata-Assisted Spatial Audio mono (MASA1)" );
     625             :     }
     626       47076 :     else if ( config == IVAS_AUDIO_CONFIG_MASA2 )
     627             :     {
     628          58 :         strcpy( str, "Metadata-Assisted Spatial Audio stereo (MASA2)" );
     629             :     }
     630       47018 :     else if ( config == IVAS_AUDIO_CONFIG_FOA )
     631             :     {
     632        6312 :         strcpy( str, "Ambisonics: First Order (FOA)" );
     633             :     }
     634       40706 :     else if ( config == IVAS_AUDIO_CONFIG_HOA2 )
     635             :     {
     636        5344 :         strcpy( str, "Ambisonics: Second Order (HOA2)" );
     637             :     }
     638       35362 :     else if ( config == IVAS_AUDIO_CONFIG_HOA3 )
     639             :     {
     640        5390 :         strcpy( str, "Ambisonics: Third Order (HOA3)" );
     641             :     }
     642       29972 :     else if ( config == IVAS_AUDIO_CONFIG_BINAURAL )
     643             :     {
     644        8292 :         strcpy( str, "Binaural: no room" );
     645             :     }
     646       21680 :     else if ( config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
     647             :     {
     648        8080 :         strcpy( str, "Binaural: room with impulse responses" );
     649             :     }
     650       13600 :     else if ( config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
     651             :     {
     652        8062 :         strcpy( str, "Binaural: room with reverb" );
     653             :     }
     654        5538 :     else if ( config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED )
     655             :     {
     656           0 :         strcpy( str, "BINAURAL_SPLIT_CODED" );
     657             :     }
     658        5538 :     else if ( config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     659             :     {
     660           0 :         strcpy( str, "Binaural_Split_PCM" );
     661             :     }
     662        5538 :     else if ( config == IVAS_AUDIO_CONFIG_EXTERNAL )
     663             :     {
     664        5538 :         strcpy( str, "External renderer" );
     665             :     }
     666             :     else
     667             :     {
     668           0 :         return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Error: Incorrect Input/Output Configuration" );
     669             :     }
     670             : 
     671       86920 :     return IVAS_ERR_OK;
     672             : }

Generated by: LCOV version 1.14