LCOV - code coverage report
Current view: top level - lib_com - ivas_mc_com.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 6baab0c613aa6c7100498ed7b93676aa8198a493 Lines: 93 101 92.1 %
Date: 2025-05-29 08:28:55 Functions: 4 4 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 <assert.h>
      34             : #include <stdint.h>
      35             : #include "options.h"
      36             : #ifdef DEBUGGING
      37             : #include "debug.h"
      38             : #endif
      39             : #include <math.h>
      40             : #include "prot.h"
      41             : #include "ivas_prot.h"
      42             : #include "wmc_auto.h"
      43             : 
      44             : 
      45             : /*---------------------------------------------------------------
      46             :  * ivas_mc_mode_select()
      47             :  *
      48             :  * selects the multichannel mode base on bitrate and LS setup
      49             :  * ---------------------------------------------------------------*/
      50             : 
      51             : /*! r : MC format mode */
      52     2976436 : MC_MODE ivas_mc_mode_select(
      53             :     const MC_LS_SETUP mc_ls_setup, /* i  : MC loudspeaker setup           */
      54             :     const int32_t total_brate      /* i  : IVAS total bitrate             */
      55             : )
      56             : {
      57     2976436 :     MC_MODE mc_mode = MC_MODE_MCT;
      58             : 
      59     2976436 :     switch ( mc_ls_setup )
      60             :     {
      61     1510330 :         case MC_LS_SETUP_5_1:
      62     1510330 :             if ( total_brate < IVAS_48k )
      63             :             {
      64      350377 :                 mc_mode = MC_MODE_MCMASA;
      65             :             }
      66     1159953 :             else if ( total_brate < IVAS_96k )
      67             :             {
      68      332151 :                 mc_mode = MC_MODE_PARAMMC;
      69             :             }
      70     1510330 :             break;
      71      225832 :         case MC_LS_SETUP_7_1:
      72      225832 :             if ( total_brate < IVAS_48k )
      73             :             {
      74       47136 :                 mc_mode = MC_MODE_MCMASA;
      75             :             }
      76      178696 :             else if ( total_brate < IVAS_128k )
      77             :             {
      78       60473 :                 mc_mode = MC_MODE_PARAMMC;
      79             :             }
      80      225832 :             break;
      81      273195 :         case MC_LS_SETUP_5_1_2:
      82      273195 :             if ( total_brate < IVAS_48k )
      83             :             {
      84       66613 :                 mc_mode = MC_MODE_MCMASA;
      85             :             }
      86      206582 :             else if ( total_brate < IVAS_128k )
      87             :             {
      88      101765 :                 mc_mode = MC_MODE_PARAMMC;
      89             :             }
      90      273195 :             break;
      91      272786 :         case MC_LS_SETUP_5_1_4:
      92      272786 :             if ( total_brate < IVAS_96k )
      93             :             {
      94       92669 :                 mc_mode = MC_MODE_MCMASA;
      95             :             }
      96      180117 :             else if ( total_brate < IVAS_160k )
      97             :             {
      98       20904 :                 mc_mode = MC_MODE_PARAMMC;
      99             :             }
     100      272786 :             break;
     101      694293 :         case MC_LS_SETUP_7_1_4:
     102      694293 :             if ( total_brate < IVAS_128k )
     103             :             {
     104      245207 :                 mc_mode = MC_MODE_MCMASA;
     105             :             }
     106      449086 :             else if ( total_brate < IVAS_160k )
     107             :             {
     108       23562 :                 mc_mode = MC_MODE_PARAMMC;
     109             :             }
     110      425524 :             else if ( total_brate < IVAS_192k )
     111             :             {
     112      126244 :                 mc_mode = MC_MODE_PARAMUPMIX;
     113             :             }
     114      694293 :             break;
     115           0 :         default:
     116           0 :             assert( 0 && "LS Setup not supported or defined for MC mode!\n" );
     117             :     }
     118             : 
     119     2976436 :     return mc_mode;
     120             : }
     121             : 
     122             : 
     123             : /*---------------------------------------------------------------
     124             :  * ivas_mc_setup_get_num_channels()
     125             :  *
     126             :  * returns the number of channels (including the LFE) for a MC LS setup
     127             :  * ---------------------------------------------------------------*/
     128             : 
     129             : /*! r : number of loudspeaker channels */
     130      574225 : int16_t ivas_mc_ls_setup_get_num_channels(
     131             :     const MC_LS_SETUP mc_ls_setup /* i  : multi channel loudspeaker setup */
     132             : )
     133             : {
     134             :     int16_t nchan;
     135             : 
     136      574225 :     nchan = 0;
     137             : 
     138      574225 :     switch ( mc_ls_setup )
     139             :     {
     140      307167 :         case MC_LS_SETUP_5_1:
     141      307167 :             nchan = 6;
     142      307167 :             break;
     143       50471 :         case MC_LS_SETUP_7_1:
     144       50471 :             nchan = 8;
     145       50471 :             break;
     146       45520 :         case MC_LS_SETUP_5_1_2:
     147       45520 :             nchan = 8;
     148       45520 :             break;
     149       61946 :         case MC_LS_SETUP_5_1_4:
     150       61946 :             nchan = 10;
     151       61946 :             break;
     152      109121 :         case MC_LS_SETUP_7_1_4:
     153      109121 :             nchan = 12;
     154      109121 :             break;
     155           0 :         default:
     156           0 :             assert( 0 && "LS Setup not supported or defined for MC mode!\n" );
     157             :     }
     158             : 
     159      574225 :     return nchan;
     160             : }
     161             : 
     162             : 
     163             : /*---------------------------------------------------------------
     164             :  * ivas_mc_map_output_config_to_mc_ls_setup()
     165             :  *
     166             :  * maps output configuration multi channel loudspeaker setup
     167             :  * ---------------------------------------------------------------*/
     168             : 
     169             : /*! r : multi channel loudspeaker setup */
     170     3122312 : MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup(
     171             :     const AUDIO_CONFIG output_config /* i  : output audio configuration */
     172             : )
     173             : {
     174             :     MC_LS_SETUP mc_ls_setup;
     175             : 
     176     3122312 :     mc_ls_setup = MC_LS_SETUP_INVALID;
     177             : 
     178     3122312 :     switch ( output_config )
     179             :     {
     180     1539618 :         case IVAS_AUDIO_CONFIG_5_1:
     181     1539618 :             mc_ls_setup = MC_LS_SETUP_5_1;
     182     1539618 :             break;
     183      260633 :         case IVAS_AUDIO_CONFIG_7_1:
     184      260633 :             mc_ls_setup = MC_LS_SETUP_7_1;
     185      260633 :             break;
     186      294009 :         case IVAS_AUDIO_CONFIG_5_1_2:
     187      294009 :             mc_ls_setup = MC_LS_SETUP_5_1_2;
     188      294009 :             break;
     189      322197 :         case IVAS_AUDIO_CONFIG_5_1_4:
     190      322197 :             mc_ls_setup = MC_LS_SETUP_5_1_4;
     191      322197 :             break;
     192      705855 :         case IVAS_AUDIO_CONFIG_7_1_4:
     193      705855 :             mc_ls_setup = MC_LS_SETUP_7_1_4;
     194      705855 :             break;
     195           0 :         default:
     196           0 :             assert( 0 && "Output config is not a valid MC loudspeaker setup!\n" );
     197             :     }
     198             : 
     199     3122312 :     return mc_ls_setup;
     200             : }
     201             : 
     202             : 
     203             : /*---------------------------------------------------------------
     204             :  * ivas_mc_map_ls_setup_to_output_config
     205             :  *
     206             :  * maps multi channel loudspeaker setup to audio configuration
     207             :  * ---------------------------------------------------------------*/
     208             : 
     209             : /*! r: audio configuration*/
     210     2202018 : AUDIO_CONFIG ivas_mc_map_ls_setup_to_output_config(
     211             :     const MC_LS_SETUP mc_ls_setup /* i  : multi channel loudspeaker setup*/
     212             : )
     213             : {
     214             :     AUDIO_CONFIG audio_config;
     215     2202018 :     audio_config = IVAS_AUDIO_CONFIG_INVALID;
     216             : 
     217     2202018 :     switch ( mc_ls_setup )
     218             :     {
     219     1085852 :         case MC_LS_SETUP_5_1:
     220     1085852 :             audio_config = IVAS_AUDIO_CONFIG_5_1;
     221     1085852 :             break;
     222      184928 :         case MC_LS_SETUP_7_1:
     223      184928 :             audio_config = IVAS_AUDIO_CONFIG_7_1;
     224      184928 :             break;
     225      218166 :         case MC_LS_SETUP_5_1_2:
     226      218166 :             audio_config = IVAS_AUDIO_CONFIG_5_1_2;
     227      218166 :             break;
     228      218880 :         case MC_LS_SETUP_5_1_4:
     229      218880 :             audio_config = IVAS_AUDIO_CONFIG_5_1_4;
     230      218880 :             break;
     231      494192 :         case MC_LS_SETUP_7_1_4:
     232      494192 :             audio_config = IVAS_AUDIO_CONFIG_7_1_4;
     233      494192 :             break;
     234           0 :         default:
     235           0 :             assert( 0 && "MC loudspeaker setup is not valid!\n" );
     236             :     }
     237             : 
     238     2202018 :     return audio_config;
     239             : }

Generated by: LCOV version 1.14