LCOV - code coverage report
Current view: top level - lib_com - ivas_mcmasa_com.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 6baab0c613aa6c7100498ed7b93676aa8198a493 Lines: 23 23 100.0 %
Date: 2025-05-29 08:28:55 Functions: 3 3 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 "ivas_cnst.h"
      34             : #include "ivas_prot.h"
      35             : #include "options.h"
      36             : #ifdef DEBUGGING
      37             : #include "debug.h"
      38             : #endif
      39             : #include "wmc_auto.h"
      40             : 
      41             : 
      42             : /*--------------------------------------------------------------------------*
      43             :  * ivas_mcmasa_setNumTransportChannels()
      44             :  *
      45             :  * Set number of transport channels in McMASA
      46             :  *--------------------------------------------------------------------------*/
      47             : 
      48       27438 : void ivas_mcmasa_setNumTransportChannels(
      49             :     int16_t *nchan_transport,      /* o  : Pointer to number of transport channels to be set */
      50             :     int16_t *element_mode,         /* o  : Pointer to element mode to be set                 */
      51             :     const int32_t ivas_total_brate /* i  : Total bitrate of IVAS                             */
      52             : )
      53             : {
      54       27438 :     if ( ivas_total_brate >= IVAS_48k )
      55             :     {
      56        9596 :         *nchan_transport = 2;
      57        9596 :         *element_mode = IVAS_CPE_MDCT;
      58             :     }
      59             :     else
      60             :     {
      61       17842 :         *nchan_transport = 1;
      62       17842 :         *element_mode = IVAS_SCE;
      63             :     }
      64             : 
      65       27438 :     return;
      66             : }
      67             : 
      68             : 
      69             : /*--------------------------------------------------------------------------*
      70             :  * ivas_mcmasa_set_separate_channel_mode()
      71             :  *
      72             :  * Set separate channel parameters in McMASA based on bitrate
      73             :  *--------------------------------------------------------------------------*/
      74             : 
      75       35102 : void ivas_mcmasa_set_separate_channel_mode(
      76             :     uint8_t *separateChannelEnabled, /* o  : Pointer to separate channel toggle                */
      77             :     int16_t *separateChannelIndex,   /* o  : Pointer to separate channel index                 */
      78             :     const int32_t ivas_total_brate   /* i  : Total bitrate of IVAS                             */
      79             : )
      80             : {
      81       35102 :     if ( ivas_total_brate >= MCMASA_SEPARATE_BRATE )
      82             :     {
      83        7094 :         *separateChannelEnabled = 1;
      84        7094 :         *separateChannelIndex = 2; /* Center channel */
      85             :     }
      86             :     else
      87             :     {
      88       28008 :         *separateChannelEnabled = 0;
      89       28008 :         *separateChannelIndex = 0;
      90             :     }
      91             : 
      92       35102 :     return;
      93             : }
      94             : 
      95             : 
      96             : /*--------------------------------------------------------------------------*
      97             :  * ivas_mcmasa_split_brate()
      98             :  *
      99             :  * Split the total bitrate to elements in McMASA
     100             :  *--------------------------------------------------------------------------*/
     101             : 
     102       17133 : void ivas_mcmasa_split_brate(
     103             :     const uint8_t separateChannelEnabled, /* i  : Transport running in "separate channel" mode      */
     104             :     const int32_t ivas_total_brate,       /* i  : IVAS total bitrate available to be split          */
     105             :     const int16_t nSCE,                   /* i  : Number of SCEs in use (0 or 1)                    */
     106             :     const int16_t nCPE,                   /* i  : Number of CPEs in use (0 or 1)                    */
     107             :     int32_t *brate_sce,                   /* o  : Pointer to SCE element bitrate                    */
     108             :     int32_t *brate_cpe                    /* o  : Pointer to CPE element bitrate                    */
     109             : )
     110             : {
     111       17133 :     if ( separateChannelEnabled )
     112             :     {
     113             :         /* 25% of total bitrate is used for SCE below 96 kb/s (separated mono channel), otherwise 30% */
     114        3533 :         if ( ivas_total_brate < IVAS_96k )
     115             :         {
     116        2471 :             *brate_sce = (int32_t) ( MCMASA_MONOBITRATIO_64k * ivas_total_brate );
     117             :         }
     118             :         else
     119             :         {
     120        1062 :             *brate_sce = (int32_t) ( MCMASA_MONOBITRATIO * ivas_total_brate );
     121             :         }
     122             : 
     123        3533 :         *brate_cpe = ivas_total_brate - *brate_sce;
     124             :     }
     125             :     else
     126             :     {
     127       13600 :         *brate_sce = nSCE > 0 ? ivas_total_brate / ( nCPE + nSCE ) : 0;
     128       13600 :         *brate_cpe = nCPE > 0 ? ivas_total_brate / ( nCPE + nSCE ) : 0;
     129             :     }
     130             : 
     131       17133 :     return;
     132             : }

Generated by: LCOV version 1.14