Commit 27508360 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

inp 12k8 precision improvement through pre_proc_front path

parent c17cc4c5
Loading
Loading
Loading
Loading
Loading
+96 −109

File changed.

Preview size limit exceeded, changes collapsed.

+28 −34
Original line number Diff line number Diff line
@@ -216,30 +216,29 @@ ivas_error ivas_cpe_enc_fx(
#endif
    }

    Copy32( data_fx_ch0, sts[0]->input32_fx, input_frame ); // Q(q_data_fx)
    sts[0]->q_inp32 = q_data_fx;
    Word16 Q_min = s_min( q_data_fx, add( sts[0]->q_inp32, L_norm_arr( sts[0]->input32_fx - input_frame, input_frame ) ) );
    scale_sig32( sts[0]->input32_fx - input_frame, input_frame, sub( Q_min, sts[0]->q_inp32 ) );
    Copy_Scale_sig32( data_fx_ch0, sts[0]->input32_fx, input_frame, sub( Q_min, q_data_fx ) ); // Q(Q_min)
    sts[0]->q_inp32 = Q_min;
    move16();

    Word16 norm = L_norm_arr( sts[0]->input32_fx, input_frame );
    scale_sig32( sts[0]->input32_fx, input_frame, norm );
    sts[0]->q_inp32 = add( sts[0]->q_inp32, norm );
    move16();

    Copy_Scale_sig32_16( sts[0]->input32_fx, sts[0]->input_fx, input_frame, 0 );
    sts[0]->q_inp = sub( sts[0]->q_inp32, Q16 );
    Copy_Scale_sig32_16( sts[0]->input32_fx, sts[0]->input_fx, input_frame, norm );
    sts[0]->q_inp = add( sub( sts[0]->q_inp32, Q16 ), norm );
    move16();
    IF( data_fx_ch1 != NULL ) /*this may happen for cases with odd number of channels*/
    {
        Copy32( data_fx_ch1, sts[1]->input32_fx, input_frame ); // Q(q_data_fx)
        sts[1]->q_inp32 = q_data_fx;
        Q_min = s_min( q_data_fx, add( sts[1]->q_inp32, L_norm_arr( sts[1]->input32_fx - input_frame, input_frame ) ) );
        scale_sig32( sts[1]->input32_fx - input_frame, input_frame, sub( Q_min, sts[1]->q_inp32 ) );
        Copy_Scale_sig32( data_fx_ch1, sts[1]->input32_fx, input_frame, sub( Q_min, q_data_fx ) ); // Q(Q_min)
        sts[1]->q_inp32 = Q_min;
        move16();

        norm = L_norm_arr( sts[1]->input32_fx, input_frame );
        scale_sig32( sts[1]->input32_fx, input_frame, norm );
        sts[1]->q_inp32 = add( sts[1]->q_inp32, norm );
        move16();

        Copy_Scale_sig32_16( sts[1]->input32_fx, sts[1]->input_fx, input_frame, 0 );
        sts[1]->q_inp = sub( sts[1]->q_inp32, Q16 );
        Copy_Scale_sig32_16( sts[1]->input32_fx, sts[1]->input_fx, input_frame, norm );
        sts[1]->q_inp = add( sub( sts[1]->q_inp32, Q16 ), norm );
        move16();
    }

@@ -369,26 +368,8 @@ ivas_error ivas_cpe_enc_fx(
    /*----------------------------------------------------------------*
     * Set TD stereo parameters
     *----------------------------------------------------------------*/
    Copy_Scale_sig_16_32_no_sat( sts[1]->input_fx, sts[1]->input32_fx, input_frame, sub( Q11, sts[1]->q_inp ) ); /* Q11 */
    Copy_Scale_sig_16_32_no_sat( sts[0]->input_fx, sts[0]->input32_fx, input_frame, sub( Q11, sts[0]->q_inp ) ); /* Q11 */
    Word16 shift = getScaleFactor32( sts[1]->input32_fx, input_frame );
    scale_sig32( sts[1]->input32_fx, input_frame, shift ); /* Q11 + shift */
    sts[1]->q_inp32 = add( Q11, shift );
    move16();

    shift = getScaleFactor32( sts[0]->input32_fx, input_frame );
    scale_sig32( sts[0]->input32_fx, input_frame, shift ); /* Q11 + shift */
    sts[0]->q_inp32 = add( Q11, shift );
    move16();

    Q_inp = s_min( Q_inp, s_min( sts[0]->q_inp32, sts[1]->q_inp32 ) );
    scale_sig32( sts[0]->input32_fx, input_frame, sub( Q_inp, sts[0]->q_inp32 ) ); /* Q_inp */
    scale_sig32( sts[1]->input32_fx, input_frame, sub( Q_inp, sts[1]->q_inp32 ) ); /* Q_inp */
    sts[1]->q_inp32 = sts[0]->q_inp32 = Q_inp;
    move16();
    move16();

    IF( ( error = stereo_set_tdm_fx( hCPE, input_frame, Q_inp ) ) != IVAS_ERR_OK )
    IF( ( error = stereo_set_tdm_fx( hCPE, input_frame, sts[1]->q_inp32 ) ) != IVAS_ERR_OK )
    {
        return error;
    }
@@ -397,7 +378,7 @@ ivas_error ivas_cpe_enc_fx(
    /*----------------------------------------------------------------*
     * Resets/updates in case of stereo switching
     *----------------------------------------------------------------*/
    shift = norm_arr( sts[1]->old_input_signal_fx, input_frame );
    Word16 shift = norm_arr( sts[1]->old_input_signal_fx, input_frame );
    Scale_sig( sts[1]->old_input_signal_fx, input_frame, shift ); /* sts[1]->q_old_inp + shift  */
    sts[1]->q_old_inp = add( sts[1]->q_old_inp, shift );
    move16();
@@ -741,6 +722,8 @@ ivas_error ivas_cpe_enc_fx(
            move16();
        }
        stereo_tdm_downmix_ivas_fx( hCPE->hStereoTD, sts[0]->input_fx, sts[1]->input_fx, input_frame, tdm_ratio_idx, tdm_SM_flag, tdm_ratio_idx_SM );
        Copy_Scale_sig_16_32_no_sat( sts[0]->input_fx, sts[0]->input32_fx, input_frame, sub( sts[0]->q_inp32, sts[0]->q_inp ) );
        Copy_Scale_sig_16_32_no_sat( sts[1]->input_fx, sts[1]->input32_fx, input_frame, sub( sts[1]->q_inp32, sts[1]->q_inp ) );

        /* signal the bitrate for BW selection in the SCh */
        sts[0]->bits_frame_channel = 0;
@@ -831,6 +814,9 @@ ivas_error ivas_cpe_enc_fx(
        move16();
        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 );
        Scale_sig32( sts[0]->input32_fx - input_frame, add( out_start_ind, input_frame ), sub( Q15, sts[0]->q_inp32 ) ); // scaling initial part of the input buffer
        sts[0]->q_inp32 = Q15;
        move16();

        // Normalise the input buffer from Q15
        Word16 input_norm, q_inp32, common_q, fir_delay_len;
@@ -890,6 +876,9 @@ ivas_error ivas_cpe_enc_fx(
        set16_fx( sts[1]->input_fx, 0, input_frame );
        sts[1]->q_inp = Q15;
        move16();
        set32_fx( sts[1]->input32_fx, 0, input_frame );
        sts[1]->q_inp32 = Q31;
        move16();
    }

#ifdef DEBUG_MODE_INFO
@@ -1232,6 +1221,9 @@ ivas_error ivas_cpe_enc_fx(
            Copy( orig_input_fx[n], sts[n]->old_input_signal_fx, input_frame ); /* Q_orig_inp */
            sts[n]->q_old_inp = Q_orig_inp[n];
            move16();
            Copy_Scale_sig_16_32_no_sat( sts[n]->input_fx - input_frame, sts[n]->input32_fx - input_frame, input_frame, 16 ); // duplicating the data for input32_fx
            sts[n]->q_inp32 = add( Q_orig_inp[n], 16 );
            move16();
        }
    }
    ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
@@ -1239,6 +1231,7 @@ ivas_error ivas_cpe_enc_fx(
        Copy( sts[0]->input_fx, sts[0]->old_input_signal_fx, input_frame ); /* sts[n]->q_inp */
        sts[0]->q_old_inp = sts[0]->q_inp;
        move16();
        Copy32( sts[0]->input32_fx, sts[0]->input32_fx - input_frame, input_frame ); /* st->q_inp32 */
    }
    ELSE IF( st_ivas->hMCT == NULL ) /* note: in MCT, input buffers are updated later in ivas_mct_enc() */
    {
@@ -1248,6 +1241,7 @@ ivas_error ivas_cpe_enc_fx(
            Copy( sts[n]->input_fx, sts[n]->old_input_signal_fx, input_frame ); /* sts[n]->q_inp */
            sts[n]->q_old_inp = sts[n]->q_inp;
            move16();
            Copy32( sts[n]->input32_fx, sts[n]->input32_fx - input_frame, input_frame ); /* st->q_inp32 */
        }
    }

+9 −14
Original line number Diff line number Diff line
@@ -165,10 +165,14 @@ ivas_error ivas_ism_enc_fx(
        /*------------------------------------------------------------------*
         * Initialization - general
         *-----------------------------------------------------------------*/
        Copy32( data[sce_id], st->input32_fx, input_frame ); // Q(q_data)
        q_st_inp_16 = sub( L_norm_arr( st->input32_fx, input_frame ), 16 );
        Copy_Scale_sig_32_16( st->input32_fx, st->input_fx, input_frame, q_st_inp_16 ); // q_data -> Q(q_inp + q_data)
        st->q_inp = add( q_st_inp_16, q_data );
        Word16 Q_min = s_min( q_data, add( st->q_inp32, L_norm_arr( st->input32_fx - input_frame, input_frame ) ) );
        scale_sig32( st->input32_fx - input_frame, input_frame, sub( Q_min, st->q_inp32 ) );
        Copy_Scale_sig32( data[sce_id], st->input32_fx, input_frame, sub( Q_min, q_data ) ); // Q(Q_min)
        st->q_inp32 = Q_min;
        move16();
        q_st_inp_16 = sub( getScaleFactor32( st->input32_fx, input_frame ), 16 );
        Copy_Scale_sig_32_16( st->input32_fx, st->input_fx, input_frame, q_st_inp_16 ); // Q_min -> Q(q_inp + Q_min)
        st->q_inp = add( q_st_inp_16, Q_min );
        move16();

        st->element_mode = IVAS_SCE;
@@ -275,16 +279,6 @@ ivas_error ivas_ism_enc_fx(
     *-----------------------------------------------------------------*/

    /* compute the dominant sce_id using long term energy */
    FOR( Word16 j = 0; j < st_ivas->nchan_transport; j++ )
    {
        test();
        IF( st_ivas->hSCE[j] && st_ivas->hSCE[j]->hCoreCoder[0] )
        {
            Copy_Scale_sig_16_32_no_sat( st_ivas->hSCE[j]->hCoreCoder[0]->input_fx, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, input_frame, sub( Q11, st_ivas->hSCE[j]->hCoreCoder[0]->q_inp ) ); /* Q11 */
            st_ivas->hSCE[j]->hCoreCoder[0]->q_inp32 = Q11;
            move16();
        }
    }

    IF( st_ivas->hEncoderConfig->Opt_DTX_ON )
    {
@@ -480,6 +474,7 @@ ivas_error ivas_ism_enc_fx(
        Copy( st->input_fx, st->old_input_signal_fx, input_frame ); /* st->q_inp */
        st->q_old_inp = st->q_inp;
        move16();
        Copy32( st->input32_fx, st->input32_fx - input_frame, input_frame ); /* st->q_inp32 */

        hSCE->last_element_brate = hSCE->element_brate; /* Q0 */
        move32();
+8 −3
Original line number Diff line number Diff line
@@ -122,10 +122,14 @@ ivas_error ivas_sce_enc_fx(

    set16_zero_fx( old_inp_12k8_fx[0], L_INP_12k8 );

    Copy32( data_fx, st->input32_fx, input_frame ); // Q(q_data_fx)
    q_input = sub( add( L_norm_arr( st->input32_fx, input_frame ), q_data_fx ), 16 );
    Word16 Q_min = s_min( q_data_fx, add( st->q_inp32, L_norm_arr( st->input32_fx - input_frame, input_frame ) ) );
    scale_sig32( st->input32_fx - input_frame, input_frame, sub( Q_min, st->q_inp32 ) );
    Copy_Scale_sig32( data_fx, st->input32_fx, input_frame, sub( Q_min, q_data_fx ) ); // Q(Q_min)
    st->q_inp32 = Q_min;
    move16();
    q_input = sub( add( L_norm_arr( st->input32_fx, input_frame ), Q_min ), 16 );

    Copy_Scale_sig32_16( st->input32_fx, st->input_fx, input_frame, sub( add( Q16, q_input ), q_data_fx ) ); // Q(q_data_fx) -> Q(q_input)
    Copy_Scale_sig32_16( st->input32_fx, st->input_fx, input_frame, sub( add( Q16, q_input ), Q_min ) ); // Q(Q_min) -> Q(q_input)
    st->q_inp = q_input;
    move16();

@@ -362,6 +366,7 @@ ivas_error ivas_sce_enc_fx(
    Copy( st->input_fx, st->old_input_signal_fx, input_frame );
    st->q_old_inp = st->q_inp;
    move16();
    Copy32( st->input32_fx, st->input32_fx - input_frame, input_frame ); /* st->q_inp32 */
    hSCE->last_element_brate = hSCE->element_brate;
    move32();

+4 −4
Original line number Diff line number Diff line
@@ -2948,11 +2948,11 @@ void ivas_smc_mode_selection_fx(
    ton = tonal_det_fx( S_map, st->vad_flag, hSpMusClas->tod_S_map_lt_fx, &hSpMusClas->tod_thr_lt_fx, &hSpMusClas->tod_weight_fx, &hSpMusClas->tod_S_mass_prev_fx, &hSpMusClas->tod_S_mass_lt_fx ); // Q22

    /* calculate spectral peak-to-average ratio */
    Word16 shift = sub( add( Q_new, Q_SCALE - 2 ), st->hSpMusClas->Q_tod_lt_Bin_E );
    Word16 shift = sub( st->q_Bin_E, st->hSpMusClas->Q_tod_lt_Bin_E );
    FOR( i = 0; i < TOD_NSPEC; i++ )
    {
        // st->hSpMusClas->tod_lt_Bin_E[i] = P2A_FACT * st->hSpMusClas->tod_lt_Bin_E[i] + ( 1 - P2A_FACT ) * st->Bin_E[i];
        st->hSpMusClas->tod_lt_Bin_E_fx[i] = Madd_32_16( L_shl( Mpy_32_16_1( st->hSpMusClas->tod_lt_Bin_E_fx[i], P2A_FACT_FX_Q15 ), shift ), st->Bin_E_fx[i], ( 32767 - P2A_FACT_FX_Q15 ) ); // Q = Q_new + Q_SCALE - 2
        st->hSpMusClas->tod_lt_Bin_E_fx[i] = Madd_32_16( L_shl( Mpy_32_16_1( st->hSpMusClas->tod_lt_Bin_E_fx[i], P2A_FACT_FX_Q15 ), shift ), st->Bin_E_fx[i], ( 32767 - P2A_FACT_FX_Q15 ) ); // Q = st->q_Bin_E + Q_SCALE - 2
        move32();
    }
    st->hSpMusClas->Q_tod_lt_Bin_E = add( st->hSpMusClas->Q_tod_lt_Bin_E, shift );
@@ -2969,11 +2969,11 @@ void ivas_smc_mode_selection_fx(

    IF( LE_32( element_brate, IVAS_16k4 ) )
    {
        thr_sp2a = L_shl( THR_P2A_HIGH_FX, add( Q_new, Q_SCALE - 2 ) ); // Q = Q_new + Q_SCALE - 2
        thr_sp2a = L_shl( THR_P2A_HIGH_FX, st->q_Bin_E ); // Q = st->q_Bin_E
    }
    ELSE
    {
        thr_sp2a = L_shl( THR_P2A_FX, add( Q_new, Q_SCALE - 2 ) ); // Q = Q_new + Q_SCALE - 2
        thr_sp2a = L_shl( THR_P2A_FX, st->q_Bin_E ); // Q = st->q_Bin_E
    }

    /* initial 3-way selection of coding modes (ACELP/GSC/TCX) */