LCOV - code coverage report
Current view: top level - lib_com - ivas_sba_config.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 58 63 92.1 %
Date: 2025-05-23 08:37:30 Functions: 8 8 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 <math.h>
      36             : #include "options.h"
      37             : #include "cnst.h"
      38             : #include "ivas_cnst.h"
      39             : #include "rom_com.h"
      40             : #include "prot.h"
      41             : #include "ivas_prot.h"
      42             : #include "ivas_stat_com.h"
      43             : #include "ivas_rom_com.h"
      44             : #ifdef DEBUGGING
      45             : #include "debug.h"
      46             : #endif
      47             : #include "wmc_auto.h"
      48             : 
      49             : 
      50             : /*-------------------------------------------------------------------*
      51             :  * ivas_sba_config()
      52             :  *
      53             :  * Configure SBA coding
      54             :  *-------------------------------------------------------------------*/
      55             : 
      56      441660 : void ivas_sba_config(
      57             :     const int32_t sba_total_brate, /* i  : SBA total bitrate                        */
      58             :     int16_t sba_order,             /* i  : Ambisonic (SBA) order                    */
      59             :     int16_t nb_channels,           /* i  : Number of ambisonic channels             */
      60             :     int16_t *nchan_transport,      /* o  : number of transport channels             */
      61             :     const int16_t sba_planar,      /* i  : SBA Planar flag                          */
      62             :     int16_t *nSCE,                 /* o  : number of SCEs                           */
      63             :     int16_t *nCPE,                 /* o  : number of CPEs                           */
      64             :     int16_t *element_mode          /* o  : element mode of the core coder           */
      65             : )
      66             : {
      67      441660 :     if ( nb_channels > 0 )
      68             :     {
      69           0 :         if ( sba_planar )
      70             :         {
      71           0 :             assert( ( ( 2 * sba_order ) + 1 == nb_channels ) && "Order and number of channels do not correspond!" );
      72             :         }
      73             :         else
      74             :         {
      75           0 :             assert( ( ( sba_order + 1 ) * ( sba_order + 1 ) == nb_channels ) && "Order and number of channels do not correspond!" );
      76             :         }
      77             :     }
      78             : 
      79      441660 :     if ( nchan_transport != NULL )
      80             :     {
      81      441660 :         *nchan_transport = ivas_get_sba_num_TCs( sba_total_brate, sba_order );
      82             :     }
      83             : 
      84             :     /* Configure core coder number of elements*/
      85      441660 :     if ( nchan_transport != NULL && nSCE != NULL && nCPE != NULL )
      86             :     {
      87      441660 :         if ( *nchan_transport == 1 )
      88             :         {
      89      112872 :             *nSCE = 1;
      90      112872 :             *nCPE = 0;
      91      112872 :             *element_mode = IVAS_SCE;
      92             :         }
      93             :         else
      94             :         {
      95      328788 :             *nSCE = 0;
      96      328788 :             *nCPE = *nchan_transport / 2;
      97      328788 :             if ( 2 * ( *nCPE ) != *nchan_transport )
      98             :             {
      99       94653 :                 ( *nCPE )++;
     100             :             }
     101      328788 :             *element_mode = IVAS_CPE_MDCT;
     102             :         }
     103             :     }
     104             : 
     105      441660 :     return;
     106             : }
     107             : 
     108             : 
     109             : /*-------------------------------------------------------------------*
     110             :  * ivas_sba_get_analysis_order()
     111             :  *
     112             :  * Get Ambisonic order used for analysis and coding
     113             :  *-------------------------------------------------------------------*/
     114             : 
     115             : /*! r: Ambisonic (SBA) order used for analysis and coding */
     116      892755 : int16_t ivas_sba_get_analysis_order(
     117             :     const int32_t ivas_total_brate, /* i  : IVAS total bitrate      */
     118             :     const int16_t sba_order         /* i  : Ambisonic (SBA) order   */
     119             : )
     120             : {
     121             :     int16_t sba_analysis_order;
     122             : 
     123      892755 :     sba_analysis_order = sba_order;
     124             : 
     125      892755 :     if ( ivas_total_brate < SBA_MIN_BRATE_HOA )
     126             :     {
     127             :         /* Hard coding the sba_analysis_order as 1 as higher not supported below SBA_MIN_BRATE_HOA bitrate */
     128      649866 :         sba_analysis_order = SBA_FOA_ORDER;
     129             :     }
     130             : 
     131      892755 :     return sba_analysis_order;
     132             : }
     133             : 
     134             : 
     135             : /*-------------------------------------------------------------------*
     136             :  * ivas_sba_get_nchan()
     137             :  *
     138             :  * Get number of Ambisonic channels
     139             :  *-------------------------------------------------------------------*/
     140             : 
     141             : /*! r: number of Ambisonic channels */
     142     3688049 : int16_t ivas_sba_get_nchan(
     143             :     const int16_t sba_order, /* i  : Ambisonic (SBA) order            */
     144             :     const int16_t sba_planar /* i  : SBA planar flag                  */
     145             : )
     146             : {
     147             :     int16_t nb_channels;
     148             : 
     149     3688049 :     if ( sba_planar )
     150             :     {
     151           0 :         nb_channels = ( 2 * sba_order ) + 1;
     152             :     }
     153             :     else
     154             :     {
     155     3688049 :         nb_channels = ( sba_order + 1 ) * ( sba_order + 1 );
     156             :     }
     157             : 
     158     3688049 :     return ( nb_channels );
     159             : }
     160             : 
     161             : 
     162             : /*-------------------------------------------------------------------*
     163             :  * ivas_sba_spar_sid_bitlen()
     164             :  *
     165             :  * Get number of bits in SBA SPAR SID frame
     166             :  *-------------------------------------------------------------------*/
     167             : 
     168             : /*! r: number of bits in SBA SPAR SID frame */
     169       11002 : int16_t ivas_sba_spar_sid_bitlen(
     170             :     const int16_t nchan_transport /* i  : number of transport channels            */
     171             : )
     172             : {
     173             :     int16_t num_bits;
     174             : 
     175       11002 :     num_bits = SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND;
     176       11002 :     if ( nchan_transport > 1 )
     177             :     {
     178        5282 :         num_bits -= 2;
     179             :     }
     180             : 
     181       11002 :     return num_bits;
     182             : }
     183             : 
     184             : /*-------------------------------------------------------------------*
     185             :  * ivas_sba_get_nchan_metadata()
     186             :  *
     187             :  * Get number of Ambisonic channels for metadata coding
     188             :  *-------------------------------------------------------------------*/
     189             : 
     190             : /*! r: number of ambisonics metadata channels */
     191     8872465 : int16_t ivas_sba_get_nchan_metadata(
     192             :     const int16_t sba_order,       /* i  : Ambisonic (SBA) order            */
     193             :     const int32_t ivas_total_brate /* i  : IVAS total bitrate               */
     194             : )
     195             : {
     196             :     int16_t nb_channels;
     197             : 
     198     8872465 :     if ( sba_order == SBA_FOA_ORDER )
     199             :     {
     200     6509330 :         nb_channels = FOA_CHANNELS;
     201             :     }
     202             :     else
     203             :     {
     204     2363135 :         if ( ivas_total_brate >= IVAS_512k )
     205             :         {
     206      722604 :             nb_channels = IVAS_SPAR_MAX_CH;
     207      722604 :             nb_channels = min( nb_channels, ( sba_order + 1 ) * ( sba_order + 1 ) );
     208             :         }
     209             :         else
     210             :         {
     211             :             /* FOA + planar HOA */
     212     1640531 :             nb_channels = FOA_CHANNELS + 2 * ( sba_order - 1 );
     213             :         }
     214             :     }
     215             : 
     216     8872465 :     return ( nb_channels );
     217             : }
     218             : 
     219             : 
     220             : /*-------------------------------------------------------------------*
     221             :  * ivas_sba_get_spar_hoa_ch_ind()
     222             :  *
     223             :  *
     224             :  *-------------------------------------------------------------------*/
     225             : 
     226             : /*! r: flag indicating to code SPAR HOA MD for all bands  */
     227        7816 : void ivas_sba_get_spar_hoa_ch_ind(
     228             :     const int16_t num_md_chs,       /* i  : number of MD channels       */
     229             :     const int32_t ivas_total_brate, /* i  : IVAS total bitrate           */
     230             :     int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] )
     231             : {
     232             :     int16_t ch;
     233             :     const int16_t *hoa_ind;
     234             : 
     235        7816 :     if ( ivas_total_brate >= IVAS_512k )
     236             :     {
     237         500 :         hoa_ind = HOA_keep_ind_spar512;
     238             :     }
     239             :     else
     240             :     {
     241        7316 :         hoa_ind = HOA_keep_ind_spar;
     242             :     }
     243             : 
     244       43780 :     for ( ch = 0; ch < num_md_chs; ch++ )
     245             :     {
     246       35964 :         HOA_md_ind[ch] = hoa_ind[ch];
     247             :     }
     248             : 
     249        7816 :     return;
     250             : }
     251             : 
     252             : 
     253             : /*-------------------------------------------------------------------*
     254             :  * ivas_sba_get_spar_hoa_md_flag()
     255             :  *
     256             :  * Get the flag to code SPAR HOA MD for all band
     257             :  *-------------------------------------------------------------------*/
     258             : 
     259        7816 : void ivas_sba_get_spar_hoa_md_flag(
     260             :     const int16_t sba_order,        /* i  : Ambisonic (SBA) order        */
     261             :     const int32_t ivas_total_brate, /* i  : IVAS total bitrate           */
     262             :     int16_t *spar_hoa_md_flag,
     263             :     int16_t *spar_hoa_dirac2spar_md_flag )
     264             : {
     265        7816 :     if ( sba_order > 1 && ivas_total_brate >= IVAS_256k )
     266             :     {
     267        1036 :         *spar_hoa_md_flag = 1;
     268             :     }
     269             :     else
     270             :     {
     271        6780 :         *spar_hoa_md_flag = 0;
     272             :     }
     273             : 
     274        7816 :     if ( sba_order > 1 && ivas_total_brate >= IVAS_512k )
     275             :     {
     276         380 :         *spar_hoa_dirac2spar_md_flag = 0;
     277             :     }
     278             :     else
     279             :     {
     280        7436 :         *spar_hoa_dirac2spar_md_flag = 1;
     281             :     }
     282             : 
     283        7816 :     return;
     284             : }
     285             : 
     286             : 
     287             : /*-------------------------------------------------------------------*
     288             :  * ivas_sba_zero_vert_comp()
     289             :  *
     290             :  * Zero vertical Ambisonics components
     291             :  *-------------------------------------------------------------------*/
     292             : 
     293       20500 : void ivas_sba_zero_vert_comp(
     294             :     float *sba_data[],        /* i  : SBA signals                 */
     295             :     const int16_t sba_order,  /* i  : SBA order                   */
     296             :     const int16_t sba_planar, /* i  : SBA planar flag             */
     297             :     const int16_t input_frame /* i  : frame length                */
     298             : )
     299             : {
     300             :     int16_t i, j;
     301             : 
     302             :     /* Channels in the range i^2+1 to (i+1)^2 -1 are zeroed (retain only first and last channel for that order) */
     303       48280 :     for ( i = 1; i <= sba_order; i++ )
     304             :     {
     305             :         /* Keep Z if not planar */
     306       27780 :         if ( !sba_planar && i == 1 )
     307             :         {
     308           0 :             continue;
     309             :         }
     310             : 
     311       75400 :         for ( j = ( i * i + 1 ); j < ( ( i + 1 ) * ( i + 1 ) - 1 ); j++ )
     312             :         {
     313       47620 :             set_zero( sba_data[j], input_frame );
     314             :         }
     315             :     }
     316             : 
     317       20500 :     return;
     318             : }

Generated by: LCOV version 1.14