LCOV - code coverage report
Current view: top level - lib_com - ivas_mct_com_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 69 84 82.1 %
Date: 2025-05-17 01:59:02 Functions: 1 1 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_fx.h"
      37             : #include "ivas_prot_fx.h"
      38             : #include "wmc_auto.h"
      39             : #include <assert.h>
      40             : 
      41             : 
      42             : /*-------------------------------------------------------------------*
      43             :  * Local constants
      44             :  *-------------------------------------------------------------------*/
      45             : 
      46             : #define MIN_SAFETY_BITS_LFE 30
      47             : #define MIN_SAFETY_BITS_MC  5
      48             : 
      49             : 
      50             : /*-------------------------------------------------------------------*
      51             :  * splitAvailableBitsMCT()
      52             :  *
      53             :  * split available TCX bits among channels
      54             :  *-------------------------------------------------------------------*/
      55             : 
      56       91423 : void splitAvailableBitsMCT_fx(
      57             :     void **sts,                                 /* i/o: encoder/decoder state structure     */
      58             :     const Word16 total_bits,                    /* i  : total number of available bits      */
      59             :     const Word16 split_ratio[MCT_MAX_CHANNELS], /* i  : ratio for splitting the bits       Q0 */
      60             :     const Word16 enc_dec,                       /* i  : encoder or decoder flag             */
      61             :     const Word16 nchan                          /* i  : number of channels                  */
      62             : )
      63             : {
      64             :     Word16 i, k, nSubframes, diff, bits_split, max_chn, tmp;
      65             :     Word16 *bits_frame_channel;
      66             :     Word16 min_chan_bits[MCT_MAX_CHANNELS], min_bits_tot, remaining_bits;
      67             :     Word16 core[MCT_MAX_CHANNELS];
      68             :     MCT_CHAN_MODE mct_chan_mode[MCT_MAX_CHANNELS];
      69       91423 :     min_bits_tot = 0;
      70       91423 :     move16();
      71             : 
      72      509763 :     FOR( i = 0; i < nchan; i++ )
      73             :     {
      74      418340 :         IF( enc_dec == ENC )
      75             :         {
      76           0 :             mct_chan_mode[i] = ( (Encoder_State *) sts[i] )->mct_chan_mode;
      77           0 :             move32();
      78           0 :             core[i] = ( (Encoder_State *) sts[i] )->core;
      79           0 :             move16();
      80             :         }
      81             :         ELSE
      82             :         {
      83      418340 :             mct_chan_mode[i] = ( (Decoder_State *) sts[i] )->mct_chan_mode;
      84      418340 :             move32();
      85      418340 :             core[i] = ( (Decoder_State *) sts[i] )->core;
      86      418340 :             move16();
      87             :         }
      88             :     }
      89             : 
      90      509763 :     FOR( i = 0; i < nchan; i++ )
      91             :     {
      92      418340 :         IF( NE_32( mct_chan_mode[i], MCT_CHAN_MODE_IGNORE ) )
      93             :         {
      94      407950 :             min_chan_bits[i] = 0;
      95      407950 :             move16();
      96      407950 :             IF( EQ_32( core[i], TCX_20_CORE ) )
      97             :             {
      98      399136 :                 nSubframes = 1;
      99      399136 :                 move16();
     100             :             }
     101             :             ELSE
     102             :             {
     103        8814 :                 nSubframes = NB_DIV;
     104        8814 :                 move16();
     105             :             }
     106      824714 :             FOR( k = 0; k < nSubframes; k++ )
     107             :             {
     108      416764 :                 min_chan_bits[i] = add( min_chan_bits[i], SMDCT_MINIMUM_ARITH_BITS + MIN_SAFETY_BITS_MC );
     109      416764 :                 move16();
     110             :             }
     111      407950 :             min_bits_tot = add( min_bits_tot, min_chan_bits[i] );
     112             :         }
     113             :     }
     114             : 
     115       91423 :     remaining_bits = sub( total_bits, min_bits_tot );
     116             : 
     117             :     /*initial value of bits already given*/
     118       91423 :     bits_split = 0;
     119       91423 :     move16();
     120             : 
     121       91423 :     tmp = 0;
     122       91423 :     move16();
     123       91423 :     max_chn = 0;
     124       91423 :     move16();
     125      509763 :     FOR( i = 0; i < nchan; i++ )
     126             :     {
     127      418340 :         IF( enc_dec == ENC )
     128             :         {
     129           0 :             bits_frame_channel = &( (Encoder_State *) sts[i] )->bits_frame_channel;
     130             :         }
     131             :         ELSE /* DEC */
     132             :         {
     133      418340 :             bits_frame_channel = &( (Decoder_State *) sts[i] )->bits_frame_channel;
     134             :         }
     135      418340 :         move16();
     136      418340 :         IF( NE_32( mct_chan_mode[i], MCT_CHAN_MODE_IGNORE ) )
     137             :         {
     138      407950 :             assert( split_ratio[i] >= 1 && split_ratio[i] < BITRATE_MCT_RATIO_RANGE );
     139      407950 :             *bits_frame_channel = add( extract_l( L_shr( L_mult0( split_ratio[i], remaining_bits ), NBBITS_MCT_RATIO ) ), min_chan_bits[i] );
     140      407950 :             bits_split = add( bits_split, *bits_frame_channel );
     141             : 
     142             :             /*determine channel with most bits (energy)*/
     143      407950 :             if ( GT_16( *bits_frame_channel, tmp ) )
     144             :             {
     145      116932 :                 tmp = *bits_frame_channel;
     146      116932 :                 move16();
     147      116932 :                 max_chn = i;
     148      116932 :                 move16();
     149             :             }
     150             :         }
     151             :     }
     152             : 
     153             :     /*if bits distributed are more than available bits, substract the proportional amount of bits from all channels*/
     154       91423 :     IF( NE_16( bits_split, total_bits ) )
     155             :     {
     156       86661 :         diff = sub( bits_split, total_bits );
     157             : 
     158             :         /*re-count bits distributed to each channel*/
     159       86661 :         bits_split = 0;
     160       86661 :         move16();
     161             : 
     162      486653 :         FOR( i = 0; i < nchan; i++ )
     163             :         {
     164      399992 :             IF( enc_dec == ENC )
     165             :             {
     166           0 :                 bits_frame_channel = &( (Encoder_State *) sts[i] )->bits_frame_channel;
     167             :             }
     168             :             ELSE /* DEC */
     169             :             {
     170      399992 :                 bits_frame_channel = &( (Decoder_State *) sts[i] )->bits_frame_channel;
     171             :             }
     172      399992 :             move16();
     173      399992 :             IF( NE_32( mct_chan_mode[i], MCT_CHAN_MODE_IGNORE ) )
     174             :             {
     175             :                 Word32 temp_res;
     176      390459 :                 temp_res = L_mult0( diff, split_ratio[i] );
     177      390459 :                 IF( temp_res < 0 )
     178             :                 {
     179      260898 :                     temp_res = L_negate( temp_res );
     180      260898 :                     temp_res = L_shr( temp_res, NBBITS_MCT_RATIO );
     181      260898 :                     temp_res = L_negate( temp_res );
     182             :                 }
     183             :                 ELSE
     184             :                 {
     185      129561 :                     temp_res = L_shr( temp_res, NBBITS_MCT_RATIO );
     186             :                 }
     187      390459 :                 *bits_frame_channel = sub( *bits_frame_channel, extract_l( temp_res ) );
     188      390459 :                 move16();
     189      390459 :                 *bits_frame_channel = s_max( min_chan_bits[i], *bits_frame_channel );
     190      390459 :                 move16();
     191      390459 :                 bits_split = add( bits_split, *bits_frame_channel );
     192             :             }
     193             :         }
     194             :     }
     195             : 
     196             :     /*if there any bits left assign them to the channel with the maximum energy (or more bits)*/
     197       91423 :     IF( NE_16( total_bits, bits_split ) )
     198             :     {
     199       86656 :         IF( enc_dec == ENC )
     200             :         {
     201           0 :             bits_frame_channel = &( (Encoder_State *) sts[max_chn] )->bits_frame_channel;
     202             :         }
     203             :         ELSE /* DEC */
     204             :         {
     205       86656 :             bits_frame_channel = &( (Decoder_State *) sts[max_chn] )->bits_frame_channel;
     206             :         }
     207       86656 :         move16();
     208       86656 :         *bits_frame_channel = add( *bits_frame_channel, sub( total_bits, bits_split ) );
     209             : 
     210             :         /*if all channels are silent assign bits to ch 0*/
     211       86656 :         IF( enc_dec == ENC )
     212             :         {
     213           0 :             IF( EQ_32( ( (Encoder_State *) sts[max_chn] )->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) )
     214             :             {
     215           0 :                 assert( bits_split == 0 );
     216             : 
     217           0 :                 ( (Encoder_State *) sts[max_chn] )->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
     218           0 :                 move32();
     219           0 :                 ( (Encoder_State *) sts[max_chn] )->side_bits_frame_channel = imult1616( ( ( (Encoder_State *) sts[max_chn] )->core ), ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ) );
     220           0 :                 move16();
     221           0 :                 *bits_frame_channel = sub( *bits_frame_channel, ( (Encoder_State *) sts[max_chn] )->side_bits_frame_channel );
     222           0 :                 move16();
     223             :             }
     224             :         }
     225             :     }
     226             : 
     227       91423 :     return;
     228             : }

Generated by: LCOV version 1.14