Commit 725d9dcd authored by vaillancour's avatar vaillancour
Browse files

fix inter-harmonic noise when transition and generic are using EVS function

parent 543c78f7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -80,6 +80,10 @@
//#define HARM_SCE_INIT

#define FORCE_GENERIC
#define ALLOW_TM  /* To allow some transition mode */

#define REMOVE_A_SCALE


#if 1        // diminish MLD by ~1 on NO_S

+13 −6
Original line number Diff line number Diff line
@@ -1110,10 +1110,12 @@ ivas_error acelp_core_enc_ivas_fx(
        st->hLPDmem->q_mem_syn = st->Q_syn;
        move16();
        // Scaling Aq to Q12
#ifndef REMOVE_A_SCALE
        FOR( Word16 k = 0; k < NB_SUBFR16k; k++ )
        {
            Scale_sig( &Aq[( M + 1 ) * k], M + 1, sub( norm_s( Aq[( M + 1 ) * k] ), 2 ) );
        }
#endif
        /* synthesis at 12.8kHz sampling rate */
        syn_12k8_fx( st->L_frame, Aq, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, sub( Q_new, 1 ), st->Q_syn );

@@ -1262,10 +1264,12 @@ ivas_error acelp_core_enc_ivas_fx(
            move16();
        }
        // Scaling Aq to Q12
#ifndef REMOVE_A_SCALE
        FOR( Word16 k = 0; k < NB_SUBFR16k; k++ )
        {
            Scale_sig( &Aq[( M + 1 ) * k], M + 1, sub( norm_s( Aq[( M + 1 ) * k] ), 2 ) );
        }
#endif
        test();
        IF( EQ_16( st->last_core, HQ_CORE ) && st->element_mode > EVS_MONO )
        {
@@ -1329,9 +1333,11 @@ ivas_error acelp_core_enc_ivas_fx(
                max = s_max( max, tmp );
            }

            shift = sub( norm_s( max ), 4 );
            shift = s_min( shift, -1 );
            //shift = -2;
            shift = sub( norm_s( max ), 3 );
            shift = s_min( shift, 0 );
            //shift = sub( norm_s( max ), 4 );
            //shift = s_min( shift, -1 );
            //shift = 0;
        }                                                           
#endif
        IF( nb_bits > 0 )
@@ -1369,8 +1375,8 @@ ivas_error acelp_core_enc_ivas_fx(
        }
        ELSE IF( EQ_16( st->coder_type, TRANSITION ) )
        {
#if 0//def TRY_SHIFT_ACELP 
            encod_tran_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, shift, Q_new );
#ifdef TRY_SHIFT_ACELP 
            encod_tran_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, shift, Q_new );
#else
            encod_tran_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, 0, Q_new );
#endif
@@ -1411,7 +1417,8 @@ ivas_error acelp_core_enc_ivas_fx(
        {
            /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */
#ifdef TRY_SHIFT_ACELP
            encod_gen_voic_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new );
            encod_gen_voic_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new );
            //encod_gen_voic_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new );
#else
            encod_gen_voic_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new );
#endif
+1 −1
Original line number Diff line number Diff line
@@ -540,7 +540,7 @@ void encod_gen_voic_ivas_fx(
    /*------------------------------------------------------------------*
     * ACELP subframe loop
     *------------------------------------------------------------------*/
#ifdef USE_EVS_FUNC_LP
#if defined USE_EVS_FUNC_LP && !defined USE_EVS_FUNC_FT_G
    shift_wsp = sub( shift_wsp, 1 );
#endif
    FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR )
+44 −13
Original line number Diff line number Diff line
@@ -522,7 +522,9 @@ Word16 encod_tran_ivas_fx(
    move16();
    set16_fx( code_preQ, 0, L_SUBFR );
    shift_wsp = add( Q_new, shift );

#ifdef USE_EVS_FUNC_LP
    shift_wsp = sub( shift_wsp, 1 );
#endif
    /*----------------------------------------------------------------*
     * ACELP subframe loop
     *----------------------------------------------------------------*/
@@ -543,14 +545,13 @@ Word16 encod_tran_ivas_fx(
        find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq,
                         res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 );
#endif
#if !defined TRY_SHIFT_ACELP || !defined USE_EVS_FUNC_FT_T
#if !defined TRY_SHIFT_ACELP && !defined USE_EVS_FUNC_FT_T
        q_h1 = sub( 14, norm_s( h1[0] ) );
        Copy_Scale_sig( h1, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/
#if !defined TRY_SHIFT_ACELP
        Scale_sig( h1, L_SUBFR, sub( 13, q_h1 ) );
#else
        Scale_sig( h1, L_SUBFR, add( sub( 14, q_h1 ), shift ) );
#endif
        Copy_Scale_sig( h1, h2, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/
#elif defined TRY_SHIFT_ACELP && !defined USE_EVS_FUNC_FT_T
        q_h1 = sub( 14, norm_s( h1[0] ) );
        Copy_Scale_sig( h1, h2_fx, L_SUBFR, sub( 11, q_h1 ) + shift ); /*Q11*/
        Scale_sig( h1, L_SUBFR, sub( 14, q_h1 ) + shift );
#else
        Copy_Scale_sig( h1, h2_fx, L_SUBFR, -2 );  /*Q11*/
        Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution Q(14+shift)*/
@@ -563,10 +564,13 @@ Word16 encod_tran_ivas_fx(
         * TC: subframe determination &
         * adaptive/glottal part of excitation construction
         *-----------------------------------------------------------------*/

#ifndef USE_EVS_FCB_5
        transition_enc_ivas_fx( st_fx, i_subfr, &tc_subfr, &Jopt_flag, &position, &T0, &T0_frac, &T0_min, &T0_max, exc_fx, y1,
                                h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx, &unbits_ACELP, Q_new, shift );

#else
        transition_enc_fx( st_fx, i_subfr, &tc_subfr, &Jopt_flag, &position, &T0, &T0_frac, &T0_min, &T0_max, exc_fx, y1,
                           h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx, &unbits_ACELP, Q_new, shift );
#endif
        /*-----------------------------------------------------------------*
         * Transform domain contribution encoding - active frames
         *-----------------------------------------------------------------*/
@@ -574,20 +578,28 @@ Word16 encod_tran_ivas_fx(
        IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) )
        {

#if !defined TRY_SHIFT_ACELP_T   
#if !defined TRY_SHIFT_ACELP   
            Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */
#endif
#ifndef USE_EVS_FCB_5
            transf_cdbk_enc_ivas_fx( st_fx, 0, i_subfr, cn, exc_fx, p_Aq, Aw_fx, h1, xn, xn2, y1, y2, Es_pred_fx,
                                     &gain_pit, gain_code, g_corr, clip_gain, &gain_preQ, code_preQ, unbits, Q_new, shift );
#else
            transf_cdbk_enc_fx( st_fx, 0, i_subfr, cn, exc_fx, p_Aq, Aw_fx, h1, xn, xn2, y1, y2, Es_pred_fx,
                                &gain_pit, gain_code, g_corr, clip_gain, &gain_preQ, code_preQ, unbits, Q_new, shift );
#endif
        }

        /*-----------------------------------------------------------------*
         * ACELP codebook search + pitch sharpening
         *-----------------------------------------------------------------*/

#ifdef USE_EVS_FCB_4 // -> this might need adjustment in acelp_fast
        inov_encode_fx( st_fx, st_fx->core_brate, 0, L_frame_fx, st_fx->last_L_frame, st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag,
                        i_subfr, tc_subfr, p_Aq, gain_pit, cn, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift );
#else
        inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_frame_fx, st_fx->last_L_frame, st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag,
                             i_subfr, tc_subfr, p_Aq, gain_pit, cn, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new );

#endif
        test();
        test();
        test();
@@ -603,30 +615,49 @@ Word16 encod_tran_ivas_fx(
         *-----------------------------------------------------------------*/
        IF( Jopt_flag == 0 )
        {
#ifndef USE_EVS_FUNC_LP
            /* SQ gain_code */
            gain_enc_tc_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y2, code, Es_pred_fx,
                                 &gain_pit, &gain_code, &gain_inov, &norm_gain_code, sub( shift_wsp, 1 ) );
#else
            gain_enc_tc_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y2, code, Es_pred_fx,
                            &gain_pit, &gain_code, &gain_inov, &norm_gain_code, shift_wsp );
#endif
        }
        ELSE
        {
            IF( GT_32( st_fx->core_brate, ACELP_32k ) )
            {
                /* SQ gain_pit and gain_code */
#ifndef USE_EVS_FUNC_LP
                gain_enc_SQ_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y1, y2, code, Es_pred_fx,
                                     &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain, sub( shift_wsp, 1 ) );
#else
                gain_enc_SQ_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y1, y2, code, Es_pred_fx,
                                &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain, shift_wsp );
#endif
            }
            ELSE
            {
                /* VQ gain_pit and gain_code */
#ifndef USE_EVS_FUNC_LP
                gain_enc_mless_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame_fx, i_subfr, tc_subfr, xn, y1, sub( shift_wsp, 1 ), y2, code, Es_pred_fx,
                                        &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
#else
                gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame_fx, i_subfr, tc_subfr, xn, y1, shift_wsp, y2, code, Es_pred_fx,
                                   &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
#endif
            }
        }
        gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx );

        Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/
        gcode16 = round_fx_o( Lgcode, &Overflow );
#if defined USE_EVS_Est_tilt2_FUNC && defined TRY_SHIFT_ACELP
        hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15  */
#else
        hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 ); // Q15
#endif
        /*-----------------------------------------------------------------*
         * Update memory of the weighting filter
         *-----------------------------------------------------------------*/
+2 −2
Original line number Diff line number Diff line
@@ -568,7 +568,7 @@ Word16 find_uv_fx( /* o : coding type */
    move32(); /*Q6*/
    st_fx->old_dE1_fx = dE1;
    move32(); /*Q13*/
#ifdef FORCE_GENERIC
#if defined FORCE_GENERIC && !defined ALLOW_TM
    coder_type = GENERIC;
#endif
    /* save the raw coder_type for various modules later in the codec (the reason is that e.g. UNVOICED is lost at higher rates) */
@@ -1109,7 +1109,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ
    move32(); /*Q6*/
    st_fx->old_dE1_fx = dE1;
    move32(); /*Q13*/
#ifdef FORCE_GENERIC
#if defined FORCE_GENERIC && !defined ALLOW_TM
    coder_type = GENERIC;
#endif
    /* save the raw coder_type for various modules later in the codec (the reason is that e.g. UNVOICED is lost at higher rates) */
Loading