LCOV - code coverage report
Current view: top level - lib_dec - hf_synth_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 136 907 15.0 %
Date: 2025-05-17 01:59:02 Functions: 6 12 50.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : #include <stdint.h>
       5             : #include "options.h" /* Compilation switches                   */
       6             : #include "cnst.h"    /* Common constants                       */
       7             : #include "prot_fx.h" /* Function prototypes                    */
       8             : #include "rom_com.h" /* Static table prototypes                */
       9             : #include "basop32.h"
      10             : 
      11             : /*---------------------------------------------------------------------*
      12             :  * Local constants
      13             :  *---------------------------------------------------------------------*/
      14             : 
      15             : #define L_SUBFR48k 240
      16             : #define L_SUBFR32k 160
      17             : 
      18             : /*---------------------------------------------------------------------*
      19             :  * Local function prototypes
      20             :  *---------------------------------------------------------------------*/
      21             : 
      22             : static void filt_6k_7k_scale_fx( Word16 signal[], Word16 lg, Word16 mem[], Word16 fact, Word16 exp );
      23             : static void hf_synthesis_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, const Word32 core_brate, const Word16 output_subfr, const Word16 Aq[], const Word16 exc[], const Word16 Q_exc, Word16 synth[], Word16 synth16k[], const Word16 Q_syn );
      24             : static void hf_synthesis_amr_wb_fx( const Word32 core_brate, const Word16 output_subfr, const Word16 Ap[], Word16 exc16k[], Word16 synth_out[], Word16 *mem_syn_hf, Word16 *delay_syn_hf, Word16 *mem_hp_interp, Word16 p_r, Word16 HF_corr_gain, Word16 til, Word16 voice_factors, const Word16 exc[], const Word16 Q_exc, const Word16 Q_out, Word16 qhf );
      25             : static void envelope_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, const Word32 core_brate, const Word16 Aq[], Word16 Ap[], Word16 *r, Word16 tilt0, Word16 tilt, Word16 voice_factor );
      26             : static void AdaptiveStartBand_fx( Word16 *start_band, const Word32 rate, const Word16 *lsf, const Word16 voicing_fac, const Word16 clas, Word16 *voicing_flag, Word16 *start_band_old, Word32 *OptCrit_old );
      27             : 
      28             : 
      29             : /*-------------------------------------------------------------------*
      30             :  * hf_synth_init()
      31             :  *
      32             :  * hf synthesis filters initialization
      33             :  * - initialization of 400 Hz high pass filter
      34             :  * - initialization of band pass 6kHz to 7kHz FIR filter
      35             :  *-------------------------------------------------------------------*/
      36             : 
      37        3256 : void hf_synth_init_fx(
      38             :     ZERO_BWE_DEC_HANDLE hBWE_zero /* o  : zero BWE decoder handle */
      39             : )
      40             : {
      41        3256 :     hBWE_zero->seed2 = RANDOM_INITSEED;
      42        3256 :     move16();
      43        3256 :     set16_fx( hBWE_zero->mem_hf_fx, 0, ( L_FIR - 1 ) );
      44        3256 :     set16_fx( hBWE_zero->mem_syn_hf_fx, 0, M );
      45        3256 :     set16_fx( hBWE_zero->mem_hp400_fx, 0, 4 );
      46        3256 :     set16_fx( hBWE_zero->delay_syn_hf_fx, 0, NS2SA( 16000, DELAY_CLDFB_NS ) );
      47        3256 :     set16_fx( hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN );
      48        3256 :     hBWE_zero->memExp1 = 0;
      49        3256 :     move16();
      50        3256 :     return;
      51             : }
      52      350067 : void hf_synth_reset_fx(
      53             :     ZERO_BWE_DEC_HANDLE hBWE_zero /* o  : zero BWE decoder handle */
      54             : )
      55             : {
      56             :     Word16 i;
      57             : 
      58   112371507 :     FOR( i = 0; i < L_FRAME16k; i++ )
      59             :     {
      60   112021440 :         Random( &hBWE_zero->seed2 );
      61             :     }
      62             : 
      63      350067 :     set16_fx( hBWE_zero->mem_hf_fx, 0, ( L_FIR - 1 ) );
      64      350067 :     set16_fx( hBWE_zero->mem_syn_hf_fx, 0, M );
      65      350067 :     set16_fx( hBWE_zero->mem_hp400_fx, 0, 4 );
      66             : 
      67      350067 :     set16_fx( hBWE_zero->delay_syn_hf_fx, 0, NS2SA( 16000, DELAY_CLDFB_NS ) );
      68      350067 :     set16_fx( hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN );
      69      350067 :     hBWE_zero->memExp1 = 0;
      70      350067 :     move16();
      71      350067 :     return;
      72             : }
      73             : 
      74             : /*---------------------------------------------------------------------*
      75             :  * hf_synth()
      76             :  *
      77             :  * High frequency regeneration
      78             :  *---------------------------------------------------------------------*/
      79             : 
      80       14951 : void hf_synth_fx(
      81             :     ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters          */
      82             :     const Word32 core_brate,       /* i  : core bitrate                                          Q0*/
      83             :     const Word16 output_frame,     /* i  : output frame length               Q0*/
      84             :     const Word16 *Aq,              /* i  : quantized Az                                         Q12*/
      85             :     const Word16 *exc,             /* i  : excitation at 12.8 kHz                 Q_exc*/
      86             :     Word16 *synth,                 /* i  : 12.8kHz synthesis signal              Q_syn2*/
      87             :     Word16 *synth16k,              /* o  : 16kHz synthesis signal        Q_syn2*/
      88             :     const Word16 Q_exc,            /* i  : excitation scaling             */
      89             :     const Word16 Q_syn2            /* i  : synthesis scaling              */
      90             : )
      91             : {
      92             :     const Word16 *p_Aq;
      93             :     Word16 i_subfr, output_subfr;
      94             : 
      95       14951 :     output_subfr = output_frame / NB_SUBFR;
      96       14951 :     move16();
      97             : 
      98       14951 :     p_Aq = Aq; /* Q12 */
      99       74755 :     FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR )
     100             :     {
     101       59804 :         hf_synthesis_fx( hBWE_zero, core_brate, output_subfr, p_Aq, &exc[i_subfr], Q_exc, &synth[i_subfr], &synth16k[imult3216( (Word32) i_subfr, output_subfr ) / L_SUBFR], Q_syn2 );
     102             : 
     103       59804 :         p_Aq += ( M + 1 ); /* Q12 */
     104             :     }
     105             : 
     106       14951 :     return;
     107             : }
     108             : 
     109             : /*-----------------------------------------------------------------------------------*
     110             :  * hf_synthesis()
     111             :  *
     112             :  * HF noise synthesis
     113             :  * - Generate HF noise between 6 and 7 kHz.
     114             :  * - Set energy of noise according to synthesis tilt.
     115             :  *     tilt > 0.8 ==> - 14 dB (voiced)
     116             :  *     tilt   0.5 ==> - 6 dB  (voiced or noise)
     117             :  *     tilt < 0.0 ==>   0 dB  (noise)
     118             :  *-----------------------------------------------------------------------------------*/
     119             : 
     120       59804 : static void hf_synthesis_fx(
     121             :     ZERO_BWE_DEC_HANDLE hBWE_zero,
     122             :     const Word32 core_brate,   /* i  : core bitrate                                Q0*/
     123             :     const Word16 output_subfr, /* i  : output sub-frame length                     Q0*/
     124             :     const Word16 Aq[],         /* i  : quantized Az                                                               Q12*/
     125             :     const Word16 exc[],        /* i  : excitation at 12.8 kHz                                   Q_exc*/
     126             :     const Word16 Q_exc,        /* i  : excitation scaling                                    */
     127             :     Word16 synth[],            /* i  : 12.8kHz synthesis signal                                 Q_syn*/
     128             :     Word16 synth16k[],         /* i/o: 16kHz synthesis signal                                   Q_syn*/
     129             :     const Word16 Q_syn         /* i  : synthesis scaling                                     */
     130             : )
     131             : {
     132             :     Word16 i, s;
     133             :     Word16 HF_syn[L_SUBFR16k], upsampled_HF_syn[L_FRAME48k / NB_SUBFR];
     134             :     Word16 HF_exc[L_SUBFR16k];
     135             :     Word16 tmp, ener, exp1, exp2, scale;
     136             :     Word32 L_tmp;
     137             :     Word16 Ap[M16k + 1];
     138             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     139       59804 :     Flag Overflow = 0;
     140       59804 :     move32();
     141             : #endif
     142             : 
     143             :     /*-----------------------------------------------------------------*
     144             :      * generate white noise vector
     145             :      *-----------------------------------------------------------------*/
     146             : 
     147       59804 :     Random_Fill( &hBWE_zero->seed2, L_SUBFR16k, HF_exc, 3 ); /* 3 = Shift Right by 3 */
     148             : 
     149             :     /* o: HF_exc in Q-3 */
     150             : 
     151             :     /*-----------------------------------------------------------------*
     152             :      * calculate energy scaling factor so that white noise would have the
     153             :      * same energy as exc12k8
     154             :      *-----------------------------------------------------------------*/
     155             : 
     156             :     /*ener = sum2_f( exc, L_SUBFR ) + 0.01f*/
     157       59804 :     ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); /* Q15 */
     158       59804 :     exp2 = sub( exp2, add( Q_exc, Q_exc ) );
     159             : 
     160             :     /*tmp = round_fx(Dot_product12(HF_exc, HF_exc, output_subfr, &exp1)); */
     161       59804 :     L_tmp = Dot_product12( HF_exc, HF_exc, L_SUBFR16k, &exp1 );
     162       59804 :     tmp = round_fx( L_tmp ); /* Q15 */
     163             :     /* tmp = (float)(sqrt(ener/tmp)) */
     164             :     /* scale is -1 if tmp > ener */
     165       59804 :     scale = shr( sub( ener, tmp ), 15 ); /* Q0 */
     166       59804 :     tmp = shl( tmp, scale );             /* Q15 + scale*/
     167       59804 :     exp1 = sub( exp1, scale );
     168             : 
     169       59804 :     tmp = div_s( tmp, ener ); /* Q15 */
     170       59804 :     exp1 = sub( exp1, exp2 );
     171             : 
     172       59804 :     L_tmp = L_deposit_h( tmp ); /* Q31 */
     173             : 
     174       59804 :     L_tmp = Isqrt_lc( L_tmp, &exp1 );
     175       59804 :     scale = round_fx( L_tmp ); /* Q18 when Q_exc=-1, HF_exc in Q-3 */
     176             : 
     177       59804 :     exp2 = sub( hBWE_zero->memExp1, exp1 );
     178       59804 :     hBWE_zero->memExp1 = exp1;
     179       59804 :     move16();
     180             : 
     181             :     /*-----------------------------------------------------------------*
     182             :      * calculate energy scaling factor to respect tilt of synth12k8
     183             :      * (tilt: 1=voiced, -1=unvoiced)
     184             :      *-----------------------------------------------------------------*/
     185       59804 :     hp400_12k8_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx );
     186             :     /* i: mem_hp400 in Q_syn */
     187             :     /* i: synth in Q_syn */
     188             :     /* o: synth in Q_syn-3 */
     189             : 
     190       59804 :     L_tmp = L_mac( 1L, synth[0], synth[0] ); /* 2*(Q_syn-3)+1 */
     191     3827456 :     FOR( i = 1; i < L_SUBFR; i++ )
     192             :     {
     193     3767652 :         L_tmp = L_mac_sat( L_tmp, synth[i], synth[i] ); /* 2*(Q_syn-3)+1 */
     194             :     }
     195       59804 :     tmp = norm_l( L_tmp );
     196       59804 :     ener = extract_h( L_shl( L_tmp, tmp ) ); /* ener = r[0] */
     197             :     /*ener in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0*/
     198             : 
     199       59804 :     L_tmp = L_mac( 1L, synth[1], synth[0] ); /* 2*(Q_syn-3)+1 */
     200     3767652 :     FOR( i = 2; i < L_SUBFR; i++ )
     201             :     {
     202     3707848 :         L_tmp = L_mac_sat( L_tmp, synth[i], synth[i - 1] ); /* 2*(Q_syn-3)+1 */
     203             :     }
     204       59804 :     tmp = extract_h( L_shl( L_tmp, tmp ) ); /* tmp = r[1] */
     205             :     /*tmp in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0 */
     206             :     /*we use the same normalization factor for both ener and tmp, */
     207             :     /*if the headroom in "tmp" is less than "ener", tmp can saturate */
     208             :     /*but this is ok since below we apply some thresholds to tmp */
     209             : 
     210       59804 :     tmp = s_max( 0, tmp );
     211       59804 :     if ( tmp > 0 )
     212             :     {
     213       59752 :         tmp = div_s( tmp, ener ); /* Q15 */
     214             :     }
     215             : 
     216             :     /*-----------------------------------------------------------------*
     217             :      * modify energy of white noise according to synthesis tilt
     218             :      *-----------------------------------------------------------------*/
     219             : 
     220             :     /* tmp = 1.0 - fac */
     221       59804 :     tmp = add_o( 1, sub( 32767 /* 1 in Q15 */, tmp ), &Overflow );
     222       59804 :     test();
     223       59804 :     if ( core_brate == FRAME_NO_DATA || EQ_32( core_brate, SID_2k40 ) )
     224             :     {
     225             :         /* emphasize HF noise in CNG */
     226             :         /*fac *= 2.0f;*/
     227       29384 :         tmp = add_o( tmp, tmp, &Overflow ); /* Q15 */
     228             :     }
     229       59804 :     tmp = s_max( tmp, 3277 ); /* 0.1 in Q15 */
     230             : 
     231             :     /*scale *= fac;*/
     232       59804 :     tmp = mult_r( scale, tmp );
     233             :     /*-----------------------------------------------------------------*
     234             :      * modify HF excitation according to both calculated scaling factors
     235             :      * high pass filtering (0.94ms of delay)
     236             :      *-----------------------------------------------------------------*/
     237             : 
     238       59804 :     filt_6k_7k_scale_fx( HF_exc, L_SUBFR16k, hBWE_zero->mem_hf_fx, tmp, exp2 );
     239             :     /* i: input HF_exc is scaled in float, here scaling is done inside this filter */
     240             :     /* i: mem_hf in Q-2 */
     241             :     /* o: HF_exc in Q0 */
     242             : 
     243             :     /*-----------------------------------------------------------------*
     244             :      * synthesis of noise: 4.8kHz..5.6kHz --> 6kHz..7kHz
     245             :      *-----------------------------------------------------------------*/
     246             : 
     247             :     /*weight_a( Aq, Ap, 0.6f, M );*/
     248       59804 :     weight_a_lc_fx( Aq, Ap, Gamma_19661_Tbl_fx, M );
     249             :     /* o: Ap in Q14 */
     250             : 
     251       59804 :     Syn_filt_s( 0, Ap, M, HF_exc, HF_syn, L_SUBFR16k, hBWE_zero->mem_syn_hf_fx, 1 );
     252             :     /* i: Ap in Q14 */
     253             :     /* i: HF_exc in Q0 */
     254             :     /* o: HF_syn in Q0 */
     255             :     /* i/o: mem_syn_hf in Q0 */
     256             : 
     257       59804 :     Scale_sig( HF_syn, L_SUBFR16k, ( add( Q_syn, exp1 ) ) ); /* bring HF_syn to (Q_syn+exp1) */
     258             : 
     259             :     /*-----------------------------------------------------------------*
     260             :      * add filtered HF noise to speech synthesis
     261             :      *-----------------------------------------------------------------*/
     262             : 
     263             :     /* delay by 5 samples @16kHz to compensate CLDFB resampling delay (20samples) and HP filtering delay (roughly 15 samples) */
     264       59804 :     delay_signal_fx( HF_syn, L_SUBFR16k, hBWE_zero->delay_syn_hf_fx, NS2SA_FX2( 16000, DELAY_CLDFB_NS ) - 15 );
     265             : 
     266             :     /* interpolate the HF synthesis */
     267       59804 :     IF( EQ_16( output_subfr, L_SUBFR48k ) ) /* 48kHz sampled output */
     268             :     {
     269       50072 :         s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( hBWE_zero->mem_hp_interp_fx, INTERP_3_1_MEM_LEN - 3 ) ), 3 ),
     270       50072 :                           sub( Find_Max_Norm16( hBWE_zero->mem_hp_interp_fx + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ),
     271             :                    0 );
     272       50072 :         Scale_sig( HF_syn, L_SUBFR16k, s );                              /* Q_syn+exp1+s */
     273       50072 :         Scale_sig( hBWE_zero->mem_hp_interp_fx, INTERP_3_1_MEM_LEN, s ); /* Qx + s */
     274       50072 :         interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, hBWE_zero->mem_hp_interp_fx );
     275       50072 :         Scale_sig( upsampled_HF_syn, 3 * L_SUBFR16k, -s );                /* Q_syn + exp1 + s */
     276       50072 :         Scale_sig( hBWE_zero->mem_hp_interp_fx, INTERP_3_1_MEM_LEN, -s ); /* Qx */
     277       50072 :         Scale_sig( HF_syn, L_SUBFR16k, -s );                              /* Q_syn+exp1 */
     278       50072 :         Scale_sig( upsampled_HF_syn, L_SUBFR48k, -1 );
     279             :     }
     280        9732 :     ELSE IF( EQ_16( output_subfr, L_SUBFR32k ) ) /* 32kHz sampled output */
     281             :     {
     282        6368 :         s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( hBWE_zero->mem_hp_interp_fx, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 );
     283        6368 :         Scale_sig( HF_syn, L_SUBFR16k, s );                                     /* Q_syn+exp1+s */
     284        6368 :         Scale_sig( hBWE_zero->mem_hp_interp_fx, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qx + s */
     285        6368 :         Interpolate_allpass_steep_fx( HF_syn, hBWE_zero->mem_hp_interp_fx, L_SUBFR16k, upsampled_HF_syn );
     286        6368 :         Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s );                       /* Q_syn + exp1 */
     287        6368 :         Scale_sig( hBWE_zero->mem_hp_interp_fx, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qx */
     288        6368 :         Scale_sig( HF_syn, L_SUBFR16k, -s );                                     /* Q_syn+exp1 */
     289             :     }
     290             :     ELSE /* 16kHz sampled output */
     291             :     {
     292        3364 :         Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Q_syn */
     293             :     }
     294             : 
     295       59804 :     Vr_add( synth16k, upsampled_HF_syn, synth16k, output_subfr );
     296             : 
     297       59804 :     return;
     298             : }
     299             : 
     300             : /*-------------------------------------------------------------------*
     301             :  * filt_6k_7k:
     302             :  *
     303             :  * 15th order band pass 6kHz to 7kHz FIR filter.
     304             :  *
     305             :  * frequency:  4kHz   5kHz  5.5kHz  6kHz  6.5kHz 7kHz  7.5kHz  8kHz
     306             :  * dB loss:   -60dB  -45dB  -13dB   -3dB   0dB   -3dB  -13dB  -45dB
     307             :  * (gain=4.0)
     308             :  *-------------------------------------------------------------------*/
     309       59804 : static void filt_6k_7k_scale_fx(
     310             :     Word16 signal[], /* i/o: signal                                     Qx*/
     311             :     Word16 lg,       /* i  : length of input            Q0*/
     312             :     Word16 mem[],    /* i/o: memory (size=30)      exp*/
     313             :     Word16 fact,     /* i  : multiply factor        Q0*/
     314             :     Word16 exp       /* i  : Mem Exponent                         */
     315             : )
     316             : {
     317             :     Word16 i, x[L_FRAME48k / NB_SUBFR + ( L_FIR - 1 )];
     318             :     Word32 L_tmp;
     319             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     320       59804 :     Flag Overflow = 0;
     321       59804 :     move32();
     322             : #endif
     323       59804 :     Copy_Scale_sig( mem, x, L_FIR - 1, exp );
     324             : 
     325     4844124 :     FOR( i = 0; i < lg; i++ )
     326             :     {
     327     4784320 :         x[i + L_FIR - 1] = shr( mult( signal[i], fact ), 2 ); /* Qx - 2 */
     328     4784320 :         move16();                                             /* gain of filter = 4 */
     329             :     }
     330     4844124 :     FOR( i = 0; i < lg; i++ )
     331             :     {
     332             : 
     333             :         Word16 j;
     334     4784320 :         L_tmp = 0;
     335     4784320 :         move32();
     336   153098240 :         FOR( j = 0; j < 31; j++ )
     337             :         {
     338   148313920 :             L_tmp = L_mac_o( L_tmp, x[i + j], fir_6k_7k_fx[j], &Overflow ); /* Q16 */
     339             :         }
     340             : 
     341     4784320 :         signal[i] = round_fx_o( L_tmp, &Overflow ); /* Q0 */
     342     4784320 :         move16();
     343             :     }
     344       59804 :     Copy( x + lg, mem, L_FIR - 1 ); /* Qx - 2 */
     345       59804 : }
     346             : 
     347             : /*-------------------------------------------------------------------*
     348             :  * hf_synth_amr_wb_init()
     349             :  *
     350             :  * hf synthesis filters initialization
     351             :  * - initialization of 1600 Hz low pass filter
     352             :  * - initialization of band pass 6kHz to 8kHz FIR filter for noise and line resampled signals
     353             :  *-------------------------------------------------------------------*/
     354             : 
     355           6 : void hf_synth_amr_wb_init_fx(
     356             :     AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle   */
     357             : )
     358             : {
     359           6 :     hAmrwb_IO->prev_r_fx = 0;
     360           6 :     move16();
     361           6 :     hAmrwb_IO->fmerit_w_sm_fx = 0;
     362           6 :     move16();
     363           6 :     hAmrwb_IO->frame_count_fx = 0;
     364           6 :     move16();
     365           6 :     hAmrwb_IO->ne_min_fx = -7680;
     366           6 :     move16(); /*-30.0f in Q8*/
     367           6 :     hAmrwb_IO->fmerit_m_sm_fx = 0;
     368           6 :     move16();
     369           6 :     hAmrwb_IO->voice_fac_amr_wb_hf = 0;
     370           6 :     move16();
     371           6 :     hAmrwb_IO->unvoicing_fx = 0;
     372           6 :     move16();
     373           6 :     hAmrwb_IO->unvoicing_sm_fx = 32767;
     374           6 :     move16(); /*1.0f in Q15*/
     375           6 :     hAmrwb_IO->unvoicing_flag_fx = 0;
     376           6 :     move16();
     377           6 :     hAmrwb_IO->voicing_flag_fx = 0;
     378           6 :     move16();
     379           6 :     hAmrwb_IO->start_band_old_fx = 160;
     380           6 :     move16();
     381           6 :     hAmrwb_IO->OptCrit_old_fx = 32768;
     382           6 :     move32(); /*1.0f in Q15*/
     383             :     ;
     384           6 :     return;
     385             : }
     386             : 
     387             : 
     388             : /*-------------------------------------------------------------------*
     389             :  * hf_synth_amr_wb_reset()
     390             :  *
     391             :  * reset of HF synthesis filters
     392             :  * - needed in switching scenarios
     393             :  *-------------------------------------------------------------------*/
     394           0 : void hf_synth_amr_wb_reset_fx(
     395             :     ZERO_BWE_DEC_HANDLE hBWE_zero, /* o  : zero BWE decoder handle */
     396             :     AMRWB_IO_DEC_HANDLE hAmrwb_IO  /* i/o: AMR-WB IO data handle   */
     397             : )
     398             : {
     399             :     Word16 i;
     400             : 
     401             : 
     402           0 :     FOR( i = 0; i < L_FRAME16k; i++ )
     403             :     {
     404           0 :         Random( &hBWE_zero->seed2 );
     405             :     }
     406             : 
     407           0 :     set16_fx( hBWE_zero->mem_syn_hf_fx, 0, M );
     408           0 :     set16_fx( hBWE_zero->delay_syn_hf_fx, 0, NS2SA( 16000, DELAY_CLDFB_NS ) );
     409           0 :     set16_fx( hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN );
     410             : 
     411           0 :     hAmrwb_IO->prev_r_fx = 0;
     412           0 :     move16();
     413           0 :     hAmrwb_IO->fmerit_w_sm_fx = 0;
     414           0 :     move16();
     415           0 :     hAmrwb_IO->frame_count_fx = 0;
     416           0 :     move16();
     417           0 :     hAmrwb_IO->ne_min_fx = -7680;
     418           0 :     move16(); /*-30.0f in Q8*/
     419           0 :     hAmrwb_IO->fmerit_m_sm_fx = 0;
     420           0 :     move16();
     421           0 :     hAmrwb_IO->voice_fac_amr_wb_hf = 0;
     422           0 :     move16();
     423           0 :     hAmrwb_IO->unvoicing_fx = 0;
     424           0 :     move16();
     425           0 :     hAmrwb_IO->unvoicing_sm_fx = 32767;
     426           0 :     move16(); /*1.0f in Q15*/
     427           0 :     hAmrwb_IO->unvoicing_flag_fx = 0;
     428           0 :     move16();
     429           0 :     hAmrwb_IO->voicing_flag_fx = 0;
     430           0 :     move16();
     431           0 :     hAmrwb_IO->start_band_old_fx = 160;
     432           0 :     move16();
     433           0 :     hAmrwb_IO->OptCrit_old_fx = 32768;
     434           0 :     move32(); /*1.0f in Q15*/
     435             : 
     436           0 :     return;
     437             : }
     438             : 
     439             : /*-------------------------------------------------------------------*
     440             :  * hf_synth_amr_wb()
     441             :  *
     442             :  * HF synthesis in AMR-WB IO
     443             :  *-------------------------------------------------------------------*/
     444             : 
     445           0 : void hf_synth_amr_wb_fx(
     446             :     AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle   */
     447             :     ZERO_BWE_DEC_HANDLE hBWE_zero, /* o  : zero BWE decoder handle */
     448             :     const Word32 core_brate,       /* i  : core bitrate                                      Q0*/
     449             :     const Word16 output_frame,     /* i  : output frame length                               Q0*/
     450             :     const Word16 *Aq,              /* i  : quantized Az :                                                                       Q12*/
     451             :     const Word16 *exc,             /* i  : excitation at 12.8 kHz  :                                      Q_exc*/
     452             :     Word16 *synth,                 /* i/o: synthesis signal at 12.8k :                                    Q_syn*/
     453             :     Word16 *amr_io_class,          /* i  : signal class (determined by FEC algorithm)        Q0*/
     454             :     Word16 *synth_out,             /* i/o: output signal at output Fs  :                                  Q_out*/
     455             :     Word16 fmerit,                 /* i  : classify parameter from FEC :                                        Q14*/
     456             :     const Word16 *hf_gain,         /* i  : decoded HF gain                                   Q0*/
     457             :     const Word16 *voice_factors,   /* i  : voicing factors  :                                                           Q15*/
     458             :     const Word16 pitch_buf[],      /* i  : pitch buffer  :                                                                       Q5*/
     459             :     const Word16 ng_ener_ST,       /* i  : Noise gate - short-term energy :                                      Q8*/
     460             :     const Word16 *lsf_new,         /* i  : ISF vector  :                                                                         Q2*/
     461             :     const Word16 Q_exc,            /* i  : exc scaling                                         */
     462             :     const Word16 Q_out             /* i  : Q_syn2-1                                            */
     463             : )
     464             : {
     465           0 :     Word16 core_type = 1;
     466             :     Word16 start_band;
     467             :     Word16 HF_corr_gain[NB_SUBFR];
     468             :     Word16 filt_weight_coeff;
     469             :     Word16 i, j, output_subfr;
     470             :     Word16 *pt3, *pt4, *pt5;
     471             :     const Word16 *pt6, *pt7;
     472             :     Word16 *pt1, *pt2;
     473             :     Word32 enr1, enr2;
     474             :     Word16 til[NB_SUBFR], til0[NB_SUBFR];
     475             :     Word16 tmp1, tmp2;
     476             :     Word32 L_tmp;
     477             :     Word16 exp;
     478             :     Word16 pitch_var_cur;
     479             :     Word16 voice_fac;
     480             :     Word16 fmerit_w;
     481             :     Word16 fmerit_m;
     482             :     Word16 *p_Ap;
     483             :     const Word16 *p_Aq;
     484             :     Word16 Ap[( M16k + 1 ) * NB_SUBFR];
     485             :     Word16 sub_gain[NB_SUBFR];
     486             :     Word16 exc16k[L_FRAME16k];
     487             :     Word16 qhf;
     488             :     Word16 dct_exc[L_FRAME], dct_hb[L_FRAME16k], filt_weight[L_SUBFR16k];
     489             :     Word16 hb_ener, g, hb_tonal[L_SUBFR16k], tonal_ener, hb_amb[L_SUBFR16k], inv_g;
     490             :     Word16 fb, fn, signum[L_SUBFR16k];
     491             :     Word16 alpha, beta, ener, tmp, scale, rev_filt_weight_coeff, qdct, q1, q2, q3, q4, shift;
     492             :     Word16 e_subfr1, e_subfr2;
     493             :     Word32 exc32[L_FRAME], dct_exc32[L_FRAME], dct_hb32[L_FRAME16k], exc16k32[L_FRAME16k];
     494             :     Word16 q_tmp;
     495             :     Word16 gamma;
     496           0 :     move16();
     497             : 
     498           0 :     Scale_sig( synth, L_FRAME, -3 ); /* Q_syn - 3 */
     499             : 
     500           0 :     pt1 = synth + 1; /* Q_syn - 3 */
     501           0 :     pt2 = synth;     /* Q_syn - 3 */
     502           0 :     pt3 = til;
     503           0 :     pt4 = til0;
     504           0 :     FOR( i = 0; i < NB_SUBFR; i++ )
     505             :     {
     506           0 :         enr1 = Dot_product( pt2, pt2, L_SUBFR );     /*2*(Q_syn-3)+1 */
     507           0 :         enr2 = Dot_product( pt1, pt2, L_SUBFR - 1 ); /*2*(Q_syn-3)+1 */
     508             : 
     509           0 :         tmp1 = extract_h( enr1 ); /*2*(Q_syn-3) - 15 */
     510           0 :         tmp1 = s_max( 1, tmp1 );
     511           0 :         tmp2 = extract_h( enr2 ); /*2*(Q_syn-3) - 15 */
     512             : 
     513           0 :         exp = norm_s( tmp1 );
     514           0 :         tmp1 = div_s( shl( 1, sub( 14, exp ) ), tmp1 );   /*Q(29-exp-2*(Q_syn-3)-1) */
     515           0 :         L_tmp = L_mult( tmp2, tmp1 );                     /*30-exp-2*(Q_syn-3)-1+2*(Q_syn-3)+1 - >30-exp */
     516           0 :         *pt3 = round_fx( L_shl( L_tmp, sub( exp, 1 ) ) ); /*13 */
     517           0 :         move16();
     518           0 :         *pt4++ = *pt3++;
     519           0 :         move16();
     520             : 
     521           0 :         pt1 += L_SUBFR;
     522           0 :         pt2 += L_SUBFR;
     523             :     }
     524             : 
     525           0 :     output_subfr = shr( output_frame, 2 ); /* Q0 */
     526             : 
     527           0 :     if ( NE_16( *amr_io_class, 7 ) )
     528             :     {
     529           0 :         core_type = 0;
     530           0 :         move16();
     531             :     }
     532             : 
     533             :     /* modify LF parameters for excitation weighting or sub-frame gains calculating */
     534           0 :     pitch_var_cur = 0;
     535           0 :     move16();
     536           0 :     pt6 = pitch_buf;     /* Q5 */
     537           0 :     pt7 = pitch_buf + 1; /* Q5 */
     538           0 :     FOR( i = 0; i < 3; i++ )
     539             :     {
     540           0 :         tmp1 = abs_s( sub( *pt6++, *pt7++ ) );                /*Q5 */
     541           0 :         pitch_var_cur = add( pitch_var_cur, shr( tmp1, 1 ) ); /*Q6 -> Q5 */
     542             :     }
     543           0 :     test();
     544           0 :     IF( GT_16( hAmrwb_IO->frame_count_fx, FRAME_COUNT_HF_SYNTH ) && *amr_io_class == UNVOICED_CLAS )
     545             :     {
     546           0 :         hAmrwb_IO->frame_count_fx = 0;
     547           0 :         hAmrwb_IO->ne_min_fx = -7680; /* -30.0f in Q8 */
     548           0 :         move16();
     549           0 :         move16(); /*Q8;  */
     550             :     }
     551             :     ELSE
     552             :     {
     553           0 :         hAmrwb_IO->frame_count_fx = s_min( hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH - 1 ); /* Q0 */
     554           0 :         move16();
     555           0 :         hAmrwb_IO->frame_count_fx = add( hAmrwb_IO->frame_count_fx, 1 ); /* Q0 */
     556           0 :         move16();
     557           0 :         hAmrwb_IO->ne_min_fx = s_min( hAmrwb_IO->ne_min_fx, ng_ener_ST ); /* Q8 */
     558           0 :         move16();
     559             :     }
     560             : 
     561           0 :     pt6 = voice_factors;
     562           0 :     L_tmp = L_mult( *pt6++, 4096 /* 0.25 IN Q14 */ ); /* Q30 */
     563           0 :     FOR( i = 1; i < 4; i++ )
     564             :     {
     565           0 :         L_tmp = L_mac( L_tmp, *pt6++, 4096 /* 0.25 IN Q14 */ ); /* Q30 */
     566             :     }
     567             : 
     568           0 :     voice_fac = round_fx( L_tmp ); /* Q14 */
     569             : 
     570             :     /*fmerit_w = fmerit > 5734 ? 5734 : (fmerit < 2458 ? 2458 : fmerit); //Q14 */
     571             : 
     572           0 :     fmerit_w = s_min( fmerit, 5734 /* 0.35 IN Q14 */ );   /* Q14 */
     573           0 :     fmerit_w = s_max( fmerit_w, 2458 /* 0.15 IN Q14 */ ); /* Q14 */
     574             : 
     575           0 :     if ( EQ_16( core_type, 1 ) )
     576             :     {
     577           0 :         fmerit_w = shr( fmerit_w, 1 ); /* Q14 */
     578             :     }
     579             : 
     580           0 :     L_tmp = L_mult( fmerit_w, add_sat( 16384, voice_fac ) ); /* Q14 */
     581           0 :     fmerit_w = extract_l( L_shr( L_tmp, 15 ) );              /*Q14 */
     582             :     /**fmerit_w_sm = add(mult_r(*fmerit_w_sm, 29491), mult_r(fmerit_w, 3277));  //Q14 */
     583           0 :     hAmrwb_IO->fmerit_w_sm_fx = round_fx( L_mac( L_mult( hAmrwb_IO->fmerit_w_sm_fx, 29491 ), fmerit_w, 3277 ) ); /*Q14 */
     584           0 :     move16();
     585           0 :     fmerit_w = hAmrwb_IO->fmerit_w_sm_fx;
     586             : 
     587           0 :     move16();
     588             : 
     589           0 :     tmp1 = fmerit; /* Q14 */
     590           0 :     move16();
     591           0 :     if ( LT_16( fmerit, 8192 /* 0.5 in Q14 */ ) )
     592             :     {
     593           0 :         tmp1 = 16384; /* 1.0f in Q14 */
     594           0 :         move16();
     595             :     }
     596           0 :     fmerit_m = negate( add( -32768, tmp1 ) );
     597           0 :     hAmrwb_IO->fmerit_m_sm_fx = add( shr( hAmrwb_IO->fmerit_m_sm_fx, 1 ), shr( fmerit_m, 1 ) ); /*Q14 */
     598           0 :     move16();
     599           0 :     fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; /* Q14 */
     600           0 :     move16();
     601             : 
     602           0 :     pt1 = til;
     603           0 :     FOR( i = 0; i < NB_SUBFR; i++ )
     604             :     {
     605           0 :         tmp = sub( pitch_var_cur, 320 );
     606           0 :         tmp = s_and( tmp, *pt1 );
     607           0 :         if ( tmp < 0 )
     608             :         {
     609           0 :             *pt1 = 1638; /* 0.2 in Q13 */
     610           0 :             move16();
     611             :         }
     612             : 
     613           0 :         tmp1 = sub( 8192 /* 1.0 in Q13 */, *pt1 );   /* Q13 */
     614           0 :         *pt1 = s_max( 6554 /* 0.8 in Q13 */, tmp1 ); /* Q13 */
     615           0 :         move16();
     616           0 :         tmp1 = add( hAmrwb_IO->ne_min_fx, 7680 /* 30.0 in Q30 */ ); /*Q8  */
     617           0 :         tmp1 = mult_r( tmp1, 7340 );                                /*Q20 - > 0.007  //Q13 */
     618           0 :         *pt1 = add( *pt1, tmp1 );
     619           0 :         move16(); /*Q13 */
     620             : 
     621           0 :         L_tmp = L_mult0( *pt1, fmerit_m );        /*Q13+14 */
     622           0 :         *pt1++ = extract_l( L_shr( L_tmp, 14 ) ); /*Q13 */
     623           0 :         move16();
     624             :     }
     625             :     /* predict LPC coefficents and calculate sub-frame gains */
     626           0 :     p_Aq = Aq;
     627           0 :     p_Ap = Ap;
     628           0 :     pt1 = sub_gain;
     629           0 :     pt2 = til0;
     630           0 :     pt3 = til;
     631           0 :     pt6 = voice_factors;
     632           0 :     FOR( i = 0; i < NB_SUBFR; i++ )
     633             :     {
     634           0 :         envelope_fx( hAmrwb_IO, core_brate, p_Aq, p_Ap, pt1, *pt2, *pt3, *pt6 );
     635           0 :         pt1++;
     636           0 :         pt2++;
     637           0 :         pt3++;
     638           0 :         pt6++;
     639             : 
     640           0 :         p_Aq += ( M + 1 );
     641           0 :         p_Ap += ( M + 1 );
     642             :     }
     643             : 
     644           0 :     AdaptiveStartBand_fx( &start_band, core_brate, lsf_new, voice_fac, *amr_io_class, &hAmrwb_IO->voicing_flag_fx, &hAmrwb_IO->start_band_old_fx, &hAmrwb_IO->OptCrit_old_fx );
     645             : 
     646           0 :     q_tmp = Exp16Array( L_FRAME, exc );
     647           0 :     qdct = sub( q_tmp, 1 );
     648           0 :     Copy_Scale_sig_16_32_DEPREC( exc, exc32, L_FRAME, qdct ); /* Qexc + qdct */
     649             : 
     650           0 :     qdct = add( qdct, Q_exc );
     651           0 :     edct_fx( exc32, dct_exc32, L_FRAME, &qdct );
     652           0 :     q_tmp = Exp32Array( L_FRAME, dct_exc32 );
     653             : 
     654           0 :     q_tmp = sub( q_tmp, 16 );
     655           0 :     Copy_Scale_sig_32_16( dct_exc32, dct_exc, L_FRAME, q_tmp ); /* qdct + qtmp */
     656           0 :     qdct = add( qdct, q_tmp );
     657             : 
     658           0 :     set16_fx( dct_hb, 0, L_FRAME16k );
     659           0 :     pt1 = &dct_hb[200];  /* qdct */
     660           0 :     pt2 = &dct_exc[200]; /* qdct */
     661           0 :     FOR( i = 200; i < 240; i++ )
     662             :     {
     663           0 :         *pt1++ = *pt2++;
     664           0 :         move16(); /*qdct */
     665             :     }
     666           0 :     set16_fx( signum, 1, L_SUBFR16k );
     667           0 :     pt1 = dct_hb + 240;
     668           0 :     pt2 = dct_exc + start_band;
     669           0 :     pt3 = signum;
     670           0 :     FOR( i = 240; i < L_FRAME16k; i++ )
     671             :     {
     672           0 :         if ( *pt2 < 0 )
     673             :         {
     674           0 :             *pt3 = -1;
     675           0 :             move16();
     676             :         }
     677           0 :         *pt1++ = abs_s( *pt2++ );
     678           0 :         move16(); /*qdct */
     679           0 :         pt3++;
     680             :     }
     681           0 :     hb_ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q1, L_SUBFR16k );
     682             : 
     683           0 :     L_tmp = L_shl( L_mult( start_band, 205 /* 0.00625f in Q15 */ ), 14 ); /*Q30 */
     684           0 :     tmp = round_fx( L_tmp );                                              /*Q14 */
     685           0 :     tmp = sub( 18022 /* 1.1f in Q14 */, tmp );                            /*Q14 */
     686           0 :     fmerit_w = round_fx( L_shl( L_mult( fmerit_w, tmp ), 1 ) );           /*Q: 14+14+1+1-16 = 14 */
     687             : 
     688             : 
     689           0 :     L_tmp = L_deposit_l( fmerit_w ); /*Q14 */
     690           0 :     L_tmp = Isqrt( L_tmp );          /*Q(31-7) */
     691           0 :     tmp = round_fx( L_tmp );         /*Q8 */
     692           0 :     q2 = norm_s( tmp );
     693           0 :     alpha = div_s( shl( 1, sub( 14, q2 ) ), tmp ); /*Q(29-q2-8); */
     694           0 :     alpha = shl( alpha, sub( q2, 7 ) );            /*Q14 */
     695             : 
     696           0 :     beta = sub( 16384 /* 1.0f in Q14 */, fmerit_w ); /*Q14 */
     697             : 
     698           0 :     L_tmp = L_mult( alpha, 31130 /* 0.95f in Q15 */ ); /*Q30 */
     699           0 :     gamma = round_fx( L_tmp );                         /*Q14 */
     700           0 :     gamma = sub( 17203 /* 1.05f in Q14 */, gamma );    /*Q14 */
     701           0 :     gamma = s_min( 16384 /* 1.0f in Q14 */, gamma );   /* Q14 */
     702           0 :     gamma = s_max( 4915 /* 0.3f in Q14 */, gamma );    /* Q14 */
     703             : 
     704           0 :     IF( LT_16( beta, 16384 /* 1 in Q14 */ ) )
     705             :     {
     706           0 :         L_tmp = 1; /*variable for tonal energy*/
     707           0 :         move32();
     708             : 
     709           0 :         pt1 = hb_amb;
     710           0 :         pt2 = hb_tonal;
     711           0 :         pt3 = &dct_hb[240];
     712           0 :         FOR( i = 0; i < 8; i++ )
     713             :         {
     714           0 :             fn = add( i, 8 );      /* Q0 */
     715           0 :             tmp1 = div_s( 1, fn ); /*Q15  */
     716           0 :             tmp = 0;
     717           0 :             move16();
     718           0 :             pt4 = &dct_hb[240];
     719           0 :             FOR( j = 0; j < fn; j++ )
     720             :             {
     721           0 :                 tmp = add_sat( tmp, shr( *pt4++, 2 ) ); /*qdct-2 */
     722             :             }
     723           0 :             *pt1 = round_fx( L_shl( L_mult( tmp, tmp1 ), 2 ) ); /*qdct */
     724           0 :             move16();
     725           0 :             *pt2 = sub( *pt3, *pt1 ); /* qdct */
     726           0 :             move16();
     727           0 :             IF( *pt2 > 0 )
     728             :             {
     729           0 :                 L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); /*2*qdct-2 */
     730             :             }
     731           0 :             pt1++;
     732           0 :             pt2++;
     733           0 :             pt3++;
     734             :         }
     735           0 :         FOR( ; i < L_SUBFR16k - 8; i++ )
     736             :         {
     737           0 :             fb = sub( i, 7 );   /* Q0 */
     738           0 :             fn = add( fb, 15 ); /* Q0 */
     739           0 :             tmp = 0;
     740           0 :             move16();
     741           0 :             pt4 = &dct_hb[fb + 240];
     742           0 :             FOR( j = fb; j < fn; j++ )
     743             :             {
     744           0 :                 tmp = add_sat( tmp, shr( *pt4++, 2 ) ); /*qdct-2 */
     745             :             }
     746           0 :             *pt1 = mult_r( tmp, 8738 );
     747           0 :             move16(); /* 8738 = 1/15 in Q17 qdct */
     748           0 :             *pt2 = sub( *pt3, *pt1 );
     749           0 :             move16();
     750           0 :             IF( *pt2 > 0 )
     751             :             {
     752           0 :                 L_tmp = L_mac0_sat( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); /*2*qdct-2 */
     753             :             }
     754           0 :             pt1++;
     755           0 :             pt2++;
     756           0 :             pt3++;
     757             :         }
     758           0 :         FOR( ; i < L_SUBFR16k; i++ )
     759             :         {
     760           0 :             fb = sub( i, 7 ); /* Q0 */
     761           0 :             tmp = 0;
     762           0 :             move16();
     763           0 :             fn = sub( L_SUBFR16k, fb ); /* Q0 */
     764           0 :             tmp1 = div_s( 1, fn );      /*Q15 */
     765           0 :             pt4 = &dct_hb[fb + 240];
     766           0 :             FOR( j = fb; j < L_SUBFR16k; j++ )
     767             :             {
     768           0 :                 tmp = add_sat( tmp, shr( *pt4++, 2 ) ); /*qdct-2 */
     769             :             }
     770           0 :             *pt1 = round_fx( L_shl( L_mult( tmp, tmp1 ), 2 ) ); /*qdct */
     771           0 :             move16();
     772           0 :             *pt2 = sub( *pt3, *pt1 );
     773           0 :             move16();
     774           0 :             IF( *pt2 > 0 )
     775             :             {
     776           0 :                 L_tmp = L_mac0_sat( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); /*2*qdct-2 */
     777             :             }
     778           0 :             pt1++;
     779           0 :             pt2++;
     780           0 :             pt3++;
     781             :         }
     782             : 
     783             :         /*scaling of hb_ener is q1; tonal_ener<hb_ener, so scaling of tonal_ener can be q1 too*/
     784           0 :         tonal_ener = round_fx( L_shr( L_tmp, sub( shl( qdct, 1 ), add( q1, 18 ) ) ) );
     785           0 :         tmp = sub( hb_ener, tonal_ener );                          /*q1 */
     786           0 :         tmp1 = round_fx( L_shl( L_mult( beta, tonal_ener ), 1 ) ); /*q1 */
     787           0 :         tmp1 = sub( hb_ener, tmp1 );                               /*q1 */
     788           0 :         tmp = div_s( tmp, s_max( tmp1, 1 ) );                      /*Q15 */
     789           0 :         g = shl( mult( beta, tmp ), 1 );                           /*Q15 */
     790           0 :         q2 = norm_s( g );
     791           0 :         inv_g = div_s( shl( 1, sub( 14, q2 ) ), g ); /*Q(29-q2-15); */
     792           0 :         inv_g = shl( inv_g, sub( q2, 2 ) );          /*Q12 */
     793           0 :         pt1 = hb_tonal;
     794           0 :         pt2 = hb_amb;
     795           0 :         pt3 = &dct_hb[240];
     796           0 :         pt4 = signum;
     797           0 :         FOR( i = 0; i < L_SUBFR16k; i++ )
     798             :         {
     799           0 :             IF( *pt1 > 0 )
     800             :             {
     801           0 :                 *pt1 = mult_r( *pt1, g ); /*qdct  */
     802           0 :                 move16();
     803             :             }
     804           0 :             *pt2 = round_fx_sat( L_shl_sat( L_mult( *pt2, inv_g ), 3 ) ); /*qdct */
     805           0 :             move16();
     806           0 :             *pt3 = add_sat( *pt1, *pt2 );
     807           0 :             move16();
     808           0 :             *pt3 = extract_l( L_mult0( *pt3, *pt4 ) ); /*qdct   */
     809           0 :             move16();
     810           0 :             pt1++;
     811           0 :             pt2++;
     812           0 :             pt3++;
     813           0 :             pt4++;
     814             :         }
     815             : 
     816           0 :         ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q2, L_SUBFR16k ); /* q2 */
     817           0 :         scale = div_s( shl( 1, 14 ), hb_ener );                                              /*Q(29-q1) */
     818           0 :         L_tmp = L_mult( ener, scale );                                                       /*30-q1+q2 */
     819           0 :         q2 = sub( q1, q2 );                                                                  /*30-q2 */
     820           0 :         scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) );                          /*Q12  */
     821           0 :         scale = round_fx_sat( L_shl_sat( L_mult( scale, gamma ), 4 ) );                      /*Q15 */
     822             :     }
     823             :     ELSE
     824             :     {
     825           0 :         scale = 32767; /*~1 in Q15 */
     826           0 :         move16();
     827             :     }
     828             : 
     829           0 :     IF( EQ_32( core_brate, ACELP_6k60 ) )
     830             :     {
     831           0 :         filt_weight_coeff = 60; /* Q0 */
     832           0 :         move16();
     833           0 :         rev_filt_weight_coeff = 555;
     834           0 :         move16(); /* 1/(filt_weight_coeff-1) Q15 */
     835             :     }
     836           0 :     ELSE IF( EQ_32( core_brate, ACELP_8k85 ) )
     837             :     {
     838           0 :         filt_weight_coeff = 40; /* Q0 */
     839           0 :         move16();
     840           0 :         rev_filt_weight_coeff = 840; /* 1/(filt_weight_coeff-1) Q15 */
     841           0 :         move16();
     842             :     }
     843             :     ELSE
     844             :     {
     845           0 :         filt_weight_coeff = 20; /* Q0 */
     846           0 :         move16();
     847           0 :         rev_filt_weight_coeff = 1725; /* 1/(filt_weight_coeff-1) Q15 */
     848           0 :         move16();
     849             :     }
     850             : 
     851           0 :     pt1 = filt_weight;
     852           0 :     FOR( i = 0; i < filt_weight_coeff; i++ )
     853             :     {
     854           0 :         L_tmp = L_mult( -32735, rev_filt_weight_coeff ); /*Q31 */
     855           0 :         L_tmp = L_shl( Mult_32_16( L_tmp, i ), 14 );     /*Q16+14 */
     856           0 :         *pt1++ = add( round_fx( L_tmp ), 16384 );
     857           0 :         move16(); /*Q14 */
     858             :     }
     859             : 
     860           0 :     IF( EQ_32( core_brate, ACELP_23k85 ) )
     861             :     {
     862           0 :         pt1 = dct_hb + 240;
     863           0 :         tmp = sub( filt_weight_coeff, 80 ); /* Q0 */
     864           0 :         pt3 = filt_weight + tmp;
     865           0 :         FOR( i = 240; i < L_FRAME16k; i++ )
     866             :         {
     867           0 :             *pt1 = mult_r( *pt1, scale ); /*qdct */
     868           0 :             move16();
     869             : 
     870           0 :             IF( GE_16( i, sub( L_FRAME16k, filt_weight_coeff ) ) )
     871             :             {
     872           0 :                 *pt1 = round_fx( L_shl( L_mult( *pt3, *pt1 ), 1 ) ); /*qdct */
     873           0 :                 move16();
     874             :             }
     875           0 :             pt1++;
     876           0 :             pt3++;
     877             :         }
     878           0 :         pt1 = dct_hb + 200;
     879           0 :         pt6 = filt_hp_fx;
     880           0 :         FOR( i = 200; i < 256; i++ )
     881             :         {
     882           0 :             *pt1 = mult_r( *pt6++, *pt1 );
     883           0 :             move16(); /*qdct */
     884           0 :             pt1++;
     885             :         }
     886           0 :         pt1 = HF_corr_gain;
     887           0 :         pt6 = hf_gain;
     888           0 :         FOR( i = 0; i < NB_SUBFR; i++ )
     889             :         {
     890           0 :             tmp = *pt6++;
     891           0 :             move16();
     892           0 :             *pt1++ = HP_gain_fx[tmp]; /* Q15 */
     893           0 :             move16();
     894             :         }
     895             :     }
     896             :     ELSE
     897             :     {
     898           0 :         pt1 = dct_hb + 240;
     899           0 :         tmp = sub( filt_weight_coeff, 80 ); /* Q0 */
     900           0 :         pt3 = filt_weight + tmp;
     901           0 :         FOR( i = 240; i < L_FRAME16k; i++ )
     902             :         {
     903           0 :             *pt1 = mult_r( *pt1, scale ); /*qdct */
     904           0 :             IF( GT_16( i, 255 ) )
     905             :             {
     906           0 :                 *pt1 = mult_r( 19505 /* 0.6 in Q15 */, *pt1 );
     907           0 :                 move16();
     908             :             }
     909             : 
     910           0 :             IF( GE_16( i, sub( L_FRAME16k, filt_weight_coeff ) ) )
     911             :             {
     912           0 :                 *pt1 = round_fx( L_shl( L_mult( *pt3, *pt1 ), 1 ) ); /*qdct */
     913           0 :                 move16();
     914             :             }
     915           0 :             pt1++;
     916           0 :             pt3++;
     917             :         }
     918             : 
     919           0 :         pt1 = dct_hb + 200;
     920           0 :         pt6 = filt_hp_fx;
     921           0 :         pt7 = deem_tab_fx; /* Q15 */
     922           0 :         FOR( i = 200; i < 256; i++ )
     923             :         {
     924           0 :             *pt1 = mult_r( *pt6++, *pt1 );
     925           0 :             move16(); /*qdct */
     926           0 :             *pt1 = mult_r( *pt7++, *pt1 );
     927           0 :             move16(); /* qdct */
     928           0 :             pt1++;
     929             :         }
     930             :     }
     931             : 
     932           0 :     q_tmp = Exp16Array( L_FRAME16k, dct_hb );
     933           0 :     qhf = sub( q_tmp, 1 );
     934           0 :     Copy_Scale_sig_16_32_DEPREC( dct_hb, dct_hb32, L_FRAME16k, qhf ); /* qhf + qdct */
     935           0 :     qhf = add( qhf, qdct );
     936           0 :     edct_fx( dct_hb32, exc16k32, L_FRAME16k, &qhf );
     937           0 :     q_tmp = Exp32Array( L_FRAME16k, exc16k32 );
     938           0 :     q_tmp = sub( q_tmp, 16 );
     939           0 :     Copy_Scale_sig_32_16( exc16k32, exc16k, L_FRAME16k, q_tmp ); /* qhf + qtmp */
     940           0 :     qhf = add( qhf, q_tmp );
     941             : 
     942           0 :     ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_FRAME );
     943           0 :     tmp = dot_prod_satcontr( exc16k, exc16k, qhf, qhf, &q2, L_FRAME16k );
     944             : 
     945           0 :     pt6 = exc;
     946           0 :     pt2 = exc16k;
     947             : 
     948           0 :     FOR( i = 0; i < NB_SUBFR; i++ )
     949             :     {
     950           0 :         e_subfr1 = dot_prod_satcontr( pt6, pt6, Q_exc, Q_exc, &q3, L_SUBFR );
     951           0 :         e_subfr2 = dot_prod_satcontr( pt2, pt2, qhf, qhf, &q4, L_SUBFR16k );
     952             : 
     953           0 :         L_tmp = L_mult( e_subfr1, tmp ); /*Q(q2+q3+1) */
     954           0 :         q3 = add( add( q2, q3 ), 1 );
     955           0 :         shift = norm_l( L_tmp );
     956           0 :         L_tmp = L_shl( L_tmp, shift ); /*Q(q3+shift); */
     957           0 :         q3 = add( q3, shift );
     958           0 :         scale = round_fx_sat( L_tmp ); /*Q(q3-16); */
     959           0 :         q3 = sub( q3, 16 );
     960           0 :         scale = div_s( shl( 1, 14 ), scale ); /*Q(29-q3)  */
     961           0 :         L_tmp = L_mult( scale, ener );        /*Q(29-q3+q1+1) */
     962           0 :         shift = norm_l( L_tmp );
     963           0 :         L_tmp = L_shl( L_tmp, shift );     /*Q(29-q3+q1+1+shift) */
     964           0 :         scale = round_fx_sat( L_tmp );     /*Q(29-q3+q1+1+shift-16) */
     965           0 :         L_tmp = L_mult( scale, e_subfr2 ); /*Q(29-q3+q1+1+shift-16+q4+1)=Q(15+q1-q3+q4+shift) */
     966           0 :         q3 = sub( 15, q3 );
     967           0 :         q3 = add( q3, q1 );
     968           0 :         q3 = add( q3, shift );
     969           0 :         q3 = add( q3, q4 );
     970           0 :         scale = round_fx_sat( Isqrt( L_shl_sat( L_tmp, sub( 6, q3 ) ) ) ); /*Q12 */
     971           0 :         pt6 += L_SUBFR;
     972           0 :         FOR( j = 0; j < L_SUBFR16k; j++ )
     973             :         {
     974           0 :             *pt2 = round_fx_sat( L_shl_sat( L_mult( *pt2, scale ), 2 ) ); /*qhf-1 */
     975           0 :             move16();
     976           0 :             pt2++;
     977             :         }
     978             :     }
     979           0 :     qhf = sub( qhf, 1 );
     980             : 
     981           0 :     p_Ap = Ap;
     982           0 :     pt1 = exc16k;
     983           0 :     pt2 = synth_out;
     984           0 :     pt3 = sub_gain;
     985           0 :     pt4 = HF_corr_gain;
     986           0 :     pt5 = til0;
     987           0 :     pt6 = voice_factors;
     988           0 :     pt7 = exc;
     989             : 
     990           0 :     FOR( i = 0; i < NB_SUBFR; i++ )
     991             :     {
     992           0 :         hf_synthesis_amr_wb_fx( core_brate, output_subfr, p_Ap, pt1, pt2, hBWE_zero->mem_syn_hf_fx, hBWE_zero->delay_syn_hf_fx,
     993           0 :                                 hBWE_zero->mem_hp_interp_fx, *pt3, *pt4, *pt5, *pt6, pt7, Q_exc, Q_out, qhf );
     994           0 :         p_Ap += ( M + 1 );
     995           0 :         pt1 += L_SUBFR16k;
     996           0 :         pt2 += output_subfr;
     997           0 :         pt3++;
     998           0 :         pt4++;
     999           0 :         pt5++;
    1000           0 :         pt6++;
    1001           0 :         pt7 += L_SUBFR;
    1002             :     }
    1003             : 
    1004           0 :     return;
    1005             : }
    1006           0 : static void hf_synthesis_amr_wb_fx(
    1007             :     const Word32 core_brate,   /* i  : core bitrate :                                           Q0*/
    1008             :     const Word16 output_subfr, /* i  : output sub-frame length :                        Q0*/
    1009             :     const Word16 Ap[],         /* i  : quantized Aq :                                      Q12*/
    1010             :     Word16 exc16k[],           /* i  : excitation at 16 kHz :                      qhf*/
    1011             :     Word16 synth_out[],        /* i/o: synthesis signal at output Fs :   Q_out*/
    1012             :     Word16 *mem_syn_hf,        /* i/o: HF synthesis memory :                     Q_out*/
    1013             :     Word16 *delay_syn_hf,      /* i/o: HF synthesis memory :                     Q_out*/
    1014             :     Word16 *mem_hp_interp,     /* i/o: interpol. memory  :                               Q_out*/
    1015             :     Word16 p_r,                /* i  : sub-frame gain :                                    Q12*/
    1016             :     Word16 HF_corr_gain,       /* i  : HF gain index :                                     Q14*/
    1017             :     Word16 til,                /* Q14 */
    1018             :     Word16 voice_factors,      /* Q14 */
    1019             :     const Word16 exc[],        /* i  : excitation at 12.8 kHz :                   Qexc*/
    1020             :     const Word16 Q_exc,        /*exc scaling*/
    1021             :     const Word16 Q_out,        /*synth_out scaling*/
    1022             :     Word16 qhf                 /*exc16k scaling*/
    1023             : )
    1024             : {
    1025             :     Word16 i;
    1026             :     Word16 HF_syn[L_SUBFR16k], upsampled_HF_syn[L_SUBFR48k];
    1027             :     Word16 ener, tmp, scale, exc2385[L_SUBFR16k];
    1028             :     Word32 L_tmp;
    1029             :     Word16 q1, q2, q3, shift;
    1030             :     Word16 *pt1, *pt2, flag;
    1031           0 :     IF( EQ_32( core_brate, ACELP_23k85 ) )
    1032             :     {
    1033           0 :         ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_SUBFR );
    1034           0 :         tmp = dot_prod_satcontr( exc16k, exc16k, qhf, qhf, &q2, L_SUBFR16k );
    1035             : 
    1036           0 :         L_tmp = L_mult( ener, 6554 /* 0.2 in Q15 */ ); /*Q(q1+16) */
    1037           0 :         q3 = norm_l( L_tmp );
    1038           0 :         L_tmp = L_shl( L_tmp, q3 ); /*Q(q1+q3+16) */
    1039           0 :         ener = extract_h( L_tmp );  /*Q(q1+q3); */
    1040           0 :         q1 = add( q1, q3 );
    1041             : 
    1042           0 :         scale = div_s( shl( 1, 14 ), ener );                                /*Q(29-q1) */
    1043           0 :         L_tmp = L_mult( tmp, scale );                                       /*30-q1+q2 */
    1044           0 :         q2 = sub( q1, q2 );                                                 /*30-q2 */
    1045           0 :         scale = round_fx_sat( Isqrt( L_shl_sat( L_tmp, sub( q2, 24 ) ) ) ); /*Q12  */
    1046           0 :         pt1 = exc16k;
    1047           0 :         pt2 = exc2385;
    1048           0 :         FOR( i = 0; i < L_SUBFR16k; i++ )
    1049             :         {
    1050           0 :             L_tmp = L_mult( *pt1++, HF_corr_gain ); /*qhf+15*/
    1051           0 :             L_tmp = Mult_32_16( L_tmp, scale );     /*qhf-1+12+1*/
    1052           0 :             *pt2++ = round_fx( L_shl( L_tmp, 1 ) ); /*qhf-3*/
    1053           0 :             move16();
    1054             :         }
    1055             : 
    1056           0 :         pt1 = exc16k;
    1057           0 :         FOR( i = 0; i < L_SUBFR16k; i++ )
    1058             :         {
    1059           0 :             *pt1 = mult_r( *pt1, p_r ); /*qhf-3*/
    1060           0 :             move16();
    1061           0 :             pt1++;
    1062             :         }
    1063             : 
    1064           0 :         qhf = sub( qhf, 3 );
    1065             : 
    1066           0 :         ener = dot_prod_satcontr( exc16k, exc16k, qhf, qhf, &q1, L_SUBFR16k );
    1067           0 :         tmp = dot_prod_satcontr( exc2385, exc2385, qhf, qhf, &q2, L_SUBFR16k );
    1068           0 :         L_tmp = L_mult( ener, 9830 ); /*Q(q1+16) */
    1069           0 :         q3 = norm_l( L_tmp );
    1070           0 :         L_tmp = L_shl( L_tmp, q3 ); /*Q(q1+q3+16) */
    1071           0 :         ener = extract_h( L_tmp );  /*Q(q1+q3); */
    1072           0 :         q1 = add( q1, q3 );
    1073             : 
    1074           0 :         scale = div_s( shl( 1, 14 ), ener );                                /*Q(29-q1) */
    1075           0 :         L_tmp = L_mult( tmp, scale );                                       /*30-q1+q2 */
    1076           0 :         q2 = sub( q1, q2 );                                                 /*30-q2 */
    1077           0 :         scale = round_fx_sat( Isqrt( L_shl_sat( L_tmp, sub( q2, 24 ) ) ) ); /*Q12  */
    1078           0 :         flag = negate( s_and( til, -0x8000 ) );
    1079           0 :         if ( GT_16( scale, 4096 /* 1.0f in Q12 */ ) )
    1080             :         {
    1081           0 :             flag = 1;
    1082           0 :             move16();
    1083             :         }
    1084           0 :         IF( flag )
    1085             :         {
    1086           0 :             Copy( exc2385, exc16k, L_SUBFR16k ); /* qhf */
    1087             :         }
    1088             :         ELSE
    1089             :         {
    1090           0 :             pt1 = exc16k;
    1091           0 :             pt2 = exc2385;
    1092           0 :             FOR( i = 0; i < L_SUBFR16k; i++ )
    1093             :             {
    1094           0 :                 tmp = sub( 16348 /* 1 in Q14 */, shl( til, 1 ) );                               /*Q14 */
    1095           0 :                 L_tmp = L_mult( tmp, sub( 26214 /* 1.6f in Q14 */, shr( voice_factors, 1 ) ) ); /*Q29*/
    1096           0 :                 tmp = round_fx( L_shr( L_tmp, 1 ) );                                            /*Q12*/
    1097           0 :                 tmp = s_min( tmp, 4096 /* 1 in Q12 */ );
    1098           0 :                 tmp = s_max( tmp, scale );
    1099           0 :                 *pt1++ = round_fx( L_shl( L_mult( *pt2++, tmp ), 3 ) ) /*qhf*/;
    1100           0 :                 move16();
    1101             :             }
    1102             :         }
    1103             :     }
    1104             :     ELSE
    1105             :     {
    1106           0 :         pt1 = exc16k;
    1107           0 :         FOR( i = 0; i < L_SUBFR16k; i++ )
    1108             :         {
    1109           0 :             *pt1 = mult_r( *pt1, p_r ); /*qhf-3*/
    1110           0 :             move16();
    1111           0 :             pt1++;
    1112             :         }
    1113             : 
    1114           0 :         qhf = sub( qhf, 3 );
    1115             :     }
    1116             : 
    1117           0 :     shift = sub( qhf, Q_out );
    1118           0 :     Syn_filt_s( shift, Ap, M, exc16k, HF_syn, L_SUBFR16k, mem_syn_hf, 1 ); /*Q_out=qhf-shift */
    1119             : 
    1120             :     /*-----------------------------------------------------------------*
    1121             :      * Resample to output sampling rate
    1122             :      * Synchronize LB and HB components (delay componsation)
    1123             :      * Add synthesised high band to speech synthesis
    1124             :      *-----------------------------------------------------------------*/
    1125             : 
    1126           0 :     delay_signal_fx( HF_syn, L_SUBFR16k, delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) );
    1127             : 
    1128           0 :     IF( EQ_16( output_subfr, L_SUBFR48k ) ) /* 48kHz sampled output */
    1129             :     {
    1130             :         Word16 s;
    1131           0 :         s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, INTERP_3_1_MEM_LEN - 3 ) ), 3 ),
    1132           0 :                           sub( Find_Max_Norm16( mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ),
    1133             :                    0 );
    1134           0 :         Scale_sig( HF_syn, L_SUBFR16k, s );                /* Qout + s */
    1135           0 :         Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); /* Qout + s */
    1136             : 
    1137           0 :         interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp );
    1138             : 
    1139           0 :         Scale_sig( upsampled_HF_syn, L_SUBFR48k, add( -s, -1 ) ); /* Qout - 1 */
    1140           0 :         Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s );       /* Qout */
    1141           0 :         Scale_sig( HF_syn, L_SUBFR16k, -s );                      /* Qout */
    1142             :     }
    1143           0 :     ELSE IF( EQ_16( output_subfr, L_SUBFR32k ) ) /* 32kHz sampled output */
    1144             :     {
    1145             :         Word16 s;
    1146           0 :         s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 );
    1147           0 :         Scale_sig( HF_syn, L_SUBFR16k, s );                       /* Qout + s */
    1148           0 :         Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qout + s */
    1149             : 
    1150           0 :         Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn );
    1151             : 
    1152           0 :         Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s );         /* Qout */
    1153           0 :         Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qout */
    1154           0 :         Scale_sig( HF_syn, L_SUBFR16k, -s );                       /* Qout */
    1155             :     }
    1156             :     ELSE /* 16kHz sampled output */
    1157             :     {
    1158           0 :         Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Qout */
    1159             :     }
    1160             : 
    1161           0 :     Vr_add( synth_out, upsampled_HF_syn, synth_out, output_subfr );
    1162             : 
    1163           0 :     return;
    1164             : }
    1165             : 
    1166           0 : static Word16 EnhanceClass_fx(
    1167             :     const Word16 qq_fx,           /* Qx */
    1168             :     const Word16 pp_fx,           /* Qx */
    1169             :     const Word16 tilt0_fx,        /* i  : spectrum tilt                Q13*/
    1170             :     const Word16 tilt_fx,         /* i  : spectrum tilt                Q13*/
    1171             :     const Word16 voice_factor_fx, /* i  : voice factor                 Q15*/
    1172             :     Word16 *voice_fac_fx,         /* i/o: smoothed voiced parameter    Q15*/
    1173             :     Word16 *unvoicing_fx,         /* i/o: unvoiced parameter           Q15*/
    1174             :     Word16 *unvoicing_sm_fx,      /* i/o: smoothed unvoiced parameter  Q15*/
    1175             :     Word16 *unvoicing_flag        /* i/o: unvoiced flag                Q0*/
    1176             : )
    1177             : {
    1178             :     Word16 unvoicing_tmp_fx;
    1179             :     Word16 tmp, tmp1;
    1180             :     Word32 L_tmp;
    1181             :     Flag Overflow;
    1182             : 
    1183             : 
    1184             :     /* Decide (*unvoicing_flag) to allow BWE enhancement when qq>pp */
    1185             :     /**voice_fac_fx = add(mult_r(*voice_fac_fx, 24576), mult_r(voice_factor_fx, 8192));  //Q15 */
    1186           0 :     *voice_fac_fx = round_fx( L_mac( L_mult( *voice_fac_fx, 24576 /* 0.75 in Q15 */ ), voice_factor_fx, 8192 /* 0.25 in Q15 */ ) ); /*Q15 */
    1187           0 :     move16();
    1188             : 
    1189           0 :     tmp = mult_r( sub( 8192 /* 1.0f in Q13 */, tilt0_fx ), 16384 /* 1.0f in Q15 */ ); /*Q13 */
    1190             : 
    1191           0 :     L_tmp = L_sub( 32768 /* 1.0 in Q15 */, *voice_fac_fx ); /*Q15 */
    1192             : 
    1193           0 :     L_tmp = Mult_32_16( L_tmp, tmp ); /*Q13 */
    1194           0 :     tmp = extract_l( L_tmp );         /*Q13 */
    1195             : 
    1196           0 :     tmp1 = mult_r( tilt_fx, 21845 ); /*Q15->1/1.5 ->Q13+15-15->Q13 */
    1197           0 :     tmp1 = s_min( tmp1, 8192 /* 1.0f in Q13 */ );
    1198             : 
    1199           0 :     L_tmp = L_mult( tmp, tmp1 );                        /*Q13+Q13+1 */
    1200           0 :     unvoicing_tmp_fx = extract_l( L_shr( L_tmp, 12 ) ); /*Q15 */
    1201             : 
    1202             :     /**unvoicing_fx = add(mult_r(16384, *unvoicing_fx), mult_r(16384, unvoicing_tmp_fx));  //Q15 */
    1203           0 :     *unvoicing_fx = round_fx( L_mac( L_mult( 16384 /* 0.5 in Q15 */, *unvoicing_fx ), 16384 /* 0.5 in Q15 */, unvoicing_tmp_fx ) ); /*Q15 */
    1204           0 :     move16();
    1205             : 
    1206           0 :     IF( GT_16( *unvoicing_sm_fx, *unvoicing_fx ) )
    1207             :     {
    1208             :         /**unvoicing_sm_fx = add(mult_r(29491, *unvoicing_sm_fx), mult_r(3277, *unvoicing_fx));  //Q15 */
    1209           0 :         *unvoicing_sm_fx = round_fx( L_mac( L_mult( 29491 /* 0.9 in Q15 */, *unvoicing_sm_fx ), 3277 /* 0.1 in Q15 */, *unvoicing_fx ) ); /*Q15 */
    1210           0 :         move16();
    1211             :     }
    1212             :     ELSE
    1213             :     {
    1214             :         /**unvoicing_sm_fx = add(mult_r(32440, *unvoicing_sm_fx), mult_r(328, *unvoicing_fx));  //Q15 */
    1215           0 :         *unvoicing_sm_fx = round_fx( L_mac( L_mult( 32440 /* 0.99 in Q15 */, *unvoicing_sm_fx ), 328 /* 0.01 in Q15 */, *unvoicing_fx ) ); /*Q15 */
    1216           0 :         move16();
    1217             :     }
    1218             : 
    1219           0 :     if ( GT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 3277 /* 0.1 in Q15 */ ) )
    1220             :     {
    1221           0 :         *unvoicing_flag = 1;
    1222           0 :         move16();
    1223             :     }
    1224             : 
    1225           0 :     if ( LT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 1638 /* 0.05 in Q15 */ ) )
    1226             :     {
    1227           0 :         *unvoicing_flag = 0;
    1228           0 :         move16();
    1229             :     }
    1230           0 :     test();
    1231           0 :     return ( *unvoicing_flag && GT_16( qq_fx, pp_fx ) );
    1232             : }
    1233             : 
    1234           0 : static void envelope_fx(
    1235             :     AMRWB_IO_DEC_HANDLE hAmrwb_IO,
    1236             :     const Word32 core_brate,    /* i  : core bitrate                                                              Q0*/
    1237             :     const Word16 Aq_dyn_scal[], /* i  : de-quant. LPC coefficents, dynamic scaling       Q12*/
    1238             :     Word16 Ap[],                /* o  : extended LPC coefficents,                                        Q12*/
    1239             :     Word16 *sub_gain,           /* o  : sub-frame gain,                                                          Q12*/
    1240             :     Word16 tilt0,               /* i  : spectrum tilt,                                                           Q14*/
    1241             :     Word16 tilt,                /* i  : spectrum tilt,                                                           Q13*/
    1242             :     Word16 voice_factor         /* i  : voice factor,                                                            Q15*/
    1243             : )
    1244             : {
    1245             : 
    1246             :     Word16 px, py, rx, ry, pp, rr, qx, qy, qq; /*Q10*/
    1247             :     Word16 i, Unvoicing_flag;
    1248             :     Word16 alpha;                  /*Q14*/
    1249             :     Word16 est_level1, est_level2; /*Q10*/
    1250             :     Word32 L_tmp;
    1251             :     Word16 tmp, q1, q2, q3, shift;
    1252             :     Word16 As[3], k1, k2;
    1253             :     Word16 *pt1;
    1254             :     const Word16 *pt2, *pt3;
    1255             :     Word16 Aq[M + 1];
    1256             : 
    1257             : 
    1258             :     /* Aq has dynamic scaling
    1259             :       go back to Q12 to make sure there's no overflow while calculating qx,qy*/
    1260           0 :     shift = sub( norm_s( Aq_dyn_scal[0] ), 2 );
    1261           0 :     Copy_Scale_sig( Aq_dyn_scal, Aq, M + 1, shift ); /* Q12 + shift */
    1262             : 
    1263             :     /* LPC envelope weighting */
    1264           0 :     IF( EQ_32( core_brate, ACELP_6k60 ) )
    1265             :     {
    1266           0 :         weight_a_lc_fx( Aq, Ap, Gamma_29491_Tbl, M );
    1267             :     }
    1268             :     ELSE
    1269             :     {
    1270           0 :         weight_a_lc_fx( Aq, Ap, Gamma_19661_Tbl_fx, M );
    1271             :     }
    1272             :     /* Ap has dynamic scaling
    1273             :       go back to Q12 to make sure there's no overflow while calculating px,py*/
    1274           0 :     shift = sub( norm_s( Ap[0] ), 2 );
    1275           0 :     IF( shift != 0 )
    1276             :     {
    1277           0 :         Scale_sig( Ap, M + 1, shift ); /* Q12 + shift */
    1278             :     }
    1279             : 
    1280             :     /* LPC envelope level estimate */
    1281           0 :     L_tmp = 0;
    1282           0 :     move32();
    1283           0 :     pt1 = Ap;           /* Q12 */
    1284           0 :     pt2 = exp_tab_p_fx; /* Q14 */
    1285           0 :     FOR( i = 0; i <= M; i++ )
    1286             :     {
    1287           0 :         L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); /* Q27 */
    1288             :     }
    1289           0 :     q1 = norm_l( L_tmp );
    1290           0 :     L_tmp = L_shl( L_tmp, q1 );         /*Q(27+q1)*/
    1291           0 :     px = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/
    1292             : 
    1293           0 :     L_tmp = L_deposit_l( 0 );
    1294             : 
    1295           0 :     pt1 = Ap;                /* Q12 */
    1296           0 :     pt2 = exp_tab_p_fx + 33; /* Q14 */
    1297           0 :     FOR( i = 0; i <= M; i++ )
    1298             :     {
    1299           0 :         L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); /* Q27 */
    1300             :     }
    1301           0 :     q2 = norm_l( L_tmp );
    1302           0 :     shift = sub( q1, q2 );
    1303           0 :     IF( shift >= 0 )
    1304             :     {
    1305           0 :         px = shr( px, shift );
    1306           0 :         L_tmp = L_shl( L_tmp, q2 ); /*Q(27+q2)*/
    1307           0 :         q1 = q2;
    1308           0 :         move16();
    1309             :     }
    1310             :     ELSE
    1311             :     {
    1312           0 :         L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/
    1313             :     }
    1314           0 :     py = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/
    1315             : 
    1316           0 :     L_tmp = L_deposit_l( 0 );
    1317           0 :     pt2 = Aq;           /* Q12 */
    1318           0 :     pt3 = exp_tab_q_fx; /* Q14 */
    1319           0 :     FOR( i = 0; i <= M; i++ )
    1320             :     {
    1321           0 :         L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3++ ); /* Q27 */
    1322             :     }
    1323           0 :     q2 = norm_l( L_tmp );
    1324           0 :     L_tmp = L_shl( L_tmp, q2 );         /*Q(27+q2)*/
    1325           0 :     rx = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q2)*/
    1326             : 
    1327           0 :     L_tmp = L_deposit_l( 0 );
    1328           0 :     pt2 = Aq;                /* Q12 */
    1329           0 :     pt3 = exp_tab_q_fx + 33; /* Q14 */
    1330           0 :     FOR( i = 0; i <= M; i++ )
    1331             :     {
    1332           0 :         L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3-- ); /* Q14 */
    1333             :     }
    1334           0 :     q3 = norm_l( L_tmp );
    1335           0 :     shift = sub( q2, q3 );
    1336           0 :     IF( shift >= 0 )
    1337             :     {
    1338           0 :         rx = shr( rx, shift );
    1339           0 :         L_tmp = L_shl( L_tmp, q3 ); /*Q(27+q3)*/
    1340           0 :         q2 = q3;
    1341           0 :         move16();
    1342             :     }
    1343             :     ELSE
    1344             :     {
    1345           0 :         L_tmp = L_shl( L_tmp, q2 ); /*Q(27+q2)*/
    1346             :     }
    1347           0 :     ry = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q2)*/
    1348             : 
    1349           0 :     L_tmp = L_mult( px, px );
    1350           0 :     L_tmp = L_mac( L_tmp, py, py );                                        /*Q(21+2*q1)*/
    1351           0 :     pp = round_fx_sat( Isqrt( L_shr( L_tmp, add( 11, shl( q1, 1 ) ) ) ) ); /*Q10*/
    1352           0 :     L_tmp = L_mult( rx, rx );
    1353           0 :     L_tmp = L_mac( L_tmp, ry, ry );                                        /*Q(21+2*q1)*/
    1354           0 :     rr = round_fx_sat( Isqrt( L_shr( L_tmp, add( 11, shl( q2, 1 ) ) ) ) ); /*Q10*/
    1355           0 :     Copy( Aq, As, 3 );
    1356           0 :     IF( EQ_16( shr( As[2], 1 ), -2048 /* -1.0f in Q11 */ ) )
    1357             :     {
    1358           0 :         k2 = -2458; /* -0.6f in Q12 */
    1359           0 :         move16();
    1360           0 :         k1 = 4055; /* 0.99f in Q12 */
    1361           0 :         move16();
    1362           0 :         if ( As[1] < 0 )
    1363             :         {
    1364           0 :             k1 = -k1; /* Q12 */
    1365           0 :             move16();
    1366             :         }
    1367             :     }
    1368             :     ELSE
    1369             :     {
    1370           0 :         k1 = add( 2048 /* 1 in Q11 */, shr( As[2], 1 ) ); /*Q11 */
    1371           0 :         q1 = 11;
    1372           0 :         move16();
    1373           0 :         q2 = norm_s( k1 );
    1374           0 :         k1 = ( shl( k1, q2 ) ); /*q1+q2 */
    1375           0 :         tmp = abs_s( k1 );
    1376           0 :         q1 = add( q1, q2 );
    1377           0 :         tmp = div_s( shl( 1, 14 ), tmp ); /*Q(29-q1) */
    1378           0 :         if ( k1 < 0 )
    1379             :         {
    1380           0 :             tmp = negate( tmp );
    1381             :         }
    1382             : 
    1383           0 :         L_tmp = L_mult( As[1], tmp ); /*Q(42-q1) */
    1384           0 :         q1 = sub( q1, 14 );
    1385           0 :         k1 = round_fx_sat( L_shl_sat( L_tmp, q1 ) ); /*Q12 */
    1386           0 :         k2 = As[2];
    1387           0 :         move16(); /*Q12 */
    1388           0 :         if ( GT_16( k2, 2458 /* 0.6f in Q12 */ ) )
    1389             :         {
    1390           0 :             k2 = 2458; /* 0.6f in Q12 */
    1391           0 :             move16();
    1392             :         }
    1393           0 :         if ( LT_16( k2, -2458 /* -0.6f in Q12 */ ) )
    1394             :         {
    1395           0 :             k2 = -2458; /* -0.6f in Q12 */
    1396           0 :             move16();
    1397             :         }
    1398           0 :         if ( GT_16( k1, 4055 /* 0.99f in Q12 */ ) )
    1399             :         {
    1400           0 :             k1 = 4055; /* 0.99f in Q12 */
    1401           0 :             move16();
    1402             :         }
    1403           0 :         if ( LT_16( k1, -4055 /* -0.99f in Q12 */ ) )
    1404             :         {
    1405           0 :             k1 = -4055; /* -0.99f in Q12 */
    1406           0 :             move16();
    1407             :         }
    1408             :     }
    1409           0 :     As[1] = add( 4096 /* 1 in Q12 */, k2 );
    1410           0 :     move16();
    1411           0 :     L_tmp = L_mult( As[1], k1 );           /*Q25 */
    1412           0 :     As[1] = round_fx( L_shl( L_tmp, 3 ) ); /*Q12 */
    1413           0 :     move16();
    1414           0 :     As[2] = k2;
    1415           0 :     move16(); /*Q12 */
    1416             : 
    1417           0 :     L_tmp = L_deposit_l( 0 );
    1418           0 :     pt1 = As;           /* Q12 */
    1419           0 :     pt2 = exp_tab_q_fx; /* Q14 */
    1420           0 :     FOR( i = 0; i < 3; i++ )
    1421             :     {
    1422           0 :         L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); /* Q27 */
    1423             :     }
    1424           0 :     q1 = norm_l( L_tmp );
    1425           0 :     L_tmp = L_shl( L_tmp, q1 );         /*Q(27+q1)*/
    1426           0 :     qx = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/
    1427             : 
    1428             : 
    1429           0 :     L_tmp = L_deposit_l( 0 );
    1430           0 :     pt1 = As;                /* Q12 */
    1431           0 :     pt2 = exp_tab_q_fx + 33; /* Q14 */
    1432           0 :     FOR( i = 0; i < 3; i++ )
    1433             :     {
    1434           0 :         L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); /* Q27 */
    1435             :     }
    1436           0 :     q2 = norm_l( L_tmp );
    1437           0 :     shift = sub( q1, q2 );
    1438           0 :     IF( shift >= 0 )
    1439             :     {
    1440           0 :         qx = shr( qx, shift );
    1441           0 :         L_tmp = L_shl( L_tmp, q2 ); /*Q(27+q2)*/
    1442           0 :         q1 = q2;
    1443           0 :         move16();
    1444             :     }
    1445             :     ELSE
    1446             :     {
    1447           0 :         L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/
    1448             :     }
    1449           0 :     qy = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/
    1450             : 
    1451             : 
    1452           0 :     L_tmp = L_mult( qx, qx );                                          /* Q21 + 2q1 */
    1453           0 :     L_tmp = L_mac( L_tmp, qy, qy );                                    /* Q21 + 2q1 */
    1454           0 :     qq = round_fx( Isqrt( L_shr( L_tmp, add( 11, shl( q1, 1 ) ) ) ) ); /*Q10*/
    1455             : 
    1456           0 :     Unvoicing_flag = EnhanceClass_fx( rr, pp, tilt0, tilt, voice_factor, &hAmrwb_IO->voice_fac_amr_wb_hf, &hAmrwb_IO->unvoicing_fx, &hAmrwb_IO->unvoicing_sm_fx, &hAmrwb_IO->unvoicing_flag_fx ); /* Q0 */
    1457           0 :     alpha = 0;
    1458           0 :     move16();
    1459           0 :     IF( Unvoicing_flag )
    1460             :     {
    1461           0 :         IF( GT_16( rr, ( hAmrwb_IO->prev_r_fx ) ) )
    1462             :         {
    1463           0 :             rr = shr( add_sat( rr, ( hAmrwb_IO->prev_r_fx ) ), 1 );
    1464             :         }
    1465             : 
    1466           0 :         hAmrwb_IO->prev_r_fx = rr;
    1467           0 :         move16();
    1468             : 
    1469           0 :         L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/
    1470             : 
    1471           0 :         L_tmp = L_min( L_tmp, 268435456 /* 1 in Q28 */ );
    1472             : 
    1473           0 :         L_tmp = Mult_32_16( L_tmp, rr );                                                /*Q23*/
    1474           0 :         rr = round_fx( L_shl( L_tmp, 3 ) );                                             /*Q10*/
    1475           0 :         L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/
    1476           0 :         L_tmp = L_max( L_tmp, 268435456 /* 1 in Q28 */ );
    1477           0 :         L_tmp = Mult_32_16( L_tmp, qq );            /*Q23*/
    1478           0 :         qq = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); /*Q10*/
    1479           0 :         rr = s_min( rr, qq );                       /* Q10 */
    1480           0 :         rr = s_max( rr, pp );                       /* Q10 */
    1481             :     }
    1482             :     ELSE
    1483             :     {
    1484           0 :         test();
    1485           0 :         IF( LT_16( rr, 1024 /* 1 in Q10 */ ) && LT_16( ( hAmrwb_IO->prev_r_fx ), 1024 /* 1 in Q10 */ ) )
    1486             :         {
    1487           0 :             L_tmp = L_mult( rr, rr );                          /*Q21*/
    1488           0 :             tmp = round_fx( L_shl( L_tmp, 9 ) );               /*Q14*/
    1489           0 :             L_tmp = L_sub( 2097152 /* 1 in Q21 */, L_tmp );    /*Q21*/
    1490           0 :             alpha = round_fx( L_shl( L_tmp, 9 ) );             /*Q14*/
    1491           0 :             L_tmp = L_mult( alpha, ( hAmrwb_IO->prev_r_fx ) ); /*Q25*/
    1492           0 :             L_tmp = L_mac( L_tmp, tmp, rr );                   /*Q25*/
    1493           0 :             rr = round_fx_sat( L_shl_sat( L_tmp, 1 ) );        /*Q10*/
    1494             :         }
    1495             : 
    1496           0 :         hAmrwb_IO->prev_r_fx = rr;
    1497           0 :         move16();
    1498             : 
    1499           0 :         L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/
    1500             : 
    1501           0 :         L_tmp = L_min( L_tmp, 268435456 /* 1 in Q28 */ );
    1502           0 :         L_tmp = Mult_32_16( L_tmp, qq );            /*Q23*/
    1503           0 :         est_level1 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/
    1504             : 
    1505           0 :         tmp = pp;
    1506           0 :         move16();
    1507           0 :         tmp = s_min( tmp, qq );
    1508           0 :         rr = s_min( tmp, rr );
    1509             : 
    1510           0 :         L_tmp = L_mult( abs_s( sub( tilt, 8192 /* 1 in Q13 */ ) ), sub( 26214 /* 1.6 in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/
    1511           0 :         L_tmp = L_add( L_tmp, 268435456 /* 1 in Q28 */ );
    1512           0 :         L_tmp = Mult_32_16( L_tmp, rr );            /*Q23*/
    1513           0 :         est_level2 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/
    1514             : 
    1515           0 :         rr = s_min( est_level1, est_level2 );
    1516             :     }
    1517             : 
    1518             : 
    1519           0 :     q1 = norm_s( pp );
    1520           0 :     tmp = div_s( shl( 1, sub( 14, q1 ) ), pp ); /*Q(29-q1-10) */
    1521           0 :     L_tmp = L_mult( rr, tmp );                  /*Q(30-q1-10+10) */
    1522             : 
    1523           0 :     *sub_gain = s_min( 20480 /* 5.0f in Q12 */, round_fx_sat( L_shl_sat( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */
    1524           0 :     move16();
    1525           0 :     return;
    1526             : }
    1527             : 
    1528             : /*---------------------------------------------------------------------*
    1529             :  * AdaptiveStartBand_fx()
    1530             :  *
    1531             :  * adaptively select the start band of bandwidth extension
    1532             :  *---------------------------------------------------------------------*/
    1533             : 
    1534           0 : static void AdaptiveStartBand_fx(
    1535             :     Word16 *start_band,          /* o  : start point of copied band                Q0*/
    1536             :     const Word32 core_rate,      /* i  : core bitrate                              Q0*/
    1537             :     const Word16 *lsf_fx,        /* i  : lsf frequency                             Q2*/
    1538             :     const Word16 voicing_fac_fx, /* i  : voicing factors                          Q14*/
    1539             :     const Word16 clas,           /* i  : signal class (determined by FEC algorithm) Q0*/
    1540             :     Word16 *voicing_flag,        /* Q0 */
    1541             :     Word16 *start_band_old,      /* Q0 */
    1542             :     Word32 *OptCrit_old_fx       /*i/o : Q15 */
    1543             : )
    1544             : {
    1545             :     Word16 i, pos, M2, voicing_flag_old;
    1546             :     Word16 lsf_diff_fx[M];
    1547             :     Word16 W_fx;
    1548             :     Word16 tmp1, tmp2;
    1549             :     Word32 L_tmp;
    1550           0 :     Word32 OptCrit_fx = 32768, Crit_fx;
    1551             :     Word16 *pt1, flag;
    1552             :     const Word16 *pt2, *pt3;
    1553             : 
    1554           0 :     move32(); // corresponding to initialization of OptCrit_fx
    1555             :     /*voicing switching flag : to avoid switching start band frequently in VOICED or AUDIO area*/
    1556           0 :     voicing_flag_old = *voicing_flag; /* Q0 */
    1557           0 :     move16();
    1558           0 :     test();
    1559           0 :     test();
    1560           0 :     test();
    1561           0 :     if ( GT_16( voicing_fac_fx, 6554 /* 0.4 in Q14 */ ) || ( GT_16( voicing_fac_fx, 4915 /* 0.3 in Q14 */ ) && GE_16( clas, VOICED_CLAS ) ) || EQ_16( clas, AUDIO_CLAS ) )
    1562             :     {
    1563           0 :         *voicing_flag = 1; /* Q0 */
    1564           0 :         move16();
    1565             :     }
    1566             : 
    1567           0 :     test();
    1568           0 :     if ( LT_16( voicing_fac_fx, 3277 /* 0.2 in Q14 */ ) && LT_16( clas, VOICED_CLAS ) )
    1569             :     {
    1570           0 :         *voicing_flag = 0;
    1571           0 :         move16();
    1572             :     }
    1573             : 
    1574             :     /* core_rate adaptive start band */
    1575           0 :     *start_band = 160;
    1576           0 :     move16();
    1577           0 :     IF( LT_32( core_rate, ACELP_23k05 ) )
    1578             :     {
    1579           0 :         pt1 = lsf_diff_fx + 1;
    1580           0 :         pt2 = lsf_fx + 1;
    1581           0 :         pt3 = lsf_fx;
    1582           0 :         FOR( i = 1; i < ( M - 1 ); i++ )
    1583             :         {
    1584           0 :             *pt1++ = sub( *pt2++, *pt3++ );
    1585           0 :             move16(); /*Q2 */
    1586             :         }
    1587           0 :         tmp1 = extract_l( Mult_32_16( core_rate, 27046 /* 0.00005 in Q29 */ ) ); /*Q14 */
    1588           0 :         L_tmp = L_shr( L_mult0( tmp1, 22370 /* 1/6000 in Q27 */ ), 15 );         /*Q27->1/6000 ->Q26 */
    1589           0 :         tmp2 = extract_l( L_tmp );                                               /*Q26 */
    1590           0 :         W_fx = mult_r( tmp1, tmp2 );                                             /*Q25 */
    1591             : 
    1592           0 :         IF( EQ_16( clas, AUDIO_CLAS ) )
    1593             :         {
    1594           0 :             W_fx = mult_r( W_fx, 24576 /* 0.75 in Q15 */ ); /*Q25 */
    1595             :         }
    1596             : 
    1597           0 :         pos = 2;
    1598           0 :         move16();
    1599           0 :         M2 = M - 2;
    1600           0 :         move16();
    1601           0 :         IF( EQ_16( *voicing_flag, 1 ) )
    1602             :         {
    1603           0 :             IF( LE_32( core_rate, ACELP_8k85 ) )
    1604             :             {
    1605           0 :                 M2 = M - 8;
    1606           0 :                 move16();
    1607             :             }
    1608           0 :             ELSE IF( LE_32( core_rate, ACELP_12k65 ) )
    1609             :             {
    1610           0 :                 M2 = M - 6;
    1611           0 :                 move16();
    1612             :             }
    1613           0 :             ELSE IF( LE_32( core_rate, ACELP_15k85 ) )
    1614             :             {
    1615           0 :                 M2 = M - 4;
    1616           0 :                 move16();
    1617             :             }
    1618             :         }
    1619             : 
    1620             :         /*do the procedure for i==2*/
    1621           0 :         L_tmp = L_max( L_msu( 171798692 /* 1 in Q2.56+25+1 */, lsf_fx[2], W_fx ), 171799 /* 0.001 in Q2.56+25+1 */ ); /* Q2.56+25+1 */
    1622           0 :         Crit_fx = Mult_32_16( L_tmp, lsf_diff_fx[2] );                                                                /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */
    1623             : 
    1624           0 :         OptCrit_fx = L_add( Crit_fx, 0 );
    1625           0 :         pos = 2;
    1626           0 :         move16();
    1627             :         /*----------------------------------------------------------------*/
    1628             : 
    1629           0 :         pt2 = &lsf_fx[3];
    1630           0 :         pt1 = &lsf_diff_fx[3];
    1631           0 :         FOR( i = 3; i < M2; i++ )
    1632             :         {
    1633           0 :             L_tmp = L_max( L_msu( 171798692 /* 1 in Q2.56+25+1 */, *pt2++, W_fx ), 171799 /* 0.001 in Q2.56+25+1 */ ); /* Q2.56+25+1 */
    1634             : 
    1635           0 :             Crit_fx = Mult_32_16( L_tmp, *pt1++ ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */
    1636             : 
    1637           0 :             IF( LE_32( Crit_fx, OptCrit_fx ) )
    1638             :             {
    1639           0 :                 OptCrit_fx = L_add( Crit_fx, 0 ); /* Q11+2.56+2.56 */
    1640           0 :                 pos = i;                          /* Q0 */
    1641           0 :                 move16();
    1642             :             }
    1643             :         }
    1644             : 
    1645           0 :         tmp1 = add( mult_r( lsf_fx[pos - 1], 256 ), mult_r( lsf_fx[pos], 256 ) ); /* Q0 */
    1646           0 :         *start_band = s_min( s_max( sub( tmp1, 40 ), 40 ), 160 );                 /* Q0 */
    1647           0 :         move16();
    1648             : 
    1649           0 :         L_tmp = Mult_32_16( *OptCrit_old_fx, 22938 /* 0.7 in Q15 */ ); /* Q11+2.56+2.56 */
    1650           0 :         test();
    1651           0 :         test();
    1652           0 :         test();
    1653           0 :         test();
    1654           0 :         IF( NE_16( voicing_flag_old, *voicing_flag ) || ( *voicing_flag == 0 && LT_32( OptCrit_fx, *OptCrit_old_fx ) ) ||
    1655             :             ( LT_32( OptCrit_fx, L_tmp ) && GT_32( *OptCrit_old_fx, 858993 /* 64 in Q11+2.56+2.56 */ ) ) )
    1656             :         {
    1657           0 :             *OptCrit_old_fx = OptCrit_fx; /* Q15 */
    1658           0 :             move16();
    1659           0 :             test();
    1660           0 :             test();
    1661           0 :             if ( LT_16( abs_s( sub( ( *start_band ), ( *start_band_old ) ) ), 20 ) && EQ_16( *voicing_flag, 1 ) && EQ_16( voicing_flag_old, 1 ) )
    1662             :             {
    1663           0 :                 *start_band = *start_band_old; /* Q0 */
    1664           0 :                 move16();
    1665             :             }
    1666             :         }
    1667             :         ELSE
    1668             :         {
    1669           0 :             test();
    1670           0 :             if ( LT_32( OptCrit_fx, ( *OptCrit_old_fx ) ) && EQ_16( ( *voicing_flag ), 1 ) )
    1671             :             {
    1672           0 :                 *OptCrit_old_fx = OptCrit_fx; /* Q15 */
    1673           0 :                 move16();
    1674             :             }
    1675             : 
    1676           0 :             *start_band = *start_band_old; /* Q0 */
    1677           0 :             move16();
    1678             :         }
    1679             : 
    1680           0 :         IF( EQ_16( clas, AUDIO_CLAS ) )
    1681             :         {
    1682           0 :             *start_band = s_min( *start_band, 120 ); /* Q0 */
    1683           0 :             move16();
    1684             :         }
    1685             : 
    1686           0 :         flag = sub( s_and( *start_band, 0x0001 ), 1 );
    1687           0 :         IF( flag == 0 )
    1688             :         {
    1689           0 :             *start_band = sub( *start_band, 1 ); /* Q0 */
    1690           0 :             move16();
    1691             :         }
    1692             :     }
    1693             : 
    1694           0 :     *start_band_old = *start_band; /* Q0 */
    1695           0 :     move16();
    1696             : 
    1697           0 :     return;
    1698             : }

Generated by: LCOV version 1.14