Commit 4e094ae8 authored by vaclav's avatar vaclav
Browse files

harmonize time_envelop_shaping_fx()

parent a1deaf28
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -380,6 +380,9 @@ void SWB_BWE_decoding_fx(
);
void time_envelop_shaping_fx(
#ifdef HARM_FD_BWE
    const Word16 element_mode, /* i  : element mode                   */
#endif
    Word16 werr[],     /* i/o: SHB synthesis           Q_synth*/
    Word32 SWB_tenv[], /* i/o: frequency envelope          Q15*/
    const Word16 L,    /* i  : frame length                   */
@@ -2675,6 +2678,7 @@ Word16 E_UTIL_f_preemph3_ivas_fx(
    Word16 bits      /* Q0 */
);
#ifndef HARM_FD_BWE
void time_envelop_shaping_fx(
    Word16 werr[],     /* i/o: SHB synthesis           Q_synth*/
    Word32 SWB_tenv[], /* i/o: frequency envelope          Q15*/
@@ -2682,11 +2686,12 @@ void time_envelop_shaping_fx(
    Word16 *Q_synth );
void time_envelop_shaping_ivas_fx(
    const Word16 element_mode, /* i  : element mode                   */
    Word16 werr[],             /* i/o: SHB synthesis           Q_synth*/
    Word32 SWB_tenv[],         /* i/o: frequency envelope          Q15*/
    const Word16 L,            /* i  : frame length                   */
    Word16 *Q_synth );
#endif
void find_td_envelope_fx(
    const Word16 inp[], /* i  : input signal                            Qx */
    const Word16 len,   /* i  : length of the input signal                 */
+31 −11
Original line number Diff line number Diff line
@@ -1945,6 +1945,7 @@ return;
/*--------------------------------------------------------------------------*/

void time_envelop_shaping_fx(
#ifndef HARM_FD_BWE
    Word16 werr[],     /* i/o: SHB synthesis           Q_synth*/
    Word32 SWB_tenv[], /* i/o: frequency envelope          Q15*/
    const Word16 L,    /* i  : frame length                   */
@@ -2024,6 +2025,9 @@ void time_envelop_shaping_fx(
}

void time_envelop_shaping_ivas_fx(
#else
    const Word16 element_mode, /* i  : element mode                   */
#endif
    Word16 werr[],     /* i/o: SHB synthesis           Q_synth*/
    Word32 SWB_tenv[], /* i/o: frequency envelope          Q15*/
    const Word16 L,    /* i  : frame length                   */
@@ -2040,7 +2044,22 @@ void time_envelop_shaping_ivas_fx(
    pit = werr;
    exp_L = norm_s( L );
    inv_L = div_s( shl( 1, sub( 14, exp_L ) ), L ); /*Q(29-exp_L) */

    FOR( i = 0; i < SWB_TENV; i++ )
    {
#ifdef HARM_FD_BWE
        IF( element_mode == EVS_MONO )
        {
            Energy = L_deposit_l( 0 );
            FOR( j = 0; j < L / 4; j++ )
            {
                Energy = L_mac0_sat( Energy, *pit, *pit ); /*(2*Q_synth) */
                pit++;
            }
            Energy_Q = shl( ( *Q_synth ), 1 );
        }
        ELSE
#endif
        {
            Energy_64 = L_deposit_l( 0 );
            FOR( j = 0; j < L / 4; j++ )
@@ -2052,19 +2071,20 @@ void time_envelop_shaping_ivas_fx(
            Energy_64 = W_shl( Energy_64, w_tmp );
            Energy = W_extract_h( Energy_64 ); /*2*Q_synth + w_tmp -32*/
            Energy_Q = sub( add( shl( ( *Q_synth ), 1 ), w_tmp ), 32 );
        }

        Energy = Mult_32_16( Energy, inv_L ); /*Q(29-exp_L-15) -> Q(-exp_L+14+2*Q_synth+w_tmp-32) */
        Energy_16 = 0;
        move16();
        /*exp = 31-(-exp_L+14 +(2*(*Q_synth)+w_tmp-32)); */
        /*exp = 31-(-exp_L+14+Energy_Q); */
        exp = sub( 17, sub( Energy_Q, exp_L ) );

        IF( Energy != 0 )
        {
            exp = norm_l( Energy );
            frac = extract_h( L_shl( Energy, exp ) );
            /*exp = sub(exp, 30-(-exp_L+14-2+(2*(*Q_synth)+w_tmp-32)));  */
            /*exp = sub(exp, 30-(-exp_L+14-2+Energy_Q));  */
            exp = sub( exp, sub( 30, add( sub( Energy_Q, exp_L ), 14 - 2 ) ) );

            tmp = div_s( 16384, frac );
            L_tmp = L_deposit_h( tmp );
            Energy = Isqrt_lc( L_tmp, &exp );                        /*Q(31-exp) */
+980 −974
Original line number Diff line number Diff line
@@ -974,21 +974,19 @@ Word16 ivas_wb_bwe_dec_fx(
    /*---------------------------------------------------------------------*
     * SWB BWE decoding
     *---------------------------------------------------------------------*/

    /* windowing of the ACELP core synthesis */
    new_input_fx_exp = *Qpost;
    move16();

        {
    wtda_fx( synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx,
                     &hBWE_FD->old_wtda_swb_fx_exp,
                     ALDO_WINDOW,
                     ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */
                     output_frame );
             &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ output_frame );

    *Qpost = sub( new_input_fx_exp, 15 );
    move16();
    /* DCT of the ACELP core synthesis */
    direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode );
        }

    /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */
    scl = sub( 16 + MAX_Q_NEW_INPUT, new_input_fx_exp );
    /* Possible to Upscale? */
@@ -1161,7 +1159,11 @@ Word16 ivas_wb_bwe_dec_fx(
        }

        /* time envelope shaping when the current frame is TRANSIENT frame */
#ifdef HARM_FD_BWE
        time_envelop_shaping_fx( st_fx->element_mode, hb_synth_fx, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb );
#else
        time_envelop_shaping_fx( hb_synth_fx, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb );
#endif
        Q_syn_hb = sub( Q_syn_hb, 3 );

        hBWE_FD->prev_td_energy_fx = SWB_tenv_fx[3];
@@ -1307,11 +1309,10 @@ Word16 ivas_wb_bwe_dec_fx(
    /*---------------------------------------------------------------------*
     * SWB BWE decoding
     *---------------------------------------------------------------------*/

    test();
    IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft )
    {
            /* todo - wtda() does not support L_FRAME length; thus temporarily resample the signal */
            /* todo - delay output[] by 1.25ms ? */
        L_lerp_fx_q11( output_fx, ysynth_fx32, L_FRAME16k, st_fx->L_frame );

        /* windowing of the ACELP core synthesis */
@@ -1332,6 +1333,7 @@ Word16 ivas_wb_bwe_dec_fx(
        /* DCT of the ACELP core synthesis */
        new_input_fx_exp = 11;
        move16();
        /* DCT of the ACELP core synthesis */
        direct_transform_fx( wtda_synth_fx, ysynth_fx32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode );
        ysynth_frame_size = output_frame;
        move16();
@@ -1527,7 +1529,11 @@ Word16 ivas_wb_bwe_dec_fx(
        }

        /* time envelope shaping when the current frame is TRANSIENT frame */
#ifdef HARM_FD_BWE
        time_envelop_shaping_fx( st_fx->element_mode, hb_synth_fx16, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb );
#else
        time_envelop_shaping_ivas_fx( hb_synth_fx16, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb );
#endif

        Q_syn_hb = sub( Q_syn_hb, 3 );