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

Correct/Improve scale of decimation filter states in SWB preprocessing. Thanks...

Correct/Improve scale of decimation filter states in SWB preprocessing. Thanks toa hint from @vaillancour
parent 03a66b57
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -928,6 +928,9 @@ typedef struct td_bwe_enc_structure
    Word16 old_input_fhb_fx_Q;
    Word16 prev_lsp_shb_fx[LPC_SHB_ORDER];                           /* Q15 */
    Word16 state_ana_filt_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* states for the analysis filters */
#ifdef NONBE_FIX_ISSUE_2206
    Word16 state_ana_filt_shb_fx_Q;
#endif
    Word16 cldfbHBLT;                                                /* Q13 */
    /* states for the filters used in generating SHB excitation from WB excitation*/
    Word32 mem_csfilt_fx[2];                  /* Q(prev_Q_bwe_exc) */
+42 −4
Original line number Diff line number Diff line
@@ -514,6 +514,14 @@ void swb_pre_proc_fx(

    set16_fx( old_input_fx, 0, NS2SA( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k );

#ifdef NONBE_FIX_ISSUE_2206
    IF( st->element_mode > EVS_MONO )
    {
        scale_sig( st->hBWE_TD->dec_2_over_3_mem_lp_fx, 6, sub( st->q_inp, 0 ) );
        scale_sig( st->hBWE_TD->dec_2_over_3_mem_fx, L_FILT_2OVER3, sub( st->q_inp, 0 ) );
    }
#endif

    IF( EQ_32( st->input_Fs, 32000 ) )
    {
        IF( st->element_mode > EVS_MONO )
@@ -765,6 +773,18 @@ void swb_pre_proc_fx(
                        inner_Fs = 32000;
                        move32();

#ifdef NONBE_FIX_ISSUE_2206
                        Copy_Scale_sig_nosat( hBWE_FD->old_fdbwe_speech_fx, new_swb_speech, L_FRAME48k, sub( st->q_inp, -1 ) );

                        IF( NE_16( st->element_mode, IVAS_CPE_DFT ) )
                        {
                            decimate_2_over_3_allpass_fx( new_swb_speech, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx );
                        }
                        ELSE
                        {
                            lerp( new_swb_speech, new_swb_speech, inner_frame, L_FRAME48k );
                        }
#else
                        IF( NE_16( st->element_mode, IVAS_CPE_DFT ) )
                        {
                            decimate_2_over_3_allpass_fx( hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx );
@@ -773,9 +793,6 @@ void swb_pre_proc_fx(
                        {
                            lerp( hBWE_FD->old_fdbwe_speech_fx, new_swb_speech, inner_frame, L_FRAME48k );
                        }

#ifdef NONBE_FIX_ISSUE_2206
                        Scale_sig( new_swb_speech, L_FRAME48k, sub( st->q_inp, -1 ) );
#endif

                        test();
@@ -1363,9 +1380,21 @@ void swb_pre_proc_fx(
                    move16();
                }
            }

#ifdef NONBE_FIX_ISSUE_2206
            Word16 spchTmp_Q;
            spchTmp_Q = s_min( add( st->q_inp, norm_arr( spchTmp, L_FRAME32k ) ), hBWE_TD->state_ana_filt_shb_fx_Q );
            scale_sig( hBWE_TD->state_ana_filt_shb_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), sub( spchTmp_Q, hBWE_TD->state_ana_filt_shb_fx_Q ) );
            scale_sig( spchTmp, L_FRAME32k, sub( spchTmp_Q, st->q_inp ) );
#endif
            Decimate_allpass_steep_fx( spchTmp, hBWE_TD->state_ana_filt_shb_fx, L_FRAME32k, shb_speech );
#ifdef NONBE_FIX_ISSUE_2206
            hBWE_TD->state_ana_filt_shb_fx_Q = spchTmp_Q;
            move16();
#endif

#ifdef NONBE_FIX_ISSUE_2206
            scale_sig( shb_speech, L_FRAME16k, sub( 0, spchTmp_Q ) ); // Q_shb_spch = 0
#endif
            Copy( shb_speech + L_FRAME16k - ( L_LOOK_16k + L_SUBFR16k ), hBWE_TD->old_speech_shb_fx, L_LOOK_16k + L_SUBFR16k );

            /*Compute the past overlap for potential next iDFTs SHB*/
@@ -1421,5 +1450,14 @@ void swb_pre_proc_fx(
        }
    }

#ifdef NONBE_FIX_ISSUE_2206
    IF( st->element_mode > EVS_MONO )
    {
        /* Consider variable Q for dec_2_over_3_mem_lp_fx and dec_2_over_3_mem_fx to avoid saturation. */
        Scale_sig( st->hBWE_TD->dec_2_over_3_mem_lp_fx, 6, sub( 0, st->q_inp ) );
        scale_sig( st->hBWE_TD->dec_2_over_3_mem_fx, L_FILT_2OVER3, sub( 0, st->q_inp ) );
    }
#endif

    return;
}
+8 −0
Original line number Diff line number Diff line
@@ -394,6 +394,10 @@ void InitSWBencBuffer_fx(
    move32();

    set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
#ifdef NONBE_FIX_ISSUE_2206
    hBWE_TD->state_ana_filt_shb_fx_Q = Q15;
    move16();
#endif
    set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[0], 0, 4 );
    set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[1], 0, 4 );
    set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[2], 0, 4 );
@@ -6648,6 +6652,10 @@ void TBEreset_enc_fx(
    ELSE IF( ( EQ_16( bandwidth, SWB ) ) || ( EQ_16( bandwidth, FB ) ) )
    {
        set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
#ifdef NONBE_FIX_ISSUE_2206
        hBWE_TD->state_ana_filt_shb_fx_Q = Q15;
        move16();
#endif

        swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx,
                          hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ),