Commit 2e6e711c authored by Manuel Jander's avatar Manuel Jander
Browse files

Encoder: Make Q factor of old_inp_16k_fx control possible for better accuracy...

Encoder: Make Q factor of old_inp_16k_fx control possible for better accuracy and avoid saturation at the same time.
parent c67b6595
Loading
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -58,7 +58,11 @@ ivas_error ivas_core_enc_fx(
    MCT_ENC_HANDLE hMCT,                                             /* i/o: MCT encoder structure                              */
    const Word16 n_CoreChannels,                                     /* i  : number of core channels to be coded              Q0*/
    Word16 old_inp_12k8_fx[][L_INP_12k8],                            /* i  : buffer of old input signal                  Q_new-1*/
#ifdef NONBE_FIX_ISSUE_2206
    Word16 old_inp_16k_fx[][L_INP],                                  /* i  : buffer of old input signal                  Q_new-1*/
#else
    Word16 old_inp_16k_fx[][L_INP],                                  /* i  : buffer of old input signal                      Q-1*/
#endif
    Word16 Q_new[],                                                  /* i  : Q factor of speech buffers                         */
    Word32 ener_fx[],                                                /* i  : residual energy from Levinson-Durbin      epsP_fx_q*/
    Word16 A_fx[][NB_SUBFR16k * ( M + 1 )],                          /* i  : A(z) unquantized for the 4 subframes            Q12*/
@@ -626,6 +630,7 @@ ivas_error ivas_core_enc_fx(
    {
        st = sts[n];

#ifndef NONBE_FIX_ISSUE_2206
        IF( st->hBWE_FD != NULL )
        {
            Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( negate( 1 ), st->Q_old_wtda ) ); // Q(-1)
@@ -635,6 +640,7 @@ ivas_error ivas_core_enc_fx(
            st->hBWE_FD->prev_Q_input_lp = sub( Q_new[n], 1 );
            move16();
        }
#endif

        Copy( st->input_fx - input_frame, tmp_old_input_fx, input_frame );
        Copy( st->input_fx, tmp_input_fx, input_frame );
@@ -665,7 +671,11 @@ ivas_error ivas_core_enc_fx(
        IF( GE_32( input_Fs, 16000 ) && LT_16( st->bwidth, SWB ) && st->hBWE_TD != NULL )
        {
            /* Common pre-processing for WB TBE and WB BWE */
#ifdef NONBE_FIX_ISSUE_2206
            wb_pre_proc_ivas_fx( st, last_element_mode, new_inp_resamp16k_fx[n], hb_speech_fx, sub( *Q_new, 1 ) );
#else
            wb_pre_proc_ivas_fx( st, last_element_mode, new_inp_resamp16k_fx[n], hb_speech_fx );
#endif
        }

        test();
@@ -678,7 +688,11 @@ ivas_error ivas_core_enc_fx(
        ELSE IF( EQ_16( st->extl, WB_BWE ) && n == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
        {
            /* WB BWE encoder */
#ifdef NONBE_FIX_ISSUE_2206
            wb_bwe_enc_ivas_fx( st, new_inp_resamp16k_fx[n], sub( *Q_new, 1 ) );
#else
            wb_bwe_enc_ivas_fx( st, new_inp_resamp16k_fx[n] );
#endif
        }

        /*---------------------------------------------------------------------*
+12 −43
Original line number Diff line number Diff line
@@ -545,17 +545,11 @@ ivas_error pre_proc_front_ivas_fx(
    ELSE /* DFT stereo */
    {
        /* update the FIR resampling filter memory, needed for switching to time-domain (FIR) resampling */
#ifdef NONBE_FIX_ISSUE_2206_NO
        Copy_Scale_sig( signal_in_fx + sub( input_frame, add( NS2SA_FX2( input_Fs, L_MEM_RECALC_NS ), 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ) ) ), st->mem_decim_fx_q_inp, 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), sub( -Q1, st->q_inp ) ); /* Q-1 */
        st->mem_q = -Q1;
        move16();
#else
        Copy( signal_in_fx + sub( input_frame, add( NS2SA_FX2( input_Fs, L_MEM_RECALC_NS ), 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ) ) ), st->mem_decim_fx_q_inp, 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ) ); /* st->q_inp */
        st->mem_q = st->q_inp;
        move16();
#endif

#ifndef NONBE_FIX_ISSUE_2206
#ifndef NONBE_FIX_ISSUE_2206_NO
        scale_sig( old_inp_12k8_fx, L_INP_MEM - STEREO_DFT_OVL_12k8, sub( Q_inp_const, st->q_inp ) );
        scale_sig( st->input_fx - input_frame, input_frame_full, sub( Q_inp_const, st->q_inp ) );
        Copy_Scale_sig( st->mem_decim_fx_q_inp, st->mem_decim_fx, 2 * L_FILT_MAX, sub( Q_inp_const, st->q_inp ) ); /* Q(-1) */
@@ -566,14 +560,6 @@ ivas_error pre_proc_front_ivas_fx(
        move16();
#endif
    }

#ifdef NONBE_FIX_ISSUE_2206
    Copy_Scale_sig( st->mem_decim_fx_q_inp, st->mem_decim_fx, 2 * L_FILT_MAX, sub( st->q_inp, st->q_inp ) ); /* st->q_inp */

    Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( st->q_inp, sub( Q15, st->exp_buf_speech_enc ) ) ); /* Q(-1) */
    st->exp_buf_speech_enc = sub( Q15, st->q_inp );
    move16();
#else
    IF( NE_16( Q_inp_const, st->q_inp ) )
    {
        Copy_Scale_sig( st->mem_decim_fx_q_inp, st->mem_decim_fx, 2 * L_FILT_MAX, sub( Q_inp_const, st->q_inp ) ); /* Q(-1) */
@@ -582,33 +568,20 @@ ivas_error pre_proc_front_ivas_fx(
    Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( -1, sub( 15, st->exp_buf_speech_enc ) ) ); /* Q(-1) */
    st->exp_buf_speech_enc = 16;
    move16();
#endif

    /* save input resampled at 12.8kHz, non-preemhasised */
    test();
    IF( EQ_16( element_mode, IVAS_CPE_DFT ) )
    {
#ifdef NONBE_FIX_ISSUE_2206
        Copy_Scale_sig( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8, sub( st->q_inp, st->q_inp ) ); /* st->q_inp */
#else
        Copy_Scale_sig( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8, sub( Q_inp_const, st->q_inp ) );                                                         /* Q_inp_const */
#endif
    }
    ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) )
    {
#ifdef NONBE_FIX_ISSUE_2206
        Copy_Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8, st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, add( L_FRAME + L_FILT, lMemRecalc_12k8 ), sub( st->q_inp, st->q_inp ) ); /* st->q_inp */
#else
        Copy_Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8, st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, add( L_FRAME + L_FILT, lMemRecalc_12k8 ), sub( Q_inp_const, st->q_inp ) );                                             /* Q_inp_const */
#endif
    }
    ELSE
    {
#ifdef NONBE_FIX_ISSUE_2206
        Copy_Scale_sig( new_inp_12k8_fx, st->buf_speech_enc + L_FRAME32k, L_FRAME, sub( st->q_inp, st->q_inp ) ); /* st->q_inp */
#else
        Copy_Scale_sig( new_inp_12k8_fx, st->buf_speech_enc + L_FRAME32k, L_FRAME, sub( Q_inp_const, st->q_inp ) );                                                                                                                           /* Q_inp_const */
#endif
    }

    /*------------------------------------------------------------------*
@@ -629,11 +602,7 @@ ivas_error pre_proc_front_ivas_fx(
    test();
    IF( EQ_16( element_mode, IVAS_CPE_DFT ) )
    {
#ifdef NONBE_FIX_ISSUE_2206
        Copy_Scale_sig( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, sub( st->q_inp, st->q_inp ) ); /* memory for TD/DFT stereo switching		st->q_inp */
#else
        Copy_Scale_sig( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, sub( Q_inp_const, st->q_inp ) );                                                    /* memory for TD/DFT stereo switching		Q_inp_const*/
#endif

        st->mem_preemph_fx_q_inp = st->mem_preemph_DFT_fx_q_inp; /* st->q_inp */
        move16();
@@ -660,11 +629,7 @@ ivas_error pre_proc_front_ivas_fx(
            {
                st->mem_preemph_fx_q_inp = st->mem_preemph_DFT_fx_q_inp; /* st->q_inp */
                move16();
#ifdef NONBE_FIX_ISSUE_2206
                Copy( st->inp_12k8_mem_stereo_sw_fx, new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* st->q_inp */
#else
                Copy_Scale_sig( st->inp_12k8_mem_stereo_sw_fx, new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, sub( st->q_inp, Q_inp_const ) ); /* st->q_inp */
#endif
                // PREEMPH_FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx );
                PREEMPH_32FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), sig_out, PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx_q_inp );
                preemp_start_idx = new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT );
@@ -756,15 +721,18 @@ ivas_error pre_proc_front_ivas_fx(

    *Q_new = add( *Q_new, Q_inp_const );
    move16();
#ifndef NONBE_FIX_ISSUE_2206
#ifndef FIX_2015_PREMPH_SAT_ALT
    Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, sub( *Q_new, st->q_inp ) ); /* Q_new */
#else
    Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, sub( add( *Q_new, 1 ), st->q_inp ) );                                                                                                                                         /* Q_new */
#endif
#ifdef NONBE_FIX_ISSUE_2206_NO
    Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), sub( *Q_new, Q_inp_const ) ); /* Q_new */
#else
    Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), sub( *Q_new, st->q_inp ) );                                                                                                                                  /* Q_new */
#else
    Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, sub( *Q_new, st->q_inp ) + 1 );                                                                                                                                         /* Q_new */
    Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), sub( *Q_new, sub( st->q_inp, -1 ) ) + 1 );                                                                                                                                  /* Q_new */

    //Scale_sig( old_inp_16k_fx, L_INP, sub( *Q_new, st->q_inp ) );
#endif

    cldfbScale.hb_scale = cldfbScale.lb_scale;
@@ -1562,6 +1530,10 @@ ivas_error pre_proc_front_ivas_fx(
            move16();
            IF( flag_16k_smc )
            {
#ifdef NONBE_FIX_ISSUE_2206
                Word16 Q_old_inp_16k = add( *Q_new, 1 );
                move16();
#else
                Word16 Q_old_inp_16k = -1;
                move16();

@@ -1590,6 +1562,7 @@ ivas_error pre_proc_front_ivas_fx(
                Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_speech_enc ) ) ); /* Q15 - Q_old_inp_16k */
                st->exp_buf_speech_enc = sub( Q15, Q_old_inp_16k );
                move16();
#endif

                Word16 Q_old_inp_12k8 = *Q_new;
                move16();
@@ -1700,11 +1673,7 @@ ivas_error pre_proc_front_ivas_fx(
    move16();


#ifdef NONBE_FIX_ISSUE_2206_NO
    *Q_new = sub( *Q_new, st->q_inp ); // ivas_core_enc will assume inp signal (12k8 and 16k) in Q_new - st->q_inp
#else
    *Q_new = sub( *Q_new, Q_inp_const );                                                                                                                                                                                                      // ivas_core_enc will assume inp signal (12k8 and 16k) in Q_new - 1
#endif
    move16();

    free( mem_decim_dummy_fx );
+179 −0

File changed.

Preview size limit exceeded, changes collapsed.

+11 −15
Original line number Diff line number Diff line
@@ -833,8 +833,8 @@ ivas_error ivas_cpe_enc_fx(
        move16();

        stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, sts[0]->input32_fx, &out_start_ind, &out_end_ind, 0, input_Fs, input_Fs, 0, NULL );
#ifdef NONBE_FIX_ISSUE_2206
        // Normalise the input buffer
#ifdef NONBE_FIX_ISSUE_2206_NO
        /* Normalise sts[0]->input32_fx */
        Word16 Qs0, Qs1, Qs2, Qs3, Qold2, Qnew2;
        assert( out_start_ind <= 0 && out_end_ind >= 0 );
        Qs0 = L_norm_arr( sts[0]->input32_fx - input_frame, add( input_frame, out_start_ind ) );
@@ -844,7 +844,7 @@ ivas_error ivas_cpe_enc_fx(
        Qold2 = s_min( add( sts[0]->q_old_inp32, Qs0 ), add( Q15, Qs1 ) );
        Qnew2 = s_min( add( Q15, Qs2 ), add( sts[0]->q_inp32, Qs3 ) );
#if 1
        /* Somewhere else sts[0]->q_old_inp32 needs to be the same as sts[0]->q_inp32 */
        /* Somewhere else (i.e. sts[]->encoderLookahead_FB) sts[0]->q_old_inp32 needs to be the same as sts[0]->q_inp32 */
        Qnew2 = s_min( Qnew2, Qold2 );
        Qold2 = Qnew2;
        move16();
@@ -896,8 +896,8 @@ ivas_error ivas_cpe_enc_fx(

        /* iDFT & resampling to 12.8kHz internal sampling rate */
        stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_inp_12k8_fx[0] + L_INP_MEM, &out_12k8_start_ind[0], &out_12k8_end_ind[0], 0, input_Fs, INT_FS_12k8, 0, NULL );
#ifdef NONBE_FIX_ISSUE_2206
        Copy_Scale_sig_32_16( old_inp_12k8_fx[0], old_inp_12k8_16fx[0], L_INP_12k8, sub( sts[0]->q_inp, Q15 ) ); // sts[0]->q_inp
#ifdef NONBE_FIX_ISSUE_2206_NO
        Copy_Scale_sig_32_16( old_inp_12k8_fx[0], old_inp_12k8_16fx[0], L_INP_12k8, sub( sts[0]->q_inp, Q15 ) ); // Q15->sts[0]->q_inp
#else
        Copy_Scale_sig_32_16( old_inp_12k8_fx[0], old_inp_12k8_16fx[0], L_INP_12k8, -Q16 );                                                                // Q-1
#endif
@@ -919,28 +919,24 @@ ivas_error ivas_cpe_enc_fx(
        {
            stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_inp_16k_fx[0] + L_INP_MEM, &out_16k_start_ind, &out_16k_end_ind, 0, input_Fs, internal_Fs, 0, NULL );
        }
#ifdef NONBE_FIX_ISSUE_2206_NO
        Copy_Scale_sig_32_16( old_inp_16k_fx[0], old_inp_16k_16fx[0], L_INP, sub( sts[0]->q_inp, Q15 ) ); // Q15->st->q_inp
#else
        Copy_Scale_sig32_16( old_inp_16k_fx[0], old_inp_16k_16fx[0], L_INP, 0 ); // Q15->Q-1
#endif

        /* DFT Stereo: iDFT of residual signal at 8kHz sampling rate */
        test();
        IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] )
        {
#ifdef NONBE_FIX_ISSUE_2206
            Copy_Scale_sig_16_32_no_sat( sts[1]->old_inp_12k8_fx, old_inp_12k8_fx[1], L_INP_MEM, sub( Q15, sub( Q15, sts[1]->exp_old_inp_12k8 ) ) ); // Q15
#else
            Copy_Scale_sig_16_32_no_sat( sts[1]->old_inp_12k8_fx, old_inp_12k8_fx[1], L_INP_MEM, 15 - 0 );                                                 // Q15
#endif
            stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_inp_12k8_fx[1] + L_INP_MEM, &out_12k8_start_ind[1], &out_12k8_end_ind[1], 1, input_Fs, 8000, 0, NULL );

            /* update old input signal buffer */
            Copy_Scale_sig_32_16( old_inp_12k8_fx[1] + L_FRAME8k, sts[1]->old_inp_12k8_fx, L_INP_MEM, 0 - 15 ); // Q0
            sts[1]->exp_old_inp_12k8 = Q15;
            move16();
#ifdef NONBE_FIX_ISSUE_2206
            Copy_Scale_sig_32_16( old_inp_12k8_fx[1], old_inp_12k8_16fx[1], L_INP_12k8, sub( sts[0]->q_inp, Q15 ) ); // sts[0]->q_inp
#else
            Copy_Scale_sig_32_16( old_inp_12k8_fx[1], old_inp_12k8_16fx[1], L_INP_12k8, -Q16 );                                                            // Q-1
#endif
        }

        /* no iDFT at input sampling rate for Side channel -> reset the buffer */
@@ -1259,8 +1255,8 @@ ivas_error ivas_cpe_enc_fx(

            FOR( Word16 i = 0; i < CPE_CHANNELS; i++ )
            {
#ifdef NONBE_FIX_ISSUE_2206
                Copy_Scale_sig_16_32_no_sat( old_inp_12k8_16fx[i], old_inp_12k8_fx[i], L_INP_12k8, sub( sts[i]->q_inp, Q15 ) ); // q_inp -> Q15
#ifdef NONBE_FIX_ISSUE_2206_NO
                Copy_Scale_sig_16_32_no_sat( old_inp_12k8_16fx[i], old_inp_12k8_fx[i], L_INP_12k8, sub( Q15, sub( Q_new[i], 1 ) ) ); // *Q_new-1 -> Q15
#else
                Copy_Scale_sig_16_32_no_sat( old_inp_12k8_16fx[i], old_inp_12k8_fx[i], L_INP_12k8, Q16 ); // Q(-1) -> Q15
#endif
+11 −0
Original line number Diff line number Diff line
@@ -727,7 +727,12 @@ void wb_bwe_enc_fx(

void wb_bwe_enc_ivas_fx(
    Encoder_State *st_fx,          /* i/o: encoder state structure                  */
#ifdef NONBE_FIX_ISSUE_2206
    const Word16 *new_wb_speech_fx,/* i  : original i   signal at 16kHz             */
    const Word16 new_wb_speech_q   /* i  : Q of new_wb_speech_fx                    */
#else
    const Word16 *new_wb_speech_fx /* i  : original i   signal at 16kHz             */
#endif
);

void wb_pre_proc_fx(
@@ -739,8 +744,14 @@ void wb_pre_proc_fx(
void wb_pre_proc_ivas_fx(
    Encoder_State *st_fx,            /* i/o: encoder state structure                   */
    const Word16 last_element_mode,  /* i  : last element mode                         */
#ifdef NONBE_FIX_ISSUE_2206
    const Word16 *new_inp_resamp16k, /* i  : original input signal in new_inp_resamp16k_q */
    Word16 *hb_speech,               /* o  : HB target signal (6-8kHz) at 16kHz in Q-1 */
    const Word16 new_inp_resamp16k_q /* i  : Q of new_inp_resamp16k                    */
#else
    const Word16 *new_inp_resamp16k, /* i  : original input signal in Q-1              */
    Word16 *hb_speech                /* o  : HB target signal (6-8kHz) at 16kHz in Q-1 */
#endif
);

void wb_tbe_enc_fx(
Loading