LCOV - code coverage report
Current view: top level - lib_com - ivas_sba_config_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 73 85 85.9 %
Date: 2025-08-23 01:22:27 Functions: 7 8 87.5 %

          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_fx.h"
      41             : #include "ivas_stat_com.h"
      42             : #include "ivas_rom_com.h"
      43             : #include "wmc_auto.h"
      44             : #include "ivas_prot_fx.h"
      45             : 
      46             : /*-------------------------------------------------------------------*
      47             :  * ivas_sba_config()
      48             :  *
      49             :  * Configure SBA coding
      50             :  *-------------------------------------------------------------------*/
      51             : 
      52      144617 : void ivas_sba_config_fx(
      53             :     const Word32 sba_total_brate, /* i  : SBA total bitrate                        */
      54             :     Word16 sba_order,             /* i  : Ambisonic (SBA) order                    */
      55             :     Word16 nb_channels,           /* i  : Number of ambisonic channels             */
      56             :     Word16 *nchan_transport,      /* o  : number of transport channels             */
      57             :     const Word16 sba_planar,      /* i  : SBA Planar flag                          */
      58             :     Word16 *nSCE,                 /* o  : number of SCEs                           */
      59             :     Word16 *nCPE,                 /* o  : number of CPEs                           */
      60             :     Word16 *element_mode          /* o  : element mode of the core coder           */
      61             : )
      62             : {
      63      144617 :     IF( nb_channels > 0 )
      64             :     {
      65           0 :         IF( sba_planar )
      66             :         {
      67           0 :             assert( ( EQ_16( add( shl( sba_order, 1 ), 1 ), nb_channels ) ) && "Order and number of channels do not correspond!" );
      68             :         }
      69             :         ELSE
      70             :         {
      71           0 :             assert( ( EQ_16( mult( add( sba_order, 1 ), add( sba_order, 1 ) ), nb_channels ) ) && "Order and number of channels do not correspond!" );
      72             :         }
      73             :     }
      74             : 
      75      144617 :     IF( nchan_transport != NULL )
      76             :     {
      77      144617 :         *nchan_transport = ivas_get_sba_num_TCs_fx( sba_total_brate, sba_order );
      78      144617 :         move16();
      79             :     }
      80             : 
      81             :     /* Configure core coder number of elements*/
      82      144617 :     test();
      83      144617 :     test();
      84      144617 :     IF( nchan_transport != NULL && nSCE != NULL && nCPE != NULL )
      85             :     {
      86      144617 :         IF( EQ_16( *nchan_transport, 1 ) )
      87             :         {
      88       37392 :             *nSCE = 1;
      89       37392 :             move16();
      90       37392 :             *nCPE = 0;
      91       37392 :             move16();
      92       37392 :             *element_mode = IVAS_SCE;
      93       37392 :             move16();
      94             :         }
      95             :         ELSE
      96             :         {
      97      107225 :             *nSCE = 0;
      98      107225 :             move16();
      99      107225 :             *nCPE = shr( *nchan_transport, 1 );
     100      107225 :             move16();
     101      107225 :             IF( NE_16( i_mult( 2, ( *nCPE ) ), *nchan_transport ) )
     102             :             {
     103       30453 :                 *nCPE = add( *nCPE, 1 );
     104       30453 :                 move16();
     105             :             }
     106      107225 :             *element_mode = IVAS_CPE_MDCT;
     107      107225 :             move16();
     108             :         }
     109             :     }
     110             : 
     111      144617 :     return;
     112             : }
     113             : 
     114             : 
     115             : /*-------------------------------------------------------------------*
     116             :  * ivas_sba_get_analysis_order()
     117             :  *
     118             :  * Get Ambisonic order used for analysis and coding
     119             :  *-------------------------------------------------------------------*/
     120             : 
     121             : /*! r: Ambisonic (SBA) order used for analysis and coding */
     122      145565 : Word16 ivas_sba_get_analysis_order_fx(
     123             :     const Word32 ivas_total_brate, /* i  : IVAS total bitrate      */
     124             :     const Word16 sba_order         /* i  : Ambisonic (SBA) order   */
     125             : )
     126             : {
     127             :     Word16 sba_analysis_order;
     128             : 
     129      145565 :     sba_analysis_order = sba_order;
     130      145565 :     move16();
     131             : 
     132      145565 :     if ( LT_32( ivas_total_brate, SBA_MIN_BRATE_HOA ) )
     133             :     {
     134             :         /* Hard coding the sba_analysis_order as 1 as higher not supported below SBA_MIN_BRATE_HOA bitrate */
     135      106371 :         sba_analysis_order = SBA_FOA_ORDER;
     136      106371 :         move16();
     137             :     }
     138             : 
     139      145565 :     return sba_analysis_order;
     140             : }
     141             : 
     142             : 
     143             : /*-------------------------------------------------------------------*
     144             :  * ivas_sba_get_nchan()
     145             :  *
     146             :  * Get number of Ambisonic channels
     147             :  *-------------------------------------------------------------------*/
     148             : 
     149             : /*! r: number of Ambisonic channels */
     150      378297 : Word16 ivas_sba_get_nchan_fx(
     151             :     const Word16 sba_order, /* i  : Ambisonic (SBA) order            */
     152             :     const Word16 sba_planar /* i  : SBA planar flag                  */
     153             : )
     154             : {
     155             :     Word16 nb_channels;
     156             : 
     157      378297 :     IF( sba_planar )
     158             :     {
     159           0 :         nb_channels = add( shl( sba_order, 1 ), 1 );
     160             :     }
     161             :     ELSE
     162             :     {
     163      378297 :         nb_channels = i_mult( add( sba_order, 1 ), add( sba_order, 1 ) );
     164             :     }
     165             : 
     166      378297 :     return ( nb_channels );
     167             : }
     168             : 
     169             : 
     170             : #ifdef NONBE_FIX_1052_SBA_EXT
     171             : /*-------------------------------------------------------------------*
     172             :  * ivas_sba_spar_sid_bitlen_fx()
     173             :  *
     174             :  * Get number of bits in SBA SID frame
     175             :  *-------------------------------------------------------------------*/
     176             : 
     177             : /*! r: number of bits in SBA SID frame */
     178        1114 : Word16 ivas_sba_spar_sid_bitlen_fx(
     179             :     const Word16 nchan_transport /* i  : number of transport channels            */
     180             : )
     181             : {
     182             :     Word16 num_bits;
     183             : 
     184        1114 :     num_bits = i_mult( SPAR_DTX_BANDS, SPAR_SID_BITS_TAR_PER_BAND );
     185        1114 :     IF( GT_16( nchan_transport, 1 ) )
     186             :     {
     187         636 :         num_bits = sub( num_bits, 2 );
     188             :     }
     189             : 
     190        1114 :     return num_bits;
     191             : }
     192             : #endif
     193             : 
     194             : 
     195             : /*-------------------------------------------------------------------*
     196             :  * ivas_sba_get_nchan_metadata()
     197             :  *
     198             :  * Get number of Ambisonic channels for metadata coding
     199             :  *-------------------------------------------------------------------*/
     200             : 
     201             : /*! r: number of ambisonics metadata channels */
     202     4003527 : Word16 ivas_sba_get_nchan_metadata_fx(
     203             :     const Word16 sba_order,       /* i  : Ambisonic (SBA) order            */
     204             :     const Word32 ivas_total_brate /* i  : IVAS total bitrate               */
     205             : )
     206             : {
     207             :     Word16 nb_channels;
     208             : 
     209     4003527 :     IF( EQ_16( sba_order, SBA_FOA_ORDER ) )
     210             :     {
     211     3013488 :         nb_channels = FOA_CHANNELS;
     212     3013488 :         move16();
     213             :     }
     214             :     ELSE
     215             :     {
     216      990039 :         IF( GE_32( ivas_total_brate, IVAS_512k ) )
     217             :         {
     218      390452 :             nb_channels = IVAS_SPAR_MAX_CH;
     219      390452 :             move16();
     220      390452 :             nb_channels = s_min( nb_channels, imult1616( add( sba_order, 1 ), add( sba_order, 1 ) ) );
     221             :         }
     222             :         ELSE
     223             :         {
     224             :             /* FOA + planar HOA */
     225      599587 :             nb_channels = add( FOA_CHANNELS, shl( sub( sba_order, 1 ), 1 ) );
     226             :         }
     227             :     }
     228             : 
     229     4003527 :     return ( nb_channels );
     230             : }
     231             : 
     232             : /*-------------------------------------------------------------------*
     233             :  * ivas_sba_get_spar_hoa_ch_ind()
     234             :  *
     235             :  *
     236             :  *-------------------------------------------------------------------*/
     237             : 
     238             : /*! r: flag indicating to code SPAR HOA MD for all bands  */
     239        1860 : void ivas_sba_get_spar_hoa_ch_ind_fx(
     240             :     const Word16 num_md_chs,       /* i  : number of MD channels       */
     241             :     const Word32 ivas_total_brate, /* i  : IVAS total bitrate           */
     242             :     Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] )
     243             : {
     244             :     Word16 ch;
     245             :     const Word16 *hoa_ind;
     246             : 
     247        1860 :     IF( GE_32( ivas_total_brate, IVAS_512k ) )
     248             :     {
     249         118 :         hoa_ind = HOA_keep_ind_spar512;
     250             :     }
     251             :     ELSE
     252             :     {
     253        1742 :         hoa_ind = HOA_keep_ind_spar;
     254             :     }
     255             : 
     256       10414 :     FOR( ch = 0; ch < num_md_chs; ch++ )
     257             :     {
     258        8554 :         HOA_md_ind[ch] = hoa_ind[ch];
     259        8554 :         move16();
     260             :     }
     261             : 
     262        1860 :     return;
     263             : }
     264             : 
     265             : 
     266             : /*-------------------------------------------------------------------*
     267             :  * ivas_sba_get_spar_hoa_md_flag()
     268             :  *
     269             :  * Get the flag to code SPAR HOA MD for all band
     270             :  *-------------------------------------------------------------------*/
     271             : 
     272        1860 : void ivas_sba_get_spar_hoa_md_flag_fx(
     273             :     const Word16 sba_order,        /* i  : Ambisonic (SBA) order        */
     274             :     const Word32 ivas_total_brate, /* i  : IVAS total bitrate           */
     275             :     Word16 *spar_hoa_md_flag,
     276             :     Word16 *spar_hoa_dirac2spar_md_flag )
     277             : {
     278        1860 :     test();
     279        1860 :     IF( GT_16( sba_order, 1 ) && GE_32( ivas_total_brate, IVAS_256k ) )
     280             :     {
     281         240 :         *spar_hoa_md_flag = 1;
     282         240 :         move16();
     283             :     }
     284             :     ELSE
     285             :     {
     286        1620 :         *spar_hoa_md_flag = 0;
     287        1620 :         move16();
     288             :     }
     289             : 
     290        1860 :     test();
     291        1860 :     IF( GT_16( sba_order, 1 ) && GE_32( ivas_total_brate, IVAS_512k ) )
     292             :     {
     293          88 :         *spar_hoa_dirac2spar_md_flag = 0;
     294          88 :         move16();
     295             :     }
     296             :     ELSE
     297             :     {
     298        1772 :         *spar_hoa_dirac2spar_md_flag = 1;
     299        1772 :         move16();
     300             :     }
     301             : 
     302        1860 :     return;
     303             : }
     304             : 
     305             : 
     306             : /*-------------------------------------------------------------------*
     307             :  * ivas_sba_zero_vert_comp()
     308             :  *
     309             :  * Zero vertical Ambisonics components
     310             :  *-------------------------------------------------------------------*/
     311           0 : void ivas_sba_zero_vert_comp_fx(
     312             :     Word32 *sba_data[],      /* i  : SBA signals q_data          */
     313             :     const Word16 sba_order,  /* i  : SBA order                   */
     314             :     const Word16 sba_planar, /* i  : SBA planar flag             */
     315             :     const Word16 input_frame /* i  : frame length                */
     316             : )
     317             : {
     318             :     Word16 i, j;
     319             : 
     320             :     /* Channels in the range i^2+1 to (i+1)^2 -1 are zeroed (retain only first and last channel for that order) */
     321           0 :     FOR( i = 1; i <= sba_order; i++ )
     322             :     {
     323           0 :         test();
     324             :         /* Keep Z if not planar */
     325           0 :         IF( !sba_planar && EQ_16( i, 1 ) )
     326             :         {
     327           0 :             CONTINUE;
     328             :         }
     329             : 
     330           0 :         FOR( j = ( i * i + 1 ); j < ( ( i + 1 ) * ( i + 1 ) - 1 ); j++ )
     331             :         {
     332           0 :             set_val_Word32( sba_data[j], 0, input_frame );
     333             :         }
     334             :     }
     335             : 
     336           0 :     return;
     337             : }

Generated by: LCOV version 1.14