LCOV - code coverage report
Current view: top level - lib_com - ivas_stereo_td_bit_alloc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 267 358 74.6 %
Date: 2025-05-17 01:59:02 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 <stdint.h>
      34             : #include "options.h"
      35             : #include "cnst.h"
      36             : #include "stat_enc.h"
      37             : #include "rom_com.h"
      38             : #include "ivas_rom_com.h"
      39             : #include "ivas_cnst.h"
      40             : #include "prot_fx.h"
      41             : #include "wmc_auto.h"
      42             : #include "ivas_prot_fx.h"
      43             : #include "ivas_rom_com_fx.h"
      44             : 
      45             : 
      46             : /*-------------------------------------------------------------------*
      47             :  * Local constants
      48             :  *-------------------------------------------------------------------*/
      49             : 
      50             : #define NB_RATE_POSS     10                              /* Nmbr of possible FCB bitrate for half rate mode*/
      51             : #define MIN_SEC_ACB_RATE ( 2 * 8 * FRAMES_PER_SEC )      /* 2 subfr ACB bitrate */
      52             : #define MIN_SEC_LPC_RATE ( ( 24 + 2 ) * FRAMES_PER_SEC ) /* LPC min rate */
      53             : 
      54             : #define MAX_SC_FCB_RATE     ( 24 + 1 ) /* Maximum bit for a FCB subfr */
      55             : #define MIN_4SUBFR_FCB_RATE 40         /* Minimum 4 subfr bitrate (4x10 bits) */
      56             : #define MIN_GAIN_BITS       6          /* Minimum number of bits used */
      57             : 
      58             : #define TDM_UC_NORMAL_MODE_MBRATE      9000                        /* Max bitrate for normal UC if LP coded */
      59             : #define TDM_UC_NORMAL_MODE_MBRATE_LP_R 8200                        /* Normal bitrate for normal UC if LP is reused */
      60             : #define TDM_UC_NORMAL_MODE_MINBR_LP_R  7000                        /* If bitrate is below 7k, add back MID_LP_BRATE */
      61             : #define MID_LP_BRATE                   ( 31 + 5 ) * FRAMES_PER_SEC /* average bitrate for LP */
      62             : #define MAX_TDM_UC_BRATE               11000                       /* Maximum bitrate for tdm normal UC mode */
      63             : 
      64             : #define MIN_SIGN_RATE    ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS * FRAMES_PER_SEC ) /* min. 2 time 12 bits FCB, used only when LPC and/or pitch is transmitted    */
      65             : #define MIN_FCB_SECRATE2 ( 2 * 16 * FRAMES_PER_SEC )                                  /* min. 2 time 14 bits FCB, used only when LPC and/or pitch is transmitted    */
      66             : 
      67             : 
      68             : /*-------------------------------------------------------------------*
      69             :  * tdm_bit_alloc()
      70             :  *
      71             :  * Bitbudget distribution between Primary and Secondary channel in TD stereo
      72             :  *-------------------------------------------------------------------*/
      73        3695 : void tdm_bit_alloc(
      74             :     const Word16 ivas_format,           /* i  : IVAS format                          Q0*/
      75             :     const Word16 ism_mode,              /* i  : ISM mode in combined format          Q0*/
      76             :     const Word32 element_brate_wo_meta, /* i  : element bitrate without metadata     Q0*/
      77             :     const Word16 tdm_lp_reuse_flag,     /* i  : LPC reusage flag                     Q0*/
      78             :     Word32 *total_brate_pri,            /* o  : Allocated primary channel bitrate    Q0*/
      79             :     Word32 *total_brate_sec,            /* o  : Allocated secondary channel bitrate  Q0*/
      80             :     Word16 *tdm_low_rate_mode,          /* o  : secondary channel low rate mode flag Q0*/
      81             :     const Word16 coder_type,            /* i  : secondary channel coder type         Q0*/
      82             :     const Word16 ener_ratio_idx,        /* i  : correlation ratio indexe             Q0*/
      83             :     const Word16 tdm_Pitch_reuse_flag,  /* i  : primary channel pitch reuse flag     Q0*/
      84             :     const Word16 bwidth_pri,            /* i  : bandwidth of the primary channel     Q0*/
      85             :     const Word16 bwidth_sec,            /* i  : bandwidth of the secondary channel   Q0*/
      86             :     const Word16 flag_ACELP16k_pri,     /* i  : ACELP@16kHz core flag, primary chan. Q0*/
      87             :     const Word16 tdm_LRTD_flag,         /* i  : LRTD stereo mode flag                Q0*/
      88             :     const Word16 coder_type0,           /* i  : coder type (temporary in the encoder, from bitstream in decoder) Q0*/
      89             :     const Word16 tdm_inst_ratio_idx_ref /* i  : instantaneous correlation ratio idx Q0*/
      90             : )
      91             : {
      92             :     Word16 idx, four_subfr_fcb, two_subfr_fcb;
      93             :     Word32 bit_rate_diff_fx;
      94             :     Word32 BWE_brate;
      95             :     Word16 tmp_bits;
      96        3695 :     Word16 tdm_inst_ratio_idx = tdm_inst_ratio_idx_ref; /*Q0*/
      97        3695 :     move16();
      98        3695 :     if ( EQ_16( tdm_inst_ratio_idx, TDM_NQ ) )
      99             :     {
     100          80 :         tdm_inst_ratio_idx = LRTD_STEREO_MID_IS_PRIM; /* Bit rate almost split half and half*/
     101          80 :         move16();
     102             :     }
     103             : 
     104             :     /* Decision on using the low rate mode or the normal mode */
     105             :     /* default is using the low rate mode for the secondary channel coding*/
     106             :     /* UC and IC are automatically coded with low rate mode */
     107        3695 :     *tdm_low_rate_mode = 1;
     108        3695 :     move16();
     109             : 
     110             :     /* Allocating different bitrate to channels */
     111        3695 :     idx = 0;
     112        3695 :     move16();
     113        3695 :     IF( LE_32( element_brate_wo_meta, IVAS_13k2 ) )
     114             :     {
     115           0 :         idx = 0;
     116           0 :         move16();
     117             :     }
     118        3695 :     ELSE IF( LE_32( element_brate_wo_meta, IVAS_16k4 ) )
     119             :     {
     120         555 :         idx = 1;
     121         555 :         move16();
     122             :     }
     123        3140 :     ELSE IF( LE_32( element_brate_wo_meta, IVAS_24k4 ) )
     124             :     {
     125        1118 :         idx = 2;
     126        1118 :         move16();
     127             :     }
     128        2022 :     ELSE IF( LE_32( element_brate_wo_meta, IVAS_32k ) )
     129             :     {
     130        2022 :         idx = 3;
     131        2022 :         move16();
     132             :     }
     133           0 :     ELSE IF( LE_32( element_brate_wo_meta, IVAS_48k ) )
     134             :     {
     135           0 :         idx = 4;
     136           0 :         move16();
     137             :     }
     138             : 
     139        3695 :     test();
     140        3695 :     if ( EQ_16( coder_type, UNVOICED ) && GE_16( tdm_bit_allc_tbl[idx][coder_type], 4200 ) )
     141             :     {
     142           0 :         *tdm_low_rate_mode = 0;
     143           0 :         move16();
     144             :     }
     145             : 
     146             :     /* Secondary channel based bitrate allocation */
     147        3695 :     *total_brate_sec = tdm_bit_allc_tbl[idx][coder_type]; /*Q0*/
     148        3695 :     move16();
     149             : 
     150        3695 :     test();
     151        3695 :     test();
     152        3695 :     test();
     153        3695 :     test();
     154        3695 :     test();
     155        3695 :     test();
     156             :     /* secondary channel bitrate allocation based on the energy scaling ratio */
     157        3695 :     IF( ( ( NE_16( ivas_format, MASA_ISM_FORMAT ) || ism_mode == ISM_MODE_NONE ) && ( ( NE_16( coder_type, UNVOICED ) ) || EQ_16( tdm_LRTD_flag, 1 ) ) ) || ( EQ_16( ivas_format, MASA_ISM_FORMAT ) && ism_mode != ISM_MODE_NONE && GT_16( coder_type, UNVOICED ) ) )
     158        3679 :     {
     159        3679 :         bit_rate_diff_fx = L_sub( element_brate_wo_meta, L_shl( *total_brate_sec, 1 ) ); /*Q0*/
     160             : 
     161        3679 :         IF( EQ_16( tdm_LRTD_flag, 1 ) ) /* >  element_brate > STEREO_22k or CT0 not used */
     162             :         {
     163             :             /* further adjustment in function of the energy/correlation ratio */
     164        3569 :             IF( coder_type == INACTIVE )
     165             :             {
     166           0 :                 Word32 res_fix = 0;
     167           0 :                 move32();
     168           0 :                 res_fix = Mpy_32_32( 644245095 /*0.3f in Q31*/, L_sub( element_brate_wo_meta, 500 ) ); /*Q0*/
     169           0 :                 res_fix = imult3216( Mpy_32_32( L_abs( res_fix ), 21474837 /*0.01 in Q31*/ ), 100 );   /*Q0*/
     170           0 :                 if ( res_fix < 0 )
     171             :                 {
     172           0 :                     res_fix = L_negate( res_fix );
     173             :                 }
     174           0 :                 *total_brate_sec = L_max( *total_brate_sec, res_fix ); /*Q0*/
     175           0 :                 move32();
     176             : 
     177           0 :                 tmp_bits = imult1616( negate( abs_s( sub( tdm_inst_ratio_idx, 16 ) ) ), imult1616( idx, 200 ) ); /*Q0*/
     178             :             }
     179             :             ELSE
     180             :             {
     181        3569 :                 Word32 res_fix = 0;
     182        3569 :                 move32();
     183        3569 :                 res_fix = Mpy_32_32( 1073741824 /*0.5f in Q31*/, L_sub( element_brate_wo_meta, 500 ) ); /*Q0*/
     184        3569 :                 res_fix = imult3216( Mpy_32_32( L_abs( res_fix ), 21474837 /*0.01 in Q31*/ ), 100 );    /*Q0*/
     185        3569 :                 if ( res_fix < 0 )
     186             :                 {
     187           0 :                     res_fix = L_negate( res_fix );
     188             :                 }
     189        3569 :                 *total_brate_sec = L_max( *total_brate_sec, res_fix ); /*Q0*/
     190        3569 :                 move32();
     191             : 
     192        3569 :                 tmp_bits = imult1616( negate( abs_s( sub( tdm_inst_ratio_idx, 16 ) ) ), imult1616( 100, idx ) ); /*Q0*/
     193             :             }
     194             : 
     195             :             /* tmp_bits should be subtract from the secondary channel bitrate */
     196             :             /* IF the primary channel doesn't correspond to the channel having the highest correlation to the mono- inverse the bitrate compensation */
     197        3569 :             test();
     198        3569 :             test();
     199        3569 :             test();
     200        3569 :             if ( ( GE_16( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) && LT_16( tdm_inst_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ) || ( LT_16( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) && GE_16( tdm_inst_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ) )
     201             :             {
     202        1581 :                 tmp_bits = negate( tmp_bits );
     203             :             }
     204        3569 :             bit_rate_diff_fx = tmp_bits;
     205        3569 :             move16();
     206             :         }
     207             :         ELSE
     208             :         {
     209         110 :             IF( LT_16( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) )
     210             :             {
     211             : 
     212          70 :                 bit_rate_diff_fx = imult3216( bit_rate_diff_fx, sub( LRTD_STEREO_MID_IS_PRIM, ener_ratio_idx ) ); /*Q0*/
     213          70 :                 bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 );                                                  /*Q0*/
     214          70 :                 bit_rate_diff_fx = Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 3277 /*0.1f in Q15*/ );                /*Q0*/
     215          70 :                 if ( bit_rate_diff_fx < 0 )
     216             :                 {
     217           0 :                     bit_rate_diff_fx = L_negate( bit_rate_diff_fx );
     218             :                 }
     219             :             }
     220             :             ELSE
     221             :             {
     222          40 :                 bit_rate_diff_fx = imult3216( bit_rate_diff_fx, sub( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ); /*Q0*/
     223          40 :                 bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 );                                                  /*Q0*/
     224          40 :                 bit_rate_diff_fx = Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 3277 /*0.1f in Q15*/ );                /*Q0*/
     225          40 :                 if ( bit_rate_diff_fx < 0 )
     226             :                 {
     227           0 :                     bit_rate_diff_fx = L_negate( bit_rate_diff_fx );
     228             :                 }
     229             :             }
     230             :         }
     231             :         /*bit_rate_diff2 = ((Word16)(10.f*(-0.5f*ener_ratio_LR+0.5f)*bit_rate_diff)/100)*100;*/
     232        3679 :         Word32 temp = imult3216( Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 328 /*0.01f in Q15*/ ), 100 ); /*Q0*/
     233        3679 :         if ( bit_rate_diff_fx < 0 )
     234             :         {
     235        1917 :             temp = L_negate( temp );
     236             :         }
     237        3679 :         *total_brate_sec = L_add( *total_brate_sec, temp ); /*Q0*/
     238        3679 :         move32();
     239             : 
     240        3679 :         *total_brate_sec = L_max( *total_brate_sec, tdm_bit_allc_tbl[idx][coder_type] ); /*Q0*/
     241        3679 :         move32();
     242             : 
     243        3679 :         test();
     244        3679 :         IF( ( coder_type == INACTIVE ) && tdm_LRTD_flag == 0 )
     245             :         {
     246           0 :             *total_brate_sec = L_min( *total_brate_sec, MIN_BRATE_SWB_BWE ); /*Q0*/
     247           0 :             move32();
     248             :         }
     249             : 
     250        3679 :         test();
     251        3679 :         test();
     252        3679 :         IF( ( LE_16( ener_ratio_idx, 1 ) || GE_16( ener_ratio_idx, 29 ) ) && GE_16( coder_type, UNVOICED ) )
     253        3615 :         {
     254        3615 :             Word16 delta_brate = 0;
     255        3615 :             move16();
     256             : 
     257        3615 :             IF( GT_16( bwidth_pri, WB ) )
     258             :             {
     259        2835 :                 delta_brate = 600; /* To slightly compensate for SWB BWE instead of WB BWE Q0*/
     260        2835 :                 move16();
     261        2835 :                 if ( LE_32( element_brate_wo_meta, IVAS_16k4 ) )
     262             :                 {
     263         439 :                     delta_brate = 1250; /* To compensate for SWB BWE instead of WB BWE Q0*/
     264         439 :                     move16();
     265             :                 }
     266             :             }
     267             : 
     268        3615 :             IF( LE_32( element_brate_wo_meta, IVAS_13k2 ) )
     269             :             {
     270           0 :                 *total_brate_sec = L_max( *total_brate_sec, add( 5600, delta_brate ) ); /* ~42-47 % of the total bitrate */
     271           0 :                 move32();
     272             :             }
     273        3615 :             ELSE IF( LE_32( element_brate_wo_meta, IVAS_16k4 ) )
     274             :             {
     275         540 :                 *total_brate_sec = L_max( *total_brate_sec, add( 6500, delta_brate ) ); /* ~40-43 % of the total bitrate Q0*/
     276         540 :                 move32();
     277             :             }
     278        3075 :             ELSE IF( LE_32( element_brate_wo_meta, IVAS_24k4 ) )
     279             :             {
     280        1096 :                 *total_brate_sec = L_max( *total_brate_sec, add( 9000, delta_brate ) ); /* ~37-39 % of the total bitrate Q0*/
     281        1096 :                 move32();
     282             :             }
     283             :             ELSE
     284             :             {
     285        1979 :                 *total_brate_sec = L_max( *total_brate_sec, add( 9600, delta_brate ) ); /* ~30-32% of the total bitrate Q0*/
     286        1979 :                 move32();
     287             :             }
     288             :         }
     289             :         ELSE
     290             :         {
     291          64 :             *total_brate_sec = L_min( *total_brate_sec, Mpy_32_32( 9663677 /*0.0045f in Q31*/, element_brate_wo_meta ) * 100 ); /*Q0*/
     292          64 :             move32();
     293             :         }
     294             : 
     295        3679 :         *total_brate_sec = L_min( *total_brate_sec, 18000 ); /*Q0*/
     296        3679 :         move32();
     297             :     }
     298          16 :     ELSE IF( EQ_16( coder_type, UNVOICED ) )
     299             :     {
     300          16 :         IF( tdm_lp_reuse_flag == 0 )
     301             :         {
     302           8 :             *total_brate_sec = L_add( *total_brate_sec, imult3216( FRAMES_PER_SEC, 36 ) ); /*Q0*/
     303           8 :             move32();
     304             :         }
     305             :     }
     306             : 
     307        3695 :     IF( LE_16( coder_type, UNVOICED ) )
     308             :     {
     309          95 :         *total_brate_sec = L_min( *total_brate_sec, MAX_TDM_UC_BRATE ); /*Q0*/
     310          95 :         move32();
     311             : 
     312          95 :         test();
     313          95 :         test();
     314          95 :         test();
     315          95 :         test();
     316          95 :         test();
     317          95 :         IF( GE_32( *total_brate_sec, TDM_UC_NORMAL_MODE_MBRATE ) && tdm_lp_reuse_flag == 0 )
     318             :         {
     319          68 :             *tdm_low_rate_mode = 0;
     320          68 :             move16();
     321             :         }
     322          27 :         ELSE IF( GE_32( *total_brate_sec, TDM_UC_NORMAL_MODE_MBRATE_LP_R ) )
     323             :         {
     324           0 :             *tdm_low_rate_mode = 0;
     325           0 :             move16();
     326             :         }
     327          27 :         ELSE IF( ( tdm_lp_reuse_flag == 0 && LT_32( *total_brate_sec, TDM_UC_NORMAL_MODE_MINBR_LP_R ) && EQ_16( coder_type, UNVOICED ) ) || ( tdm_lp_reuse_flag == 0 && LE_32( *total_brate_sec, L_deposit_l( add( tdm_bit_allc_tbl[idx][0], MID_LP_BRATE ) ) ) ) )
     328             :         {
     329           8 :             *total_brate_sec = L_add( *total_brate_sec, MID_LP_BRATE ); /*Q0*/
     330           8 :             move32();
     331             :         }
     332             :     }
     333             : 
     334             :     /* verify that primary channel bitrate is higher than the minimum supported bitrate */
     335        3695 :     IF( flag_ACELP16k_pri )
     336             :     {
     337        2044 :         BWE_brate = SWB_TBE_1k75;
     338        2044 :         move32();
     339             : 
     340        2044 :         test();
     341        2044 :         test();
     342        2044 :         if ( LT_32( element_brate_wo_meta, IVAS_24k4 ) )
     343             :         {
     344           0 :             BWE_brate = SWB_TBE_1k10;
     345           0 :             move32();
     346             :         }
     347             : 
     348        2044 :         test();
     349        2044 :         if ( GT_16( bwidth_pri, WB ) && tdm_LRTD_flag == 0 )
     350             :         {
     351          91 :             BWE_brate = L_add( BWE_brate, ( STEREO_BITS_ICBWE + STEREO_ICBWE_MSFLAG_BITS ) * FRAMES_PER_SEC );
     352             :         }
     353        2044 :         test();
     354        2044 :         if ( GT_16( bwidth_pri, SWB ) && EQ_16( tdm_LRTD_flag, 1 ) )
     355             :         {
     356         702 :             BWE_brate = L_add( BWE_brate, 300 );
     357             :         }
     358             : 
     359        2044 :         if ( EQ_16( bwidth_pri, FB ) )
     360             :         {
     361         714 :             BWE_brate = L_add( BWE_brate, ( FB_TBE_1k8 - SWB_TBE_1k75 ) );
     362             :         }
     363             : 
     364        2044 :         IF( LT_32( ( L_sub( ( L_sub( element_brate_wo_meta, *total_brate_sec ) ), BWE_brate ) ), 14000 ) )
     365             :         {
     366         920 :             *total_brate_sec = L_sub( element_brate_wo_meta, L_add( 14000, BWE_brate ) ); /*Q0*/
     367         920 :             move32();
     368             :         }
     369             :     }
     370             :     ELSE
     371             :     {
     372        1651 :         BWE_brate = SWB_TBE_1k75;
     373        1651 :         move32();
     374        1651 :         IF( EQ_16( bwidth_pri, WB ) )
     375             :         {
     376         416 :             BWE_brate = WB_BWE_0k35;
     377         416 :             move32();
     378         416 :             if ( tdm_LRTD_flag == 0 )
     379             :             {
     380           3 :                 BWE_brate = L_add( BWE_brate, 250 ); /* ICA Brate Q0*/
     381             :             }
     382             :         }
     383        1235 :         ELSE IF( tdm_LRTD_flag == 0 )
     384             :         {
     385          12 :             BWE_brate = L_add( BWE_brate, 350 ); /* ICA Brate Q0*/
     386             :         }
     387             :     }
     388             : 
     389        3695 :     IF( EQ_16( coder_type0, TRANSITION ) )
     390             :     {
     391          22 :         IF( GT_32( element_brate_wo_meta, IVAS_13k2 ) )
     392             :         {
     393          22 :             *total_brate_sec = L_min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( ACELP_8k00, BWE_brate ) ) ); /*Q0*/
     394          22 :             move32();
     395             :         }
     396             :         ELSE
     397             :         {
     398           0 :             *total_brate_sec = L_min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( ACELP_7k20, BWE_brate ) ) ); /*Q0*/
     399           0 :             move32();
     400             :         }
     401             :     }
     402             :     ELSE
     403             :     {
     404        3673 :         *total_brate_sec = L_min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( 5900, BWE_brate ) ) ); /*Q0*/
     405        3673 :         move32();
     406             :     }
     407             : 
     408        3695 :     IF( coder_type == INACTIVE )
     409             :     {
     410           0 :         *total_brate_sec = L_max( *total_brate_sec, tdm_bit_allc_tbl[0][0] ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs Q0*/
     411           0 :         move32();
     412             :     }
     413             :     ELSE
     414             :     {
     415        3695 :         *total_brate_sec = L_max( *total_brate_sec, 3500 ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs Q0*/
     416        3695 :         move32();
     417             :     }
     418             : 
     419             :     /* Secondary channel bitrate adjusment                                                      */
     420             :     /* First, adjust the bitrate depending of what is transmitted                               */
     421             :     /* Second, choose the number of subframe for ACELP core depending of the targetted bitratre */
     422             :     /* Finally, verify that the concordance between the number of subframe, the parameters sent and the bitrate available */
     423        3695 :     IF( EQ_16( coder_type, GENERIC ) /* || coder_type == AUDIO*/ )
     424             :     {
     425             :         /* Adjust the bitrate depending of what is transmitted */
     426             :         /* IF LPC are transmitted, ensure enough bits are used */
     427        3600 :         IF( tdm_lp_reuse_flag == 0 )
     428             :         {
     429             :             /* Pitch is transmitted as well, further increase the bitrate */
     430        3467 :             IF( tdm_Pitch_reuse_flag == 0 )
     431             :             {
     432        3434 :                 *total_brate_sec = L_max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); /*Q0*/
     433        3434 :                 move32();
     434             : 
     435        3434 :                 test();
     436        3434 :                 IF( EQ_16( tdm_LRTD_flag, 1 ) && EQ_16( bwidth_sec, SWB ) )
     437             :                 {
     438             :                     /* ensure that there are enough bits to code SWB TBE_1k10 as well */
     439        1936 :                     *total_brate_sec = L_max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE + SWB_TBE_1k10 ); /*Q0*/
     440        1936 :                     move32();
     441             :                 }
     442             :             }
     443             :             ELSE /* only LPC is tranmitted -> IF ( *total_brate_sec  < MIN_SEC_BRATE+MIN_SEC_LPC_RATE ) */
     444             :             {
     445          33 :                 *total_brate_sec = L_max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); /*Q0*/
     446          33 :                 move32();
     447             :             }
     448             :         }
     449         133 :         ELSE IF( /*tdm_lp_reuse_flag == 1*/ tdm_Pitch_reuse_flag == 0 )
     450             :         {
     451         133 :             *total_brate_sec = L_max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SIGN_RATE ); /*Q0*/
     452         133 :             move32();
     453             :         }
     454             : 
     455             :         /* Choose between 2 and 4 subfr, depending of the bitrate available and prevent the gap between the 2 atlernative */
     456        3600 :         IF( EQ_16( tdm_LRTD_flag, 1 ) )
     457             :         {
     458        3490 :             four_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); /*Q0*/
     459        3490 :             two_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) );  /*Q0*/
     460             :         }
     461             :         ELSE
     462             :         {
     463         110 :             four_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); /*Q0*/
     464         110 :             two_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) );  /*Q0*/
     465             :         }
     466             : 
     467        3600 :         IF( tdm_lp_reuse_flag == 0 )
     468             :         {
     469        3467 :             four_subfr_fcb = sub( four_subfr_fcb, MIN_SEC_LPC_RATE ); /*Q0*/
     470        3467 :             two_subfr_fcb = sub( two_subfr_fcb, MIN_SEC_LPC_RATE );   /*Q0*/
     471             :         }
     472             : 
     473        3600 :         IF( tdm_Pitch_reuse_flag == 0 )
     474             :         {
     475        3567 :             four_subfr_fcb = sub( four_subfr_fcb, ( MIN_SEC_ACB_RATE + 10 * FRAMES_PER_SEC ) ); /*Q0*/
     476        3567 :             two_subfr_fcb = sub( two_subfr_fcb, MIN_SEC_ACB_RATE );                             /*Q0*/
     477             :         }
     478             : 
     479             :         /* Too much bits for the 2 subfr model but not enough for the the 4 subfr model -> slightly reduce the 2nd channel bitrate */
     480        3600 :         test();
     481        3600 :         IF( GT_16( two_subfr_fcb, 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC ) && LT_16( four_subfr_fcb, MIN_4SUBFR_FCB_RATE * FRAMES_PER_SEC ) )
     482             :         {
     483           0 :             IF( EQ_16( tdm_LRTD_flag, 1 ) )
     484             :             {
     485           0 :                 *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; /*Q0*/
     486           0 :                 move32();
     487             :             }
     488             :             ELSE
     489             :             {
     490           0 :                 *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; /*Q0*/
     491           0 :                 move32();
     492             :             }
     493             : 
     494           0 :             IF( tdm_lp_reuse_flag == 0 )
     495             :             {
     496           0 :                 *total_brate_sec = L_add( *total_brate_sec, MIN_SEC_LPC_RATE ); /*Q0*/
     497           0 :                 move32();
     498             :             }
     499             : 
     500           0 :             IF( tdm_Pitch_reuse_flag == 0 )
     501             :             {
     502           0 :                 *total_brate_sec = L_add( *total_brate_sec, MIN_SEC_ACB_RATE ); /*Q0*/
     503           0 :                 move32();
     504             :             }
     505             :         }
     506        3600 :         ELSE IF( GE_16( four_subfr_fcb, 40 * FRAMES_PER_SEC ) ) /* Enough bits to have minimally 2 x 12 + 2*7 bits FCB  */
     507             :         {
     508        3600 :             *tdm_low_rate_mode = 0; /* Use normal rate mode */
     509        3600 :             move16();
     510             :         }
     511             :         ELSE /* Possible slight increase of secondary channel bit budget to compensate for FCB limited flexibility */
     512             :         {
     513             :             Word16 tmp_rate, i;
     514           0 :             tmp_rate = two_subfr_fcb; /*Q0*/
     515           0 :             move16();
     516           0 :             idx = sub( NB_RATE_POSS, 2 );
     517             : 
     518           0 :             FOR( i = 0; i < NB_RATE_POSS; i++ ){
     519           0 :                 IF( LE_16( tmp_rate, fast_FCB_rates_2sfr[i] ) ){
     520           0 :                     idx = i;
     521           0 :             move16();
     522           0 :             BREAK;
     523             :         }
     524             :     }
     525           0 :     *total_brate_sec = L_add( *total_brate_sec, sub( fast_FCB_rates_2sfr[idx], tmp_rate ) ); /*Q0*/
     526           0 :     move32();
     527             : }
     528             : /* To prevent 13.2 kb/s for primary channel as some bitstream issues arrise with it */
     529        3600 : IF( EQ_32( L_sub( element_brate_wo_meta, *total_brate_sec ), ACELP_13k20 ) )
     530             : {
     531           0 :     *total_brate_sec = L_add( *total_brate_sec, 100 ); /*Q0*/
     532           0 :     move32();
     533             : }
     534             : }
     535             : /* prevent 2.4 kb/s and 2.8 kb/s as they are reserved bitrates for DTX and VBR */
     536        3695 : test();
     537        3695 : IF( EQ_32( *total_brate_sec, PPP_NELP_2k80 ) || EQ_32( *total_brate_sec, SID_2k40 ) )
     538             : {
     539           0 :     *total_brate_sec = L_sub( *total_brate_sec, 100 ); /*Q0*/
     540           0 :     move32();
     541             : }
     542             : 
     543        3695 : *total_brate_pri = L_sub( element_brate_wo_meta, *total_brate_sec ); /*Q0*/
     544        3695 : move32();
     545             : 
     546        3695 : return;
     547             : }
     548             : /*-------------------------------------------------------------------*
     549             :  * td_stereo_param_updt()
     550             :  *
     551             :  * copy certain TD stereo parameters from primary channel to secondary channel
     552             :  *-------------------------------------------------------------------*/
     553        3751 : void td_stereo_param_updt_fx(
     554             :     const Word16 lsp_old_PCh_fx[],    /* i  : primary channel old LSPs                                     Q15 */
     555             :     const Word16 lsf_old_PCh_fx[],    /* i  : primary channel old LSFs                             Qlog2(2.56) */
     556             :     const Word16 pitch_buf_PCh_fx[],  /* i  : primary channel pitch buffer                                  Q6 */
     557             :     Word16 tdm_lspQ_PCh_fx[],         /* o  : Q LSPs for primary channel                                   Q15 */
     558             :     Word16 tdm_lsfQ_PCh_fx[],         /* o  : Q LSFs for primary channel                           Qlog2(2.56) */
     559             :     Word16 tdm_Pri_pitch_buf_fx[],    /* o  : pitch values for primary channel                              Q6 */
     560             :     const Word16 flag_ACELP16k,       /* i  : ACELP@16kHz flag                                                 Q0*/
     561             :     const Word16 tdm_use_IAWB_Ave_lpc /* i  : flag to indicate the usage of mean inactive LP coefficients      Q0*/
     562             : )
     563             : {
     564             :     Word16 i;
     565             :     /* Copy some primary channel information into the secondary channel structure for later usage */
     566        3751 :     IF( EQ_16( tdm_use_IAWB_Ave_lpc, 1 ) )
     567             :     {
     568             :         /*not being assert*/
     569           0 :         Copy( IAWB_Ave_fx, tdm_lsfQ_PCh_fx, M ); /*Qlog2(2.56)*/
     570           0 :         lsf2lsp_fx( tdm_lsfQ_PCh_fx, tdm_lspQ_PCh_fx, M, INT_FS_12k8 );
     571             :     }
     572        3751 :     ELSE IF( EQ_16( flag_ACELP16k, 1 ) )
     573             :     {
     574        2082 :         Copy( lsp_old_PCh_fx, tdm_lspQ_PCh_fx, M ); /*Q15*/
     575        2082 :         lsp_convert_poly_fx( tdm_lspQ_PCh_fx, L_FRAME, 0 );
     576        2082 :         lsp2lsf_fx( tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, M, INT_FS_12k8 );
     577             :     }
     578             :     ELSE
     579             :     {
     580        1669 :         Copy( lsp_old_PCh_fx, tdm_lspQ_PCh_fx, M ); /*Q15*/
     581        1669 :         Copy( lsf_old_PCh_fx, tdm_lsfQ_PCh_fx, M ); /*Qlog2(2.56)*/
     582             :     }
     583        3751 :     IF( EQ_16( flag_ACELP16k, 1 ) )
     584             :     {
     585             :         Word16 tmp16;
     586        2082 :         Word16 mult_factor = 26214 /*0.8f in Q15*/;
     587        2082 :         move16();
     588       10410 :         FOR( i = 0; i < NB_SUBFR; i++ )
     589             :         {
     590        8328 :             tmp16 = mult_r( pitch_buf_PCh_fx[i], mult_factor );          /* Convert 16kHz to 12.8 kHz pitch values Q6*/
     591        8328 :             tdm_Pri_pitch_buf_fx[i] = s_max( tmp16, shl( PIT_MIN, 6 ) ); /* pitch is represented in Q6*/
     592        8328 :             move16();
     593             :         }
     594             :     }
     595             :     ELSE
     596             :     {
     597        1669 :         Copy( pitch_buf_PCh_fx, tdm_Pri_pitch_buf_fx, NB_SUBFR ); /*Q6*/
     598             :     }
     599             : 
     600        3751 :     return;
     601             : }
     602             : 
     603             : /*-------------------------------------------------------------------*
     604             :  * tdm_SCh_LSF_intra_pred_zero_bits_fx()
     605             :  *
     606             :  *
     607             :  *-------------------------------------------------------------------*/
     608             : 
     609         110 : static void tdm_SCh_LSF_intra_pred_zero_bits_fx(
     610             :     const Word16 *tdm_lsfQ_PCh_fx, /* i  : primary channel LSFs             x2.56*/
     611             :     Word16 *pred_lsf_SCh_fx,       /* o  : predicted secondary channel LSFs x2.56*/
     612             :     const Word16 *lsf_mean_fx,     /* i  : secondary channel mean LSFs      x2.56*/
     613             :     const Word16 beta_fx           /* i  : pull to average beta factor      Q15*/
     614             : )
     615             : {
     616             :     Word16 i;
     617             :     /* pulling the LSFs closer to the average */
     618        1870 :     FOR( i = 0; i < M; i++ )
     619             :     {
     620        1760 :         pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r( sub( 32767 /*1.0f in Q15*/, beta_fx ), lsf_mean_fx[i] ) );
     621        1760 :         move16();
     622             :     }
     623             : 
     624         110 :     return;
     625             : }
     626             : 
     627             : /*-------------------------------------------------------------------*
     628             :  * tdm_SCh_LSF_intra_pred_tri_diag_mat_fx()
     629             :  *
     630             :  *
     631             :  *-------------------------------------------------------------------*/
     632             : 
     633         251 : static void tdm_SCh_LSF_intra_pred_tri_diag_mat_fx(
     634             :     Word16 *lsf_SCh_fx,            /* i/o: secondary channel LSFs               x2.56*/
     635             :     const Word16 *lsf_mean_in_fx,  /* i  : secondary channel mean LSFs (in)     x2.56*/
     636             :     const Word16 *lsf_mean_out_fx, /* i  : secondary channel mean LSFs (out)    x2.56*/
     637             :     const Word16 *prd_diag_3_fx    /* i  : secondary channel mean LSFs          Q15*/
     638             : )
     639             : {
     640             :     Word16 i;
     641             :     Word16 lsf_tmp_fx[M];
     642             :     const Word16 *prd_ptr_fx;
     643             :     Word16 *lsf_tmp_ptr1_fx;
     644             :     Word16 *lsf_tmp_ptr2_fx;
     645             :     Word16 *lsf_SCh_ptr_fx;
     646             : 
     647         251 :     prd_ptr_fx = prd_diag_3_fx; /*Q15*/
     648             : 
     649         251 :     v_sub_16( lsf_SCh_fx, lsf_mean_in_fx, lsf_tmp_fx, M );
     650             : 
     651         251 :     lsf_tmp_ptr1_fx = lsf_tmp_fx; /*x2.56*/
     652             : 
     653         251 :     lsf_SCh_ptr_fx = lsf_SCh_fx; /*x2.56*/
     654             : 
     655             : 
     656         251 :     lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx; /*x2.56*/
     657             : 
     658         251 :     *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); // Q2.56 + 15 -15
     659         251 :     move16();
     660         251 :     *lsf_SCh_ptr_fx = add( *lsf_SCh_ptr_fx, mult_r( *lsf_tmp_ptr1_fx, *prd_ptr_fx++ ) ); // Q2.56 + 15 -15
     661         251 :     move16();
     662         251 :     lsf_SCh_ptr_fx++;
     663             : 
     664        3765 :     FOR( i = 1; i < M - 1; i++ )
     665             :     {
     666        3514 :         lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx;                             // Q2.56
     667        3514 :         *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); // Q2.56 + 15 -15
     668        3514 :         move16();
     669        3514 :         lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx;                                                             /*x2.56*/
     670        3514 :         *lsf_SCh_ptr_fx = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx++ ), ( *prd_ptr_fx++ ) ) ); /*x2.56*/
     671        3514 :         move16();
     672        3514 :         ( *lsf_SCh_ptr_fx ) = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx++ ) ) ); /*x2.56*/
     673        3514 :         move16();
     674        3514 :         lsf_SCh_ptr_fx++;
     675             :     }
     676             : 
     677         251 :     lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx;                                 /*x2.56*/
     678         251 :     *lsf_SCh_ptr_fx = mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx ) ); /*x2.56*/
     679         251 :     move16();
     680         251 :     lsf_tmp_ptr1_fx++;
     681         251 :     prd_ptr_fx++;
     682         251 :     *lsf_SCh_ptr_fx = add( mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx ) ), *lsf_SCh_ptr_fx ); /*x2.56*/
     683         251 :     move16();
     684             : 
     685         251 :     v_add_16( lsf_SCh_fx, lsf_mean_out_fx, lsf_SCh_fx, M ); /*x2.56*/
     686             : 
     687         251 :     return;
     688             : }
     689             : 
     690             : /*-------------------------------------------------------------------*
     691             :  * tdm_SCh_LSF_intra_pred_fx()
     692             :  *
     693             :  *
     694             :  *-------------------------------------------------------------------*/
     695             : 
     696         110 : void tdm_SCh_LSF_intra_pred_fx(
     697             :     const Word32 element_brate,    /* i  : element bitrate                  Q0*/
     698             :     const Word16 *tdm_lsfQ_PCh_fx, /* i  : primary channel LSFs             x2.56*/
     699             :     Word16 *pred_lsf_SCh_fx        /* o  : predicted secondary channel LSFs x2.56*/
     700             : )
     701             : {
     702             :     Word16 fixed_beta;
     703             : 
     704         110 :     IF( LE_32( element_brate, IVAS_13k2 ) )
     705             :     {
     706           0 :         fixed_beta = 28508; // 0.87f in Q15
     707           0 :         move16();
     708             :     }
     709         110 :     ELSE IF( LE_32( element_brate, IVAS_16k4 ) )
     710             :     {
     711          15 :         fixed_beta = 30801; // 0.94f in Q15
     712          15 :         move16();
     713             :     }
     714          95 :     ELSE IF( element_brate <= IVAS_24k4 )
     715             :     {
     716          14 :         fixed_beta = 29818; // 0.91f in Q15
     717          14 :         move16();
     718             :     }
     719          81 :     ELSE IF( LE_32( element_brate, IVAS_32k ) )
     720             :     {
     721          81 :         fixed_beta = 30146; // 0.92f in Q15
     722          81 :         move16();
     723             :     }
     724             :     ELSE
     725             :     {
     726           0 :         fixed_beta = 29818; // 0.91f in Q15
     727           0 :         move16();
     728             :     }
     729             : 
     730         110 :     tdm_SCh_LSF_intra_pred_zero_bits_fx( tdm_lsfQ_PCh_fx, pred_lsf_SCh_fx, tdm_LSF_MEAN_PRED_QNT_fx, fixed_beta );
     731             : 
     732         110 :     tdm_SCh_LSF_intra_pred_tri_diag_mat_fx( pred_lsf_SCh_fx, tdm_LSF_MEAN_PRED_QNT_IN_fx, tdm_LSF_MEAN_PRED_QNT_OUT_fx, tdm_PRED_QNT_fixed_beta_prd_diag_3_fx );
     733             : 
     734         110 :     return;
     735             : }
     736             : 
     737             : /*-------------------------------------------------------------------*
     738             :  * tdm_SCh_LSF_intra_pred_one_bit_dec_fx()
     739             :  *
     740             :  *
     741             :  *-------------------------------------------------------------------*/
     742             : 
     743         141 : static void tdm_SCh_LSF_intra_pred_one_bit_dec_fx(
     744             :     const Word16 *tdm_lsfQ_PCh_fx, /* i  : primary channel LSFs                              x2.56*/
     745             :     Word16 *pred_lsf_SCh_fx,       /* o  : predicted secondary channel LSFs                  x2.56*/
     746             :     const Word16 *lsf_mean_fx,     /* i  : secondary channel mean LSFs                       x2.56*/
     747             :     const Word16 *Beta_Q_x_fx,     /* i  : beta quantization values                          Q15*/
     748             :     const Word16 beta_index_fx     /* i  : the quantization bits for beta (-1 if beta fixed) Q0*/
     749             : )
     750             : {
     751             :     Word16 i;
     752             :     Word16 beta_fx;
     753             : 
     754         141 :     beta_fx = Beta_Q_x_fx[beta_index_fx]; // Q15
     755         141 :     move16();
     756             : 
     757             :     /* pulling the LSFs closer to the avergae */
     758        2397 :     FOR( i = 0; i < M; i++ )
     759             :     {
     760        2256 :         pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r( sub( 32767 /*1.0f in Q15*/, beta_fx ), lsf_mean_fx[i] ) ); /*x2.56*/
     761        2256 :         move16();
     762             :     }
     763             : 
     764         141 :     return;
     765             : }
     766             : 
     767             : /*-------------------------------------------------------------------*
     768             :  * tdm_SCh_LSF_intra_pred_one_bit_enc_fx()
     769             :  *
     770             :  *
     771             :  *-------------------------------------------------------------------*/
     772             : 
     773           0 : static void tdm_SCh_LSF_intra_pred_one_bit_enc_fx(
     774             :     const Word16 *lsf_SCh_fx,      /* i  : secondary channel LSFs                              x2.56*/
     775             :     const Word16 *tdm_lsfQ_PCh_fx, /* i  : primary channel LSFs                                x2.56*/
     776             :     Word16 *pred_lsf_SCh_fx,       /* o  : predicted secondary channel LSFs                    x2.56*/
     777             :     const Word16 *lsf_mean_fx,     /* i  : secondary channel mean LSFs                         x2.56*/
     778             :     const Word16 *lsf_wgts_new_fx, /* i  : Improved wgts for LSFs                              Q8*/
     779             :     const Word16 *Beta_Q_x_fx,     /* i  : beta quantization values                            Q15*/
     780             :     Word16 *beta_index             /* o  : the quantization bits for beta (-1 if beta fixed)   Q0*/
     781             : )
     782             : {
     783             :     Word16 i;
     784             : 
     785             :     Word16 A_temp_fx[M];
     786             :     Word16 B_temp_fx[M];
     787           0 :     Word32 WD_fx[2] = { 0 };
     788           0 :     move32();
     789           0 :     move32();
     790             : 
     791           0 :     FOR( i = 0; i < M; i++ )
     792             :     {
     793           0 :         A_temp_fx[i] = sub( lsf_SCh_fx[i], lsf_mean_fx[i] ); /*x2.56*/
     794           0 :         move16();
     795           0 :         B_temp_fx[i] = sub( lsf_mean_fx[i], tdm_lsfQ_PCh_fx[i] ); /*x2.56*/
     796           0 :         move16();
     797             :     }
     798             : 
     799           0 :     FOR( i = 0; i < M; i++ )
     800             :     {
     801           0 :         Word32 wgt_A_temp = Mpy_32_16_1( L_mult( A_temp_fx[i], A_temp_fx[i] ), lsf_wgts_new_fx[i] );  /*2*(x2.56)-7*/
     802           0 :         Word32 wgt_B_temp = Mpy_32_16_1( L_mult( B_temp_fx[i], B_temp_fx[i] ), lsf_wgts_new_fx[i] );  /*2*(x2.56)-7*/
     803           0 :         Word32 wgt_AB_temp = Mpy_32_16_1( L_mult( A_temp_fx[i], B_temp_fx[i] ), lsf_wgts_new_fx[i] ); /*2*(x2.56)-7*/
     804           0 :         Word32 Beta_Q_x0 = L_mult( Beta_Q_x_fx[0], Beta_Q_x_fx[0] );                                  // Q31
     805           0 :         Word32 Beta_Q_x1 = L_mult( Beta_Q_x_fx[1], Beta_Q_x_fx[1] );                                  // Q31
     806             : 
     807           0 :         WD_fx[0] = L_add( WD_fx[0], L_add( L_add( wgt_A_temp, Mpy_32_16_1( L_shl( wgt_AB_temp, 1 ), Beta_Q_x_fx[0] ) ), Mpy_32_32( wgt_B_temp, Beta_Q_x0 ) ) ); /*2*(x2.56)-7*/
     808           0 :         move32();
     809           0 :         WD_fx[1] = L_add( WD_fx[1], L_add( L_add( wgt_A_temp, Mpy_32_16_1( L_shl( wgt_AB_temp, 1 ), Beta_Q_x_fx[1] ) ), Mpy_32_32( wgt_B_temp, Beta_Q_x1 ) ) ); /*2*(x2.56)-7*/
     810           0 :         move32();
     811             :     }
     812             : 
     813           0 :     IF( LT_32( WD_fx[0], WD_fx[1] ) )
     814             :     {
     815           0 :         *beta_index = 0;
     816           0 :         move16();
     817             :     }
     818             :     ELSE
     819             :     {
     820           0 :         *beta_index = 1;
     821           0 :         move16();
     822             :     }
     823             : 
     824           0 :     tdm_SCh_LSF_intra_pred_one_bit_dec_fx( tdm_lsfQ_PCh_fx, pred_lsf_SCh_fx, tdm_LSF_MEAN_RE_USE_fx, Beta_Q_x_fx, *beta_index );
     825             : 
     826           0 :     return;
     827             : }
     828             : 
     829             : /*-------------------------------------------------------------------*
     830             :  * tdm_SCh_lsf_reuse_fx()
     831             :  *
     832             :  *
     833             :  *-------------------------------------------------------------------*/
     834             : 
     835         141 : void tdm_SCh_lsf_reuse_fx(
     836             :     const Word16 enc_dec,            /* i  : encoder/decoder flag                Q0*/
     837             :     const Word32 element_brate,      /* i  : element bitrate                     Q0*/
     838             :     Word16 lsf_new_fx[M],            /* i/o: LSFs at the end of the frame        x2.56*/
     839             :     Word16 lsp_new_fx[M],            /* i/o: LSPs at the end of the frame        Q15*/
     840             :     const Word16 tdm_lsfQ_PCh_fx[M], /* i  : primary channel LSFs                x2.56*/
     841             :     const Word16 lsf_wgts_fx[M],     /* i  : LSF weights                         Q8*/
     842             :     Word16 *beta_index               /* i/o: quantization index                  Q0*/
     843             : )
     844             : {
     845             :     const Word16 *Beta_Q1bit_re_use_fx;
     846             : 
     847         141 :     IF( LE_32( element_brate, IVAS_13k2 ) )
     848             :     {
     849           0 :         Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_13k2_fx; /*Q15*/
     850             :     }
     851         141 :     ELSE IF( LE_32( element_brate, IVAS_16k4 ) )
     852             :     {
     853          11 :         Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_16k4_fx; /*Q15*/
     854             :     }
     855         130 :     ELSE IF( LE_32( element_brate, IVAS_32k ) )
     856             :     {
     857         130 :         Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_24k4_32k_fx; /*Q15*/
     858             :     }
     859             :     ELSE
     860             :     {
     861           0 :         Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_48k_fx; /*Q15*/
     862             :     }
     863             : 
     864         141 :     IF( enc_dec == ENC )
     865             :     {
     866           0 :         tdm_SCh_LSF_intra_pred_one_bit_enc_fx( lsf_new_fx, tdm_lsfQ_PCh_fx, lsf_new_fx, tdm_LSF_MEAN_RE_USE_fx, lsf_wgts_fx, Beta_Q1bit_re_use_fx, beta_index );
     867             :     }
     868             :     ELSE /* DEC */
     869             :     {
     870         141 :         tdm_SCh_LSF_intra_pred_one_bit_dec_fx( tdm_lsfQ_PCh_fx, lsf_new_fx, tdm_LSF_MEAN_RE_USE_fx, Beta_Q1bit_re_use_fx, *beta_index );
     871             :     }
     872             : 
     873         141 :     tdm_SCh_LSF_intra_pred_tri_diag_mat_fx( lsf_new_fx, tdm_LSF_MEAN_RE_USE_IN_fx, tdm_LSF_MEAN_RE_USE_OUT_fx, tdm_RE_USE_adaptive_beta_prd_diag_3_fx );
     874             : 
     875         141 :     lsf2lsp_fx( lsf_new_fx, lsp_new_fx, M, INT_FS_12k8 );
     876             : 
     877         141 :     return;
     878             : }

Generated by: LCOV version 1.14