Commit 3ea8505d authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch '3gpp_issue_1457_fix_3' into 'main'

Fix for 3GPP issue 1457: Stereo Encoder 32 kbps: More rattling artifcats in 16 kHz LTVs [allow regression]

See merge request !1673
parents e73f7b67 306f26e2
Loading
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -649,10 +649,11 @@ ivas_error ivas_cpe_enc_fx(
        hCPE->hStereoDft->Spd_R_smooth_fx_e = sub( hCPE->hStereoDft->Spd_R_smooth_fx_e, temp );
        move16();


        q_com = MAX_16;
        move16();
        FOR( n = 0; n < CPE_CHANNELS; n++ )
        {
            q_com = sub( add( L_norm_arr( sts[n]->input32_fx, input_frame ), sts[n]->q_inp32 ), 16 );
            q_com = s_min( q_com, sub( add( L_norm_arr( sts[n]->input32_fx, input_frame ), sts[n]->q_inp32 ), 16 ) );
            q_com = s_min( q_com, sub( add( L_norm_arr( sts[n]->old_input_signal32_fx, input_frame ), sts[n]->q_old_inp32 ), 16 ) );
            q_com = s_min( q_com, add( norm_arr( hCPE->input_mem_fx[n], hCPE->hStereoDft->dft_ovl ), hCPE->q_input_mem[n] ) );

@@ -661,7 +662,9 @@ ivas_error ivas_cpe_enc_fx(
                q_com = 0;
                move16();
            }

        }
        FOR( n = 0; n < CPE_CHANNELS; n++ )
        {
            Copy_Scale_sig_32_16( sts[n]->input32_fx, sts[n]->input_fx, input_frame, sub( q_com, sts[n]->q_inp32 ) );
            sts[n]->q_inp = q_com;
            move16();
@@ -674,7 +677,6 @@ ivas_error ivas_cpe_enc_fx(
            hCPE->q_input_mem[n] = q_com;
            move16();
        }

        stereo_dft_hybrid_ITD_flag_fx( hCPE->hStereoDft->hConfig, input_Fs, hCPE->hStereoDft->hItd->hybrid_itd_max );

        /* Time Domain ITD compensation using extrapolation */
+24 −2
Original line number Diff line number Diff line
@@ -169,7 +169,8 @@ static void stereo_dft_quantize_itd_fx(
    Word16 *ind )
{
    Word16 itd;

    Word16 input_fs_by_stereo_dft_itd_fs = 0;
    move16();
    // itd = (int16_t) ( sign( in ) * 0.5f + in );
    itd = in;
    move16();
@@ -188,9 +189,30 @@ static void stereo_dft_quantize_itd_fx(
        move16();
    }

    SWITCH( input_Fs )
    {
        case 8000:
            input_fs_by_stereo_dft_itd_fs = 1; // Q2
            move16();
            BREAK;
        case 16000:
            input_fs_by_stereo_dft_itd_fs = 2; // Q2
            move16();
            BREAK;
        case 32000:
            input_fs_by_stereo_dft_itd_fs = 4; // Q2
            move16();
            BREAK;
        case 48000:
            input_fs_by_stereo_dft_itd_fs = 6; // Q2
            move16();
            BREAK;
        default:
            assert( 0 );
    }
    /*Convert back @ fs*/
    //*out = (float) ( itd * input_Fs ) / ( (float) ( STEREO_DFT_ITD_FS ) );
    *out = Mpy_32_32( L_shl( itd * input_Fs, 2 ), 1099511628 /*Q45*/ ); // Q45+Q2-Q31 = Q16
    *out = L_shl( L_mult( itd, input_fs_by_stereo_dft_itd_fs ), Q13 ); // Q16
    move32();

    return;
+49 −17
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@

#define STEREO_DFT_CHANNEL_EXTR_LPC_ORDER     10
#define STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT 320
#define FLR_FX                                16384 // Q15
#define FLR_FX                                1073741824 // Q31
#define ONE_HALF                              24576      // Q14
const Word16 wac_swb_h_fx[LPC_SHB_ORDER + 1] = {         // Q15
    32767,
@@ -95,7 +95,12 @@ static void stereo_td_get_td_itd_fx(
{
    /* *td_itd is the closest integer to itd that transforms into an integer value *
     * under the transform x -> (32000/fs) x.                                      */
    Word16 d, d_e;
    Word32 inverse_input_fs_by_16k = 0;
    move32();
    Word64 tmp64;
    Word16 d = 0, shift = 0;
    move16();
    move16();

    IF( EQ_32( input_Fs, 32000 ) )
    {
@@ -106,25 +111,52 @@ static void stereo_td_get_td_itd_fx(
    ELSE
    {
        assert( ( input_Fs % 16000 ) == 0 && "sampling frequency should be divisible by 16000" );
        Word16 temp_div, temp_e, temp_add;
        d = BASOP_Util_Divide3232_Scale( input_Fs, 16000, &d_e );
        temp_div = BASOP_Util_Divide3232_Scale( itd, L_deposit_h( d ), &temp_e );
        temp_e = add( temp_e, sub( sub( 31, q_itd ), d_e ) ); // e+(e1-e2)//
        temp_add = add_sat( temp_div, shr_sat( FLR_FX, temp_e ) );

        IF( itd != 0 )
        IF( itd == 0 )
        {
            *td_itd_32 = extract_l( L_shl( L_shr( L_add( temp_add, EPSILON_FX ), sub( 15, temp_e ) ), 1 ) );
            *td_itd_32 = *td_itd = 0;
            move16();
            move16();
        }
        ELSE
        {
            *td_itd_32 = shl( shr( temp_add, sub( 15, temp_e ) ), 1 );
            SWITCH( input_Fs )
            {
                case 16000:
                    inverse_input_fs_by_16k = 1073741824; // Q30 /* This is in Q30, because 2147483648 cannot be represnt in Word32*/
                    move32();
                    d = 1; // Q0
                    move16();
                    shift = 1;
                    move16();
                    BREAK;
                case 32000:
                    inverse_input_fs_by_16k = 1073741824; // Q31
                    move32();
                    d = 2; // Q0
                    move16();
                    BREAK;
                case 48000:
                    inverse_input_fs_by_16k = 715827883; // Q31
                    move32();
                    d = 3; // Q0
                    move16();
                    if ( itd < 0 )
                    {
                        inverse_input_fs_by_16k = 715827882; /* Reducing the precision by 1 to handle multiplication of negative case*/
                        move32();
                    }
                    BREAK;
                default:
                    assert( 0 );
            }
            tmp64 = W_add( W_mult0_32_32( itd, inverse_input_fs_by_16k ), W_shl( FLR_FX, sub( q_itd, shift ) ) ); // Q: q_itd - shift + 31
            *td_itd_32 = shl( extract_l( W_extract_l( W_shr( tmp64, add( sub( q_itd, shift ), Q31 ) ) ) ), 1 );   // Q0
            move16();

        *td_itd = i_mult( shr( *td_itd_32, 1 ), shr( d, sub( 15, d_e ) ) );
            *td_itd = i_mult( shr( *td_itd_32, 1 ), d ); // Q0
            move16();
        }
    }

    return;
}