Commit a4d343e1 authored by multrus's avatar multrus
Browse files

fix calculation of hStereoDft->hb_nrg_subr_fx[]

parent 96b69bd9
Loading
Loading
Loading
Loading
Loading
+59 −1
Original line number Diff line number Diff line
@@ -684,20 +684,67 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs(
    const Word16 q_hb_synth )
{
    Word16 i;
#ifdef FIX_BASOP_2521_DIRAC_STEREO_STEFFI_NRGS
    Word32 hb_nrg;
    Word32 max_val;
    Word16 shift;
#else
    Word32 hb_nrg = EPSILON_FIX;
    move32();
    Word32 hb_nrg2 = EPSILON_FIX;
    move32();
#endif

#ifdef FIX_BASOP_2521_DIRAC_STEREO_STEFFI_NRGS
    maximum_abs_32_fx( hb_synth, output_frame, &max_val );
    shift = norm_l( max_val );
    if ( max_val == 0 )
    {
        shift = 31;
        move16();
    }
    shift = sub( shift, shr( add( find_guarded_bits_fx( shr( output_frame, 1 ) ), 1 ), 1 ) );
#endif

    test();
    test();
    IF( ( EQ_16( core, ACELP_CORE ) && !fd_cng_flag ) || EQ_16( hStereoDft->core_hist[1], ACELP_CORE ) )
    {
#ifdef FIX_BASOP_2521_DIRAC_STEREO_STEFFI_NRGS
        Word32 L_tmp;
        Word16 tmp;
        Word64 W_tmp;

        tmp = shl_sat( 1, shift );

        W_tmp = EPSILON_FIX;
        move64();
        FOR( i = 0; i < shr( output_frame, 1 ); i++ )
        {
            // needed to be adjusted for q
            L_tmp = Mpy_32_16_1( hb_synth[i], tmp );    /* q_hb_synth + shift - 15 */
            W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); /* 2 * (q_hb_synth + shift) - 29 */
        }

        hStereoDft->hb_nrg_subr_fx[0] = W_round48_L( W_tmp ); /* 2 * (q_hb_synth + shift) - 45 */
        move32();

        W_tmp = EPSILON_FIX;
        move64();
        FOR( ; i < output_frame; i++ )
        {
            L_tmp = Mpy_32_16_1( hb_synth[i], tmp );    /* q_hb_synth + shift - 15 */
            W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); /* 2 * (q_hb_synth + shift) - 45 */
        }

        hStereoDft->hb_nrg_subr_fx[1] = W_round48_L( W_tmp ); // 2 * (q_hb_synth + shift) - 45
        move32();
        hStereoDft->q_hb_nrg_subr = sub( shl( add( q_hb_synth, shift ), 1 ), 45 );
        move16();

        hb_nrg = L_add( hStereoDft->hb_nrg_subr_fx[0], hStereoDft->hb_nrg_subr_fx[1] ); // 2 * (q_hb_synth + shift) - 45
#else
        FOR( i = 0; i < shr( output_frame, 2 ); i++ )
#endif
        {
            hb_nrg2 = Madd_32_32( hb_nrg2, hb_synth[i], hb_synth[i] ); /*2*q_hb_synth-31*/
        }
@@ -719,6 +766,7 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs(
        hStereoDft->hb_nrg_subr_fx[1] = hb_nrg2; /*2*q_hb_synth-31*/
        move32();
        hb_nrg = L_add( hb_nrg, hb_nrg2 );
#endif

        IF( EQ_16( hStereoDft->q_hb_stefi_sig_fx, q_hb_synth ) )
        {
@@ -747,12 +795,22 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs(
        hStereoDft->hb_nrg_subr_fx[1] = 0;
        move32();
    }
#ifdef FIX_BASOP_2521_DIRAC_STEREO_STEFFI_NRGS
    hStereoDft->hb_nrg_subr_fx[0] = ( Mpy_32_16_1( hStereoDft->hb_nrg_subr_fx[0], shl( shr( hStereoDft->NFFT, 1 ), 6 ) ) ); // 2 * (q_hb_synth + shift) - 40
    move32();
    hStereoDft->hb_nrg_subr_fx[1] = ( Mpy_32_16_1( hStereoDft->hb_nrg_subr_fx[1], shl( shr( hStereoDft->NFFT, 1 ), 6 ) ) ); // 2 * (q_hb_synth + shift) - 40
    move32();
    hStereoDft->q_hb_nrg_subr = sub( shl( ( q_hb_synth + shift ), 1 ), 45 + 9 );
    hStereoDft->hb_nrg_fx[0] = hb_nrg; /* todo: which Q-value is this supposed to be? */
    move32();
#else
    hStereoDft->hb_nrg_subr_fx[0] = hStereoDft->hb_nrg_subr_fx[0]; // imult3216(hStereoDft->hb_nrg_subr_fx[0] , shr(hStereoDft->NFFT, 1)); /*hStereoDft->q_hb_nrg_subr*/
    move32();
    hStereoDft->hb_nrg_subr_fx[1] = hStereoDft->hb_nrg_subr_fx[1]; // imult3216(hStereoDft->hb_nrg_subr_fx[1] , shr(hStereoDft->NFFT, 1)); /*hStereoDft->q_hb_nrg_subr*/
    move32();
    hStereoDft->hb_nrg_fx[0] = hb_nrg;
    move32();
#endif
    hStereoDft->td_gain_fx[0] = 0;
    move32();
    hStereoDft->core_hist[0] = core; /* full signal available for DTX with FD-CNG, thus apply stereo filling on full spectrum like in TCX */