Commit c101a3a9 authored by Manuel Jander's avatar Manuel Jander
Browse files

Correct scale of new_inp_resamp16k_fx and change some normalizations to avoid...

Correct scale of new_inp_resamp16k_fx and change some normalizations to avoid crashes because of inconvenient Q value differences.
parent a7e134cc
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -6022,7 +6022,12 @@ ivas_error pre_proc_ivas_fx(
    Word16 *epsP_fx_q,                                          /* i  : LP prediction errors                                   */
    Word16 lsp_new_fx[M],                                       /* i/o: LSPs at the end of the frame                        Q15*/
    Word16 lsp_mid_fx[M],                                       /* i/o: LSPs in the middle of the frame                     Q15*/
#ifdef NONBE_FIX_ISSUE_2206
    Word16 *new_inp_resamp16k_fx,                               /* o  : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE    q_new_inp_resamp16k_fx*/
    Word16 *q_new_inp_resamp16k_fx,                             /* o  : Q value of new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */
#else
    Word16 *new_inp_resamp16k_fx,                               /* o  : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE    Q_new-1*/
#endif
    Word16 *Voicing_flag,                                       /* o  : voicing flag for HQ FEC                              Q0*/
    Word16 old_wsp_fx[],                                        /* i  : weighted input signal buffer                  e_old_wsp*/
    Word16 e_old_wsp,
+10 −8
Original line number Diff line number Diff line
@@ -235,7 +235,11 @@ ivas_error ivas_core_enc_fx(
        IF( EQ_32( ivas_format, SBA_FORMAT ) )
        {
            IF( NE_32( ( error = pre_proc_ivas_fx( st, last_element_mode, element_brate, last_element_brate, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */,
#ifdef NONBE_FIX_ISSUE_2206
                                                   &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &q_new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n],
#else
                                                   &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n],
#endif
                                                   vad_flag_dtx[n], MCT_flag, vad_hover_flag[n], flag_16k_smc, enerBuffer_fx[n], enerBuffer_fx_exp[n], fft_buff_fx[n], cor_map_sum_fx[n], &Q_new[n] ) ),
                       IVAS_ERR_OK ) )
            {
@@ -245,20 +249,17 @@ ivas_error ivas_core_enc_fx(
        ELSE
        {
            IF( NE_32( ( error = pre_proc_ivas_fx( st, last_element_mode, element_brate, element_brate, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */,
#ifdef NONBE_FIX_ISSUE_2206
                                                   &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &q_new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n],
#else
                                                   &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n],
#endif
                                                   vad_flag_dtx[n], MCT_flag, vad_hover_flag[n], flag_16k_smc, enerBuffer_fx[n], enerBuffer_fx_exp[n], fft_buff_fx[n], cor_map_sum_fx[n], &Q_new[n] ) ),
                       IVAS_ERR_OK ) )
            {
                return error;
            }
        }
#ifdef NONBE_FIX_ISSUE_2206
        /* Normalize new_inp_resamp16k_fx to avoid inconvenient rescale of old WTDA buffers later. */
        q_new_inp_resamp16k_fx[n] = norm_arr( new_inp_resamp16k_fx[n], L_FRAME16k );
        scale_sig( new_inp_resamp16k_fx[n], L_FRAME16k, q_new_inp_resamp16k_fx[n] );
        q_new_inp_resamp16k_fx[n] = add( q_new_inp_resamp16k_fx[n], sub( Q_new[n], 1 ) );

#endif
        test();
        IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || EQ_16( st->element_mode, IVAS_SCE ) )
        {
@@ -642,7 +643,8 @@ ivas_error ivas_core_enc_fx(
        q_inp[0] = st->q_old_inp;
        q_inp[1] = st->q_inp;

        st->q_inp = s_min( st->Q_old_wtda, st->q_inp );
        st->q_inp = s_min( s_min( st->Q_old_wtda, st->q_inp ), sub( Q15, st->exp_old_inp_12k8 ) );
        st->q_inp = s_min( st->q_inp, sub( Q15, st->exp_old_inp_16k ) );
        st->q_old_inp = st->q_inp;

        IF( st->hBWE_FD != NULL )
+30 −6
Original line number Diff line number Diff line
@@ -65,7 +65,12 @@ ivas_error pre_proc_ivas_fx(
    Word16 *epsP_fx_q,                     /* i  : LP prediction errors                      */
    Word16 lsp_new_fx[M],                  /* i/o: LSPs at the end of the frame              Q15*/
    Word16 lsp_mid_fx[M],                  /* i/o: LSPs in the middle of the frame           Q15*/
#ifdef NONBE_FIX_ISSUE_2206
    Word16 *new_inp_resamp16k_fx,          /* o  : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE    q_new_inp_resamp16k_fx*/
    Word16 *q_new_inp_resamp16k_fx,        /* o  : Q value of new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */
#else
    Word16 *new_inp_resamp16k_fx,          /* o  : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE    Q_new-1*/
#endif
    Word16 *Voicing_flag,                  /* o  : voicing flag for HQ FEC                   Q0*/
    Word16 old_wsp_fx[],                   /* i  : weighted input signal buffer              e_old_wsp*/
    Word16 e_old_wsp,
@@ -544,12 +549,26 @@ ivas_error pre_proc_ivas_fx(
    move16();
    inp_16k_fx = old_inp_16k_fx + L_INP_MEM - L_look;

#ifdef NONBE_FIX_ISSUE_2206
    Word16 shift = norm_arr( st->old_inp_12k8_fx, L_INP_MEM );
    Scale_sig( st->old_inp_12k8_fx, L_INP_MEM, shift ); /* exp(st->exp_old_inp_12k8 - shift) */
    st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift );
    move16();
    shift = norm_arr( st->old_inp_16k_fx, L_INP_MEM );
    Scale_sig( st->old_inp_16k_fx, L_INP_MEM, shift ); /* exp(st->exp_old_inp_12k8 - shift) */
    st->exp_old_inp_16k = sub( st->exp_old_inp_16k, shift );
    move16();
    IF( st->hBWE_FD != NULL ) {
        shift = norm_arr( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k );
        Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, shift ); /* exp(st->exp_old_inp_12k8 - shift) */
        st->Q_old_wtda = add( st->Q_old_wtda, shift );
        move16();
    }
#else
    Word16 shift = getScaleFactor16( st->old_inp_12k8_fx, L_INP_MEM );
    Scale_sig( st->old_inp_12k8_fx, L_INP_MEM, shift ); /* exp(st->exp_old_inp_12k8 - shift) */
    st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift );
    move16();

#ifndef NONBE_FIX_ISSUE_2206
    Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( Q_old_inp_16k, sub( Q15, st->exp_old_inp_16k ) ) ); /* Q15 - st->exp_old_inp_16k */
    st->exp_old_inp_16k = sub( Q15, Q_old_inp_16k );
    move16();
@@ -598,7 +617,10 @@ ivas_error pre_proc_ivas_fx(
            *Q_new = Q_inp_16k;
        }
        move16();

#ifdef NONBE_FIX_ISSUE_2206
        *q_new_inp_resamp16k_fx = Q_old_inp_16k;
        move16();
#endif
        IF( error != IVAS_ERR_OK )
        {
            return error;
@@ -641,7 +663,9 @@ ivas_error pre_proc_ivas_fx(
    IF( flag_16k_smc )
    {
#ifdef NONBE_FIX_ISSUE_2206
        Copy_Scale_sig( st->buf_speech_enc + L_FRAME16k, new_inp_resamp16k_fx, L_FRAME16k, sub( sub( *Q_new, 1 ), sub( Q15, st->exp_buf_speech_enc ) ) ); /* *Q_new-1 */
        *q_new_inp_resamp16k_fx = sub( Q15, st->exp_buf_speech_enc );
        move16();
        Copy( st->buf_speech_enc + L_FRAME16k, new_inp_resamp16k_fx, L_FRAME16k ); /* q_new_inp_resamp16k_fx */
#else
        Copy( st->buf_speech_enc + L_FRAME16k, new_inp_resamp16k_fx, L_FRAME16k ); /* Q_old_inp_16k */
#endif
@@ -1376,8 +1400,8 @@ ivas_error ivas_compute_core_buffers_fx(

    IF( new_inp_resamp16k_out_fx != NULL )
    {
#ifdef NONBE_FIX_ISSUE_2206
        Copy_Scale_sig( new_inp_resamp16k_fx, new_inp_resamp16k_out_fx, L_FRAME16k, sub( sub( *Q_new, 1 ), Q_old_inp_16k ) );
#ifdef NONBE_FIX_ISSUE_2206_NO
        Copy_Scale_sig( new_inp_resamp16k_fx, new_inp_resamp16k_out_fx, L_FRAME16k, sub( sub( *Q_new, 0 ), Q_old_inp_16k ) );
#else
        Copy( new_inp_resamp16k_fx, new_inp_resamp16k_out_fx, L_FRAME16k );
#endif