LCOV - code coverage report
Current view: top level - lib_dec - lsf_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 365 401 91.0 %
Date: 2025-05-17 01:59:02 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <stdint.h>
       6             : #include "options.h" /* Compilation switches                   */
       7             : #include "cnst.h"    /* Common constants                       */
       8             : #include "rom_com.h" /* Static table prototypes                */
       9             : #include "prot_fx.h" /* Function prototypes                    */
      10             : #include "ivas_prot_fx.h"
      11             : 
      12             : /*-------------------------------------------------------------------*
      13             :  * Local functions
      14             :  *-------------------------------------------------------------------*/
      15             : 
      16             : static void dqlsf_CNG_fx( Decoder_State *st_fx, Word16 *lsf_q );
      17             : 
      18             : /*--------------------------------------------------------------------------------------*
      19             : * dqlsf_CNG_fx()
      20             : *
      21             : * LSF de-quantizer for SID frames (uses 28 bits, 4 for VQ, 24 for LVQ)
      22             : *
      23             : * Note:
      24             : * LP-CNG LSF decoder does not need to know the sampling rate,
      25             : * the sampling rate data is embedded inside the LSF coefficients.
      26             : * If the highest order LSF coefficient (lsf_q[M-1]) is smaller than 6350 then Fs=12.8kHz
      27             : * If the highest order LSF coefficient (lsf_q[M-1]) is larger than 6350 then Fs=16kHz
      28             : ----------------------------------------------------------------------------------------*/
      29             : 
      30         417 : static void dqlsf_CNG_fx(
      31             :     Decoder_State *st_fx, /* i/o: decoder state structure            */
      32             :     Word16 *lsf_q         /* o  : decoded LSFs                     Q9*/
      33             : )
      34             : {
      35             :     Word16 indice[4];
      36             :     Word16 ber_flag;
      37             : 
      38         417 :     indice[0] = (Word16) get_next_indice_fx( st_fx, 4 ); /* Q0 */
      39         417 :     move16();
      40         417 :     indice[1] = (Word16) get_next_indice_fx( st_fx, LEN_INDICE ); /* Q0 */
      41         417 :     move16();
      42         417 :     indice[2] = (Word16) get_next_indice_fx( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); /* Q0 */
      43         417 :     move16();
      44             : 
      45             :     /* deindex_lvq_cng decoder does not need to know the sampling rate, the sampling rate data is embedded inside the LSF coefficients */
      46         417 :     IF( st_fx->element_mode == EVS_MONO )
      47             :     {
      48             :         ber_flag =
      49           0 :             deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4, &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->no_scales_fx[0][0] ); /* Q0 */
      50             :     }
      51             :     ELSE
      52             :     {
      53             :         ber_flag =
      54         417 :             deindex_lvq_cng_ivas_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4 ); /* Q0 */
      55             :     }
      56         417 :     st_fx->BER_detect = s_or( ber_flag, st_fx->BER_detect ); /* Q0 */
      57         417 :     move16();
      58             : 
      59             :     /* The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF coefficient (last coefficient).
      60             :        If the last decoded LSF coefficient is larger than 6350 the decoded frame is WB2 with sampling rate of 16 kHz
      61             :        otherwise it is sampled at 12.8kHz and contains either NB or WB LSF data.  */
      62         417 :     Vr_add( lsf_q, &CNG_SN1_fx[indice[0] * M], lsf_q, M );
      63             : 
      64         417 :     test();
      65         417 :     test();
      66         417 :     test();
      67         417 :     IF( ( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( LE_16( lsf_q[M - 1], WB_LIMIT_LSF_FX ) ) ) || ( ( LT_16( st_fx->L_frame, L_FRAME16k ) ) && ( GT_16( lsf_q[M - 1], WB_LIMIT_LSF_FX ) ) ) )
      68             :     {
      69           0 :         st_fx->BER_detect = 1; /* Q0 */
      70           0 :         move16();
      71             :     }
      72             : 
      73         417 :     return;
      74             : }
      75             : 
      76             : /*===========================================================================*/
      77             : /* FUNCTION : lsf_dec_fx()                                                   */
      78             : /*---------------------------------------------------------------------------*/
      79             : /* PURPOSE : LSF decoder                                                     */
      80             : /*---------------------------------------------------------------------------*/
      81             : /* INPUT ARGUMENTS :                                                         */
      82             : /* _ (Struct) st_fx       : decoder static memory                            */
      83             : /* _ (Word16) L_frame     : length of the frame                              */
      84             : /* _ (Word16) coder_type  : coding type                                      */
      85             : /* _ (Word16) bwidth      : input signal bandwidth                           */
      86             : /*---------------------------------------------------------------------------*/
      87             : /* OUTPUT ARGUMENTS :                                                        */
      88             : /* _ (Word16*) Aq          : LP filter coefficient    Q12                    */
      89             : /* _ (Word16*) lsf_new      : LP filter coefficient    Q(x2.56)              */
      90             : /* _ (Word16*) lsp_new      : LP filter coefficient    Q15                   */
      91             : /* _ (Word16*) lsp_mid      : LP filter coefficient    Q15                   */
      92             : /*---------------------------------------------------------------------------*/
      93             : /* _ (Word16[]) st_fx->lsf_adaptive_mean_fx  : FEC - adaptive mean LSF       */
      94             : /*                        vector for FEC  Q(x2.56)                           */
      95             : /* _ (Word16[]) st_fx->mem_AR_fx : AR memory of LSF quantizer                */
      96             : /*                  (past quantized LSFs without mean) Q(x2.56)              */
      97             : /* _ (Word16) st_fx->stab_fac_fx : LSF stability factor    Q15               */
      98             : /*---------------------------------------------------------------------------*/
      99             : /* RETURN ARGUMENTS :                                                        */
     100             : /* _ None                                                                    */
     101             : /*===========================================================================*/
     102             : 
     103      140402 : void lsf_dec_fx(
     104             :     Decoder_State *st_fx,           /* i/o: State structure                               */
     105             :     const Word16 tc_subfr,          /* i  : TC subframe index                           Q0*/
     106             :     Word16 *Aq,                     /* o  : quantized A(z) for 4 subframes             Q12*/
     107             :     Word16 *LSF_Q_prediction,       /* o  : LSF prediction mode                         Q0*/
     108             :     Word16 *lsf_new,                /* o  : de-quantized LSF vector               Q(x2.56)*/
     109             :     Word16 *lsp_new,                /* o  : de-quantized LSP vector                    Q15*/
     110             :     Word16 *lsp_mid,                /* o  : de-quantized mid-frame LSP vector          Q15*/
     111             :     const Word16 tdm_low_rate_mode, /* i  : secondary channel low rate mode flag           Q0*/
     112             :     const Word16 tdm_lsfQ_PCh[M]    /* i  : Q LSFs for primary channel                                 Qx*/
     113             : )
     114             : {
     115             :     Word16 i;
     116             :     Word16 no_param_lpc;
     117             :     Word16 param_lpc[NPRM_LPC_NEW];
     118             :     Word32 L_tmp;
     119      140402 :     Word16 nBits = 0;
     120      140402 :     move16();
     121             :     Word16 tmp_old[M + 1], tmp_new[M + 1];
     122      140402 :     Word16 enr_old = 0, enr_new = 0;
     123      140402 :     move16();
     124      140402 :     move16();
     125             :     Word16 lsf_diff, coder_type;
     126             : 
     127             :     /* initialize */
     128      140402 :     coder_type = st_fx->coder_type;
     129      140402 :     if ( EQ_32( st_fx->core_brate, SID_2k40 ) )
     130             :     {
     131         417 :         coder_type = INACTIVE; /* Q0 */
     132         417 :         move16();
     133             :     }
     134      140402 :     test();
     135      140402 :     if ( EQ_16( coder_type, AUDIO ) && st_fx->GSC_IVAS_mode > 0 )
     136             :     {
     137        3893 :         coder_type = GENERIC; /* Q0 */
     138        3893 :         move16();
     139             :     }
     140      140402 :     no_param_lpc = 0;
     141      140402 :     nBits = 0;
     142      140402 :     move16();
     143      140402 :     move16();
     144             : 
     145             :     /* Find the number of bits for LSF quantization */
     146      140402 :     IF( EQ_32( st_fx->core_brate, SID_2k40 ) )
     147             :     {
     148         417 :         nBits = LSF_BITS_CNG; /* Q0 */
     149         417 :         move16();
     150             :     }
     151             :     ELSE
     152             :     {
     153      139985 :         test();
     154      139985 :         IF( st_fx->nelp_mode_dec == 0 && st_fx->ppp_mode_dec == 0 )
     155             :         {
     156      139985 :             nBits = st_fx->acelp_cfg.lsf_bits; /* Q0 */
     157      139985 :             move16();
     158             :         }
     159           0 :         ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) )
     160             :         {
     161           0 :             IF( EQ_16( coder_type, UNVOICED ) )
     162             :             {
     163           0 :                 nBits = 30; /* Q0 */
     164           0 :                 move16();
     165           0 :                 if ( st_fx->bwidth == NB )
     166             :                 {
     167           0 :                     nBits = 32; /* Q0 */
     168           0 :                     move16();
     169             :                 }
     170             :             }
     171             :         }
     172           0 :         ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) )
     173             :         {
     174           0 :             nBits = 26; /* Q0 */
     175           0 :             move16();
     176             :         }
     177             :     }
     178             : 
     179             :     /* LSF de-quantization */
     180      140402 :     lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth, nBits, lsf_new, param_lpc, LSF_Q_prediction, &no_param_lpc,
     181             :                     tdm_lsfQ_PCh );
     182             : 
     183             :     /* convert quantized LSFs to LSPs */
     184             : 
     185      140402 :     lsf2lsp_fx( lsf_new, lsp_new, M, st_fx->sr_core );
     186             :     /* set seed_acelp used in UC mode */
     187      140402 :     test();
     188      140402 :     IF( EQ_16( coder_type, UNVOICED ) && GT_16( st_fx->element_mode, EVS_MONO ) )
     189             :     {
     190        1393 :         st_fx->seed_acelp = 0;
     191        1393 :         move16();
     192        1393 :         FOR( i = no_param_lpc - 1; i >= 0; i-- )
     193             :         {
     194             :             /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/
     195           0 :             st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L /* Q0 */, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L /* Q0 */ ) ); /* Q0 */
     196           0 :             move16();
     197             :         }
     198             :     }
     199      140402 :     IF( EQ_32( st_fx->core_brate, SID_2k40 ) )
     200             :     {
     201             :         /* return if SID frame (conversion to A(z) done in the calling function) */
     202         417 :         return;
     203             :     }
     204             : 
     205             :     /*-------------------------------------------------------------------------------------*
     206             :      * FEC - update adaptive LSF mean vector
     207             :      *-------------------------------------------------------------------------------------*/
     208             : 
     209     2379745 :     FOR( i = 0; i < M; i++ )
     210             :     {
     211     2239760 :         L_tmp = L_mult( lsf_new[i], 10922 );                    /*Q(x2.56+16)*/
     212     2239760 :         L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi1_fx[i], 10922 ); /*Q(x2.56+16)*/
     213     2239760 :         L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi0_fx[i], 10922 ); /*Q(x2.56+16)*/
     214     2239760 :         st_fx->lsf_adaptive_mean_fx[i] = round_fx( L_tmp );     /*Q(x2.56)*/
     215     2239760 :         move16();
     216             :     }
     217             : 
     218      139985 :     test();
     219      139985 :     test();
     220      139985 :     IF( ( st_fx->prev_bfi && ( EQ_16( coder_type, TRANSITION ) ) && ( EQ_16( tc_subfr, sub( st_fx->L_frame, L_SUBFR ) ) ) ) )
     221             :     {
     222          18 :         lsf_diff = 1205;
     223          18 :         move16(); /*int_fs / (float)(2*(M+1)); = 470.588 -> 1205 in Q2.56 */
     224          18 :         if ( EQ_16( st_fx->L_frame, L_FRAME ) )
     225             :         {
     226          11 :             lsf_diff = 964;
     227          11 :             move16(); /*int_fs / (float)(2*(M+1)); = 376.47 -> 964 in Q2.56 */
     228             :         }
     229          18 :         st_fx->lsf_old_fx[0] = lsf_diff;
     230          18 :         move16();
     231             : 
     232         288 :         FOR( i = 1; i < M; i++ )
     233             :         {
     234         270 :             st_fx->lsf_old_fx[i] = add( st_fx->lsf_old_fx[i - 1], lsf_diff ); /* Q2.56 */
     235         270 :             move16();
     236             :         }
     237          18 :         lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, st_fx->sr_core );
     238             :     }
     239             :     /*-------------------------------------------------------------------------------------*
     240             :      * Mid-frame LSF decoding
     241             :      * LSP interpolation and conversion of LSPs to A(z)
     242             :      *-------------------------------------------------------------------------------------*/
     243      139985 :     IF( st_fx->rate_switching_reset )
     244             :     {
     245             :         /*extrapolation in case of unstable LSF convert*/
     246           0 :         Copy( lsp_new, st_fx->lsp_old_fx, M ); /* Q15 */
     247           0 :         Copy( lsf_new, st_fx->lsf_old_fx, M ); /* Q2.56 */
     248             :     }
     249             :     {
     250             :         /* Mid-frame LSF decoding */
     251      139985 :         lsf_mid_dec_fx( st_fx, lsp_new, coder_type, lsp_mid );
     252             :     }
     253      139985 :     test();
     254      139985 :     test();
     255      139985 :     IF( !( st_fx->prev_bfi && ( EQ_16( coder_type, TRANSITION ) ) && ( EQ_16( tc_subfr, sub( st_fx->L_frame, L_SUBFR ) ) ) ) )
     256             :     {
     257      139967 :         IF( st_fx->prev_bfi )
     258             :         {
     259             :             /* check, if LSP interpolation can be relaxed */
     260        1584 :             E_LPC_f_lsp_a_conversion( st_fx->lsp_old_fx, tmp_old, M );
     261        1584 :             enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); /* Q3 */
     262             : 
     263        1584 :             E_LPC_f_lsp_a_conversion( lsp_new, tmp_new, M );
     264        1584 :             enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); /* Q3 */
     265             : 
     266        1584 :             IF( LT_16( enr_new, mult_r( 9830 /*0.3 Q15*/, enr_old ) ) )
     267             :             {
     268             :                 /* OLD CODE : if( st->safety_net == 1), replaced with a decision similar to MODE2 */
     269         181 :                 st_fx->relax_prev_lsf_interp = -1;
     270         181 :                 move16();
     271         181 :                 test();
     272         181 :                 test();
     273         181 :                 test();
     274         181 :                 test();
     275         181 :                 if ( st_fx->clas_dec == UNVOICED_CLAS || EQ_16( st_fx->clas_dec, SIN_ONSET ) || st_fx->clas_dec == INACTIVE_CLAS || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) )
     276             :                 {
     277         178 :                     st_fx->relax_prev_lsf_interp = 1;
     278         178 :                     move16();
     279             :                 }
     280             :             }
     281             :         }
     282             :     }
     283      139985 :     test();
     284      139985 :     IF( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->core == ACELP_CORE )
     285             :     {
     286             :         /* update old LSPs/LSFs in case of HQ->ACELP core switching */
     287         245 :         Copy( lsp_mid, st_fx->lsp_old_fx, M );                       /* Q15 */
     288         245 :         lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */
     289             :     }
     290      139985 :     test();
     291      139985 :     IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) )
     292             :     {
     293             :         // PMT("To be verified")
     294           0 :         IF( EQ_16( st_fx->active_cnt, 1 ) )
     295             :         {
     296           0 :             Copy( lsp_mid, st_fx->lsp_old_fx, M );                       /* Q15 */
     297           0 :             lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */
     298           0 :             Copy( lsp_new, lsp_mid, M );                                 /* Q15 */
     299             :         }
     300             : 
     301             :         /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */
     302           0 :         int_lsp4_ivas_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 );
     303             :     }
     304             :     ELSE
     305             :     {
     306             :         /* LSP interpolation and conversion of LSPs to A(z) */
     307      139985 :         int_lsp4_ivas_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp );
     308             :     }
     309             :     /*------------------------------------------------------------------*
     310             :      * Check LSF stability (distance between old LSFs and current LSFs)
     311             :      *------------------------------------------------------------------*/
     312             : 
     313      139985 :     IF( st_fx->element_mode == EVS_MONO )
     314             :     {
     315        1423 :         st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /*Q15*/
     316        1423 :         move16();
     317             :     }
     318             :     ELSE
     319             :     {
     320      138562 :         st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /* Q15 */
     321      138562 :         move16();
     322             :     }
     323             : 
     324      139985 :     return;
     325             : }
     326             : 
     327             : 
     328             : /*========================================================================*/
     329             : /* FUNCTION : lsf_end_dec_fx()                                            */
     330             : /*------------------------------------------------------------------------*/
     331             : /* PURPOSE : De-quantize  frame end LSF vector                            */
     332             : /*------------------------------------------------------------------------*/
     333             : /* INPUT ARGUMENTS :                                                      */
     334             : /* _ (Word16) coder_type  : coding type                                   */
     335             : /* _ (Word16) bwidth    : input signal bandwidth                          */
     336             : /* _ (Word16) nBits      : number of bits used for ISF quantization       */
     337             : /* _ (Word32*) grid       : Table of 100 grid points for evaluating       */
     338             : /*                  Chebyshev polynomials          Q31                    */
     339             : /* _ (Word16) int_fs    : sampling frequency                              */
     340             : /* _ (Word32) core_brate  : Coding Bit Rate                               */
     341             : /* _ (Word32*) p_offset_scale1    : offsets for LSF LVQ structure 1st     */
     342             : /*                    8-dim subvector          Q0                         */
     343             : /* _ (Word32*) p_offset_scale2    : offsets for LSF LVQ structure 2nd     */
     344             : /*                    8-dim subvector          Q0                         */
     345             : /* _ (Word32*) p_offset_scale1_p   : offsets for LSF LVQ structure, pred .*/
     346             : /*                    case, 1st 8-dim subvector      Q0                   */
     347             : /* _ (Word32*) p_offset_scale2_p  : offsets for LSF LVQ structure,        */
     348             : /*                    pred. case, 2nd 8-dim subvector Q0                  */
     349             : /* _ (Word16*)  p_no_scales        : LSF LVQ structure           Q0       */
     350             : /* _ (Word16*)  p_no_scales_p    : LSF LVQ structure             Q0       */
     351             : /*------------------------------------------------------------------------*/
     352             : /* INPUT/OUTPUT ARGUMENTS :                                               */
     353             : /* _ (Word16*) mem_AR  : quantizer memory for AR model        Q(x2.56)    */
     354             : /*------------------------------------------------------------------------*/
     355             : /* OUTPUT ARGUMENTS :                                                     */
     356             : /* _ (Word16*) qlsf    : quantized LSFs in the cosine domain Q(x2.56)     */
     357             : /*------------------------------------------------------------------------*/
     358             : 
     359             : /*------------------------------------------------------------------------*/
     360             : /* RETURN ARGUMENTS :                                                     */
     361             : /* _ None                                                                 */
     362             : /*========================================================================*/
     363             : 
     364      238859 : void lsf_end_dec_fx(
     365             :     Decoder_State *st,           /* i/o: decoder state structure                 */
     366             :     Word16 mode2_flag,           /* Q0 */
     367             :     const Word16 coder_type_org, /* i  : coding type                                                            Q0*/
     368             :     const Word16 bwidth,         /* i  : input signal bandwidth                                         Q0*/
     369             :     const Word16 nBits_in,       /* i  : number of bits used for ISF quantization       Q0*/
     370             :     Word16 *qlsf,                /* o  : quantized LSFs in the cosine domain            Qx2.56*/
     371             :     Word16 *lpc_param,           /* i  : LPC parameters                                                         Q0*/
     372             :     Word16 *LSF_Q_prediction,    /* o  : LSF prediction mode                                            Q0*/
     373             :     Word16 *nb_indices           /* o  : number of indices                                                      Q0*/
     374             :     ,
     375             :     const Word16 tdm_lsfQ_PCh[M] /* i  : Q LSFs for primary channel              Qx*/
     376             : )
     377             : {
     378             :     Word16 pred0[M];               /* Prediction for the safety-net quantizer (usually mean)*/
     379             :     Word16 pred1[M], pred2[M];     /* Prediction for the predictive quantizer*/
     380             :     Word16 stages0;                /* Amount of stages used by safety-net quantizer*/
     381             :     Word16 stages1;                /* Amount of stages used by predictive quantizer*/
     382             :     Word16 levels0[MAX_VQ_STAGES]; /* Sizes of different codebook stages for safety-net quantizer*/
     383             :     Word16 levels1[MAX_VQ_STAGES]; /* Sizes of different codebook stages for predictive quantizer*/
     384             :     Word16 i;
     385             :     Word16 TCQIdx[M / 2 + 4];
     386             :     Word16 bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES];
     387             :     Word16 cumleft;
     388             :     Word16 lindice[MAX_VQ_STAGES + 3]; /* Predictor selector needs 1 bit and the LVQ indice uses 3 shorts */
     389             :     Word16 mode_lvq, mode_lvq_p;
     390             :     Word16 safety_net, predmode, stages, *levels;
     391      238859 :     const Word16 *Bit_alloc1 = NULL, *bits;
     392             :     Word16 num_bits;
     393             :     Word16 *p_lpc_param;
     394             : 
     395             :     Word16 nBits;
     396             : 
     397             :     Word16 coder_type;
     398             :     Word16 ber_flag;
     399             :     Word16 flag_1bit_gran;
     400             :     Word16 pred3[M];
     401      238859 :     flag_1bit_gran = (Word16) ( st->element_mode > EVS_MONO ); /* Q0 */
     402             : 
     403      238859 :     nBits = nBits_in; /* Q0 */
     404      238859 :     *nb_indices = 0;
     405      238859 :     move16();
     406      238859 :     move16();
     407      238859 :     move16();
     408             : 
     409      238859 :     test();
     410      238859 :     test();
     411      238859 :     IF( ( EQ_16( coder_type_org, GENERIC ) ) && ( EQ_32( st->sr_core, INT_FS_16k ) ) && ( mode2_flag == 0 ) )
     412             :     {
     413             :         /* this bit is used only for primary channel or mono */
     414       56283 :         coder_type = (Word16) get_next_indice_fx( st, 1 ); /* Q0 */
     415       56283 :         coder_type = add( coder_type, 2 );                 /* Q0 */
     416       56283 :         test();
     417       56283 :         test();
     418       56283 :         if ( EQ_16( coder_type, GENERIC ) || ( EQ_16( coder_type, VOICED ) && EQ_16( flag_1bit_gran, 1 ) ) )
     419             :         {
     420       55977 :             nBits = sub( nBits, 1 ); /* Q0 */
     421             :         }
     422             :     }
     423             :     ELSE
     424             :     {
     425      182576 :         coder_type = coder_type_org; /* Q0 */
     426      182576 :         move16();
     427             :     }
     428             : 
     429             :     /*--------------------------------------------------------------------------------*
     430             :      * LSF de-quantization of SID frames
     431             :      *--------------------------------------------------------------------------------*/
     432             : 
     433      238859 :     IF( st->core_brate == SID_2k40 )
     434             :     {
     435         417 :         dqlsf_CNG_fx( st, qlsf );
     436         417 :         sort_fx( qlsf, 0, M - 1 );
     437         417 :         reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core );
     438             : 
     439         417 :         return;
     440             :     }
     441             : 
     442             : 
     443      238442 :     find_pred_mode( &predmode, coder_type, bwidth, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate );
     444             :     /*----------------------------------------------------------------*
     445             :      * Calculate number of stages and levels for each stage based on the allowed bit allocation
     446             :      * (subtract one bit for LSF predictor selection)
     447             :      *----------------------------------------------------------------*/
     448      238442 :     lsf_allocate_fx( sub( nBits, shr( predmode, 1 ) ), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1,
     449             :                      bits0, bits1 );
     450             : 
     451             : 
     452             :     /*--------------------------------------------------------------------------*
     453             :      * Select safety_net or predictive mode
     454             :      *--------------------------------------------------------------------------*/
     455      238442 :     test();
     456      238442 :     test();
     457      238442 :     IF( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL )
     458             :     {
     459             :         /* if secondary channel predmode is set to be > 2  */
     460             :         /*predmode += 3;*/
     461         110 :         predmode = add( predmode, 3 ); /* Q0 */
     462             :     }
     463      238442 :     p_lpc_param = lpc_param; /* Q0 */
     464             : 
     465             : 
     466      238442 :     move16();
     467      238442 :     IF( predmode == 0 )
     468             :     {
     469       12668 :         safety_net = 1; /* Q0 */
     470       12668 :         move16();
     471             :     }
     472      225774 :     ELSE IF( predmode == 1 )
     473             :     {
     474      157688 :         safety_net = 0;
     475      157688 :         move16();
     476             :     }
     477             :     ELSE
     478             :     {
     479       68086 :         test();
     480       68086 :         test();
     481       68086 :         IF( EQ_16( mode2_flag, 1 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) )
     482             :         {
     483             :             /* read from param_lpc */
     484       32133 :             safety_net = p_lpc_param[0]; /* Q0 */
     485       32133 :             move16();
     486       32133 :             p_lpc_param++;
     487       32133 :             *nb_indices = add( *nb_indices, 1 ); /* Q0 */
     488             :         }
     489             :         ELSE
     490             :         {
     491       35953 :             safety_net = (Word16) get_next_indice_fx( st, 1 ); /* Q0 */
     492             :         }
     493             :     }
     494             : 
     495      238442 :     st->safety_net = safety_net; /* Q0 */
     496      238442 :     move16();
     497             : 
     498             :     /*--------------------------------------------------------------------------*
     499             :      * Read indices from array
     500             :      *--------------------------------------------------------------------------*/
     501      238442 :     test();
     502             :     /* Make sure there are the correct bit allocations */
     503      238442 :     IF( EQ_16( st->idchan, 1 ) && GT_16( predmode, 2 ) )
     504             :     {
     505             :         /* use same AR prediction bit allocation  for intra and inter modes*/
     506         110 :         lsf_allocate_fx( sub( nBits, 1 ), mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1 );
     507         110 :         stages0 = stages1;                 /* Q0 */
     508         110 :         Copy( levels1, levels0, stages0 ); /* Q0 */
     509         110 :         Copy( bits1, bits0, stages0 );     /* Q0 */
     510             :     }
     511             : 
     512      238442 :     test();
     513      238442 :     test();
     514      238442 :     IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 )
     515             :     {
     516             :         /* BC-TCVQ - only in VOICED_WB@16kHz */
     517         574 :         test();
     518         574 :         test();
     519         574 :         IF( EQ_16( st->codec_mode, MODE2 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) )
     520             :         {
     521         268 :             *nb_indices = 10; /* Q0 */
     522         268 :             move16();
     523         268 :             TCQIdx[0] = safety_net; /* Q0 */
     524         268 :             move16();
     525        2680 :             FOR( i = 1; i < *nb_indices; i++ )
     526             :             {
     527        2412 :                 TCQIdx[i] = *p_lpc_param++; /* Q0 */
     528        2412 :                 move16();
     529             :             }
     530             :         }
     531             :         ELSE
     532             :         {
     533         306 :             Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; /* Q0 */
     534         306 :             TCQIdx[0] = safety_net;                 /* Q0 */
     535         306 :             move16();
     536        3672 :             FOR( i = 0; i < M / 2 + 3; i++ )
     537             :             {
     538        3366 :                 TCQIdx[i + 1] = get_next_indice_fx( st, Bit_alloc1[i] ); /* Q0 */
     539        3366 :                 move16();
     540             :             }
     541             :         }
     542             :     }
     543             :     ELSE
     544             :     {
     545      237868 :         IF( safety_net )
     546             :         {
     547       33487 :             stages = stages0; /* Q0 */
     548       33487 :             move16();
     549       33487 :             levels = levels0; /* Q0 */
     550       33487 :             move16();
     551       33487 :             bits = bits0; /* Q0 */
     552       33487 :             move16();
     553             :         }
     554             :         ELSE
     555             :         {
     556      204381 :             stages = stages1; /* Q0 */
     557      204381 :             move16();
     558      204381 :             levels = levels1; /* Q0 */
     559      204381 :             move16();
     560      204381 :             bits = bits1; /* Q0 */
     561      204381 :             move16();
     562             :         }
     563      237868 :         test();
     564      237868 :         test();
     565      237868 :         IF( EQ_16( mode2_flag, 1 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) )
     566             :         {
     567      175299 :             FOR( i = 0; i < sub( stages, 1 ); i++ )
     568             :             {
     569       77110 :                 num_bits = bits[i]; /* Q0 */
     570       77110 :                 move16();
     571       77110 :                 lindice[i + 1] = *p_lpc_param++; /* Q0 */
     572       77110 :                 move16();
     573             :             }
     574             : 
     575       98189 :             cumleft = levels[stages - 1]; /* Q0 */
     576       98189 :             move16();
     577      294567 :             WHILE( cumleft > 0 )
     578             :             {
     579      196378 :                 IF( GT_16( cumleft, LEN_INDICE ) )
     580             :                 {
     581       98189 :                     cumleft = sub( cumleft, LEN_INDICE ); /* Q0 */
     582             :                 }
     583             :                 ELSE
     584             :                 {
     585       98189 :                     cumleft = 0;
     586       98189 :                     move16();
     587             :                 }
     588             : 
     589      196378 :                 lindice[i + 1] = *p_lpc_param++; /* Q0 */
     590      196378 :                 move16();
     591      196378 :                 i++;
     592             :             }
     593       98189 :             *nb_indices = add( *nb_indices, i ); /* Q0 */
     594       98189 :             move16();
     595             :         }
     596             :         ELSE
     597             :         {
     598      320935 :             FOR( i = 0; i < stages - 1; i++ )
     599             :             {
     600      181256 :                 num_bits = bits[i]; /* Q0 */
     601      181256 :                 move16();
     602      181256 :                 lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); /* Q0 */
     603      181256 :                 move16();
     604             :             }
     605             : 
     606      139679 :             cumleft = levels[stages - 1]; /* Q0 */
     607      527159 :             WHILE( cumleft > 0 )
     608             :             {
     609      387480 :                 IF( GT_16( cumleft, LEN_INDICE ) )
     610             :                 {
     611      247801 :                     cumleft = sub( cumleft, LEN_INDICE ); /* Q0 */
     612      247801 :                     num_bits = LEN_INDICE;                /* Q0 */
     613      247801 :                     move16();
     614             :                 }
     615             :                 ELSE
     616             :                 {
     617      139679 :                     num_bits = (Word16) cumleft; /* Q0 */
     618      139679 :                     move16();
     619      139679 :                     cumleft = 0;
     620      139679 :                     move16();
     621             :                 }
     622             : 
     623      387480 :                 lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); /* Q0 */
     624      387480 :                 move16();
     625      387480 :                 i++;
     626             :             }
     627             :         }
     628             :     }
     629      238442 :     IF( EQ_16( st->reset_mem_AR, 1 ) )
     630             :     {
     631           0 :         FOR( i = 0; i < M; i++ )
     632             :         {
     633           0 :             st->mem_AR_fx[i] = ModeMeans_fx[mode_lvq][i]; /* Q2.56 */
     634           0 :             move16();
     635             :         }
     636           0 :         st->reset_mem_AR = 0;
     637           0 :         move16();
     638             :     }
     639             : 
     640             :     /*------------------------------------------------------------------------------------------*
     641             :      * De-quantize LSF vector
     642             :      *------------------------------------------------------------------------------------------*/
     643             : 
     644      238442 :     *LSF_Q_prediction = SAFETY_NET; /* Q0 */
     645      238442 :     move16();
     646             :     /* VOICED_WB@16kHz */
     647      238442 :     test();
     648      238442 :     test();
     649      238442 :     IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 )
     650             :     {
     651             :         /* BC-TCVQ decoder */
     652         574 :         safety_net = qlsf_ARSN_tcvq_Dec_16k_fx( qlsf, TCQIdx, sub( nBits, 1 ) ); /* Q0 */
     653             : 
     654             :         /* Update mem_MA */
     655         574 :         Copy( qlsf, st->mem_MA_fx, M ); /* Q2.56 */
     656             : 
     657         574 :         IF( safety_net )
     658             :         {
     659          88 :             Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* Q2.56 */
     660             :         }
     661             :         ELSE
     662             :         {
     663        8262 :             FOR( i = 0; i < M; i++ )
     664             :             {
     665        7776 :                 pred0[i] = add( ModeMeans_fx[mode_lvq][i], mult( Predictors_fx[mode_lvq_p][i], ( sub( st->mem_AR_fx[i], ModeMeans_fx[mode_lvq][i] ) ) ) ); /* Q(x2.56)*/
     666        7776 :                 move16();
     667             :             }
     668         486 :             *LSF_Q_prediction = AUTO_REGRESSIVE; /* Q0 */
     669         486 :             move16();
     670             :         }
     671         574 :         Vr_add( qlsf, pred0, qlsf, M );
     672             :     }
     673             :     ELSE
     674             :     {
     675             : 
     676             :         /* Safety-net */
     677      237868 :         Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* Q2.56 */
     678             :         /* for mem_MA update */
     679     4043756 :         FOR( i = 0; i < M; i++ )
     680             :         {
     681     3805888 :             pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); /* Q2.56 */
     682     3805888 :             move16();
     683             :         }
     684             :         /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */
     685      237868 :         IF( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL )
     686             :         {
     687         110 :             tdm_SCh_LSF_intra_pred_fx( st->element_brate, tdm_lsfQ_PCh, pred3 );
     688             :         }
     689      237868 :         IF( safety_net )
     690             :         {
     691             :             /* LVQ */
     692       33487 :             test();
     693       33487 :             test();
     694       33487 :             IF( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL )
     695             :             {
     696             : 
     697             :                 /* intra mode*/
     698          36 :                 st->BER_detect = s_or( st->BER_detect,
     699          36 :                                        vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ) ); /* Q0 */
     700          36 :                 move16();
     701             : 
     702          36 :                 Vr_add( qlsf, pred3, qlsf, M );
     703          36 :                 Vr_subt( qlsf, pred1, st->mem_MA_fx, M );
     704             :             }
     705             :             ELSE
     706             :             {
     707       33451 :                 IF( st->element_mode != EVS_MONO )
     708             :                 {
     709       33216 :                     ber_flag = vq_dec_lvq_ivas_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1] ); /* Q0 */
     710             :                 }
     711             :                 ELSE
     712             :                 {
     713         235 :                     ber_flag = vq_dec_lvq_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1],
     714             :                                               &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0],
     715             :                                               &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); /* Q0 */
     716             :                 }
     717       33451 :                 st->BER_detect = s_or( st->BER_detect, ber_flag ); /* Q0 */
     718       33451 :                 move16();
     719       33451 :                 Vr_add( qlsf, pred0, qlsf, M );
     720       33451 :                 Vr_subt( qlsf, pred1, st->mem_MA_fx, M );
     721             :             }
     722             :         }
     723             :         ELSE
     724             :         {
     725      204381 :             IF( EQ_16( predmode, 4 ) )
     726             :             {
     727          57 :                 mode_lvq_p = 9;
     728          57 :                 predmode = 2;
     729          57 :                 move16();
     730          57 :                 move16();
     731             :             }
     732      204381 :             IF( st->element_mode != EVS_MONO )
     733             :             {
     734      202519 :                 ber_flag = vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); /* Q0 */
     735             :             }
     736             :             ELSE
     737             :             {
     738        1862 :                 ber_flag = vq_dec_lvq_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1],
     739             :                                           &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0],
     740             :                                           &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); /* Q0 */
     741             :             }
     742      204381 :             st->BER_detect = s_or( st->BER_detect, ber_flag ); /* Q0 */
     743      204381 :             move16();
     744      204381 :             test();
     745      204381 :             IF( EQ_16( predmode, 1 ) || EQ_16( predmode, 4 ) ) /* MA only */
     746             :             {
     747      157688 :                 Copy( qlsf, st->mem_MA_fx, M );     /* Q2.56 */
     748      157688 :                 Vr_add( qlsf, pred1, qlsf, M );     /* Q2.56 */
     749      157688 :                 *LSF_Q_prediction = MOVING_AVERAGE; /* Q0 */
     750      157688 :                 move16();
     751             :             }
     752             :             ELSE
     753             :             {
     754             :                 /* AR  */
     755      793781 :                 FOR( i = 0; i < M; i++ )
     756             :                 {
     757      747088 :                     pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); /* Q2.56 */
     758      747088 :                     move16();
     759             :                 }
     760       46693 :                 Vr_add( qlsf, pred2, qlsf, M );
     761       46693 :                 Vr_subt( qlsf, pred1, st->mem_MA_fx, M );
     762       46693 :                 *LSF_Q_prediction = AUTO_REGRESSIVE; /* Q0 */
     763       46693 :                 move16();
     764             :             }
     765             :         }
     766             :     }
     767             : 
     768             :     /*--------------------------------------------------------------------------*
     769             :      * Sort the quantized vector
     770             :      * Verify stability
     771             :      * Update AR-predictor memory
     772             :      *--------------------------------------------------------------------------*/
     773             : 
     774             :     /* Sort the quantized vector */
     775      238442 :     sort_fx( qlsf, 0, M - 1 );
     776             : 
     777             :     /* Verify stability */
     778      238442 :     reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core );
     779             :     /* Update predictor memory */
     780      238442 :     Copy( qlsf, st->mem_AR_fx, M ); /* Q2.56 */
     781             : 
     782      238442 :     st->mode_lvq = mode_lvq; /* Q0 */
     783      238442 :     move16();
     784             : 
     785             : 
     786      238442 :     return;
     787             : }
     788             : 
     789             : 
     790             : /*========================================================================*/
     791             : /* FUNCTION : lsf_mid_dec_fx()                                            */
     792             : /*------------------------------------------------------------------------*/
     793             : /* PURPOSE : Decode mid-frame LSFs                                        */
     794             : /*------------------------------------------------------------------------*/
     795             : /* INPUT ARGUMENTS :                                                      */
     796             : /* _ (Word16) coder_type  : Coder type                                    */
     797             : /* _ (Word32) core_brate  : core bitrate                                  */
     798             : /* _ (Word16[]) lsp_new    : quantized LSPs from frame beginning     Q15  */
     799             : /* _ (Word16[]) lsp_mid    : quantized LSPs from frame end           Q15  */
     800             : /*------------------------------------------------------------------------*/
     801             : /* INPUT/OUTPUT ARGUMENTS :                                               */
     802             : /*------------------------------------------------------------------------*/
     803             : /* OUTPUT ARGUMENTS :                                                     */
     804             : /* _ (Word16[]) qlsp    : quantized LSPs                        Q15       */
     805             : /*------------------------------------------------------------------------*/
     806             : 
     807             : /*------------------------------------------------------------------------*/
     808             : /* RETURN ARGUMENTS :                                                     */
     809             : /* _ None                                                                 */
     810             : /*========================================================================*/
     811      139985 : void lsf_mid_dec_fx(
     812             :     Decoder_State *st_fx, /* i/o: decoder state structure                          */
     813             :     Word16 lsp_new[],     /* i  : quantized LSPs from frame endS    Q15*/
     814             :     Word16 coder_type,    /* i  : Coder type                                             Q0*/
     815             :     Word16 lsp_mid[]      /* o  : quantized LSPs                                        Q15*/
     816             : )
     817             : {
     818             :     Word16 j, idx;
     819             :     Word16 nb_bits;
     820             :     Word16 qlsf0[M], qlsf1[M], qlsf[M];
     821             :     Word32 L_tmp;
     822             :     Word16 bad_spacing;
     823      139985 :     const Word16 *ratio = NULL;
     824      139985 :     bad_spacing = 0;
     825      139985 :     move16();
     826             : 
     827             : 
     828             :     /* Convert LSPs to LSFs */
     829      139985 :     lsp2lsf_fx( st_fx->lsp_old_fx, qlsf0, M, st_fx->sr_core );
     830      139985 :     lsp2lsf_fx( lsp_new, qlsf1, M, st_fx->sr_core );
     831             : 
     832             :     /* Codebook selection */
     833      139985 :     IF( EQ_16( st_fx->ppp_mode_dec, 1 ) )
     834             :     {
     835           0 :         nb_bits = 1; /* Q0 */
     836           0 :         move16();
     837           0 :         ratio = &tbl_mid_voi_wb_1b_fx[0]; /* Q13 */
     838             :     }
     839      139985 :     ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) )
     840             :     {
     841           0 :         nb_bits = 4; /* Q0 */
     842           0 :         move16();
     843           0 :         ratio = &tbl_mid_unv_wb_4b_fx[0]; /* Q13 */
     844             :     }
     845             :     ELSE
     846             :     {
     847      139985 :         nb_bits = st_fx->acelp_cfg.mid_lsf_bits; /* Q0 */
     848      139985 :         move16();
     849             : 
     850             :         /* codebook selection */
     851             : 
     852      139985 :         IF( EQ_16( coder_type, VOICED ) )
     853             :         {
     854        7412 :             SWITCH( nb_bits )
     855             :             {
     856        1464 :                 case 5:
     857             :                 {
     858        1464 :                     ratio = tbl_mid_voi_wb_5b_fx; /* Q13 */
     859        1464 :                     BREAK;
     860             :                 }
     861        5948 :                 case 4:
     862             :                 {
     863        5948 :                     ratio = tbl_mid_voi_wb_4b_fx; /* Q13 */
     864        5948 :                     BREAK;
     865             :                 }
     866           0 :                 case 1:
     867             :                 {
     868           0 :                     ratio = tbl_mid_voi_wb_1b_fx; /* Q13 */
     869           0 :                     break;
     870             :                 }
     871             :             }
     872        7412 :         }
     873      132573 :         ELSE IF( EQ_16( coder_type, UNVOICED ) )
     874             :         {
     875        1393 :             ratio = tbl_mid_unv_wb_5b_fx; /* Q13 */
     876             :         }
     877             :         ELSE
     878             :         {
     879             :             /* GENERIC, TRANSITION, AUDIO and INACTIVE */
     880      131180 :             SWITCH( nb_bits )
     881             :             {
     882      122828 :                 case 5:
     883             :                 {
     884      122828 :                     ratio = tbl_mid_gen_wb_5b_fx; /* Q13 */
     885      122828 :                     BREAK;
     886             :                 }
     887         735 :                 case 4:
     888             :                 {
     889         735 :                     ratio = tbl_mid_gen_wb_4b_fx; /* Q13 */
     890         735 :                     break;
     891             :                 }
     892        7617 :                 case 2:
     893             :                 {
     894        7617 :                     ratio = tbl_mid_gen_wb_2b_fx; /* Q13 */
     895        7617 :                     BREAK;
     896             :                 }
     897             :             }
     898      139985 :         }
     899             :     }
     900             : 
     901             :     /* Retrieve mid-frame LSF index */
     902      139985 :     idx = (Word16) get_next_indice_fx( st_fx, nb_bits ); /* Q0 */
     903             : 
     904             :     /* Calculation of mid-LSF vector */
     905     2379745 :     FOR( j = 0; j < M; j++ )
     906             :     {
     907     2239760 :         L_tmp = L_mult( sub( 0x2000, ratio[add( i_mult( idx, M ), j )] ), qlsf0[j] ); /*Q(x2.56+13+1)->Q(x2.56+14)*/
     908     2239760 :         L_tmp = L_mac( L_tmp, ratio[add( i_mult( idx, M ), j )], qlsf1[j] );          /*Q(x2.56+14)*/
     909     2239760 :         qlsf[j] = round_fx( L_shl( L_tmp, 2 ) );                                      /*Q(x2.56)*/
     910     2239760 :         move16();
     911             :     }
     912             : 
     913             :     /* check for incorrect LSF ordering */
     914      139985 :     IF( EQ_16( st_fx->mid_lsf_int, 1 ) )
     915             :     {
     916      128176 :         FOR( j = 1; j < M; j++ )
     917             :         {
     918      120169 :             IF( LT_16( qlsf[j], qlsf[j - 1] ) )
     919             :             {
     920           5 :                 bad_spacing = 1; /* Q0 */
     921           5 :                 move16();
     922           5 :                 BREAK;
     923             :             }
     924             :         }
     925             :     }
     926             : 
     927             :     /* Redo mid-LSF interpolation with 0.4 in case of LSF instability */
     928      139985 :     test();
     929      139985 :     test();
     930      139985 :     IF( st_fx->prev_bfi || ( EQ_16( st_fx->mid_lsf_int, 1 ) && bad_spacing ) )
     931             :     {
     932       27319 :         FOR( j = 0; j < M; j++ )
     933             :         {
     934             :             /* redo mid-LSF interpolation with 0.4 */
     935       25712 :             qlsf[j] = add( mult_r( 13107, qlsf0[j] ), mult_r( 19661, qlsf1[j] ) ); /* Q15 +x2.56 -Q15 13107 = 0.4(Q15), 19661 = 0.6 (Q15)*/
     936       25712 :             move16();
     937             : 
     938             :             /* ensure correct ordering of LSF indices */
     939       25712 :             test();
     940       25712 :             test();
     941       25712 :             IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) )
     942             :             {
     943          72 :                 qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); /* Q2.56 */
     944          72 :                 move16();
     945             :             }
     946             :         }
     947             :     }
     948             :     ELSE
     949             :     {
     950             :         /* otherwise, use regular LSF spacing and ordering as in the encoder */
     951     2352426 :         FOR( j = 0; j < M; j++ )
     952             :         {
     953     2214048 :             test();
     954     2214048 :             test();
     955     2214048 :             IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) )
     956             :             {
     957       13094 :                 qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); /* Q2.56 */
     958       13094 :                 move16();
     959             :             }
     960             :         }
     961             :     }
     962             : 
     963      139985 :     if ( st_fx->prev_bfi )
     964             :     {
     965             :         /* continue redoing mid-LSF interpolation with 0.4 in order not to propagate the error */
     966        1602 :         st_fx->mid_lsf_int = 1; /* Q0 */
     967        1602 :         move16();
     968             :     }
     969             : 
     970      139985 :     if ( st_fx->safety_net )
     971             :     {
     972             :         /* safety-net encountered -> stop redoing mid-LSF interpolation with 0.4 */
     973       22745 :         st_fx->mid_lsf_int = 0;
     974       22745 :         move16();
     975             :     }
     976             : 
     977      139985 :     reorder_lsf_fx( qlsf, LSF_GAP_MID_FX, M, st_fx->sr_core );
     978             : 
     979             :     /* convert back to LSPs */
     980      139985 :     lsf2lsp_fx( qlsf, lsp_mid, M, st_fx->sr_core );
     981             : 
     982      139985 :     return;
     983             : }

Generated by: LCOV version 1.14