Commit b357a867 authored by Nishant S Kulgod's avatar Nishant S Kulgod
Browse files

commit 1

parent 916e6860
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1098,6 +1098,7 @@ void ivas_hq_core_dec_fx(
            IF( EQ_16( st_fx->bfi, 1 ) && GE_16( output_frame, L_FRAME16k ) )
            {
                /* PHASE_ECU active */
                Scale_sig32( t_audio_q, L_FRAME48k_EXT, sub( Q15, Q_audio ) );
                Q_audio = 15;
                move16();
                window_ola_fx( t_audio_q, synth, &Q_audio, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame,
+1 −1
Original line number Diff line number Diff line
@@ -1769,7 +1769,7 @@ void stereo_tdm_prep_dwnmx_fx(
                mener = Sqrt32( mener, &mener_e );
                test();
                test();
                IF( LT_32( mener, L_shl( 10, sub( 31, mener_e ) ) ) && ( sts[1]->vad_flag == 0 || EQ_16( sts[1]->coder_type_raw, UNVOICED ) ) )
                IF( ( BASOP_Util_Cmp_Mant32Exp( mener, mener_e, 10, Q31 ) < 0 ) && ( sts[1]->vad_flag == 0 || EQ_16( sts[1]->coder_type_raw, UNVOICED ) ) )
                {
                    hCPE->hStereoTD->flag_skip_DMX = 0; /* Can start using the TD downmix whenever the right channel is sufficiently low energy to limit switching artefacts */
                    move16();
+1 −1
Original line number Diff line number Diff line
@@ -564,7 +564,7 @@ void swb_pre_proc_ivas_fx(
                    {
                        Word16 out_start_ind, out_end_ind;
                        stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, new_swb_speech_fx, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 32000, 0, NULL );
                        Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, q_reImBuffer, L_FRAME48k + STEREO_DFT_OVL_MAX );
                        Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, L_FRAME48k + STEREO_DFT_OVL_MAX, q_reImBuffer );
                        Copy( new_swb_speech - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k );
                    }
                }
+145 −7
Original line number Diff line number Diff line
@@ -110,6 +110,16 @@ static void gainFrSmooth_En_fx( Encoder_State *st_fx,
                                Word16 *frGainAttenuate,
                                Word16 *frGainSmoothEn );

#ifdef IVAS_FLOAT_FIXED
static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx,
                                     Word16 *shb_frame_fx,
                                     const Word16 *lpc_shb_fx,
                                     const Word16 *lsp_shb_fx,
                                     Word16 *MA_lsp_shb_spacing,
                                     Word16 *frGainAttenuate,
                                     Word16 *frGainSmoothEn );
#endif


/*-------------------------------------------------------------------*
 * find_max_mem_enc()
@@ -2966,7 +2976,7 @@ void swb_tbe_enc_ivas_fx(

    /* Input signal filtering in case of tonal sounds in the high band
       gain Frame smoothing and attenuation control */
    gainFrSmooth_En_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn );
    gainFrSmooth_En_ivas_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn );

    test();
    test();
@@ -5372,19 +5382,19 @@ static void Quant_shb_ener_sf_ivas_fx(
    exp = norm_l( sum );
    frac = Log2_norm_lc( L_shl( sum, exp ) );
    exp = sub( 30, add( exp, Q_ener ) );  /* 30-(exp+Q_ener ) */
    L_tmp1 = Mpy_32_16( exp, frac, 617 ); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */
    L_tmp1 = Mpy_32_16( exp, frac, 308 ); /* 308=LOG10(2) in Q10, so answer Ltmp in Q11 */

    tmp = round_fx( L_shl( L_tmp1, 30 - 14 ) ); /* tmp in Q12 */
    tmp = extract_l( L_tmp1 ); /* tmp in Q11 */

    temp_shb_ener_sf_fx = 0;
    move16();
    idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 86, shl( 1, NUM_BITS_SHB_ENER_SF ) ); /* 86 = 0.042f in Q11 = Qin-1 */
    /* o: temp_shb_ener_sf_fx in Q12 */
    idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 43, shl( 1, NUM_BITS_SHB_ENER_SF ) ); /* 43 = 0.042f in Q10 = Qin-1 */
    /* o: temp_shb_ener_sf_fx in Q11 */

    /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx );     */
    /*                   = pow(2, 3.321928*temp_shb_ener_sf_fx) */
    L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */
    L_tmp = L_shl( L_tmp, -10 );                  /* bring L_tmp from Q26 to Q16 */
    L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q11+Q13+1 = Q25 */
    L_tmp = L_shl( L_tmp, -9 );                   /* bring L_tmp from Q25 to Q16 */
    frac = L_Extract_lc( L_tmp, &exp );           /* Extract exponent */
    L_tmp = Pow2( 14, frac );
    *shb_ener_sf_Q31 = L_shl( L_tmp, add( sub( exp, 14 ), Q_ener ) ); /* In Q_ener */
@@ -6376,6 +6386,134 @@ static void gainFrSmooth_En_fx( Encoder_State *st_fx,
    }
}

#ifdef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------*
 * gainFrSmooth_En_ivas_fx()
 *
 * Gain frame smoothing and attenuation control
 *-------------------------------------------------------------------*/
static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx,
                                     Word16 *shb_frame_fx,
                                     const Word16 *lpc_shb_fx,
                                     const Word16 *lsp_shb_fx,
                                     Word16 *MA_lsp_shb_spacing,
                                     Word16 *frGainAttenuate,
                                     Word16 *frGainSmoothEn )
{
    Word16 temp_shb_frame[L_FRAME16k + L_SHB_LAHEAD];
    Word32 lsp_slow_evol_rate, lsp_fast_evol_rate;
    Word16 lsp_slow_evol_rate_e, lsp_fast_evol_rate_e;
    Word16 lsp_spacing;

    Word32 tempQ31;
    Word16 tempQ15_1, tempQ15_2;
    Word16 i;
    TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD;

    /* inits */
    *frGainAttenuate = 0;
    move16();
    *frGainSmoothEn = 0;
    move16();
    *MA_lsp_shb_spacing = 16384;
    move16();
    lsp_spacing = lsp_shb_fx[0];
    move16();

    /* estimate the mean square error in lsps from current frame to past frames */
    tempQ15_1 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_slow_interpl_fx[0] );
    tempQ15_2 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_fast_interpl_fx[0] );
    lsp_slow_evol_rate = L_mult( tempQ15_1, tempQ15_1 );
    lsp_slow_evol_rate_e = 0;
    move16();
    lsp_fast_evol_rate = L_mult( tempQ15_2, tempQ15_2 );
    lsp_fast_evol_rate_e = 0;
    move16();

    /* update the slow and fast lsp interp for next frame */
    tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[0], 22937 );
    hBWE_TD->lsp_shb_slow_interpl_fx[0] = mac_r( tempQ31, lsp_shb_fx[0], 9830 );
    move16();
    tempQ31 = L_mult( hBWE_TD->lsp_shb_fast_interpl_fx[0], 9830 );
    hBWE_TD->lsp_shb_fast_interpl_fx[0] = mac_r( tempQ31, lsp_shb_fx[0], 22937 );
    move16();

    FOR( i = 1; i < LPC_SHB_ORDER; i++ )
    {
        tempQ15_1 = sub( lsp_shb_fx[i], lsp_shb_fx[i - 1] );
        lsp_spacing = s_min( lsp_spacing, tempQ15_1 );

        /* estimate the mean square error in lsps from current frame to past frames */
        tempQ15_1 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_slow_interpl_fx[i] );
        tempQ15_2 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_fast_interpl_fx[i] );
        lsp_slow_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, L_mult( tempQ15_1, tempQ15_1 ), 0, &lsp_slow_evol_rate_e );
        lsp_fast_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, L_mult( tempQ15_2, tempQ15_2 ), 0, &lsp_fast_evol_rate_e );

        /* update the slow and fast interpolation lsps for next frame */
        tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[i], 22937 );
        hBWE_TD->lsp_shb_slow_interpl_fx[i] = mac_r( tempQ31, lsp_shb_fx[i], 9830 );
        move16();
        tempQ31 = L_mult( hBWE_TD->lsp_shb_fast_interpl_fx[i], 9830 );
        hBWE_TD->lsp_shb_fast_interpl_fx[i] = mac_r( tempQ31, lsp_shb_fx[i], 22937 );
        move16();
    }

    test();
    test();
    IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && LT_16( lsp_spacing, 262 ) )
    {
        hBWE_TD->lsp_shb_spacing_fx[0] = lsp_spacing;
        move16();
        hBWE_TD->lsp_shb_spacing_fx[1] = lsp_spacing;
        move16();
        hBWE_TD->lsp_shb_spacing_fx[2] = lsp_spacing;
        move16();
        hBWE_TD->prev_frGainAtten = 1;
        move16();
        set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER );
    }

    /* Estimate the moving average LSP spacing */
    tempQ31 = L_mult( hBWE_TD->lsp_shb_spacing_fx[0], 3277 );         /* 0.1f */
    tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[1], 6553 ); /* 0.2f */
    tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[2], 9830 ); /* 0.3f */
    *MA_lsp_shb_spacing = mac_r( tempQ31, lsp_spacing, 13107 );       /* 0.4f */

    hBWE_TD->lsp_shb_spacing_fx[0] = hBWE_TD->lsp_shb_spacing_fx[1];
    move16();
    hBWE_TD->lsp_shb_spacing_fx[1] = hBWE_TD->lsp_shb_spacing_fx[2];
    move16();
    hBWE_TD->lsp_shb_spacing_fx[2] = lsp_spacing;
    move16();

    test();
    test();
    test();
    IF( ( LT_16( lsp_spacing, 262 ) && ( LT_16( *MA_lsp_shb_spacing, 164 ) || EQ_16( hBWE_TD->prev_frGainAtten, 1 ) ) ) || LE_16( lsp_spacing, 105 ) )
    {
        *frGainAttenuate = 1;
        move16();

        IF( NE_32( st_fx->total_brate, ACELP_24k40 ) )
        {
            Copy( shb_frame_fx, temp_shb_frame, L_FRAME16k + L_SHB_LAHEAD );
            fir_fx( temp_shb_frame, lpc_shb_fx, shb_frame_fx, hBWE_TD->shb_inv_filt_mem_fx, L_FRAME16k + L_SHB_LAHEAD, LPC_SHB_ORDER, 1, 3 );
        }
        ELSE
        {
            set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER );
        }

        test();
        IF( ( BASOP_Util_Cmp_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, 2147484l /*0.001f Q31*/, 0 ) < 0 ) && ( BASOP_Util_Cmp_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, 2147484l /*0.001f Q31*/, 0 ) < 0 ) )
        {
            *frGainSmoothEn = 1;
            move16();
        }
    }
}
#endif

#define MAXINT32 MAX_32
static void first_VQstages_fx(
    const Word16 *const *cb,